akhauriyash/Code-Regression huggingface dataset:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math


S = list(str(input()))


def calc(en):
  if len(en) != 3:
    return 0
  else:
    ret = int(S[0])
    for i in range(len(en)):
      if en[i] == "+":
        ret += int(S[i+1])
      else:
        ret -= int(S[i+1])
    return ret


def solve(i, en):
  if i == 4:
    if calc(en) == 7:
      return en
    else:
      return ""

  ret = max("", solve(i+1, en+"+"), solve(i+1, en+"-"))
  return ret


if __name__ == "__main__":
  en = solve(1, "")
  print(S[0]+en[0]+S[1]+en[1]+S[2]+en[2]+S[3]+"=7")    



Measured memory_bytes: 38256
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vi blocks[222222];
set<ii> intervals;
int ans;
void cut(int h)
{
	auto it = intervals.lower_bound(mp(h+1,-1));
	if(it==intervals.begin()) return ;
	it--;
	int l=it->fi; int r=it->se;
	if(l<=h&&h<=r)
	{
		cout<<ans<<'\n';exit(0);
		intervals.erase(mp(l,r));
		if(l<=h-1) intervals.insert(mp(l,h-1));
		if(h+1<=r) intervals.insert(mp(h+1,r));
	}
}

void extend()
{
	vector<ii> tmp;
	for(auto x:intervals) 
	{
		if(binary_search(blocks[ans+1].begin(),blocks[ans+1].end(),x.se+1)) tmp.pb(x);
		else tmp.pb(mp(x.fi,x.se+1));
	}
	intervals.clear();
	int l=-1; int r=-1;
	for(auto x:tmp)
	{
		int L=x.fi; int R=x.se;
		if(l==-1)
		{
			l=x.fi; r=x.se;
		}
		else
		{
			if(L>r+1)
			{
				intervals.insert(mp(l,r));
				l=L; r=R;
			}
			else
			{
				//L==r+1
				r=R;
			}
		}
	}
	if(l!=-1) intervals.insert(mp(l,r));
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int r,c,n; cin>>r>>c>>n;
	for(int i=0;i<n;i++)
	{
		int x,y; cin>>x>>y;
		blocks[x].pb(y);
	}
	//int curmin=mn[1];
	intervals.insert(mp(1,1));
	ans=1;
	while(ans<r)
	{
		sort(blocks[ans+1].begin(),blocks[ans+1].end());
		for(int h:blocks[ans+1])
		{
			cut(h);
		}
		extend();
		/*
		for(ii x:intervals)
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		cerr<<"END "<<ans<<'\n';
		*/
		ans++;
	}
	cout<<ans<<'\n';
}


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

int main(){
  int n;
  cin >> n;
  
  int max=0,sum=0,p;
  rep(i,n){
    cin >> p;
    sum += p;
    if(p>max) max = p;
  }
  sum -= max/2;
  
  cout << sum << endl;
    
  return 0;

}


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

