akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e15);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}


int main(){
    fastio;
    //clock_t tm = clock();
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vl p(a),q(b),r(c);
    f(i,0,a)cin>>p[i];
    f(i,0,b)cin>>q[i];
    f(i,0,c)cin>>r[i];
    sort(all(p));
    sort(all(q));
    sort(all(r));
    vi z;
    fd(i,a-1,max(0ll,a-x))z.pb(p[i]);
    fd(i,b-1,max(0ll,b-y))z.pb(q[i]);
    fd(i,c-1,max(0ll,c-x-y))z.pb(r[i]);
    sort(all(z),greater<ll>());
    ll ans=0;
    f(i,0,min(x+y,ll(size(z)))){
        ans+=z[i];
    }
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 4852
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int S = sc.nextInt();
        sc.close();

        int ans = 0;
        for (int i = 0; i <= K; ++i) {
            for (int j = 0; j <= K; ++j) {
                if (S - i - j >= 0 && S - i - j <= K) {
                    ans++;
                } 
            }
        }

        System.out.println(ans);
	}
}


Measured memory_bytes: 22100
/*

TimeLimit:8sec,Memory Limit:Limit:262144KB,isSolved:-
水ようかん(Mizuyoukan)
<問題文>
水ようかんとは，おもに小豆からなる餡を型に流し込んで寒天で固めることにより作られる和菓子である．
いま，JOI 君の手元には，横長の直方体の形をした水ようかんがひとつある．
JOI 君は，今日のおやつとしてこの水ようかんを食べる予定である．
この水ようかんには，縦方向の切れ目が全部で N−1 箇所に入っている．水ようかんの長さは 
L1+L2+…+LN であり，i 番目 (1≦i≦N−1) の切れ目は，左から L1+L2+…+Li の位置にある．
この水ようかんは丸ごと食べるには大きすぎるので，
JOI 君は，水ようかんに入っている切れ目から 1 箇所以上を選び，
選んだ切れ目に沿って水ようかんを切って，複数のピースに切り分けることにした．
ただし，ピースの大きさが不揃いでは見栄えが悪いので，
長さ最大のピースと最小のピースの長さの差ができるだけ小さくなるように切ることにした．
長さ最大のピースと最小のピースの長さの差の最小値を求めよ．
<制約>
2≤N≤50
1≤Li≤1000(1≤i≤N)
<入力>
入力は以下の形式で標準入力から与えられる．
N
L1
L2
:
LN
<出力>
長さ最大のピースと最小のピースの長さの差の最小値を 1 行で出力せよ．
*/
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
const int INF=(int)1e9;
int solve(const int low,const vector<int>& ls)
{
	const int n=ls.size();
	vector<int> dp(n+1);
	dp[0]=low;
	for(int position=0;position<n;position++){
		int piece_length=0;
		int& value=dp[position+1];
		value=INF;
		for(int piece_left=position;piece_left>=0;piece_left--){
			piece_length+=ls[piece_left];
			if(position==n-1&&piece_left==0){
				continue;
			}
			if(piece_length>=low){
				const int high=max(piece_length,dp[piece_left]);
				value=min(value,high);
			}
		}
	}
	return dp[n]-low;
}
int main(void)
{
	int n;
	vector<int> ls;
	cin>>n;
	ls.resize(n);
	for(int i=0;i<n;i++){
		cin>>ls[i];
	}
	int answer=INF;
	for(int left=0;left<n;left++){
		int total_length=0;
		for(int right=left;right<n;right++){
			total_length+=ls[right];
			int temp=solve(total_length,ls);
			answer=min(answer,temp);
		}
	}
	cout<<answer<<endl;
	return 0;
}


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

int main() {
	int N, check;
	cin >> N;
	check = N % 10;
	if (check == 3) {
		cout << "bon" << endl;
		return 0;
	}
	else if (check == 0 || check == 1 || check == 6 || check == 8) {
		cout << "pon" << endl;
		return 0;
	}
	else {
		cout << "hon" << endl;
		return 0;
	}

	return 0;
}

Measured memory_bytes: 3624
import math
N = int(input())
ls1 = []
ls2 = []
for i in range(N):
    ls1.append(list(map(int,input().split())))
x = 0
y = 0
for i in range(N):
    for j in range(i+1,N):
        x = (ls1[i][0]-ls1[j][0])**2
        y = (ls1[i][1]-ls1[j][1])**2
        XY = math.sqrt(x+y)
        ls2.append(XY)
if len(ls2) == 1:
    print(ls2[0])
