akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;

int n;
int x[maxn],y[maxn],f[5][3];

int main()
{
	cin>>n;
	int x1;int y1;
	cin>>x1>>y1;
	f[1][1]=x1+y1;f[1][2]=x1+y1;
	f[2][1]=x1-y1;f[2][2]=x1-y1;
	f[3][1]=y1-x1;f[3][2]=y1-x1;
	f[4][1]=-x1-y1;f[4][2]=-x1-y1;
	for(int i=2;i<=n;++i)
	  {
	  	  cin>>x[i]>>y[i];
	  	  if(x[i]+y[i]>f[1][1])
	  	    f[1][1]=x[i]+y[i];
	  	  if(x[i]+y[i]<f[1][2])
	  	    f[1][2]=x[i]+y[i];
		     if(x[i]-y[i]>f[2][1])
	  	      f[2][1]=x[i]-y[i];
		     if(x[i]-y[i]<f[2][2])
	  	      f[2][2]=x[i]-y[i];
		  if(y[i]-x[i]>f[3][1])
	  	    f[3][1]=y[i]-x[i];
		  if(y[i]-x[i]<f[3][2])
	  	    f[3][2]=y[i]-x[i];	  
		     if(-x[i]-y[i]>f[4][1])
	  	      f[4][1]=-x[i]-y[i];
		     if(-x[i]-y[i]<f[4][2])
	  	      f[4][2]=-x[i]-y[i];	  	    
	  }
	long long ans=0;
	for(int i=1;i<=4;++i)
	  {
	  	  if(f[i][1]-f[i][2]>ans) ans=f[i][1]-f[i][2];;
	  	 //cout<<f[i][1]<<" "<<f[i][2]<<endl;
	  }
	cout<<ans<<endl;     
}


Measured memory_bytes: 5184
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int val = 0;
	int n; cin>>n;
	string s; cin>>s;	

	int pref[n+1] = {0};

	forn(i,n){
		pref[i+1] = pref[i];
		if(s[i] == 'R'){
			val++;
			pref[i+1]++;
		} 
	}

	int ans = MOD;

	forn(i,n+1){
		int f = 0;
		f += i-pref[i];
		int left = val-pref[i];
		if(left <= 	f){
			f = f;
		}
		else{
			f += left-f;
		}
		ans = min(ans, f);
	}
	cout<<ans<<ln;

	return 0;
}

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

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

    int n;
    cin >> n;
    long long A[n][n];
    bool F[n][n];

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> A[i][j];
            F[i][j] = true;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){

                // Aには最短距離が示されているはずなのでダメ
                if(A[j][i] + A[i][k] < A[j][k]){
                    cout << -1 << endl;
                    return 0;
                }

                // i - k
                // | /
                // j
                // このとき j-kのパスはとりのぞきj-i i-kを生き残らせる
                //（多く生き残らせて存在する道路の長さの和を最小にするため）
                if(A[j][k] == A[j][i] + A[i][k] and i != j and i != k){
                    F[j][k] = false;
                }
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(F[i][j]) ans += A[i][j];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
package main

import(
  "fmt"
  "strconv"
	"bufio"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}

func abc138atest(rerow []string){
	var flag = 0
	var ans = 0
	for _,num := range rerow{
		if flag != 1{
			ans, _ = strconv.Atoi(num)
			flag = 1
		}else{
			if ans < 3200{
				fmt.Println("red")
			}else{
              fmt.Printf("%s\n", num)
			}
		}
	}
}

func main(){
	rerow := []string{}
	for i := 0; i < 2; i++{
		s := Rr()
		rerow = append(rerow, s[0])
	}
	abc138atest(rerow)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
int cnt[200001];
 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &p : a) cin >> p;
  for (int p : a) ++cnt[p];
  long long ans = 0;
  for (int i = 1; i <= 200000; ++i) {
    ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
  }
  for (int p : a) {
  	cout << ans - cnt[p] + 1 << '\n';
  }
  return 0;
}

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