int main() {
  int n;
  cin >> n;
  vector<vector<int>>c(10,vector<int>(10));
  rep2(i,1,n+1){
    string s=to_string(i);
    c[s.at(0)-'0'][s.at(s.size()-1)-'0']++;
  }
  int ans=0;
  rep(i,10){
    rep(j,10){
      ans+=c[i][j]*c[j][i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
l=[0]*(10**4+1)
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            f=i**2+j**2+k**2+i*j+j*k+k*i
            if f<=10**4:
                l[f]+=1
for i in range(1,n+1):
    print(l[i])

Measured memory_bytes: 68976
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int n,ww,wl;
	int w[1010],l[1010];
	int cnt=0;
	cin>>n>>ww>>wl;
	for(int i=0;i<n;i++){
		cin>>w[i]>>l[i];
		if(w[i]>=ww&&l[i]>=wl){
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
}     

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue
            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()

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

int main(void)
{
	int n;
	int a[100];

	cin >> n;

	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = n - 1; i >= 0; i--)
		cout << a[i] << (i == 0 ? "": " ");
	cout << endl;
	return 0;
}

Measured memory_bytes: 1160
fun main(args: Array<String>) = ABC163D.main()

object ABC163D {
    fun log(message: Any?) {
        //println(message)// TODO: ←消す
    }

    fun main() {
        val (N, K) = readLongs()

        val sizes = (K..N + 1).asSequence().map { k ->
            val min = (0..k - 1).sum()
            val max = (N - k + 1..N).sum()
            max - min + 1
        }
        val ans = sizes.fold(0L.toModLong(1000000007)) { acc, it -> acc + it }
        println(ans)
    }

    /*####################################################################################*/
    fun readLongs() = readLine()!!.split(" ").map { it.toLong() }

    fun LongRange.sum(): Long {
        val length = this.last - this.first + 1
        return length * (this.first + this.last) / 2
    }

    fun Number.toModLong(base: Long): ModLong = ModLong(this.toLong() % base, base)
    class ModLong(
        private val value: Long,
        private val base: Long
    ) : Number(), Comparable<ModLong> {
        override fun toString(): String = value.toString()
        override fun equals(other: Any?): Boolean = value == other
        override fun hashCode(): Int = value.hashCode()
        operator fun plus(other: Long): ModLong = (this.value + other % base).toModLong(base)
        override fun compareTo(other: ModLong): Int = value.compareTo(other.value)
        override fun toByte(): Byte = value.toByte()
        override fun toChar(): Char = value.toChar()
        override fun toDouble(): Double = value.toDouble()
        override fun toFloat(): Float = value.toFloat()
        override fun toInt(): Int = value.toInt()
        override fun toLong(): Long = value
        override fun toShort(): Short = value.toShort()
    }
}

Measured memory_bytes: 52992
n, g = gets.chomp.split.map(&:to_i)
a = Array.new(n) { Array.new }

n.times do |i|
  a[i] = gets.chomp.split
end

sum = 0
a.each do |a|
  if a[1] == 'JPY'
    sum += a[0].to_i
  else
    sum += a[0].to_f * 380000.0
  end
  
end
puts sum

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

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

    vector<int> b(N - 1);
    rep(i, N - 1) b[i] = a[i + 1] + a[i];

    int last_i = -1;
    rep(i, N - 1) {
        if (b[i] >= L) {
            last_i = i;
            break;
        }
    }

    if (last_i == -1) {
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;
    rep(i, last_i) cout << i + 1 << endl;
    for (int i = N - 2; i > last_i; i--) if (last_i < i) cout << i + 1 << endl;
    cout << last_i + 1 << endl;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
int n;
ll a[200005];
ll dp[200005][5];
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;++i) cin>>a[i];
	//memset(dp,0x7f,sizeof(dp)); // useless
	dp[0][0]=0;
	for (int i=1;i<=n;++i){
		dp[i][0]=dp[i-1][0]+a[i];
		dp[i][1]=min(dp[i][0],dp[i-1][1]+(a[i]? a[i]&1:2));
		dp[i][2]=min(dp[i][1],dp[i-1][2]+!(a[i]&1));
		dp[i][3]=min(dp[i][2],dp[i-1][3]+(a[i]? a[i]&1:2));
		dp[i][4]=min(dp[i][3],dp[i-1][4]+a[i]);
	}
	cout<<dp[n][4]<<endl;
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

int a[3],b[3];
int ans;

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

	REP(i,3) cin>>a[i];
	sort(a,a+3);
	REP(i,3) b[i]=a[i]%2;
	if(b[0]==b[1]&&b[1]==b[2]) {
		;
	}
	else if(b[0]!=b[1]&&b[1]==b[2]) {
		a[1]++,a[2]++;
		ans+=1;
	}
	else if(b[0]==b[2]&&b[0]!=b[1]) {
		a[0]++,a[2]++;
		ans+=1;
	}
	else if(b[0]==b[1]&&b[2]!=b[0]) {
		a[0]++,a[1]++;
		ans+=1;
	}
	ans+=(a[2]-a[0])/2+(a[2]-a[1])/2;
	cout<<ans<<endl;

	return 0;
}


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

using namespace std;

int main(){
    int a,b;
    cin >> a;
    cin >> b;
    
    if(a < 10 && a > 0 && b < 10 && b > 0){
        cout << a * b << endl;
    }
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

struct edge {
	ll to, a, b;
};

vector<edge> g[maxn];

ll cc[maxn], dd[maxn];
ll const magic = 2522;

unordered_map<ll, ll>d[55];

//map<pair<ll, ll>, ll> d;
set<pair<ll,pair<ll, ll>>> st;

void check(ll u, ll s, ll new_d) {
	if (d[u].find(s) == d[u].end()) {
		d[u][s] = new_d;
		st.insert({ new_d ,{u, s} });
	} else {
		ll old_d = d[u][s];
		if (old_d > new_d) {
			st.erase({ old_d ,{u, s} });
			d[u][s] = new_d;
			st.insert({ new_d ,{u, s} });
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	ll n, m, s;
	cin >> n >> m >> s;
	for (ll i = 0; i < m; i++) {
		ll u, v, a, b; cin >> u >> v >> a >> b;
		g[u].push_back({ v, a, b });
		g[v].push_back({ u, a, b });
	}

	for (ll i = 1; i <= n; i++) {
		cin >> cc[i] >> dd[i];
	}

	st.insert({ 0, {1, s} });
	d[1][s] = 0;

	while (!st.empty()) {
		auto p = *st.begin();
		st.erase(st.begin());

		ll rast = p.X;
		ll u = p.Y.X, cur_s = p.Y.Y;
		if (cur_s < s - magic) {
			continue;
		}

		if (cur_s < magic) {
			ll v = u, w = dd[u];
			check(v, cur_s + cc[u], rast + dd[u]);
		}

		for (auto e : g[u]) {
			if (e.a <= cur_s) {
				check(e.to, cur_s - e.a, rast + e.b);
			}
		}
	}

	vector<ll> ans(n + 1, LLONG_MAX);

	for (ll i = 2; i <= n; i++) {
		for (auto p : d[i]) {
			ans[i] = min(ans[i], p.Y);
		}
	}

	for (ll i = 2; i <= n; i++) {
		cout << ans[i] << '\n';
	}

	return 0;
}

/*

*/


Measured memory_bytes: 18972
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF 9999999
#define LINF 99999999999
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}

class info{
public:
	ll x;
	ll y;
	ll h;

};

bool cmp(info a, info b){
	if(a.h == 0){
		return false;
	}
	if(b.h == 0){
		return true;
	}
	if(a.x == b.x){
		return a.y < b.y;
	}
	return a.x < b.x;
	
}
int manhattan(info a, pair<int, int> kouho){
	return abs(a.x - kouho.first) + abs(a.y - kouho.second);
}
bool check(info a, info b, pair<int, int> kouho){
	int ma = manhattan(a,kouho);
	int mb = manhattan(b,kouho);
	if(a.h==0){
		if(manhattan(a,kouho) == 0 || b.h+mb>ma){
			return false;
		}
	}

	if(b.h == 0){
		if(manhattan(b,kouho) == 0 || a.h+ma>mb){
			return false;
		}		
	}


	if(ma+a.h != mb+b.h && !(a.h == 0 && b.h==0)){
		return false;
	}
	return true;
}



int main(void){
	int n;
	cin>>n;
	vector<info> infos;
	rep(i,n){
		ll mx,my,mh;
		cin>>mx>>my>>mh;
		info tmp;
		tmp.x = mx;
		tmp.y = my;
		tmp.h = mh;
		infos.push_back(tmp);
	}
	sort(infos.begin(),infos.end(),cmp);
	reverse(infos.begin(),infos.end());
	vector<pair<int,int> > kouho;
	rep(i,101){
		rep(j,101){
			pair<int,int> p;
			p.first = i;
			p.second = j;
			kouho.push_back(p);
		}
	}
	bool turai = true;

	REP(i,n){
		REP(j,i){
			REP(k,kouho.size()){
				if(!check(infos[i],infos[j],kouho[k])){
					kouho.erase(kouho.begin() + k);
				}
			}
			if(kouho.size() <= 1){
				break;
			}
		}
		if(kouho.size() <= 1){
			//cout<<"hoge"<<endl;
			turai = false;
			break;
		}
	}
	while(turai){
		int huga = 3;
	}
	cout<<kouho[0].first<<" "<<kouho[0].second<<" "<<manhattan(infos[infos.size() - 1], kouho[0]) + infos[infos.size() - 1].h<<endl;
	
	return 0;
}

Measured memory_bytes: 512
from bisect import bisect_left,bisect_right
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aset=set(a)
bset=set(b)
ans=0
for i in range(n):
  if a[i] in bset:
    ans=max(i-bisect_left(b,a[i]),ans)
b=(b+b+b)[n-ans-1:n+n-ans-1]
for i in range(n):
  if a[i]==b[i]:
    exit(print("No"))
print("Yes")
print(*b)

Measured memory_bytes: 154784
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    string s; cin >> s;
    for (int i = 0; i < 3; i++) {
        if (s[i] == '1') s[i] = '9';
        else if (s[i] == '9') s[i] = '1';
    }
    cout << s << '\n';
}

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

    solve();

    return 0;
}

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

int main(){

    int D,T,S;
    cin>>D>>T>>S;

    int x=D/S,y=D%S;

    if(x>T){

        cout<<"No"<<endl;
    }

    else if(x<T){

        cout<<"Yes"<<endl;
    }

    else if(x==T&&y==0){

        cout<<"Yes"<<endl;
    }

    else {

        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) cout << 1 << endl;
  else if (h % 2 == 0) cout << h / 2 * w << endl;
  else if (w % 2 == 0) cout << w / 2 * h << endl;
  else cout << (h * w + 1) / 2 << endl;
}

Measured memory_bytes: 256
# 解説YouTubeを参考（写経）
S = input()
N = 13
dp = [0 for _ in range(N)]
dp[0] = 1

mod = 1e9+7
mul = 1
for i in range(len(S)-1, -1, -1):
  nextDP = [0 for _ in range(N)]
  c = S[i]
  if c=="?":
    for k in range(10):
      for j in range(N):
        nextDP[(k*mul + j)%N] += dp[j]
        nextDP[(k*mul + j)%N] %= mod  
  else:
    k = int(c)
    for j in range(N):
      nextDP[(k*mul + j)%N] += dp[j]
      nextDP[(k*mul + j)%N] %= mod  
    
  mul *= 10
  mul %= N
  dp = nextDP
print(int(dp[5]))

Measured memory_bytes: 44908
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){
    int N; cin >> N;
    int C[N-1], S[N-1], F[N-1]; REP(i,N-1) cin >> C[i] >> S[i] >> F[i];
    VI ans(N,0);
    REP(i,N-1){
        int tmp = S[i] + C[i];
        FOR(j,i+1,N-1){
            if(tmp < S[j]) tmp = S[j];
            else if(tmp % F[j]) tmp = (tmp + F[j]) / F[j] * F[j];
            tmp += C[j];
        }
        ans[i] = tmp;
    }
    REP(i,N) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] cnt = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
            cnt[A[i]-1]++;
        }
        long tmp = 0L;
        for (int i=0;i<N;i++) {
            tmp += (long)cnt[i]*(cnt[i]-1)/2;
        }
        for (int i=0;i<N;i++) {
            long minus = (long)cnt[A[i]-1]*(cnt[A[i]-1]-1)/2;
            tmp -= minus;
            cnt[A[i]-1]--;
            tmp += (long)cnt[A[i]-1]*(cnt[A[i]-1]-1)/2;
            System.out.println(tmp);
            tmp += minus-(long)cnt[A[i]-1]*(cnt[A[i]-1]-1)/2;
            cnt[A[i]-1]++;
        }
    }
}

