akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>

using namespace std;

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

	string s;
	int ans = 0;
	long long N, a;


	cin >> N >> s;
	string f, b;
	int cnt = 0;

	for (int i = 1; i <= N; i++) {
		f = s.substr(0, i);
		b = s.substr(i, s.length() - i);

		for (int j = 0; j < 26; j++) {
			if (f.find('a' + j) != f.npos) {
				if (b.find('a' + j) != b.npos) {
					cnt++;
				}
			}
		}

		ans = max(cnt, ans);
		cnt = 0;
	}
	

	cout << ans  << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N, M;
  int INF = 1e7;
  cin >> N >> M;
  vector<vector<int>> d(N, vector<int>(N, INF));
  vector<array<int, 3>> edge(M);
  vector<bool> is_used(M, false);

  rep(i, M)
  {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = c;
    d[b][a] = c;
    edge[i] = {a, b, c};
  }
  rep(i, N)
  {
    d[i][i] = 0;
  }
  rep(k, N) rep(i, N) rep(j, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  rep(i, M)
  {
    int a = edge[i][0];
    int b = edge[i][1];
    int c = edge[i][2];
    rep(s, N) rep(e, N)
    {
      if (d[s][a] + c + d[b][e] == d[s][e] || d[s][b] + c + d[a][e] == d[s][e])
      {
        is_used[i] = true;
      }
    }
  }
  int ans = 0;
  rep(i, M)
  {
    if (!is_used[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <cmath>

using namespace std;

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

	vector<pair<double, pair<int, int>>> e;

	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		double rm = atan2(double(y), double(x)) + M_PI;
		e.push_back(make_pair(rm, make_pair(x, y)));
		//cerr << rm << " " << x << " " << y << endl;
	}

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

	//for (int i = 0; i < n; i++) {
	//	cerr << e[i].first << " " << e[i].second.first << " " << e[i].second.second << endl;
	//}

	double max_dist = 0;
	for (int i = 0; i < n; i++) {
		long int x = e[i].second.first;
		long int y = e[i].second.second;
		double rad = e[i].first;
		for (int j = 0; j < n; j++) {
			int k = (i + j) % n;
			if (i == k) {
				continue;
			}
			double dist = sqrt((double)x * x + (double)y * y);
			long int x_new = x + e[k].second.first;
			long int y_new = y + e[k].second.second;
			double dist_new = sqrt((double)x_new * x_new + (double)y_new * y_new);
			if (dist_new > dist) {
				x = x_new;
				y = y_new;
			}
			/*
			double d = abs(rad - e[j].first);
			if (d <= M_PI / 2 || d >= 1.5 * M_PI) {
				x += e[j].second.first;
				y += e[j].second.second;
			}
			*/
		}
		double dist = sqrt((double)x*x + (double)y*y);
		if (dist > max_dist) {
			max_dist = dist;
		}

	}
	if (n == 1) {
		long int x = e[0].second.first;
		long int y = e[0].second.second;
		max_dist = sqrt((double)x * x + (double)y * y);
	}

	printf("%.15lf\n",max_dist);
	//cout << max_dist << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
const ll MOD = 1e9+7;
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    vector<int> ans(1001001,0);
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                ll cnt=x*x+y*y+z*z+x*y+y*z+z*x;
                ans[cnt]++;
            }
        }
    }
    int n; cin >> n;
    rep(i,n){
        cout<<ans[i+1]<<endl;
    }
}



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

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

  ll ans = 1;
  ll tmp = 0;
  for (int i = 0; i < 2*n; ++i) {
    if (2*n-i < tmp) {
      ans = 0;
      break;
    }
    if (s[i] == 'B') {
      if (tmp % 2 == 0) ++tmp;
      else {
        ans = ans * tmp % mod;
        --tmp;
      }
    }
    else {
      if (tmp % 2 == 1) ++tmp;
      else {
        ans = ans * tmp % mod;
        --tmp;
      }
    }

    if (tmp < 0) {
      ans = 0;
      break;
    }
  }

  ll kai = 1;
  for (int i = 0; i < n; ++i) {
    kai = kai * (n-i) % mod;
  }
  
  ans = ans * kai % mod;
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    vector<string>v(2), tmp;
    cin >> v[0] >> v[1];
    tmp = v;
    reverse(v[0].begin(), v[0].end());
    reverse(v[1].begin(), v[1].end());
    reverse(v.begin(), v.end());
    cout << (v == tmp ? "YES" : "NO");
    return 0;
}


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

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

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

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

    int64_t prev = T[0];
    for(int i = 1; i < N; ++i){
        prev /= gcd(prev, T[i]);
        prev *= T[i];
    }
    cout << prev << endl;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputNum = Console.ReadLine().Split(' ');
            int N = int.Parse(inputNum[0]);
            int K = int.Parse(inputNum[1]);

            string[] arrD = Console.ReadLine().Split(' ');
            
            int pay = N; 

            while(!isPayCheck(pay, arrD))
            {
                pay = pay + 1;
            }

            Console.WriteLine(pay.ToString());
        }

        static private bool isPayCheck(int pay, string[] arrD)
        {
            string strPay = pay.ToString();
            for (int i = 0; i <= arrD.Length - 1; i++)
            {
                if (strPay.Contains(arrD[i]))
                {
                    return false;
                }
            }
            return true;
        }
    }
}


