akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int p[212345];
int dp[212345];
int main(){
  int n;
  cin>>n;
  rep(i,n)cin>>p[i];

  int answ=0;

  rep(i,n){
    dp[p[i]]=dp[p[i]-1]+1;
    answ=max(answ,dp[p[i]]);
  }

  cout<<n-answ<<endl;




}


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

int N,M;
vector<pair<int, int>> Jobs;
vector<int> worked;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

int main() {
  cin >> N >> M;
  int a,b;
  rep(i, N) {
    scanf("%d %d", &a, &b);
    Jobs.push_back(make_pair(a, b));
  }
  rep(i, M) {
    worked.push_back(i+1);
  }
  sort(Jobs.begin(), Jobs.end(), compare_by_b);
  long long ans=0;
  rep(i, N) {
    auto day = lower_bound(worked.begin(), worked.end(), Jobs[i].first);
    if(day != worked.end()) {
      ans += Jobs[i].second;
      worked.erase(day);
    }
    /* cout << "days" << endl; */
    /* rep(i, worked.size()) { */
    /*   cout << worked[i] << endl; */
    /* } */
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30

int main()
{
	int a, b;

	cin >> a >> b;
	cout << a+b/2 << endl;

	return 0;
}


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

int main(){
    int s;
    cin >> s;
    int cou=0;
    //string hoge=s;

    int fs,bs;

    fs = bs = s;
    for(int i=0;i<s;i++){
        string fst=to_string(fs);
        //int bst=bs;
        string bst=to_string(bs);
        string hoge=fst;
        string huga=bst;
        reverse(hoge.begin(),hoge.end());
        reverse(huga.begin(),huga.end());
        if(hoge==fst){
            cout << fs << endl;
            break;
        }else if(huga==bst){
            cout << bs << endl;
            break;
        }
        fs--;
        bs++;
    }

}

Measured memory_bytes: 3272
import java.awt.datatransfer.FlavorEvent;
import java.util.Scanner;
import javax.sound.midi.SysexMessage;
  
public class Main{      
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.nextLine();
        String str2[] = str.split(" ");
        int ints[] = new int[n];
        int flag = 1;
        int count = 0;

        for(int i = 0;i<n;i++)
        {
            ints[i]= sc.nextInt();
        }

        for(int i = 0;i<n;i++)
        {
            int minj=i;
            for(int j=i;j<n;j++)
                {
                    if(ints[j]<ints[minj])
                        minj=j;
                }
                if(minj!=i){
                    int ii = ints[i];
                    ints[i]=ints[minj];
                    ints[minj]=ii;
                    count++;
                }
            
        }

        for (int i = 0; i<n;i++)
        {
          System.out.print(ints[i]);
          if(i!=n-1)
            System.out.print(" ");
        }
        System.out.print("\n"+count+"\n");
    }   
}


Measured memory_bytes: 26456
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <vector>

int main() {
  int n;
  scanf("%d",&n);
  char s[n];
  scanf("%s",s);
  int i,j,cost;
  int d[n];//number of East (+ side) for 0~i
  if(s[0]=='E') {
    d[0]=1;
  } else {
    d[0]=0;
  }
  for(i=1;i<n;i++) {
    if(s[i]=='E') {
      d[i] = d[i-1]+1;
    } else {
      d[i] = d[i-1];
    }
  }
  int ans = n;
  for(i=0;i<n;i++) {
    cost = 0;
    if(i>0) {
      cost += i - d[i-1];
    }
    if(i<n-1) {
      cost += d[n-1] - d[i];
    }
    if(ans > cost) {
      ans = cost;
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

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

  vector<long long> ans(n-1);
  long long x = 0;
  for (int i = 0; i < n-1; i++)
  {
    x+=a[i];
    y-=a[i];
    ans[i] = abs(x-y); 
  }
  sort(ans.begin(),ans.end());

  cout << ans[0] << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,Z,W;
  cin >> N >> Z >> W;
  vector<ll> A(N);
  rep(i,N) cin >> A.at(i);
  if(N==1){
    cout << abs(A.at(0)-W) << endl;
  }else{
    cout << max(abs(A.at(N-1)-W),abs(A.at(N-1)-A.at(N-2))) << endl;
  }
}

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

using namespace std;

typedef long long ll;

int main() {

    int a,b;
    cin >> a >> b;
    int ag,bg;
    if(a == 2){
        ag = 3;
    }
    else if(a == 4 || a == 6 || a == 9 || a == 11){
        ag = 2;
    }
    else{
        ag = 1;
    }
    if(b == 2){
        bg = 3;
    }
    else if(b == 4 || b == 6 || b == 9 || b == 11){
        bg = 2;
    }
    else{
        bg = 1;
    }
    if(ag == bg){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
	return 0;
}


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

int main() {
  int64_t i;
  std::cin >> i;
  int64_t diff = 1000;

  while (100 <= i) {
    auto s = i % 1000 - 753;
    if (s < 0) {
      s = -s;
    }
    diff = std::min(diff, s);
    i /= 10;
  }
  std::cout << diff << std::endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
import heapq

def main():
    _,M=map(int,input().split())
    A = []
    for a in list(map(int, input().split())):
        heapq.heappush(A, -a)
    while M>0:
        a = -heapq.heappop(A)
        a //= 2
        M -= 1
        heapq.heappush(A, -a)
    print(-sum(A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 60824
#include <bits/stdc++.h>
#define nl endl
#define dbg(a) cout << #a << "=" << a << endl
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define md 1000000007

using namespace std;

int solve()
{
    ll n;
    cin>>n;
    vector<long long> v(n);
    for(auto &it:v) cin>>it;
    sort(v.begin(), v.end());
    ll c=0;
    for(int i=0;i<n;i++)
    {
        // dbg(v[i]);
        for(int j=i+1;j<n;j++)
        {
            // dbg(v[j]);
            if(v[i]==v[j]) continue;
            for(int k=j+1;k<n;k++)
            {
                if(v[j]==v[k]) continue;
                ll x=v[i]+v[j];
                // dbg(v[k]);
                // dbg(x);
                if(x>v[k])
                    c++;
                // dbg(c);
            }
            // dbg(c);
        }
        // dbg(c);
    }
    cout<<c<<endl;
    return 0;
}

int main()
{
    fast;
    solve();
    return 0;
}

Measured memory_bytes: 3604
n=input()
cnt =   n.count("1") +2*n.count("2")+3*n.count("3")+4*n.count("4")+5*n.count("5")+6*n.count("6")+7*n.count("7")+8*n.count("8")+9*n.count("9")
if cnt%9 == 0 :
    print ('Yes')
else :
    print ('No')

Measured memory_bytes: 9284
n = int(input())
a = [input() for i in range(n)]
m = int(input())
b = [input() for i in range(m)]
min = 0
for i in range(n):
    max = a.count(a[i])-b.count(a[i])
    if max >= min:
        min = max
    else:
        pass
print(min)
        


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))

left = A[0]
left %= (10**9)+7
right = sum(A) - A[0]
right %= (10**9)+7
ans = 0
for i in range(1, N):
  tmp = left * right
  tmp %= (10**9)+7
  ans += tmp
  ans %= (10**9)+7
  left = A[i]
  right -= A[i]
print(ans)

Measured memory_bytes: 94076
import java.util.Scanner;

class Main {
	// 絵柄
	static final String[] MARK = { "S", "H", "C", "D" };

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		// カード総数
		final int TOTAL_CARDS = 52;

		// どのカードを所持しているかのフラグ
		boolean[] flagArray = new boolean[TOTAL_CARDS];

		// 所持カード枚数(入力レコード数)を記録
		int cardCount = Integer.parseInt(sc.nextLine());

		for (int i = 0; i < cardCount; i++) {
			// 所持カード(絵柄 + " " + 数字)の入力
			String[] input = sc.nextLine().split("[\\s]+");
			// 所持フラグの変更
			int arraynum = CardToArrayNum(input[0], input[1]);
			flagArray[arraynum] = true;

		}

		print(flagArray);

	}

	// カードから配列番号へ
	static int CardToArrayNum(String mark, String num) {
		for (int x = 0; x < MARK.length; x++) {

			if (mark.equals(MARK[x])) {

				return Integer.parseInt(num) + (x * 13) - 1;
			}
		}
		return -1;
	}

	// 配列番号からカードへ
	static String[] ArrayNumToCard(int num) {
		String[] card = new String[2];
		card[0] = MARK[num / 13];
		card[1] = String.valueOf(num % 13 + 1);
		return card;
	}

	// 表示処理
	static void print(boolean[] flagArray) {
		// 所持していなかったカードを表示させる
		for (int i = 0; i < flagArray.length; i++) {

			if (flagArray[i] == false) {
				String[] card = ArrayNumToCard(i);
				// 出力
				System.out.println(card[0] + " " + card[1]);
			}
		}
	}
}



Measured memory_bytes: 26368
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define testcases() int t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	ll n;
	cin>>n;
	unordered_map<string,ll> mp;
	for(int i=0;i<n;i++)
	{
		string str;
		cin>>str;
		sort(str.begin(),str.end());
		if(mp.find(str)==mp.end())
			mp[str]=1;
		else
			mp[str]++;
	}
	ll ans=0;
	for(auto it: mp)
		ans+=(it.se*(it.se-1))/2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 10660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

class UnionFind {
public:
  vector<ll> par; 
  vector<ll> siz; 

    
  UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i) par[i] = i; 
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.resize(sz_, 1);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }

  ll root(ll x) { 
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind fre(n);
  vector<int> ans(n, -1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    fre.merge(a, b);
    ans[a]--, ans[b]--;
  }
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    c--, d--;
    if (fre.issame(c, d)) {
      ans[c]--, ans[d]--;
    }
  }

  rep(i, n) {
    ans[i] += fre.size(i);
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;


  
  return 0;
}

Measured memory_bytes: 2816
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>
const long long INF=1e18;

using namespace std;

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

    int ans=10000-N;

    while(ans>=1000){
        ans-=1000;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int main(){

  int n, m, d;
  cin >> n >> m >> d;

  long long int cnt = 0;
  for(int j=1; j<=n; j++){
    if( d == 0 ){
      cnt ++;
      continue;
    }
    if( j + d <= n ) cnt++;
    if( j - d > 0 ) cnt++;
  }
  cerr << cnt << endl;
  cnt *= m-1;
  cerr << cnt << endl;
  double ans = cnt * 1.0;
  ans /= n;
  ans /= n;

  printf("%.10lf\n", ans);

  return 0;
}


Measured memory_bytes: 256
M, N = map(int, input().split())

X = list(map(int, input().split()))
X.sort()

Y = []

for i in range(N - 1):
    Y.append(X[i + 1] - X[i])

Y.sort()

if M < N:
    c = X[-1] - X[0] - sum(Y[N - M:])
else:
    c = 0

print(c)


Measured memory_bytes: 57384
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)


set<string> tree;

int main(){
    int n;

    scanf("%d",&n);

    for(int i = 0;i < n;i++){
        string a,b,op = "insert";

        cin>>a>>b;

        if(a == op){
            tree.insert(b);
        }else{
            set<string>::iterator itr;
            itr = tree.find(b);
            if(itr != tree.end())
                printf("yes\n");
            else
                printf("no\n");
        }
    }
}

Measured memory_bytes: 32204
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;


template <typename T> class LazySegmentTree {

private:

    int n;
    vector < bool > flag;
    vector < T > node, lazy;
    const T INF = numeric_limits<T>::max() / 2;
    
    void  lazy_eval (int l, int r, int k) {
        if (flag[k]) {
            node[k] = lazy[k];
            flag[k] = false;
            if (r - l > 1) {
                lazy[2 * k + 1] = lazy[k];
                lazy[2 * k + 2] = lazy[k];
                flag[2 * k + 1] = true;
                flag[2 * k + 2] = true;
            }
        }
    }
    
    void _update (int a, int b, T val, int k, int l, int r) {
        lazy_eval(l, r, k);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] = val;
            flag[k] = true;
            lazy_eval(l, r, k);
        } else {
            _update (a, b, val, 2 * k + 1, l, (l + r) / 2);
            _update (a, b, val, 2 * k + 2, (l + r) / 2, r);
            node[k] = min(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    T _get_min (int a, int b, int k, int l, int r) {
        lazy_eval (l, r, k);
        if (b <= l || r <= a) return INF;
        if (a <= l && r <= b) return node[k];
        T vl = _get_min (a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = _get_min (a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
    
public:
    
    LazySegmentTree (int _n) : n(1) {
        while (n < _n) n <<= 1;
        node.resize (2 * n, INF);
        lazy.resize (2 * n, INF);
        flag.resize (2 * n, false);
    }
    
    void update (int l, int r, T val) {
        _update (l, r, val, 0, 0, n);
    }
    
    T get_min (int l, int r) {
        return _get_min (l, r, 0, 0, n);
    }
    
};

int main() {
    
    int n,q; cin >> n >> q;
    
    LazySegmentTree < ll > inst(100010);
    
    const ll INF = numeric_limits<ll>::max() / 2;
    
    REP(i,q) {
        int a,l,r;
        cin >> a >> l >> r;
        if (a == 0) {
            ll x; cin >> x;
            inst.update(l, r + 1, x);
        } else {
            ll ans = inst.get_min(l, r + 1);
            if (ans == INF) {
                cout << ((1LL << 31LL) - 1LL) << endl;
            } else {
                cout << ans << endl;
            }
        }
    }

    return 0;
}





Measured memory_bytes: 7032
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    if(a[N - 1] - a[0] >= 2){
        cout << "No" << endl;
        return 0;
    }

    if(a[N - 1] == a[0]){
        if(a[0] == N - 1){
            cout << "Yes" << endl;
        }else{
            if(a[0] * 2 <= N){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
        return 0;
    }

    ll color = a[N - 1];
    ll enableCol = color;
    ll tmp = 0;
    for (int i = 0; i < N; ++i) {
        if(a[i] != color){
            enableCol--;
        }else{
            tmp++;
        }
    }
    if(enableCol <= 0){
        cout << "No" << endl;
        return 0;
    }
    if(enableCol * 2 <= tmp){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }



}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <utility>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <stack>
#define N 100010

using namespace std;

char ges[N];

int main()
{
    scanf("%s",ges);
    int len = strlen(ges);
    int pa = len/2;
    int pp = 0;
    for (int i=0;i<len;i++)
    {
        if (ges[i]=='p')
        {
            pp++;
        }
    }
    printf("%d\n",pa-pp);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define push_back pb;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	ll INF=1e18l+7;
	cin>>n;
	ll a[n],b[n],c[n];
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	ll dp[n+1][3];
	dp[0][0]=dp[0][1]=dp[0][2]=0;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=max(dp[i-1][1]+b[i-1],dp[i-1][2]+c[i-1]);
		dp[i][1]=max(dp[i-1][0]+a[i-1],dp[i-1][2]+c[i-1]);
		dp[i][2]=max(dp[i-1][1]+b[i-1],dp[i-1][0]+a[i-1]);
	}
	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
	return 0;
}


Measured memory_bytes: 8296
#include <iostream>
#include <vector>
using namespace std;
 
int main(int argc, char *argv[])
{
    int n;
    cin >> n;

    vector<int> a(n), b(n);
    //for(int i = 0; i < n; ++i) 
    //{
    //    cin >> a[i] >> b[i];
    //}
 
    //long long num = 0;
    //for(int i = n - 1; i >= 0; --i)
    //{
    //    a[i] += num;
    //    num += (b[i] - (a[i] % b[i])) % b[i];
    //}
    
    for(int i=0;i<n;i++){
                cin>>a[i]>>b[i];
        }
        long long d=0;
        for(int i=n-1;i>=0;i--){
                d+=(b[i]-(a[i]+d)%b[i])%b[i];
        }
        cout<<d<<endl;
 
    //cout << num << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define in insert
#define mp make_pair
using namespace std;
const int N = 1e5+123;
int a[N];
int n,m,k;
string s;
set<int>setik;

bool ok(int a1,int b1)
{
	for(int i = 0; i <= 1000; i++)
		for(int j = 0; j <= 1000; j++)
			if(i * a1 + j * b1 == n)
				return 1;
	return 0;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	if(ok(4,7))
		cout << "Yes";
	else
		cout << "No";
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n;
    string s;
    cin>>n>>s;
    map<char,ll> mp;
    rep(i,n) mp[s[i]]++;
    ll ans=1;
    for(auto x:mp) ans *= (x.second+1)%mod,ans%=mod;
    cout<<(ans-1)%mod<<endl;
    return 0;
}

Measured memory_bytes: 3740
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e16;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> a(n+1);
  rep(i,n+1) {
    cin >> a[i];
  }
  if (a[0] >= 2) {
    cout << -1 << endl;
    return 0;
  }
  assert(a[0] <= 1);

  vector<ll> maxNodes(n+1);
  maxNodes[0] = 1-a[0];
  for (int i = 1; i <= n; ++i) {
    maxNodes[i] = 2*maxNodes[i-1] - a[i];
    chmin(maxNodes[i], INF); // for avoiding overflow
  }
  // printvec(maxNodes);

  ll ans = 0; // TODO: update

  ll cnt = a[n]; // node + leaf
  ans += cnt;
  for (ll i = n-1; i >= 0; --i) {
    // node must be in [minNode,cnt]
    ll minNode = (cnt+1)/2;

    ll node = min(cnt, maxNodes[i]); // initial value
    ll leaf = a[i];

    // // TODO: update logic of all
    // ll all = pow(2,i);
    // // ll all = 1;
    // // {
    // //   ll j = 0;
    // //   while (j < i && all < node + leaf) { // all-leaf < node
    // //     all *= 2;
    // //     ++j;
    // //   }
    // // }
    // cout << "cnt: " << cnt << endl;
    // cout << "all: " << all << endl;
    // cout << "leaf: " << leaf << endl;
    // cout << "node: " << node << endl;
    // cout << "all-leaf: " << all-leaf << endl;
    // cout << "minNode: " << minNode << endl;

    // if (all < cnt + leaf) { // Here, all == 2^i
    //   chmin(node, all - leaf);
    //   // Here, node >=minNode. OK>
    // } else { // Here, all is large. node <= all - leaf
    //   // Do nothing
    // }

    if (node < minNode) { // check size of node. node is too small.
      cout << -1 << endl;
      return 0;
    }

    cnt = node + leaf; // update cnt
    ans += cnt;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4756
R, C, K=map(int, input().split())
math=[[0]*C for _ in range(R)]
for _ in range(K):
  r, c, v=map(int, input().split())
  math[r-1][c-1]=v
  
dp=[[[0]*C for __ in range(R)] for _ in range(4)]
if math[0][0]>0:
  dp[1][0][0]=math[0][0]+0
  
for j in range(1, C):
  dp[0][0][j]=dp[0][0][j-1]+0
  dp[1][0][j]=max(dp[1][0][j-1], dp[0][0][j-1]+math[0][j])
  dp[2][0][j]=max(dp[2][0][j-1], dp[1][0][j-1]+math[0][j])
  dp[3][0][j]=max(dp[3][0][j-1], dp[2][0][j-1]+math[0][j])
    
for i in range(1, R):
  dp[0][i][0]=max(dp[0][i-1][0], dp[1][i-1][0], dp[2][i-1][0], dp[3][i-1][0])
  dp[1][i][0]=dp[0][i][0]+math[i][0]
  for j in range(1, C):
    dp[0][i][j]=max(dp[0][i][j-1], max(dp[0][i-1][j], dp[1][i-1][j], dp[2][i-1][j], dp[3][i-1][j]))
    dp[1][i][j]=max(dp[1][i][j-1], dp[0][i][j-1]+math[i][j], max(dp[0][i-1][j], dp[1][i-1][j], dp[2][i-1][j], dp[3][i-1][j])+math[i][j])
    dp[2][i][j]=max(dp[2][i][j-1], dp[1][i][j-1]+math[i][j])
    dp[3][i][j]=max(dp[3][i][j-1], dp[2][i][j-1]+math[i][j])
    
print(max(dp[0][-1][-1], dp[1][-1][-1], dp[2][-1][-1], dp[3][-1][-1]))

Measured memory_bytes: 429804
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int N;
	cin >> N;

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

	for(int i = 0; i < N; i++){
		if(v[i] > i+1){
			cout << -1 << endl;
			return 0;
		}
	}

	vector<int> ans(N);
	for(int k = 0; k < N; k++){
		int t = 0;
		for(int i = 0; i < N - k; i++){
			if(v[i] == i+1) t = i+1;
		}

		ans[N-1-k] = t;
		v.erase(v.begin() + t-1);
	}

	rep(i, N) cout << ans[i] << endl;
}


Measured memory_bytes: 256
n=int(input())
s=[list(map(int,list(input().split()))) for i in range(n)]  # 二次元配列入力　二次元マップみたいな入力のとき

import math
from functools import lru_cache

@lru_cache(maxsize=100000)
def calc_distance(a, b):
    tmp = (a[0]-b[0])**2 + (a[1]-b[1])**2
    return math.sqrt(tmp)


import itertools
sum = 0
for all in itertools.permutations(s, n):
    for i in range(n-1):
        # tupleにすることで、lru_cacheを使用可能にする．
        # listはハッシュ出来ないが、tupleはハッシュ可能．
        sum += calc_distance(tuple(all[i]), tuple(all[i+1])) 

kaizyo = math.factorial(n)
# print("sum:", sum)
# print("kaizyo:", kaizyo)

print(sum/kaizyo)

Measured memory_bytes: 3572
from fractions import gcd
inf = input().split()
A = int(inf[0])
B = int(inf[1])
C = int(inf[2])
D = int(inf[3])

num = B-A+1
target = B
X = C*D//gcd(C,D)

total = B//C + B//D - B//X
lim = (A-1)//C + (A-1)//D - (A-1)//X
print(num-total+lim)


Measured memory_bytes: 5344
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;
    cout << max(A - 2 * B, 0) << endl;
    return 0;
}

Measured memory_bytes: 384
using System;

namespace ITP1_7_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int n = int.Parse(input[0]);
                int x = int.Parse(input[1]);
                if (n == 0)
                    break;
                Console.WriteLine(CountCombi(n, x));
            }
        }

        static int CountCombi(int n,int x)
        {
            int ret = 0;
            for(int i = 1; i < n - 1; i++)
            {
                for(int j = i + 1; j < n; j++)
                {
                    int temp = x - (i + j);
                    if (temp <= j)
                        break;
                    if (temp <= n)
                        ret++;
                }
            }
            return ret;
        }
    }
}

Measured memory_bytes: 9136
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 x = sc.nextInt();

    int y = x-a;

    if (y < 0) {
      System.out.println("NO");
    } else {
      if (b >= y) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
}


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

 
int main(){
    string s; cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s << endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    string a, b, c;
    cin >> a >> b >> c;
    
    transform(a.begin(), a.end(), a.begin(), ::toupper);
    transform(b.begin(), b.end(), b.begin(),::toupper);
    transform(c.begin(), c.end(), c.begin(),::toupper);
    cout << a[0] << b[0] << c[0] << endl;

    return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static int[] hs;
        static long ans;
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            hs = ReadLine().Split(' ').Select(int.Parse).ToArray();

            ans = 0;

            while (hs.Sum() > 0)
            {
                int l = 0;
                bool findNum = false;
                for (int i = 0; i < n; i++)
                {
                    if (hs[i] != 0&& findNum == false) { findNum = true; l = i; }

                    if(hs[i] == 0 && findNum)
                    {
                        ans++;
                        Func(l, i);
                        l = i + 1;
                        findNum = false;
                    }
                }
                if(l != n)
                {
                    ans++;
                    Func(l, n);
                }
            }
            WriteLine(ans);
        }

        static void Func(int start,int end)
        {
            bool tmp = false;
            for (int i = start; i < end; i++)
            {
                if (hs[i] > 0) { hs[i]--; tmp = true; }
            }
            if (tmp == false) ans--;
        }

    }
}



Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll s;
    cin >> s;

    vector<ll> div;
    for(ll i=1; i*i<=s; ++i) {
        if(s%i==0) {
            div.push_back(i);
            if(s/i != i) div.push_back(s/i);
        }
    }

    ll ret = 0;
    for(auto x: div) {
        ll y = s/x;

        // 2xの約数
        ll cnt1;
        {
            set<PII> st;
            for(ll p=1; p*p<=2*x; ++p) {
                if(2*x%p == 0) {
                    ll q = 2*x/p;
                    if((p+q)%2 == 0) continue;
                    ll i = (q-p+1)/2;
                    ll j = (p+q-1)/2;
                    if(i>j) swap(i,j);
                    st.insert({i,j});
                }
            }
            dump(2*x, st);
            cnt1 = st.size();
        }

        // 2yの約数
        ll cnt2;
        {
            set<PII> st;
            for(ll p=1; p*p<=2*y; ++p) {
                if(2*y%p == 0) {
                    ll q = 2*y/p;
                    if((p+q)%2 == 0) continue;
                    ll i = (q-p+1)/2;
                    ll j = (p+q-1)/2;
                    if(i>j) swap(i,j);
                    st.insert({i,j});
                }
            }
            dump(2*y, st);
            cnt2 = st.size();
        }

        ret += cnt1 * cnt2;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		String s = stdin.next();
		if(s.charAt(0)==s.charAt(2)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		

	}

}


Measured memory_bytes: 23764
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
for i in range(1, N):
    for j in range(K):
        if i - (j + 1) >= 0:
            dp[i] = min(dp[i], dp[i-j-1] + abs(h[i] - h[i-j-1]))

print(dp[N-1])

Measured memory_bytes: 55520
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int h = kb.nextInt();
		int n = kb.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			int j = kb.nextInt();
			a[i] = j;
		}
		for (int e : a) {
			h -= e;
		}
		if (h <= 0)
			System.out.println("Yes");
		else
			System.out.println("No");
		kb.close();
	}

}


