akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <cstring>

using namespace std;

typedef complex<double> P;

struct L { P p, q; L(P p, P q) : p(p), q(q) {} };

const double EPS = 1e-8;

double cross(P a, P b){ return imag(conj(a)*b); }
double rot(P a, P b){ return arg(conj(a)*b); }

P ssCrosspoint(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A*(b.q-b.p);
}

double distLP(L l, P p){
	return abs(cross(l.q-l.p,p-l.p))/abs(l.q-l.p);
}

void getPoint(vector<P> &vp, L a, L b, double r){
	if(abs(imag((a.q-a.p)/(b.q-b.p))) < EPS) return ;
	P c = ssCrosspoint(a, b);
	P dirA = (a.q-a.p)/abs(a.q-a.p);
	P dirB = (b.q-b.p)/abs(b.q-b.p);
	P dirC = (dirA+dirB)/abs(dirA+dirB);
	P dirD = dirC*P(0,1);
	double rad = abs(rot(dirA, dirC));
	vp.push_back(c+dirC*r/sin(rad));
	vp.push_back(c-dirC*r/sin(rad));
	vp.push_back(c+dirD*r/cos(rad));
	vp.push_back(c-dirD*r/cos(rad));
}

void getSafepoint(vector<P> &vp, pair<L,double> a, pair<L,double> b, double w, double h, double r){
	vector<P> tmp;
	L l = a.first, m = b.first;
	P dirA = a.second*(l.q-l.p)/abs(l.q-l.p)*P(0,1);
	P dirB = b.second*(m.q-m.p)/abs(m.q-m.p)*P(0,1);
	getPoint(tmp, L(l.p+dirA,l.q+dirA), L(m.p+dirB,m.q+dirB), r);
	getPoint(tmp, L(l.p+dirA,l.q+dirA), L(m.p-dirB,m.q-dirB), r);
	getPoint(tmp, L(l.p-dirA,l.q-dirA), L(m.p+dirB,m.q+dirB), r);
	getPoint(tmp, L(l.p-dirA,l.q-dirA), L(m.p-dirB,m.q-dirB), r);
	for(int i=0;i<tmp.size();i++){
		if(real(tmp[i])<-EPS||w+EPS<real(tmp[i])||imag(tmp[i])<-EPS||h+EPS<imag(tmp[i])) continue;
		double rA = distLP(l, tmp[i]), rB = distLP(m, tmp[i]);
		if(rA+EPS < a.second+r || rB+EPS < b.second+r) continue;
		vp.push_back(tmp[i]);
	}
}