else:
    ans = sum(ls2)*2/N
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
#else
#define DE(...) 0
void debug(...) {}
#endif
const int maxn = 2003, inf = 1e9;
int n, a[maxn], x;
int v[maxn<<1];
void ch(int &v, int val) { v = min(v, val) ; }
void chmin(int l, int r, int val) {
	l += n, r += n;
	for (;l < r;l>>=1, r>>=1) {
		if (l&1) ch(v[l++], val);
		if (r&1) ch(v[--r], val);
	}
}
int query(int i) {
	int res = inf;
	for (i+=n;i;i>>=1)
		ch(res, v[i]);
	return res;
}
ll cal(ll len) {
	fill(v, v+n+n, inf);
	ll res = (len-1) * x;
	for (int i = 0;i < n;++i) {
		int l = i - len + 1, r = i;
		DE(l, ' '), DE(r, '\n');
		if (l < 0) {
			chmin(0, r+1, a[i]);
			chmin(l+n, n, a[i]);
		}
		else chmin(l, r+1, a[i]);
	}
	for (int i = 0;i < n;++i)
		res += query(i), DE(query(i), '\n');
	DE(len, ' '), DE(res, '\n');
	return res;
}
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> x;
	for (int i = 0;i < n;++i)
		cin >> a[i];
	ll res = LLONG_MAX;
	for (int i = 1;i <= n;++i)
		res = min(res, cal(i));
	cout << res << '\n';
}


Measured memory_bytes: 3620
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
//const int mod = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	int cnt = 0;
	rep(i, 1, s.size()) {
		if (s[i] != s[i - 1]) { cnt += 1; }
	}
	print(cnt);
}

Measured memory_bytes: 512
integer N
real(8),allocatable,dimension(:)::v
read*,N
allocate(v(N))
read*,v
call heapsort(n,v)
do i=1,N-1
  v(i+1)=(v(i)+v(i+1))/2.0
end do

print"(f0.10)",v(i)

contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  real(8),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  real(8):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

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

using namespace std;

