akhauriyash/Code-Regression huggingface dataset:
paper = [[0 for i in range(10)] for j in range(10)]
while True :
    try :
        x, y, s = map(int, input().split(","))
        
        paper[x][y] += 1
        if x > 0 :
            paper[x-1][y] += 1
        if y > 0 :
            paper[x][y-1] += 1
        if x < 9 :
            paper[x+1][y] += 1
        if y < 9 :
            paper[x][y+1] += 1

        if s > 1 :
            if x > 0 :
                if y > 0 :
                    paper[x-1][y-1] += 1
                if y < 9 :
                    paper[x-1][y+1] += 1
            if x < 9 :
                if y > 0 :
                    paper[x+1][y-1] += 1
                if y < 9 :
                    paper[x+1][y+1] += 1
        if s > 2 :
            if x > 1 :
                paper[x-2][y] += 1
            if y > 1 :
                paper[x][y-2] += 1
            if x < 8 :
                paper[x+2][y] += 1
            if y < 8 :
                paper[x][y+2] += 1
                
    except EOFError :
        break


S = 0
M = 0
for i in range(10) :
    for j in range(10) :
        if paper[i][j] == 0 :
            S += 1
        if paper[i][j] > M :
            M = paper[i][j]
        
print(S)
print(M)


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main() {
    int n;
    cin >> n;
    map<char, int> mp;
    rep(i, n) {string str; cin >> str; mp[str[0]]++; }
    int a[5] = {0};
    a[0] = mp['M']; a[1] = mp['A']; a[2] = mp['R']; a[3] = mp['C']; a[4] = mp['H'];
    ll ans = 0;
    
    int bit = (1 << 3) - 1;
    for (;bit < (1 << 5); bit = next_combination(bit)) {
        // out(bit);
        ll tmp = 1;
        rep(j, 5) {
            if (bit & (1 << j)) {
                tmp *= a[j];
            }
        }
        ans += tmp;
    }
    out(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

#define P 1000000007

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> v, cnt;
  v.resize(n);
  cnt.resize(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  unsigned long long ans = 0, a = 0;
  while(true) {
    a = 0;
    for(int i = 0; i < n; i++) {
      ans += v[i] / n;
      a += v[i] / n;
      cnt[i] = v[i] / n;
    }
    for(int i = 0; i < n; i++) {
      v[i] = v[i] % n + a - cnt[i];
    }
    if(a == 0) {
      cout << ans << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        vector<int> n(3, 0);
        for(int i=0; i<6; ++i){
            int a;
            cin >> a;
            n[i%3] += a;
        }
        if(n[0] + n[1] + n[2] == 0)
            return 0;

        int ret = 0;
        for(int i=0; i<3; ++i){
            if(n[i] > 0){
                -- n[i];
                ret += n[i] / 3;
                n[i] %= 3;
                ++ n[i];
            }
        }

        sort(n.begin(), n.end());
        vector<bitset<3> > bs(3);
        for(int i=0; i<3; ++i){
            for(int j=0; j<n[i]; ++j)
                bs[i][j] = true;
        }

        int a = 0;
        int b = 0;
        for(int i=0; i<3; ++i){
            if(bs[i][0] && bs[i][1] && bs[i][2])
                ++ a;
            if(bs[0][i] && bs[1][i] && bs[2][i])
                ++ b;
        }
        ret += max(a, b);

        cout << ret << endl;
    }
}

Measured memory_bytes: 904
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, W = MAP()

v, w = [0]*N, [0]*N
for i in range(N):
	v[i], w[i] = MAP()
dp = [0]*(W+1)
for i in range(N):
	for j in range(W, w[i]-1, -1):
		dp[j] = max(dp[j], dp[j-w[i]]+v[i])

print(dp[W])



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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main()
{
     fast;
    int n,k;
    cin>>n>>k;
    int arr[n];
    int freq[62];
    for(int i=0;i<62;i++)
     freq[i]=0;
    for(int i=0;i<n;i++)
    {
     cin>>arr[i];
     int x=arr[i];
     for(int p=0;p<62;p++)
     {
         if(((int)1<<p)&x)
         {
             freq[p]++;
         }
     }
    }
    int sum=0;
    int no=0;
    for(int i=61;i>=0;i--)
    {
        if(freq[i]>=(n+1)/2)
        {
            sum+=(((int)1<<i)*freq[i]);
        }
        else
        {
            if(k>=((int)1<<i)+no)
            {
                no|=((int)1<<i);
                sum+=((int)1<<i)*(n-freq[i]);
            }
            else
             sum+=(((int)1<<i)*freq[i]);
        }
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int X,A,B;

	scanf("%d %d %d",&X,&A,&B);

	int num_query;
	scanf("%d",&num_query);

	char command[10];

	for(int loop = 0; loop < num_query; loop++){

		scanf("%s",command);

		switch(command[0]){
		case 'n':

			X += A;
			break;

		case 't':

			X += B;
			break;

		case 'k':

			X = 0;
			break;
		}

		X = max(0,X);
	}

	printf("%d\n",X);

	return 0;
}



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

int main(void){
	using namespace std;
	string s;
	int ss = 0, max = -1;
	cin >> s;
	for(auto&&c :s){
		if( c == 'A' || c == 'C'|| c=='G' ||c=='T')
			ss++;
		else{
			if(max < ss)
				max = ss;
			ss = 0;
		}
	}
	if(max < ss)
		max = ss;
	cout <<max <<endl;
	return 0;
}


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

using namespace std;

char mp[41][45];
int n;
long long dp[42][42][42][42],dp2[42][42][42][42];

long long calc_dp2(int l,int r,int ll,int rr) ;
long long calc_dp(int l,int r,int ll,int rr) ;

long long calc_dp(int l,int r,int ll,int rr)
{
	if(dp[l][r][ll][rr] != -1) return dp[l][r][ll][rr];
	//do something plz
	dp[l][r][ll][rr] = 0;
	for(int p = l;p <= r; ++ p)
		for(int q = ll;q <= rr; ++ q)
			dp[l][r][ll][rr] += (mp[p][q] - '0') * calc_dp2(l,p - 1,p + 1,r) * calc_dp2(ll,q - 1,q + 1,rr);
	return dp[l][r][ll][rr];
}

long long calc_dp2(int l,int r,int ll,int rr)
{
	if(dp2[l][r][ll][rr] != -1) return dp2[l][r][ll][rr];
	//also do something plz
	dp2[l][r][ll][rr] = 0;
	for(int p = l;p <= r; ++ p)
		for(int q = ll;q <= rr; ++ q)
			dp2[l][r][ll][rr] += calc_dp(l,p,q,rr) * calc_dp2(p + 1,r,ll,q - 1);
	return dp2[l][r][ll][rr];
}

int main()
{
	scanf("%d",&n); n *= 2;
	for(int i = 1;i <= n; ++ i)
		scanf("%s",mp[i] + 1);
	memset(dp,-1,sizeof(dp)); memset(dp2,-1,sizeof(dp2));
	for(int i = 1;i <= n + 1; ++ i) for(int j = 1;j <= n + 1; ++ j) dp[i][i - 1][j][j - 1] = dp2[i][i - 1][j][j - 1] = 1;
	long long as = 0;
	for(int i = 2;i <= n; ++ i)
		if(mp[1][i] == '1')
			as += calc_dp2(2,i - 1,i + 1,n);
	printf("%lld\n",as);
}

Measured memory_bytes: 52400
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


typedef vector<vector<ll>> mat;

// 行列A*Bの計算
mat mulmod(mat &A, mat&B){
    mat C((int)A.size(), vector<ll>((int)B.size()));
    for(int i=0; i<(int)A.size(); ++i){
        for(int j=0; j<(int)B[0].size(); ++j){
            for(int k=0; k<(int)B.size(); ++k){
                C[i][j] += A[i][k] * B[k][j];
                chmod(C[i][j]);
            }
        }
    }
    return C;
}

// A^nの計算
mat matrixpowmod(mat A, ll n){
    mat B((int)A.size(), vector<ll>((int)A.size(), 0));
    for(int i=0; i<(int)A.size(); ++i) B[i][i] = 1;

    while(n>0){
        if(n&1) B = mulmod(B, A);
        A = mulmod(A, A);
        n >>= 1;
    }
    return B;
}


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

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

    mat A(n, vector<ll>(n));
    rep(i, n) rep(j, n) cin >> A[i][j];

    mat B = matrixpowmod(A, k);
    ll ans = 0;
    rep(i, n) rep(j, n) ans += B[i][j], chmod(ans);
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
  #define MAX 500000

  int H,A[MAX+1];

  void swap(int *a ,int *b){
  	int	temp;
  	temp = *a;
  	*a = *b;
  	*b = temp;
  }
  int Left(int i){
    return 2*i;
  }
  int Right(int i){
    return 2*i+1;
  }

  void maxH(int i){
    int l,r,larg;
    l=Left(i);
    r=Right(i);

    if(l<=H && A[l]>A[i])larg=l;
    else larg=i;
    if(r<=H && A[r]>A[larg])larg=r;
    if(larg!=i){
      swap(&A[i],&A[larg]);
      maxH(larg);
    }
  }

  int main(){
    int i;
    scanf("%d",&H);
    for(i=1;i<=H;i++)scanf("%d",&A[i]);
    for(i=H/2;i>=1;i--)maxH(i);
    for(i=1;i<=H;i++)printf(" %d",A[i]);
    printf("\n");

    return 0;
  }

Measured memory_bytes: 2552
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

const int MAX = 10000000;

signed main() {
        int n;
        cin >> n;
        vector<int> x(n);
        for(int i = 0; i < n; i++) cin >> x[i];

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

        int ans = MAX;
        for(int i = x[0]; i <= x[n - 1]; i++) {
                int sum = 0;
                for(int j = 0; j < n; j++) {
                        int dist = pow(i - x[j], 2);
                        sum += dist;
                }
                ans = min(ans, sum);
        }

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

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 998244353;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<vector<vector<ll>>> dp(c+1,vector<vector<ll>>(d+1,vector<ll>(2,0)));
    dp[a][b][0]=1;
    for(ll i=a+1;i<=c;i++){
        dp[i][b][0] = (dp[i - 1][b][0] + dp[i - 1][b][1]) * b;
        dp[i][b][0] %= MOD;
        dp[i][b][1] = (dp[i][b - 1][0] + dp[i][b - 1][1]) * i;
        dp[i][b][1] %= MOD;
    }
    for(ll j=b+1;j<=d;j++){
        dp[a][j][0] = (dp[a - 1][j][0] + dp[a - 1][j][1]) * j;
        dp[a][j][0] %= MOD;
        dp[a][j][1] = (dp[a][j - 1][0] + dp[a][j - 1][1]) * a;
        dp[a][j][1] %= MOD;
    }
    for(ll i=a+1;i<=c;i++){
        for(ll j=b+1;j<=d;j++){
            dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1])*j;
            dp[i][j][0]%=MOD;
            dp[i][j][1] = dp[i][j-1][0] + (dp[i][j-1][1]) * i;
            dp[i][j][1] %= MOD;
        }
    }
    cout<<(dp[c][d][0]+dp[c][d][1])%MOD<<"\n";
}

Measured memory_bytes: 496060
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,x,y,xx,yy,ans;
int f[N];
int find(int x)
{
	if (f[x]==x) return x;
	return f[x]=find(f[x]);
}
	
int main(){
	scanf("%d%d",&n,&m);
	for (register int i=1; i<=n; ++i) f[i]=i;
	for (register int i=1; i<=m; ++i)
	{
		scanf("%d%d",&x,&y);
		xx=find(x); yy=find(y);	
		f[xx]=yy;
	}
	for (register int i=1; i<=n; ++i) if (find(i)==i) ans++;
	printf("%d\n",ans-1);
return 0;	
}

Measured memory_bytes: 4216
#include <iostream>
#include <cstring>
#include <algorithm>
#include <sstream>

using namespace std;


typedef long long ll;

ll combi(ll n){
  ll res=1;

  for(ll i=0;i<n;i++){
    res*=2;
  }
  return res;
}

ll nzyuuzyou(ll n){
  ll beki=1;
  for(ll i=0;i<n;i++){
    beki*=10;
  }
  return beki;
}
int main()
{
    string s;
    cin >> s;

    ll imp=s.size();
    ll ans=0;

    for(ll i=1;i<=imp;i++){
      ll temp=0;
      for(ll j=0;j<imp-i;j++){
        temp+=(s[j]-'0')*combi(imp-(i+1));
        //cout<<"temp="<<temp<<endl;
      }
      temp+=(s[imp-i]-'0')*combi(imp-i);
      //cout<<"temp="<<temp<<endl;
      ans+=temp*nzyuuzyou(i-1);
      //cout<<"ans="<<ans<<endl;
    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
int nmax=200000;
vvec g(nmax);

ll ans=INF;
int m;
void saiki(vec idx,vvec &a,vector<bool> f){
    vector<int> mp(m);
    int n=idx.size();
    rep(i,n){
        mp[a[i][idx[i]]]++;
    }
    vec sa;
    int ma=0;
    rep(i,m) chmax(ma,mp[i]);
    chmin(ans,ma);
    rep(i,m){
        if(ma==mp[i]) sa.pb(i);
    }
    vec next=idx;
    for(int k:sa){
        f[k]=true;
        rep(i,n){
            while(f[a[i][next[i]]]){
                next[i]++;
                if(next[i]==m) return;
            }
        }        
    }
    saiki(next,a,f);
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n>>m;
    vvec a(n,vec(m));
    rep(i,n) rep(j,m) cin>>a[i][j],a[i][j]--;
    vec idx(n);
    vector<bool> f(m,false);
    saiki(idx,a,f);
    
    cout<<ans<<endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

vector<ll> G[1010];
vector<ll> X(1010);
ll dp[1010][5050];

pll dfs(ll now, ll par){
	//dump(now)
	vector<pll> cand;
	ll K = 0;
	REP(i, G[now].size()){
		ll next = G[now][i];
		if(next==par) continue;
		K++;
		pll tmp = dfs(next, now);
		cand.push_back(tmp);
	}
	REP(i, K+1)REP(j, 5050) dp[i][j] = 0;
	dp[0][0] = 1;
	ll total = 0;
	REP(i, K){
		total += cand[i].first;
		total += cand[i].second;
		REP(j, 5050){
			if(dp[i][j]<1) continue;
			if(j+cand[i].first<5050) dp[i+1][j+cand[i].first] = 1;
			if(j+cand[i].second<5050) dp[i+1][j+cand[i].second] = 1;
		}
	}
	ll res = -1;
	REP(i, X[now]+1) if(dp[K][i]>0) res = i;
	if(res == -1){
		cout << "IMPOSSIBLE" << endl;
		exit(0);
	}else{
		ll nokori = total - res;
		return {X[now], nokori};
	}
}

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

    ll N;
    cin >> N;
    REP(i, N-1){
    	ll P;
    	cin >> P;
    	P--;
    	G[i+1].push_back(P);
    	G[P].push_back(i+1);
    }
    REP(i, N) cin >> X[i];

    dfs(0, -1);
    cout << "POSSIBLE" << endl;


    return 0;
}

Measured memory_bytes: 39808
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	vector<vector<int>> dp(n,vector<int>(3)),a(n,vector<int>(3));
	for(int i=0;i<n;i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
	dp[0] = a[0];
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(j!=k) dp[i][j] = max(dp[i][j],dp[i-1][k]+a[i][j]);
			}
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 14084
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
       string s1;
       string s2,s3;
       cin>>s1;
       cin>>s2;
       if(s1.size()>=s2.size())
       {
           cout<<"No";
           return 0;
       }
       int i,j;
       int f=1;
       for(i=0;i<s1.size();i++)
       {
           if(s1[i]!=s2[i]){
            f=0;
            break;
           }
       }
       if(f)
       {
           cout<<"Yes";
       }
       else{
        cout<<"No";
       }


}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
  int  N;
  cin >>  N;
  int size = 2*N;
  int arr[size];
  for(int i=0;i<size;i++)
    cin>>arr[i];
  sort(arr,arr+size);
  int s=0;int i=0;bool flag=true;
  while(flag)
  {
    s+=min(arr[i],arr[i+1]);
    i=i+2;
    if(i==size)
      flag=false;
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
lr=[tuple(map(int,input().split())) for i in range(k)]
mod=998244353
dp=[0]*n
dp[0]=1
s=0
for i in range(n):
  s+=dp[i]
  for l,r in lr:
    if i+l<n:
      dp[i+l]=(dp[i+l]+s)%mod
    if i+r+1<n:
      dp[i+r+1]=(dp[i+r+1]-s)%mod
print(dp[n-1])

Measured memory_bytes: 16720
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,li[310][310],pos[310][310];
ll s=0;

int main(){
	cin >> n;
	REP(i,0,n) REP(j,0,n) cin >> li[i][j],pos[i][j]=li[i][j];
	REP(k,0,n) REP(i,0,n) REP(j,0,n) pos[i][j]=min(pos[i][j], pos[i][k]+pos[k][j]);
	REP(i,0,n) REP(j,0,n) if(li[i][j]!=pos[i][j]){cout << -1 << endl; return 0;}
	REP(i,0,n){
		REP(j,i+1,n){
			bool f=true;
			REP(k,0,n) if(k!=i and k!=j and li[i][k]+li[k][j]==li[i][j]) f=false;
			if(f) s+=li[i][j];
		}
	}
	
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

int main(){
   int N, X;
   std::cin >> N >> X;
   int L;
   int x = 0;
   int ans = 1;
   for(int i=0; i<N; ++i){
      std::cin >> L;
      x += L;
      if(x<=X) ++ans;
   }
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 256
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
r = L[K-1]
print(r)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int n;
int h[100000];
int main(){
    cin >> n;
    bool ans = true;
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    if(n==1){
        ans = true;
    }
    for(int i=(n-1);i>0;i--){
        if(h[i-1] >h[i]){
            if(h[i-1] == 0){
                ans = false;
            }
            else{
                h[i-1] = h[i-1]-1;
                if(h[i-1] > h[i]){
                ans = false;
            }
            }
            
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

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

int main() {
    int N;
    cin >> N;
    if (N % 1000 == 0) {
        cout << 0 << endl;
    } else {
        cout << 1000 - N % 1000 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3628
s = input()
s0 = int(s[0])
s1 = int(s[1])
s2 = int(s[2])

if s0 == s1 and s1 == s2:
    print(int(s))
elif s1 == s0:
    if s0 > s2:
        print("".join([str(s0)] * 3))
    else:
        print("".join([str(s0+1)] * 3))
elif s1 > s0:
    print("".join([str(s0+1)] * 3))
elif s1 < s0:
    print("".join([str(s0)] * 3))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

pi normalize(int y, int x, int n)
{
    if(y>=n/2) y = n-1-y;
    if(x>=n/2) x = n-1-x;
    return {y,x};
}

int main()
{
    int C,n;
    cin >>C >>n;
    --C;

    vector<vector<int>> p(n,vector<int>(n));
    rep(i,n)
    {
        string tmp;
        cin >>tmp;
        rep(j,n) p[i][j] = tmp[j]-'0';
    }

    set<pi> s;

    vector<vector<int>> ct(n/2,vector<int>(n/2));
    rep(i,n/2)rep(j,n/2)
    {
        ct[i][j] += p[i][j];
        ct[i][j] += p[i][n-1-j];
        ct[i][j] += p[n-1-i][j];
        ct[i][j] += p[n-1-i][n-1-j];

        if(ct[i][j]!=0 && ct[i][j]!=4) s.insert({i,j});
    }

    int ans = 0;
    if(s.empty()) ++ans;

    while(C--)
    {
        // dbg(vector<pi>(all(s)));
        int D;
        cin >>D;
        while(D--)
        {
            int r,c;
            cin >>r >>c;
            --r;
            --c;

            pi pos = normalize(r,c,n);

            if(p[r][c]==0) ++ct[pos.fi][pos.se];
            else --ct[pos.fi][pos.se];
            p[r][c] = !p[r][c];

            if(ct[pos.fi][pos.se]==0 || ct[pos.fi][pos.se]==4) s.erase(pos);
            else s.insert(pos);
        }

        if(s.empty()) ++ans;
    }

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

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

int main(void) {
    int h, w;
    cin >> h >> w;
    bool black;
    string answer = "Yes";

    string board[50];

    for (int i = 0; i < h; ++i) cin >> board[i];

    const int dx[4] = {1, 0, -1, 0};
    const int dy[4] = {0, 1, 0, -1};

    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (board[i][j] == '#') {
          black = false;
          for (int d = 0; d < 4; ++ d) {
            const int ni = i + dy[d];
            const int nj = j + dx[d];

            if (ni < 0 or h <= ni) continue;
            if (nj < 0 or w <= nj) continue;
            if (board[ni][nj] == '#') black = true;
          }
        if(black == false) answer = "No";
        }
      }
    }
  cout << answer << endl; 
}

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

int main() {
    long long N, K;
    cin >> N >> K;

    if (K & 2 != 0) {
        long long a = N / K;
        cout << a * a * a << endl;
    } else {
        long long a1 = N / K;
        long long a2 = N / (K / 2) - a1;
        cout << a1 * a1 * a1 + a2 * a2 * a2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>

using namespace std;

int main()
{
      string s ,t , str;
      cin >> s >> t;
      if(s == t)
            {
                  cout << "Yes";
                  return 0;
            }

      for(int j=0 ; j< s.size(); j++)
      {
            str = s[s.size() -1];
            for(int i=0 ; i<s.size()-1 ; i++)
            {
                  str += s[i];
            }
            s = str;
            if(s == t)
            {
                  cout << "Yes";
                  return 0;
            }
      }

      cout << "No";



      return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
li = []
del_r = []
del_c = []
for i in range(h):
    li.append(list(input()))
    #print(i)
    
    for j in range(w):
        if li[i][j] == '#':
            break
            
        if li[i][j] == '.' and j == w-1:
            del_r.append(int(i))

for j in range(w):
    for i in range(h):
        if li[i][j] == '#':
            break
        if li[i][j] == '.' and i == h-1:
            del_c.append(int(j))
            
#print(del_r)
#print(del_c)

for i in range(h):
    if i in del_r:
        continue
    for j in range(w):
        if j in del_c:
            continue
        print(li[i][j], end="")
    print("")
            

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int a, b;
  string s;
  cin >> a >> b >> s;
  bool ok = true;
  for(auto c : s.substr(0, a)) if(c < '0' || c > '9') ok = false;
  if(s[a] != '-') ok = false;
  for(auto c : s.substr(a+1, b)) if(c < '0' || c > '9') ok = false;

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,m;
	cin>>n>>m;
	priority_queue<ll> que;
	for(int i=0;i<n;i++){
		ll a;
		cin>>a;
		que.push(a);
	}
	for(int i=0;i<m;i++){
		ll b=que.top();
		que.pop();
		que.push(b/2);
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ans+=que.top();
		que.pop();
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

const int MOD = 998244353;
const int MAX_N = 2000010;

int64_t fa[MAX_N];  // n! mod MOD
int64_t fb[MAX_N];  // n!^(MOD - 2) mod MOD ≡ 1 / n!

int64_t modpow(int64_t base, int64_t k, int64_t mod) {
  base %= mod;
  int64_t answer = 1;
  while (k > 0) {
    if (k & 1) answer = (answer * base) % mod;
    base = (base * base) % mod;
    k >>= 1;
  }
  return answer;
}

// nCk =  n! / (k! * (n - k)!)
//     ≡ n! * k!^(MOD-2) * (n-k)!^(MOD-2) mod MOD
int64_t nCk(int64_t n, int64_t k, int64_t mod) {
  if (n == 0 || k == 0) return 1;
  if (n < 0 || k < 0) return 0;
  int64_t answer = fa[n];
  answer = answer * fb[k] % mod;
  answer = answer * fb[n - k] % mod;
  return answer;
}

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  N--;

  fa[0] = 1;
  fb[0] = 1;
  for (int i = 0; i + 1 < MAX_N; i++) {
    fa[i + 1] = fa[i] * (i + 1) % MOD;
    fb[i + 1] = fb[i] * modpow(i + 1, MOD - 2, MOD) % MOD;
  }

  int64_t answer = 0;
  for (int k = 0; k <= K; k++) {
    int64_t tmp = (M * nCk(N, k, MOD)) % MOD;
    tmp = tmp * modpow(M - 1, N - k, MOD) % MOD;
    answer = (answer + tmp) % MOD;
  }

  cout << answer % MOD << endl;

  return 0;
}


Measured memory_bytes: 34896
#include<bits/stdc++.h>
using namespace std;
#define file {freopen("i.txt","r",stdin);freopen("o.txt","w",stdout);}
#define ios {ios_base::sync_with_stdio(false);cin.tie(NULL);}
typedef long long ll;
typedef long double ld;
typedef pair<long ,long> pll; 	
const ll mod=1e9+7;

ll count(ll a, ll b, ll c){
  return(a*a+b*b+c*c+a*b+b*c+c*a);
}

int main(){
	ios;
  ll N,ans=0; cin>>N;
  //for(ll n=1; n<=N; n++){
  ll i=1, j=1, k=1;
for(ll n=1; n<=N; n++){
  for(ll i=int(sqrt(n)) ;i>0; i--){
    for(ll j=i; j>0; j--){
      for(ll k=j; k>0; k--){

       //  cout<<i<<" "<<j<<" "<<k<<endl;
       // cout<<n<<" "<<count(i,j,k)<<endl;


        if(count(i,j,k)==n){
         // cout<<"ohya"<<endl;

          if((i>j && j>k)){
            ans+=6;
          }else if(( i>j && j==k) || (i==j && j>k)){
            ans+=3;
          }else{
            ans+=1;
          }
          //cout<<ans<<endl;


        }
      }
    }
  }


  cout<<ans<<endl;
  ans=0;
  i=1; j=1; k=1;
  }

//}
	//return 0;
} 


Measured memory_bytes: 3588
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int h,w,ans;
string s,t;

main(){
	int n;
	cin>>h>>w>>n;
	int sy,sx;cin>>sy>>sx;
	cin>>s>>t;
	int y=sy,x=sx;
	rep(i,n){
		if(s[i]=='U'){
			y--;
			if(y==0){
				dump("NO");
				return 0;
			}
		}
		if(t[i]=='D'){
			if(y!=h)y++;
		}
		//cerr<<'('<<y<<','<<x<<')'<<' ';
	}
	y=sy,x=sx;
	//cerr<<endl;
	rep(i,n){
		if(s[i]=='R'){
			x++;
			if(x==w+1){
				dump("NO");
				return 0;
			}
		}
		if(t[i]=='L'){
			if(x!=1)x--;
		}
		//cerr<<'('<<y<<','<<x<<')'<<' ';
	}
	y=sy,x=sx;
	//cerr<<endl;
	rep(i,n){
		if(s[i]=='D'){
			y++;
			if(y==h+1){
				dump("NO");
				return 0;
			}
		}
		if(t[i]=='U'){
			if(y!=1)y--;
		}
		//cerr<<'('<<y<<','<<x<<')'<<' ';
	}
	y=sy,x=sx;
	//cerr<<endl;
	rep(i,n){
		if(s[i]=='L'){
			x--;
			if(x==0){
				dump("NO");
				return 0;
			}
		}
		if(t[i]=='R'){
			if(x!=w)x++;
		}
		//cerr<<'('<<y<<','<<x<<')'<<' ';
	}
	//cerr<<endl;
	dump("YES");
}





Measured memory_bytes: 776
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
  int n;
  cin >> n;
  long long int sum=0;
  long long int ans;
  long long int a[200001]={};
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum += a[i];
  }

  sum -= 2*a[0];
  ans = max(sum,-sum);
  for(int i=1;i<n-1;i++){
    sum -= 2*a[i];
    if(ans > max(sum,-sum))
      ans = max(sum,-sum);
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    vpl red(n),blue(n);
    set<P> rse,bse;
    rep(i,n){
        cin >> red[i].second >> red[i].first;
    }
    rep(i,n){
        cin >> blue[i].first >> blue[i].second;
    }
    ll ans = 0;
    sort(all(blue));
    sort(rall(red));
    rep(i,n){
        rep(j,n){
            if(blue[i].first>red[j].second && blue[i].second>red[j].first){
                ans++;
                red[j].first = INF;
                red[j].second = INF;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()
csum=[0]*len(s)
for i in range(len(s)):
    if i<len(s)-1:
        if s[i]=='A' and s[i+1]=='C':
            csum[i+1]=csum[i]+1
        else:
            csum[i+1]=csum[i]

for i in range(q):
    l,r=map(int,input().split())
    print(csum[r-1]-csum[l-1])

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

const ll INF = 1LL<<60;

int main(){

    int K, A, B;
    cin >> K >> A >> B;

    bool ans = false;
    for (int i = A; i<= B; i++){
        if (i % K == 0){
            ans = true;
            break;
        }
    }

    if (ans){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }

}


Measured memory_bytes: 3592
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let s: String = read!();
    let s = s.chars().collect_vec();
    let mut b = true;
    b = b && s[0]=='A';
    
    b = b && s[2..s.len()-1].contains(&'C');
    
    b = b && s.iter().filter(|c| c.is_uppercase()).count() == 2;
    
    let ans = if b {"AC"}else{ "WA"};
    println!("{}", ans);
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    
    if ( ceil(n / 1.08)*1.08 < n+1){
        cout << ceil(n / 1.08) << endl;
    }
    else{
        cout << ":(" << endl;
    }
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define TESTCASES 0

using namespace std;

int n;

int Go(){

  scanf("%d",&n);

  ll sum = 0;

  for(int i = 1 ; i <= n ; ++i)
    if(i % 3 && i % 5) sum += (ll) i;

  printf("%lld\n",sum);

  return 0;
}


int main(){

  int t;
  if(TESTCASES) scanf("%d",&t); 
  else          t = 1;
  
  while(t--) Go();
} 

Measured memory_bytes: 3816
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let h :: hs = reads int |> List.rev
    let rec loop x = function
        | [] -> "Yes"
        | y :: ys ->
            if y - x >= 2 then
                "No"
            else
                loop (min x y) ys
    loop h hs
    |> printfn "%s"
    0

Measured memory_bytes: 33872
from collections import deque

dq = deque()

n = int(input())

for _ in range(n):
    command = input()
    if command[:6] == 'insert':
        dq.appendleft(command[7:])
    elif command[:10] == 'deleteLast':
        dq.pop()
    elif command[:11] == 'deleteFirst':
        dq.popleft()
    elif command[:6] == 'delete':
        if (command[7:]) in dq:
            dq.remove(command[7:])
print(" ".join(dq))




Measured memory_bytes: 69728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int a,b,x; cin>>a>>b>>x;
  int empty = a*a*b - x;
  double theta;
  if (x*2 > a*a*b) {
    theta = atan(2*empty/pow(a,3))*180/M_PI;
  } else {
    theta = 90 - atan(2*x/(double)(a*b*b))*180/M_PI;
  }
  printf("%.10f\n", theta);
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const  int maxn=1e5+10;
int a[maxn];
int gcdpr[maxn];
int gcded[maxn];
int main()
{
     int n;
     scanf("%d",&n);
     for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int sum=a[1];
    gcdpr[1]=sum;
        for(int i=2;i<=n;i++)
        {
           sum=__gcd(sum,a[i]);
            gcdpr[i]=sum;
        }
    sum=a[n];
     gcded[n]=sum;
     for(int i= n-1;i>=1;i--)
     {
         sum=__gcd(sum,a[i]);
          gcded[i]=sum;
     }

     int ans=0;
     for(int i=1;i<=n;i++)
     {
        ans=max(__gcd(gcdpr[i-1],gcded[i+1]),ans);
     }
     cout<<ans<<endl;

    return 0;
}


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

int main()
{
	int cnt = 0;
	string s,t;
	
	cin >> s >> t;
	
	for (int i = 0; i < s.length(); ++i)
	{
		if(s[i] == t[i])
		{
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int N;
	int i;
	long int cnt;

	scanf("%d",&N);	

	int M[N+1];
	int H[N];
	for(i=0;i<N+1;i++){
		scanf("%d",&M[i]);
	}

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

	cnt=0;	
	for(i=0;i<N;i++){
		if(M[i]>=H[i]){
			cnt+=H[i];
		}else{
			cnt+=M[i];
			H[i]-=M[i];
			if(M[i+1]>=H[i]){
				cnt+=H[i];
				M[i+1]-=H[i];
			}else{
				cnt+=M[i+1];
				M[i+1]=0;
			}
		}
	}

	printf("%ld\n",cnt);

	return 0;
}	






Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
// ax + by = gcd(a, b) O(logN)
long long extended_euclidean(long long a, long long b, long long &x, long long &y)
{
	x = 1;
	y = 0;
	long long u = 0, v = 1;
	long long ri = a, rj = b, rk, k;

	// [x y]
	// [u v]
	while (1) {
		k = ri/rj;
		rk = ri%rj;
		ri = rj;
		rj = rk;


		// [newx newy] = [0  1] [x y]
		// [newu newv] = [1 -k] [u v]
		long long newx, newy, newu, newv;
		newx = u;
		newy = v;
		newu = x-k*u;
		newv = y-k*v;
		x = newx;
		y = newy;
		u = newu;
		v = newv;

		if (rk == 0)
			break;
	}

	return a*x+b*y; // gcd
}
void prime_factorization(long long n, map<long long, int>& m) // O(sqrt(n))
{
	for (long long i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			n/=i;
			m[i]++;
		}
	}
	if (n != 1)
		m[n]++;
}
int main(void)
{
	long long a, b;
	cin >> a >> b;
	long long x, y;
	long long gcd = extended_euclidean(a, b, x, y);

	map<long long, int> m;
	prime_factorization(gcd, m);
	cout << m.size()+1 << endl;


	return 0;
}

Measured memory_bytes: 3620
#Problem B

n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    for j in range(n-i-2):
        for k in range(n-i-j-2):
            len = a[i] + a[i+j+1] + a[i+j+k+2]
            ma = max(a[i],  a[i+j+1],  a[i+j+k+2])
            rest = len - ma

            if ma < rest:
                 if a[i] != a[i+j+1] and a[i+j+1] != a[i+j+k+2]:
                        if a[i+j+k+2] != a[i]:
                            cnt += 1


print(cnt)            

Measured memory_bytes: 68792
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a = [str(i) for i in input().split()]

    if a[0][len(a[0])-1] ==a[1][0] and a[1][len(a[1])-1] ==a[2][0]:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3828