akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String st = sc.next();
		int num = st.length();
		if ((st.substring(num-1, num)).equals("s")) {
			System.out.println(st + "es");
		} else {
			System.out.println(st + "s");
		}
	}

}


Measured memory_bytes: 38496
#include <iostream>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<deque>
#include<iomanip>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#include<stack>
#include<unordered_set>
#include<cstring>
#include<list>
using namespace std;
//	int x=atoi(s.c_str()); s_to_in;
int dx[] = { -1,0,0,1 };
int dy[] = { 0,1,-1 ,0 };
#define endl '\n'
long long mo = 1e9;
const long double P = 3.141592653589793238L;
void trust_yourself()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
long long gcd(long long x, long long y)
{
	if (x == 0)
		return y;
	return gcd(y%x, x);
}
long long fast_power(long long x, long long y, long long mo)
{
	long long p = 1;
	while (y)
	{
		if (y & 1)
			p = (p*x) % mo;
		y = (y >> 1); //y/=2
		x = (x*x) % mo;
	}

	return p;
}
long long convert_to_num(string x) {
	long long  num = 0;
	for (int i = 0; i < x.size(); i++) {
		num *= 2;
		num += x[i] - '0';
	}
	return num;
}

long long com(long long n, long long r) {
	long long p = 1, p1 = 1;
	for (long long i = r + 1; i <= n; i++) {
		p = p * i;
		p /= p1;
		p1++;
	}
	return p;
}


int main()
{
	trust_yourself();
	//freopen("hussien.in", "r", stdin);
	int a, b, k;
	cin >> k >> a >> b;
	if (a > b)
		swap(a, b);
	for (int i = a; i <= b; i++) {
		if (i%k == 0) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
	return 0;

}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n;
cin>>n;
char c[n];
int r=0,w=0,x=0;
FOR(i,n)
{
	cin>>c[i];
	if(c[i]=='R')
	{
		r++;
	}
	if(c[i]=='W')
	{
		w++;
	}
}
FOR(i,r)
{
	if(c[i]=='W')
	{
		x++;
	}
}
cout<<min(min(r,w),x)<<endl;
return  0;
}






Measured memory_bytes: 3852
N = int(input())
L = []
M = []
for i in range(N):
  a = int(input())
  L.append(a)
  M.append(a)
L.sort()
for j in range(N):
  if M[j] == L[len(L) - 1]:
    print(L[len(L) - 2])
  else:
    print(L[len(L) - 1])

Measured memory_bytes: 19080
import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print s[n-1]

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

int x, y, s;

int tax(int a, int b) {
  return a*(100+b)/100;
}

int main() {
  while (1) {
    scanf("%d%d%d", &x, &y, &s);
    if ((x|y|s) == 0) return 0;

    int ans = 0;
    for (int i=1; i<s; i++) {
      int low = -1;
      int high = s;
      while (high - low > 1) {
        int mid = (high+low)/2;
        if (tax(i, x)+tax(mid, x) >= s) high = mid;
        else low = mid;
      }

      if (high <= 0) continue;
      if (tax(i, x)+tax(high, x) == s) ans = max(ans, tax(i, y)+tax(high, y));
    }

    printf("%d\n", ans);
  }
}

Measured memory_bytes: 3228
# -*- coding: utf-8 -*-
# map(int, input().split())
mod = pow(10,9)+7
S = int(input())
if S <= 2:
    print(0)
    exit(0)

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

max_len = int(S/3)

ans = 0
for l in range(1,max_len+1):
    s = S-(l*3)
    ans = (ans+cmb(s+l-1,s))%mod

print(ans)

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,m;
    cin>>n>>m;
    vi cc(n+1,0);
    vi vis(n+1,0);
    ll ans1=0,ans2=0;
    ll x;
    string s;
    rep(i,0,m-1){
        cin>>x>>s;
        if(s=="AC"){
            if(vis[x]) continue;
            else {
                ans2+=cc[x];
                vis[x]=1;
            }
        }
        else{
            cc[x]++;
        }
    }
    rep(i,1,n) if(vis[i]) ans1++;
    cout<<ans1<<" "<<ans2<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

def solve():

    X = int(input().rstrip())

    for A in range(1000):
        A5 = A*A*A*A*A
        for B in range(-1000,1000):
            B5 = B*B*B*B*B
            if A5-B5 == X:
                print(f'{A} {B}')
                return

solve()