int main()
{
	string s;
	int a[100005];
	int n, q, bb, cc;

	cin >> n >> q;
	cin >> s;

	a[0] = 0;
	for(int i = 0; i < n-1; i++)
	{
		if(s[i]=='A' and s[i+1]=='C') a[i+1] = a[i]+1;
		else a[i+1] = a[i];
	}

	//for(int i = 0; i < n; i++) cout << a[i] << endl;

	for(int i = 0; i < q; i++)
	{
		cin >> bb >> cc;

		int ans = a[cc-1] - a[bb-1];

		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;


struct BipartiteMatching {
	int V;
	vector<vector<bool> > G;
	vector<int> match;
	vector<bool> used;

	BipartiteMatching(int v) {
		V = v;
		G = vector<vector<bool> >(v, vector<bool>(v));
		match = vector<int>(v);
		used = vector<bool>(v);
	}

	void add_edge(int v, int u) {
		G[v][u] = G[u][v] = true;
	}

	bool dfs(int v) {
		used[v] = true;
		for(int i = 0; i < V; i++) {
			if(!G[v][i]) continue;
			int u = i, w = match[u];
			if(w < 0 || (!used[w] && dfs(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}

	int calc() {
		int res = 0;
		fill(match.begin(), match.end(), -1);
		for(int v = 0; v < V; v++) {
			if(match[v] < 0) {
				fill(used.begin(), used.end(), false);
				if(dfs(v)) {
					res++;
				}
			}
		}
		return res;
	}
};

typedef pair<int, int> Pii;

int h, w;
string C[100];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

bool exist(int i, int j) {
	if(0 <= i && i < h && 0 <= j && j < w) return C[i][j] == '#';
	return false;
}

struct line {
	int x1, y1, x2, y2;
};

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

	while(cin >> h >> w, h) {
		for(int i = 0; i < h; i++) {
			cin >> C[i];
		}

		bool G[101][101][4] = { { 0 } };
		bool E[101][101] = { { 0 } };
		vector<Pii> p;
		for(int i = 0; i < h + 1; i++) {
			for(int j = 0; j < w + 1; j++) {
				G[i][j][0] = exist(i - 1, j) && exist(i, j);
				G[i][j][1] = exist(i, j - 1) && exist(i, j);
				G[i][j][2] = exist(i - 1, j - 1) && exist(i, j - 1);
				G[i][j][3] = exist(i - 1, j - 1) && exist(i - 1, j);
				if(exist(i, j) + exist(i - 1, j) + exist(i, j - 1) + exist(i - 1, j - 1) == 3) {
					E[i][j] = true;
					p.emplace_back(j, i);
				}
			}
		}


		vector<line> tate, yoko;
		for(int y = 0; y < h + 1; y++) {
			for(int x = 0; x < w + 1; x++) {
				if(!E[y][x]) continue;
				for(int k = 0; k < 2; k++) {
					int ny = y, nx = x;
					if(!G[ny][nx][k]) continue;
					do {
						ny += dy[k];
						nx += dx[k];
					} while(!E[ny][nx] && G[ny][nx][k]);
					if(E[ny][nx]) {
						if(k % 2 == 1) tate.push_back(line{ x, y, nx, ny });
						else yoko.push_back(line{ x, y, nx, ny });
					}
				}
			}
		}

		int N = tate.size(), M = yoko.size();
		BipartiteMatching bp(N + M);
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < M; j++) {
				line t = tate[i], y = yoko[j];
				if(t.y1 <= y.y1 && y.y1 <= t.y2 && y.x1 <= t.x1 && t.x1 <= y.x2) {
					bp.add_edge(i, N + j);
				}
			}
		}

		int match = bp.calc();
		cout << p.size() - (N + M - match) + 1 << endl;
	}
}

Measured memory_bytes: 6376
#include <iostream>
#include <vector>

int main()
{
    int N; std::cin >> N;

    int A, B;

    long long count = 0;

    for (int A=1; A<N; A++)
    {
        if (N % A == 0)
        {
            count += N / A - 1;
        }
        else count += N / A;
    }

    std::cout << count << std::endl;
}

Measured memory_bytes: 3624
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define N 100005
#define int long long
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1 == p2)?EOF:*p1++)
using namespace std ;
//char buf[(1 << 22)] , *p1 = buf , *p2 = buf ;
inline int read ()
{
    char c = getchar () ; int x = 0 , f = 1 ;
    while (c < '0' || c > '9') { if (c == '-') f = -1 ; c = getchar () ; }
    while (c >= '0' && c <= '9'){ x = x * 10 + c - '0' ; c = getchar () ; }
    return x * f ;
}
int n , m , ver[N << 1] , nxt[N << 1] , hed[N] , tot , ans[N] , Dis[N] ;
struct as {
	int v , d , c ;
} a[N] ;
void add (int x , int y) { ver[++ tot] = y ; nxt[tot] = hed[x] ; hed[x] = tot ; }
void dfs (int x , int col , int dis)
{
	if (! ans[x]) ans[x] = col ;
	if (! dis || Dis[x] >= dis) return ;
	Dis[x] = dis ;
	for (int i = hed[x] ; i ; i = nxt[i])
	{
		int y = ver[i] ;
		dfs (y , col , dis - 1) ;
	}
}
signed main ()
{
	n = read () , m = read () ;
	for (int i = 1 , u , v ; i <= m ; u = read () , v = read () , add (u , v) , add (v , u) , i ++) ;
	int q = read () ;
	for (int i = 1 ; i <= q ; i ++) a[i].v = read () , a[i].d = read () , a[i].c = read () ;
	for (int i = q ; i >= 1 ; i --) dfs (a[i].v , a[i].c , a[i].d) ;
	for (int i = 1 ; i <= n ; i ++) printf ("%d\n" , ans[i]) ;
}
/*
7 7
1 2
1 3
1 4
4 5	
5 6
5 7
2 3
2
6 1 1
1 2 2
*/

Measured memory_bytes: 8448
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		String t = sc.next();
		int n = sc.nextInt();
		int cnt = 0;
		for(int i=0;i<n;i++) {
			String s = sc.next();
			for(int j=0;j<10;j++) {
				boolean flg = true;
				for(int k=0;k<t.length();k++) {
					if( t.charAt(k) != s.charAt((j+k)%10) )
						flg = false;
				}
				if( flg ) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    ll n;
    cin >> n;
    vector<string> s(n);
    set<string> ss;
    REP(i,n)cin >> s[i];
    REP(i,n){
        ss.insert(s[i]);
    }

    ll ans = ss.size();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 25084
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#define dMAX 1000000
using namespace std;

int n;
int p[200],pSize, vSize;
int dp1[dMAX];
int dp2[dMAX];
int i,j;


int main(){

  for( pSize=0; pSize<200 ; pSize++ ){
    p[pSize]= pSize*(pSize+1)*(pSize+2)/6;
  }
  

  fill_n( dp1,dMAX,INT_MAX );
  fill_n( dp2,dMAX,INT_MAX );

  dp1[0]=0;
  for( i=1;i<pSize;i++){
    for( j=p[i];j<dMAX;j++ )
      dp1[j] = min( dp1[j],dp1[ j-p[i] ]+1 );
  }

  dp2[0]=0;
  for( i=1;i<pSize;i++){
    if( p[i] & 0x01 ){
      for( j=p[i];j<dMAX;j++ )
	dp2[j] = min( dp2[j],dp2[ j-p[i] ]+1 );
    }
  }

  while( cin>>n && n )
    cout << dp1[ n ] << " " << dp2[ n ] << endl;

  return 0;
}

Measured memory_bytes: 8560
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		var r = rl();
		Console.WriteLine(3 * r * r);
	}

	public Sol(){
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#![allow(dead_code, unused_variables)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        p: [f64;n],
    }

    let mut dp = vec![vec![0.0 ; n+2];n+2];
    dp[0][0] = 1.0;
    for i in 0..n{
        for j in 0..=i+1{
            if j == 0{
                dp[i+1][j] = dp[i][j] * (1.0 - p[i]);
            }else{
                dp[i+1][j] = dp[i][j-1] * p[i] + dp[i][j] * (1.0 - p[i]);
            }
        }
    }

    let mut ans = 0.0;
    let semi = (n + 1)/2;
    for i in semi..=n{
        ans += dp[n][i]; 
    }
    println!("{:.10}",ans);
}


Measured memory_bytes: 72584
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define ld long double
#define inf 1000000000
using namespace std;
#define N 200005
#define lc (o<<1)
#define rc (o<<1|1)
int n,m,b[N],sum,mi[N<<2],tg[N<<2];
struct node{ int l,r; }a[N];
const bool cmp(const node &x,const node &y){ return x.l<y.l; }
void down(int o){
	if (!tg[o]) return;
	mi[lc]+=tg[o]; mi[rc]+=tg[o]; tg[o]=0;
}
void up(int o){ mi[o]=min(mi[lc],mi[rc]); }
int qrymin(int o,int l,int r,int x,int y){
	if (x<=l && r<=y) return mi[o];
	down(o); int mid=l+r>>1,ret=inf;
	if (x<=mid) ret=min(ret,qrymin(lc,l,mid,x,y));
	if (y>mid) ret=min(ret,qrymin(rc,mid+1,r,x,y));
	return ret;
}
void modify(int o,int l,int r,int x,int val){
	if (l==r){ mi[o]=val; return; }
	down(o); int mid=l+r>>1;
	if (x<=mid) modify(lc,l,mid,x,val);
	else modify(rc,mid+1,r,x,val); up(o);
}
void add(int o,int l,int r,int x,int y,int val){
	if (x<=l && r<=y){ tg[o]+=val,mi[o]+=val; return; }
	down(o); int mid=l+r>>1;
	if (x<=mid) add(lc,l,mid,x,y,val);
	if (y>mid) add(rc,mid+1,r,x,y,val); up(o);
}
int main(){
	scanf("%d",&n);
	rep (i,1,n) scanf("%d",&b[i]),sum+=!b[i];
	scanf("%d",&m);
	rep (i,1,m) scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+1+m,cmp); int po=1;
	memset(mi,127,sizeof(mi)); modify(1,0,n,0,0);
	rep (i,1,n){
		//f[i][j]表示前i个数已经确定，最后一个1在第j位，最小的(0,1)-(0,0)。一位一位确定。
		while (po<=m && a[po].l<=i){
			modify(1,0,n,a[po].r,qrymin(1,0,n,0,a[po].r));//f[i][r]=min{f[i-1][k]}(k<=r);
			po++;
		}
		add(1,0,n,0,i-1,b[i]?1:-1);
	}
	printf("%d\n",mi[1]+sum);
	return 0;
}