Measured memory_bytes: 11220
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}
/*inline T gcd(T a,T b){
	while(b != 0 ){
		a = a % b;
		swap(a,b);
	}
	return a;
}*/

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////

inline void solve(){
	int N;
	string str;
	cin >> N >> str;
	vector<int> ans(N);
	vector<int> ani(N);
	for(int i=0;i<N;++i){
		ans[i] = str[i] == 'x';
	}
	bool flag;
	for(int i=0;i<4;++i){
		flag = true;
		ani[0] = (i/2);
		ani[1] = (i%2);
		for(int j=0;j+2<N;++j){
			ani[j+2] = (ani[j]+ani[j+1]+ans[j+1] )%2;
		}
		
		if( (ani[N-2] +ani[N-1]+ans[N-1])%2  != ani[0] )continue;
		if( (ani[N-1] +ani[0]+ans[0])%2 != ani[1] )continue;
		
		for(int j=0;j<N;++j){
			cout << (char)('S' + ani[j]*4);
		}
		cout << endl;
		return;
	}
	cout << -1 << endl;
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


Measured memory_bytes: 1360
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int m[1010];

int main() {
  int n;
  cin >> n;
  map<int, int> mp[2];
  int tmp;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    if (i & 1) mp[1][tmp]++;
    else mp[0][tmp]++;
  }

  vector<P> p[2];
  for (int i = 0; i < 2; ++i) {
    for (auto pp: mp[i])
      p[i].push_back(make_pair(pp.second, pp.first));
  }

  sort(p[0].rbegin(), p[0].rend());
  sort(p[1].rbegin(), p[1].rend());
  int a1 = p[0][0].first, a2 = 0;
  int b1 = p[1][0].first, b2 = 0;
  if (p[0].size() > 1) a2 = p[0][1].first;
  if (p[1].size() > 1) b2 = p[1][1].first;

  if (p[0][0].second == p[1][0].second) {
    cout << min(n - a1 - b2, n - a2 - b1) << endl;
  } else {
    cout << n - a1 - b1 << endl;
  }
  return 0;
}


Measured memory_bytes: 6136
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>

using namespace std;


int main() {
	long long int N;
	cin >> N;
	long long int a;
	long long int Y = 0;
	for(long long int i = 0; i < N; i++) {
		cin >> a;
		while (a % 2 == 0) {
			a /= 2;
			Y++;
		}
	}
	cout << Y << endl;
	return 0;
}



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

typedef long long ll;

ll N, M;
vector<vector<ll>> Out;

vector<bool> Seen;
list<ll> Loop;
vector<bool> InLoop;
bool Found;