Measured memory_bytes: 93296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    long long a,b,x; cin>>a>>b>>x;
    cout<<(a==0?b/x+1:b/x-(a-1)/x)<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <utility>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <time.h>
using namespace std;
 
typedef long long int ll;
typedef pair<ll, ll> ipair;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define ln length()
#define rep(i,n) for(i=0;i<n;i++)
#define fu(i,a,n) for(i=a;i<=n;i++)
#define fd(i,n,a) for(i=n;i>=a;i--)
#define all(a)  a.begin(),a.end() 
#define gi(n) scanf("%d",&n)
#define gl(n) scanf("%lld",&n)
#define pi(n) printf("%d",n)
#define pl(n) printf("%lld",n);
#define pp printf(" ")
#define pn printf("\n")

char s[105];
int c[26];
int main() {
	scanf("%s", s);
	string s1, s2;
	s1 = "";
	s2 = "";
	ll l = strlen(s);
	ll i;
	rep(i, l) {
		c[s[i] - 'a']++;
	}
	rep(i, 26) {
		while(c[i]) {
			s1+=(char)(i + 'a');
			c[i]--;
		}
	}
	scanf("%s", s);
	l = strlen(s);
	rep(i, l) {
		c[s[i] - 'a']++;
	}
	fd(i, 25, 0) {
		while(c[i]) {
			s2+=(char)(i + 'a');
			c[i]--;
		}
	}
	if(s1 < s2) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int N = intRead();
        int[] n = SpRead(' ').Select(i => int.Parse(i)).ToArray();
        int[] H = SpRead(' ').Select(i => int.Parse(i)).ToArray();
        double MinAbs = 50000000;
        int MinP = 0;
        double A = 0;
        for (int i = 0; i < N; i++)
        {
            A = n[0] - H[i] * 0.006;
            A = Math.Abs(A - n[1]);
            if (MinAbs > A) { MinAbs = A;MinP = i + 1; }
        }
        Console.WriteLine(MinP);
    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }

}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    string S, T; cin >> S >> T;
    bool ok = true;
    REP(i, S.length()) {
        if (S[i] != T[i]) ok = false;
    }
    yesno(ok);

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3656
S=input()
T=input()
ls=len(S)
lt=len(T)
cnt2=lt