Measured memory_bytes: 51052
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a) for (int i = (a)-1; i >= 0; i--)
#define reps(i, a, j) for (int i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define mp make_pair
#define eb emplace_back
#define FastOpen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pii pair < int , int >
#define all(a) a.begin(),a.end() 
//int power(int x,int p){if(p==0)return 1;if(p==1)return x;if(p%2)return x*power(x,p-1);int y=power(x,p/2);return y*y;}
/*
*/

void solve() {
    int n; cin >> n;
    double dp[n+1][n+1],res = 0;
    ms(dp);
    rep(i,n) {
        double x; cin >> x;
        if (i == 0) {
            dp[i][0] = 1-x;
            dp[i][1] = x;
            continue;
        }
        rep(j,n+1) {
            // tails
            dp[i][j] += (1-x)*(dp[i-1][j]);
            // head
            dp[i][j] += (x)*(dp[i-1][j-1]);
        }
    }
    reps(i,n+1,(n/2)+1) res += dp[n-1][i];
    cout << setprecision(9) << res << endl; 
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    FastOpen
    int t; t=1;
    while (t--) solve();
}





Measured memory_bytes: 74036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------
// 深さ優先探索
vector<bool> seen;
vector<int> ans;
int backlog=0;
void dfs(const vector<vector<int>> &g,int v,const vector<int> &p) {

    seen[v] = true; // v を訪問済にする
    ans[v] = ans[backlog]+p[v];//countor
    backlog = v;
    // v から行ける各頂点 next_v について
    for (auto next_v : g[v]) {
        if (seen[next_v]) {
          //backlog=next_v;
          continue; // next_v が探索済だったらスルー
        }
        dfs(g, next_v,p); // 再帰的に探索
        backlog=v;
    }
}
//------------------------------------------------
int main(){
  int n,q;
  cin>>n>>q;
  vector<vector<int>> g(n);
  rep(i,0,n-1){
    int a,b;
    cin>>a>>b;
    g.at(a-1).push_back(b-1);
    g.at(b-1).push_back(a-1);
  }
  vector<int> p;
  p.assign(n, 0);
  int h,r;
  rep(i,0,q){
    cin>>h>>r;
    p[h-1]+=r;
    //dfs(g,p-1,x);
  }

  ans.assign(n, 0);
    seen.assign(n, false);
    dfs(g,0,p);
rep(i,0,n) cout<<ans[i]<<endl;
}