void dfs(ll v) {
  if (Seen[v]) {
    if (InLoop[v]) {
      Found = true;
      while (Loop.front() != v) {
        InLoop[Loop.front()] = false;
        Loop.pop_front();
      }
    }
    return;
  }
  Seen[v] = true;
  InLoop[v] = true;
  Loop.push_back(v);
  for (ll w : Out[v]) {
    dfs(w);
    if (Found) return;
  }
  InLoop[v] = false;
  assert(Loop.back() == v);
  Loop.pop_back();
}
bool find_loop() {
  Seen.resize(N);
  InLoop.resize(N);
  for (ll v = 0; v < N; ++v) {
    dfs(v);
    if (Found) return true;
  }
  return false;
}
void find() {
  for (auto it = Loop.begin(); it != Loop.end(); ++it) {
    ll v = *it;
    for (ll w : Out[v]) {
      if (InLoop[w]) {
        for (auto it2 = next(it); true;) {
          if (it2 == Loop.end()) it2 = Loop.begin();
          if (*it2 == w) break;
          InLoop[*it2] = false;
          it2 = Loop.erase(it2);
        }
      }
    }
  }
  cout << Loop.size() << endl;
  for (ll v : Loop) cout << v + 1 << endl;
}

int main() {
  cin >> N >> M;
  Out.resize(N);
  for (ll i = 0; i < M; ++i) {
    ll a, b;
    cin >> a >> b;
    --a;
    --b;
    Out[a].push_back(b);
  }

  if (find_loop()) {
    find();
  } else {
    cout << -1 << endl;
  }
  return 0;
}


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


void solve(){
    int n;
    cin >> n;
    vector<pair<string, int>> v;
    unordered_map<int,int> mp;
    rep(i,n){
        string s;
        int p;
        cin >> s >> p;
        v.emplace_back(make_pair(s,-p));
        mp[p] = i+1;
    }
    sort(v.begin(),v.end());
    rep(i,n){
        cout << mp[-(v[i].second)] << endl;
    }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);

void solve(long long H, long long W)
{
  if (H == 1 | W == 1)
  {
    cout << 1 << endl;
    return;
  }
  cout << (H * W + 1ll) / 2 << endl;
}

signed main()
{
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  solve(H, W);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 256
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    // i番目までの最大の高さより2低いだけならOK
    int M = 0;
    for(int i=0;i<N;i++){
        M = max(M,h[i]);
        if(h[i]-M>=-1) continue;
        cout << "No" << nn;
        return 0;
    }
    cout << "Yes" << nn;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int n, k; cin >> n >> k;
    cout << (n-k) + 1;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
   char str[14];
   int len;
   int i;

   scanf("%s",str);
   len=strlen(str);
   for(i=len;i>3;--i){
      str[i+1]=str[i];
   }
   str[4]=' ';
   puts(str);

   return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	puts(n >= 1000 ? "ABD" : "ABC");
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
struct edge{
  int to,c;
};
vector<edge> G[811];
int dp[811][811][2];
int solve(int id,int pr,int fl){
  if( dp[id][pr][fl] != -1 ) return dp[id][pr][fl];
  vector<int> nex;
  int ret = 0;
  int tc = 0;
  for(int i=0;i<(int)G[id].size();i++){
    edge e = G[id][i];
    if( e.to == pr ){
      tc= e.c;
     continue;
    }
    if( G[e.to].size() == 1 ) nex.push_back( e.c );
    else nex.push_back( solve( e.to, id, 1 ) + e.c*2 );    
    ret += nex.back();
  }
  int sum = ret;
  // if( fl == 1 )cout << id << " " << pr << " "<< fl << " " << ret + tc << endl;
   if(fl==1) return dp[id][pr][fl] = ret + tc;
  for(int i=0,j=0;i<(int)G[id].size();i++){
    edge e = G[id][i];
    if( e.to == pr ) continue;
    if( G[e.to].size() == 1 ) ret = min( ret, sum - nex[j] + e.c );
    else ret = min( ret, sum - nex[j] + solve( e.to, id, 0 ) + e.c );
    j++;
  }
  // cout << id << " " << pr << " "<< fl << " "<< ret + tc << endl;
  return dp[id][pr][fl] = ret + tc;
}

int main(){
  while( cin >>n && n ) {
    memset(dp,-1,sizeof(dp));
    int p[811]={};
    for(int i=1;i<n;i++)
      cin >> p[i];
    for(int i=1;i<n;i++){
      int d; cin >> d; p[i]--;
      G[i].push_back((edge){p[i],d});
      G[p[i]].push_back((edge){i,d});
    }
    /*
    for(int i=0;i<n;i++){
      cout << " i " << i << endl;
      for(int j=0;j<(int)G[i].size();j++){
	cout << " - > " << G[i][j].to << endl;
      }
    }
    */
    int res = (1<<30);
    for(int i=0;i<n;i++){
      if( G[i].size() == 1 ){
	res = min(res,solve(G[i][0].to,i,0));
      }
    }
    cout << res << endl;
    for(int i=0;i<n;i++) G[i].clear();
  }
}

Measured memory_bytes: 6584
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn main() {
    let in_vec: Vec<usize> = read_line();
    let n = in_vec[0];
    let k = in_vec[1];

    let mut res: usize = 0;
    for i in k..=n+1 {
        res = (res + ((n + 1 - i) * i + 1) % 1_000_000_007) % 1_000_000_007;
    }

    println!("{}", res);
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T, typename U> istream& operator>>(istream& in, pair<T, U>& a) { cin >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }

#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

class UnionFind { private: vector<int> par; vector<int> rnk; int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } public: UnionFind(int size) { par.resize(size); rnk.resize(size); REP(i, size) par[i] = i, rnk[i] = 0; } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } };

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

