akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int k,s;
    cin >> k >> s;
    int count=0;
    if(s>=k){
        for(int i=0;i<=k;i++){
            for(int j=0;j<=k;j++){
                if(i+j>=s-k&&s>=i+j){
                    count++;
                }
            }
        }
    }
    else{
        for(int i=0;i<=k;i++){
            for(int j=0;j<=k;j++){
                if(s>=i+j){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
    int n;cin>>n;
    int a[n],b[n]; for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    sort(a,a+n),sort(b,b+n);
    n&1?cout<<b[n/2]-a[n/2]+1:cout<<(b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1])+1;
}


Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

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

    int ans = 0;
    if ((n-1)%(k-1) == 0) ans = (n-1)/(k-1);
    else ans = (n-1)/(k-1) + 1;

    cout << ans << endl;

}


Measured memory_bytes: 768
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T x; cin >> x; return x; }

signed main()
{
	int n = in();
	int hund = n / 100;
	if (n > hund * 100 + hund * 10 + hund)++hund;
	cout << hund * 100 + hund * 10 + hund << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template <size_t I, class H, class... T> struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template <class H, class... T> struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template <class... T> istream& operator>>(istream&i,tuple<T...>& t) { t = TupleReaderWriter<sizeof...(T), T...>::r(i); return i; }
template <class... T> ostream& operator<<(ostream& o, tuple<T...>& t) { string delim = " "; TupleReaderWriter<sizeof...(T) - 1, T...>::w(o, t, delim); return o; }
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N, A;
    cin >> N >> A;
    vector<int> X(N);
    for(auto &x : X) cin >> x;
    int S = accumulate(WHOLE(X),0);
    vector2d<i64> dp(N + 1, vector<i64>(S + 1, 0));
    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int n = N; n > 0; n--) {
            for(int s = S; s >= 0; s--) {
                dp[n][s + X[i]] += dp[n - 1][s];
            }
        }
    }
    i64 ans = 0;
    for(int n = 1; n <= N; n++) {
        if(n * A <= S) ans += dp[n][n * A];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main{
	//for(Map.Entry<Object, Object> e: map.entrySet()){ ...
	public static void main(String[] args){
		try{
//-*-*- tp start -*-*-
			final int INF = Integer.MAX_VALUE, MINF = Integer.MIN_VALUE;
			SpecialComparator scomparator = new SpecialComparator();
			Scanner s = new Scanner(System.in);
//-*-*- tp end -*-*-
			//write a program...
			for(int i = 1; i <= 9; i++){
				for(int j = 1; j <= 9; j++){
					debugl(i+"x"+j+"="+i*j);
				}
			}
//-*-*- tp start -*-*-
		}catch(Exception e){
			e.printStackTrace();
		}
	}
//-*-*- tp end -*-*-
	//functions
//-*-*- tp start -*-*-
	private static void debugl(Object obj){
		System.out.println(obj);
	}
	private static void debug(Object obj){
		System.out.print(obj);
	}
	private static String toStrmd(Object[] obj){
		return Arrays.deepToString(obj);
	}
}

class SpecialComparator implements Comparator{
	private int index = 0;
	public void setIndex(int index){
		this.index = index;
	}
	public int compare(Object a, Object b){
		String[] sa = (String[])a;
		String[] sb = (String[])b;
		return (sa[index].compareTo(sb[index]));
	}
}
//-*-*- tp end -*-*-

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
const int mod = 1e9 + 7;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
ll power(ll a, ll b)
{
    ll ans = 1 % mod;
    while (b)
    {
        if (b & 1)
        {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll c[maxn];
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    ll cur = 1;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        //cur = lcm(a[i], cur);
    }
    for (int i = 1; i <= n; i++)
    {
        ll x = a[i];
        for (int j = 2; j * j <= x; j++)
        {
            ll cnt = 0;
            if (x % j == 0)
            {
                while (x % j == 0)
                {
                    cnt++;
                    x /= j;
                }
            }
            //pos = max(cnt, pos);
            c[j] = max(c[j], cnt);
            // pos = max(pos, j);
            // pos = max(pos, x);
        }
        if (x > 1)
        {
            c[x] = max(c[x], 1ll);
        }
    }
    ll lcm = 1;
    vector<ll> inv(n + 1);
    for (int i = 1; i <= n; i++)
    {
        inv[i] = power(a[i], mod - 2);
    }
    for (int i = 1; i <= 1e6; i++)
    {
        if (c[i] >= 1)
        {
            ll cur = power(1ll * i, c[i]);
            lcm = lcm * cur % mod;
        }
    }
    //DBG(c[3]);
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans = (ans + lcm * inv[i]) % mod;
    }
    cout << ans << "\n";
    //cout << "\n";
    return 0;
}

Measured memory_bytes: 8320
N = str(input())
N = N[:-1]

if len(N) % 2 == 1:
  N = N[:-1]


l = len(N)

# print(l)

r = int(l/2)
N_1 = N[0:r]
N_2 = N[r:l+1]

# print(N_1)
# print(N_2)

# print("______________________________________")

while l >= 2:
  if N_1 == N_2:
    # print("found: " + N_1)
    print(len(N_1)*2)
    break
  else:
    l = l-2
    r = int(l/2)
    N_1 = N[0:r]
    N_2 = N[r:l]
    # print(N_1)
    # print(N_2)

# print("not found")
    
  













##################################################

# l = list(str(input()))
# P = l

# # print(l[0])
# print(P[0])
# x = []
# s = []
# n = 0
# j = []
# for i in l:
#   x.append(i)
#   # "".join(x)
#   x = list(x)
#   j.append(x)

# j.insert(0,l[0])
# j.pop(-1)
# print(j)


Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<double,P> PP;
struct edge { int to; int cost; };
int s[15][15];
int k[15];
int p[15];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, m) {
		cin >> k[i];
		rep(j, k[i]) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	rep(i, m)cin >> p[i];
	int cnt = 0;
	rep(i, 1 << n) {
		int sc = 0;
		rep(j, m) {
			int tc = 0;
			rep(l, k[j]) {
				if (i&(1 << s[j][l]))tc++;
			}
			if ((tc & 1) == (p[j] & 1))sc++;
		}
		if (sc == m)cnt++;
	}
	cout << cnt << endl;
}

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