Measured memory_bytes: 8960
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int N,M,K,A,B,C,ans=0,cnt=0;
string S,T;
vector<int> P,Q;
vector<pair<int,int>> PP;
bool CAN=false;


int main(){
  cin>>N>>M;
  int X[M+1],Y[M+1],num[N+1];
  bool red[N+1];
  
  RREP(i,N){
    num[i]=1;
    red[i]=false;
  }
  
  red[1]=true;
  
  RREP(i,M) cin>>X[i]>>Y[i];
  
  RREP(i,M){
    if(red[X[i]]){
      red[Y[i]]=true;
    }
    num[X[i]]--;
    num[Y[i]]++;
    if(num[X[i]]==0) red[X[i]]=false;
  }
  
  RREP(i,N) if(red[i]) ans++;
  
  cout<<ans<<endl;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int m,t,p,r;
	while(cin>>m>>t>>p>>r){
		if(m==0) break;
		int mm,tt,pp,j;
		int ac[t+1],wa[t+1][p+1],pen[t+1];
		for(int i=0;i<=t;i++){
			ac[i]=0;
			pen[i]=0;
			for(int j=0;j<=p;j++){
				wa[i][j]=0;
			}
		}
		for(int i=0;i<r;i++){
			cin>>mm>>tt>>pp>>j;
			if(j!=0){
				wa[tt][pp]++;
			}
			else{
				ac[tt]++;
				pen[tt]=pen[tt]+wa[tt][pp]*20+mm;
				wa[tt][pp]=0;
			}
		}
		int ctct=0;
		for(int i=1;i<=t;i++){
			int acmax=-1,penmin;
			for(int j=t;j>=1;j--){
				if(ac[j]>acmax){
					acmax=ac[j];
					penmin=pen[j];
				}
				else if(ac[j]==acmax){
					penmin=min(penmin,pen[j]);
				}
			}
			int ct=0;
			if(acmax==-1) break;
			else if(ctct>0) cout<<",";
			ctct++;
			for(int j=t;j>=1;j--){
				if(acmax==ac[j]&&penmin==pen[j]){
					if(ct>0) cout<<"=";
					cout<<j;
					ac[j]=-2;
					pen[j]=0;
					ct++;
				}
			}
		}
		cout<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#define INF 10000000
using namespace std;

int main(){
  int n,x[302][302]={},y[302][302]={};
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];

  /*  for(int i=0;i<300;i++)
    for(int j=0;j<300;j++) y[i][j]=x[i][j]=-1;
    n=300;*/
  
  for(int i=0;i<n;i++)
    for(int j=n-2;j>=0;j--) {
      x[i][j]+=x[i][j+1];
      y[j][i]+=y[j+1][i];
    }

  int ans=max(y[0][n-1],y[n-1][0]),sum,K[302][302]={},t=0,f=1;
  while(f){
    t++,f=0;
    for(int i=0;i<n;i++) //yoko
      for(int j=i+1;j<n;j++) {//yoko
	int a=K[i][j],nk=a;
	sum=-INF;
	for(int k=a+1;k<n;k++) { //tate
	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);
	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);
	  if(sum<=X+Y)sum=X+Y,nk=k;
	}
	ans=max(ans,sum);
	
	if(nk!=n-1)f=1;
	for(int k=a+1;k<nk;k++){//tate
	  sum+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);
	  ans=max(ans,sum);
	  }
	K[i][j]=nk;
      }
  }
  cout <<ans<<endl;
	  
  return 0; 
}

