akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const int N = 105;
ll dp[N][4][4][4];
ll go(int i, int j, int k, int l, int n)
{
	if (i == n)
		return 1;
	if (dp[i][j][k][l] != -1)
		return dp[i][j][k][l];
	//use A
	ll ans = 0;
	ans = add(ans, go(i + 1, k, l, 0, n), MOD);
	//use G
	if (!(k == 0 && l == 2))
		ans = add(ans, go(i + 1, k, l, 1, n), MOD);
	//use C
	if (!((k == 0 && l == 1) || (k == 1 && l == 0) || (j == 0 && l == 1) || (j == 0 && k == 1)))
		ans = add(ans, go(i + 1, k, l, 2, n), MOD);
	//use T
	ans = add(ans, go(i + 1, k, l, 3, n), MOD);
	return dp[i][j][k][l] = ans;
}
void solve(int tc)
{
	int n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	ll ans = go(0, 3, 3, 3, n);
	cout << ans << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,K = inpl()


if K%2 == 0:
    Kdiv2 = K//2
    n1 = n2 = 0
    for i in range(1,N+1):
        if i%K == 0:
            n1 += 1
        elif i%Kdiv2 == 0:
            n2 += 1
    print(n1**3+n2**3)


else:
    n1 = n2 = 0
    for i in range(1,N+1):
        if i%K == 0:
            n1 += 1
    print(n1**3)


Measured memory_bytes: 4204
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

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


Measured memory_bytes: 256
//Stones

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;string s,t;cin>>n>>s;
    int k=0,w=0;
    vector<p>m(n);
    rep(i,0,n){
        if(s[i]=='#')k++;
        else w++;
        m[i].first=w;
        m[i].second=k;
    }
    int ans = min(w,k);
    //......#####
    rep(i,0,n){
        ans = min(ans,m[i].second+w-m[i].first);
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 6828
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
template<class T=ll> 
T in(){T x;cin>>x;return (x);}
template<class T> 
void print(T &x){cout<<x<<"\n";}
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x"="<< (x) << "\n"
#define dbgv(x) cerr<<#x<<"\n";reps(y,x){cerr<<y<<" ";}cerr<<"\n"

int main(){
  int D=in();
  string ans="Christmas";
  rep(i,25-D){
    ans+=" Eve";
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int money=0,money1=0,all=0;
	while(1){
	cin>>money;
	if(money==0){break;}
	money1=1000-money;
	all+=(money1/500);
	all+=(money1%500/100);
	all+=(money1%500%100/50);
	all+=(money1%500%100%50/10);
	all+=(money1%500%100%50%10/5);
	all+=(money1%500%100%50%10%5/1);
	cout<<all<<endl;
	all=0;
	}
	return 0;
}
//9:18.853クリア


Measured memory_bytes: 2952
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 3000050;
using namespace std;
typedef long long ll;
int p[1010];
int main()
{
	int x,n;
	cin>>x>>n;
	int y;
	for(int i=0;i<n;i++){
		cin>>y;
		p[y+110]=1;
	}
	int cnt=0;
	while(1){
		if(!p[x-cnt+110]){
			cout<<x-cnt;
			break;
		}
		else if(!p[x+cnt+110]){
			cout<<x+cnt;
			break;
		}
		cnt++;
	}
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
lis = list(map(int, input().split()))

lis  =sorted(lis)

t1 = sum(lis[n:2*n])
#print(sum(t1))

nlis = lis[::-1]

t2 = 0
for i in nlis[1:2*n:2]:
    t2 += i


print(max(t1, t2))

Measured memory_bytes: 42600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int n,a,b,c;
vector<int> l;
int dfs(int now,int p,int q,int r){
    if(now==n) {
        if(p==0 || q==0 || r==0) return INF;
        else return abs(p-a)+abs(q-b)+abs(r-c);
    }
    
    int ret=INF;
    ret=min(ret,dfs(now+1,p,q,r));
    ret=min(ret,dfs(now+1,p+l[now],q,r)+(p==0 ? 0 : 10));
    ret=min(ret,dfs(now+1,p,q+l[now],r)+(q==0 ? 0 : 10));
    ret=min(ret,dfs(now+1,p,q,r+l[now])+(r==0 ? 0 : 10));
    return ret;
}

int main(){
    cin>>n>>a>>b>>c;
    l.resize(n);
    rep(i,n) cin>>l[i];
    cout<<dfs(0,0,0,0)<<endl;
}


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  MAX= int(1e5)+5;
int n, m;
int dp[MAX],indegree[MAX],visited[MAX];
vector< vector<int> > graph(MAX);

void dfs(int u) {
    visited[u] = true;
    for(int v : graph[u]) {
        dp[v] = max(dp[v] , dp[u]+1);
        indegree[v]--;
        if(indegree[v] == 0) {
            dfs(v);
        }
    }
} 

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;

    for( int i = 0 ; i < m ; i++) {
        int u , v;
        cin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
        indegree[v]++;
    }

    for( int i = 0; i < n ; i++) {
        if(indegree[i] == 0 && !visited[i]) {
            dfs(i);
        }
    }


    int res = 0;
    for(int i = 0; i < n ; i++) {
        res = max(res,dp[i]);
    }


    cout << res << "\n";

    return 0;
}



Measured memory_bytes: 9984
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[]
y=[]
c=[]
for _ in range(M):
    x0,y0,c0=map(int,input().split())
    x.append(x0)
    y.append(y0)
    c.append(c0)

ans = min(a) + min(b)

for i in range(M):
    price = a[x[i]-1] + b[y[i]-1] - c[i]
    if price < ans:
        ans = price

print(ans)


Measured memory_bytes: 102608
n, a, b, c = map(int,input().split())
L = [int(input()) for i in range(n)]
ans = 10**10

for i in range(4**n):
    ta, tb, tc = 0, 0, 0
    tmp = 0
    for j in range(n):
        k = (i>>(2*j)) & 3
        if k == 1:
            if ta > 0:
                tmp += 10
            ta += L[j]
        elif k == 2:
            if tb > 0:
                tmp += 10
            tb += L[j]
        elif k == 3:
            if tc > 0:
                tmp += 10
            tc += L[j]
    if ta * tb * tc == 0:
        continue
    tmp += abs(a - ta) + abs(b - tb) + abs(c - tc)
    ans = min(ans,tmp)

print(ans)

Measured memory_bytes: 45980
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ALL(a) (a).begin(), (a).end()

int main(){
    int n;
    cin >> n;
    vector<int> A(n), B(n), C(n);
    for(int i = 0; i < n; ++i) cin >> A[i];
    for(int i = 0; i < n; ++i) cin >> B[i];
    for(int i = 0; i < n; ++i) cin >> C[i];
    sort(ALL(A));
    sort(ALL(C));
    ll int ans = 0;
    for(int b : B){
        auto itra = lower_bound(ALL(A), b);
        auto itrc = upper_bound(ALL(C), b);
        ans += (itra - A.begin()) * (C.end() - itrc);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

bool isth(int n) {
	while (n) {
		if (n % 10 == 3) { return true; }
		n /= 10;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	for (int i = 3; i <= n; ++i) {
		if (i % 3 == 0 || isth(i)) { cout << " " << i; }
	}
	cout << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
const int INF = 0x3f3f3f3f;

int main() {
    char c;
    cin >> c;
    if (c == 'A') {
        cout << "T" << endl;
    } else if (c == 'T') {
        cout << "A" << endl;
    } else if (c == 'C') {
        cout << "G" << endl;
    } else {
        cout << "C" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MOD = 1e9 + 7;

ll add(string s){
    ll res = 0;
    rep(i, 0, s.size()){
        string num = "";
        while(i < s.size() && s[i] != '+') num += s[i++];
        if(num.size()) res += stoll(num);
    }
    return res;
}

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

    ll ans = 0;
    rep(i, 0, (1 << s.size())){
        bitset<10> bit(i);
        string a = "";
        rep(j, 0, s.size()){
            a += s[j];
            if(bit.test(j)) a += '+';
        }
        ans += add(a);
    }

    cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;


int main(){
    int x, n;
    cin >> x >> n;
    vint p(n);
    rep(i, n){
        cin >> p[i];
    }

    int midiff = 1e5;
    int ans = 1e5;
    for(int i = 105; i > -105; i--){
        bool flag = false;
        for(auto ps : p){
            if(ps == i){
                flag = true;
                break;
            }
        }
        if(flag) continue;
        int diff = abs(x - i);
        midiff = min(midiff, diff);
        if(midiff == diff){
            ans = min(ans, i);
        }
    }

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


Measured memory_bytes: 3628
#141b
S = str(input()) #S は長さ 1 以上 100 以下の文字列

#S が以下の 2 条件を満たすとき、またその時に限り、Sを「踏みやすい」文字列といいます。
#    奇数文字目がすべて R, U, D のいずれか。
#    偶数文字目がすべて L, U, D のいずれか。
#Sが「踏みやすい」文字列なら Yes を、そうでなければ No を出力してください。

for i in range(len(S)):
  if i%2==1 and S[i]!="L" and S[i]!="U" and S[i]!="D":
    print("No")
    break
  elif i%2==0 and S[i]!="R" and S[i]!="U" and S[i]!="D":
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 3060
#include <stdio.h>

int main() {
    int N;
    int A;
    scanf("%d", &N);
    scanf("%d", &A);

    while (500 <= N) {
        N -= 500;
    }
    while (0 < A) {
        N--;
        A--;
    }

    if (N <= 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

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

/*
  let's try computer shogi!!!
 */

/*
  距離1の島を列挙した後に、それらの島から島nに行けるかチェックすれば良い
 */

struct fleet{
  int from;
  int to;
};


int main(){
  int N, M; // 島の数、定期便の数
  cin >> N >> M;
  vector<fleet> fleets;
  vector<int> oneway; //1手で行ける島の集合
  vector<int> onewayfromN; //1手で行ける島の集合
  fleets.resize(M);
  for(int i=0;i<M;++i){
    cin >> fleets[i].from >> fleets[i].to;
    if(fleets[i].from == 1){
      oneway.push_back(fleets[i].to); // fromがtoより値が小さいことが保証されてるのでtoの走査は不要
      if(fleets[i].to == N){
	cout<<"POSSIBLE";
	return 0;
      }
    }
    if(fleets[i].to == N){
	onewayfromN.push_back(fleets[i].from);
    }
  }

  sort(oneway.begin(),oneway.end());
  sort(onewayfromN.begin(),onewayfromN.end());
  int jstart = 0;
  int ist = 0;
  // しゃくとり法で比較

  while(1){
    for(int j=jstart;j<onewayfromN.size();++j){

      if(oneway[ist] == onewayfromN[j]){
	cout<<"POSSIBLE";
	return 0;
      }
      if(oneway[ist] < onewayfromN[j]){
	jstart = j;
	break;
      }
    }
    ist++;
    if(ist == oneway.size()){
      break;
    }
  }
  
  cout<<"IMPOSSIBLE";
  return 0;
}

Measured memory_bytes: 2812
#include <cstdio>
#include <cmath>
using namespace std;

#define EPS (1e-10)
#define equals( A, B ) (fabs((A) - (B)) < EPS)

class Point {
public:
    double x, y;
    Point( double x = 0, double y = 0 ): x(x), y(y) {}
    
    Point operator + ( Point p ) { return Point( x + p.x, y + p.y ); }
    Point operator - ( Point p ) { return Point( x - p.x, y - p.y ); }
    Point operator * ( double a ) { return Point( a * x, a * y ); }
    Point operator / ( double a ) { return Point( x / a, y / a ); }

    double abs() { return sqrt( norm() ); }
    double norm() { return x * x + y * y; }

    bool operator < ( const Point &p ) const {
	return ( x != p.x ) ? x < p.x : y < p.y;
    }

    bool operator == ( const Point &p ) const {
	return equals( x, p.x ) && equals( y, p.y ); 
    }

    double dot( Point a ) { return x * a.x + y * a.y; }
    double cross( Point a ) { return x * a.y - y * a.x; }
    double distance( Point a ) {
	return (*this - a).abs();
    }
};

typedef Point Vector;


static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Line {
public:
    Point p1, p2;
    Line( Point p1 = Point(), Point p2 = Point() ): p1(p1), p2(p2){}
    // ?????´????????????( cos = 0 )
    bool isOrthogonal( Line a ) {
	return equals( 0.0, (p1 - p2).dot( a.p1 - a.p2 ) );
    }
    // ??????????????????( sin = 0 )
    bool isParallel( Line a ) {
	return equals( 0.0, (p1 - p2).cross( a.p1 - a.p2 ) );
    }

    Point projection( Point p ) {
	Vector v12 = p2 - p1;
	double r = v12.dot( p - p1 ) / v12.norm();
	return p1 + v12 * r;
    }

    Point reflection( Point p ) {
	return p + ( projection( p ) - p ) * 2.0;
    }

    double distance( Point p ) {
	Vector v12 = this->p2 -this->p1;
	Vector v10 = p - this->p1;
	
	return v12.cross( v12 ) / v12.abs();
    }

    double distanceSP( Point p ) {
	if ( (p - this->p1).dot( this->p2 - this->p1 ) < 0.0 ) {
	    return this->p1.distance( p );
	} else if ( (p - this->p2).dot( this->p1 - this->p2 ) < 0.0 ) {
	    return this->p2.distance( p );
	}
	else {
	    return distance( p );
	}
    }

    int ccw( Point p ) {
	Vector a = p2 - p1;
	Vector b = p - p1;
	if ( a.cross( b ) > EPS ) return COUNTER_CLOCKWISE;
	else if ( a.cross( b ) < -EPS ) return CLOCKWISE;
	else if ( a.dot( b ) < -EPS ) return ONLINE_BACK;
	else if ( a.norm() < b.norm() ) return ONLINE_FRONT;
	else return ON_SEGMENT;
    }

    bool intersect( Line l ) {
	return ( ( ccw( l.p1 ) * ccw( l.p2 ) <= 0 && l.ccw( p1 ) * l.ccw( p2 ) <= 0 ) );
    }
};

typedef Line Segment;

int main()
{
    int q;
    scanf("%d", &q);

    for ( int i = 0; i < q; i++ ) {
	Point p0, p1, p2, p3;
	scanf("%lf %lf", &p0.x, &p0.y);
	scanf("%lf %lf", &p1.x, &p1.y);
	scanf("%lf %lf", &p2.x, &p2.y);
	scanf("%lf %lf", &p3.x, &p3.y);
	Segment s1 = Segment( p0, p1 );
	Segment s2 = Segment( p2, p3 );
	
	if ( s1.intersect( s2 ) ) printf("1\n");
	else printf("0\n");
    }

    return 0;
}

Measured memory_bytes: 1048
//    _        _   __
//   (_)      | | / /
//    __ ___  | |/ / ___    ____
//   | |/ _ `\|   | / _ `\ / _  \
//   | | (_) | |\ \| (_) || (_) |
//   | |\__,_|_| \_\\__,_|\____/
// _/ |
//|__/
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353LL
#define endl '\n'
using namespace std;

mt19937 gen(time(0));

int n,m,maxn=0;
ll dp[2][505][515];	// len,last,xor
ll prefix[505][515];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	ll ans=0,tmp;
	cin>>n>>m;
	tmp=m;
	while(tmp){
		maxn++;
		tmp>>=1;
	}
	maxn=(1<<maxn)-1;
	for(int i=0;i<=m;i++){
		dp[1][i][i]=1;
	}
	for(int i=2;i<=n;i++){
		memset(prefix,0,sizeof(prefix));
		for(int j=0;j<=m;j++){
			for(int k=0;k<=maxn;k++){
				dp[i&1][j][k]=0;
			}
		}
		for(int j=0;j<=m;j++){
			for(int k=0;k<=maxn;k++){
				if(j)
					prefix[j][k]=dp[~i&1][j][k]+prefix[j-1][k];
				else
					prefix[j][k]=dp[~i&1][j][k];
			}
		}
		for(int j=0;j<=m;j++){
			for(int k=0;k<=maxn;k++){
				dp[i&1][j][k]+=prefix[j][j^k];
				dp[i&1][j][k]%=mod;
			}
		}
	}
	for(int i=0;i<=m;i++){
		ans+=dp[n&1][i][m];
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}
/*
dp[i][j][k]=dp[i-1][x][x^k] (0<=x<=j,x=j^k)
*/


Measured memory_bytes: 9260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define inf 10000000000000

int main()
{    
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef APNA_IO
    	freopen("input.txt","r",stdin);
    	freopen("output.txt","w",stdout);
    #endif

	ll n,k;
    cin>>n>>k;
    ll h[n];
    ll Min;

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

    ll p[n];
    p[0]=0;
    p[1]=abs(h[1]-h[0]);

	for(ll i=2;i<n;i++)
	{ Min = 1000000000000;
		for(ll j=1;j<=k;j++)
		{
			if(i-j>=0)
			{
			if (abs (h[i]-h[i-j])+p[i-j]<Min)
				Min=abs (h[i]-h[i-j])+p[i-j];
			}
			
		}
		p[i]=Min;
	}

cout<<p[n-1];
    	
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 5e18;
const int nax = 100005;
int n,m,u,v;
bool vis[nax];
vector<int> adj[nax];
void dfs(int node)
 {
  vis[node] = 1;
  for(auto x : adj[node])
     {
      if(!vis[x])
         dfs(x);
     }
 }
void solve()
  {
   cin>>n>>m;
   loop(i,0,m)
    {
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
   loop(i,1,n+1)
    vis[i] = 0;
   int cc = 0;
   loop(i,1,n+1)
    if(!vis[i])
       {
        dfs(i);
        cc++;
       }
   cout<<cc - 1;
  } 
int32_t main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 10408
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        //int n = Integer.parseInt("1");
        for(int i = 0;i < n;i++){
            String[] vals = br.readLine().split(" ",0);
            //String[] vals = "4 3 5".split(" ",0);
            int[] int_vals = new int[vals.length];
            for(int j = 0;j < int_vals.length;j++){
                int_vals[j] = Integer.parseInt(vals[j]);
            }
            Arrays.sort(int_vals);
            
            int a2 = int_vals[2] * int_vals[2];
            int b2 = int_vals[1] * int_vals[1];
            int c2 = int_vals[0] * int_vals[0];

            if(a2 == b2 + c2){
                 System.out.println("YES");
            }else{
                 System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 25988
/*  -*- coding: utf-8 -*-
 *
 * 3028.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_CN = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int ls[MAX_CN];
pii wcs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, cn;
  scanf("%d%d%d", &n, &m, &cn);

  for (int i = 0; i < cn; i++) scanf("%d", ls + i);

  for (int i = 0; i < n; i++) {
    int ci, wi;
    scanf("%d%d", &ci, &wi);
    ci--;
    wcs[i] = pii(wi, ci);
  }
  sort(wcs, wcs + n);

  int sum = 0;
  for (int i = n - 1; i >= 0 && m > 0; i--) {
    int &wi = wcs[i].first, &ci = wcs[i].second;
    if (ls[ci] > 0) {
      sum += wi;
      ls[ci]--;
      m--;
    }
  }

  printf("%d\n", sum);
  return 0;
}



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

int main()
{
  int n;
  cin >> n;
  
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  int up = 0, down = 0,same = 0;
  int ans = 1;
  for(int i = 1; i < n; i++){
    if(a[i] > a[i-1]){
      up = 1;
      same = 0;
    }else if(a[i] < a[i-1]){
      down = 1;
      same = 0;
    }else{
      same = 1;
    }
    
    if( (up == down) && (same != 1) ){
      up = 0;
      down = 0;
      same = 0;
      ans++;
    }
  }//for
  
  cout << ans << endl;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
string lcs_func(string x, string y)
{

    // FINDING THE LENGTH OF LCS
    
    ll n=x.length(),m=y.length(),i,j;
    ll dp[n+1][m+1];

    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            dp[i][j]=0;
            else if(x[i-1]==y[j-1])
            dp[i][j]=1+dp[i-1][j-1];
            else if(x[i-1]!=y[j-1])
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

    // PRINTING THE LONGEST COMMON SUBSTRING
    ll k=1,ans=dp[n][m],u;
    u=ans;
    i=n;
    j=m;
    string s="";
    while(k<=u)
    {
        if(dp[i][j]==0)
        break;
        if(dp[i-1][j]!=ans && dp[i][j-1]!=ans)
        {
            s=x[i-1]+s;
            k++;
            ans=dp[i-1][j-1];
            i=i-1;
            j=j-1;
            continue;
        }
        else
        {
            if(dp[i-1][j]==ans)
            {
                i=i-1;
                j=j;
                continue;
            }
            else if(dp[i][j-1]==ans)
            {
                i=i;
                j=j-1;
                continue;
            }
        }  
    }
    return s;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s1,s2,rev;
    cin>>s1>>s2;
    cout<<lcs_func(s1,s2)<<endl;
    return 0;
}

Measured memory_bytes: 70656
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
    char w[10], t[1000];
    int i, n = 0;

    scanf("%s", w);
    for(i = 0; i < strlen(w); i++)
        w[i] = tolower(w[i]);
    
    for(;;){
        scanf("%s", t);
        if(strcmp(t, "END_OF_TEXT") == 0) break;
        for(i = 0; i < strlen(t); i++)
            t[i] = tolower(t[i]);
    
        if(strcmp(w, t) == 0)
            n++;
    }

    printf("%d", n);
    putchar('\n');

    return 0;
}


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

#include <vector>
#define modes 1000000007;
int main(){
    long long sum=0;
    int n;cin >> n;
    vector<long long> a(n);
    for(int i=0; i<n; i++) {
        cin >> a.at(i);
        sum += a.at(i);
        sum %= modes;
    }
    long long ans = 0;
    for(int i=0; i<n; i++) {
        sum -= a.at(i);
        if(sum<0) sum += modes;
        ans += a.at(i)*sum;
        ans %= modes;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define MOD 1000000007
#define PI acos(-1)
vector<int> adj[100005];
int main()
{
	IOS
	int n,m;
	cin>>n>>m;
	int h[n+1],i;
	for(i=1;i<=n;i++)
	cin>>h[i];
	int x,y;
	for(i=1;i<=m;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	int ans=0;
	int vis[n+1]={0};
	for(i=1;i<=n;i++)
	{
		if(adj[i].size()==0)
		ans++;
		else
		{
			int j;
		 for(j=0;j<adj[i].size();j++)
		 {
		 	if(h[i]<=h[adj[i][j]])
		 	break;
		 }
		 if(j==adj[i].size())
		 ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 9536
#include<stdio.h>
int main(void)
{
	int a[3];
	int c,d;
	int i, j,wk,x;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	scanf("%d",&c);
	scanf("%d",&d);
	for(i=0;i<2;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				wk=a[i];
				a[i]=a[j];
				a[j]=wk;
			}
		}
	}
//	printf("%d %d %d\n",a[0],a[1],a[2]);
	if(c<d){
		x=a[0]+c-50;
	}
	else{
		x=a[0]+d-50;
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 1808
a,b=map(int,input().split())

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

d=[]
for i in range(b-1):
  x=c[i+1]-c[i]
  d.append(x)

x=c[0]+a-c[b-1]
d.append(x)
d.sort()
print(sum(d[:b-1]))

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	ll n, k;
	cin >> n >> k;
	while (true) {
		if (n % k == 0) {
			cout << 0 << endl;
			return 0;
		} else if (abs(n - k) < (n % k)) {
			cout << min(n, abs(n - k)) << endl;
			return 0;
		} else if ((n % k) < abs(n - k)){
			cout << min(n % k, abs((n % k) - k)) << endl;
			return 0;
		} else {
			n = abs(n - k);
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    multiset<int> A;
    set<int> B;
    int n,k;
    cin >> n >> k;
    for (int i=0; i<n; i++){
        int a;
        cin >> a;
        A.insert(a);
        B.insert(a);
    }
    int n_size=B.size();
    if (n_size<=k){
        cout << 0 << endl;
    }
    else {
        vector<int> v;
        for (auto a: B){
            int x=A.count(a);
            v.push_back(x);
        }
        sort(v.begin(),v.end());
        int n_delete=n_size-k;
        int change=0;
        for (int i=0; i<n_delete; i++){
            change+=v[i];
        }
        cout << change <<endl;
    }
}


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

int main() {
  string s;
  cin>>s;
  int n = s.length();
  for (int i=n-2; i>=0; i--) {
    if (i % 2 == 0) {
      continue;
    }
    if (s.substr(0, i/2+1) == s.substr(i/2+1, i/2+1)) {
      cout<<i+1<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
##2つの整数 K,Sが与えられます。
##入力は以下の形式で標準入力から与えられる。
##K S
k, s = gets.chomp.split(" ").map(&:to_i)

##3つの変数 X,Y,Zがあり、0 ≦ X,Y,Z ≦ Kを満たす整数の値を取ります。
##X+Y+Z=S を満たす X,Y,Zへの値の割り当ては何通りありますか。

##制約
##2 ≦ K ≦ 2500 | 0 ≦ S ≦ 3K | K,Sは整数である。

##問題文の条件を満たす X,Y,Zの組が何通りあるか出力せよ。
num = ((k+1)*2)+(k-1)
a_way = Array.new(num, 0)

mid_idx_b, mid_idx_e = 0, 0
plus_v = 1
(0..k).each do |idx|
  idx_l = num - 1 - idx
  # print(" #{plus_v}")
  # print(" #{idx}")
  # print(" #{idx_l},")
  if idx == 0
    a_way[idx] = a_way[idx_l] = plus_v + 0
  else
    a_way[idx] = a_way[idx_l] = plus_v + a_way[idx-1]
  end
  plus_v += 1
  
  mid_idx_b, mid_idx_e = idx, idx_l
end
# print("\n")
# p a_way

mid_idx_b, mid_idx_e = mid_idx_b+1, mid_idx_e-1
# print("mid_idx_b: #{mid_idx_b}, ")
# print("mid_idx_e: #{mid_idx_e}\n")

minus_v = k - 1
(mid_idx_b..mid_idx_e).each do |idx|
  idx_l = num - 1 - idx
  # print(" #{minus_v}")
  # print(" #{idx}")
  # print(" #{idx_l},")
  a_way[idx] = a_way[idx_l] = minus_v + a_way[idx-1]
  
  minus_v -= 2
  
  break if idx == idx_l || minus_v < 0
end
# print("\n")
# p a_way

p a_way[s]

Measured memory_bytes: 1788
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;

int main(){
  ll X, K, D;
  cin>>X>>K>>D;
  
  ll div=abs(X)/D;
  
  if(div>=K){
    cout<<abs(abs(X)-K*D);
  }else{
    cout<<(((K-div)%2==1) ? abs(abs(X)-(div+1)*D) : abs(abs(X)-div*D))<<endl;
  }
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	int n, x, t;
	cin >> n >> x >> t;

	int ans = n / x * t;
	if (n % x)
		ans += t;
	cout << ans << endl;
}



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

int main()
{
        long long X;
        cin >> X;

        long long p = 100;
        long long y = 0;
        while (1) {

                p += (p / 100);
                y++;
                if (p >= X) {
                        break;
                }
        }
        cout << y << endl;

}


Measured memory_bytes: 3596
// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }

    let mut paper = HashSet::new();

    for n in a {
        if !paper.insert(n) {
            paper.remove(&n);
        }
    }

    println!("{}", paper.len());
}


Measured memory_bytes: 8444
"""
AtCoder Educational DP Contest
https://atcoder.jp/contests/dp/tasks/dp_k

K - Stones
"""
import collections

def solve(xs):
    dp = collections.defaultdict(bool)
    dp[0] = False
    for j in range(1, K + 1):
        dp[j] = any((j >= x) and (not dp[j - x]) for x in xs)
    return dp[K]

N, K = map(int, input().split())
choices = [int(s) for s in input().split()]
assert len(choices) == N
res = solve(choices)
print("First" if res else "Second")


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

static const int MAX = 1000000;

void make_prime(bool *n){
    for (int i=2; i<1000; i++) {
        if (!n[i]){
            for(int j = i*i; j < MAX; j+=i){
                n[j] = true;
            }
        }
    }
}

int main(){
    bool num[MAX] = {false};
    make_prime(num);
    int n;
    while(cin >>n){
        int ans = 0;
        for(int i=2; i<=n; i++){
            if(!num[i]){ans++;}
        }
        cout <<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << " = " << (x) << "\n";
using ll = long long;
using ld = long double;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    string s;
    cin >> s;
    stack<char> st;
    int count = 0;
    for (int i = 0; i < s.length(); ++i)
    {
        if (!st.empty())
        {
            if (st.top() != s[i])
            {
                count += 2;
                st.pop();
            }
            else
            {
                st.push(s[i]);
            }
        }
        else
        {
            st.push(s[i]);
        }
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int findroot(vector<int> &indeg) {
    for(int i = 1;i <= indeg.size();i++) {
        if(indeg[i] == 0)
            return i;
    }

    return -1;
}

int main(void) {
    Int N,M;

    cin>>N>>M;
    vector<int> indeg(N+1,0);
    vector<int> ans(N+1,0);
    vector<Int> Edge[N+1];

    for(int i = 0;i < N-1+M;i++) {
        int from,to;
        cin>>from>>to;
        Edge[from].push_back(to);
        indeg[to]++;
    }

    int root = findroot(indeg);

    queue<int> Q;
    Q.push(root);

    while(!Q.empty()) {
        int from = Q.front();Q.pop();
        for(int i = 0;i < Edge[from].size();i++) {
            indeg[Edge[from][i]]--;
            if(indeg[Edge[from][i]] == 0) {
                ans[Edge[from][i]] = from;
                Q.push(Edge[from][i]);
            }
        }
    }

    for(int i = 1;i <= N;i++) {
        cout<<ans[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 7040
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

long long int gcd(long long int m, long long int n)
{
	if(n == 0) return m;
	return gcd(n, m % n);
}

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
int n;
struct op
{
	int a,h;
};
bool cmp(op x,op y)
{
	return x.a<y.a;
}
op u[maxn],b[maxn];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>u[i].a;
		b[i].a=u[i].a;
		u[i].h=i;
		b[i].h=u[i].h;
	}
	sort(b+1,b+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		for(int j=n;j>0;j--)
		{
			if(u[i].a==b[n].a)
			{
				cout<<b[n-1].a<<endl;
				break;
			}
			if(b[j].a >= u[i].a&&b[j].h!=u[i].h)
			{
				cout<<b[j].a<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4736
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
dd=defaultdict(lambda:0)
for aa in a:
  dd[aa]+=1
x,y=0,0
for k in sorted(dd.keys(), reverse=True):
  if x==0 and dd[k]>=2:
    x=k
    dd[k]-=2
  if y==0 and dd[k]>=2:
    y=k
    break
print(x*y)

Measured memory_bytes: 22012
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll n;
    cin >> n;
    vector<ll> ts;
    for (auto &&i: irange(0LL, n)){
        ll t;
        cin >> t;
        ts.emplace_back(t);
    }
    ll m;
    cin >> m;
    vector<ll> ps, xs;
    for (auto &&i: irange(0LL, m)){
        ll p, x;
        cin >> p >> x;
        p--;
        ps.emplace_back(p);
        xs.emplace_back(x);
    }
    for (auto &&i: irange(0LL, m)){
        ll s{0};
        for (auto &&j: irange(0LL, n)){
            if (j == ps.at(i))s+=xs.at(i);
            else s+=ts.at(j);
        }
        cout << s << endl;
    }
    return 0;
}

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

const int maxv = 8000;

int n;
char s[maxv+5];
int dp[maxv*2+5], temp[maxv*2+5];
vector<int> p[2];

void solve(int t) {
    int i,pos = 0;
    memset(dp,0,sizeof(dp));
    dp[maxv] = 1;
    for(auto x : p[t]) {
        pos++;
        memset(temp,0,sizeof(temp));
        for(i=-maxv;i<=maxv;i++) {
            if(dp[i+maxv]) {
                if(i+x <= maxv) temp[i+x+maxv] = 1;
                if(t==0 && pos==1) continue;
                if(i-x >= -maxv) temp[i-x+maxv] = 1;
            }
        }
        for(i=-maxv;i<=maxv;i++) dp[i+maxv] = temp[i+maxv];
    }
}
int main() {
    int i,cnt_t,cnt,x,y;
    scanf(" %s%d%d",s,&x,&y);
    n = strlen(s);
    cnt_t = cnt = 0;
    for(i=0;i<=n;i++) {
        if(i==n || s[i]=='T') {
            p[cnt_t&1].push_back(cnt);
            cnt_t++; cnt = 0;
        }
        else cnt++;
    }
    int ans = 1;
    solve(0);
    ans &= dp[x+maxv];
    solve(1);
    ans &= dp[y+maxv];
    if(ans) printf("Yes");
    else printf("No");
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>

using namespace std;

int N,K;

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

  int i,j,k;
  k=0;
  for(i=0;i<N;i++)
  {
    cin >> j;
    
    if(j>=K)
    {
      k++;
    }
  }

  
  
  cout << k;
  
  
}

Measured memory_bytes: 256
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
vector<pair<char, int>> runLengthEncoding(string s) {
    int n = s.length();

    vector<pair<char, int>> res;
    char pre = s[0];
    int cnt = 1;
    rep(i, 1, n) {
        if (pre != s[i]) {
            res.push_back({ pre, cnt });
            pre = s[i];
            cnt = 1;
        }
        else cnt++;
    }

    res.push_back({ pre, cnt });
    return res;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;
	auto rl = runLengthEncoding(S);
	cout << rl.size() << endl;
}







Measured memory_bytes: 1608
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, q;
    cin >> n >> q;
    vector<stack<int>> s(n);
    while (q--) {
        int com, t;
        cin >> com >> t;
        if (com == 0) {
            int x;
            cin >> x;
            s[t].push(x);
        } else if (com == 1) {
            if (!s[t].empty()) cout << s[t].top() << endl;
        } else {
            if (!s[t].empty()) s[t].pop();
        }
    }
}



Measured memory_bytes: 4244
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define MOD 998244353

using namespace std;

int main()
{
    IOS;
    int n;
    cin>>n;
    ll a[n];
    repf(i,0,n) cin>>a[i];
    int sign=1;
    ll sum=0;
    int i=0,j=n-1;
    while(i<=j)
    {
        if(i==j) 
        {
            sum+=sign*a[i];
            break;
        }
        sum+=sign*(a[i]+a[j]);
        sign*=-1;
        i++,j--;
    }
    ll x=sum;
    repf(i,0,n)
    {
        cout<<x<<" ";
        x=a[i]-x/2;
        x=x*2;
    }
}
 

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

int main(){
  long long int n,i,j,r=0,g=0,b=0,tokushu=0,kotae;
  string s;
  cin>>n;
  cin>>s;
  for(i=0;i<n;i++){
    if(s[i]=='R'){
      r++;
    }else if(s[i]=='G'){
      g++;
    }else{
      b++;
    }
  }
  for(i=1;i<=(n-1)/2;i++){
    for(j=0;;j++){
      if(j+i+i>=n){
        break;
      }
      if(s[j]!=s[j+i]&&s[j+i]!=s[j+i+i]&&s[j+i+i]!=s[j]){
        tokushu++;
      }
    }
  }
  kotae=r*g*b-tokushu;
  cout<<kotae;
}

Measured memory_bytes: 3628
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)
for i in range(1, n):
    if a[i] == a[i-1] + 1:
        ans += c[a[i-1] - 1]
print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<int>> vec(H,vector<int>(W));
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            cin >> vec.at(i).at(j);
        }
    }
    vector<pair<P,P>> ret;
    for(int i = 0;i < H;i++) {
        if(i % 2 == 0) {
            for(int j = 0;j < W - 1;j++) {
                if(vec.at(i).at(j) % 2 == 1) {
                    ret.push_back(make_pair(P(i,j),P(i,j + 1)));
                    vec.at(i).at(j + 1)++;
                }
            }
            if(vec.at(i).at(W - 1) % 2 == 1 && i != H - 1) {
                ret.push_back(make_pair(P(i,W - 1),P(i + 1,W - 1)));
                vec.at(i + 1).at(W - 1)++;
            }
        }
        else {
            for(int j = W - 1;j >= 1;j--) {
                if(vec.at(i).at(j) % 2 == 1) {
                    ret.push_back(make_pair(P(i,j),P(i,j - 1)));
                    vec.at(i).at(j - 1)++;
                }
            }
            if(vec.at(i).at(0) % 2 == 1 && i != H - 1) {
                ret.push_back(make_pair(P(i,0),P(i + 1,0)));
                vec.at(i + 1).at(0)++;
            }
        }
    }
    cout << ret.size() << endl;
    for(int i = 0;i < ret.size();i++) {
        cout << ret.at(i).first.first + 1 << " " << ret.at(i).first.second + 1 << " " << ret.at(i).second.first + 1 << " " << ret.at(i).second.second + 1 << endl;
    }
}

Measured memory_bytes: 5232
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
ab_list = []
ans =0
for i in range(M):
    a,b = map(int, input().split())
    a, b = a-1, b-1
    ab_list.append([a, b])

ans_list = [0 for i in range(M)]
for i in range(M, 0, -1):
    if i == M:
        ans_list[i-1] = N*(N-1)//2
    else:
        if uf.find(ab_list[i][0]) != uf.find(ab_list[i][1]):
            ans_list[i-1] = ans_list[i] - uf.size(ab_list[i][0])*uf.size(ab_list[i][1])
        else:
            ans_list[i-1] = ans_list[i]
        uf.union(ab_list[i][0], ab_list[i][1])
print(*ans_list)


Measured memory_bytes: 29488