int main() {
    int n;
    cin >> n;
    string taro, hana;
    int taro_p = 0, hana_p = 0;
    int min_size;
    for (int i = 0; i < n; i++) {
        cin >> taro >> hana;
        if (taro.compare(hana) == 0) {
            taro_p += 1;
            hana_p += 1;
        }
        else {
            if (taro.compare(hana) > 0) {
                taro_p += 3;
            }
            else {
                hana_p += 3;
            }
        }
    }
    cout << taro_p << ' ' << hana_p << endl;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using lond = long double;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
//ans

int main (){
	lint n,x,t, ans;
	cin >> n >> x >> t; 
	ans = n/x;
	if (fmod(n,x) != 0) ans += 1;
	
	cout << (int)ans*t << endl;
	return 0;
}

Measured memory_bytes: 3640
M,D =map(int,input().split())
count=0
for j in range(M+1):
    for i in range(D+1):
        left=i//10
        right=i%10
        seki=left*right
#        print(left,right)
        if left >=2 and right >= 2:
            if seki == j:
                count += 1
print(count)


Measured memory_bytes: 39024
#include<stdio.h>
int n,A[2000];

int solve(int i, int m) {
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  res = solve(i + 1,m) || solve(i +1, m-A[i]);
  return res;
}

int main() {
  int q,m,i;
  scanf("%d",&n);
 for(i = 0;i<n;i++) scanf("%d\n",&A[i]);
 scanf("%d\n", &q);
 for(i = 0;i<q;i++) {
    scanf("%d\n", &m);
    if(solve(0,m)) printf("yes\n");
    else printf("no\n");
 }
  return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/

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

int main() {
	int w, h;

	while (1) {
		cin >> w >> h;
		if (w == 0 && h == 0) { return 0; }

		char a[22][22];
		memset(a, '!', sizeof(a));

		bool check[22][22];

		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				check[i][j] = false;
			}
		}

		queue<pair<int, int>> q;

		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				cin >> a[i][j];
				if (a[i][j] == '@') { q.push(make_pair(i, j)); check[i][j] = true; }
			}
		}


		while (!q.empty()) {
			pair<int, int> n = q.front(); q.pop();

			int x = n.first;
			int y = n.second;

			for (int i = 0; i < 4; i++) {
				if (a[x + dx[i]][y + dy[i]] == '.' && check[x + dx[i]][y + dy[i]] == false) {
					check[x + dx[i]][y + dy[i]] = true; q.push(make_pair(x + dx[i], y + dy[i]));
				}
			}
		}

		int ans = 0;

		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				if (check[i][j]) { ans++; }
			}
		}

		cout << ans << endl;

	}

	return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	int n, cnt = 0;
	cin >> n;
	P Red[n], Blue[n];
	for (int i = 0; i < n; i++) {
		cin >> Red[i].se >> Red[i].fi;
	}
	for (int i = 0; i < n; i++) {
		cin >> Blue[i].fi >> Blue[i].se;
	}
	sort(Red, Red + n);
	reverse(Red, Red + n);
	sort(Blue, Blue + n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (Red[j].se < Blue[i].fi && Red[j].fi < Blue[i].se) {
				cnt++;
				Red[j].fi = INF, Red[j].se = INF;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
// template starts
typedef long long int ll;
ll fact(ll n, ll p){
	ll ans = 1;
	for(ll i = 1; i <= n; i++){
		ans *= i;
		ans %= p;
	}
	return ans;
}
ll power(ll x, ll n, ll p){
	ll res = 1;
	if(n == 1) return x%p;
	if(n%2 == 1) res = x%p;

	ll temp = power(x,n/2,p);
	return res*((temp*temp)%p)%p;
}
ll inv(ll a, ll p){
	return power(a,p-2,p);
}
ll nCr(ll n, ll r, ll p){
	if(r > n) return 0;
	ll t1 = fact(n,p);
	ll t2 = inv(fact(r,p),p);
	ll t3 = inv(fact(n-r,p),p);

	return (((t1*t2)%p)*t3)%p;
}
vector<vector<ll> > multiply(vector<vector<ll> > &a, vector<vector<ll> > &b, ll p){
	int r1,c1,r2,c2;
	r1 = a.size(); c1 = a[0].size();
	r2 = b.size(); c2 = b[0].size();

	vector<vector<ll> > result(r1,vector<ll>(c2,0));

	if(c1 != r2) return result;

	for(int i = 0; i < r1; i++){
		for(int j = 0; j < c2; j++){
			for(int k = 0; k < c1; k++){
				result[i][j] += a[i][k]*b[k][j];
				result[i][j] %= p;
			}
		}
	}
	return result;
}

vector<vector<ll> > power(vector<vector<ll> >&a,ll n, ll p){
	int r = a.size();
	vector<vector<ll> > result(r,vector<ll>(r,0));
	for(int i = 0; i < r; i++) result[i][i] = 1;

	while(n > 0){
		if(n%2 == 1){
			result = multiply(result,a,p);
		}
		n /= 2;
		a = multiply(a,a,p);
	}
	return result;
}
// template ends here

void solve(){
	// code starts from here
	double r;
	cin >> r;
	r = 2.0*3.14159265*r;
	cout << setprecision(10) << r << endl;
}

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

	int T;
	T = 1;
	while(T--){
		solve();
	}

	return 0;
}


Measured memory_bytes: 3848
from itertools import permutations
from math import sqrt,factorial
N=int(input())
L=[]
for i in range(N):
    L.append(list(map(int, input().split())))
# print(L)

sum=0
for S in permutations(range(N)):
    tmp=0
    for i in range(N-1):
        tmp+= sqrt((L[S[i]][0]-L[S[i+1]][0])**2 + (L[S[i]][1]-L[S[i+1]][1])**2)
    sum+=tmp
print(sum/factorial(N))

Measured memory_bytes: 74220
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int n;
	cin >> n;
	int x = n % 10;
	if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9)puts("hon");
	else if (x == 0 || x == 1 || x == 6 || x == 8)puts("pon");
	else puts("bon");*/


	int k;
	string s;
	cin >> k >> s;
	if (s.size() <= k)cout << s;
	else {
		rep(i, k) {
			cout << s[i];
		}
		cout << "...";
	}
	return 0;
}

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