Measured memory_bytes: 2236
import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    H,W,K = map(int, input().split())
    C = np.zeros((H,W), dtype='int8')
    for h in range(H):
        s = input()
        for i in range(len(s)):
            if s[i] == '.':
                C[h,i] = 0
            else:
                C[h,i] = 1

    t2 = 0
    count = 0
    while t2 < 2**(H+W):
        t = t2
        h = []
        w = []
        for i in range(H+W):
            if t&1 == 1:
                if i < H:
                    h += i,
                else:
                    w += (i-H),
            t = t >> 1
        a = np.delete(np.delete(C, h, 0), w, 1)
        c = np.count_nonzero(np.delete(np.delete(C, h, 0), w, 1))
        if c == K:
            count += 1
        t2+=1

    print(count)


main()


Measured memory_bytes: 27312
package main

import (
	"bufio"
	"fmt"
	"os"
	"regexp"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	N := next()

	r := regexp.MustCompile(`[a-z]`)
	r2 := regexp.MustCompile(`[A-Z]`)

	if r.Match([]byte(N)) {
		fmt.Println("a")
	} else if r2.Match([]byte(N)) {
		fmt.Println("A")
	}
}

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

int main() {
	int n;
	cin >> n;
	int a = n % 10;
	if (a == 0 || a == 1 || a == 6 || a == 8) cout << "pon";
	else if (a == 3)cout << "bon";
	else cout << "hon";
}


