akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b == c || a == b + c || b == a + c ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

template<class T> class rollinghash {
	const ull mask30 = (1LL << 30) - 1;
	const ull mask31 = (1LL << 31) - 1;
	const ull mod61 = (1LL << 61) - 1;
	const ull base = 10000001;
	vector<ull> hashvalue, basepower;
	int length;
	ull modulo(ull a) {
		ull au = a >> 61; ull ad = a & mod61;
		ull res = au + ad; if (res >= mod61) res -= mod61;
		return res;
	}
  	ull multiply(ull a, ull b) {
		ull au = a >> 31; ull ad = a & mask31;
		ull bu = b >> 31; ull bd = b & mask31;
		ull mid = ad * bu + au * bd;
		ull midu = mid >> 30; ull midd = mid & mask30;
		return au * bu * 2 + midu + (midd << 31) + ad * bd;
	}
public:
	rollinghash(T s) {
		length = s.size();
		hashvalue = vector<ull>(length + 1);
		for (int i = 0; i < length; i++) {
			hashvalue[i + 1] = modulo(multiply(hashvalue[i], base) + s[i] + 1);
		}
		basepower = vector<ull>(length + 1);
		basepower[0] = 1;
		for (int i = 1; i <= length; i++) {
			basepower[i] = modulo(multiply(basepower[i - 1], base));
		}
	}
	ull hash(ll l, ll r) {
		assert(l < r && 0 <= l && l < length && 0 < r && r <= length);
		return modulo(hashvalue[r] + mod61 - modulo(multiply(hashvalue[l], basepower[r - l])));
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	string s;
	cin >> s;
	rollinghash<string> rol(s);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			while (i + ans < j && j + ans < n) {
				if (rol.hash(i, i + ans + 1) != rol.hash(j, j + ans + 1)) break;
				ans++;
			}
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],o,p;
pair<int,int> pp[220000];
string s,sa,ss[220000];
char c,ca;
double d=0.0;
queue<int> que;
signed main(){
    cin>>s;
    rep(i,16){
        sa="";
        if(i%2==0){
            sa+="AKIH";
        }else{
            sa+="KIH";
        }
        if(i/2%2==0){
            sa+="AB";
        }else{
            sa+="B";
        }
        if(i/4%2==0){
            sa+="AR";
        }else{
            sa+="R";
        }
        if(i/8%2==0){
            sa+="A";
        }
        if(s==sa){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 10444
while n = gets.to_i do
  if n == 0 then
    break
  end
  
  a,b = 0,0

  n.times do
    data = gets.split().map(&:to_i)
    if data[0] > data[1] then
      a += data[0] + data[1]
    elsif data[0] < data[1] then
      b += data[0] + data[1]
    else
      a += data[0]
      b += data[1]
    end
  end
  
  puts "#{a} #{b}"
end

Measured memory_bytes: 6100
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string dame="zyxwvutsrqponmlkjihgfedcba";
	string S;
	scan(S);
	int N=S.size();
	if(S==dame){
		prin(-1);
	}
	else if(N==26){
		int minmoji=-1;
		vint kouho;
		int okikae;
		for(int i=N-1;i>=0;i--){
			if(S[i]-'a'>minmoji){
				minmoji=S[i]-'a';
				kouho.push_back(S[i]-'a');
			}
			else{
				okikae=S[i]-'a';
				rep(j,i){
					printf("%c",S[j]);
				}
				break;
			}
		}
		char nextchar;
		int minnum=INF;
		rep(i,kouho.size()){
			if(kouho[i]>okikae&&kouho[i]<minnum){
				nextchar='a'+kouho[i];
				minnum=kouho[i];
			}
		}
		printf("%c\n",nextchar);
	}
	else{
		int count[26]={0};
		rep(i,N){
			count[S[i]-'a']++;
		}
		char nextchar;
		rep(i,26){
			if(count[i]==0){
				nextchar='a'+i;
				break;
			}
		}
		S+=nextchar;
		prin(S);
	}
	return 0;
}


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

int main() {
    int z;
    while(cin>>z, z) {
        int ans = 1<<29;
        for(int x = 1; x*x*x<z*z*z; ++x) {
            for(int y = x; x*x*x+y*y*y<z*z*z; ++y) {
                if(z*z*z-(x*x*x+y*y*y) < 0) continue;
                ans = min(ans, z*z*z-(x*x*x+y*y*y));
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 864
#include <stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
main(){
    int sy[51]={0,0,};
    int soba[6][2]={{2,380},{3,550},{5,850},
    {10,380*5*8/10},{3*4,550*4*85/100},{15,850*3*88/100}};
    int i,j;
    int c=1;
    for(i=1;i<=50;i++)
        sy[i]=32768;
    for(i=0;i<6;i++)
        sy[soba[i][0]]=soba[i][1];
    c=0;
    while(c++<100){
        for(i=1;i<=50;i++){
            for(j=0;j<6;j++){
                if(i+soba[j][0]>50)
                    continue;
                sy[i+soba[j][0]]=min(sy[i+soba[j][0]],sy[i]+soba[j][1]);
            }
        }
    }

    while(scanf("%d",&i)==1){
        if(i==0)
            break;
        printf("%d\n",sy[i/100]);
    }
    return 0;
}

Measured memory_bytes: 600
program main
  implicit none
  integer :: n, i, j, k, d, a(100)
  integer :: pena(100)
  pena(:) = 0
  read *, n, k
  pena(1:n) = 1
  do i = 1, k
    read *, d
    read *, a(1:d)
    do j = 1, d
      pena(a(j)) = 0
    end do
  end do
  print "(i0)", sum(pena)
end program main


Measured memory_bytes: 2868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll N;
    cin>>N;
    string S,T;
    cin>>S>>T;
    rep(0,i,N){
        cout<<S.substr(i,1)<<T.substr(i,1);
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
main(){
  string b,ans;
  cin >> b;
  
  if(b=="A"){
    ans = "T";
  }else if(b=="T"){
    ans = "A";
  }else if(b=="C"){
    ans = "G";
  }else if(b=="G"){
    ans = "C";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    string k;
    ll n, d, pb, dp[105][10005]={0}, sum[1005]={0};
    cin >> k >> d;
    n = k.size();
    dp[0][0] = 1;
    rep(i,1,n){
    	pb = k[i-1] - '0';
    	sum[i] = (sum[i-1] + pb) % d;
    	rep(j,0,d-1) rep(k,0,9) dp[(j+k)%d][i] = (dp[(j+k)%d][i] + dp[j][i-1]) % mod;
    	rep(k,pb+1,9) dp[(sum[i-1]+k)%d][i] = (dp[(sum[i-1]+k)%d][i] - 1 + mod) % mod;
    }
    cout << (dp[0][n] - 1 + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

int n, m,u,v,s,t;
vector<int>edge[100000 + 5];
int vis[100000 + 5][4];

struct node {
	int u, f, len;
	friend  bool operator < (node a,node b)
	{
		if (a.len == b.len)
		{
			return a.f < b.f;
		}
		return a.len > b.len;
	}
};

void bfs()
{
	priority_queue<node>que;
	que.push({s,3,0});
	while (!que.empty())
	{
		node p = que.top();
		que.pop();
		int u = p.u;
		int f = p.f;
		int len = p.len;
		vis[u][f] = p.len;

		if (u == t&&f==3)
		{
			cout << len << endl;
			exit(0);
		}
		if (f == 3)f = 0;
		for (int i = 0; i < edge[u].size(); i++)
		{
			int v = edge[u][i];
			int lenx=len;
			if (f == 2)lenx++;
			if (lenx < vis[v][f+1])
			{
				que.push({ v,f+1,lenx });
			}
		}
	}
	cout << -1 << endl;
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", &u, &v);
		edge[u].push_back(v);
	}
	scanf("%d%d", &s, &t);
	for (int i = 1; i <= n; i++)vis[i][0] = vis[i][1] = vis[i][2] = vis[i][3] = 0x3f3f3f3f;
	bfs();
	return 0;
}

Measured memory_bytes: 102240
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;


int main()
{
  ll n;
  cin >> n;
  
  ll cnd = 1;
  ll pn = n;
  while(true){
    if(pn<=pow(26,cnd)){
      break;
    }else{
      pn -= pow(26,cnd);
      cnd++;
    }
  }
  ll cou2=cnd-1;
  pn--;
  vector<ll> ans;

  while(true){
    ll waru = pow(26,cou2);
    ll na = pn/waru;
    ans.push_back(na);
    pn -= na*waru;
    if(cou2==0){
      break;
    }
    cou2--;
  }

  REP(i,ans.size()){
    char sss = 'a'+ans[i];
    cout << sss;
    if(i==ans.size()-1) cout << endl;
  }

  
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:
const int limit = 4010;
using T = bitset<limit>;

T gcd(T a, T b) {
	if (b.none()) return a;
	int ta = 0, tb = 0;
	rep(i, limit) if (a[i]) ta = i;
	rep(i, limit) if (b[i]) tb = i;

	if (ta < tb) {
		return gcd(b, a);
	} else {
		T ab = a;
		for (int i = ta; i >= tb; --i) {
			if (ab[i]) {
				ab ^= b << (i - tb);
			}
		}
		return gcd(b, ab);
	}
	return b;
}

T read() {
	string s;
	cin >> s;
	const int n = s.size();
	T ret;
	ret.reset();
	rep(i, n) if (s[i] == '1') ret.set(n - 1 - i);
	return ret;
}

const ll mod = 998244353LL;

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

	T x, a[6];

	x = read();
	rep(i, n) a[i] = read();

	T g = a[0];
	rep(i, 1, n) g = gcd(g, a[i]);

	int tg = 0, tx = 0;
	rep(i, limit) if (g[i]) tg = i;
	rep(i, limit) if (x[i]) tx = i;

	ll ans = 0LL;
	for (int i = tx; i >= tg; --i) ans = (2LL * ans + x[i]) % mod;
	ans = (ans + 1) % mod;

	T y;
	y.reset();

	for (int i = tx; i >= tg; --i) {
		if (x[i] != y[i]) {
			y ^= g << (i - tg);
		}
	}

	bool big = false;
	rrep(i, tg) {
		if (x[i] != y[i]) {
			if (x[i] < y[i]) big = true;
			break;
		}
	}

	if (big) ans = (ans + mod - 1) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <set>

using namespace std;

set <int> s;
int n, x;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        s.insert(x);
    }
    if(n == s.size()) cout << "YES";
    else cout << "NO";
    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  string s;
  cin >> s;
  int a[26] = {};
  a[s[0] - 'a']++;
  a[s[1] - 'a']++;
  a[s[2] - 'a']++;

  if (a[0] * a[1] * a[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}



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

using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)

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

    string S; cin >> S;
    string T; cin >> T;

    vector<vector<int>> counter(26, vector<int>(26, 0));
    rep(i, T.size())
        counter[T[i]-'a'][S[i]-'a']++;

    rep(i, 26) {
        if (count_if(all(counter[i]), [](int x){return x>0;}) >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    rep(i, 26) {
        int c = 0;
        rep(j, 26) c += counter[j][i] > 0;
        if (c >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 916
//  [amitdu6ey]
// g++ -std=c++11 -o2 -Wall filename.cpp -o filename
#include <bits/stdc++.h>
#define hell 1000000009
#define bug1(x) cout<<"$ "<<x<<" $"<<endl
#define bug2(x) cout<<"% "<<x<<" %"<<endl
#define bug3(x) cout<<"# "<<x<<" #"<<endl
#define ll long long
#define pb push_back
#define mp make_pair
#define tr(z) for(auto it=z.begin(); it!=z.end(); it++)
#define rloop(i,a,b) for(long long i=a; i>=b;i--)
#define loop(i,a,b) for(long long i=a; i<b; i++)
#define vbool vector< bool >
#define vvbool  vector< vector<bool> >
#define vchar vector<char>
#define vi vector<int>
#define vvi vector< vector<int> >
#define pll pair<long long, long long>
#define vll vector<long long>
#define vvl vector< vector<long long> >
#define ninf numeric_limits<long long>::min()
#define pinf numeric_limits<long long>::max()
#define comp(a,b) (abs(a-b)<1e-9) // to compare doubles
using namespace std;

void solve(){
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    vll h(n,0);
    loop(i,0,n) cin>>h[i];
    vll dp(n,pinf);
    dp[0]=0;
    loop(i,1,n){
        loop(j,max(0ll,i-k),i){
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int test_cases=1;
    //cin>>test_cases;
    while(test_cases--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4780
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
 int n,k;
  cin >> n >> k;
 int a[n];
 int cnt[n]={0};
  
  for(int i=0;i<n;i++) {
    cin >> a[i];
    cnt[a[i]-1]++;
  }
  
  sort(cnt,cnt+n);
  
  int res=0;
  for(int i=0;i<n-k;i++) {
   res+=cnt[i];
  }
 cout << res << endl;
}

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

long long int n,m,x,i;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>m;
	for (i=1;i<m+1;i++) cin>>x,n=n-x;
	if (n<0) n=-1;
	cout<<n;
}


Measured memory_bytes: 3648
//In The Name Of Godd
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef pair<ll, ll> ii;
typedef pair<int, ii> iii;
typedef pair<double, double> dd;
typedef pair<dd, double> ddd;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<dd> vdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

#define forn(i, n) for (ll i = 0; i < n; i++)
#define forr(i, n) for (ll i = n; i >= 0; i--)
#define fore(i, x, n) for (ll i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define inf 100000000000
#define eps 1e-9

const int maxn = 3010;
ll dp[maxn][maxn];
int n;

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    vi nms(n);
    forn(i, n) cin >> nms[i];
    forn(i, n) dp[i][i] = nms[i];
    for(int i = 2; i <= n; i++) {
        for(int j = i - 1; j < n; j++) {
            int l = j - i + 1, r = j;
            ll f = nms[l] - dp[l + 1][r], s = nms[r] - dp[l][r - 1];
            dp[l][r] = max(f, s);
        }
    }
    cout << dp[0][n - 1] << endl;
}


Measured memory_bytes: 70016
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <fstream>

using namespace std;

#define ll long long
#define pb push_back
/*void usacosolve(string x){
    ofstream fout(x+".out");
    ifstream fin(x+".in");
}*/
void solve() {
    ll n;
    cin>>n;
    ll arr[n][3];
    for(ll i=0;i<n;i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    ll dp[n][3];
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(ll i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+arr[i][2];
    }
    ll ans=0;
    for(ll i=0;i<3;i++){
        ans=max(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;
}
int main(){
    /*//usaco:
    string x="";
    usacosolve(x);*/
    //codechef and others
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
        //cout<<t<<endl;
    }
    return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>

int main()
{
	int count[4][3][10]={0}; 
	int n,i,t,s,b,f,r,v;
	
	scanf("%d",&n);
	for(i=0; i < n ; i++)
	{
		scanf("%d %d %d %d",&b,&f,&r,&v);
		count[b-1][f-1][r-1]+=v;
	}
	for(i=0; i<4; i++)
	{
		for(t=0; t < 3; t++)
		{
			for(s=0; s < 10; s++)
			{
				printf(" %d",count[i][t][s]);
			}
			printf("\n");
		}
		if(i!=3)
		{
			printf("####################\n");
		}
	}
    return 0;
}

Measured memory_bytes: 612
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var ABCXY = Sarray();
            var A = ABCXY[0];
            var B = ABCXY[1];
            var C = ABCXY[2];
            var X = ABCXY[3];
            var Y = ABCXY[4];
            var a1 = A*X+B*Y;
            var a2 = 2 * X * C;
            if (X < Y)
            {
                a2 += B * (Y - X);
            }
            var a3 = 2 * Y * C;
            if (Y < X)
            {
                a3 += A * (X - Y);
            }
            var a4 = Math.Max(X, Y) * 2 * C;
            WriteLine(Math.Min(a1, Math.Min(a2, Math.Min(a3, a4))));

        }
    }
}


Measured memory_bytes: 13268
n=int(input())
a=list(map(int,input().split()))
l=[0]*8
col=0
for i in range(n):
  if a[i]<400:
    l[0]=1
  elif a[i]<800:
    l[1]=1
  elif a[i]<1200:
    l[2]=1
  elif a[i]<1600:
    l[3]=1
  elif a[i]<2000:
    l[4]=1
  elif a[i]<2400:
    l[5]=1
  elif a[i]<2800:
    l[6]=1
  elif a[i]<3200:
    l[7]=1
  else:
    col+=1
ans=sum(l)
if ans==0:
  print(1,col)
elif col==0:
  print(ans,ans)
else:
  print(ans,ans+col)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long[][][] warshall=new long[11][10][10];
        int h=sc.nextInt();
        int w=sc.nextInt();
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                warshall[0][i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    warshall[i+1][j][k]=Math.min(warshall[i][j][k],warshall[i][j][i]+warshall[i][i][k]);
                }
            }
        }
        long ans=0;
        int tmp;
        for(int i=0;i<h*w;i++){
            tmp=sc.nextInt();
            if(tmp>=0)ans+=warshall[10][tmp][1];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 44600
#include <bits/stdc++.h>
#define MAXN 200005
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(c) (c).begin(), (c).end()
using namespace std;

ll n, x;
vector <ll> v;
bool flag = true;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		v.pb(x);
	}
	sort(all(v));
	for (int i = 0; i < n - 1; i++)
		if (v[i] == v[i + 1]) flag = false;
	flag ? cout << "YES" : cout << "NO";
	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main() {
 int a[101],b[101],n,c=0;
 cin>>n;
 for(int i=0;i<n;i++){
   cin>>a[i]>>b[i];
 }
 for(int i=0;i<n-2;i++){
   if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
     c=1;
     break;
   }
 }
 if(c==1){
   cout<<"Yes";
 }else{
   cout<<"No";
 }
}

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

int main(){

  int n,x,t;
  cin>>n>>x>>t;
  
  int ans,b,c;
  ans=0;
  b=n/x;
  c=n%x;
  
  if(c==0){ans=b*t;}
  else{ans=(b+1)*t;}
  
  cout<<ans<<endl;
  
return 0;
}


Measured memory_bytes: 3588
//Tonight's the night and it is going to happen again and again.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define T ll t; cin>>t; while(t--)
#define mod 1000000007
#define inf 1000000000000000000
#define mem(name,val) memset(name,val,sizeof(name))
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define endl "\n"
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif 
   int s;cin>>s;
   int dp[s+3];mem(dp,0);dp[0]=1;
   for(int i=1;i<=s;i++)
   {
    for(int j=3;j<=s;j++)
    {
      if(i>=j)
      {
      dp[i]+=dp[i-j];dp[i]%=mod;
      }
    }
   }
   cout<<dp[s]; 
}

Measured memory_bytes: 3612
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - First Second
 */

#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 = 200000;
const int MAX_L = 1000000;
const int MAX_M = MAX_L + 1;
const int K = 26;

/* typedef */

typedef long long ll;
typedef int vec[K];

/* global variables */

char s[MAX_L + 4];
string ss[MAX_N];
int ps[MAX_M];
vec cs[MAX_M], cts[MAX_M];

/* subroutines */

bool cmpstr(const string &a, const string &b) {
  return a.size() > b.size();
}

void printvec(vec v) {
  for (int i = 0; i < K; i++) printf("%d ", v[i]);
  putchar('\n');
}

void store_word(string &w, int &m) {
  int u = 0;
  for (int i = w.size() - 1; i >= 0; i--) {
    int c = w[i] - 'a';
    int v = cs[u][c];
    if (v < 0) {
      v = cs[u][c] = m++;
      ps[v] = u;
    }
    u = v;
  }

  vec t;
  memset(t, 0, sizeof(t));

  for (int i = 0; i < w.size(); i++) {
    u = ps[u];
    t[w[i] - 'a'] = 1;
    for (int j = 0; j < K; j++) cts[u][j] += t[j];
  }
}

int lookup_word(string &w) {
  int u = 0;
  for (int i = w.size() - 1; i > 0; i--) {
    int c = w[i] - 'a';
    if (cs[u][c] < 0) return 0;
    u = cs[u][c];
  }
  return cts[u][w[0] - 'a'];
}

/* main */

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

  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    ss[i] = string(s);
  }
  sort(ss, ss + n, cmpstr);
  //for (int i = 0; i < n; i++) cout << ss[i] << endl;

  memset(cs, -1, sizeof(cs));
  ps[0] = -1;

  int m = 1;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    string &w = ss[i];
    sum += lookup_word(w);
    store_word(w, m);
  }

  printf("%lld\n", sum);
  //printf("m=%d\n", m);
  //printvec(cts[0]);
  return 0;
}


Measured memory_bytes: 215732
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        
        // process:
        // 次のルールで、n個の値を集合に追加する。
        // rule: 自分より小さい値がいれば、自分に最も近い値を自分に書き換える。
        //       いない場合は、誰も書き換えず自分を追加する。
        
        // ans: 集合の要素数
        // ex. {2, 1, 4, 5, 3} =>
        // {2} -> {1,2} -> {1,4} -> {1,5} -> {3,5} ans = 2;
        
        while (n-- > 0) {
            int num = sc.nextInt();
            
            if (map.lowerKey(num) == null) {
                int val = map.getOrDefault(num, 0);
                map.put(num, ++val);
            } else {
                int key = map.lowerKey(num);
                int val = map.get(key);
                if (val == 1) {
                    map.remove(key);
                } else {
                    map.put(key, --val);
                }
                val = map.getOrDefault(num, 0);
                map.put(num, ++val);
            }
        }
        
        // TreeMapなので、集合の要素数はvalの総和
        int ans = 0;
        for (Integer key : map.keySet()) {
            int val = map.get(key);
            ans += val;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 64696
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int A[] = new int[N];
		PriorityQueue<Double> pq = new PriorityQueue<Double>(Collections.reverseOrder());;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			pq.add((double)A[i]);
		}
		
		for(int i = 0; i < M; i++) {
			double temp = pq.poll();
			temp = temp / 2;
			pq.add(temp);
		}
		
		long ans = 0;
		for(int i = 0; i < N; i++) {
			ans += Math.floor(pq.poll());
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 62236
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>
#include <queue>
#include <set>

using namespace std;


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
 	return 0;
}



Measured memory_bytes: 256
program exponential
  implicit none
  integer :: x, n, i, s, t, k
  read(*,*) x
  if (x.lt.4) then
    write(*,'(i0)') 1
    stop
  end if
  k = ceiling(sqrt(real(x,8)))
  s = 0
  do i = 2, k
    t = i*i
    do
      if (t.gt.x) exit
      if (s.lt.t) s = t
      t = t*i
    end do
  end do
  write(*,'(i0)') s
  stop
end program exponential

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int smax = 1000000000;

int main(){
	int n,k,s;
	cin >> n >> k >> s;

	vector<int> ans(n);
	for(int i=0; i<k; i++){
		ans[i] = s;
	}
	for(int i=k; i<n; i++){
		if(s == smax){
			ans[i] = 1;
		}else{
			ans[i] = smax;
		}
	}
	for(int i=0; i<n-1; i++){
		cout << ans[i] << " ";
	}
	cout << ans[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1664
def eratosthenes(n):
    prime = []
    limit = n**0.5
    numbers = [i for i in range(2,n+1)]
    while True:
        p = numbers[0]
        if limit <= p:
            return prime + numbers
        prime.append(p)
        numbers = [i for i in numbers if i%p != 0]

primes = eratosthenes(100000)
numbers = [(p+1)//2 for p in primes]
alike = list(set(primes)&set(numbers))
alike = [2*p-1 for p in alike]
alike.sort()
alike

cum = [0]*(10**5+1)
for p in alike:
    cum[p] = 1
import numpy as np
cum = np.array(cum)
cum = np.cumsum(cum)

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


Measured memory_bytes: 19300
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  ll x=(n+999)/1000;
  print(1000*x-n);
  return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int dp[100001],h[100001],n,c=0;
int f(int i)
{
	if(dp[i]!=-1)
	return dp[i];
	
	
	
	
	if((i+1)<n && (i+2)<n)
	{
		dp[i]=min((f(i+1)+abs(h[i+1]-h[i])),(f(i+2)+abs(h[i+2]-h[i])));
	}
	else if((i+1 )<n)
	{
		dp[i]=f(i+1)+abs(h[i+1]-h[i]);
	}
	else
	return 0;
	
	return dp[i];
}
int main()
{int i;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>h[i];
	memset(dp,-1,sizeof(dp));
	cout<<f(0);
return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, ans = 1000000000000000;
	cin >> nn;
	for(int64 ii = 1;ii <= sqrt(nn);ii++)
	{
		if(nn % ii == 0)
		{
			ans = min(ans, ii + (nn / ii) - 2);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  int N,K,i,j,ans=0,max,check;
  scanf("%d %d",&N,&K);
  int l[N];
  for(i=0;i<N;i++){
    scanf("%d",&l[i]);
  }
  for(i=0;i<K;i++){
    max=l[0];
    check=0;
    for(j=0;j<N;j++){
      if(max<l[j]){
        max=l[j];
        check=j;
      }
    }
    ans=ans+max;
    l[check]=0;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N,K;
vector<int> A;
const int MAX_N = 5010;
int8_t dp[MAX_N][MAX_N];
int src;
int tabooo[MAX_N];
int memo(int pos, int val){
  if (val >= K - A[src] and val < K){
    return 1;
  }

  if (pos == N){
    return 0;
  }
  int8_t &res = dp[pos][val];
  if (res >= 0){
    return res;
  }
  res = 0;
  res = memo(pos + 1, val);
  if (res&1){
    return res;
  }
  if (not tabooo[pos]){
    res = memo(pos + 1, min(K, val + A[pos]));
    if (res&1){
      return res;
    }
  }

  return res;
}


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

  A.resize(N);
  for (auto &val : A){
    cin >> val;
  }
  sort(A.begin(), A.end());
  int left,right;
  left = -1;
  right = N;
  while (right - left > 1){
    int med = (right + left) / 2;
    if (med >= N){
      right--;
      continue;
    }else if(med < 0){
      left++;
      continue;
    }

    src = med;
    memset(dp, -1, sizeof(dp));
    tabooo[med] = true;
    int res = memo(max(0, left), 0);
    tabooo[med] = false;
    if (res > 0){//necessary
      right = med;
    }else{//unnecessary
      left = med;
      for (int i = med; i >= 0; i--){
        if (tabooo[i])break;
        tabooo[i] = true;
      }
    }
  }
  cout << (left + 1) << endl;

  return 0;
}


Measured memory_bytes: 25336
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 111111;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    int a=0,b=0,c=0;
    for(auto d:s){
        if(d=='a')a++;
        else if(d=='b')b++;
        else c++;
    }
    if(max({a,b,c})-min({a,b,c})>=2){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }

}

Measured memory_bytes: 512
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, d = MAP()
ans = 0
for _ in range(n):
    x, y = MAP()
    if sqrt(x  ** 2 + y ** 2) <= d:
        ans += 1
print(ans)

Measured memory_bytes: 73712
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
import bisect
from logging import getLogger, StreamHandler, DEBUG, WARNING
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
# handler.setLevel(WARNING)
# logger.setLevel(WARNING)
logger.addHandler(handler)
def main():
    s = input().strip()
    n = len(s)
    tmp = s[0]
    ans = 0
    for i , c in enumerate(s):
        if tmp != c:
            if i > ans:
                ans = i

        if i >= (n) // 2:
            break
        tmp = c


    tmp = s[-1]
    for i, c in enumerate(s[::-1]):
        if tmp != c:
            if i > ans:
                ans = i

        if i >= (n) // 2:
            break
        tmp = c

    print(n - ans)

    # print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 46060
from collections import defaultdict

n, m = map(int, input().split())
alist = list(map(int, input().split()))

c = 0
cnt = defaultdict(int)
cnt[0] = 1
s = 0
for i in range(n):
    s += alist[i]
    c += cnt[s%m]
    cnt[s%m] += 1

print(c)


Measured memory_bytes: 14636
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int N, X;
    cin >> N >> X;

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

    int ans = 1;
    int d = 0;

    for (int i = 0; i < N; ++i) {
        d = d + L[i];

        if (d > X) {
            break;
        }

        ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
import math
n=int(input())
L=list(map(int,input().split()))
print
if n==1:
    print(L[0])
else:
    x=L[0]
    for i in range(1,n):
        x=(x*L[i])//math.gcd(x,L[i])
        i+=1
    print(x)


Measured memory_bytes: 5664
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    REP2(i, -1000, 1000){
        REP2(j, -1000, 1000){
            if(pow(i, 5) - pow(j, 5) == n){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4024
from collections import Counter
a=input().strip()
x,y=[int(i) for i in input().split(" ")]

e1=[0]
e2=[0]
f=0
t=0
for i in a:
  if i=='F':
    f+=1
  elif i=='T':
    if f!=0:
      if t==0:
        e1.append(f)
      elif t==1:
        e2.append(f)
    t=(t+1)%2
    f=0

if t==0:
  e1.append(f)
elif t==1:
  e2.append(f)

s={0}
o=0
for i in e1:
  if a[0]=='F' and o==1:
    s=set([k+i for k in s])
  else:
    sp=set([k+i for k in s])
    sm=set([k-i for k in s])
    s=sp|sm
  o+=1
r={0}
for i in e2:
  rp=set([k+i for k in r])
  rm=set([k-i for k in r])
  r=rp|rm


if x in s and y in r:
  print('Yes')
else:
  print('No')

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/01/29  Problem: ARC 090 B / Link: http://arc090.contest.atcoder.jp/tasks/arc090_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N, M;

LL ans = 0LL;

void dfs(int v, int p, LL sum, vector<vector<PLL>>&G, VI& checked, VL &we) {

	//debug(v);
	checked[v] = 1;

	FOR(i, 0, SZ(G[v])) {
		int nx = G[v][i].first;
		LL pc = G[v][i].second;
		if (checked[nx]) {
			if (we[nx] != sum + pc) {
				ans = 0; return;
			}
			else { // ok
				;
			}
		}
		else {
			we[nx] = we[v] + pc;
			dfs(nx, v, we[nx], G, checked, we);
		}
	}

}


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

	cin >> N >> M;
	VL L(M,0), R(M,0), D(M,0);
	VI checked(N, 0);
	VL we(N, 0);
	vector<vector<PLL>> G(N, vector<PLL>());

	FOR(i, 0, M) {
		cin >> L[i] >> R[i] >> D[i];
		L[i]--;
		R[i]--;
		G[L[i]].push_back(PLL(R[i], D[i]));
		G[R[i]].push_back(PLL(L[i], -D[i]));
	}
	ans = 1;
	/*debug(ans);
	we[L[0]] = 0;*/

	FOR(i, 0, N) {
		if (checked[i] == 0)
			dfs(i, -1, 0, G, checked, we);
	}
	if (ans == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

using namespace std;
const int maxn = 3010;

int n;
int niz[maxn];
long long dp[maxn][maxn];

long long rek(int x, int y, bool turn) {
    if (x > y) return 0;
    long long &ret = dp[x][y];
    if (ret != -1) return ret;

    if (turn) ret = max(rek(x + 1, y, false) + niz[x], rek(x, y - 1, false) + niz[y]);
    else ret = min(rek(x + 1, y, true) - niz[x], rek(x, y - 1, true) - niz[y]);
    return ret;
}

int main() {
    memset(dp, -1, sizeof dp);
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", niz+i);

    printf("%lld", rek(0, n - 1, true));
    return 0;
}


Measured memory_bytes: 71168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5; 

#define endl "\n"

char str[N];
int cnt[26]={0};

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>str;
	for(int i=0;i<4;i++){
		cnt[str[i]-'A']++;
	}
	int sum=0;
	bool flag=1;
	for(int i=0;i<26;i++){
		if(cnt[i]){
			sum++;
			if(sum>2||cnt[i]!=2){
				flag=0;
				break;
			}
		}
	}
	if(sum!=2) flag=0;
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }else if(A+B<C+D){
    cout<<"Right"<<endl;
  }else{
    cout<<"Balanced"<<endl;
  }
}

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



int main() {
    string s, t;
    cin >> s >> t;
    
    int ans = 10010010;
    rep(i,s.size()-t.size()+1) {
        int cnt = 0;
        rep(j,t.size()) {
            if(s[i+j] != t[j]) {
                cnt++;
            }
        }
        ans = min(ans,cnt);
    }
    
    cout << ans << endl;
    
    
    return 0;
}




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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;
#define END cout << endl;

int main() {
  int n; cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  vector<ll> a(n), b(n);
  ll maxi = 40000;
  rep(i,n) {
    a[i] = maxi*(i+1);
    b[i] = maxi*(n-i+1) + 1;
  }
  rep(i,n) {
    a[p[i] - 1] += i;
  }
  for (auto itr : a) {
    cout << itr << " ";
  } END;
  for (auto itr : b) {
    cout << itr << " ";
  } END;
}

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

int main() 
{
	int result;
	bool flg=false;
	cin >> result;

	for( int i=1 ; i<10 ; i++ )
	{
		for( int j=1 ; j<10 ; j++ )
		{
			if( i*j == result )
			{
				flg = true;
				break;
			}	
		}
		if( flg )
			break;
	}

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

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long k=sc.nextLong();
      	long a=sc.nextLong();
		long b=sc.nextLong();
      	
		long n=(b/k)*k;
		if(n>=a){
			System.out.println("OK");
		}else{
			System.out.println("NG");
		}
	}
}

Measured memory_bytes: 27000
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int INF = 1e18 + 239;
const int N = 4005;

int n;
int a[N];
int mn[N][N];

void init() {
	for (int i = 0; i < n; i++) {
		mn[1][i] = a[i];
	}
	for (int i = 1; i + 1 <= n; i++) {
		for (int j = 0; j + i + 1 <= n; j++) {
			mn[i + 1][j] = min(a[j], mn[i][j + 1]);
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	

	int x;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		a[i + n] = a[i];
	}
	n *= 2;
	init();
	int ans = INF;
	for (int k = 0; k < n / 2; k++) {
		int c = k * x;
		for (int i = 0; i < n / 2; i++) {
			c += mn[k + 1][i];
		}
		ans = min(ans, c);
	}
	cout << ans << endl;
}

Measured memory_bytes: 125184
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
    
using namespace std;

typedef long long ll;


int main() {
    vector<int> a;
    int s;
    cin >> s;
    
    a.push_back(s);
    ll ans = 0;
    for (int i = 0; i<100010; i++) {
        if (a.at(i) % 2 == 0) a.push_back(a.at(i)/2);
        else a.push_back(3*a.at(i) + 1);
        for (int j = 0; j<i+1; j++) {
            if (a.at(i+1) == a.at(j)) {
                ans = i + 2;
                break;
            }
        }
        if (ans != 0) break;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256