using P = pair<int, int>;
signed main() {
  i64 n, k;
  cin >> n >> k;
  vector<P> ab(n);
  cin >> ab;
  sort(ALL(ab));
  for (auto& p : ab) {
    int a, b;
    tie(a, b) = p;
    k -= b;
    if (k <= 0) {
      cout << a << endl;
      break;
    }
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
using namespace std;

int main()
{
	int ans, n,m,a;
	cin >> n >> m >> a;

	cout << n*m/2 << endl;
}

Measured memory_bytes: 3612
n = int(input())
s = input()
a = s.count('R')
b = 0
ans = max(a,b)
for i in range(n):
    if s[i] == 'R': a -= 1
    else: b += 1
    now = max(a,b)
    ans = min(ans,now)

print(ans)


Measured memory_bytes: 9420
S = input()
mm = ["0"+str(x) for x in range(1,10)]+["10","11","12"]
mmyy = (S[:2] in mm)
yymm = (S[2:] in mm)
a = "NA"

if yymm and mmyy:
  a = "AMBIGUOUS"
elif yymm:
  a = "YYMM"
elif mmyy:
  a = "MMYY"
  
print(a)

Measured memory_bytes: 9012
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;

bool cmp(const string& a,const string& b)
{
  
  if(a.size() != b.size())
    return a.size() < b.size(); 
    
  for(int i=0;i<a.size();i++)
    {
      if(a[i] == b[i])
	continue;
      return a[i] < b[i];
    }
  return false;
}

int main()
{
  map<string,int> ans;
  vector<string> vec;
  int n;
  cin >> n;
  for(int i=0;i<n;i++)
    {
      string name;
      int val;
      cin >> name >> val;
      ans[name] += val;
      vec.push_back(name);
    }
  sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()),vec.end());
  sort(vec.begin(),vec.end(),cmp);

  for(int i=0;i<vec.size();i++)
    cout << vec[i] << " " << ans[vec[i]] << endl;
 
  return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <cstdio> 
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <complex>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#ifndef typeof
#define typeof __typeof__
#endif // typeof
 
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); i++)
#define repby(i, a, b, step) for(typeof(b) i = (a); i < (b); i += (step))
#define repab(i, a, b) repby(i, (a), (b), 1)
#define rep(i, n) repab(i, 0, (n))
#define pb push_back
#define sz(c) int((c).size())

void reverse(string &s)
{
        int i, j;
        char c;

        for (i = 0, j = sz(s) - 1; i < j; i++, j--) {
                c = s[i];
                s[i] = s[j];
                s[j] = c;
        }
}