void solve() {
    ll x, k, d, ans;
    cin >> x >> k >> d;
    x = abs(x);
    ll pos_steps = (x) / d;
    ll neg_steps = (x + d) / d;
    if (k < neg_steps) {
        ans = x - k * d;
    } else {
        ll pos = x - pos_steps * d;
        ll neg = d - pos;
        if (pos_steps % 2 == k % 2) {
            ans = pos;
        } else {
            ans = neg;
        }
    }
    cout << ans << "\n";
}

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

    int t = 1;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pair <ll, ll> pi
#define vector <ll> vi
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define SQ(a) (a) * (a)
#define ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen('input.txt', 'r', stdin);
    //freopen('output.txt', 'w', stdout);
    ll i, j, k, n, m, b, d, t, ans = 0,a,x,y;
    string s,r;
    cin>>s>>r;
    cout<<r<<s<<endl;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> D(N);
	for (int i = 0; i < N; i++) cin >> D[i];
	sort(D.begin(), D.end());
	int MIN = 12;
	int bp = 0, bm = 0;
	for (int i = 0; i < N; i++) {
		if (min({ D[i] - bp, 24 - D[i] + bp, D[i] - bm, 24 - D[i] + bm })
	> min({ D[i] + bm, 24 - D[i] - bm,D[i] + bp, 24 - D[i] - bp })) {
			MIN = min({ MIN, D[i] - bp, 24 - D[i] + bp, D[i] - bm, 24 - D[i] + bm });
			bp = D[i];
		}
		else {
			MIN = min({ MIN, D[i] + bm, 24 - D[i] - bm,D[i] + bp, 24 - D[i] - bp });
			bm = -D[i];
		}
	}
	cout << MIN << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
