akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;

int Search(long long int box) {
	long long int bag = N;
	while (bag%box == 0)bag /= box;
	return (bag%box) == 1;
}

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

	cin >> N >> M;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	long long int sum = accumulate(v.begin(), v.end(),0LL);
	for (int i = 0; i < M; i++) {
		if (v[i]*M*4<sum) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}

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

int main(){
    int a,b=1,c=0,d=0;
    cin>>a;
    cin>>c;
    cin>>d;
    int e=0;
    int f=0;
    int amari=0;
    for(long int i=0;i<50000000;i++){
        e=a*b;
        b++;
        amari=e%c;
            if(amari==d){
            f=1;
            }
        
        }
        if(f>0){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
}


Measured memory_bytes: 256
N, K = map( int, input().split())
H = list( map( int, input().split()))
dp = [0]*N
for i in range(1,N):
    h = H[i]
    now = dp[i-1] + abs( h - H[i-1])
    for j in range( max(i-K,0), i):
        if now > dp[j] + abs( h - H[j]):
            now = dp[j] + abs( h - H[j])
    dp[i] = now
print( dp[-1])


Measured memory_bytes: 52464
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int col[100010];
vector<int> G[100010];
int ca = 0, cb = 0;
bool oddcycle = false;

void solve(int p, int c, int prev=-1) {
    col[p] = c;
    if(c == 0) ca++;
    else cb++;
    for(auto to : G[p]) {
        if(to == prev) continue;
        if(col[to] == col[p]) oddcycle = true;
        else if(col[to] < 0) solve(to, c^1, p);
    }
}

signed main() {
    memset(col, -1, sizeof(col));
    int N, M; cin >> N >> M;
    rep(i,0,M) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    solve(0, 0);
    if(oddcycle) {
        cout << N * (N-1) / 2 - M << endl;
    }
    else {
        cout << ca * cb - M << endl;
    }
    return 0;
}

Measured memory_bytes: 8064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int dp[301][301][301];

class DReversedLCS {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      string s; cin >> s;
      int k; cin >> k;
      int n = s.size();
      rep(i, n) rep(j, n) rep(k, n) {
        dp[i][j][k] = 0;
      }
      // d = 0;
      rep(i, n) {
        dp[i][i][0] = 1;
      }

      // d >= 2
      for(int d=0; d<n-1; d++) {
        for(int i=0; i<n; i++) {
          int j=i+d;
          for(int r=0; r<=k; r++) {
            if (j+1<n) chmax(dp[i][j+1][r], dp[i][j][r]);
            if (i-1>=0 && j<n) chmax(dp[i-1][j][r], dp[i][j][r]);
            if (j+1<n) {
              if (s[i]==s[j+1]) {
                chmax(dp[i][j+1][r], dp[i+1][j][r]+2);
              } else {
                chmax(dp[i][j+1][r], dp[i+1][j][r]);
              }
              chmax(dp[i][j+1][r+1], dp[i+1][j][r]+2);
            }
            if (i-1>=0 && j<n) {
              if (s[i-1]==s[j]) {
                chmax(dp[i-1][j][r], dp[i][j-1][r]+2);
              } else {
                chmax(dp[i-1][j][r], dp[i][j-1][r]);
              }
              chmax(dp[i-1][j][r+1], dp[i][j-1][r]+2);
            }
          }
        }
      }
      int ans = 0;
      rep(i, n) rep(j, n) rep(r, k+1) {
        chmax(ans, dp[i][j][r]);
      }
      cout << ans << endl;
    }
};

signed main() {
  DReversedLCS solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 106880
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int n, m;
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			n = sc.nextInt();
			m = sc.nextInt();
			if((n|m) == 0) break;
			LinkedList<Integer> player = new LinkedList<Integer>();
			for(int i=1;i<=n;i++)player.addLast(i);
			Iterator<Integer> p = player.iterator();
			for(int i=1;i<=m;i++) {
				String s = sc.next();
				if(!p.hasNext()) p = player.iterator();
				p.next();
				if(player.size() == 1) continue;
				if(i%15 == 0 && s.equals("FizzBuzz"));
				else if(i%5 == 0 && s.equals("Buzz"));
				else if(i%3 == 0 && s.equals("Fizz"));
				else if(i%3 != 0 && i%5 != 0 && s.equals("" + i));
				else {
//					System.out.println(s + " " + s.equals("" + i));
					p.remove();
				}
			}
			System.out.print(player.removeFirst());
			for(int i: player) {
				System.out.print(" " + i);
			}
			System.out.println();
		}
	}

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

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
typedef pair<lint, lint> P;