int main(int argc, char **argv)
{
        string s;
        while (cin >> s) {
                reverse(s);
                cout << s << endl;
        }

  return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
//#define int __int128
//#define ll __int128
//typedef __int128 long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}

const ll M = 1e9 + 7;

const int N = 2e5 + 100;

int c[N];
int n;
int lst[N];
ll dp[N];
void smain() {

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >>c[i];
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1];
        if (lst[c[i]] && lst[c[i]] != i - 1) {
            dp[i] = (dp[i] + dp[lst[c[i]]]) % M;
        }
        lst[c[i]] = i;
    }
    cout << dp[n];
}


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

int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int num = 0;

	while (b <= a)
	{
		b *= 2;
		num++;
	}

	while (c <= b)
	{
		c *= 2;
		num++;
	}

	cout << ((num <= k) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
//#include<math.h>
int ifcl(int p0[2],int p1[2],int p2[2],int p3[2]){
  long long x0=p1[0]-p0[0],x1=p2[0]-p0[0],x2=p3[0]-p0[0],x3=x2-x1,x4=x0-x1,x5=-x1;
  long long y0=p1[1]-p0[1],y1=p2[1]-p0[1],y2=p3[1]-p0[1],y3=y2-y1,y4=y0-y1,y5=-y1;
  long long x6=p2[0]-p1[0],x7=p3[0]-p1[0]/*,x3=x2-x1,x4=x0-x1,x5=-x1*/;
  long long y6=p2[1]-p1[1],y7=p3[1]-p1[1]/*,y3=y2-y1,y4=y0-y1,y5=-y1*/;
  
  long long c1=(x0*y1-y0*x1)*(x0*y2-y0*x2),c2=(x3*y4-y3*x4)*(x3*y5-y3*x5);
  long long d1=x1*(-x4)+y1*(-y4),d2=x2*x7+y2*y7,d3=x1*x2+y1*y2,d4=(-x4)*x7+(-y4)*y7;
  if(c1==0&&c2==0)return (d1>0&&d2>0&&d3>0&&d4>0)?0:1;
  return (c1<=0&&c2<=0)?1:0;
}
/*double dMIN(double a,double b){return a<b?a:b;}
double drpl(int p0[2],int p1[2],int p2[2]){
  int a=p0[1]-p1[1],b=p0[0]-p1[0],c=p0[0]*p1[1]-p1[0]*p0[1];
  int d=p2[1]-p1[1],e=p2[0]-p1[0];
  int f=p2[1]-p0[1],g=p2[0]-p0[0];
  if(a*d+b*e<0||a*f+b*g>0)return dMIN(hypot(d,e),hypot(f,g));
  return abs(p2[0]*a-p2[1]*b+c)/hypot(a,b);
}
double drll(int *p0,int *p1,int *p2,int *p3){
  double l=drpl(p2,p3,p0);
  l=dMIN(l,drpl(p2,p3,p1));
  l=dMIN(l,drpl(p0,p1,p2));
  l=dMIN(l,drpl(p0,p1,p3));
  if(ifcl(p0,p1,p2,p3))l=0;
  return l;
  }*/
int main(){
  int p[4][2],n,i;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<8;i++)scanf(" %d",&p[i/2][i%2]);
    printf("%d\n",ifcl(p[0],p[1],p[2],p[3]));
  }
  return 0;
}

Measured memory_bytes: 600
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);


const int MAX_V=1000;
int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
}

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

int bipartite_matching() {
    int res = 0;
    memset(match, -1, sizeof(match));
    for(int v = 0; v < V; v++) {
        if (match[v] < 0) {
            memset(used, 0, sizeof(used));
            if (dfs(v)) {
                res++;
            }
        }
    }
    return res;
}

int gcd(int a, int b) {
  return b != 0 ? gcd(b, a % b) : a;
}

int main(){
	int m,n;
	while(cin>>m>>n,m|n){
		vi b(m),r(n);
		REP(i,m){
			cin>>b[i];
		}
		REP(i,n){
			cin>>r[i];
		}

		V=n+m;
		REP(i,V){
			G[i].clear();
		}
		REP(i,m){
			REP(j,n){
				if(gcd(b[i],r[j])>1){
					add_edge(i,m+j);
				}
			}
		}
		cout<<bipartite_matching()<<endl;
	}
}