Measured memory_bytes: 3636
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto hw = readints;
    int h = hw[0];
    for (int i = 0; i < h; i++) {
        string s = read!string;
        writeln(s);
        writeln(s);
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint N,X,Y;
    cin >> N >> X >> Y;
    X--,Y--;
    lint ans[N]={};
    lint edge=Y-X-1;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++){
        lint dis=j-i;
        lint comp=abs(i-X)+1+abs(j-Y);
        dis=min(dis,comp);
        ans[dis]++;
    }
    rep(i,N-1) cout << ans[i+1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[1000005];
void solve(){
    string s;
    cin>>s;
    ll res=0,n=ll(s.length()),pre[n+2];
    pre[n+1]=0;
    for(ll i=n;i>=1;i--)
    pre[i]=9+pre[i+1]-ll(s[i-1]-'0');
    set<ll> st;
    st.insert(0);
    for(ll i=n;i>=1;i--){
        dp[i]=dp[i+1]+ll(s[i-1]-'0');
        dp[i]=min(dp[i],2+pre[i]+(*st.begin()));
        //cout<<dp[i]<<endl;
        st.insert(dp[i]-pre[i]);
    }
    cout<<dp[1];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t=1;
    for(ll i=0;i<t;i++)
    solve();
}


Measured memory_bytes: 63772
def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


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

MOD = 998244353
modFacts, invs = prepare(2 * N)
ans = 0
for k in range(K + 1):
    num = N - k
    cnt = 1
    if num >= 0:
        cnt *= modFacts[N - 1] * invs[N - 1 - (num - 1)] * invs[num - 1]
        cnt %= MOD
        cnt *= M * pow(M - 1, num - 1, MOD)
        cnt %= MOD
    ans += cnt
    ans %= MOD

print(ans)


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

bool isPrime(ll x)
{
    if(x<=1)
    return false;
    
    for(ll i=2;i*i<=x;i++)
    if(x%i==0)
    return false;
    return true;
}

int main() {
   
   ll x;
   cin>>x;
   
   while(!isPrime(x))
   x++;
   
   cout<<x;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 20000

typedef struct __area_each_ {
  int cur, area;
} __area_each_t;

int main() {
  int cur = 0, stack1_size = 0, stack1[MAX], stack2_size = 0, area_all = 0;
  __area_each_t stack2[MAX];
  char c;
  while (scanf("%c", &c)) {
    int f = 0;
    cur++;
    switch (c) {
      case '\\':
        stack1[stack1_size] = cur;
        stack1_size++;
        break;
      case '/':
        if (stack1_size) {
          area_all += (cur - stack1[--stack1_size]);
          __area_each_t area_each;
          area_each.cur = stack1[stack1_size];
          area_each.area = cur - stack1[stack1_size];
          while (stack2_size) {
            if (stack1[stack1_size] < stack2[stack2_size - 1].cur) {
              stack2_size--;
              area_each.area += stack2[stack2_size].area;
            }
            else {
              break;
            }
          }
          stack2[stack2_size] = area_each;
          stack2_size++;
        }
        break;
      case '_':
        break;
      case '\n':
      default:
        f = 1;
        break;
    }
    if (f)
      break;
  }
  printf("%d\n", area_all);
  int i;
  printf("%d", stack2_size);
  for (i = 0; i < stack2_size; i++) {
    printf(" %d", stack2[i].area);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <algorithm>
using namespace std;
const int N_MAX = 200000;

int main() {
	int n;
	int A[N_MAX], B[N_MAX];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i] >> B[i];
	}
	sort(A, A+n);
	sort(B, B+n);
	long long ans;
	if (n % 2 == 0) {
		int l = n / 2 - 1;
		ans = (B[l] + B[l+1]) - (A[l] + A[l+1]) + 1;
	} else {
		int l = (n+1) / 2 - 1;
		ans = B[l] - A[l] + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5160
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007

#define par pair<int, int>
#define maxn 505

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

int n;
char s[maxn],s1[maxn];

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    cin >> s >> s1;


    for(int i=0;i<n;i++)
        cout << s[i] << s1[i];




}


Measured memory_bytes: 256
// ConsoleApplication11.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <algorithm>

using namespace std;

long long a[100005], b[100005], c[200005], n, ans, suma = 0, sumb = 0, qzh[100005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[i] = a[i];
		c[i + n] = b[i];
		suma += a[i];
		sumb += b[i];
	}
	sort(c, c + 2 * n);
	ans = min(suma, sumb);
	qzh[0] = c[0];
	for (int i = 1; i < n; i++) {
		qzh[i] = qzh[i - 1] + c[i];
	}
	for (int i = 0; i < n; i++) {
		long long x = a[i], y = b[i];
		if (x > y)
			swap(x, y);
		if (lower_bound(c, c + 2 * n, x) - c <= n - 2) {
			if (lower_bound(c, c + 2 * n, y) - c <= n - 1) {
				ans = min(ans, qzh[n - 1]);
			}
			else {
				ans = min(ans, qzh[n - 2] + y);
			}
		}
		else {
			ans = min(ans, qzh[n - 3] + x + y);
		}
	}
	cout << ans << endl;
	return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件


Measured memory_bytes: 4096
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
A.sort()
ans = 0
max_A = max(A)
dp = [True]*(max_A+1)  # 0~max(A)の数についてのリスト
happend = set()
for a in A:
    if C[a] >= 2:
        if a in happend:
            continue
        else:
            # aが存在したという証拠だけは残しておく
            x = a * 2
            while x <= max_A:
                dp[x] = False
                x += a
            happend.add(a)
    else:
        if dp[a]:
            ans += 1
        x = a * 2
        while x <= max_A:
            dp[x] = False
            x += a
print(ans)


Measured memory_bytes: 38340
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)
#define P pair<long int, long int>

vector<P> prime;

long int gcd(long int x, long int y){
    if(y == 0) return x;
    return gcd(y, x % y);
}

void factorize(long int x){
    long int num = x;
    for (long int i = 2; i * i <= x; i++){
        if (num % i == 0){
            P p;
            p.first = i;
            p.second = 0;
            while(num % i == 0){
                p.second++;
                num /= i;
            }
            prime.push_back(p);
        }
    }
    if (num > 1){
        P p;
        p.first = num;
        p.second = 1;
        prime.push_back(p);
    }
}

int main(){
    long int a, b;
    cin >> a >> b;
    long int n = gcd(a, b);
    factorize(n);
    cout << prime.size() + 1 << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int X;
int Y;
int C[10][10];
int A;
int main(){
  int Lj4PdHRW, i, k;
  int res = 0;
  rd(X);
  rd(Y);
  for(i=(0);i<(10);i++){
    int j;
    for(j=(0);j<(10);j++){
      rd(C[i][j]);
    }
  }
  for(k=(0);k<(10);k++){
    for(i=(0);i<(10);i++){
      int j;
      for(j=(0);j<(10);j++){
        chmin(C[i][j], C[i][k] + C[k][j]);
      }
    }
  }
  for(Lj4PdHRW=(0);Lj4PdHRW<(X*Y);Lj4PdHRW++){
    rd(A);
    if(A >= 0){
      res += C[A][1];
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// int X, Y, C[10][10], A;
// {
//   int res = 0;
//   rd(X,Y);
//   rep(i,10) rep(j,10) rd(C[i][j]);
//   rep(k,10) rep(i,10) rep(j,10) C[i][j] <?= C[i][k] + C[k][j];
//   rep(X*Y){
//     rd(A);
//     if(A >= 0) res += C[A][1];
//   }
//   wt(res);
// }


Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
    if i == 0:
        if a[0] != 0:
            print("-1")
            exit()
    else:
        if a[i] >= a[i-1]+2:
            print("-1")
            exit()
a += [a[-1]]
a.reverse()

ans = 0
for i in range(1,n):
    if a[i] >= a[i-1]:
        ans += a[i]
print(ans)





Measured memory_bytes: 57688
using System;

namespace _0565
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] pasta = new int[3];
            int[] juice = new int[2];
            for (int i = 0; i < 3; i++)
            {
                pasta[i] = int.Parse(Console.ReadLine());
            }
            for (int i = 0; i < 2; i++)
            {
                juice[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(pasta);
            Array.Sort(juice);
            Console.WriteLine((pasta[0] + juice[0] - 50).ToString());
        }
    }
}

Measured memory_bytes: 9244
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, K; cin >> n >> K;
    string in; cin >> in;
    vi a(n); rep(i, n) a[i] = in[i] - '0';

    bool is_one = true;
    int cnt = 0;
    vi sum = {0};
    rep(i, n){
        if(is_one ^ a[i]){
            sum.emplace_back(cnt);
            cnt = 1;
            is_one ^= true;
        }
        else {
            cnt++;
        }
    }
    sum.emplace_back(cnt);

    if(not is_one){
        sum.emplace_back(0);
    }

    int m = sum.size();
    rep(i, 1, m){
        sum[i] += sum[i-1];
    }

    int res = 0;
    rep(i, 1, m){
        if(i % 2 == 0) continue;

        int ni = min(m-1, i+2*K);
        int cur = sum[ni] - sum[i-1];
        chmax(res, cur);
    }
    
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1404
#include <iostream>
using namespace std;
int n,m;
char s[100000],t[100000];

int gcd(int x,int y){
    if(x>y){
        x+=y;
        y=x-y;
        x-=y;
    }if(x==0) return y;
    return gcd(y%x,x);
}

int main(){
    cin>>n>>m;
    int g=gcd(n,m);
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<m;i++)cin>>t[i];
    n/=g; m/=g;
    for(int i=0;i<g;i++){
        if(s[n*i]!=t[m*i]){
            cout<<-1;
            return 0;
        }
    }
    cout<<(long long)n*m*g;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  int dp[101][4][4][4]={0}; //ACGT
  rep(i,0,4){
    rep(j,0,4){
      rep(k,0,4) dp[3][i][j][k]=1;
    }
  }
  dp[3][0][2][1]=0;
  dp[3][0][1][2]=0;
  dp[3][2][0][1]=0;
  REP(i,4,N){
    rep(j,0,4){
      rep(k,0,4){
        rep(l,0,4){
          rep(m,0,4){
            dp[i][j][k][l]+=dp[i-1][k][l][m];
            dp[i][j][k][l]%=MOD;
          }
        }
      }
    }
    dp[i][0][2][1]=0;
    dp[i][0][1][2]=0;
    dp[i][2][0][1]=0;
    dp[i][0][2][0]=(dp[i][0][2][0]+MOD-dp[i-1][2][0][1])%MOD;
    dp[i][0][2][1]=(dp[i][0][2][1]+MOD-dp[i-1][2][1][1])%MOD;
    dp[i][0][2][2]=(dp[i][0][2][2]+MOD-dp[i-1][2][2][1])%MOD;
    dp[i][0][2][3]=(dp[i][0][2][3]+MOD-dp[i-1][2][3][1])%MOD;
  }
  int ans=0;
  rep(i,0,4){
    rep(j,0,4){
      rep(k,0,4){
        ans+=dp[N][i][j][k];
        ans%=MOD;
      }
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
#!/usr/bin/env python3
#AGC28 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

n,m = map(int,sys.stdin.readline().split())
s = input()
t = input()
l = lcm(n,m)
a,b = n//gcd(n,m),m//gcd(n,m)
for i in range(min(n//a,m//b)):
    if s[a*i] != t[b*i]:
        print(-1)
        quit()
print(l)


Measured memory_bytes: 39792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef queue<ll> ql;
typedef set<ll> sl;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 500010;
ll num, M, N, ans=0, count=0, sum=0;
int main() {
    ll X;
    cin >> X;

    N = X/500;
    sum += N*1000;
    X %= 500;
    N = X/5;
    sum += N*5;

    cout << sum << endl;
    return 0;
}


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


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int count = 0;
  rep(i,n) {
    if (h[i] >= k) ++count;
  }
  cout << count << endl;
  return 0;
}

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

using namespace std;


int fact(int n)
{
	if (n == 1)
		return 1;
	return n * fact(n-1);
}

int main(void)
{
	int n;
	cin >> n;
	int x[n], y[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	long double sum = 0.0;
	vector<int> numbers(n);
	for (int i = 0; i < n; i++)
		numbers[i] = i;

	do {
		for (int i = 1; i < n; i++) {
			sum += sqrt((long double)((x[numbers[i]]-x[numbers[i-1]])*(x[numbers[i]]-x[numbers[i-1]]) +
						(y[numbers[i]]-y[numbers[i-1]])*(y[numbers[i]]-y[numbers[i-1]])));
		}
	} while (next_permutation(numbers.begin(), numbers.end()));
	sum /= (long double)fact(n);
	printf("%20.20Lf\n", sum);
	return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <map>
#include <set>
#include <algorithm>
#include <stack>

using namespace std;

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vll> vvl;
typedef pair<ll, ll> pll;
typedef pair<string, ll> psl;
typedef vector<psl> vpsl;
typedef vector<pll> vpl;
typedef unordered_set<ll> usl;
typedef set<ll> sl;
typedef unordered_map<ll, ll> uml;
typedef map<ll, ll> ml;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

#define all(v) v.begin() , v.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll inf = 1e9 + 7;
const double pie = 3.14159265358979323846;
const char nl = '\n';

template<typename Type>
istream &operator>>(istream &in, vector<Type> &v)
{
    ll n = v.size();
    for (int i = 0; i < n; i++)
        in >> v[i];
    return in;
}

template<typename Type>
ostream &operator<<(ostream &out, vector<Type> &v)
{
    for (auto value : v)
        out << value << " ";
    out << endl;
    return out;
}

void solve()
{
    ll n;
    cin >> n;
    vector <double> p(n + 1);
    for (ll i = 1; i <= n; ++i)
        cin >> p[i];
   vector<vector<double>> dp (n + 1, vector <double>(n + 1, 0.0));
    dp[0][0] = 1.0;
    for (ll i = 1; i <= n; ++i)
    {
        for (ll j = 0; j <= i; ++j)
        {
            if (j == 0)
                dp[i][j] = (1.0 - p[i]) * dp[i - 1][j];
            else
                dp[i][j] = (p[i] * dp[i - 1][j - 1]) + (1.0 - p[i]) * dp[i - 1][j];
        }
    }
//    for (const auto& v : dp)
//    {
//        for (float i : v)
//            cout << i << ' ';
//        cout << nl;
//    }
    double ans = 0.0;
    for (ll j = 0; j <= n; ++j)
    {
        if (j > n - j)
            ans += dp[n][j];
    }
    printf("%.10f\n", ans);
}

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

Measured memory_bytes: 73768
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    int ans = 0;
    REP(i,n) {
        while(v[i] % 2 == 0) {
            ans++;
            v[i] /= 2;
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,l;
char li[100][101];
int a[100];
int le(int x,int y){
int k=0;
  while(k<l){
  if(li[x][k]<li[y][k])return 1;
  if(li[x][k]>li[y][k])return 0;
    k++;
  }
  return 0;
}
void q(int s,int t){
int p=a[s],i=s,j=t;
if(s<t){
while(1){
while(le(a[i],p))i++;
while(le(p,a[j]))j--;
if(i>=j)break;
a[i]^=a[j]^=a[i]^=a[j];
i++;j--;
}
q(s,i-1);q(j+1,t);
}  
}
int main(){
  int i;
  scanf("%d %d",&n,&l);
  for(i=0;i<n;i++){scanf("%s",li[i]);a[i]=i;}
  q(0,n-1);
  for(i=0;i<n;i++)printf("%s",li[a[i]]);
}


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

int main(){
	int n,ans=0;
  	string s;
  	cin >> n >> s;
  	for (int l=0;l<n-1;l++){
    	set<char> k,m;
    	int maxi=0;
  		for (int i=0;i<=l;i++){
    		k.insert(s[i]);
  		}
  		for (int j=l+1;j<n;j++){
    		m.insert(s[j]);
        }
  		for (char j='a';j<='z';j++){
    		if(k.count(j)==1 && m.count(j)==1) maxi++;
    	}
    	ans = max(ans, maxi);
  	}
  	cout << ans << endl; 
}

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

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

using namespace std;

const int N = 3010;
const int INF = 1e9;

int n, t;
pair<int, int> a[N];
int dp[N][N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> t;
    for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1);
    for (int i = 0; i <= n; i++) for (int j = 0; j < t; j++) dp[i][j] = -INF;
    dp[0][0] = 0;
    int res = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < t; j++) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
            int foo = dp[i - 1][j] + a[i].second;
            res = max(res, foo);
            if (j + a[i].first < t) dp[i][j + a[i].first] = max(dp[i][j + a[i].first], foo);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>

using namespace std;

int main(void) {
  int n, minv, maxv = -1000000000;
  int ary[200000];

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> ary[i];

    if (i == 0) {
      minv = ary[0];
      continue;
    }

    if (ary[i] - minv > maxv) maxv = ary[i] - minv;
    if (ary[i] < minv) minv = ary[i];
  }

  cout << maxv << endl;

  return 0;
}

Measured memory_bytes: 3860
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define inf 200000000000
const int maxnodes=1005;
#define ll long long
#define N 101
#define EPS 0.01
#define ld long double


bool comp(pair<int,int> p1,pair<int,int> p2)
{
    if(p1.first != p2.first)
        return p1.first > p2.first;
    else
        return p1.second < p2.second;
}
int32_t main()
{
    IOS;

    int n,m;
    cin >> n >> m;
    vector<int> g[m+1];
    vector<pair<int,int>> v(n);
    for(int i = 0;i < n;i++)
    {
        cin >> v[i].second >> v[i].first;
        // if(v[i].first <= m)
        //     g[m-v[i].first+1].push_back(v[i].second);
    }
    multiset<int> s;
    for(int i = 1;i <= m;i++)
        s.insert(i);
    sort(v.begin(),v.end(),comp);
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        multiset<int>::iterator it = s.lower_bound(v[i].second);
        if(it != s.end())
        {
            ans += v[i].first;
            s.erase(it);
        }
    }
    cout << ans;
   

}   

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  int cnt = 0;
  while (true) {
    for (int i = 0; i < n; i++) {
      if (a.at(i) % 2 == 0) a.at(i) /= 2;
      else {
        cout << cnt << endl;
        return 0;
      }
    }
    cnt++;
  }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    map<string, int> m;
    vs v;
    bool test = false;
    char a;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        if(!v.empty()){
            if(s[0]!=a) test = true;
        }
        v.pb(s);
        m[s]++;
        a = s[s.size()-1];
    }
    if(test){
        cout << "No";
        return 0;
    }
    else{
        map<string, int> ::iterator it;
        for(it = m.begin(); it != m.end(); it++){
            if(it->second > 1){
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
}   

Measured memory_bytes: 256