typedef long long ll;
using namespace std;

ll dpa[100500], dpb[100500], dpc[100500];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n; cin >> n;
  vector<ll> a(n),b(n),c(n);
  rep(i,n) cin >> a[i] >> b[i] >> c[i];
  dpa[0] = a[0]; dpb[0] = b[0]; dpc[0] = c[0];
  rep2(i,1,n){
  		dpa[i] =  max(dpb[i-1] + a[i], dpc[i-1] + a[i]);
        dpb[i] =  max(dpa[i-1] + b[i], dpc[i-1] + b[i]);
        dpc[i] =  max(dpa[i-1] + c[i], dpb[i-1] + c[i]);
  }
  cout << max({dpa[n-1],dpb[n-1],dpc[n-1]});
  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	string s;
	vector<int> occs(26);
	for (int i = 0; i < n; ++i) {
		cin >> s;
		if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H') {
			++occs[s[0] - 'A'];
		}
	}

	long long ways = 0;
	for (int i = 0; i < 26; ++i) {
		for (int j = i + 1; j < 26; ++j) {
			for (int k = j + 1; k < 26; ++k) {
				ways += (long long) occs[i] * occs[j] * occs[k];
			}
		}
	}

	cout << ways << "\n";

	return 0;

}

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

int main() {
    int N,A,B;cin>>N>>A>>B;
    string S;cin>>S;
    int a = 0, b = 0;
    for(int i=0;i<N;++i){
        if(S[i]=='c') cout << "No";
        else if(S[i]=='b'){
            if(b < B && a+b < A+B) {
                ++b;
                cout << "Yes";
            } else {
                cout << "No";
            }
        }
        else {
            if(a+b < A+B){
                ++a;
                cout << "Yes";
            } else {
                cout << "No";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

string s;

int main()
{
    while (getline(cin, s))
    {
        if (s == ".")
            break;
        stack<char> st;
        bool flag = true;
        int N = s.size();
        for (int i = 0; i < N && flag; i++)
        {
            if (s[i] == '(')
                st.push(s[i]);
            if (s[i] == '[')
                st.push(s[i]);
            if (s[i] == ')')
            {
                if (st.size() > 0 && st.top() == '(')
                    st.pop();
                else
                    flag = false;
            }
            if (s[i] == ']')
            {
                if (st.size() > 0 && st.top() == '[')
                    st.pop();
                else
                    flag = false;
            }
        }
        if (st.empty() == false)
            flag = false;
        cout << ((flag ? "yes\n" : "no\n"));
    }
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int s,w;
signed main(){
    cin>>s>>w;
    if(w>=s)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
typedef char mtx[510][510];
mtx s,c[2];
int main(){
	int h,w;
	scanf("%d%d",&h,&w);
	for (int i=0;i<h;i++) scanf("%s",s[i]);
	for (int i=0;i<h;i++){
		int a=i&1,b=!a;
		for (int j=1;j<w-1;j++){
			c[a][i][j]='#';
			c[b][i][j]=s[i][j];
		}
		c[0][i][0]=c[1][i][w-1]='#';
		c[1][i][0]=c[0][i][w-1]='.';
	}
	for (int p=0;p<2;p++,printf("\n"))
		for (int i=0;i<h;i++){
			printf("%s\n",c[p][i]);
		}
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int top,S[1000];
void push(int x){
    S[++top]=x;
}
 
int pop(){
    top--;
    return S[top+1];
}
 
int main(){
    int a, b;
    top =0;
    char s[100];
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(s[0] == '-'){
            b=pop();
            a=pop();
            push(a-b);
        }
        else if(s[0] =='*'){
            a=pop();
            b=pop();
            push(a*b);
        }
        else push(atoi(s));
    }
    printf("%d\n",pop());
 
    return 0;
}

Measured memory_bytes: 2692
n, p = map(int, input().split())
s = input()
if p == 2:
    ans = 0
    for i in range(n):
        if int(s[i]) % 2 == 0:
            ans += (i + 1)
elif p == 5:
    ans = 0
    for i in range(n):
        if int(s[i]) % 5 == 0:
            ans += (i + 1)
else:
    a = [1]
    for i in range(n - 1):
        a.append(a[-1] * 10 % p)
    a.reverse()
    b = [int(s[i]) * a[i] % p for i in range(n)]
    c = [0]
    for i in range(n):
        c.append((c[-1] + b[i]) % p)
    d = {}
    for i in c:
        d.setdefault(i, 0)
        d[i] += 1
    ans = 0
    for i in d.values():
        ans += i * (i - 1) // 2
print(ans)

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

int main() {
  int K;string str;
  cin >> K >> str;
  if(str.size()<=K){
    cout << str <<endl;
  }else{
    for(int i=0;i<K;i++){
      cout << str.at(i);
    }
    cout << "..." <<endl;
  }
}



Measured memory_bytes: 3580
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		int[][] dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
		Deque<int[]> deq = new ArrayDeque<>();
		
		boolean[][] a = new boolean[H][W];
		
		for(int i = 0; i < H; i++) {
			char[] s = sc.next().toCharArray();
			for(int j = 0; j < W; j++) {
				if(s[j] == '#') {
					int[] b = {i, j};
					deq.add(b);
					a[i][j] = true;
				}
			}
		}
		
		
		boolean check = true;
		int count = 0;
		
		while(check) {
			check = false;
			Deque<int[]> nextdeq = new ArrayDeque<>();
			while(!deq.isEmpty()) {
				int[] b = deq.poll();
				for(int i = 0; i < 4; i++) {
					int x = b[0] + dir[i][0];
					int y = b[1] + dir[i][1];
					if(x < 0 || x > H - 1 || y < 0 || y > W - 1 ) {
						continue;
					}
					if(a[x][y]) {
						continue;
					}
					a[x][y] = true;
					int[] c = {x, y};
					nextdeq.add(c);
					check = true;
				}
			}
			if(check) {
				count++;
			}
			deq = nextdeq;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 70280
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int n, k, x, y;
	cin >> n >> k >> x >> y;

	if (n <= k)
		cout << x * n;
	else
		cout << x * k + y * (n - k);

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/23/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int INF = 1e9+7;

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

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

  vector<vector<int>> dp(1<<N, vector<int>(N, INF));
  for (int i = 0; i < N; i++)
    dp[1<<i][i] = 0;
  for (int mask = 1; mask < (1<<N); mask++) {
    int pc = __builtin_popcount(mask);
    int cnt = pc;
    for (int k = 0; k < N; k++) {
      if (((1<<k)&mask) == 0)
        continue;
      --cnt;
      auto prev_mask = mask ^ (1<<k);
      for (int t = 0; t < N; t++) {
        if (((1<<t)&prev_mask) == 0)
          continue;
        int cur = (pc^t)%2?B[t]:A[t];
        int nxt = (pc^k)%2?A[k]:B[k];
        if (cur <= nxt)
          dp[mask][k] = min(dp[mask][k], dp[prev_mask][t]+cnt);
      }
//      cerr<<bitset<18>(mask)<<" "<<k<<": " << dp[mask][k]<<endl;
    }
  }
  int ans = *min_element(dp[(1<<N)-1].begin(), dp[(1<<N)-1].end());
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 27008
N = int(input())
H = [int(x) for x in input().split()]
ans = 1
max = H[0]-1
for i in range(N-1):
    if max < H[i + 1]-1:
        max = H[i+1]-1

    if max > H[i+1]:
        ans = 0
        # print(i)
        break
if ans == 1:
    print("Yes")
else:
    print("No")


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

int main(){
  long long x;
  cin >> x;
  
  long long A, B;
  for(long long i = -300; i < 301; ++i){
    for(long long j = -300; j < 301; ++j){
      long long a = pow(i, 5), b = pow(j, 5);
      if(a - b == x){
        A = i;
        B = j;
        break;
      }
    }
  }

  cout << A << ' ' << B << endl;
}

Measured memory_bytes: 4064
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define RMAX 4294967295
#define equals(a,b)(fabs((a)-(b))<EPS)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef complex<double> comp;
typedef vector<complex<double>> vcomp;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef string::const_iterator State;
class ParseError {};
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

class UnionFind {
public:
	vector<int> par, rank, _size;
	int _num;

	UnionFind(int n) {
		par = vector<int>(n);
		rank = vector<int>(n);
		_size = vector<int>(n);
		_num = n;
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
			_size[i] = 1;
		}
	}

	// 木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;

		_num--;
		if (rank[x] < rank[y]) {
			par[x] = y;
			_size[y] += _size[x];
		}
		else {
			par[y] = x;
			_size[x] += _size[y];
			if (rank[x] == rank[y])rank[x]++;
		}
	}

	// xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// xの属する集合のサイズ
	int size(int x) {
		return _size[find(x)];
	}

	// 集合の個数
	int num() {
		return _num;
	}
};

int diff(int d) {
	if (d < 0)d = 24 - (d % 24);
	d %= 24;
	cout << d << endl;
	return min(d, 24 - d);
}

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

	int N;
	cin >> N;
	vi d(N);
	int ansmin = 25;
	rep(i, N) {
		cin >> d[i];
		if (d[i] > 12)d[i] = 24 - d[i];
		ansmin = min(ansmin, d[i]);
	}

	UnionFind uf(2 * N);

	rep(mind, ansmin + 1) {
		rep(i, N - 1) {
			repr(j, i + 1, N) {
				if (abs(d[i] - d[j]) < mind) {
					uf.unite(i * 2, j * 2 + 1);
					uf.unite(i * 2 + 1, j * 2);
				}
				if (abs(d[i] - (24 - d[j])) < mind) {
					uf.unite(i * 2, j * 2);
					uf.unite(i * 2 + 1, j * 2 + 1);
				}
			}
		}
		rep(i, N) {
			if (uf.same(i * 2, i * 2 + 1)) {
				cout << mind - 1 << endl;
				return 0;
			}
		}
	}

	cout << ansmin << endl;

	return 0;
}

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

int main(){
  long long N,P;
  string S;
  cin >> N >> P >> S;
  vector<long long> V(N);
  for(int i=0;i<N;i++) V[i] = S[N-i-1]-'0';
  
  if(P==2 || P==5){
    long long ans=0;
    for(int i=0;i<N;i++){
      if(V[i]%P==0) ans += N-i;
    }
    cout << ans << endl;
    return 0;
  }
  
  vector<long long> pow10(N,1);
  V[0] %= P;
  for(int i=1;i<N;i++){
    pow10[i] = pow10[i-1]*10;
    pow10[i] %= P;
    V[i] *= pow10[i];
    V[i] %= P;
    V[i] += V[i-1];
    V[i] %= P;
  }
  
  map<long long, long long> M;
  M[0] = 1;
  long long ans=0;
  for(int i=0;i<N;i++){
    ans += M[V[i]];
    M[V[i]]++;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4228
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<ll>h(n);
    REP(i,n)cin >> h[i];
    int answer = 0;
    int tmp=0;
    int i=0;
    while(i < n-1){
        if(h[i] >= h[i+1]){
            tmp++;
        }else{
            answer = max(tmp,answer);
            tmp=0;
        }
        i++;
        cerr << tmp << endl;
    }
    answer = max(tmp,answer);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
int gi() {
    char cc = getchar() ; int cn = 0, flus = 1 ;
    while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
    while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
    return cn * flus ;
}
const int N = 1e6 + 5 ; 
int n, a[N], bk ,w1,w2; 
char s[N] ; 
signed main()
{
    n = gi(); scanf("%s", s ) ; n--;
    rep( i, 0, n ) {a[i] = s[i] - '1'; if (a[i]==1) bk = 1 ;} 
    rep( i, 0, n ) if( ( ( i  ) & ( n  ) ) == ( i  ) ) {if (a[i]==1) w1 ^= 1 ; if (a[i]==2) w2^=1;}
    if( w1 ) { printf("1") ; exit(0) ; }
    if( w2 && ( !bk ) ) { printf("2") ; exit(0) ; }
    printf("0") ; 
    return 0 ;
} 

Measured memory_bytes: 5120
/**
 *      ABC 42 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-20 07:29:30
**/

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int A, B, C; cin >> A >> B >> C;
    if (A == 7 && B == 5 && C == 5){
        cout << "YES" << endl;
    }
    else if (A == 5 && B == 7 && C == 5){
        cout << "YES" << endl;
    }
    else if (A == 5 && B == 5 && C == 7){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int main() {
	int n;
	cin >> n;
	vector<int> a(n), g(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	g[0] = a[0];
	for (int i = 1; i < n; ++i) {
		g[i] = gcd(g[i - 1], a[i]);
	}
	int ans = g[n - 2], curg = a[n - 1];
	for (int i = n - 1; i >= 2; --i) {
		ans = max(ans, gcd(g[i - 2], curg));
		curg = gcd(curg, a[i - 1]);
	}
	ans = max(ans, curg);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

ll od(ll n, ll m) {
	if (m%n != 0) { return 0; }

	return od(n, m / n)+1;
}


int main() {
	ll N, P;

	cin >> N >> P;

	if (N == 1) {
		cout << P;
	}

	else if (N >= 40) { cout << 1; }

	else {
		ll ans = 1;

		for (ll i = 2; i*i <= P; i++) {
			if (od(i, P) >= N) { ans = i; }
		}

		cout << ans;
	}


	

	system("PAUSE");
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
int main(){
    ll n ; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        ll x; cin >> x;
        x--;
        a.at(x)=i;
    }
    ll cnt = 1;
    ll mxm = 0;
    for(int i=1;i<n;i++){
        if(a.at(i)>a.at(i-1)){
            cnt++;
        }else{
            mxm = max(mxm,cnt);
            cnt = 1;
        }
    }
    mxm = max(mxm,cnt);
    cout << n-mxm << endl;
}

Measured memory_bytes: 1792
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		String s = sc.next();
		HashSet<Character> set = new HashSet<>();
		//使っている文字をsetに追加
		for (char c : s.toCharArray()) {
			set.add(c);
		}

		if (s.length() != 26) {
			for (char c = 'a'; c <= 'z'; c++) {
				if (set.contains(c)) {
					continue;
				} else {
					System.out.println(s + c);
					return;
				}
			}
		}

		for (int i = s.length() - 1; i > 0; i--) {
			String ss = s.substring(i);//後ろから切り取っていく
			String a = s.substring(0, i - 1);//その余り-1
			//切り取った部分を削除
			for (char c : ss.toCharArray()) {
				set.remove(c);
			}
			
			for (char c = s.charAt(i - 1); c <= 'z'; c++) {
				if (set.contains(c)) {
					continue;
				} else {
					System.out.println(a + c);
					return;
				}
			}
			//切り取った部分を追加
			for (char c : ss.toCharArray()) {
				set.add(c);
			}
		}
		System.out.println(-1);
	}
}

Measured memory_bytes: 24020
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

		Scanner sc = new Scanner(System.in);
		String[] s = sc.next().split("");
		
		String ans = "No";
		for(String ss : s) {
			if(ss.equals("7")) {
				ans = "Yes";
				break;
			}
		}

		System.out.println(ans);
	}


}


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

int main() {
  // ここにプログラムを追記
  //101 で2を出す
  int a , b , c , z;

  cin >> z;
  
  a = z / 100;
  b = ( z - a * 100 ) / 10;
  c = z - ( a * 100 ) - ( b * 10 );
  
  cout << a + b + c << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
ll x[100010], y[100010];

ll mod_mult(ll a, ll b, ll c) {
    return a * b % mod * c % mod;
}
ll mod_mult(ll a, ll b, ll c, ll d) {
    return a * b % mod * c % mod * d % mod;
}

ll solve() {
    sort(x, x+n);
    sort(y, y+m);
    ll X = 0, Y = 0, P = 0, Q = 0;
    for (int i = 0; i < n; i++) {
        X = (X + x[i]) % mod;
        P = (P + i * x[i]) % mod;
    }
    for (int i = 0; i < m; i++) {
        Y = (Y + y[i]) % mod;
        Q = (Q + i * y[i]) % mod;
    }
    return ((mod_mult(n-1, m-1, X, Y) - mod_mult(2, n-1, X, Q) - mod_mult(2, m-1, Y, P) + mod_mult(4, P, Q)) % mod + mod) % mod;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int j = 0; j < m; j++) cin >> y[j];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int main() {
 
int x,y,z=0;
int i,j;
string st;
vector<string> st1;

cin >> x >> y;

for(i=0;i<y;i++)
	st.insert(0,".");
st1.push_back(st);
for(i=0;i<x;i++){
	cin >> st;
	st.insert(0,".");
	st.insert(y+1,".");
	st1.push_back(st);
	}
for(i=0;i<y;i++)
	st.insert(0,".");
st1.push_back(st);

for(i=1;i<=x;i++){
	for(j=1;j<=y;j++){
	if(st1[i].substr(j,1)=="#" &&
	   st1[i].substr(j,1)!=st1[i-1].substr(j,1) && 
	   st1[i].substr(j,1)!=st1[i+1].substr(j,1) &&
	   st1[i].substr(j,1)!=st1[i].substr(j-1,1) &&
	   st1[i].substr(j,1)!=st1[i].substr(j+1,1) 
	){
		z=1;
		goto END;
	 }
	}
}
END:

if(z==0)
	cout << "Yes" << endl;
else
	cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
words_count = {}
count = 0
n.times do
  word = gets.chomp.chars.sort
  if words_count[word].nil?
    words_count[word] = 1
  else
    words_count[word] += 1
  end
end

words_count.each_value do |v|
  unless v == 1
    count += v * (v - 1) / 2
  end
end

puts count

Measured memory_bytes: 69500
def ord(N,n):#N,nは正の整数、Nで割り切れる回数、許容はN^1000
    if n%N!=0:
        return 0
    else:
        return 1+ord(N,n//N)

N=int(input())
A=input()
A=[int(A[i]) for i in range(0,N)]
X=[abs(A[i]-A[i+1]) for i in range(0,N-1)]


cmb=[0 for i in range(0,N-1)]
cmb[0]=0
for i in range(1,N-1):
    cmb[i]=cmb[i-1]+ord(2,N-2-(i-1))-ord(2,i)
data=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    if cmb[i]>0:
        data[i]=0
    else:
        data[i]=1

s=0
for i in range(0,N-1):
    s=(s+X[i]*data[i])%2
if s==1:
    print(1)
else:
    if 1 in X:
        print(0)
    else:
        X=[X[i]//2 for i in range(0,N-1)]
        s=0
        for i in range(0,N-1):
            s=(s+X[i]*data[i])%2
        if s==1:
            print(2)
        else:
            print(0)

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

using namespace std;

int N, M;
vector<vector<int>> E;
int dp[100000];

int memo(int pos) {
	if (dp[pos] != -1)return dp[pos];

	int res = 0;
	for (int i = 0; i < E[pos].size(); i++) {
		res = max(res, memo(E[pos][i]) + 1);
	}
	return dp[pos] = res;
}

int main() {
	cin >> N >> M;
	E.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].push_back(b);
	}
	int ans = -1;
	for (int i = 0; i < N; i++)dp[i] = -1;
	for (int i = 0; i < N; i++)ans = max(ans, memo(i));

	cout << ans << endl;

	return 0;
}

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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

using namespace std;
#define TYPEMAX(type)   numeric_limits<type>::max()
#define TYPEMIN(type)   numeric_limits<type>::min()
typedef long long ll;
typedef pair<int,int> pii;
map<ll,ll> memo;
ll dp(ll x){
    if(x==0ll) return 0;
    if(x==1ll) return 1;
    if(memo.count(x)) return memo[x];
    return memo[x]=1ll+2ll*dp(x/2);
}
int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll x; cin>>x;
    cout<<dp(x);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(void){
    std::string s;
    std::cin >> s;

    long long  sum = 0;
    int n = s.size();

    for(int temp = 0; temp < (1 << n-1); temp++){
        long long t = s[0] - '0';

        for(int i = 0; i < n-1; i++){

            if(temp & (1 << i)){ //1が立っていれば, プラス記号を入れる場所とみなす
                sum += t;
                t = s[i+1] - '0';
            }
            else{
                t *= 10; //1が立っていなければプラス記号を入れないとみなす
                t += s[i+1] - '0';
            }
        }
        sum += t;
    }

    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int D, N;
    
    cin >> D >> N;
    
    if (D == 0) {
        if (N == 100) {
            cout << N + 1;
        }
        else {
            cout << N;
        }
    }
    
    if (D == 1) {
        if (N == 100) {
            cout << (100 * N) + N;
        }
        else {
            cout << 100 * N;
        }
    }
    
    if (D == 2) {
        if (N == 100) {
            cout << (10000 * N) + 100 * N;
        }
        else {
            cout << 10000 * N;
        }
    }
    return 0;
}



Measured memory_bytes: 256