Measured memory_bytes: 3380
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // 整数の入力

    int a = sc.nextInt();
    int b = sc.nextInt();

    int p = a*100 / 8;
    if (( a*100 % 8) !=0) {
      p = p+1;
    }
      //int q = b*10;
    int q = b*10;
    //出力
    if ( b == p/10 ) {
      System.out.println( p );
    } else if ( a == q*10/125) {
       System.out.println( q );
    }else{
      System.out.println(-1);
    }
    
    
  }
}




Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner scanner = new Scanner(System.in);
		Sub sub = new Sub();
	}

	static class Sub
	{
		int i;
		public Sub()
		{
			Scanner scanner = new Scanner(System.in);
			i = scanner.nextInt();
			System.out.println(i*i*i);
		}
	}
}



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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;



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

    V v(6);
    map<int, int> mp;
    rep(i, 6) {
        cin >> v[i];
        mp[v[i]] = i + 1;
    }
    int q;
    cin >> q;
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        x = mp[x], y = mp[y];
        bool swapped = false;
        if (x > y) {
            swap(x, y);
            swapped = true;
        }
        int ans = -1;
        if (x == 1 && y == 2) ans = 3;
        if (x == 1 && y == 3) ans = 5;
        if (x == 1 && y == 4) ans = 2;
        if (x == 1 && y == 5) ans = 4;
        if (x == 2 && y == 3) ans = 1;
        if (x == 2 && y == 4) ans = 6;
        if (x == 2 && y == 6) ans = 3;
        if (x == 3 && y == 5) ans = 1;
        if (x == 3 && y == 6) ans = 5;
        if (x == 4 && y == 5) ans = 6;
        if (x == 4 && y == 6) ans = 2;
        if (x == 5 && y == 6) ans = 4;
        assert(ans != -1);
        if (swapped) ans = 7 - ans;
        cout << v[ans - 1] << endl;
    }
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int a, b;
  cin >> a >> b;

  int ans = 0;
  for(; 1+(a-1)*ans < b; ans++) ;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector <int> A(100001,0);
    ll s=0;
    for (int i=0;i<n;i++) {int a; cin>>a; A[a]++; s+=a;}
    int q;
    cin>>q;
    for (int i=0;i<q;i++) {
		ll b,c;
		cin>>b>>c;
		int x=A[b];
		s+=(c-b)*x;
		cout<<s<<endl;
		A[c]+=x;
		A[b]=0;
		}
    return 0;
}


Measured memory_bytes: 3704
#include<iostream>
#include<algorithm>
#include<cstdint>
using namespace std; // 575