Measured memory_bytes: 9100
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
	int R_cnt = 0;
	string S;

	cin >> S;

	if(!S.compare("RRR"))	R_cnt = 3;
	if(!S.compare("RRS"))	R_cnt = 2;
	if(!S.compare("RSS"))	R_cnt = 1;
	if(!S.compare("SRR"))	R_cnt = 2;
	if(!S.compare("SSR"))	R_cnt = 1;
	if(!S.compare("RSR"))	R_cnt = 1;
	if(!S.compare("SRS"))	R_cnt = 1;

	cout << R_cnt << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(void)
{
	int a,b,c,wa,sa,se,syo;
	
	scanf("%d %c %d",&a,&c,&b);
	while(c!='?'){
	if(c=='+'){
		wa=a+b;
		printf("%d\n",wa);
		scanf("%d %c %d",&a,&c,&b);
		}
	if(c=='-'){
		sa=a-b;
		printf("%d\n",sa);
		scanf("%d %c %d",&a,&c,&b);
		}
	if(c=='*'){
		se=a*b;
		printf("%d\n",se);
		scanf("%d %c %d",&a,&c,&b);
		}
	if(c=='/'){
		syo=a/b;
		printf("%d\n",syo);
		scanf("%d %c %d",&a,&c,&b);
		}
	}
	return 0;
}

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