for i in range(0,ls-lt+1):
  cnt=0
  for ss,tt in zip(S[i:],T):
    if ss!=tt:
      cnt+=1
  
  if cnt<cnt2:
    cnt2=cnt

print(cnt2)


Measured memory_bytes: 9108
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,s ;
int fun(int k)
{
    int p=n,sm=0 ;
    while(p)
    {
        sm+=(p%k) ;
        p/=k ;
    }
    return sm ;
}
int32_t main()
{
    cin>>n>>s ;
    for(int i = 2 ; i*i <= n ; i++)
    {
        if(fun(i)==s){cout<<i<<endl ; return 0 ; }
    }
   // cout<<fun(n+1)<<" "<<s<<endl ;
    int ans=-1 ;
    for(int i = 1 ; i*i<=(n-s) ; i++)
    {
        if((n-s)%i!=0) continue ;
        int b1=i+1 ;
        if(b1>1 && fun(b1)==s)
        {
            if(ans==-1) ans=b1 ; else ans=min(ans,b1) ;
        }
        int b2=(n-s)/i+1 ;
        if(b2>1 && fun(b2)==s)
        {
            if(ans==-1) ans=b2 ; else ans=min(ans,b2) ;
        }
    }
    if(fun(n+1)==s)
    {
        if(ans==-1) ans=n+1 ;
    }
    cout<<ans<<endl ;
}