int main(){
	int w, h, n; double r; 
	while(cin >> w >> h >> n >> r, w){
		vector< pair<L,double> > laser;
		laser.push_back(make_pair(L(P(0, -1),P(w, -1)),1));
		laser.push_back(make_pair(L(P(0,h+1),P(w,h+1)),1));
		laser.push_back(make_pair(L(P( -1,0),P( -1,h)),1));
		laser.push_back(make_pair(L(P(w+1,0),P(w+1,h)),1));
		int x1, y1, x2, y2, t;
		for(int i=0;i<n;i++){
			cin >> x1 >> y1 >> x2 >> y2 >> t;
			laser.push_back(make_pair(L(P(x1,y1),P(x2,y2)),t));
		}
		vector<P> vp;
		for(int i=0;i<n+4;i++){
			for(int j=i+1;j<n+4;j++){
				getSafepoint(vp, laser[i], laser[j], w, h, r);
			}
		}
		bool flag = false;
		for(int i=0;i<vp.size();i++){
			bool check = true;
			for(int j=0;j<laser.size();j++){
				double l = distLP(laser[j].first, vp[i]);
				if(distLP(laser[j].first, vp[i])+EPS < laser[j].second+r) check = false;
			}
			if(check) flag = true;
		}
		cout << (flag ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 1444
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gosagu(ll A,ll B)
{
	if(A<B) swap(A,B);
	if(A%B==0) return B;
	else return gosagu(B,A%B);
}
int main()
{
	int N;cin>>N;
	int A[N+5];
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
	}
	int unbreakable = 1;
	int breakable = 0;
	for(int i=0;i<N;i++)
	{
		if(A[i]==unbreakable) unbreakable++;
		else breakable++;
	}
	if(breakable==N) cout<<"-1\n";
	else cout<<breakable<<"\n";
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.Math;
public class Main{
public static void main(String[] args){
Scanner x= new Scanner(System.in);

int c= x.nextInt();
int[] arr = new int[c];
double a =0;
for(int i =0;i<c;i++){
	arr[i]=x.nextInt();
	a += arr[i];
}

int a1 = (int)(a/c);
int a2 = a1 +1;


int r1=0;
int r2=0;
for(int i =0;i<c;i++){
	r1 += Math.pow(arr[i]-a1 , 2);
}


for(int i =0;i<c;i++){
	r2 += Math.pow(arr[i]-a2 , 2);
}

System.out.println(Math.min(r1,r2));



}
}


Measured memory_bytes: 9556
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int sum(int a) {
    int s = 0;
    while (a) {
        s += a % 10;
        a /= 10;
    }
    return s;
}


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

    int ans = 1e9;
    for (int i = 1; i <= n / 2; i++) {
        int a = i;
        int b = n - i;
        int sa = sum(a);
        int sb = sum(b);
        if (sa + sb < ans) {
            ans = sa + sb;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]

dp = [0] * (n+1);

dp[0] = 1
dp[1] = -1

for i in range(0, n):
    if i>0: dp[i] += dp[i-1]
    dp[i] %= 998244353
    for l,r in lr:
        if i+l > n: continue
        dp[i+l] += dp[i]
        dp[min(n, i+r+1)] -= dp[i]

print(dp[-2] % 998244353)


Measured memory_bytes: 16636
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0)cout << -1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) {
		cout << 0 << endl; return 0;
	}
	int cnt = 1;
	while (true) {
		if (a % 4 != 0 || b % 4 != 0 || c % 4 != 0) {
			cout << cnt << endl; return 0;
		}
		else {
			int tmp = a / 2; int tmp2 = b / 2; int tmp3 = c / 2;
			a = tmp2 + tmp3;
			b = tmp + tmp3;
			c = tmp + tmp2; cnt++;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	string s = "MARCH", tmp;
	ll n, ans = 0;
	map<char, ll> m;
	cin >> n;
	REP(i, 0, n){
		cin >> tmp;
		++m[tmp[0]];
	}
	
	ll ss = s.size();
	REP(i, 0, ss-2){
		REP(j, i+1, ss-1){
			REP(k, j+1, ss){
				ans += m[s[i]] * m[s[j]]* m[s[k]];
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
static const int NMAX = 10001;

bool LinearSearch(int *arr, int N, int key);

int main() {
    int n, q, key, num;
    int S[NMAX];

    num = 0;

    std::cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        scanf("%d", &key);
        if (LinearSearch(S, n, key)) {
            num++;
        }
    }
    
    std::cout << num << std::endl;

    return 0;
}

bool LinearSearch(int *arr, int N, int key) {
    int j;

    j = 0;
    arr[N] = key;

    while (key != arr[j]) {
        j++;
    }
    return j != N;
}


Measured memory_bytes: 3256
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    bool bl = 1;
    for(int i = 0; i<n; i++){
        int x;
        cin >> x;
        if(x%2==0&&x%5!=0&&x%3!=0) bl =0;
    }
    if(bl)cout << "APPROVED\n";
    else cout << "DENIED\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() 
{
	int n,top=-1,tmp,less=10000;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>tmp;
		if(top<tmp)top=tmp;
		if(less>tmp)less=tmp;
	}
	cout << top-less;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	int count = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0)	{
			count++;
		}
	}
	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int D;
    int N;
    cin >> D;
    cin >> N;
    if (N == 100) {
        N++;
    }
    if (D == 0) {
        cout << N << endl;
        return 0;
    }
    int result = 0;
    int toDiv = pow(100, D);
    for (int i = 1, c = 0; c < N; i++) {
        int tmp = i % toDiv;
        if (tmp == 0) {
            result = i;
            c++;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3724
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
using namespace std;
int a[110],b[110],c[110];
char x[110],y[110];
void ff(char z[110])
{
    int d=strlen(z);
    for(int i=0;i<d/2;i++)
    {
        swap(z[i],z[d-1-i]);
    }

}
int main()
{
   int n;
   scanf("%d",&n);
   while(n--)
   {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       memset(c,0,sizeof(c));
       scanf("%s",x);
       scanf("%s",y);
      ff(x),ff(y);
     for(int i=0;i<strlen(x);i++)
     {
         a[i]=x[i]-'0';
     }
     for(int i=0;i<strlen(y);i++)
     {
         b[i]=y[i]-'0';
     }
     int d=0,s;
      for(int i=0;i<110;i++)
      {
          s=a[i]+b[i]+d;
         c[i]=s%10;
         d=s/10;
      }
      int p=0;
      for(int i=109;i>=0;i--)
      {
          if(c[i])
          {
              p=i;
              break;
          }
      }
      if(p>=80)
      {
          printf("overflow\n");
         
      }
      else
        {
          for(int i=p;i>=0;i--)
          {
              printf("%d",c[i]);
          }
          printf("\n");
      }
   }
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
int t,n,m;
int arr[maxn];
#define pi cos(-1)
int main()
{
	scanf("%d",&n);
	double fin=n*1.0*2.0*3.1415926;
	printf("%.3lf\n",fin);
	return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <vector>
using namespace std;
int main(){
	int A, B, C;
	cin >> A >> B >> C;
	int kai = B / A;
	if(kai > C){
		cout << C << endl;
	}	
	else{
		cout << kai << endl;
	}
}

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

int main() {

	string S, T, U;
	cin >> S >> T;

	if (T.back() >= 'a' && T.back() <= 'z') {
		T.pop_back();
		if (T == S) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

}


Measured memory_bytes: 3624
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	vector<int> h(N,0);
	REP(i,N){
		cin >> h[i];
	}
	vector<int> dp(N, 0);

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);

	FOR(i,2,N){
		int a = dp[i-1] + abs(h[i-1] - h[i]);
		int b = dp[i-2] + abs(h[i-2] - h[i]);
		dp[i] = min(a, b);
	}

	cout << dp[N-1] << endl;

	return 0;

}


Measured memory_bytes: 1024
#c
import math

n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
orderp=0
orderq=0

for i in range(n):
  orderp+=(p[i]-1)*math.factorial(n-i-1)
  orderq+=(q[i]-1)*math.factorial(n-i-1)
  for j in range(i+1,n):
    if p[j]>p[i]:
      p[j]-=1
    if q[j]>q[i]:
      q[j]-=1
  #print(orderp,orderq)
  #print(p,q)


print(abs(orderp-orderq))

Measured memory_bytes: 9156
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int h, w, k;
    cin>>h>>w>>k;
    vector<string> v(h);
    vector<vector<int> > ans(h, vector<int>(w));
    rep(i, h) cin>>v[i];
    int cnt=1;
    set<int> zeros;
    rep(i, h){
        bool ok = false;
        rep(j, w){
            if(v[i][j]=='#') ok=true;
        }
        if(ok){
            int nowcnt=0;
            rep(j, w){
                int ki=j;
                if(i%2) ki=w-j-1;
                if(v[i][ki]=='#') {
                    nowcnt++;
                }
                ans[i][ki] = cnt+max(0, nowcnt-1);
            }
            cnt+=max(1, nowcnt);
        }
        else{
            zeros.insert(i);
        }
    }
    int nonzero;
    rep(i, h){
        if(zeros.find(i)==zeros.end()){
            nonzero=i;
            break;
        }
    }
    rep(i, nonzero){
        if(zeros.find(i)!=zeros.end()){
            rep(j, w){
                ans[i][j]=ans[nonzero][j];
            }
        }
    }
    for(int i=nonzero;i<=h-1;i++){
        if(zeros.find(i)!=zeros.end()){
            rep(j, w){
                ans[i][j]=ans[i-1][j];
            }
        }
    }
    rep(i, h){
        rep(j, w) cout<<ans[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define int long long
using namespace std;
 
const int INF = 1e15;
 
main()
{
  int N, W;
  cin >> N >> W;
 
  int dp[1000001];
  fill_n(dp, 1000001, INF);
  dp[0] = 0;
 
  for(int i = 0; i < N; i++) {
    int v, w;
    cin >> w >> v;
    for(int j = 1000000; j >= v; j--) {
      dp[j] = min(dp[j], dp[j - v] + w);
    }
  }
 
  int ret = 0;
  for(int i = 0; i < 1000001; i++) {
    if(dp[i] <= W) ret = max(ret, i);
  }
  cout << ret << endl;
}

Measured memory_bytes: 8064
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())

    ans = 0
    n_gcd = [0] * (K + 1)
    for k in reversed(range(1, K + 1)):
        n = pow(K // k, N, mod=P)
        for m in range(2, K // k + 1):
            n -= n_gcd[k * m]
        n_gcd[k] = n % P
        ans = (ans + k * n_gcd[k]) % P

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11084
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){

	string sol[100];
	int nsol;
	string inp;
	int n;
	int c;

	while(1){

		cin>>inp;
		if(inp==".") break;

		n=0;
		c=0;
		for(int i=0;i<100;i++) sol[i]="";

		for(int i=0;i<inp.size();i++){
			switch(inp[i]){
			case '+':
				c++;
				break;
			case'-':
				c--;
				break;
			case'?':
				sol[n]+='A';
				c=0;
				break;
			case'[':
				n++;
				break;
			case']':
				reverse(sol[n].begin(),sol[n].end());
				sol[n-1]+=sol[n];
				sol[n]="";
				n--;
				break;
			default:
				nsol=(inp[i]-'A'+c)%26;
				if(nsol<0) nsol+=26;
				sol[n]+=nsol+'A';
				c=0;
				break;
			}
		}

		cout<<sol[0]<<endl;

	}

	return 0;
}

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

int main(){
  int N;cin>>N;
  int V[N];
  int C[N];
  rep(i,N) cin>>V[i];
  rep(i,N) cin>>C[i];
  
  int ans=0;
  rep(i,N){
    if(V[i]>C[i]) ans += V[i]-C[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main() {
    int i, j, r, c;
    int n[101][101] = {};

    cin >> r >> c;

    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            cin >> n[i][j];
            n[i][c] += n[i][j];
            n[r][j] += n[i][j];
            n[r][c] += n[i][j];
        }
    }

    for (i = 0; i < r + 1; i++) {
        for (j = 0; j < c + 1; j++) {
            cout << n[i][j];
            if (j != c) cout << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

bool isPrime(ll n){
	if(n<=1) return 0;
	for(ll k=2;k*k<=n;k++) if(n%k==0) return 0;
	return 1;
}

const int NPrime=100000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

int l,r;

int main(){
	vi pr=EnumeratePrime();
	cin>>l>>r;
	int n=r-l+1;
	vi a(n),b(n);
	for(int i=0;i<n;i++) a[i]=l+i;
	for(auto i:pr){
		for(int j=(l+i-1)/i*i;j<=r;j+=i){
			while(a[j-l]%i==0){
				a[j-l]/=i;
				b[j-l]++;
			}
		}
	}
	for(int i=0;i<n;i++) if(a[i]>1) b[i]++;
	int res=0;
	for(int i=0;i<n;i++) if(isPrime(b[i])) res++;
	cout<<res<<endl;
}


Measured memory_bytes: 10804
# -*- coding: utf-8 -*-
"""
Created on Tue Mar  5 15:34:44 2019

@author: avina
"""

n = int(input())
L = list(map(int, input().strip().split()))
dp = [0 for i in range(n)]
dp[1] = abs(L[1] - L[0]) 
for j in range(2,n):
    for i in range(j,j+2):
        if i < n:
            dp[i] = min(dp[i-2] + abs(L[i]-L[i-2]),dp[i-1] + abs(L[i] - L[i-1]))

print(dp[-1])

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

// コンビネーション *****************
//v[n][r]に nCrの結果を格納する
// nの最大値(nmax)がわかっているなら、comb0(nmax+1, nmax/2+1)で一度comb0を実施しておけば、
// combで結果だけを使用可能

#define COMB_N 2001         // nCrのnの最大値
#define COMB_R 1001         // nCrのrの最大値
#define DIVIDE  1000000007   // 結果がDIVIDE以上の値の場合、DIVIDEで割った余りを格納

int comb_v[COMB_N + 1][COMB_R+1];

int comb0(int n, int r)
{
  int i, j;
  
  if (n<r*2) r=n-r;
  if (r<0) return 0;
  
  for (i=0; i<=n; i++) {
    comb_v[i][0] = 1;
    comb_v[i][i] = 1;
  }
  for (i=1; i<=n; i++) {
    for (j=1; j<i && j<=r; j++) {
      comb_v[i][j] = (comb_v[i-1][j-1] + comb_v[i-1][j])%DIVIDE;
    }
  }
  return comb_v[n][r];
}

int comb(int n, int r)
{
  if (n<r*2) r=n-r;
  if (r<0) return 0;
  return comb_v[n][r];
}
// **************** コンビネーション *



int main() {
  int N, K, M;
  int i, j;
  int patR, patB;
  long long int result;
  scanf ("%d %d", &N, &K);
  M=N-K; // 赤いボールの数
  
  comb0(N+1, N/2+1);
  
  for (i=1;i<=K;i++) {
    result = 0;
    
    if (i==1 && M==0) {
      printf("1\n");
      continue;
    }
    
    if (i>M+1) {
      printf("0\n");
      continue;
    }
    
    
    // i=3 の例：B,R,B,R,B 
    // Bの間にRがi-1個, Rの間にBがi-2個
    patB = comb(K-1, i-1); // K個の青いボールをi個に区切る位置の選び方
    patR = comb(M-1, i-2); // M個の赤いボールをi-2個に区切る位置の選び方
    result += ((long long int) patB * patR);
    result %= DIVIDE;
    
    // i=3 の例：B,R,B,R,B,R か R,B,R,B,R,B 
    // Bの間にRがi-1個, Rの間にBがi-1個
    patB = comb(K-1, i-1); // K個の青いボールをi個に区切る位置の選び方
    patR = comb(M-1, i-1); // M個の赤いボールをi個に区切る位置の選び方
    result += ((long long int) patB * patR * 2);
    result %= DIVIDE;
    
    // i=3 の例：R,B,R,B,R,B,R 
    // Bの間にRがi-1個, Rの間にBがi個
    patB = comb(K-1, i-1); // K個の青いボールをi個に区切る位置の選び方
    patR = comb(M-1, i  ); // M個の赤いいボールi+1個に区切る位置の選び方
    result += ((long long int) patB * patR);
    result %= DIVIDE;
    
    printf ("%lld\n", result);
  }
  

  return 0;
}




Measured memory_bytes: 8064
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int f(int x) {
	if (x <= 3) {
		return (4 - x);
	}
	return 0;
}

int main() {
	int x, y;
	cin >> x >> y;
	if (x == 1 && y == 1) {
		cout << 1000000 << endl;
	} else {
		cout << 100000 * (f(x) + f(y)) << endl;
	}
	return 0;
}


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

int main(){
  int x,y;
  cin >> x >> y;
  if(x % y == 0){
    cout << x / y << endl;
  }
  else if(x < y){
    cout << "1" << endl;
  }
  else{
    int res = x / y;
    cout << res + 1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define ll long long
#define boostUP ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fsr(i,n) for(int i=0;i<n;i++)
#define fcr(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define sz(arr) sizeof(arr)/sizeof(arr[0])

using namespace std;

int main(){
    int h,a;
    cin >> h >> a;
    int count = 0;
    while( h > 0 ){
        h = h-a;
        count++;
    }
    cout << count << endl;
}



 







 

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define mp(a, b) make_pair(a, b)
#define newline cout << endl;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(),v.end()
using namespace std;

template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p)
{
	out << '(' << p.ff << ", " << p.ss << ')';
	return out;
}

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

template <typename T> void trace(const char* name, T&& arg1) { cout << name << " : " << arg1 << endl; }

template <typename T, typename... Args> void trace(const char* names, T&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | ";
	trace(comma + 1, args...);
}

/*Input*/
/*Input*/

int main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	clock_t tStart = clock();
	int test;
	test = 1;
	// cin >> test;
	while (test--) {
            string s;
            cin >> s;
            bool f = 1;
            for(int i = 0; i < s.length(); i++){
                if(i%2==0){
                    if(s[i]=='L'){
                        f=0; break;
                    }
                } else {
                    if(s[i]=='R'){
                        f=0; break;
                    } 
                }
            }
            if(f) cout << "Yes\n";
            else cout << "No\n";
	}
#ifdef LOCAL_DEFINE
	printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args> void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  vector<vector<int> > ans(h, vector<int>(w,1));
  rep(y,b) rep(x,a) {
    ans[y][x] = 0;
  }
  for (int y = b; y < h; ++y) {
    for (int x = a; x < w; ++x) {
      ans[y][x] = 0;
    }
  }
  rep(y,h) {
    rep(x,w) {
      cout << ans[y][x];
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<pii> P;
    rep(i, 0, n) 
    {
        int p;
        cin >> p;
        P.emplace_back(p, i);
    }
    sort(P.begin(), P.end());

    int best_cnt, cnt;
    best_cnt = cnt = 1;
    rep(i, 0, n-1)
    {
        if (P[i].second < P[i+1].second)
        {
            ++cnt;
            best_cnt = max(best_cnt, cnt);
        }
        else
            cnt = 1;
    }

    cout << n - best_cnt << endl;
    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

using namespace std;
//typedef long long ll;
//typedef pair<int, int> P;
//static const int dx[4] = {1, -1, 0, 0};
//static const int dy[4] = {0, 0, 1, -1};
int main() {

    string S; cin >> S;
    vector<char> s(4);
    for (int i = 0; i < 4; i++) {
        s[i] = S[i];
    }

    sort(s.begin(), s.end());

    if (s[0] == s[1] and s[1] != s[2] and s[2] == s[3])
        cout << "Yes\n";
    else cout << "No\n";

}


Measured memory_bytes: 256
x,y=map(int,input().split())
l1=[1,3,5,7,8,10,12]
l2=[4,6,9,11]
l3=[2]

if (x in l1) and (y in l1):
    print("Yes")
elif (x in l2) and (y in l2):
    print("Yes")
else:
    print("No")

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

int main()
{
    int N;
    scanf("%d", &N);
    char S[15];
    int res = 0;
    int A = 0, B = 0, BA = 0;
    for(int i = 0; i < N; ++i) {
        scanf("%s", S);
        int len = strlen(S);
        bool Bh = S[0] == 'B';
        bool At = S[len-1] == 'A';
        if(Bh && !At) ++B;
        if(!Bh && At) ++A;
        if(Bh && At) ++BA;
        for(int i = 0; i < len-1; ++i) {
            if(S[i] == 'A' && S[i+1] == 'B') ++res;
        }
    }

    if(BA == 0) { printf("%d\n", res + min(A, B));  return 0;}
    /*
    res += (BA-1);
    if(A >= 1) res += 1, --A;
    if(B >= 1) res += 1, --B;
    res += min(A, B);
    */
    if(A + B > 0) res += BA + min(A, B);
    else res += BA - 1;
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define min(a,b) (a)<(b)?(a):(b)
int dp[50001]={0},n,m,c[20],i,j,k;
int main()
{
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
		scanf("%d",&c[i]);
	for(i=1;i<=n;i++)
		dp[i]=500000000;
	for(i=0;i<m;i++)
		for(j=0;j<=n;j++)
			if(j-c[i]>=0)
				dp[j]=min(dp[j],dp[j-c[i]]+1);
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
const int N = 3000300;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod =    1e9+7;
string s;
int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>s;
int x=s.length();
int y=0;
y=x;
y--;
int cnt=0,i=0;

while(i<y)
{
	if(s[i]!=s[y])
	cnt++;
	y--;
	i++;

}
cout<<cnt;




}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    S = IS(str)
    T = IS(str)
    if S == T[:-1]:
        print('Yes')
    else:
        print('No')


solve()


Measured memory_bytes: 9120
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int main(){
    int n,kk,p,ans=0;cin>>n>>kk;
    p=min(n,kk);
    vector<int> v(n);
    for(auto &i:v) cin>>i;
    for(int i=0;i<=p;i++){
        int t=0;
        priority_queue<int> q;
        for(int j=0;j<i;j++){
            if(v[j]<0) q.push(-v[j]);
            t+=v[j];
        }
        for(int j=0;j<=p-i;j++){
            int tt=t;priority_queue<int> qq=q;
            for(int k=0;k<j;k++){
                tt+=v[n-1-k];
                if(v[n-1-k]<0) qq.push(-v[n-1-k]);
            }
            for(int k=0;k<kk-i-j;k++) {
                if(qq.empty()) break;
                tt+=qq.top();
                qq.pop();
            }
            ans=max(ans,tt);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

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

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

int n;
std::stack<int> s;

int main(){
	std::cin >> n;
	rep(i, n){
		int a;
		std::cin >> a;
		s.push(a);
	}

	rep(i, n - 1){
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(lcm(a, b));
	}

	std::cout << s.top() << std::endl;

	return 0;
}

Measured memory_bytes: 1200
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    long[long] D;
    foreach (x; 1 .. N + 1)
    {
        auto f = factorize(x);
        foreach (key, val; f)
        {
            D[key] = D.get(key, 0) + val;
        }
    }
    long ans = 1;
    foreach (key, value; D)
    {
        ans *= value + 1;
        ans %= MOD;
    }
    writeln(ans);
}

/// 素因数分解
long[long] factorize(long x)
{
    assert(0 < x, "x is negative");
    long[long] ps;
    while ((x & 1) == 0)
    {
        x /= 2;
        ps[2] = (2 in ps) ? ps[2] + 1 : 1;
    }
    for (long i = 3; i * i <= x; i += 2)
        while (x % i == 0)
        {
            x /= i;
            ps[i] = (i in ps) ? ps[i] + 1 : 1;
        }
    if (x != 1)
        ps[x] = (x in ps) ? ps[x] + 1 : 1;
    return ps;
}


Measured memory_bytes: 380
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd(a, b) * b
n=I()
ans=lcm(2,n)
print(ans)

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

using namespace std;

#define ll long long int
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.14159265
#define pb push_back
#define bits(n) __builtin_popcount(n)

void solve()
{
    int n,r;
    cin>>n>>r;
    if(n>=10)
    cout<<r;
    else
    {
        cout<<r+(100*(10-n));
    }
    
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t=1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  set<string> s;
  ll n;
  cin >> n;
  rep(i, n){
    string t;
    cin >> t;
    s.insert(t);
  }
  print(SZ(s));
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

	int min1 = 0;
	int min0 = 0;

	rep(i, s.size())
	{
		if (s[i] == '0')
			min1++;
		else
			min0++;
	}
	cout << min(min1, min0) * 2 << endl;
	return (0);
}


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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;
    for (int i = 0; i < N; ++i) {
        // same を抜ける
        while (i+1 < N && A[i] == A[i+1]) ++i;

        // up
        if (i+1 < N && A[i] < A[i+1]) {
            while (i+1 < N && A[i] <= A[i+1]) ++i;
        }
        // down
        else if (i+1 < N && A[i] > A[i+1]) {
            while (i+1 < N && A[i] >= A[i+1]) ++i;
        }
        ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void)
{
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (auto &i: L) cin >> i;
    int now = 0;
    int i;
    for (i = 0; i < N; i++)
    {
        now += L[i];
        if (now > X) break;
    }
    cout << (i + 1) << endl;
    return 0;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int h, w, k;
	cin >> h >> w >> k;
	string z[h];
	for (int i = 0; i < h; i++) cin >> z[i];
	
	int ans{};
	for (int i = 0; i < (1 << h); i++) {
		for (int j = 0; j < (1 << w); j++) {
			int a{};
			for (int x = 0; x < h; x++) {
				if (i&(1 << x)) continue;
				for (int y = 0; y < w; y++) {
					if (j&(1 << y)) continue;
					if (z[x][y] == '#') a++;
				}
			}
			if (a == k) ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3648
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve
{   
    public static void Main()
    {
        var xab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int x = xab[0], a = xab[1], b = xab[2];
        int c = Math.Abs(x - a), d = Math.Abs(x - b);
        Console.WriteLine(c > d ? "B" : "A");
    }
}

Measured memory_bytes: 13396
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String[] line = in.nextLine().split(" ");
        final int r = Integer.parseInt(line[0]);
        final int c = Integer.parseInt(line[1]);
        final int K = Integer.parseInt(line[2]);
        final int[][] matrix = new int[r][c];
        for (int i = 0; i < K; i++) {
            line = in.nextLine().split(" ");
            final int row = Integer.parseInt(line[0]);
            final int col = Integer.parseInt(line[1]);
            final int v = Integer.parseInt(line[2]);
            matrix[row - 1][col - 1] = v;
        }
        final long[][][] dp = new long[r][c][4];
        dp[0][0][1] = matrix[0][0];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                for (int k = 0; k < 4; k++) {
                    if (i > 0) { dp[i][j][k] = Math.max(dp[i][j][k], dp[i - 1][j][k]); }
                    if (j > 0) { dp[i][j][k] = Math.max(dp[i][j][k], dp[i][j - 1][k]); }
                    if (i > 0) { dp[i][j][1] = Math.max(dp[i][j][1], dp[i - 1][j][k] + matrix[i][j]); }
                }
                for (int k = 1; k < 4; k++) {
                    if (j > 0) { dp[i][j][k] = Math.max(dp[i][j][k], dp[i][j - 1][k - 1] + matrix[i][j]); }
                }
            }
        }
        long res = 0;
        for (long ans : dp[r - 1][c - 1]) {
            res = Math.max(res, ans);
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 718232
if __name__ == '__main__':

    s = input()
    
    cnt = 0
    #check1
    r = s[::-1]
    if s == r:
        cnt += 1

    #check2
    n = len(s)
    n2 = (n-1)//2
    ss = s[:n2]
    rr = ss[::-1]
    if ss == rr:
        cnt += 1

    #check3
    n3 = (n+3) //2
    sss = s[n3-1:]
    rrr = sss[::-1]
    if sss == rrr:
        cnt += 1

    if cnt==3 :
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 9136
N, M = map(int, input().split(' '))
ac_set = set()
wa_cnt_ls, wa_cnt = [0] * N, 0

for i in range(M):
    p, s = input().split(' ')
    idx = int(p) - 1
    if not idx in ac_set:
        if s == 'AC':
            ac_set.add(idx)
            wa_cnt += wa_cnt_ls[idx]
        else:
            wa_cnt_ls[idx] += 1
print(len(ac_set), wa_cnt)

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

int a[30];

int main() {
	string s;
  	char m;
	int n;

	vector<int> a(30);

	cin >> s;

	if (s=="zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	n=s.size();
	rep(i,n) a.at(s.at(i)-'a')++;
	if(n<26){
		cout << s ;
		rep(i,26) {
			if (a.at(i)==0){
				cout << char('a'+i) << endl;
				return 0;
			}
		}
	}else{
		m=s.at(25);
		for (int i=24; i>=0; i--){
			if(s.at(i)>s.at(i+1)) continue;
			if(i>0){
				rep(j, i) cout << s.at(j);
			}
			for (int j=25; j>=0; j--){
				if(s.at(i)>s.at(j)) continue;
				cout << s.at(j) << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    int n;
    cin >> n;
    VL a(n);
    FOR(i,0,n) cin >> a.at(i);
    bool ans = true;

    FOR(i,0,n){
        if(a.at(i) % 2 == 0){
            if(a.at(i) % 3 == 0 || a.at(i) % 5 == 0){
                ans = true;
            }else{
                ans = false;
                break;
            }

            
        }
    }
    if(ans == true){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }
  

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#define N 510000
#define md 1000000007
using namespace std;
int read()
{
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
ll dp[N],sum;
int ex[N],cnt,q[N],size,l[N],r[N],n,m,tmp,i,head,tail;
struct node {int v,x;}a[N];
bool cmp(node x,node y){return x.x<y.x;}
void init()
{
	sort(ex+1,ex+1+cnt);size=unique(ex+1,ex+1+cnt)-ex-1;
	for (ll i=1;i<=n;i++) l[i]=upper_bound(ex+1,ex+1+size,l[i])-ex-1,r[i]=upper_bound(ex+1,ex+1+size,r[i])-ex-1;
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)a[i].x=read(),a[i].v=read();
	sort(a+1,a+1+n,cmp);
	for (i=1;i<=n;i++) tmp=max(tmp,a[i].v),r[i]=tmp;
	tmp=2000000000;for (i=n;i>=1;i--) tmp=min(tmp,a[i].v),l[i]=tmp;
	for (i=1;i<=n;i++) ex[++cnt]=a[i].v;
	init();
	dp[0]=1;n++;l[n]=r[n]=n;
	q[++tail]=0;sum=1;
	for (i=1;i<=n;i++) 
	{
		while (head!=tail&&r[q[head+1]]<l[i]-1) sum=(sum-dp[q[head+1]]+md)%md,head++;
		dp[i]=sum;sum=(sum+dp[i])%md;
		q[++tail]=i;
	}
	printf("%lld\n",dp[n]%md);
}

Measured memory_bytes: 14080
# -*- coding: utf-8 -*-
x1, y1, x2, y2 = map(int, input().split())
x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x1 - (y2-y1)
y4 = y1 + (x2-x1)
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include<stdio.h>

int main(){
	
	int i,n,a[100];

	scanf("%d",&n);

	for(i=0;i<n;i++){
	
		scanf("%d",&a[i]);
	
	}

	for(i=n-1;i>=0;i--){
		
		if(i==0){
		printf("%d\n",a[i]);
		}

		else {
		printf("%d ",a[i]);
		}
	}

return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define sf(x) scanf("%d",&x);
#define pf(x); printf("%d\n",x);
using namespace std;
int main()
{
    long long int a,b,x,t=1,y;
    cin>>a>>b;
    x=max(a,b);
    y=min(a,b);
    while(t)
    {
        if((x*t)%y==0)
        {
            cout<<x*t;
            break;
        }
        t++;
  }
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

bool IsPrime[300000];
int sum[300000];
int main() {
    //cout.precision(10);
    cin.tie(0);
    for(int i = 2; i <= 250000; i++) IsPrime[i] = true;
    ios::sync_with_stdio(false);
    for(int i = 2; i <= 250000; i++) {
        if(!IsPrime[i]) continue;
        //cerr << i << endl;
        for(int j = i * 2; j <= 250000; j += i) IsPrime[j] = false;
    }
    for(int i = 2; i <= 250000; i++) {
        sum[i] = sum[i-1];
        if(IsPrime[i]) sum[i]++;
    }
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        cout << sum[2 * n] - sum[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 4360
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		int N;

		cin >> N;
		if (cin.fail()) break;

		int p[5]{};
		while (N--) {
			string s;
			cin >> s;
			switch (s[0]) {
			case 'M': p[0]++; break;
			case 'A': p[1]++; break;
			case 'R': p[2]++; break;
			case 'C': p[3]++; break;
			case 'H': p[4]++; break;
			}
		}
		ll result = 0;
		for (int i = 0; i < 1 << 5; i++) {
			bitset<5> bs(i);
			if (bs.count() != 3) continue;
			ll t = 1;
			for (int j = 0; j < 5; j++) {
				if (bs[j]) t *= p[j];
			}
			result += t;
		}
		cout << result << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int n;
int x,y,h1,h2,d1,d2,s1,s2;
  
double dist(int a, int b){
    return sqrt(a*a+b*b+0.0);
}  
int main(){
    while(1){
		bool ok=true;
        cin >> n;
        if(n == 0) break;
        cin >>h1>>h2>>d1>>d2>>s1>>s2;
		if(dist(h1-s1,h2-s2)>= dist(d1-s1,d2-s2))ok=false;
        for(int i=1;i<n;i++){
            cin>>x>>y;
			if(dist(h1-s1,h2-s2)+dist(s1-x,s2-y) >= dist(d1-x,d2-y))ok=false;
        }
  
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 2964
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int nam[4];
    for(int i=0; i<4; i++) cin >> nam[i];
    int big=max(nam[0],nam[2]);
    int sma=min(nam[1],nam[3]);
    cout << max(0,sma - big) << '\n';
    return 0;
}

Measured memory_bytes: 256