signed main(){
	lint N, W; cin >> N >> W;
	vector<P> vec(N);
	for(int i = 0; i < N; i++) cin >> vec[i].first >> vec[i].second;
	sort(vec.begin(), vec.end());
	vector<lint> weight(N), value(N);
	for(int i = 0; i < N; i++) weight[i] = vec[i].first, value[i] = vec[i].second;
	vector<vector<lint> > dp(N + 10, vector<lint> (W + 10, 0));
	for(int i = 0; i < N - 1; i++){
		for(int w = 0; w < W; w++){
			if (w >= weight[i]) {
        if (dp[i + 1][w] < dp[i][w - weight[i]] + value[i]) {
          dp[i + 1][w] = dp[i][w - weight[i]] + value[i];
        }
      }
      if (dp[i + 1][w] < dp[i][w]) {
        dp[i + 1][w] = dp[i][w];
      }
    }
	}
	lint ans = 0;
    for(lint i = 0;i < N; i++){
        ans = max(ans, dp[i][W - 1] + value[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 71296
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

int main() {
	int n;
	int k;
	int sum = 0;
	cin >> n >> k;
	vector<int> data(n);
	ff(i, 0, n) {
		cin >> data.at(i);
		sum += data.at(i);
	}
	st(data);
	rvs(data);
	int ans = 0;
	ff(i, 0, k) {
		ans += data.at(i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/*
ID: Aman Raj
LANG: C++
TASK: prefix
*/
//#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
//#define mod 13
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;
   ll power(ll a,ll b)//a raised to power b
   {  if(b==0)return 1;if(b==1)return a;
       ll c=power(a,b/2);
       c*=c;c%=mod;if(b%2==1)c*=a;c%=mod;
        return c;
   }
   ll mi(ll a)
   {
       return power(a,mod-2);
   }

   int main()
{   ll n;cin>>n;
    vector<ll> vmon(n+1),v(n);
     for(ll i=0;i<=n;i++)cin>>vmon[i];
     for(ll i=0;i<n;i++)cin>>v[i];
      ll ans=0;
       for(ll i=0;i<n;i++)
       {
           if(v[i]<=vmon[i])ans+=v[i];
           else
           {
               ans+=vmon[i];v[i]-=vmon[i];if(vmon[i+1]>=v[i])ans+=v[i];else ans+=vmon[i+1];
               vmon[i+1]-=(v[i]);
               if(vmon[i+1]<=0)vmon[i+1]=0;
           }
       }

       cout<<ans;

    return 0;
 }


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e15;
int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    vector<long long> ans(N - 1, 0);
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            long long u;
            u = min(j - i, abs(X - i) + 1 + abs(Y - j));
            ans[u - 1]++;
        }
    }
    for(int i = 0; i < N - 1; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int n, k;
ll sum, cnt, ans;
Pair ss[N];
Map map;
std::stack< Pair > s;

inline bool cmp(const Pair &a, const Pair &b) {
    return a.se > b.se;
}

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) ss[i].fi = read(), ss[i].se = read();
    std::sort(ss + 1, ss + n + 1, cmp);
    for (int i = 1; i <= k; i++) {
        if (!map.count(ss[i].fi)) map[ss[i].fi] = 1, cnt++;
        else s.push(ss[i]);
        sum += ss[i].se;
    }
    ans = cnt * cnt + sum;
    for (int i = k + 1; i <= n; i++) {
        if (s.empty()) break;
        if (map.count(ss[i].fi)) continue;
        Pair tmp = s.top();
        s.pop();
        sum -= tmp.se;
        sum += ss[i].se;
        cnt++;
        map[ss[i].fi] = 1;
        ans = std::max(ans, cnt * cnt + sum);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
        ll n; cin >> n;
        map <string, int> m;
        for (ll x = 0; x < n; ++x){
            string s; cin >> s;
            m[s]++;
        }
        cout << "AC x " << m["AC"] << endl;
        cout << "WA x " << m["WA"] << endl;
        cout << "TLE x " << m["TLE"] << endl;
        cout << "RE x " << m["RE"] << endl;
    return 0;
}



Measured memory_bytes: 3644
#include <stdio.h>

int main(){
  int a[6], b[6], c[6], i;

  for(i = 0 ; i < 6 ; i++){
    scanf("%d",&a[i]);
  }
  for(i = 0 ; i < 6 ; i++){
    scanf("%d",&b[i]);
  }
  for(i = 0 ; i < 6 ; i++){
    scanf("%d",&c[i]);
  }
  a[0] = a[3] - a[0];
  a[1] = a[4] - a[1];
  if(a[1] < 0){
    a[0] -= 1;
    a[1] = 60 + a[1];
  }
  a[2] = a[5] - a[2];
  if(a[2] < 0){
    a[1] -= 1;
    a[2] = 60 + a[2];
    if(a[1] < 0){
      a[0] -= 1;
      a[1] = 60 + a[1];
    }
  }

  b[0] = b[3] - b[0];
  b[1] = b[4] - b[1];
  if(b[1] < 0){
    b[0] -= 1;
    b[1] = 60 + b[1];
  }
  b[2] = b[5] - b[2];
  if(b[2] < 0){
    b[1] -= 1;
    b[2] = 60 + b[2];
    if(b[1] < 0){
      b[0] -= 1;
      b[1] = 60 + b[1];
    }
  }

  c[0] = c[3] - c[0];
  c[1] = c[4] - c[1];
  if(c[1] < 0){
    c[0] -= 1;
    c[1] = 60 + c[1];
  }
  c[2] = c[5] - c[2];
  if(c[2] < 0){
    c[1] -= 1;
    c[2] = 60 + c[2];
    if(c[1] < 0){
      c[0] -= 1;
      c[1] = 60 + c[1];
    }
  }

  printf("%d %d %d",a[0],a[1],a[2]);
  printf("\n");
  printf("%d %d %d",b[0],b[1],b[2]);
  printf("\n");
  printf("%d %d %d",c[0],c[1],c[2]);
  printf("\n");

  return 0;

}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(N), B(M);
    for (int i=0;i<N;i++) cin >> A[i];
    for (int i=0;i<M;i++) cin >> B[i];
    vector<ll> sumA(N+1),sumB(M+1);
    for (int i=0;i<N;i++) sumA[i+1] = sumA[i] + A[i];
    for (int i=0;i<M;i++) sumB[i+1] = sumB[i] + B[i];
    int ans = 0;
    for (int i=0;i<=N;i++){
        ll sum = sumA[i];
        int left = -1;
        int right = M + 1;
        while (right - left > 1){
            int mid = (left+right)/2;
            if (K-sum < sumB[mid]) right = mid;
            else left = mid;
        }
        if (left > -1){
            ans = max(ans, i + left);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 7956
#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>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

ll modpow(ll n,ll r){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%MOD;
    n = n*n%MOD;
    r >>= 1;
  }
  return res;
}

ll comb(int n,int r){
  ll res = 1;
  for(ll i = n;i >= n-r+1;i--)res *= i;
  for(int i = r;i > 0;i--)res /= i;
  return res;
}

int main(){

  ll res = 0;
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i,n)cin >> v[i];
  sort(ALL(v));
  rep(j,n-1){
    ll k = (n-j-1)*modpow(2,n-j-2)%MOD;
    k = (k+modpow(2,n-j-1))%MOD;
    k = k*v[j]%MOD;
    k = k*modpow(2,j)%MOD;
    res = (res+k)%MOD;
  }
  res = (res+modpow(2,n-1)*v[n-1])%MOD;
  res = res*modpow(2,n)%MOD;
  cout << res << "\n";
  

  return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
typedef long long ll;
const int INF = 1<<29;
const int N = 1e6 + 9;
ll a[N];
bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b)
{
    if(a.second == b.second){
        return a.first < b.first;
    }
    return a.second < b.second;
}
int main()
{
    fio;
    ll a, b;
    cin >> a >> b;
    for(int i = 1; i <= 100000; i ++)
    {
        ll k = (i * 8) / 100;
        ll kk = (i * 10) / 100;
        if(k == a && kk == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#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);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n;
struct stick {int pr, qb, ri, bi;};

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

long long lcm(long long a, long long b) {
    long long g = gcd(a, b);
    return a / g * b;
}

int dfs(int now, vector<vector<stick>>& st) {
    int p = st[now][0].pr;
    int q = st[now][0].qb;
    int r = st[now][0].ri;
    int b = st[now][0].bi;
    int wr = 1;
    int wb = 1;
    if (r == 0 && b == 0) return p + q;
    if (r != 0) wr = dfs(r, st);
    if (b != 0) wb = dfs(b, st);
    int l = lcm(wr * p, wb * q);
    return l / p + l / q;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    while (n != 0) {
        vector<vector<stick>> st(105);
        int cnt[105] = {};
        rep(i, n) {
            int p, q, r, b;
            cin >> p >> q >> r >> b;
            int g = gcd(p, q);
            p /= g;
            q /= g;
            st[i + 1].pb(stick{p, q, r, b});
            cnt[r] += 1;
            cnt[b] += 1;
        }
        int s = 0;
        rep(i, n + 1) if (cnt[i] == 0) {s = i; break;}
        int ans = dfs(s, st);
        cout << ans << endl;
        cin >> n;
    }

}

Measured memory_bytes: 3108
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

def f(n):
    if n % 2:
        return 3 * n + 1
    else:
        return n // 2

x = ii()
d = defaultdict(int)
d[x] = 1
ind = 1
while True:
    ind += 1
    if d[f(x)] == 1:
        print(ind)
        exit()
    d[f(x)] += 1
    x = f(x)




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

int main(void){
    int a;
    int b;
    int i;
    int n;
    int count;
    
    cin >> a;
    vector<int> tab(a);
    i = -1;
    while (++i < a)
    {
        cin >> b;
        tab.at(i) = b;
    }
    count = 0;
    n = 0;
    i = -1;
    while (++i < a)
    {
        count++;
        if (tab.at(n) == 2)
        {
            cout << count << endl;
            return (0);
        }
        n = tab.at(n) - 1;
    }
    cout << -1 << endl;
    return (0); 
}


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

using namespace std;

int main()
{
    long long n,i,j,x,y,k;
    cin >> n;
    vector<vector<long long> > dp(100001);
    for(i=0;i<=n;i++){
        vector<long long> aux(3,0);
        dp[i]=aux;
    }
    vector<vector<int> > v;
    for(i=0;i<n;i++){
        vector<int> aux;
        cin >> x; aux.push_back(x);
        cin >> x; aux.push_back(x);
        cin >> x; aux.push_back(x);
        v.push_back(aux);
    }

    dp[0][0]=v[0][0];
    dp[0][1]=v[0][1];
    dp[0][2]=v[0][2];

    for(i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+v[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+v[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+v[i][2];
    }
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]) );
    return 0;
}


Measured memory_bytes: 12212
#include <stdio.h>

int main(){
  int i,j,n,u,k,num;
  int A[1000][1000];
  scanf("%d",&n);
  for(i=0;i<=n;i++){
    A[i][i] = 0;
  }
 
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    if(k == 0){
      continue;
    }
    for(j=0;j<k;j++){
      scanf("%d",&num);
      A[u-1][num-1] = 1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j == n-1){
	printf("%d\n",A[i][j]);
      }
      else printf("%d ",A[i][j]);
    }
   }

  return 0;
  
}



Measured memory_bytes: 2116
#include"bits/stdc++.h" 
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
vector<int>u;
vector<int>w;
vector<int>::iterator it;
priority_queue<int>pq;
const int N=1e5+10;
/*--------------------------hbp16@hbp16-Inspiron-3543:-$------------------------------*/
int main(int argc, char const *argv[])
{
	ll n,a,b;
	cin>>n>>a>>b;

	ll tim=n/(a+b);
	ll md = n%(a+b);

	cout<<a*tim+min(a,md);
	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int costs[40][40];
vector<int> vs[3];
int scosts[3][40];

int main(void) {
  int n;
  int nColor;
  scanf("%d%d", &n, &nColor);
  REP(i, nColor) REP(j, nColor) {
    scanf("%d", &costs[i][j]);
  }
  REP(i, n) REP(j, n) {
    int v;
    scanf("%d", &v);
    vs[(i+j)%3].push_back(v-1);
  }
  REP(i, 3) {
    REP(c, nColor) {
      REP(j, vs[i].size()) {
        scosts[i][c] += costs[vs[i][j]][c];
      }
    }
  }
  int res = 2e9;
  REP(c1, nColor) REP(c2, nColor) REP(c3, nColor){
    if(c1 == c2 || c2 == c3 || c3 == c1) {
      continue;
    }
    int cur = scosts[0][c1] + scosts[1][c2] + scosts[2][c3];
    // cerr << c1 << " " << c2 << " " << c3 << " " << cur << endl;
    res = min(res, cur);
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ft first
#define se second
#define all(x) x.begin(),x.end()
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define mk(a,b) make_back(a,b)
#define endll "\n"

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    bitset<101> b(0);
    while(k--){
        int d;cin>>d;
        for(int i=0;i<d;i++){
            int a;cin>>a;
            b[a]=1;
        }
    }
    cout<<n-b.count()<<endl;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x, n;
    cin >> x >> n;
    vi p(n);
    rep(i, n) cin >> p[i];
    map<int, bool> mp;
    rep(i, n) mp[p[i]] = true;
    int a = 0;
    while (1) {
        if (!mp[x-a]) {
            cout << x-a << endl;
            return 0;
        }
        if (!mp[x+a]) {
            cout << x+a << endl;
            return 0;
        }
        ++a;
    }
    return 0;
}


Measured memory_bytes: 3640
N = int(input())
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    if i == 0:
        ans += B[0]
        continue
    if i == N - 1:
        ans += B[-1]
        continue
    ans += min(B[i - 1], B[i])
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

/**
 * @author yoshizaki
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int first = scanner.nextInt();
        int second = scanner.nextInt();
        int therd = scanner.nextInt();
        int[] words = {first, second, therd}; 
        String answer = "NO";
        
        int word = 0;
        int fCount = 0;
        int sCount = 0;
                
        for (int w :words) {
            if (w == 5) fCount++;
            if (w == 7) sCount++;
        }
        if(fCount == 2 && sCount == 1) answer = "YES";
        
        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
using namespace std;
string ab[26] = {
"100101","10011010","0101","0001","110",
"01001","10011011","010000","0111","10011000",
"0110","00100","10011001","10011110","00101",
"111","10011111","1000","00110","00111",
"10011100","10011101","000010","10010010","10010011",
"10010000"};
string ctoi(char c) {
    if (c==' ') return "101";
    else if (c=='\'') return "000000";
    else if (c==',') return "000011";
    else if (c=='-') return "10010001";
    else if (c=='.') return "010001";
    else if (c=='?') return "000001";
    else if (c>='A'&&c<='Z') return ab[c-'A'];
}
char itoc(string num) {
    if (num=="00000") return 'A';
    if (num=="00001") return 'B';
    if (num=="00010") return 'C';
    if (num=="00011") return 'D';
    if (num=="00100") return 'E';
    if (num=="00101") return 'F';
    if (num=="00110") return 'G';
    if (num=="00111") return 'H';
    if (num=="01000") return 'I';
    if (num=="01001") return 'J';
    if (num=="01010") return 'K';
    if (num=="01011") return 'L';
    if (num=="01100") return 'M';
    if (num=="01101") return 'N';
    if (num=="01110") return 'O';
    if (num=="01111") return 'P';
    if (num=="10000") return 'Q';
    if (num=="10001") return 'R';
    if (num=="10010") return 'S';
    if (num=="10011") return 'T';
    if (num=="10100") return 'U';
    if (num=="10101") return 'V';
    if (num=="10110") return 'W';
    if (num=="10111") return 'X';
    if (num=="11000") return 'Y';
    if (num=="11001") return 'Z';
    if (num=="11010") return ' ';
    if (num=="11011") return '.';
    if (num=="11100") return ',';
    if (num=="11101") return '-';
    if (num=="11110") return '\'';
    if (num=="11111") return '?';
}
int main() {
    string str;
    while (getline(cin,str)) {
        string num="";
        for (int i=0; i<str.length(); i++) num+=ctoi(str[i]);
        int cnt=0;
        string temp="", res="";
        for (int i=0; i<num.length(); i++) {
            cnt++;
            temp+=num[i];
            if (cnt==5) {
                res+=itoc(temp);
                cnt=0;
                temp="";
            }
        }
        if (temp.length()>0) {
            while (temp.length()<5) {
                temp+='0';
            }
            res+=itoc(temp);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();

		long sum = n * (n + 1l) / 2l;
		long fizzsum = 3l * (n / 3l * (n / 3l + 1l) / 2l);
		long buzzsum = 5l * (n / 5l * (n / 5l + 1l) / 2l);
		long fizzbuzzsum = 15l * (n / 15l * (n / 15l + 1l) / 2l);
		out(sum - fizzsum - buzzsum + fizzbuzzsum);

	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

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

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


Measured memory_bytes: 35812
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        IO.INT();
        string[] m = IO.STRING(' ');
        IO.INT();
        string[] o = IO.STRING(' ');
        int c = 0;
        foreach (string b in o)
        {
            if (m.Contains(b)) { c++; }
        }
        IO.WRITE(c);
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
        public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    list<int> v;

    auto pointer = v.end();
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == 0) {
            int x;
            cin >> x;
            pointer = v.insert(pointer, x);
        } else if (a == 1) {
            int b;
            cin >> b;
            if (b > 0) for (int i = 0; i < b; i++) pointer++;
            else for (int i = 0; i > b; i--) pointer--;
        } else {
            pointer = v.erase(pointer);
        }
    }

    for (auto x:v) cout << x << endl;
    return 0;
}


Measured memory_bytes: 18620
import sys

def gen_list(lst):
    length = len(lst)
    dp = [{}] * length
    dp[0] = {lst[0]: True}
    dp[0][0] = True

    # s[i]までで出る数字
    for i in range(1, length):
        s = lst[i]
        dp[i] = dp[i-1]
        keys = [k for k in dp[i].keys()]
        for val in keys:
            dp[i][val + s] = True
    
    return sorted(dp[length-1].keys(), reverse=True)

N = int(input())
s = [int(input()) for _ in range(N)]

for m in gen_list(s):
    if m % 10 != 0:
        print(m)
        sys.exit()

print('0')

Measured memory_bytes: 3924
n = int(input())
w = [input() for _ in range(n)]
t = []

w_s = w.copy()
w_s = set(w_s)
w_s = list(w_s)

if len(w) != len(w_s):
    print("No")
    exit()

for i in range(n-1):
    a = w[i]
    b = w[i+1]
    if a[-1] != b[0]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3064
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
  int N;

  cin >> N;
  ll A[N],B[N],C[N];

  for(int i=0;i<N;i++) cin >> A[i];

  for(int i=0;i<N;i++) cin >> B[i];

  for(int i=0;i<N;i++) cin >> C[i];

  sort(A, A+N);
  sort(B, B+N);
  sort(C, C+N);

  vector<P> compare;

  int front = 0;
  int back = 0;
  for(int i=0;i<N;i++){
  	while(A[front] < B[i] && front<N){
  		front++;
  	}
  	while(C[back] <= B[i] && back<N){
  		back++;
  	}
  	compare.push_back(make_pair(front, N-back));
  	//cout << compare[i].first << " " << compare[i].second <<endl;
  }

  ll ans = 0;
  for(int i=0;i<N;i++){
  	ans += (compare[i].first)*(compare[i].second);
  }
  cout << ans <<endl;

  return 0;
}










Measured memory_bytes: 4724
#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

typedef long long ll;

using namespace std;
int main(){
    string s;
    cin >> s;
    cout << s.substr(0, 5) << " " << s.substr(6, 7) << " " << s.substr(14, 5); 
}


Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 110000;
int par[maxn];
vector<pii> reles[maxn];
pii e[2][maxn];
set<pii> se[2];

int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
}

pii normp(int x, int y) {
    if (x > y) swap(x, y);
    return {x, y};
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    forn(i, n) par[i] = i;
    forn(k, 2) forn(i, n - 1) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        pii p = normp(x, y);
        e[k][i] = p;
        se[k].insert(p);
        reles[x].pb({i, k});
        reles[y].pb({i, k});
    }

    vector<pii> q;
    for (auto w: se[0]) {
        if (se[1].count(w)) q.pb(w);
    }

    forn(cur, q.size()) {
        pii p = q[cur];
        int x = root(p.fi), y = root(p.se);
        if (x == y) continue;
        if (reles[x].size() > reles[y].size()) swap(x, y);
        par[x] = y;
        for (auto w: reles[x]) {
            int id = w.fi, k = w.se;
            se[k].erase(e[k][id]);
            e[k][id].fi = root(e[k][id].fi);
            e[k][id].se = root(e[k][id].se);
            e[k][id] = normp(e[k][id].fi, e[k][id].se);
            se[k].insert(e[k][id]);
            if (se[k ^ 1].count(e[k][id])) q.pb(e[k][id]);
            reles[y].pb(w);
        }
        reles[x].clear();
    }

    bool ok = true;
    forn(i, n) ok &= root(i) == root(0);
    cout << (ok ? "YES" : "NO") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 57064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

using namespace std;

int main(){
  int A, B; cin >> A >> B;
  if ((A>B && B!=1) || (A==1 && B!=1)) cout << "Alice" << endl;
  else if ((A<B && A!=1) || (B==1 && A!=1)) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int h = s.nextInt();
    int w = s.nextInt();
    while (h != 0 && w != 0) {
      for (int i = 0; i < h; i++) {
        String st = "";
        for (int j = 0; j < w; j++) {
          if (i % 2 == 0 && j % 2 == 0)
            st += "#";
          else if (i % 2 == 0 && j % 2 != 0)
            st += ".";
          else if (i % 2 != 0 && j % 2 == 0)
            st += ".";
          else
            st += "#";
        }
        System.out.println(st);
      }
      System.out.println();
      h = s.nextInt();
      w = s.nextInt();
    }
    s.close();
  }
}



Measured memory_bytes: 55652
s = input()
t = input()
a = 0

if len(s) == len(t)-1:
    for i in range(len(s)):
        if s[i] != t[i]:
            a = 1
            break
else:
    a = 1
    
if a == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61852
n,k=map(int,input().split())

s=input()
ANS=[]
cnt=0
if s[0]=='L':
    for i in range(n-1):
        if s[i]=='R' and s[i+1]=='L':
            cnt+=1
    if s[n-1]=='R':
        cnt+=1
    if cnt<=k:
        ANS.append(n-1)
    else:
        if s[n-1]=='R':
            ANS.append(n-1-1-2*(cnt-k-1))
        else:
            ANS.append(n-1-2*(cnt-k))
CNT=0
if s[0]=='R':
    for i in range(n-1):
        if s[i]=='L' and s[i+1]=='R':
            CNT+=1
    if s[n-1]=='L':
        CNT+=1
    if CNT<=k:
        ANS.append(n-1)
    else:
        if s[n-1]=='L':
            ANS.append(n-1-1-2*(CNT-k-1))
        else:
            ANS.append(n-1-2*(CNT-k))

print(max(ANS))

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

using namespace std;

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

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    string s, t;

    cin >> s >> t;

    int a, b;

    cin >> a >> b;

    map <string, int> mapa;

    mapa[s] = a;
    mapa[t] = b;

    string u;

    cin >> u;

    mapa[u] -= 1;

    cout << mapa[s] << ' ' << mapa[t] << '\n';

    return 0;
}


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

int main(){
  int h, w;
  while(1){
    cin >> h >> w;
    if(h==0 && w==0){break;}
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
	if(j==0 || j==w-1 || i==0 || i==h-1){
	  cout <<"#";
	}else{
	  cout << ".";
	}
      }
      cout << "\n";
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 1120
import Control.Monad
import Data.Maybe

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- getInts
  bs <- getInts
  let as'= decide as
      bs' = reverse $ decide (reverse bs)
      ms = zipWith min as bs
      xs = solve as' bs' ms
--  print as'
--  print bs'
--  print xs
  print $ fromMaybe 0 (solve' <$> xs)
  

getInts :: IO [Int]
getInts = map read . words <$> getLine

decide :: [Int] -> [Int]
decide ns = go (zip ns (0 : init ns))
  where
    go [] = []
    go ((c, n):xs)
      | c == n = -c : go xs
      | otherwise = c : go xs

solve :: [Int] -> [Int] -> [Int] -> Maybe [Int]
solve as bs mins = go as bs mins
  where
    go [] _ _ = Just []
    go (x:xs) (y:ys) (m:ms)
      | x == y && x > 0= go xs ys ms
      | y < 0 && x < 0 = (m :) <$> go xs ys ms
      | y + x <= 0 = go xs ys ms
      | otherwise = Nothing

solve' :: [Int] -> Int
solve' ns = go ns
  where
    go [] = 1
    go (n:ns) = (n * go ns) `mod` 1000000007


Measured memory_bytes: 143740
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
//ll const mod=998244353;
ll const mod = 1e9 + 7;
const ll MAX = 1000005;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }


int main() {
    int n, C;
    cin >> n >> C;
    vvi d(C, vi(C));
    vvi c(n, vi(n));
    rep(i, C)rep(j, C) {
        cin >> d[i][j];
    }
    rep(i, n)rep(j, n) {
        cin >> c[i][j];
        c[i][j]--;
    }

    vvi a(3);
    rep(i, n)rep(j, n) {
        a[(i + j + 2) % 3].push_back(c[i][j]);
    }
    P res[3][3];
    rep(i, 3)rep(j, 3)res[i][j].fs = INF;
    rep(i, C) {
        int tmp = 0;
        for (auto x : a[0]) {
            tmp += d[x][i];
        }
        P s;
        s.first = tmp, s.second = i;
        rep(j, 3) {
            if (s < res[0][j]) {
                swap(s, res[0][j]);
            }
        }

        tmp = 0;
        for (auto x : a[1]) {
            tmp += d[x][i];
        }
        s.first = tmp, s.second = i;
        rep(j, 3) {
            if (s.fs < res[1][j].fs) {
                swap(s, res[1][j]);
            }
        }

        tmp = 0;
        for (auto x : a[2]) {
            tmp += d[x][i];
        }
        s.fs = tmp, s.sc = i;
        rep(j, 3) {
            if (s.fs < res[2][j].fs) {
                swap(s, res[2][j]);
            }
        }
    }
    int ans = INF;
    rep(i, 3)rep(j, 3)rep(k,3) {
        if (res[0][i].sc == res[1][j].sc || res[1][j].sc == res[2][k].sc||res[0][i].sc==res[2][k].sc)continue;
        chmin(ans, res[0][i].fs + res[1][j].fs + res[2][k].fs);
    }
    cout << ans<< endl;
    return 0;
}

Measured memory_bytes: 5384
n=int(input())
l=[]
for i in range(n-1):
    x,y,z=map(int,input().split())
    l.append([x,y,z])

for i in range(n):
    t=0
    for j in range(i,n-1):
        if t<l[j][1]:
            t=l[j][1]
        elif t%l[j][2]==0:
            pass
        else:
            t+=l[j][2]-t%l[j][2]
        t+=l[j][0]
    print(t)

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

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    string S;
    cin >> S;

    int max_count = 0;
    int count = 0;
    REP(i, S.length()){
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            count++;
        } else {
            max_count = max(max_count, count);
            count = 0;
        }
    }

    max_count = max(max_count, count);
    cout << max_count << endl;

    return 0;
}

Measured memory_bytes: 256