Measured memory_bytes: 3612
def solve():
    N, M = map(int, input().split())
    edges = [[] for _ in [0]*N]
    r_edges = [[] for _ in [0]*N]

    for _ in [0]*M:
        a, b = map(int, input().split())
        edges[a].append(b)
        r_edges[b].append(a)

    c = get_strongly_connected_components(edges, r_edges)
    group = [0]*N
    for i in range(len(c)):
        for v in c[i]:
            group[v] = i

    result = []
    append = result.append
    for _ in [0]*int(input()):
        a, b = map(int, input().split())
        append("1" if group[a] == group[b] else "0")

    print("\n".join(result))


def get_strongly_connected_components(edges, r_edges):
    import sys
    sys.setrecursionlimit(10**7)
    v_count = len(edges)
    order = [0]*v_count
    k = [1]

    def get_order(v):
        order[v] = 1
        [None for dest in edges[v] if order[dest] == 0 and get_order(dest)]
        order[v] = k[0]
        k[0] += 1

    def get_components(v):
        order[v] = 0
        return [v] + [_v for dest in r_edges[v] if order[dest] > 0 for _v in get_components(dest)]

    [None for v in range(v_count) if order[v] == 0 and get_order(v)]
    return [get_components(v) for v, _ in sorted(enumerate(order), key=lambda x: x[1], reverse=True) if order[v] > 0]