int main(void) {
    int n,m,a,b;
    while(cin >> n && n){
        vector<pair<int,int> > v;
        for(int i = 0; i < n; i++){
            cin >> a >> b;
            v.push_back(make_pair(a,b));
        }
        cin >> m;
        for(int i = 0; i < m; i++){
            cin >> a >> b;
            v.push_back(make_pair(a,b));
        }
        sort(v.begin(), v.end());

        int sz = v.size();
        vector<int> dp(sz, 0);
        int res = 0;
        for(int i = 0; i < sz; i++){
            int mx = 0;
            for(int j = 0; j < i; j++){
                if(v[j].first < v[i].first && v[j].second < v[i].second){
                    mx = max(mx, dp[j]);
                }
            }
            dp[i] = mx+1;
            res = max(res, dp[i]);
        }
        cout << res << endl;
    }
	return 0;
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
map<int,int> GetPrimeFactors(int n) {
  map<int,int> mp;
  // divide by 2, 3, 5, ...
  while(n%2 == 0) {
    ++mp[2];
    n /= 2;
  }
  for(int i=3; i*i<=n; i+=2) {
    while(n%i == 0) {
      ++mp[i];
      n /= i;
    }
  }
  if(n!=1) ++mp[n];

  return mp;
}
/***** MAIN *****/
signed main() {
  int n; cin >> n;
  map<int, int> mp = GetPrimeFactors(n);
  int ans = 0;
  for(auto& itr : mp) {
    int i = 1;
    int a = itr.second;
    while(a-i >= 0){
      a -= i;
      ++i;
      ++ans;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;

fn main() {
	let n: u32 = read();
	let r: u32 = read();
	println!("{}", rating(n, r));
}

fn rating(n: u32, r: u32) -> u32 {
	if n >= 10 {
		r
	} else {
		r + 100*(10-n)
	}
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}



Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i;
	int cnt,temp;
	int men[6]={1,3,6,4,2,5};
	char a[6];
	
	scanf("%d",&n);
	while(n!=0){
		cnt=1;
		men[0]=1;
		men[1]=3;
		men[2]=6;
		men[3]=4;
		men[4]=2;
		men[5]=5;
		for(i=0;i<n;i++){
			scanf("%s",a);
			if(strcmp(a,"North")==0){
				temp=men[0];
				men[0]=men[4];
				men[4]=men[2];
				men[2]=men[5];
				men[5]=temp;
				cnt+=men[0];
			}
			else if(strcmp(a,"East")==0){
				temp=men[0];
				men[0]=men[3];
				men[3]=men[2];
				men[2]=men[1];
				men[1]=temp;
				cnt+=men[0];
			}
			else if(strcmp(a,"West")==0){
				temp=men[0];
				men[0]=men[1];
				men[1]=men[2];
				men[2]=men[3];
				men[3]=temp;
				cnt+=men[0];
			}
			else if(strcmp(a,"South")==0){
				temp=men[0];
				men[0]=men[5];
				men[5]=men[2];
				men[2]=men[4];
				men[4]=temp;
				cnt+=men[0];
			}
			else if(strcmp(a,"Right")==0){
				temp=men[1];
				men[1]=men[5];
				men[5]=men[3];
				men[3]=men[4];
				men[4]=temp;
				cnt+=men[0];
			}
			else if(strcmp(a,"Left")==0){
				temp=men[1];
				men[1]=men[4];
				men[4]=men[3];
				men[3]=men[5];
				men[5]=temp;
				cnt+=men[0];
			}
		}
	printf("%d\n",cnt);
	scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 604
from collections import deque

n = int(input())
linked_list = deque()

for _ in range(n):
    row = input().split()
    if len(row) == 1:
        command = row[0]
    else:
        command, key = row
    # print(linked_list, row)
    if command == 'deleteFirst' and linked_list:
        del linked_list[0]
    elif command == 'deleteLast' and linked_list:
        del linked_list[-1]
    elif command == 'delete':
        if key in linked_list:
            linked_list.remove(key)
    else:
        linked_list.appendleft(key)

print(*linked_list)


Measured memory_bytes: 69732
n,m=map(int,input().split())
nums = []
target = m

for i in range(1,pow(10,9)+1):
  if m <= i*i:
    break
  if target % i == 0:
    nums.append([i,target//i])
  if target == 1:
    break

keep = 0
for x in range(len(nums)):
  if n <= nums[x][0]:
    print(nums[x][1])
    exit()
  elif n <= nums[x][1]:
    keep = nums[x][0]
if 0 < keep:
  print(keep)
else:
  print(1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define outl(x) cout << x << endl
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n;
	set<int> st;
	cin >> n;
	for(int i = 0;i < n;i++){
		int h;
		cin >> h;
		st.insert(h);
	}
	cout << st.size() << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int,ll> P;
typedef pair<P,P> P2;
const ll INF=100000000000000001;
int main() {
	ll k;
	cin>>k;

	ll a[50]={};
	for(int i=0;i<50;++i)a[i]=49-i+k/50;
	for(int i=0;i<k%50;++i)a[i]++;
	cout<<"50"<<endl;
	cout<<a[0];
	for(int i=1;i<50;++i)cout<<" "<<a[i];
	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;

void Main()
{
	string S, T; cin >> S >> T;
	int idx = -1;
	for (int i = S.size() - 1; i >= T.size() - 1; --i) {
		bool match = true;
		rep(j,T.size()) {
			if (S[i - j] != T[T.size() - j - 1] && S[i - j] != '?') {
				match  = false;
				break;
			}
		}
		if (match) {
			idx = i - T.size() + 1;
			break;
		}
	}
	if (idx == -1) {
		cout << "UNRESTORABLE" << endl;
		return;
	}
	rep(i,S.size()) {
		if (i >= idx && i < idx + T.size()) {
			cout << T[i - idx];
		} else if (S[i] == '?') {
			cout << "a";
		} else {
			cout << S[i];
		}
	}
	cout << endl;
}

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


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

int main(void)
{
    int N;
    cin >> N;
    int a[N];
    int b;
    for( int i = 0; i < N; i++){
        cin >> a[i];
    }
    b = a[0] - 1;
    for( int i = 0; i < N; i++){
        if(b == 2 - 1){
            cout << i + 1;
            return 0;
        }
        b = a[b]-1;
    }
    cout << -1;
    return 0;
}

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

#define pb push_back
#define SZ(x) ((int) (x).size())

using namespace std;
typedef long long LL;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
template <typename T> void read(T & x) 
{
	int f = 1; char ch; x = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x *= f;
}

const int NX = 200010;

int n, m; vector<int> edge[NX];
bool used[NX]; int par[NX], siz[NX], tu, tv, len;

namespace tree {
	LL ans = 0;
	int dfs(int x, int fa, int d)
	{
		int cur_size = (d & 1) ? 1 : -1;
		for (int y : edge[x])
		{
			if(y != fa)
			{
				cur_size += dfs(y, x, d + 1);
			}
		}
		
		ans += abs(cur_size);
		return siz[x] = cur_size;
	}
	void solve()
	{
		ans = 0; 
		if(dfs(1, 0, 1))
			puts("-1");
		else
			cout << ans << "\n";
	}

}

void dfs(int x)
{
	used[x] = true;
	for (int y : edge[x])
	{
		if(y == par[x]) continue;
		if(used[y])
		{
			if(tu) continue;
			tu = x, tv = y;
			len = 1;
			for (int u = tu; u != tv; u = par[u])
				++len;
		} else {
			par[y] = x;
			dfs(y);
		}
	}
}

int get_circle() 
{
	dfs(1);	
	for (int i = 0; i < SZ(edge[tu]); i++)
		if(edge[tu][i] == tv)
				edge[tu].erase(edge[tu].begin() + i);
	for (int i = 0; i < SZ(edge[tv]); i++)
		if(edge[tv][i] == tu)
			edge[tv].erase(edge[tv].begin() + i);
	
	return len;
}

namespace odd
{
	LL ans = 0; int sym[NX];
	int dfs(int x, int fa, int d)
	{
		int cur_size = (d & 1) ? 1 : -1;
		if(x == tu || x == tv)
			cur_size += sym[x];	
			
		for (int y : edge[x])
		{
			if(y != fa)
			{
				cur_size += dfs(y, x, d + 1);
			}
		}
		
		ans += abs(cur_size);
		return siz[x] = cur_size;
	}
	
	void solve()
	{
		int t = dfs(1, 0, 1);
		if(t & 1)
			puts("-1");
		else
		{
			ans = (abs(t) >> 1);
			sym[tu] = -(t >> 1);
			sym[tv] = -(t >> 1);
			dfs(1, 0, 1);
			cout << ans << "\n";
		}
	}
}

namespace even 
{
	int ts[NX], tk[NX];
	pair<int, int> dfs(int x, int fa, int d)
	{
		int cur_size = (d & 1) ? 1 : -1;
		int cur_k = 0;
		if(x == tu || x == tv)
			cur_k = tk[x];
			
		for (int y : edge[x])
		{
			if(y != fa)
			{
				pair<int, int> thi = dfs(y, x, d + 1);
				cur_size += thi.first;
				cur_k += thi.second;
			}
		}
		
		return make_pair(ts[x] = cur_size, tk[x] = cur_k);
	}
	
	void solve()
	{
		tk[tu] = 1;
		tk[tv] = -1;
		pair<int, int> t = dfs(1, 0, 1);
		if(t.first)
			puts("-1");
		else
		{
			LL ans = 0; vector<int> v;
			for (int i = 1; i <= n; i++)
			{
				if(!tk[i])
					ans += abs(ts[i]);
				else
				{
					ts[i] *= -1;
					v.pb(ts[i]);
				}
			}
			v.pb(0);
			sort(v.begin(), v.end());
			int mid = v[SZ(v) >> 1];
			for (int i : v)
				ans += abs(i - mid);
			cout << ans << "\n";
		} 
	}
}

int main() 
{
	read(n); read(m);
	for (int i = 1; i <= m; i++)
	{
		int u, v; read(u); read(v);
		edge[u].pb(v);
		edge[v].pb(u);
	}
	
	if(m == n - 1)
		tree::solve();
	else
		if(get_circle() & 1)
			odd::solve();
		else
			even::solve();
		
	return 0;
}





Measured memory_bytes: 19324
#include <iostream>

using namespace std;

int main()
{
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	if (a*b == c*d) cout << a*b << endl;
	else if (a*b < c*d)cout << c*d << endl;
	else cout << a*b << endl;
	
	return 0;
}

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

#define rep(i, a, n) for(int i=(a);i<(n);++i)
#define per(i, a, n) for(int i=(a);i>(n);--i)
#define pb emplace_back
#define mp make_pair
#define lowbit(x) (x & -x)

typedef long long LL;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 1e6 + 10;

char s[N];
int n, ch[N][26], C[N][26], D[N][26];
int sz;
int cnt[N], cur[26];

struct Trie{
	void init(){
		sz = 1;
		memset(ch[0], 0, sizeof(ch[0]));
		cnt[0] = 0;
	}
	int query(int len){
		rep(i, 0, 26)	cur[i] = 0;
		rep(i, 0, len){
			++cur[s[i]-'a'];
		}

		int ret = 0;

		int u = 0, c = 0;

		rep(i, 0, len){
			c = s[i] - 'a';

			rep(j, 0, 26){
				if(cur[j])	ret += D[u][j];
			}

			if(!ch[u][c])	break;

			u = ch[u][c];

			--cur[c];
		}

		u = 0;
		rep(i, 0, len - 1){
			c = s[i] - 'a';
			if(!ch[u][c]){
				return ret;
			}
			u = ch[u][c];
		}
		c = s[len-1] - 'a';
		return ret + C[u][c];
	}

	int ins(int len){
		int u = 0, c = 0;
		rep(i, 0, 26)	cur[i] = 0;
		rep(i, 0, len)	++cur[s[i]-'a'];
		rep(i, 0, len){
			c = s[i] - 'a';
			if(!ch[u][c]){
				memset(ch[sz], 0, sizeof(ch[sz]));
				cnt[sz] = 0;
				rep(j, 0, 26){
					C[sz][j] = D[sz][j] = 0;
				}
				ch[u][c] = sz++;
			}

			if(i == len - 1){
				++D[u][c];
			}
			rep(j, 0, 26){
				if(cur[j])	++C[u][j];
			}
			--cur[c];

			u = ch[u][c];
		}

		++cnt[u];

		return cnt[u] - 1;
	}
}tr;

int main(){
	scanf("%d", &n);
	
	LL ans = 0;
	int len;

	tr.init();
	while(n--){
		scanf("%s", s);
		len = strlen(s);
		reverse(s, s+len);
		
		ans += tr.query(len);
		ans -= tr.ins(len);
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 311708
n = int(input())
l = list(map(int, input().split()))

suml = 0
lmax = l[0]
for i in range(n):
  suml += l[i]
  if lmax < l[i]:
    lmax = l[i]

s = suml - lmax
if s > lmax:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn main() {
    input!{
        v: [usize1; 6]
    }
    let mut tab: Vec<usize> = vec![0; 4];
    for x in v {
        tab[x] += 1;
    }
    tab.sort();
    println!("{}", if tab == vec![1,1,2,2] {"YES"} else {"NO"});
}


Measured memory_bytes: 4476
from operator import mul
from functools import reduce


def cmb(n, r):
	if n < r:
		return 0
	r = min(n - r, r)
	if r == 0:
		return 1
	numer = reduce(mul, range(n, n - r, -1))
	denom = reduce(mul, range(1, r + 1))
	return numer // denom % INF


N, K = map(int, input().split())
INF = 10 ** 9 + 7

for i in range(1, K + 1):
	print(cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF)

Measured memory_bytes: 3944
N = int(input())
S = input()
NEX = [[float("inf")]*10 for i in range(N+1)]
for i in range(N):
    j = N-1-i
    for k in range(10):
        NEX[j][k] = NEX[j+1][k]
    NEX[j][int(S[j])] = j
from collections import defaultdict
dp = defaultdict(int)
for i in range(1000):
    j = "0"*(3-len(str(i))) + str(i)
    dp[i] = 0
ans = 0    
for i in range(10):
    idx1 = NEX[0][i]
    if idx1 != float("inf"):
        for j in range(10):
            idx2 = NEX[idx1+1][j]
            if idx2 != float("inf"):
                for k in range(10):
                    idx3 = NEX[idx2+1][k]
                    if idx3 != float("inf"):
                        ans += 1
                        #print(str(i)+str(j)+str(k))
print(ans)

Measured memory_bytes: 50268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod =1e9+7;
#define N 100010
int fa[N],du[N];
int a[N],b[N];
vector<int>d4;
int get_fa(int x)
{
    return fa[x]==x ? x : fa[x]=get_fa(fa[x]);
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        du[a[i]]++,du[b[i]]++;
    }
    for(int i=1;i<=n;i++)
        if(du[i]%2){printf("No\n");return 0;}

    for(int i=1;i<=n;i++)
        if(du[i]>=6){printf("Yes\n");return 0;}
        else if(du[i]==4)d4.push_back(i);

    if(d4.size()>=3)
        printf("Yes\n");
    else if(d4.size()<2)
        printf("No\n");
    else
    {
        for(int i=1;i<=n;i++)fa[i]=i;
        for(int i=1;i<=m;i++)
        {
            if(a[i]==d4[0] || b[i]==d4[0])continue;
            fa[get_fa(a[i])]=fa[get_fa(b[i])];
        }
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(fa[i]==i)cnt++;
        }
        if(cnt>=3)
            printf("Yes\n");
        else
            printf("No\n");
    }
   return 0;
}


Measured memory_bytes: 1792
def reconstract(l, r):
    if l >= r:
        return None

    c = next(root)
    m = in_hoge.index(c)
    
    reconstract(l, m)
    reconstract(m+1, r)
    
    post_hoge.append(c)

if __name__ == '__main__':
    _ = int(input())
    pre_hoge = [int(x) for x in input().split()]
    root = (x for x in pre_hoge)
    in_hoge = [int(x) for x in input().split()]
    post_hoge = list()
    
    reconstract(0, len(pre_hoge))
    
    print(' '.join([str(x) for x in post_hoge]))


Measured memory_bytes: 5608
#include <stdio.h>
int main(void){
	
	int x[3000],y[3000];
	int i=0,a,z;
	for(i=0;i<3000;i++){
		scanf("%d %d",&x[i],&y[i]);
		if(x[i]==0 && y[i]==0)break;
		if(x[i]>=y[i]){
			z=x[i];
			x[i]=y[i];
			y[i]=z;
		}
	}
	for(a=0;a<i;a++){
		printf("%d %d\n",x[a],y[a]);
	}
	
	return 0;
}


Measured memory_bytes: 2140
#include<cstdio>
int main(){
	int a,b,c,d;
	long long e;
	while(~scanf("%d%d",&a,&b))
	{
		c=a;d=0;
		while(c>0)
		{
			d+=1;c-=2*b+1;
		}
		printf("%d\n",d);
	}
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 100010;

vector<vi> g;
bool vis[maxn];
bool f[maxn];
set<pii> us;
vector<pii> ans;

void dfs(int v, int p) {
	vis[v] = true;
	for (int to : g[v]) {
		if (to == p) continue;

		if (!vis[to]) {
			dfs(to, v);
		} else if (!us.count(mp(v, to))) {
			ans.eb(v, to);
			us.insert(mp(v, to));
			us.insert(mp(to, v));
			f[v] ^= 1;			
		}
	}

	if (p != -1) {
		if (f[v]) {
			ans.eb(v, p);
			f[v] ^= 1;
		} else {
			ans.eb(p, v);
			f[p] ^= 1;
		}
		us.insert(mp(v, p));
		us.insert(mp(p, v));
	}
}

int main() {
	int N, M; cin >> N >> M;

	if (M & 1) {
		puts("-1");
		return 0;
	}

	g.resize(N);

	rep(i, M) {
		int a, b;
		cin >> a >> b; --a; --b;
		g[a].pb(b); g[b].pb(a);
	}

	dfs(0, -1);

	assert(M == ans.size());
	for (auto p : ans) {
		cout << p.fi+1 << " " << p.se+1 << "\n";
	}

	return 0;
}

Measured memory_bytes: 25076
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100005
#define LL long long
using namespace std;
int n,m,fa[maxn],use[maxn],cnt;
LL ans;
struct node { int w;bool vis; } a[maxn];
bool cmp(node p,node q) 
{
	if(p.vis) return false;
	if(q.vis) return true;
	return p.w<q.w; 
}
int find(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].w);
		fa[i]=i;use[i]=i;
		a[i].vis=true;
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		u++,v++;
		int r1=find(u),r2=find(v);
		if(r1!=r2)
		{
			if(a[use[r2]].w<a[use[r1]].w)
			{
				a[use[r1]].vis=false;
				use[r1]=use[r2];
			}
			else a[use[r2]].vis=false;
			fa[r2]=r1;
		}
	}
	for(int i=1;i<=n;i++)
		if(find(i)==i) 
		{
			ans+=1ll*a[use[i]].w;
			cnt++;
		}
	if(cnt==1)
	{
		printf("0\n");
		return 0;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=cnt-2;i++)
		if(a[i].vis)
		{
			printf("Impossible\n");
			return 0;
		}
		else ans+=1ll*a[i].w;
	printf("%lld\n",ans);
}

Measured memory_bytes: 1664
import java.util.*;
import java.io.*;

public class Main{

	public static void main(String[] args) throws IOException {
		int a = readInt(), b = readInt();
		if((a*b)%2 == 0) println("Even");
		else println("Odd");
		exit();
	}

	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;

	static String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine().trim());
		return st.nextToken();
	}

	static long readLong() throws IOException {
		return Long.parseLong(next());
	}

	static float readFloat() throws IOException {
		return Float.parseFloat(next());
	}

	static boolean readBoolean() throws IOException {
		return Boolean.parseBoolean(next());
	}

	static short readShort() throws IOException {
		return Short.parseShort(next());
	}

	static byte readByte() throws IOException {
		return Byte.parseByte(next());
	}

	static int readInt() throws IOException {
		return Integer.parseInt(next());
	}

	static double readDouble() throws IOException {
		return Double.parseDouble(next());
	}

	static char readCharacter() throws IOException {
		return next().charAt(0);
	}

	static String readLine() throws IOException {
		return br.readLine().trim();
	}

	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		br.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 21204
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, A);
    IN(ll, B);
    IN(ll, C);
    IN(ll, K);
    while (B <= A)
    {
        B *= 2;
        --K;
    }
    while (C <= B)
    {
        C *= 2;
        --K;
    }
    YES(K >= 0);
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n, m;
    cin >> n >> m;
    vi a;
    a.resize(n);

    REP(i, n)
    cin >> a[i];

    int s;
    s = 0;
    REP(i, n)
    s += a[i];

    if (s % (4 * m) == 0)
        s = s / (4 * m);
    else
        s = s / (4 * m) + 1;

    int cnt;
    cnt = 0;

    REP(i, n)
    {
        if (a[i] >= s)
            cnt++;
    }
    if (cnt >= m)
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int N;
vector<int> C;
set<int> L;
vector<bool> used;
vector<vector<int> > P;

void l_check(void) {
	L.clear();
	for (int i = 0; i < N; ++i) {
		if (C[i] == 1)
			L.insert(i);
	}
}

int solve(void) {
	while (L.size()) {
		int leaf = *L.begin();
		L.erase(L.begin());
		for (int i = 0; i < (int)P[leaf].size(); ++i) {
			int rank1 = P[leaf][i];
			if (used[rank1])
				continue;
			used[leaf] = used[rank1] = true;
			for (int j = 0; j < (int)P[rank1].size(); ++j) {
				int rank2 = P[rank1][j];
				if (!used[rank2]) {
					--C[rank2];
					if (C[rank2] == 0)
						return 1;
					if (C[rank2] == 1)
						L.insert(rank2);
				}
			}
		}
	}
	return 0;
}

int main(void) {
	cin >> N;
	C.resize(N, 0);
	P.resize(N);
	for (int i = 1; i <= N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a;	--b;
		++C[a];	++C[b];
		P[a].push_back(b);
		P[b].push_back(a);
	}

	l_check();
	used.resize(N, false);

	int win = solve();
	if (win == 1)
		cout << "First\n";
	else
		cout << "Second\n";
	return 0;
}


Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,oo=0x3f3f3f3f;

long long memo[100][N],w[N],v[N],n,W;

long long dp(int i, int wi){
    if(i>=n) return 0;
    if(memo[i][wi]!=-1)return memo[i][wi];
    long long t=-oo;
    if(w[i]+wi<=W)t=dp(i+1,w[i]+wi)+v[i];
    long long l=dp(i+1,wi);
    return memo[i][wi]=max(t,l);
}

int main(){
    memset(memo,-1,sizeof memo);
    cin >> n >> W;
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
    }
    cout << dp(0,0);
    return 0;
}



Measured memory_bytes: 78336
S= str(input())
S=list(S)
for i in range(len(S)):
    if i%2==0:
        if S[i] not in ('R','U','D'):
            print('No')
            exit()
    if i%2!=0:
        if S[i] not in ('L','U','D'):
            print('No')
            exit()
print('Yes')
    

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

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'

int n,m;
int a[1010],b[1010];
int f[12000];

int main(){
	scanf("%d%d",&m,&n);
	for (int i=0;i<n;i++) scanf("%d%d",&a[i],&b[i]);
	int ans=1e9;
	for (int i=0;i<12000;i++) {
		if (i==0) {
			f[i]=0;
			continue;
		}
		else f[i]=1e9;
		for (int j=0;j<n;j++) 
			if (i-a[j]>=0) f[i]=min(f[i-a[j]]+b[j],f[i]);
		if (i>=m) ans=min(ans,f[i]);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[LI() for _ in range(n)]

  dp=[[0 for _ in range(n+1)]for __ in range(3)]

  for i in range(n):
    for j in range(3):
      dp[j][i+1]=max(dp[(j+1)%3][i],dp[(j+2)%3][i])+l[i][j]
  return max(dp[0][n],dp[1][n],dp[2][n])

# main()
print(main())


Measured memory_bytes: 39008
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll
#define BITOF(a, k) (1 & ((a) >> (k)))

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        m ++;
        vector<pii> v;
        REP(i, n) {
            int a, b;
            cin >> a >> b;
            v.emplace_back(a, b);
        }
        ll ans = 0;

        REP(k, 31) if (BITOF(m, k)) {
            // k bit 目で確定 それより下はなんでもよい というケースについて計算
                ll sum = 0;
                REP(i, n) {
                    int a, b; tie(a, b) = v[i];
                    if (BITOF(a, k)) continue;
                    if (((m >> (k+1)) & (a >> (k+1))) != (a >> (k+1))) continue;
                    sum += b;
                }
                ans = max(ans, sum);
        }

        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1400
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); //入出力高速化
  int N; cin >> N;
  vector<pair<int, int>> A(N);
  rep(i,N) {
    int a; cin >> a;
    A[i] = make_pair(a,i+1);
  }

  sort(all(A));

  rep(i,N) cout << A[i].second << " ";
  cout << endl;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


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

/* Rolling Hash */
// n = 9973, 10007

struct RollingHash{
  int N, base;
  ll hash[SIZE], pow[SIZE];

  template <typename Type>
  RollingHash(int base, int n, Type *arr):
    N(n), base(base)
  {
    hash[0] = 0;
    pow[0] = 1;
    for(int i=0; i<N; i++){
      hash[i+1] = (hash[i] + arr[i]) * base % mod;
      pow[i+1] = pow[i] * base % mod;
    }
  }

  // get [l,r)
  ll getHash(int l, int r) {
    return (mod + hash[r] - hash[l] * pow[r-l] % mod) % mod;
  }
};

const int base1 = 9973;
const int base2 = 10007;

set<pair<ll,ll>> ss[700];
map<int,int> dict;
int dicti = 0;
vector<int> vec;

ll getHash(int base, int n, char *arr){
  RollingHash rh(base, n, arr);
  return rh.getHash(0, n);
}

char s[SIZE], t[SIZE];
ll dp[SIZE] = {};

int main(){
  int n;

  scanf("%d", &n);

  for(int i=0;i<n;i++){
    scanf("%s", s);
    int m = strlen(s);
    ll h1 = getHash(base1, m, s);
    ll h2 = getHash(base2, m, s);
    vec.push_back(m);
    if(dict.find(m) == dict.end()) dict[m] = dicti++;
    ss[dict[m]].insert({h1, h2});
  }

  scanf("%s", t);

  int m = strlen(t);
  RollingHash rh1(base1, m, t), rh2(base2, m, t);

  dp[0] = 1;

  for(int i=0;i<m;i++){
    for(auto it : dict){
      int p = it.first;
      if(i+p > m) break;
      ll h1 = rh1.getHash(i, i+p);
      ll h2 = rh2.getHash(i, i+p);
      if(ss[it.second].find({h1, h2}) != ss[it.second].end())
        dp[i+p] = (dp[i+p] + dp[i]) % mod;
    }
  }

  printf("%lld\n", dp[m]);

  return 0;
}



Measured memory_bytes: 8576
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> L(n);
	rep(i, n) cin >> L.at(i);
	int sum = 0;
	sort(L.begin(), L.end());
	rep(i, n) {
		rep2(j, i + 1, n) {
			int it = lower_bound(L.begin() + j + 1, L.end(), L[i] + L[j])-L.begin();
			sum += it - j - 1;
		}
	}
	cout << sum << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char s[3003],t[3003];
	scanf("%s%s",s,t);
	int n,m;
	n=0;
	while(s[n]!='\0')
		n++;
	m=0;
	while(t[m]!='\0')
		m++;
	int i,j;
	int dp[3003][3003];
	for(i=0;i<=n;i++)
		for(j=0;j<=m;j++)
			dp[i][j]=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			dp[i+1][j+1]=dp[i+1][j];
			if(dp[i+1][j+1]<dp[i][j+1])
				dp[i+1][j+1]=dp[i][j+1];
			if(s[i]==t[j])
			{
				if(dp[i+1][j+1]<dp[i][j]+1)
					dp[i+1][j+1]=dp[i][j]+1;
			}
		}
	}
	char ans[3003];
	int l=dp[n][m];
	i=n;
	j=m;
	ans[l]='\0';
	while(l>0)
	{
		while(dp[i][j-1]==l && j>0)
			j--;
		while(dp[i-1][j]==l && i>0)
			i--;
		l--;
		i--;
		j--;
		ans[l]=s[i];
	}
	printf("%s\n",ans);
	return 0;
}

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

def f(A):
  D=[0]*(N+1)
  for j in range(N):
    mi=max(j-A[j],0)
    ma=min(j+A[j],N-1)
    D[mi]+=1
    D[ma+1]-=1   
  for i in range(1,N):
    D[i]+=D[i-1]
  A=D[:-1]
  return A 

for i in range(min(K,42)):
  A=f(A)
print(*A)

Measured memory_bytes: 167896
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextInt();
            }

            int ans = 0;
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (p[i] == i + 1) {
                    cnt++;
                } else {
                    ans += (cnt + 1) / 2;
                    cnt = 0;
                }
            }
            ans += (cnt + 1) / 2;
            out.println(ans);
        }

    }
}



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