Measured memory_bytes: 27392
use std::str::FromStr;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let a: Vec<i32> = read_vec();
    let mut ans = 10000000;
    for t in 0..n-1 {
        let mut s1 = 0;
        let mut s2 = 0;
        for i in 0..t+1 {
            s1 += a[i];
        }
        for i in t+1..n {
            s2 += a[i];
        }
        ans = min(ans, (s1 - s2).abs());
    }
    println!("{}", ans);
}

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

long long euler_phi(long long n) {
    long long res = n;
    for (long long i = 2LL; i * i <= n; i++) if (n % i == 0) {
        res -= res / i;
        while (n % i == 0) n /= i;
    }
    if (n > 1) res -= res / n;
    return res;
}

int main() {
    int n; cin >> n;
    cout << euler_phi(n) << endl;
    return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
int main(){
	int a,b,e,s=0;
	while(scanf("%d%d",&a,&b),a|b){
		e=0;
		if(s)
			puts("");
		s=1;
		for(;a<=b;a++){
			if(a%400==0||a%100&&a%4==0) {
				printf("%d\n",a);
				e=1;
			}
		}
		if(!e)
			puts("NA");
	}
	return 0;
}

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

// macros
#define overload_rep(va_0, va_1, va_2, name, ...) name
#define rep_0(i, n) for(int i = 0; i < (n); ++i)
#define rep_1(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations
int N, K;
string S;

int dp[310][310][310];

// solve
int main(){

    cin >> S >> K;
    N = S.size();

    rep(i, N)rep(j, 0, K)dp[i][i + 1][j] = 1;
    rep(len, 1, N){
        rep(i, 0, N - len){
            if(i > 0){
                rep(j, 0, K)chmax(dp[i - 1][i + len][j], dp[i][len][j]);
                int pos = -1;
                for(int j = i + len - 1; j >= i; j--){
                    if(S[i - 1] == S[j]){
                        pos = j;
                        break;
                    }
                }
                if(pos != -1)rep(j, 0, K)chmax(dp[i - 1][i + len][j], dp[i][pos][j] + 2);
                rep(j, K){
                    chmax(dp[i - 1][i + len][j + 1], dp[i][i + len - 1][j] + 2);
                }
            }
            if(i < N - len){
                rep(j, 0, K)chmax(dp[i][i + len + 1][j], dp[i][i + len][j]);
                int pos = -1;
                for(int j = i; j < i + len; j++){
                    if(S[i + len] == S[j]){
                        pos = j;
                        break;
                    }
                }
                if(pos != -1)rep(j, 0, K)chmax(dp[i][i + len + 1][j], dp[pos + 1][i + len][j] + 2);
                rep(j, K){
                    chmax(dp[i][i + len + 1][j + 1], dp[i + 1][i + len][j] + 2);
                }
            }
        }
    }

    int ans = 0;
    rep(i, 0, K)chmax(ans, dp[0][N][i]);
    cout << ans << '\n';

}


Measured memory_bytes: 112768
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    // https://atcoder.jp/contests/abc134/tasks/abc134_c
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 47020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 150004;

bool ok(long long x){
	bool a = false, b = false, c = false;
	while(x){
		if(x%10 == 3) a=true;
		else if(x%10 == 5) b=true;
		else if(x%10 == 7) c=true;
		else return false;
		x /= 10;
	}
	return (a && b && c);
}

int cnt = 0;

void dfs(long long n, long long x){
	if(x > n) return;
	if(x <= n && ok(x)) cnt++;
	dfs(n, x*10+3);
	dfs(n, x*10+5);
	dfs(n, x*10+7);
}

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

	cnt = 0;
	long long n;
	cin >> n;
	dfs(n, 0);
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{int x[6];
for(int i=1;i<=5;i++)
{cin>>x[i];
}
 for(int i=1;i<=5;i++)
 {if(x[i]==0)
  cout<<i;
}
return 0;
 }

Measured memory_bytes: 3568
import sys
input = sys.stdin.readline

def pri(tbl, tbl2, tbl3, tbl4, n, m):
	for i in range(n):
		for j in range(m):
			print("{:2}".format(tbl[i][j]+tbl2[i][j]+tbl3[i][j]+tbl4[i][j]), end='')
		print('')
	print('')

def main():
	n, m = map(int, input().strip().split())
	v = []
	for i in range(n):
		v.append(input().strip())
	tbl = [[0] * m for _ in range(n)]
	tbl2 = [[0] * m for _ in range(n)]
	tbl3 = [[0] * m for _ in range(n)]
	tbl4 = [[0] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if v[i][j] == '#':
				tbl[i][j] = -1
			elif j == 0:
				continue
			else:
				tbl[i][j] = tbl[i][j-1] + 1
	# pri(tbl, tbl2, tbl3, tbl4, n, m)
	for i in range(n):
		for j in range(m-1, -1, -1):
			if v[i][j] == '#':
				tbl2[i][j] = -1
			elif j == m-1:
				continue
			else:
				tbl2[i][j] = tbl2[i][j+1] + 1
	# pri(tbl, tbl2, tbl3, tbl4, n, m)

	
	for j in range(m):
		for i in range(n):
			if v[i][j] == '#':
				tbl3[i][j] = -1
			elif i == 0:
				continue
			else:
				tbl3[i][j] = tbl3[i-1][j] + 1
	for j in range(m):
		for i in range(n-1, -1, -1):
			if v[i][j] == '#':
				tbl4[i][j] = -1
			elif i == n-1:
				continue
			else:
				tbl4[i][j] = tbl4[i+1][j] + 1
	# for i in range(n):
	# 	print(tbl[i])
	# pri(tbl, tbl2, tbl3, tbl4, n, m)
	ans = 0
	for i in range(n):
		for j in range(m):
			ans = max(ans, tbl[i][j]+tbl2[i][j]+tbl3[i][j]+tbl4[i][j])
	print(ans+1)

if __name__ == '__main__':
	main()


Measured memory_bytes: 178440
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;

  int count = 0; //回分数カウンタ
  for(int i = A; i <= B; i++) {
    if(i / 10000 == i % 10 && (i / 1000) % 10 == (i % 100) / 10) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3596