if __name__ == "__main__":
    solve()

Measured memory_bytes: 35068
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> T;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using vec = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    char x;
    cin>>x;
    x++;
    cout<<x<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int x;
    cin >> x;
    cout << (x ^ 1);


    return 0;
}


Measured memory_bytes: 3536
n, k = map(int, input().split())
x = list(map(int, input().split()))

min_t = 10 ** 9

import bisect

snuke = bisect.bisect_left(x, 0)
if snuke < n and x[snuke] == 0:
    k -= 1
    n -= 1
    del x[snuke]

for i in range(k+1):
    if i == 0:
        left = 0
    elif snuke - i >= 0:
        left = abs(x[snuke - i])
    else:
        left = 10 ** 9

    if k - i == 0:
        right = 0
    elif snuke + k - i - 1 <= n - 1:
        right = abs(x[snuke + k - i - 1])
    else:
        right = 10 ** 9

    min_t = min(min_t, min(left, right) * 2 + max(left, right))

print(min_t)

Measured memory_bytes: 14568
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;

const int INF = 1001001001;
const ll INFLL = 1001001001001001001LL;


template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }


int main() {


	
	int H,W;

	scanf("%d %d", &H,&W);
	


	
	
	char Mat[56][56];
	/*
	for (int i = 0;i<N;i++) {
		int tmp;
		scanf("%d",&tmp);
		VA.push_back(tmp);
	}
	*/

	for (int i = 0; i < 56; i++) {
		sprintf(Mat[i], ".......................................................");
	}



	for (int i = 1; i<=H; i++) {
		char buf[55];
		scanf("%s", buf);
		sprintf(Mat[i], ".%s.", buf);
	}




	

	bool ans = true;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (Mat[i][j] == '#') {
				if (Mat[i-1][j] == '.' && Mat[i+1][j] == '.' && Mat[i][j-1] == '.' && Mat[i][j+1] == '.') {
					ans = false;
				}

			}
		}
	}

	if (ans == true) {
		printf("Yes");
	}
	else {
		printf("No");
	}


	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var N = int.Parse(input[0]);
        long x = int.Parse(input[1]);
        var A = Console.ReadLine().Split(" ").Select(long.Parse).ToArray();
        
        Array.Sort(A);

        var count = 0;
        for (var i = 0; i < N; i++)
        {
            if (x >= A[i])
            {
                x -= A[i];
                count++;
            }
        }

        if (x > 0 && count == A.Length) count--;
        
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 28244
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	

struct edge{
	ll point;
	ll index;
};

vector <vector<edge>> graph;
vector <bool> visited;
vector <ll> ans;
ll k = 0;