int main(){
    int n;
    cin>>n;
    int a[n],b[n],c[n]={},cnt=0;
    r(i,n)cin>>a[i],b[i]=a[i];
    sort(b,b+n);
    r(i,n)if(a[i]==b[i])c[i]=1,cnt++;
    if(cnt==n){
            cout<<0<<endl;
            return 0;
        }
    int m;
    cin>>m;
    r(i,m){
        int l,r;
        cin>>l>>r;l--;r--;
        if(a[l]==b[l])cnt--;
        if(a[r]==b[r])cnt--;
        if(a[l]==b[r])cnt++;
        if(a[r]==b[l])cnt++;
        swap(a[l],a[r]);
        if(cnt==n){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 6688
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    FOR(i, A, B + 1) {
        string S = to_string(i);
        if (S[0] == S[4] && S[1] == S[3]) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#pragma warning(disable: 4996)
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int h, n, a;
	cin >> h >> n;
	int sum = 0;

	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
	}
	cout << (sum >= h ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
 
int main() {
    int n,k;
    int num = 1;
    cin >> n >> k;

    for(int i = 0; i < n; i++){
        if(num < k) num *= 2;
        else num += k;
    }

    cout << num << endl;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << 
#define bit(n) (1LL << (n))
#define int long long
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
template <class T>
bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}


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

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    int cnt = 1;
    string tmp = s[0];
    rep(i, n)
    {
        if(s[i]!=tmp){
            tmp = s[i];
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 9540
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

int main()
{
	int a, p;
	std::cin >> a >> p;

	std::cout << (a * 3 + p) / 2 << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
int i=0;
int j=0;
int k=0;
int s=0;


for(i=0; i<=a; i++){
   for(j=0; j<=b; j++){
        for(k=0; k<=c; k++){
int f=0;
f=500*i+100*j+50*k;
          if(d==f) s+=1;

            }
              }
                }

printf("%d",s);


return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=4e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int N,K;
    cin >> N >> K;

    vector<i64> x(N),y(N),xs,ys;
    rep(i,0,N){
        cin >> x[i] >> y[i];
        xs.push_back(x[i]);
        ys.push_back(y[i]);
    }

    sort(begin(xs),end(xs));
    sort(begin(ys),end(ys));

    auto count_points=[&](i64 x1,i64 y1,i64 x2,i64 y2){
        int res=0;
        rep(i,0,N) if(x1<=x[i] and x[i]<=x2 and y1<=y[i] and y[i]<=y2) ++res;
        return res;
    };

    i64 ans=inf64;
    rep(i,0,N) rep(j,i+1,N) rep(k,0,N){
        int lb=k,ub=N;
        while(ub-lb>1){
            int mid=(lb+ub)/2;
            if(count_points(xs[i],ys[k],xs[j],ys[mid])>=K) ub=mid;
            else lb=mid;
        }
        if(ub<N) ans=min(ans,(xs[j]-xs[i])*(ys[ub]-ys[k]));
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int N = 100;
void trace(int A[], int n){
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}
void BubbleSort(int A[], int n){
    int cnt = 0, flag = 1;
    while(flag){
        flag = 0;
        for(int j = n-1; j > 0; j--){
            if(A[j] < A[j-1]){
                int tmp;
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                cnt ++;
            }
        }
    }
    trace(A,n);
    cout << cnt << endl;
}
int main(){
    int n;
    int A[N+1];
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i];
    BubbleSort(A,n);
}

Measured memory_bytes: 3100
n = gets.chomp.to_i
nn = Math.sqrt(n*2)
l = nn.floor
if l * (l + 1) == n * 2 then
  puts (1..l).to_a
elsif ((l - 1) * l <= n*2) && (n*2 <= l * (l + 1)) then
  ll = l * (l + 1) / 2
  ret = (1..l).to_a
  rem = ll - n
  ret.delete(rem)
  puts ret
else
  ll = (l + 1) * (l + 2) / 2
  ret = (1..(l+1)).to_a
  rem = ll - n
  ret.delete(rem)
  puts ret
end

Measured memory_bytes: 1788
#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<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int main() {
    i64 N;
    cin >> N;
    cout << (N * (N + 1) / 2 - N) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 2000000
#define MOD 1000000007
#define endl "\n"
bool ans[MAX];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli N,K;
    cin>>N>>K;
    for(lli i = 0; i<K; i++){
        lli d;
        cin>>d;
        for(lli j = 0; j<d; j++){
            lli a;
            cin>>a;
            ans[a-1] = true;
        }
    }
    lli s =0;
    for(lli i = 0; i<N; i++)
    {
        if(!ans[i])
            s++;
    }
    cout<<s<<endl;

}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());

  int64_t sizeSum = 0;
  int canEat = -1;
  for (int i = 0; i < N; i++) {
    if (canEat < i) {
      sizeSum += A[i];
      canEat = i;
    }

    while (canEat < N - 1 and A[canEat + 1] <= sizeSum * 2) {
      sizeSum += A[canEat + 1];
      canEat++;
    }
    if (canEat == N - 1) {
      printf("%d\n", N - i);
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
//
// Created by mustafa on 17/07/19.
//
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std ;

#define ll long long
#define submitStage int TCF = 1 ;
#define testStage int TCF = 1000 ;
#define all(v)  v.begin() , v.end()
#define Start while(TCF--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define FastInputOutput ios_base :: sync_with_stdio( 0 ) ; cin.tie( 0 ) ; cout.tie( 0 ) ;
#define ReadFromFile(x)  freopen( x, "rt" , stdin ) ;
#define WriteToFile(x)  freopen( "in.txt", "wt" , stdout ) ;
#define D(x) scanf("%d",&x);
#define LLD(X) scanf("%lld",&x);
#define in(x,...) scanf(x,__VA_ARGS__)
#define out(x,...) printf(x,__VA_ARGS__)
/// for debugging
string to_string(string s) {return '"' + s + '"';}string to_string(const char* s) {return to_string((string) s);}string to_string(bool b) {return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void debug_out() { cerr << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/// start driven program
const int N=1e6+7  , MOD= 1e9+7;

int mod(int k, int n){
    return((k %= n) < 0) ? k+n : k;
}
bool isP(int num){
    int ret=0;
    int temp=num;
    while(num){
        int m=num%10;
        ret=ret*10 + m;
        num/=10;
    }
    return (temp==ret);
}

int main(){
    submitStage Start {
        int n,m;
        D(n)   D(m)
        int cnt=0;
        FOR(i,n,m+1){
            cnt+= isP(i);
        }
        printf("%d\n",cnt);
    }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

const int N=1e5+5;
const int mod=1e9+7;
map<pair<int,int> ,int> m;
int32_t main() {
int n,m;
cin>>n>>m;

vector<pair<int,int> > student,checkpoint;
    for (int i = 0; i < n; ++i) {
        int a,b;
        cin>>a>>b;
        student.push_back({a,b});
    }
    for (int i = 0; i < m; ++i) {
        int a,b;
        cin>>a>>b;
        checkpoint.push_back({a,b});
    }
    for (int i = 0; i < n; ++i) {
        int now=1e9,idx=0;
        for (int j = 0; j < m ; ++j) {
            int mi=abs(student[i].first-checkpoint[j].first)+abs(student[i].second-checkpoint[j].second);
            if(mi<now)now=mi,idx=j+1;
        }
        cout<<idx<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int m = std.nextInt();
//        BigDecimal sum = BigDecimal.ZERO;
        long sum = 0;
        long baseCount = 0;
        long liftCount = 0;
        for (int i = 0; i < m; i++) {
            int d = std.nextInt();
            long c = std.nextLong();
            baseCount += c;
            sum += d * c;
        }

        liftCount = (sum - 1) / 9;

        long ans = baseCount - 1 + liftCount;
        System.out.println(ans);

    }
}


Measured memory_bytes: 92708
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var s = bufio.NewScanner(os.Stdin)

func main() {
	a := make([]int, 5)
	for i := 0; i < 5; i++ {
		s.Scan()
		a[i], _ = strconv.Atoi(s.Text())
	}
	min := (a[0] - 1) % 10
	minIndex := 0
	for i := 0; i < 5; i++ {
		if (a[i]-1)%10 < min {
			min = a[i] % 10
			minIndex = i
		}
	}
	ans := 0
	for i := 0; i < 5; i++ {
		if i == minIndex {
			ans += a[i]
			continue
		}
		if a[i]%10 == 0 {
			ans += a[i]
			continue
		}
		ans += ((a[i] + 10) / 10) * 10
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>
#include <cassert>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<int>a(n),b(n),c(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    rep(i,n){
        cin >> b[i];
    }
    rep(i,n-1){
        cin >> c[i];
    }
    int sm = 0;
    rep(i,n){
        if(i==0){
            sm += b[a[i]];
        }else{
             sm += b[a[i]];
            if(a[i]==a[i-1]+1){
                sm += c[a[i-1]];
            }
        }
    }
    cout << sm << endl;
    return 0;
}

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

int main(void){
    long long x,y;
    scanf("%lld%lld",&x,&y);
    if (x==0 || y==0){
        if (x>y){
            printf("%lld\n",llabs(y-x)+1);
        } else {
            printf ("%lld\n",llabs(y-x));
        }
            } else if (x*y>0){
        if(x<y){
            printf("%lld\n",y-x);
        } else {
            printf("%lld\n",x-y+2);
        }
    } else {
            printf("%lld\n",llabs(llabs(x)-llabs(y))+1);
    }
	return 0 ;
}

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

int main(){
    string S,T;
    cin >> S;
    int tail=0;
    int n=S.length();

    for(int i=0; i<n; i++){
        switch(S[i]){
            case '0':
                T[tail]='0';
                tail++;
                break;
            case '1':
                T[tail]='1';
                tail++;
                break;
            case 'B':
                if(tail!=0) tail--;
                break;
        }
    }

    for(int i=0; i<tail; i++){
        cout << T[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

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

    set<ll> s;
    for (int i = 0; i < k; i++) {
        ll x = a+i;
        if (x <= b)
            s.insert(x);
    }
    for (int i = 0; i < k; i++) {
        ll x = b-i;
        if (x >= a)
            s.insert(x);
    }

    for (auto ite = s.begin(); ite != s.end(); ite++)
        cout << *ite << endl;

    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define pii pair<int, int>
#define ld long double

const int INF = 2e9 + 1;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 != 0) cout << "IMPOSSIBLE";
    else cout << (a + b) / 2;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
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;
}

class UnionFind {
  public:
    // 親の番号を格納する。親の場合 -1 になる
    vector<int> Parent;

    // 宣言されたとき Parent の値はすべて -1 にする
    UnionFind(int N) { Parent = vector<int>(N, -1); }

    // 与えられた値 x がどの親であるか調べる
    int root(int x) {
        // x が親だったとき
        if (Parent[x] < 0)
            return x;
        // 辺の縮約をいっしょにおこなう
        return Parent[x] = root(Parent[x]);
    }

    // 木の全体の数を返す
    int size(int x) {
        // マイナスがついているのは root
        // 以下の数をマイナスの値で管理しているから
        return -Parent[root(x)];
    }

    // 2つの引数を同じ親にする
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);

        // 同じ親の場合くっつけない
        if (x == y)
            return false;

        // x のほうが必ず大きな size にしたい
        if (size(x) < size(y))
            swap(x, y);
        Parent[x] += Parent[y];
        Parent[y] = x;
        return true;
    }

    bool isame(int x, int y) {
        if (root(x) == root(y))
            return true;
        else
            return false;
    }
};

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

    int N;
    cin >> N;
    auto uni = UnionFind(N * 2);

    REP(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;

        if (w % 2 != 0) {
            uni.merge(u + N, v);
            uni.merge(u, v + N);
        } else {
            uni.merge(u, v);
            uni.merge(u + N, v + N);
        }
    }

    REP(i, N) {
        if (uni.isame(0, i))
            std::cout << 0 << '\n';
        else
            std::cout << 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 1280
use proconio::{fastout, input};

#[fastout]
fn main() {
    let mut s: String;
    input! {s: String};

    let s_index = s.len() / 2;

    let s1 = &s[0..s_index];

    let s2 = &s[s_index + 1..];

    if s1 == s2 {
        println!("Yes")
    } else {
        println!("No")
    }
}


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

int main() {
  int A[9], marked;
  marked = 0;
  for (int i = 0; i < 9; i++) cin >> A[i];
  int N, b; cin >> N;
  for (int j = 0; j < N; j++) {
    cin >> b;
    for (int i = 0; i < 9; i++) {
      if (A[i] == b) marked |= (1<<i);
    }
  }
  int bingos[] = {0b000000111, 0b000111000,
                  0b111000000, 0b001001001,
                  0b010010010, 0b100100100,
                  0b100010001, 0b001010100};
  bool res = false;
  for (int i = 0; i < 8; i++) {
    if ((marked | bingos[i]) == marked) res = true;
  }
  if (res) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B
  * Structured Program II - How many ways?
  */
object Main {
  def main(args: Array[String]): Unit = {
    val dataSets = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" ").map(_.toInt))
      .map { case Array(n, x) => (n, x) }
      .takeWhile(_ != (0, 0))
      .toList
    val results = dataSets.map { case (n, x) =>
      // Memory Limit Exceeded
      // (1 to n).combinations(3).count(_.sum == x)
      (for (a <- 1 to n; b <- 1 to n if a < b; c <- 1 to n if a < c && b < c && (a + b + c) == x)
        yield 1).length
    }
    results.foreach(println)
  }

}

Measured memory_bytes: 88500
#[allow(unused_macros)]
macro_rules! p {
    ($x:expr $(, $tail:expr)*) => {
        let mut s = String::new();
        s.push_str(format!("{:?}", $x).as_str());
        $(
            s.push_str(format!(", {:?}", $tail).as_str());
        )*
        println!("{}", s);
    };
}

#[allow(unused_macros)]
macro_rules! pl {
    ($($x:expr), *) => {
        $(println!("{:?}", $x);)*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input! {
        source = src,
        n: usize,
        s: chars,
    }
    let red = s.iter().filter(|&&x| x == 'R').count();
    if red > n / 2 {
        "Yes"
    } else {
        "No"
    }.to_string()
}

// Test Code

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    };
}

test! {
    r"4
      RRBR" => "Yes",
    r"4
      BRBR" => "No",
    r"3
      RBR" => "Yes",
    r"3
      BBR" => "No",
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int h[100001];
    int dp[100001];
    dp[n-1]=0;
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=n-2;i>=0;i--)
    {
        dp[i]=abs(h[i]-h[i+1])+dp[i+1];
        for(int j=1;j<=k;j++)
        {
            if(i+j>=n)
                break;
                        dp[i]=min(dp[i],abs(h[i]-h[i+j])+dp[i+j]);
        }
    }
    cout<<dp[0];
    return 0;
}

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

typedef long long ll;

int main()
{
	ll n,m=1000;
	cin>>n;
	ll arr[n];
	for (ll i=0; i<n; i++)
	{
		cin>>arr[i];
	}
	ll s;
	for (ll i=0; i<n-1; i++)
	{
		if (arr[i]>=arr[i+1])
		  continue;
		else
		{
			s=m/arr[i];
			m=m%arr[i];
			m=m+s*arr[i+1];
		}
	}
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
const int MOD = 1e9 + 7; 

long long fastMonkey(int a, int b) {
    if(b == 0)
        return 1;
    long long x = fastMonkey(a, b / 2);
	if(b % 2 == 0) {
		return (x * x) % MOD;
	} else {
		return (((x * x) % MOD) * a) % MOD;
	}
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n;
    cin >> n;
    if(n < 2) {
        cout << 0;
    } else {
        long long ans = fastMonkey(10, n);
        ans -= 2 * fastMonkey(9, n);
        ans += fastMonkey(8, n);
        ans = ((ans % MOD) + MOD) % MOD;
        cout << ans;
    }
}

Measured memory_bytes: 3644
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

inf = float("inf")

def main():
    inp = [i for i in readlines()]
    for _inp in inp:
        n, x = map(int, _inp.split())
        if n == x == 0:
            return
        else:
            count = 0
            l = [i for i in range(1, n+1)]
            for a, b, c in combinations(l, 3):
                if a + b + c == x:
                    count += 1
            print(count)
            
if __name__=='__main__':
    main()


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

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

  long long a, b, n;

  cin >> a >> b >> n;
  long long x = min(n, b - 1);

  cout << (a * x / b) - a * (x / b) << '\n';
}

Measured memory_bytes: 3608
// Ryo Kamoi
// #define DEBUG

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

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

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

int INF = 1000000000;

pii dp[33][33][33][33]; // num of groups, yobi

int h, w, s;
int min_pow;
int field[33][33];

pii pii_sum(pii a, pii b) {
    if (a.second >= 0 && b.second >= 0) {
        return pii(a.first+b.first, min(a.second, b.second));
    }
    if (a.first == 1 && b.first == 1) {
        return pii(1, min_pow + a.second + b.second);
    }
    return pii(-INF, -INF);
}

pii solve(int u, int d, int l, int r) {
    if (dp[u][d][l][r].first > 0) {
        return dp[u][d][l][r];
    }

    if (u==d && l==r) {
        return dp[u][d][l][r] = pii(1, field[u][l]-min_pow);
    }
    
    pii output = pii(-INF, -INF);
    for (int i=u; i<d; i++) {
        output = max(output, pii_sum(solve(u, i, l, r),
                    solve(i+1, d, l, r)));
    }
    for (int i=l; i<r; i++) {
        output = max(output, pii_sum(solve(u, d, l, i),
                    solve(u, d, i+1, r)));
    }
#ifdef DEBUG
    cout << u << " " << d << " " << l << " " << r << endl;
    cout << output.first << " " << output.second << endl;
#endif
    return dp[u][d][l][r] = output;
}

int main(){
    while(1) {
        cin >> h >> w >> s;
        if (h==0) break;

        // initialize dp
        REP(i, h) {
            for (int j=i; j<h; j++) {
                REP(k, w) {
                    for (int l=k; l<w; l++) {
                        dp[i][j][k][l] = pii(0, 0);
                    }
                }
            }
        }

        int sum_supply = 0;
        REP(i, h) {
            REP(j, w) {
                cin >> field[i][j];
                sum_supply += field[i][j];
            }
        }
        min_pow = sum_supply - s;
#ifdef DEBUG
        cout << min_pow << endl;
#endif

        pii p = solve(0, h-1, 0, w-1);
        cout << p.first << ' ' << p.second << endl;
    }
}



Measured memory_bytes: 7724
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#define inf 1000000007
using namespace std;
 
int main(void){
    int n;
    cin >> n;
    long long int check[5];
    for(int i = 0; i < 5; i++)
        check[i] = 0;
    string s[n];
    long long int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        if(s[i][0]=='M') check[0]++;
        else if(s[i][0]=='A') check[1]++;
        else if(s[i][0]=='R') check[2]++;   
        else if(s[i][0]=='C') check[3]++;
        else if(s[i][0]=='H') check[4]++;                     
    }
    for(int i = 0; i < 3; i++){
        for(int j = i+1; j < 4; j++)
            for(int k = j+1; k < 5; k++){
                if(i!=j&&j!=k&&k!=i)
                ans +=check[i]*check[j]*check[k];
            }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
using namespace std;
#define int long long

constexpr int N = 3;
array<array<int, N>, N> card;
array<array<int, N>, N> hole;
array<int, 100> b;

void mark(int a)
{
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (a == card[i][j])
                hole[i][j]++;
        }
    }
}

bool isBingo()
{
    bool can = false;
    for (int i = 0; i < N; i++)
    {
        can |= hole[i][0] && hole[i][1] && hole[i][2];
        can |= hole[0][i] && hole[1][i] && hole[2][i];
    }
    can |= hole[0][0] && hole[1][1] && hole[2][2];
    can |= hole[0][2] && hole[1][1] && hole[2][0];

    return can;
}

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

    for (auto &&i : hole)
        for (auto &&j : i)
            j = 0;

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            int tmp;
            cin >> tmp;
            card[i][j] = tmp;
        }
    }

    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
        mark(b[i]);
    }

    cout << (isBingo() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,a[10005],b[10005];
  ll asum=0,bsum=0,k;
  
  cin >> n;
  for (i=0;i<n;i++) cin >> a[i];
  for (i=0;i<n;i++) cin >> b[i];
  
  for (i=0;i<n;i++) asum+=a[i];
  for (i=0;i<n;i++) bsum+=b[i];
  
  k=bsum-asum;
  
  if (k<0){
    cout << "No" << endl;
    return 0;
  }
  
  if (k==0){
    for (i=0;i<n;i++){
      if (a[i]!=b[i]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  ll ra=0,rb=0;
  for (i=0;i<n;i++){
    if (a[i]==b[i]) continue;
    if (a[i]>b[i]){
      rb+=a[i]-b[i];
    }else{
      if ((b[i]-a[i])%2==0){
        ra+=(b[i]-a[i])/2;
      }else{
        ra+=(b[i]-a[i]+1)/2;
        rb++;
      }
    }
  }
  
  if (ra<=k && rb<=k && (k-ra)*2==k-rb){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define INF 1000000
int matrixChainOrder(int *);
  
int res,sum;
int mainn[100][100],cap[100],p[101];
  
int matrixChainOrder(int *p){
  int n,l,i,j,k,q;
  
  n = res;
  for(i = 1;i <= n;i++){
    mainn[i][i] = 0;
  }
  for(l = 2;l <= n;l++){
    for(i = 1;i <= n-l+1;i++){
      j = i + l - 1;
      mainn[i][j] = INF;
      for(k = i;k <= j-1;k++){
  
    q = mainn[i][k] + mainn[k+1][j] + (p[i-1] * p[k] * p[j]);
  
    mainn[i][j] = (int)fmin(mainn[i][j],q);
  
      }
    }
  }
  
 return mainn[1][n];
}

int main(){
  int i,j,n,re;
  
  scanf("%d",&n);
  
  res = n;
   
  for(i = 1;i <= n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
  
  re = matrixChainOrder(p);
  
  printf("%d\n",re);
  
  return 0;
}

Measured memory_bytes: 640
import sys

N,A,B=map(int,input().split())

BIT=0
for i in range(N):
    if (1<<i) & A!=(1<<i) & B:
        BIT+=1

if BIT%2==1:
    print("YES")
else:
    print("NO")
    sys.exit()

check=[0]*(1<<N)

ANS=[]
check[A]=1
check[B]=1

def route(x,i,j):#xから始まるルート,bit iは固定.j 残りbitの個数
    NOW=x
    ANS.append(NOW)
    check[NOW]=1

    for k in range(1<<j):
        for l in range(N):
            if check[NOW ^ (1<<l)]==0 and l!=i:
                NOW=NOW ^ (1<<l)
                check[NOW]=1
                ANS.append(NOW)
                break

    return NOW^(1<<i)

checkbit=[0]*N     
for i in range(N-1,-1,-1):
    for j in range(N):
        if (1<<j)&A!=(1<<j)&B and checkbit[j]==0:
            break
    A=route(A,j,i)
    checkbit[j]=1

ANS.append(B)
print(*ANS)


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

string s[101];
int j=0;

int solve( int p) {
    int res = 0, sz=s[j].size();
    if (isdigit(s[j][p])) return s[j][p]-'0';
    if (s[j][p] == '+') {
        while (s[j+1].size() >sz) {
            j++;
            res += solve(p+1);
        }
    }
    else {
        res = 1;
        while (s[j+1].size() > sz) {
            j++;
            res *= solve(p+1);
        }
    }
    return res;
}

int main() {
    int n;
    while (cin >> n, n) {
        rep(i, 100) s[i]="";
        rep(i, n) cin >> s[i];
        j=0;
        cout << solve(0) << endl;
    }
}



Measured memory_bytes: 3160
import bisect

N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 0

for i in range(N-1):
  k = A[i]
  for j in range(i+1, N):
    l = A[j]
    res = bisect.bisect_left(A, k+l)
    ans += res-j-1
    
print(ans)


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


set<int> setpos[26];
int n;
string s;


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

    cin >> n >> s;
    for (int i = 0; i < n; i++) setpos[s[i] - 'a'].insert(i + 1);
    int q, idx, iq, lq, rq;
    char cq;
    cin >> q;
    while (q--) {
        cin >> idx;
        if (idx == 1) {    // 1 iq cq
            cin >> iq >> cq;
            if (s[iq - 1] != cq) {
                setpos[s[iq - 1] - 'a'].erase(iq);
                setpos[cq - 'a'].insert(iq);
                s[iq - 1] = cq;
            }
        } else {    // 2 lq rq
            cin >> lq >> rq;
            int cnt = 0;
            for (int c = 0; c < 26; c++) {
                auto it = setpos[c].lower_bound(lq);
                if (it != setpos[c].end() && *it <= rq) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 24220
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let s = it.next().unwrap().bytes().collect::<Vec<_>>();
    if s[2] == s[3] && s[4] == s[5] {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
N,W=map(int,input().split())
#dp=[ [0]*(W+1) for i in range(N+1) ]

Wl=[]
Vl=[]
for i in range(N):
  w,v=map(int,input().split())
  Wl.append(w)
  Vl.append(v)
V=max(Vl)
dp=[ [10**20]*((V+1)*(N+1)) for i in range(N+1) ]
dp[0][0]=0
#print(dp)
for i in range(1,N+1):
  for v in range((V+1)*(N+1)):
    #print(i,w)
    if v>=Vl[i-1]:
      dp[i][v]=min(dp[i-1][v-Vl[i-1]]+Wl[i-1],dp[i-1][v])
    else:
      dp[i][v]=dp[i-1][v]

ans=0
for i in range(len(dp[N])):
  if dp[N][i]<=W and i>ans:
    ans=i
print(ans)

Measured memory_bytes: 144136
import sys

def MI(): return map(int, sys.stdin.readline().split())

md = 10 ** 9 + 7

n_max = 1005
fac = [1]
for i in range(1, n_max + 1): fac.append(fac[-1] * i % md)
ifac = [1] * (n_max + 1)
ifac[n_max] = pow(fac[n_max], md - 2, md)
for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1) % md

def main():
    n, a, b, c, d = MI()
    pn = b - a + 1  # 班人数の種類数
    dp = [[0] * (n + 1) for _ in range(pn + 1)]
    # dp[i][j]...i番目の人数の班まで決めて全体でj人が決まったときの場合の数
    dp[0][0] = 1
    ps = 0
    for i in range(pn):
        p = i + a  # 班人数
        low = n - (p + b) * (b - p + 1) * d // 2
        up = (a + p - 1) * (p - a) * d // 2
        for j in range(max(low, 0), min(n, up) + 1):
            pre = dp[i][j]
            if pre == 0: continue
            dp[i + 1][j] += pre
            dp[i + 1][j] %= md
            r = n - j  # 残りの人数
            for g in range(c, d + 1):
                if j + p * g > n: break
                dp[i + 1][j + p * g] += pre * fac[r] * ifac[r - p * g] * ifac[g] * pow(ifac[p], g, md)
                dp[i + 1][j + p * g] %= md
        ps += p
    print(dp[pn][n])

main()


Measured memory_bytes: 128988
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
vector<pair<int,int>> vt;
// H×Wの迷路，(sx, sy)から歩いて移動できる所のワープ回数をqueueで求める まだ行ったことのないtimeは-1

void walk (int H, int W, int sx, int sy, vector<vector<char>> &maze, vector<vector<int>> &time) {
    vector<int> dx = {-1, 1, 0, 0};
    vector<int> dy = {0, 0, -1, 1};

    queue<P> que;
    que.push(P (sx, sy));

    while (que.size() > 0) {
        P p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
          
            if (nx > 0 && nx <= H && ny > 0 && ny <= W && maze[nx][ny] == '.' && time[nx][ny] == -1) {
                time[nx][ny] = time[p.first][p.second];
              //cout<<nx<<" "<<ny<<endl;
              vt.push_back({nx,ny});
                que.push(P (nx, ny));
            }
        }
    }
    return;
}

// (sx, sy)からワープで移動できるところのワープ回数を求める
void warp (int H, int W, int sx, int sy, vector<vector<char>> &maze, vector<vector<int>> &time, queue<P> &que) {
    for (int i = -2; i <= 2; i++) {
        for (int j = -2; j <= 2; j++) {
            int nx = sx + i;
            int ny = sy + j;
            if (nx > 0 && nx <= H && ny > 0 && ny <= W && maze[nx][ny] == '.' && time[nx][ny] == -1) {
                time[nx][ny] = time[sx][sy] + 1;
                que.push(P (nx, ny));
            }
        }
     }
    return;
}



int main () {
    int H, W, sx, sy, gx, gy; //sはスタート，gはゴール
    cin >> H >> W >> sx >> sy >> gx >> gy;
    
    vector<vector<char>> maze(H + 1, vector<char> (W + 1));
    for (int i = 1; i <= H; i++) {
        string s;
        cin >> s;
        for (int j = 1; j <= W; j++) {
            maze[i][j] = s[j - 1];
        }
    }

    vector<vector<int>> time(H + 1, vector<int> (W + 1, -1));
    
    time[sx][sy] = 0;
    
    queue<P> que;
    que.push(P (sx, sy));
    
    int time_max = 0; //timeに書かれている数の最大値

    while (que.size() > 0) {
        if (time[gx][gy] != -1) {
            break;
        }
vt.clear();
        while (que.size() > 0) {
            P p = que.front();
          //cout<<p.first<<" "<<p.second<<endl;
            que.pop();
            walk(H, W, p.first, p.second, maze, time);
          vt.push_back({p.first,p.second});
        }
      
        
        //ワープをする 上の歩きでtimeが更新されたところだけからワープしたいので一度timeを別のものにコピーする
        

        
      for(int i=0;i<vt.size();i++){
        int ni=vt[i].first,nj=vt[i].second;
        warp(H, W, ni, nj, maze, time, que);
      }
        time_max++;
    }

    cout << time[gx][gy] << endl;
}





Measured memory_bytes: 8736
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length = 2*a+2*b;

        System.out.println(area+" "+length);
    }
}


Measured memory_bytes: 26252