using lint = long long int;
using pii = std::pair<int, int>;

using std::min;

char str[110];
char temp[110];

bool is_it(char cur, int len) {
	for (int i = 0; i < len; i++) {
		if (str[i] == cur) {
			return true;
		}
	}
	return false;
}

bool check(char cur, int len) {
	for (int i = 0; i < len; i++) {
		if (temp[i] != cur) {
			return false;
		}
	}
	return true;
}

int cal(char cur, int len) {
	if (!is_it(cur, len)) {
		return 1000;
	}
	for (int i = 0; i < len; i++) {
		temp[i] = str[i];
	}
	temp[len] = 0;
	int cou = 0;

	if (check(cur, len)) {
		return 0;
	}
	for (int i = 1; i < len; i++) {
		cou++;
		int cur_len = len - i;
		for (int j = 0; j < cur_len; j++) {
			if (temp[j] == cur || temp[j + 1] == cur) {
				temp[j] = cur;
			}
		}
		if (check(cur, cur_len)) {
			break;
		}
	}

	return cou;
}

int main(void) {
	scanf("%s", str);
	int len = strlen(str);

	int ans = 1000;

	for (char cur = 'a'; cur <= 'z'; cur++) {
		ans = min(ans, cal(cur, len));
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 256
package main
import(
  "fmt"
)
func main(){
  var n, h, w, i int
  ans:=0
  fmt.Scan(&n, &h, &w)
  a:=make([]int, n)
  b:=make([]int, n)
  for i=0;i<n;i++{
    fmt.Scan(&a[i], &b[i])
    if a[i]>=h && b[i]>=w{
      ans++
    }
  }
  fmt.Println(ans)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N;
  cin>>N;
  int len[N];
  string str,S[N],T[N];
  for(int i = 0 ;i<N;i++){
    cin>>str;
    len[i]=str.size();
    S[i]=str;
    T[i]=S[i];
    //cout<<len[i]<<endl;
  }
  for(int i = 1 ;i<N;i++){
    //cout<<S[i-1][len[i-1]-1]<<endl;
    if(S[i-1][len[i-1]-1]!=S[i][0]){
      cout<<"No"<<endl;
      return 0;
    }
    for(int k = 0; k < i ; k++){
      if(S[i]==T[k]){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256