void dfs(ll u,ll color){
	visited[u] = true;
	ll c = 1;
	for (int z=0;z<graph[u].size();z++){
		if (visited[graph[u][z].point]) continue;
		if (color == c) c++;
		ans[graph[u][z].index] = c;
		k = max(k,c);
		dfs(graph[u][z].point,c++);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	graph.resize(n+1);
	visited.resize(n+1,false);
	ans.resize(n-1);
	for (int z=0;z<n-1;z++){
		ll u,v;
		cin >> u >> v;
		edge temp;
		temp.point = v;
		temp.index = z;
		graph[u].push_back(temp);
		temp.point = u;
		graph[v].push_back(temp);
	}
	visited[1] = true;
	dfs(1,0);
	cout << k << endl;
	for (ll i : ans){
		cout << i << endl;
	} 
}
 

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



int sc1() {int x; scanf("%d", &x); return x;}

long long sc2() {long long x; scanf("%lld", &x); return x;}



#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
#define  MAX              100007








int main()
{

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n = Int;
	int arr[n + 1];
	int arr2[n + 1];

	For(n) arr[i] = Int, arr2[i] = arr[i];
	if (n == 2)
	{
		cout << arr2[1] << endl << arr2[0] << endl;
		return 0;
	}

	sort(arr, arr + n);
	int a = arr[n - 1];
	int b = arr[n - 2];
	for (int i = 0; i < n; i++)
	{
		if (arr2[i] == a) cout << b << endl;
		else cout << a << endl;

	}

	return 0;
}




Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;

int main() {
    int h,n;
    cin >> h >> n;
    int a[n],sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if(h <= sum) {
        cout << "Yes";
    }else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  string s;cin>>s;
  string ans = "";
  rep(i,s.size()){
    if(s[i] == 'B'){
      if(ans.size() > 0)ans.pop_back();
    }
    else ans.pb(s[i]);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int a[3][3] = {};
  REP(i, 3) {
    REP(j, 3) { cin >> a[i][j]; }
  }
  int n;
  cin >> n;
  vi b(n);
  REP(i, n) { cin >> b[i]; }
  bool checked[3][3] = {};
  REP(i, 3) {
    REP(j, 3) {
      REP(k, n) {
        if (a[i][j] == b[k])
          checked[i][j] = true;
      }
    }
  }

  bool ok = false;
  REP(i, 3) {
    if (checked[i][0] && checked[i][1] && checked[i][2]) {
      ok = true;
    }
  }
  REP(j, 3) {
    if (checked[0][j] && checked[1][j] && checked[2][j]) {
      ok = true;
    }
  }
  if (checked[0][0] && checked[1][1] && checked[2][2]) {
    ok = true;
  }
  if (checked[0][2] && checked[1][1] && checked[2][0]) {
    ok = true;
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int mod = 1000000007;
int n, m;
int s[2000];
int t[2000];
int dp[2001][2001][2];

int dfs(int i, int j, int k) {
	if (i == n || j == m) { return (k == 0); }
	if (dp[i][j][k] != -1) { return dp[i][j][k]; }
	
	int ret;
	
	if (k == 0) {
		int res1 = dfs(i + 1, j, k);
		int res2 = dfs(i, j, !k);
		ret = res1 + res2;
	}
	
	if (k == 1) {
		int res1 = dfs(i, j + 1, k);
		int res2 = 0;
		if (s[i] == t[j]) {
			res2 = dfs(i + 1, j + 1, !k);
		}
		ret = res1 + res2;
	}
	ret %= mod;
	return dp[i][j][k] = ret;
}

signed main() {
	int i, j, k;
	
	cin >> n >> m;
	rep(i, n) cin >> s[i];
	rep(i, m) cin >> t[i];
	rep(i, n + 1) rep(j, m + 1) rep(k, 2) dp[i][j][k] = -1;
	cout << dfs(0, 0, 0) << endl;
	return 0;
}

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

template <class T> inline bool chmax(T& a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}

int count(const string& s, int n) {
  int a[30] = {0};
  int b[30] = {0};
  for(int i = 0; i < s.size(); ++i) {
    if(i < n) {
      a[s[i] - 'a']++;
    } else {
      b[s[i] - 'a']++;
    }
  }
  int ans = 0;
  for(int i = 0; i < 26; ++i) {
    if(a[i] > 0 && b[i] > 0) {
      ans++;
    }
  }
  return ans;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  int mx = 0;
  for(int i = 1; i < S.size() - 1; ++i) {
    chmax(mx, count(S, i));
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	long n; cin >> n;
	long sum=n; char ch;
	while(1)
	{
		cin >> ch ;
		if(ch=='=') break;
		else cin >> n;
		if(ch=='+') sum+=n;
		else if(ch=='*') sum*=n;
		else if(ch=='-') sum-=n;
		else if(ch=='/') sum/=n;
	}
	cout << sum << endl;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  int ans = 0;
  for(int i = 0; i + 1 < N; i++){
    for(int j = i+1; j < N; j++){
      ans += d[i] * d[j];
    }
  }

  cout << ans << endl;

  return 0;
}


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


void solve(long long N){
  int ans = 0;
  if (N <= 9) {
    ans = N;
  } else if (N <= 99) {
    ans = 9;
  } else if (N <= 999) {
    ans = 9 + (N - 100 + 1);
  } else if (N <= 9999) {
    ans = 9 + 900;
  } else if (N <= 99999){
    ans = 9 + 900 + (N - 10000 + 1);
  } else {
    ans = 9 + 900 + 90000;
  }
  std::cout << ans << std::endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
from subprocess import*
call(('pypy3','-c',r"""
def main():
    from bisect import bisect_left
    I=10**9+1
    n,q,*t=map(int,open(0).read().split())
    d=tuple(t[-q:])
    t=t[:-q]
    N0=2**(q-1).bit_length()
    data=[I]*2*N0
    for x,l,r in sorted(((x,bisect_left(d,s-x)+N0,bisect_left(d,t-x)+N0)for s,t,x in zip(t[::3],t[1::3],t[2::3])),reverse=1):
        while l<r:
            if r&1:
                r-=1
                data[r-1]=x
            if l&1:
                data[l-1]=x
                l+=1
            l//=2
            r//=2
    a=[]
    for k in range(N0-1,q+N0-1):
        s=I
        while~k:
            if data[k]<s:s=data[k]
            k=(k-1)//2
        a.append(-(s==I)or s)
    print('\n'.join(map(str,a)))
main()
"""))

Measured memory_bytes: 170436
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

vector<int> have(10);

int solve(int N){
    string S;
    cin>>S;
    int ba=0;
    int peo=0;
    for(int i=0;i<100;i++){
       if(S[i]=='S') {
           ba+=have[peo]+1;
           have[peo]=0;
       }else if(S[i]=='L'){
           have[peo]+=ba+1;
           ba=0;
       }else have[peo]++;
       peo++;
       if(peo==N) peo=0;
    }
    sort(have.begin(),have.begin()+N);
    for(int i=0;i<N;i++){
        cout<<have[i]<<" ";
    }
    cout<<ba<<endl;
}

int main(){
    while(1){
        int N;
        cin>>N;
        if(N) solve(N);
        else break;
        have.assign(10,0);
    }
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }

const int MAX_BIT = 20;

int main() {
    FAST_IO();
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    // if i-th, j-th (N - 1 > i > j) is answer
    // comb(A[i], A[j]) <= comb(A[N-1], A[j])
    pii ans;
    int pos = upper_bound(A.begin(), A.end(), A[N-1] / 2.0) - A.begin();
    if(pos == 0) {
        ans = {A[N - 1], A[pos]};
    } else if(pos == N - 1) {
        ans = {A[N - 1], A[pos - 1]};
    } else {
        if(A[N - 1] / 2.0 - A[pos - 1] > A[pos] - A[N - 1] / 2.0) {
            ans = {A[N - 1], A[pos]};
        } else ans = {A[N - 1], A[pos - 1]};
    }
    cout << ans.first << " " << ans.second << "\n";
}

Measured memory_bytes: 640