const int MAX = 100000;
int main() {
	static int N, A[MAX], B[MAX];
	cin >> N;
	for (int i = 0;i < N;++ i) cin >> A[i];
	for (int i = 0;i < N;++ i) cin >> B[i];
	
	static int diff[MAX];
	for (int i = 0;i < N;++ i) diff[i] = A[i] - B[i];
	sort(diff, diff+N);
	int negC = 0, posC;
	int64_t neg = 0;
	for (negC = 0;negC < N && diff[negC] < 0;++ negC) neg += diff[negC];
	for (posC = N - 1;posC >= negC && neg < 0;-- posC) neg += diff[posC];
	if (neg < 0) cout << -1;
	else cout << negC + N - posC - 1;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

1. sum(A)<sum(B)なら不可能なので-1
そうでない時を考える
まず、仮に操作するAがあるなら、そのAは必ずBと同値にするのが最適
そして、足りてない奴は全部操作する必要がある→いくつ足りてないのか先に求めておく
次に、多すぎる準備をしている奴は、大きいものから順に動かすのが最適
よって、その大きさでソートして上から使っていけばいい
*/

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <cassert>

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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main() {
    int n, k;
    cin >> n >> k;
    vector<string> a(k);
    REP(i,k) {
        cin >> a[i];
    }

    for (int i=n; i<1e9; i++) {
        string ss = to_string(i);
        bool f=true;
        for (auto b : a) {
            if (ss.find(b) != string::npos)
                f=false;
        }
        if (f){
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, 1, n + 1)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
 using namespace std;
  
int main() {
	string s;
  	cin>>s;
	int ans=100000;
	int a;
	for(int i=0;i<s.size()-2;++i){
 		a = 753 - stoi(s.substr(i,3));
 		a = abs(a);
 		if(ans > a) ans = a;
 	}
 	cout<<ans<<endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define ll long long

int main(void)
{
	int n;
	cin >> n;
	vec<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	vec<ll> sum(n);
	sum[0] = a[0];
	rep(i, n - 1) sum[i + 1] = sum[i] + a[i + 1]; 

	int ans = 0;
	rep(i, n) {
		int prev = i + 1;
		while(1) {
			int next = (int)(upper_bound(a.begin(), a.end(), sum[prev - 1] * 2) - a.begin());
			if (next == n) {
				ans++;
				break;
			} else if (next == prev) break;
			else prev = next;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 10000000000000000
#define int long long
int dp[3010][3010];
int a[3010];
int N; 
int calc(int L = 0, int R = N - 1, int turn = 1) {
    if(L > R) return 0;
    if(dp[L][R] != -INF2) return dp[L][R];
    int ret;
    if(turn) {
        int c1 = calc(L + 1, R, !turn) + a[L];
        int c2 = calc(L, R - 1, !turn) + a[R];
        ret = max(c1, c2);
    } else {
        int c1 = calc(L + 1, R, !turn) - a[L];
        int c2 = calc(L, R - 1, !turn) - a[R];
        ret = min(c1, c2);
    }
    return dp[L][R] = ret;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    
    rep(i, N) cin >> a[i];
    rep(i, 3010) rep(j, 3010) dp[i][j] = -INF2;
    cout << calc() << endl;

    return 0;
}


Measured memory_bytes: 74568
def main():
    n, k = map(int, input().split())
    a = tuple(map(int, input().split()))

    dp = [0] * (k + 1)  # 石がi個で手番が回ってきたら勝てる：1、負ける：0
    for i1 in range(1, k + 1):  # i1：手番が回ってきた時点の石の残数。残数１から始めてｋまでみる。
        for i2 in range(n):
            if i1 - a[i2] >= 0:  # i1-a[i2]がマイナスだと(スライスにより)意図しない値を見てしまうのでパス。
                if dp[i1 - a[i2]] == 0:  # 相手の負けになるようにできるなら、こちらが勝てる。
                    dp[i1] = 1
    if dp[k] == 1:
        print('First')
    else:
        print('Second')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    for(int a, b; cin >> a >> b; ) {
        map<int, int> dict;
        dict[a]++;
        dict[b]++;
        for(int x, y; cin >> x >> y, x + y; ) {
            dict[x]++;
            dict[y]++;
        }
        bool ok = true;
        if(dict[1] % 2 == 0 || dict[2] % 2 == 0) ok = false;
        for(auto p : dict) {
            if(p.first == 1 || p.first == 2) continue;
            if(p.second % 2 != 0) ok = false;
        }
        cout << (ok ? "OK" : "NG") << endl;
    }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int N;
vector<int> cum(110, 0), v(110, 0);

double f(int i, double t){
    if(i == 0) return t;
    if(i == N+1) return cum[N]-t;

    if(t <= cum[i-1]) return v[i]+cum[i-1]-t;
    else if(t <= cum[i]) return v[i];
    else return v[i]+t-cum[i];
}   

int main(){
    cin >> N;
    vector<int> t(N+2);
    for(int i=1; i<=N; i++) cin >> t[i];
    for(int i=1; i<=N; i++) cin >> v[i];

    for(int i=1; i<=N; i++) cum[i] = cum[i-1]+t[i];

    double ans = 0.0;
    double h1 = 0, h2;
    for(double x=0.5; x<=cum[N]; x+=0.5){
        double h2 = 10000000;
        for(int i=0; i<=N+1; i++) h2 = min(h2, f(i, x));
        ans += (h1 + h2) * 0.5 / 2;
        h1 = h2;
    }

    printf("%.8lf\n", ans);
    return 0;
}

Measured memory_bytes: 256
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const LL MOD = 1e9 + 7;
const int N = 40;
const int M = 17;
LL dp[N + 1][1<<M];
LL arr[N + 1];
int psum[M + 5], mapping[1<<M];
int allH, MAXH;
vector<int> num;

inline int normalize(int x) {
	x &= MAXH;
	return mapping[x];
}

inline LL solve(int idx,int bm) {
	bm = normalize(bm);
	if(bm == -1) return 0;
	if(idx == 0) return bm != -1;
	LL &res = dp[idx][bm];
	if(res != -1) return res;
	res = 0;
	int nbm = bm * 2 + 1;
	for(int i = 1;i <= 10;i++) {
		res += solve(idx - 1, nbm);
		nbm *= 2;
	}
	res %= MOD;
	return res;
}


vector<int> parse;

void pre() {
	for(int i = 1;i <= MAXH;i++) {
		mapping[i] = i;
		parse.clear(); num.clear();
		int x = i;
		while(x) {
			parse.PB(x%2);
			x /= 2;
		}
		reverse(parse.begin(), parse.end());
		int ctr = 0;
		for(int j = 0;j < parse.size();j++) {
			if(j != 0 && parse[j] == 1) {
				num.PB(ctr + 1);
				ctr = 0;
			}
			else if(parse[j] != 1) ctr++;
		}
		num.PB(ctr + 1);
		int id = 1;
		ctr = 0;
		for(auto x: num) {
			if(id == 4) id++;
			ctr += x;
			if(ctr == arr[id]) {
				id++;
				ctr = 0;
			}
		}
//		cout<<"I "<<i<<": ";
//		for(auto x: num) cout<<x<<" ";
//		cout<<mapping[i]<<endl;
		if(id == 4) mapping[i] = -1;
	}
}

void hora(int tc) {
	memset(dp, -1, sizeof dp);
	int n;
	cin>>n>>arr[1]>>arr[2]>>arr[3];
	allH = arr[1] + arr[2] + arr[3];
	MAXH = ((1<<allH) - 1);
	pre();
	LL total = solve(n, 0);
	LL alltotal = 1;
	for(int i = 1;i <= n;i++) alltotal = alltotal * 10 % MOD;
	cout<<(alltotal - total + MOD) % MOD<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 42752
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    string str[4];
    string InputStr;
    str[0]="Sunny";
    str[1]="Cloudy";
    str[2]="Rainy";
    str[3]="Sunny";
    cin>>InputStr;
    for(int i=0;i<3;i++){
        if(InputStr==str[i]){
           cout <<str[i+1]<< endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
a = str(input())
q = int(input())
for i in range(q):
    ope = list(map(str, input().split(" ")))
    if ope[0] == "replace":
        a_list = list(a)
        a = ""
        for i in range(int(ope[2])-int(ope[1])+1):
            del a_list[int(ope[1])]
        a_list.insert(int(ope[1]), ope[3])
        for i in a_list:
            a += i
    elif ope[0] == "reverse":
        new_a = a[int(ope[1]):int(ope[2])+1]
        a = a.replace(a[int(ope[1]):int(ope[2])+1], new_a[::-1])
    elif ope[0] == "print":
        print(a[int(ope[1]):int(ope[2])+1])


Measured memory_bytes: 5640
N,M=[int(a) for a in input().split(" ")]
PY = [[int(a) for a in input().split(" ")] for i in range(M)]
from collections import defaultdict
dic = defaultdict(list)
for i, (p, y) in enumerate(PY):
    dic[p].append((i, y))
ans = []
fill6 = lambda s:(6-len(s))*"0"+s
for p, arr in dic.items():
    s = fill6(str(p))
    arr = sorted(arr, key=lambda t: t[1])
    ans += [(j, s+fill6(str(i+1))) for i, (j, _) in enumerate(arr)]
for j, idx in sorted(ans, key=lambda t:t[0]):
    print(idx)

Measured memory_bytes: 110552
s = [i for i in input()]

flag = 0
for i in range(len(s)):
    if (i%2==0):
        if (s[i]=='R' or s[i]=='D' or s[i]=='U'):
            pass
        else:
            flag = 1
    else:
        if (s[i]=='L' or s[i]=='D' or s[i]=='U'):
            pass
        else:
            flag = 1
        
if (flag ==0):
    print('Yes')
elif(flag==1):
    print('No')

Measured memory_bytes: 38384