akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
    
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define int long long

int32_t main(){
    int n;
    cin >> n;
    int v[n];
    REP(i, n) cin >> v[i];
    
    if(n == 1){
        cout << v[0]/2 << endl;
        return 0;
    }
    
    int ans = 0;
    REP(i, n-1){
            ans += (v[i]+v[i+1])/2;
            if((v[i]+v[i+1])%2 == 1 && (v[i]+v[i+1]/2 > 1)){
                v[i+1] = 1;
            }
            else v[i+1] = 0;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll ans;
  if((b-a)%2==0){
    ans=(b-a)/2;
  }
  if((b-a)%2==1){
    if(a-1>=n-b){
      ans=(n-(n-b+1+a))/2+n-b+1;
    }
    if(a-1<n-b){
      ans=(b-a-1)/2+a;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
N = int(input())
S = [input() for i in range(N)]

c = 0
w = 0
t = 0
r = 0


for j in range(N):
	if S[j] == "AC":
		c += 1
	elif S[j] == "WA":
		w += 1
	elif S[j] == "TLE":
		t += 1
	elif S[j] == "RE":
		r += 1
		
print("AC x " + str(c))
print("WA x " + str(w))
print("TLE x " + str(t))
print("RE x " + str(r))

Measured memory_bytes: 16328
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int An[] = new int[N];
		for(int i = 0;i < N;i++){//値取得
			An[i] = sc.nextInt();
		}

		System.out.println(solve(N,An));

	}
	
	private static int solve(int N,int[] An){
       		ArrayList<Integer> an = new ArrayList<>();
		for(int a : An){
		an.add(a);
		}
		//Sorting
     		Collections.sort(an);

			//aの最大は配列の0番目と偶数番目の数を全て足したもの
			int amax = 0;
			for(int i = 0;i < an.size();i = i + 2){
			amax = amax + an.get(i); 
			}
			
			//bの最大
			int bmax = 0;
			for(int i = 1;i <  an.size();i = i + 2){
				bmax = bmax + an.get(i); 
			}
		int subtraction =  amax - bmax;
			if(subtraction > 0){
			return subtraction;
			}else if(subtraction < 0){
			return -subtraction;
			}
			return 0;


	}


}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
string s;
int main() {
  string ans="A C";
  for (int i = 0; i < 3; ++i) {
  	cin>>s;
    if (i == 1) ans[1] = s[0];
  }
  cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M 1000000007
#define INF 999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define MAX 1000005
#define fs first
#define sc second
#define N 7
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;


ll a1[100005]={0};
ll a2[100005]={0};

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
 cin.tie(0);
string str;
ll n,a,b,c=0,p,q,sum=0,cnt=0,x;
cin>>x>>a>>b;
ll d1=abs(x-a);
ll d2=abs(x-b);
if(d1>d2)
cout<<"B"<<endl;
else
cout<<"A"<<endl;







return 0;

}

Measured memory_bytes: 256
import itertools

S = input()

for op1, op2, op3 in itertools.product('+-', repeat=3):
    if eval(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]) == 7:
        print(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + "=7")
        exit()


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

using ll = long long;

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列として入力を受け取る
template<typename T>
void read_vec(vector<T>& v, size_t n){
    for(size_t i = 0; i < n; i++){
        T t;
        cin >> t;
        v.push_back(t);
    }
}
//

int main(){
    ll N;
    read(N);
    string ans = "No";
    for(ll i = 1; i <= 9; ++i){
        if(N % i == 0 && N / i <= 9) ans = "Yes"; 
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
SP = []
for i in range(N):
    s, p = input().split()
    p = int(p)
    SP.append([s, p, i + 1])

SP.sort(key=lambda x: [x[0], 100 - x[1]])

for i in range(N):
    print(SP[i][2])

Measured memory_bytes: 3060
#include<cstdio>
#define sacnf scanf
#define pritnf printf
#define srnad srand
#define rnad rand
#define sl(sl_a) strlen(sl_a)
#define gt(gt_a) goto gt_a
#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))
#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))
#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))
#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))
#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))
#define re register
#define inl inline
#define br break
#define con continue
#define stt struct
#define nms namespace
#define gc getchar
#define rt return
#define infa (0x3f3f3f3f)
#define infb (0x7fffffff)
#define infd (0x7f)
#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)
#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)
#define fin(filein_a) freopen(filein_a".in","r",stdin)
#define fout(fileout_a) freopen(fileout_a".out","w",stdout)
typedef long long ll;
typedef int itn,nti,tin,tni,nit;
using namespace std;
const nit maxa=1004;
const nit maxb=54;
const nit maxc=4;
const tni maxd=24;
#include<iostream>

string x;
tni s;

tin main()
{
	cin>>x;
	//
	s=x.size();
	if(x[0]==x[s-1])
	{
		if(s%2)
		{
			printf("Second\n");
		}
		else
		{
			pritnf("First\n");
		}
	}
	else
	{
		if(s%2)
		{
			pritnf("First\n");
		}
		else
		{
			printf("Second\n");
		}
	}
	//
	rt 0;
}

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

long gcd( int a, int b ) {
	return b ? gcd( b, a%b ) : a;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int A, B;
	cin >> A >> B;
	cout << lcm( A, B ) << endl;;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;

int n;
int A, B, C;
int D[100];
int main() {
    cin >> n;
    cin >> A >> B;
    cin >> C;
    for (int i = 0; i < n; i++) {
        cin >> D[i];
    }

    int ans = 0;
    
    // テ」ツδ暗」ツδε」ツδ氾」ツδウテ」ツつーテ」ツ?ョテ」ツつォテ」ツδュテ」ツδェテ」ツδシテ」ツ?ョテ・ツ青暗ィツィツ?
    int sum = 0;
    
    // テゥツ卍催ゥツ??10,9,8,...)テ」ツ?ォテ」ツつステ」ツδシテ」ツδ暗」ツ?凖」ツつ?
    sort(D, D + n);
    reverse(D, D + n);
    for (int i = 0; i < n; i++) {
    	sum+=D[i];
    	ans=max(ans,(sum+C)/(A+B*(i+1)));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

int main(){
	string s;
	cin>>s;
	if(s[0]=='7' or s[1]=='7' or s[2]=='7')
	{
		 cout<<"Yes"<<endl;
	}
	else
	{
		 cout<<"No"<<endl;
	}
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

void add(ll& a, ll b){
  a = (a+b) % MOD;
}

void mul(ll& a, ll b){
  a = (a*b) % MOD;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  ll pre; cin>>pre;
  vll a(n-1);
  rep(i,n-1){
    ll x; cin>>x;
    a[i]=x-pre;
    pre=x;
  }
  cin>>pre;
  vll b(m-1);
  rep(i,m-1){
    ll y; cin>>y;
    b[i]=y-pre;
    pre=y;
  }
  ll xsum=0;
  rep(i,n-1){
    ll l=i, r=n-2-i;
    ll s=a[i];
    mul(s,l+1);
    mul(s,r+1);
    add(xsum,s);
  }
  ll ysum=0;
  rep(i,m-1){
    ll l=i, r=m-2-i;
    ll s=b[i];
    mul(s,l+1);
    mul(s,r+1);
    add(ysum,s);
  }
  ll ans=xsum*ysum%MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
	int n, k;
	int a=1;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		if(a*2-a < k){a *= 2;}
		else a+=k;
	}
	cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main() {
    ll n,x,y;
    cin>>n>>x>>y;
    V ans(n,0);
    for(ll i=1;i<=n;i++){
        for(ll j=i+1;j<=n;j++){
            ans[min(j-i,abs(i-x)+abs(j-y)+1)]++;
        }
    }
    rep(i,n-1)cout<<ans[i+1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <utility>

using vvi = std::vector<std::vector<int>>;

std::vector<int> DistanseFrom(const vvi& edges, int from)
{
    using namespace std;
    constexpr int nil = -1;

    int nextDist {};
    const int n = edges.size();
    queue<int> currentQ;
    queue<int> nextQ;
    vector<int> distances(n, nil);

    nextQ.push(from);
    distances[from] = nextDist;
    ++nextDist;

    while (!nextQ.empty())
    {
        currentQ = nextQ;
        nextQ = queue<int>();
        
        while (!currentQ.empty())
        {
            int c = currentQ.front();
            currentQ.pop();

            for (const auto& e : edges[c])
            {
                if (distances[e] == nil)
                {
                    nextQ.push(e);
                    distances[e] = nextDist;
                }
            }
        }
        
        ++nextDist;
    }

    return distances;
}

void solve()
{
    using namespace std;

    int n;
    cin >> n;

    //隣接リスト形式(1オリジン)
    vvi edges(n + 1);

    //読み込み
    for (int i = 1; i <= n; ++i)
    {
        int u, k;
        cin >> u >> k;

        edges[u] = vector<int>(k);

        for (int j = 0; j < k; ++j)
        {
            cin >> edges[u][j];
        }
    }

    auto dist = DistanseFrom(edges, 1);

    for (int i = 1; i <= n; ++i)
    {
        cout << i << " " << dist[i] << endl;
    }
}

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


Measured memory_bytes: 3120
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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 grid[1010][1010][2], sum[1010][1010][2];

int main() {
  int N, K;
  cin >> N >> K;
  rep(i, N) {
    int x, y;
    char tmp;
    cin >> x >> y >> tmp;
    bool c = (tmp=='W' ? 0 : 1);
    grid[x%K][y%K][(x/K+y/K+c)%2]++;
  }
  rep(i, K) rep(j, K) rep(k, 2)
    sum[i+1][j+1][k] = sum[i+1][j][k]+sum[i][j+1][k]-sum[i][j][k]+grid[i][j][k];
  int ans = 0;
  for (int i=1; i<=K; i++) {
    for (int j=1; j<=K; j++) {
      rep(k, 2) {
        int res = sum[K][K][k]-sum[i][K][k]-sum[K][j][k]+sum[i][j][k]*2;
        res += sum[i][K][k^1]+sum[K][j][k^1]-sum[i][j][k^1]*2;
        chmax(ans, res);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16128
#include <stdio.h>
#include <string.h>

int N, L;
char S[112][112];
char tmp[112];

int main(void)
{
	scanf("%d%d", &N, &L);
	for (int i = 0; i < N; ++i) { scanf("%s", &S[i]); }

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			if (strcmp(S[i], S[j]) < 0)
			{
				strcpy(tmp, S[i]);
				strcpy(S[i], S[j]);
				strcpy(S[j], tmp);
			}
		}
	}

	for (int i = 0; i < N; ++i) { printf("%s", &S[i]); }
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
# A - キャンディーとN人の子供イージー

# 一人目にはキャンディーを一個、二人目には二個、N人目にはN個あげていくと
# 必要なキャンディーは合計何個か？

child = int(input())

answer = int(child * (child + 1) / 2)

print(answer)


Measured memory_bytes: 9076
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1e5 + 20 ;
int n ;
string s ;

vector <pii> edges ;

inline void err () {
	cout << "-1\n" ;
	exit(0) ;
}

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

	cin >> s ;
	n = s.size() ;

	s = "#" + s ;

	if (s[n] == '1' || s[1] == '0') err() ;

	for (int i = 1 ; i < n ; i ++) {
		if (s[i] != s[n - i]) err() ;
	}

	int last = 1 , p = 0 , cur = 0 ;
	for (int i = 2 ; i <= n / 2 ;  i ++) {
		if (s[i] == '1') {
			edges.push_back({++ p , cur}) ;
			cur = p ;
	
			for (int j = 0 ; j < i - last - 1 ; j ++) {
				edges.push_back({++ p , cur}) ;
			}
			
			last = i ;
		}
	}

	edges.push_back({++ p , cur}) ;
	cur = p ;

	for (int i = 0 ; i < n - last - 1 ; i ++) {
		edges.push_back({++ p , cur}) ;
	}

	for (pii p : edges) cout << p.F + 1 << ' ' << p.S + 1 << '\n' ;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
	#define ll long long
	#define f(i,a,b) for(ll i=a;i<b;i++)
	#define fi(i,a,b) for(ll i=b;i>=a;i--)
	using namespace std;
	ll mod(ll a)
	{
	if(a>0)
	return a;
	else
	return -a;
	}
	ll min(ll a,ll b)
	{
	if(a>b)
	return b;
	else
	return a;
	}
	ll gcd(ll a, ll b)
	{
	    if (b == 0)
	        return a;
	    return gcd(b, a % b);

	}
	ll max(ll a,ll b)
	{
	if(a<b)
	return b;
	else
	return a;
	}
	int main()
	{
	string s;
	string t;
	cin>>s>>t;
	int n=s.size(),m=t.size();
	int cnt=0,mx=0;
	for(int i=0;i<n-m+1;i++)
	{
		cnt=0;
		for(int j=0;j<m;j++)
		{
			if(s[i+j]==t[j])cnt++;
			mx=max(mx,cnt);
		}
	}
	cout<<m-mx;
	return 0;
	}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            num[i] = -1;
        }

        int s, c;
        boolean flag = true;
        for (int i = 0; i < m; i++) {
            s = sc.nextInt() - 1;
            c = sc.nextInt();
            if (num[s] == -1) {
                num[s] = c;
            } else if (num[s] != c) {
                flag = false;
                break;
            }
        }

        if (num[0] == 0 && n > 1) {
            flag = false;
        }

        if (!flag) {
            System.out.println(-1);
            return;
        }

        if (num[0] == -1 && n > 1) {
            num[0] = 1;
        }

        for (int i = 0; i < n; i++) {
            if (num[i] == -1) {
                num[i] = 0;
            }
            System.out.print(num[i]);
        }

    }
}

Measured memory_bytes: 23892
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<iomanip>
#include<functional>
#include<unordered_map>
#define io ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define ll long long
#define P pair<int,int>
#define lc rt*2
#define rc rt*2+1
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const double PI = 3.1415926536;

using namespace std;

deque<char> dq;
string s;
int main()
{
	io;
	cin >> s;
	for (auto i : s)
		dq.push_back(i);
	int flag = 0;
	int q;
	cin >> q;
	while (q--)
	{
		int p, f;
		char c;
		cin >> p;
		if (p == 1)
			flag ^= 1;
		if (p == 2)
		{
			cin >> f >> c;
			--f;
			if (flag == f)
				dq.push_front(c);
			else
				dq.push_back(c);
		}
	}
	s.clear();
	for (auto i : dq)
		s += i;
	if (flag)
		reverse(s.begin(), s.end());
	cout << s;
	return 0;
}


Measured memory_bytes: 1168
#include <stdio.h>
int main()
{
int a,b,c,n1,n2,n3 = 0;
scanf("%i %i %i",&a,&b,&c);
  if (a <= b && a <= c) n1 = a;
  if (b <= a && b <= c) n1 = b;
  if (c <= a && c <= b) n1 = c;
  if (((a >= b && a <= c) || (a >= c && a <= b))) n2 = a;
  if (((b >= a && b <= c) || (b >= c && b <= a))) n2 = b;
  if (((c >= a && c <= b) || (c >= b && b <= a))) n2 = c;
  if (a >= b && a >= c) n3 = a;
  if (b >= c && b >= a) n3 = b;
  if (c >= a && c >= b) n3 = c;
    printf("%i %i %i\n",n1,n2,n3);
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = 998244353;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(12e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

ll pow_mod(ll a, ll x){
    ll res = 1;
    while(x>0){
        if(x&1){
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        x >>= 1;
    }
    return res;
}

ll n, a[305], dp[305][90500], sum, ans;

int main() {
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ans = pow_mod(3,n);
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        sum += a[i];
        for(int j=0;j<=sum;j++){
            dp[i+1][j+a[i]] += dp[i][j];
            dp[i+1][j+a[i]] %= MOD;
            dp[i+1][j] += dp[i][j]*2;
            dp[i+1][j] %= MOD;
        }
    }
    for(int i=(sum-1)/2+1;i<=sum;i++){
        ans -= dp[n][i]*3;
        if(ans < 0){
            ans += MOD*3;
            ans %= MOD;
        }
    }
    if(sum % 2 == 0){
        for(int i=0;i<=n;i++){
            fill(dp[i], dp[i]+sum, 0);
        }
        dp[0][0] = 1;
        for(int i=0;i<n;i++){
            for(int j=0;j<sum;j++){
                dp[i+1][j+a[i]] += dp[i][j];
                dp[i+1][j+a[i]] %= MOD;
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
        }
        ans += dp[n][(sum-1)/2+1]*3;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 213248
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final PrintStream so = System.out;
    static final Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        int N = ni();
        int[] A = new int[N];
        int min = Integer.MAX_VALUE;
        long sum = 0;
        int countMinus = 0;
        for (int i = 0; i < N; i++) {
            int Ai = ni();
            if (Ai < 0) {
                countMinus++;
            }
            if (Math.abs(Ai) < Math.abs(min)) {
                min = Ai;
            }
            sum += Math.abs(Ai);
        }
        if (countMinus % 2 == 0) {
            so.println(sum);
        } else {
            so.println(sum - 2*Math.abs(min));
        }
    }
        
       
    static int ni() {
        return sc.nextInt();
    }
    
    static long nl() {
        return sc.nextLong();
    }

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


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int a, b, c;
    cin>> a>> b>> c;

    if(a+ b== c || b+ c== a || a+ c== b)
        cout<<"Yes\n";

        else
        cout<< "No\n";

    return 0;
}




Measured memory_bytes: 3608
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

using namespace std;
using LL = long long;

class Solution {
private:
	void insertBasis(LL num, array<LL, 64>& basis) {
		for (int d = 63; d >= 0; --d) {
			const LL bit = 1LL << d;
			if (num & bit) {
				if (basis[d]) {
					num ^= basis[d];
				} else {
					basis[d] = num;
					break;
				}
			}
		}
	}
public:
	/* time: O(n), space: O(1) */
	LL xorSum3(const vector<LL>& A) {
		LL oddBits = 0;
		for (LL num : A)
			oddBits ^= num;
		LL evenBits = ~oddBits;

		array<LL, 64> basis = {};
		for (LL num : A)
			insertBasis(num & evenBits, basis);

		LL maxEvenBits = 0;
		for (int d = 63; d >= 0; --d)
			maxEvenBits = max(maxEvenBits, maxEvenBits ^ basis[d]);
		return maxEvenBits * 2 + oddBits;
	}
};

int main() {
	int n;
	cin >> n;

	vector<LL> A(n);
	for (int i = 0; i < n; ++i)
		cin >> A[i];

	Solution sol;
	LL ans = sol.xorSum3(A);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
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();
    String s = sc.next();

    for (int i = 0; i < s.length(); i++) {
      if (i == a) {
        if (s.charAt(i) != '-') {
          System.out.println("No");
          return;
        }
      } else {
        if (s.charAt(i) == '-') {
          System.out.println("No");
          return;
        }
      }
    }

    System.out.println("Yes");

  }
}

Measured memory_bytes: 35676
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }

int check(char A[64][64], char B[64][64], int i, int j, int m) {
	int x, y;
	for (x = 0; x < m; x++) {
		for (y = 0; y < m; y++) {
			if (A[i + x][j + y] != B[x][y]) {
				return 0;
			}
		}
	}
	return 1;
}

int main() {
	int N, M;
	int i, j;
	int flag = 0;

	scanf("%d%d", &N, &M);
	char A[50][51], B[50][51];
	for (int i = 0; i < N; i++) {
		scanf("%s", &A[i][0]);
	}
	for (int k = 0; k < M; k++) {
		scanf("%s", &B[k][0]);
	}

	for (i = 0; i < N - (M - 1); i++) {
		for (j = 0; j < N - (M - 1); j++) {
			flag = check(A, B, i, j, M);
			if (flag) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");




#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int n,m,h,k,i,j,ans,d[1001],t,r[1001],b,c,min;
  while(scanf("%d %d %d %d",&n,&m,&h,&k),n||m||h||k){
    char a[1001][1001]={0};
    for(i=ans=0;i<n;i++)scanf("%d",&d[i+1]);
    for(i=0;i<m;i++){
      scanf("%d %d",&b,&c);
      a[c][b]=1;
    }
    for(i=h-1;i;i--){
      for(j=1;j<=n;j++){
	if(a[i][j]==0)continue;
	t=d[j];
	d[j]=d[j+1];
	d[j+1]=t;
      }
    }
    for(i=1;i<=n;i++){
      r[i]=i;
      if(i<=k)ans+=d[i];
    }
    min=ans;
    for(i=1;i<h;i++){//printf("%d %d\n",i-1,min);
      for(j=1;j<n;j++){
	if(a[i][j]==0)continue;
	if(r[j]<=k&&r[j+1]>k){
	  if(min>ans-d[j]+d[j+1])min=ans-d[j]+d[j+1];
	}
	else if(r[j+1]<=k&&r[j]>k){
	  if(min>ans-d[j+1]+d[j])min=ans-d[j+1]+d[j];
	}
	t=r[j];
	r[j]=r[j+1];
	r[j+1]=t;
	t=d[j];
	d[j]=d[j+1];
	d[j+1]=t;
      }//printf("%d %d\n",i,min);
    }
    printf("%d\n",min);
  }
  return 0;
}
    
	

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n);
  int xr = 0;
  for(int &i: a) {
    cin >> i;
    xr ^= i;
  }
  for(int i: a) {
    cout << (xr ^ i) << ' ';
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 3896
#include <iostream>
using namespace std;
int main()
{
  for(;;){
    int b,r,g,c,s,t;
    cin >> b >> r >> g >> c >> s >> t;
    if(t == 0) break;
    int coin = 100;
    coin += b * 80; t -= b * 5;
    coin += r * 54; t -= r * 3;
    coin += g * 4; t -= g;
    coin += c * -1; t -= c;
    t -= s;
    coin -= t * 3;
    cout << coin << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD 998244353
#define INF 0x3f3f3f3f
#define MAXN (int)(2e4+20)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define valsum first
#define wsum second
bool comp(tuple<ll,ll,ll> a,tuple<ll,ll,ll> b)
{
	return (get<0>(a)+get<1>(a))<(get<0>(b)+get<1>(b));
}
vll dp(MAXN,-1);
int main()
{
	fastio;
	int n;cin>>n;
	vector< tuple<ll,ll,ll> >v(n+1);
	for(int i=1;i<=n;i++)
	{
		ll a,b,c;cin>>a>>b>>c;
		v[i]=make_tuple(a,b,c);
	}
	sort(v.begin()+1,v.end(),comp);//exchange arguments
	//dp[i]-max score with total weight i so far considering n items
	//when considering n+1 th item see if all weights <= its strength 
	//can increase the dp[weights + curr_weight] from its previous value
	ll res=0;
	dp[0]=0;
	for(int i=1;i<=n;i++)
	{	
		vll newdp(MAXN,-1);
		int strength=get<1>(v[i]);
		int wt=get<0>(v[i]);
		for(int j=0;j<=min(strength+wt,MAXN);j++){
			newdp[j]=dp[j];
			if(j-wt>=0 && dp[j-wt]!=-1){
				newdp[j]=max(newdp[j],dp[j-wt]+get<2>(v[i]));
			}
			res=max(res,newdp[j]);
		}
		dp=newdp;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define mod (ll) (1e9)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
//#define make_pair mp
#define pi acos(-1)

int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
//#endif
    int n,count=0,sum=0;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        if(ar[i]%2==0)
        {
            count++;
            if(ar[i]%3==0 || ar[i]%5==0)
            {
                sum++;
            }
        }

    }
    if(sum==count)
    {
        cout<<"APPROVED"<<endl;
    }
    else cout<<"DENIED"<<endl;

}


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

int main()
{
  int n;
  double ans = 0.0;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());

  for (int i = 0; i < n - 1; i++)
    v[i + 1] = (double)((v[i] + v[i + 1]) / 2.0);

  cout << setprecision(5) << v[n - 1] << endl;
}

Measured memory_bytes: 256
n, q = map(int,input().split())
s = input()
countac = [0]
for i in range(1,len(s)):
    if s[i-1] == "A" and s[i] == "C":
        countac.append(countac[i-1] + 1)
    else:
        countac.append(countac[i-1])
ans = []
for i in range(q):
    l,r = map(int,input().split())
    ans.append(countac[r-1]-countac[l-1])
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 59212
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
set<string> se;

int main(void)
{
    int n;
    bool flag=false;
    string s1,s2;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> s2;
        if(i!=1 && s1[s1.size()-1]!=s2[0])
            flag=true;
        if(se.count(s2)==1)
            flag=true;
        se.insert(s2);
        s1=s2;
    }
    if(flag==true)
        cout << "No";
    else cout << "Yes";
    return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN=2e5+10,MAXM=4010<<1,MOD=1e9+7;
ll res,fac[MAXM],inv[MAXM],dp[MAXM][MAXM],ret;
int n,a[MAXN],b[MAXN],mx,mx_sum;

ll quick_pow(ll a,ll b)
{
	for(ret=1;b;b>>=1,(a*=a)%=MOD)
		if(b&1) (ret*=a)%=MOD;
	return ret;
}

ll C(ll a,ll b)
{return fac[a]*inv[a-b]%MOD*inv[b]%MOD;}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i],&b[i]),
		mx=max(mx,max(a[i],b[i])),mx_sum=max(mx_sum,a[i]+b[i]);
	
	for(int i=1;i<=n;i++)
		dp[-a[i]+mx][-b[i]+mx]++;
	for(int i=0;i<=(mx<<1);i++)
		for(int j=0;j<=(mx<<1);j++)
			if(dp[i][j]) (dp[i+1][j]+=dp[i][j])%=MOD,(dp[i][j+1]+=dp[i][j])%=MOD;
	for(int i=1;i<=n;i++) (res+=dp[a[i]+mx][b[i]+mx])%=MOD;
	
	mx_sum<<=1;fac[0]=1;
	for(int i=1;i<=mx_sum;i++) fac[i]=fac[i-1]*i%MOD;
	inv[mx_sum]=quick_pow(fac[mx_sum],MOD-2);
	for(int i=mx_sum;i;i--) inv[i-1]=inv[i]*i%MOD;
	
	for(int i=1;i<=n;i++)
		res=(res-C((a[i]+b[i])<<1,a[i]<<1)+MOD)%MOD;
	res=(res*(MOD+1)>>1)%MOD;
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 254080
using System;

class program{
	public static void Main(string[] args){
    	char input = Console.ReadLine()[0];
      	
      	char[] correct = {'a','e','i','o','u'};
      	string result = "consonant";
      	foreach(char c in correct){
        	if(input == c){result = "vowel";break;}
        }
      	Console.WriteLine(result);
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_set>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<climits>
using namespace std;

int main() {
    int n;
    cin>>n;
    vector<int> a(n+1),b(n+1),c(n+1);
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    vector<vector<int>> dp(n+1, vector<int> (4,0));
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    for(int i=2;i<=n;i++) {
        dp[i][1] = a[i] + max(dp[i-1][2], dp[i-1][3]);
        dp[i][2] = b[i] + max(dp[i-1][1], dp[i-1][3]);
        dp[i][3] = c[i] + max(dp[i-1][1], dp[i-1][2]);
    }
    cout<<max({dp[n][1],dp[n][2],dp[n][3]});
}


Measured memory_bytes: 9844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main(void){
    int n;cin>>n;
    map<int,int> mp;
    rep(i,n){
        int a;cin>>a;
        if(mp[a]==0) mp[a]++;
        else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n, k;
    cin >> n >> k;

    ll ans = 0;
    if (k % 2 == 1) {
        ans = pow(n/k, 3);
    } else {
        ans += pow(n/k, 3);
        int tmp = n + k/2;
        ans += pow(tmp/k, 3);
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
  int N;
  cin>>N;
  int s=0;
  for(int i=0;i<10;i++){
    s+=N%int(pow(10,i+1))/int(pow(10,i));
  }
  if(N%s==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


  return 0;
}


Measured memory_bytes: 384
def main():
    n = int(input())
    a = list(map(int, input().split()))

    UP = 1
    NEUTRAL = 0
    DOWN = -1

    sgn = NEUTRAL

    ans = 0
    for i in range(n-1):
        if sgn == UP:
            if a[i] > a[i+1]:
                sgn = NEUTRAL
                ans += 1
        elif sgn == NEUTRAL:
            if a[i] < a[i+1]:
                sgn = UP
            elif a[i] > a[i+1]:
                sgn = DOWN
        else:
            if a[i] < a[i+1]:
                sgn = NEUTRAL
                ans += 1

    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
	int n;
	cin>>n;
	set<string> S;
  for(int i = 0; i< n ; i++){
  	string a;
  	cin>>a;
  	S.insert(a);
  }
  cout<<S.size()<<endl;
}

Measured memory_bytes: 19200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
#define re resize
#define PB pop_back
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=200005;
string s[N];
ll ans;
int n,nodecnt=1,cnt[N*5],go[N*5][26];
bool cmp(string a,string b){
	return a.size()<b.size();
}
void ins(string s){
	for(auto &i:s)i-='a';
	int p=1;
	int to[26]; mem(to);
	for(auto i:s)to[i]++;
	For(i,0,s.size()-1){
		to[s[i]]--;
		For(j,0,25)if(j!=s[i]&&to[j]){
			ans+=cnt[go[p][j]];
			//if(s.size()==2&&cnt[go[p][j]])cout<<i<<" "<<j<<" "<<ans<<endl;
		}
		int c=s[i];
		if(!go[p][c])go[p][c]=++nodecnt;
		p=go[p][c];
		//cout<<p<<" "<<go[p][c]<<" "<<cnt[p]<<endl;
		ans+=cnt[p];
	}
	//cerr<<p<<endl;
	cnt[p]++;
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	n=read();
	For(i,1,n)cin>>s[i];
	sort(s+1,s+n+1,cmp);
	For(i,1,n){
		reverse(s[i].begin(),s[i].end());
		ins(s[i]);
		//cerr<<s[i]<<" "<<ans<<endl;
	}
	cout<<ans<<endl;
}

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

typedef int64_t i64;
typedef uint64_t ui64;

const int inf=1073741823;
const i64 llinf=4611686018427387903LL;

int main(void){
    int a[3];
    scanf("%i%i%i",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    printf("%i %i %i\n",a[0],a[1],a[2]);
    return 0;
}



Measured memory_bytes: 3244
using System;
using System.Linq;
class Program {
	static void Main() {
		int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = b[0], m = b[1];
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine());
		int[] c = new int[n]; int x;
		for(int i = 0; i < m; i++) {
			x = int.Parse(Console.ReadLine());
			for(int j = 0; j < n; j++) {
				if(a[j] <= x) {
					c[j]++; break;
				}
			}
		}
		int ret = 0;
		for(int i = 1; i < n; i++) {
			if(c[ret] < c[i]) ret = i;
		}
		Console.WriteLine(ret + 1);
	}
}

Measured memory_bytes: 9572
#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(register int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

const int N = 100100;
long long sum, maxa;
long long once[N];
long long a[N], b[N];

bool cmp (int a, int b) {
	return (a > b);
}

int main () {

	long long n = read(), h = read();
	For (i, 1, n) {
		a[i] = read(); b[i] = read();
		once[i] = max(a[i], b[i]);
		maxa = max(maxa, (long long)a[i]);
	}

	sort (once + 1, once + 1 + n, cmp);
	long long big = 0, tot = 0;
	For (i, 1, n)
		if (once[i] > maxa) {
			big += once[i];
			tot = i;
		}
		else break;

	if (h <= big) {
		int ans = 0;
		For (i, 1, n) {
			h -= once[i]; ++ ans;
			if (h <= 0) break;
		}
		printf ("%d\n", ans);
		return 0;
	}

	long long res = (h - big) / maxa;
	h -= res * maxa;

	if (h > big) h -= maxa, ++ res;
	For (i, 1, tot) {
		h -= once[i]; ++ res;
		if (h <= 0) break;
	}
	printf ("%lld\n", res);
    return 0;
}


Measured memory_bytes: 2560
#define GBN_USE_C
#ifdef GBN_USE_C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#else
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#endif

#define rep(i,n) for(int i = 0; i < (n); ++i)
 
typedef long long ll;

typedef char str255[256];
int  StrLen(char *s       ) { for(int ptr = 0;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除
void StrDel(char *s, int n) { int l = StrLen(s); s[l - n + 1] = '\0'; }

int main()
{
    int N; scanf("%d", &N);
    int *H = (int *)malloc(sizeof(int) * (N + 9));
    rep(i, N) scanf("%d", &H[i]);

    int ans = 1;
    for (int i = N - 1; i >= 1; --i){
        if (H[i - 1] > H[i]) --H[i - 1];
        if (H[i - 1] > H[i]){
            ans = 0; break;
        }
    }

    if (ans) puts("Yes");
    else puts("No");

    free(H);
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    int max = 0;

    for (char c: s) {
        if (c == 'R') cnt++;
        if (c == 'S') {
            if (max < cnt) max = cnt;
            cnt = 0;
        }
    }

    if (max < cnt) cout << cnt << endl;
    else cout << max << endl;

    return 0;
}

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

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/////////////////////

int const N = 1e5 + 41;

int n;
vector<pii> e[N];

int dc[N];
vector<int> cen;

int dfs0(int u, int p){
	dc[u] = 1;
	fr(i, 0, sz(e[u])){
		int to = e[u][i].first;
		if(to == p) continue;
		dc[u] += dfs0(to, u);
	}
	return dc[u];
}

void dfs1(int u, int p, int top){
	int maxi = top;
	fr(i, 0, sz(e[u])){
		int to = e[u][i].first;
		if(to == p) continue;
		dfs1(to, u, top + dc[u] - dc[to]);
		maxi = max(maxi, dc[to]);
	}
	if(maxi * 2 <= n) cen.pb(u);
}

pll dfs2(int u, int p, ll cost){
	pll ret = mp(0, 1);
	fr(i, 0, sz(e[u])){
		int to = e[u][i].first;
		if(to == p) continue;
		pll res = dfs2(to, u, e[u][i].second);
		ret.first += res.first;
		ret.second += res.second;
	}
	//cerr << u << " " << cost * ret.second * 2 << endl;
	ret.first += cost * ret.second * 2;
	return ret;
}

ll dh[N];
ll const INF = 1e9 * 1LL * 1e9 + 41;

ll dfs3(int u, int p){
	dh[u] = INF;
	fr(i, 0, sz(e[u])){
		int to = e[u][i].first;
		if(to == p) continue;
		dh[u] = min(dh[u], dfs3(to, u) + e[u][i].second);
	}
	if(dh[u] == INF) dh[u] = 0;
	return dh[u];
}

int ec[N];

ll calc(int root){
	ll ret = 0;
	ret = dfs2(root, root, 0).first;
	dfs3(root, root);
	dfs0(root, root);
	ll mini = INF;
	fr(i, 0, sz(e[root])){
		int to = e[root][i].first;
		int co = e[root][i].second;
		if(dc[to] * 2 == n){
			mini = co;
			break;
		}else{
			mini = min(mini, co * 1LL);
		}
	}

	return ret - mini;
}

void solve(){
	cin >> n;
	fr(i, 0, n-1){
		int u, v, c;
		cin >> u >> v >> c;
		--u;--v;
		e[u].pb(mp(v, c));
		e[v].pb(mp(u, c));
	}

	dfs0(0, -1);
	dfs1(0, -1, 0);
	
	assert(sz(cen) < 3);
	ll ans = 0;
	fr(i, 0, sz(cen)){
		ans = max(ans, calc(cen[i]));
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
namespace ZDY{
    #pragma GCC optimize(3)
    #define il __inline__ __attribute__ ((always_inline))
    #define rg register
    #define ll long long
    #define ull unsigned long long
    #define db double
    #define sht short
    #define MB template <class T>il
    #define Fur(i,x,y) for(int i=x;i<=y;i++)
    #define Fdr(i,x,y) for(int i=x;i>=y;i--)
    #define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdout)
    #define fcin ios::sync_with_stdio(false)
    #define l2(n) ((int)(log2(n)))
    #define inf 0x3f3f3f3f
    MB T ABS(T x){return x>0?x:-x;}
    MB T MAX(T x,T y){return x>y?x:y;}
    MB T MIN(T x,T y){return x<y?x:y;}
    MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
    MB void SWAP(T &x,T &y){T t=x;x=y;y=t;}
}using namespace ZDY;using namespace std;
namespace IO{const char* ln="\n";const int str=1<<20;struct IN{char buf[str],*s,*t;bool _;IN():s(buf),t(buf),_(0){}il char gc(){return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);}IN&operator>>(char&ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)_=1;else ch=c;return *this;}IN& operator>>(char* ch){clr(ch,0);if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;*ch=c;ch++;while((c=gc())!=EOF&&!isspace(c))*ch=c,ch++;if(c==EOF)_=1;return *this;}IN& operator>>(string& ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;ch+=c;while((c=gc())!=EOF&&!isspace(c))ch+=c;if(c==EOF)_=1;return *this;}template<typename T>IN&operator>>(T&x){if(_)return *this;char c=gc();bool ff=0;while(c!=EOF&&(c<'0'||c>'9'))ff^=(c=='-'),c=gc();if(c==EOF){_=1;return *this;}x=0;while(c!=EOF&&'0'<=c&&c<='9')x=(x<<3)+(x<<1)+c-48,c=gc();if(c==EOF)_=1;if(ff)x=-x;return *this;}}in;struct OUT{char buf[str],*s,*t;OUT():s(buf),t(buf+str){}~OUT(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);}OUT&operator<<(const char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(string s){for(int i=0;s[i];i++)pt(s[i]);return *this;}template<typename T>OUT&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[30],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}}out;}using namespace IO;
#define N 111111
char s[N];
int main(){
    int n;
    in>>n>>s;
    int ans=1;
    char x,y=s[0];
    Fur(i,1,n-1){
        x=s[i];
        ans+=(x!=y);
        y=x;
    }
    out<<ans<<ln;
}

Measured memory_bytes: 384