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

#define endl "\n"
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define Set(N,p) ((N)|((1LL)<<(p)))
#define Reset(N,p) ((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

#define LL long long
#define LLU long long unsigned int
typedef pair < int, int > pii;
typedef pair < LL, LL > pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pll> vll;

#ifdef s_da_sailor
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " = " << arg1 << " , ";
    __f(comma + 1, args...);
    }
#else
    #define line
    #define trace(...)
#endif // s_da_sailor

inline LL gcd ( LL a, LL b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

LL ext_gcd ( LL A, LL B, LL *X, LL *Y ){
    LL x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline LL modInv ( LL a, LL m ) {
    LL x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline LL bigmod ( LL a, LL p, LL m ) {
    LL res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}


//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const LL inf = 2147383647;
const LL mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

LL N, D;

void solve() {
    cin >> N >> D;
    LL cnt=0;
    for(int i=0; i<N; i++) {
        double x, y;
        cin >> x >> y;
        if(sqrt(x*x+y*y)<=(double)D) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

    fast_cin;

    solve();

    return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
 
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
 
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

LL ans[1 << 18];
int l[1 << 18];
int r[1 << 18];
int c[1 << 18];
VI pos[1 << 18];
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		cin >> l[i] >> r[i] >> c[i];
		pos[l[i] - 1].PB(i + 1);
		pos[r[i]].PB(-i - 1);
		ans[i] = LINF;
	}
	multiset<LL> foo;
	FOR(i, 0, n + 1)
	{
		sort(ALL(pos[i]));
		for(int ind : pos[i])
		{
			if(!i)
			{
			//	cout << ind << endl;
				ans[ind - 1] = c[ind - 1];
				foo.insert(ans[ind - 1]);
				continue;
			}
			if(ind < 0)
			{
				ind *= -1;
				foo.erase(foo.find(ans[ind - 1]));
			}
			else
			{
				if(!SZ(foo))
				{
						cout << -1 << endl;
						return 0;
				}
				ans[ind - 1] = *foo.begin() + c[ind - 1];
				foo.insert(ans[ind - 1]);
			}
		}
	}
	
	LL res = LINF;
	FOR(i, 0, m)
	{
		if(r[i] == n)
		{
			setmin(res, ans[i]);
		}
	}
	if(res == LINF) res = -1;
	cout << res << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}
 


Measured memory_bytes: 16804
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
    long n, k;
    cin >> n >> k;
    vector<long> h;
    long tmp;
    for (int i = 0; i <  n; ++i) {
        cin >> tmp;
        h.push_back(tmp);
    }
    sort(h.begin(), h.end(), greater<int>());

    long ans = h.size() <= k ? 0 : accumulate(h.begin() + k, h.end(), 0L);

    cout << ans << endl;

    return 0;
}


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

int main(){
  string S;
  cin >> S;
  if(S=="hi" || S=="hihi" || S=="hihihi" || S=="hihihihi" || S=="hihihihihi"){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
li = list(map(int, input().split()))
a, b, c, k = li[0], li[1], li[2], li[3]

if a >= k:
  print(1*k)
elif (a+b) >= k:
  print(1*a)
else:
  ans = (1*a) - (k-(a+b))
  print(ans)


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

int main(void){
  ll h,w,k;
  cin >> h >> w >> k;
  char s[h][w];
  rep(i,h){
    rep(j,w){
      cin >> s[i][j];
    }
  }
  char t[h][w];
  ll m,ans=0;
  for (int bit = 0; bit < (1<<h); ++bit) {
    for (int bit2 = 0; bit2 < (1<<w); ++bit2) {
      m=0;
      rep(i,h){
        rep(j,w){
          t[i][j]=s[i][j];
        }
      }
      rep(i,h){
        if (bit & (1 << i)) {
          rep(j,w){
            t[i][j]='.';
          }
        }
      }
      rep(i,w){
        if (bit2 & (1 << i)) {
          rep(j,h){
            t[j][i]='.';
          }
        }
      }
      rep(i,h){
        rep(j,w){
          if(t[i][j]=='#')m++;
        }
      }
      if(m==k)ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3620
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

a=10**9+7
N=int(input())
A=list(map(int,input().split()))

common=lcm(A)
ans=0
for i in range(N):
    ans+=common//A[i]
print(ans%a)

Measured memory_bytes: 5616
#include "bits/stdc++.h"

using namespace std;

int main() {
	string S;
	cin >> S;
	vector<int>V(4);
	V[0] = S[0] - '0';	
	V[1] = S[1] - '0';	
	V[2] = S[2] - '0';
	V[3] = S[3] - '0';
	for (int i = 0;i<(1<<3);++i) {
		int n = V[0];
		string Sout;
		Sout += S[0];
		for (int j = 0;j<3;++j) {
			if (1 & (i>>j)) {
				n += V[j+1]; 
				Sout += "+";
			}
			else {
				n -= V[j + 1]; 
				Sout += "-";
			}
			Sout += S[j+1];
		}
		if (7 == n) {
			Sout += "=7";
			cout << Sout<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int co = 0;
    rep(i, N) if(A[i] == co + 1) co++;
    int ans = (co == 0 ? -1 : N - co);
    cout << ans << endl;
}

Measured memory_bytes: 4028
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int[] pre = new int[n];
    	for (int i = 0; i < n; i++) {
    		pre[i] = sc.nextInt();
    	}
		int[] in = new int[n];
    	for (int i = 0; i < n; i++) {
    		in[i] = sc.nextInt();
    	}

    	int[] post = new int[n];
    	makePost(post, n - 1, pre, 0, in, 0, n);

    	for (int i = 0; i < n; i++) {
    		if (i != 0) {
            	System.out.print(" ");
    		}
        	System.out.print(post[i]);
    	}
    	System.out.println("");

    	sc.close();
	}
	
	private static void makePost(int[] post, int spost, int[] pre, int spre, int[] in, int sin, int n) {
		if (n < 1) {
			return;
		}
		
		post[spost] = pre[spre];

		int i = sin;
		for (; i < sin + n; i++) {
			if (in[i] == pre[spre]) {
				break;
			}
		}

		makePost(post, spost - 1, pre, spre + 1 + (i - sin), in, sin + 1 + (i -sin), n - (i - sin) - 1);
		makePost(post, spost - 1 - (n - (i - sin) - 1), pre, spre + 1, in, sin, i - sin);
	}
}

Measured memory_bytes: 18248
#include<bits/stdc++.h>
using namespace std;
int main()
    {

   long long int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%5!= 0 && i%3 !=0){
            sum+=i;
        }
    }
    cout<<sum;



    }


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

 
int main()
{
   int n,j,i;
  scanf("%d",&n);
  string s;
  cin>>s;
  if(n%2!=0)
      printf("No");
  
  else
  {
    j=n/2;
    for(i=0;i<n/2;++i)
    {
      if(s[i]==s[j])
          j++;
      
      else
         break;
    }
    
    if(i==n/2)
        printf("Yes");
    
    else
        printf("No");
  }
  
}

Measured memory_bytes: 256
/*
    I was lying to myself
*/




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

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

#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pf           push_front
#define pi           acos(-1)
#define all(x)       x.begin(),x.end()
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF          0x3f3f3f3f
#define inputfile    freopen("input.txt", "r", stdin)
#define outputfile   freopen("output.txt", "w", stdout)
#define appendfile   freopen("output.txt", "a", stdout)


struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);auto hash2 = hash<T2> {}(p.second);return hash1 ^ hash2;
    }
};

ll t;
ll mod=N;
ll BigMod(ll base,ll pow,ll mod)
{
    if(pow==0||base==1)return 1;
    else if(pow==1)return base;
    else if(pow%2)return BigMod(base,pow-1,mod)*base%mod;
    else {ll x=(BigMod(base,pow/2,mod)%mod);x=(x*x)%mod;return x;}
}





vector<ll>v;
ll pr[1000005],cnt[1000005];

void sieve()
{
    for(ll i=1;i<=1e6;i++)
    {
        pr[i]=i;
    }
    for(ll i=2;i<=1e6;i+=2)pr[i]=2;
    for(ll i=3;i*i<=1e6;i+=2)
    {
        if(pr[i]!=i)continue;
        for(ll j=i*i;j<=1e6;j+=2*i)
        {
            if(pr[j]!=j)continue;
            pr[j]=i;
        }
    }
}

int main()
{
    fast;
    sieve();
    ll a,b,c,d,e,f,g,i,j;
    ll n,m,k;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        v.pb(a);
        if(i)
        {
            g=__gcd(g,a);
        }
        else g=a;
    }
    d=0;
    for(i=0;i<n;i++)
    {
        a=v[i];
        while(a!=1)
        {
            b=pr[a];
            cnt[b]++;
            if(cnt[b]>=2)
            {
                d=1;
                break;
            }
            while(a%b==0)
            {
                a=a/b;
            }
        }
        if(d)break;
    }
    if(d&&g==1)
    {
        cout<<"setwise coprime"<<endl;
    }
    else if(d)
    {
        cout<<"not coprime"<<endl;
    }
    else cout<<"pairwise coprime"<<endl;
    return 0;
}



Measured memory_bytes: 19636
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
struct ml{
  int dt;
  struct ml *nx;
};
typedef struct ml Ml;
void f(Ml *a,int p,int q){
  int i;
  Ml *b,*c,*d;
  b=a;
  for(i=0;i<p-1;i++)
    b=b->nx;
  c=b;
  for(i=0;i<q;i++)
    c=c->nx;
  d=a->nx;
  a->nx=b->nx;
  b->nx=c->nx;
  c->nx=d;
  return;
}
int main(){
  int i;
  int n,r,p,q;
  Ml *a;
  while(cin>>n>>r&&n+r){
    a=(Ml*)malloc((n+2)*sizeof(Ml));
    for(i=0;i<n+1;i++){
      (a+i)->dt=n-i+1;
      (a+i)->nx=a+i+1;
    }
    (a+i)->dt=n-i+1;
    for(i=0;i<r;i++){
      cin>>p>>q;
      if(p!=1)
	f(a,p,q);
    }
    cout<<a->nx->dt<<endl;
    free(a);
  }
  return 0;
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/abc179/tasks/abc179_c

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

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

    long ans = 0;
    for (long a = 1; a < n; a++)
    {
        long b;
        b = (n - 1) / a;
        ans += b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
z['   '],i;
main(j){
	for(;++i<2e3;)
		for(j=z[i>>5]&1<<i?1e7:-2*i*~i;j<5e6;j+=i-~i)z[j>>5]|=1<<j;
	for(;~scanf("%d",&i);)
		for(j=i+1>>1;i;)
			z[--j>>5]&1<<j|
			z[j-1>>5]&1<<j-1|
			z[j-3>>5]&1<<j-3|
			z[j-4>>5]&1<<j-4||printf("%d\n",j*2+1,i=0);
}

Measured memory_bytes: 1016
H,W,K=map(int,input().split())
S=[input() for _ in range(H)]

ans=[[0]*W for _ in range(H)]

zero = -1
count = 1
for i in range(H):
  if zero == -1 and S[i].count('#')==0:
    zero = i
    continue
  if zero != -1 and S[i].count('#')==0:
    continue
  last=0
  for j in range(W):
    if S[i][j]=='.':
      if zero != -1:
        for k in range(zero,i):
          ans[k][j] = count
      ans[i][j] = count
    if S[i][j]=='#':
      if zero != -1:
        for k in range(zero,i):
          ans[k][j] = count
      ans[i][j] = count
      if j<W-1 and S[i][j+1:].count('#')==0:
        last = 1
      else:
        count += 1
    if j == W-1 and last:
      last = 0
      count += 1
    if j == W-1:
      zero = -1
      
if zero != -1:
  for i in range(zero,H):
    ans[i] = ans[zero-1]
      
for i in range(H):
  print(*ans[i])

Measured memory_bytes: 12596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <cctype>
using namespace std;

int main(){
    int n;
    cin >> n;
    while( n-- > 0 ){
        char t[12];
        int l, h;
        cin >> t;
        sort(t, t+8);
        l = atoi(t);
        sort(t, t+8, greater<int>());
        h = atoi(t);
        cout << h - l << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
W, H, N = map(int, input().split())
d = [[0, W], [0, H]]
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    d[0][0] = max(x, d[0][0])
  elif a == 2:
    d[0][1] = min(x, d[0][1])
  elif a == 3:
    d[1][0] = max(y, d[1][0])
  elif a == 4:
    d[1][1] = min(y, d[1][1])
print(max((d[0][1] - d[0][0]), 0) * max((d[1][1] - d[1][0]), 0))

Measured memory_bytes: 3064
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	ll n;
	cin >> n;

	ll ans = (n / 11) * 2;
	n %= 11;
	if (n > 6) ans += 2;
	else if (n > 0) ans++;
	cout << ans << endl;

}




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


	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    ts = list(map(int, input().split()))
    m = int(input())
    pxs = [list(map(int, input().split())) for _ in range(m)]

    for px in pxs:
        ans = 0
        for i in range(n):
            if i+1 == px[0]:
                ans += px[1]
            else:
                ans += ts[i]
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.util.*;

public class Main{

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String s = sc.next();

    if(a >= 3200) System.out.println(s);
    if(a < 3200) System.out.println("red");
  }

}


Measured memory_bytes: 21844
package main

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

// 速い標準入力 https://qiita.com/tnoda_/items/b503a72eac82862d30c6
var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	var sAry = make([]string, n)
	for i := 0; i < n; i++ {
		sAry[i] = nextLine()
	}

	m := map[string]int{}
	for i := 0; i < n; i++ {
		A := strings.Split(sAry[i], "")
		sort.Strings(A)
		s := strings.Join(A, "")
		m[s]++
	}

	ret := 0
	for key := range m {
		x := m[key] - 1
		ret += (x * (1 + x) / 2)
	}
	fmt.Println(ret)
}


Measured memory_bytes: 17408
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int a, b; cin >> a >> b;
    int ans = b;
    if(a < 13) {
        if(a >= 6) ans /= 2;
        else ans = 0;
    }
    cout << ans << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

const int mxn = 3005;
int dp[mxn][mxn];
int c[mxn][mxn];
int n, a[mxn];

int f(int l,int r)
{
	if(c[l][r])
		return dp[l][r];
	if(l == r)
		dp[l][r] = a[l];
	else
		dp[l][r] = max(a[l] - f(l + 1, r), a[r] - f(l, r - 1));
	c[l][r] = 1;
	return dp[l][r];
}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	FOR(i,1,n)
		cin >> a[i];
	memset(c,0,sizeof(c));
	cout << f(1,n);

	return 0;
}

Measured memory_bytes: 120492
# 種類が同じ寿司であれば、最も美味しさが高い寿司を選ぶべき。
# 従い、
# (1)各種類の最も美味しさが高い寿司グループ
# (2)それ以外の寿司グループ
# をいずれも降順に並べて、(1)から幾つ取るか(最低でも1つは取る)を全探索する
import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())

from collections import defaultdict
sushi = defaultdict(list) # 種類・おいしさ　のdictionary

for i in range(N):
  t,d = map(int,readline().split())
  sushi[t].append(d)
  
best_sushi = []
other_sushi = []

for value in sushi.values():
  value = sorted(value, reverse = True)
  best_sushi.append(value[0])
  other_sushi += value[1:]

best_sushi = sorted(best_sushi, reverse = True)
other_sushi = sorted(other_sushi, reverse = True)

best_num = 1 # best_sushiから選ぶ個数
other_num = K - 1 # other_sushiから選ぶ個数

if len(other_sushi) < other_num: # 選べない場合
  other_num = len(other_sushi)
  best_num = K - other_num
  
# それぞれの寿司から選ぶ個数の開始値が決定
# other_sushiの後ろの要素は切り離して良い

other_sushi = other_sushi[:other_num]
  
sushi_point = sum(best_sushi[:best_num]) + sum(other_sushi)
kind_point = best_num ** 2

ans = sushi_point + kind_point

# best寿司のインデックスを進めていく
for i in range(best_num, len(best_sushi)):
  sushi_point += best_sushi[i]
  if len(other_sushi) == 0:
    break
  rem = other_sushi.pop() # 取り除く寿司
  sushi_point -= rem
  kind_point = (i + 1) ** 2
  
  if ans < sushi_point + kind_point:
    ans = sushi_point + kind_point
    
print(ans)

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


#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;

signed main(){
    fast_IO;
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<ll> a(n);
        ll sum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        sort(a.begin(),a.end());
        sum-=a[n-1]/2;
        cout<<sum<<endl;
    }   
    return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int h,w,k;
  cin >> h >> w >> k;
  ll dp[h+1][w];
  mem(dp);
  dp[0][0]=1;
  rep(i,h) {
    rep(j,w) {
      rep(t,1<<(w-1)) {
        bool f=1;
        rep(l,w-1) {
          if((t&(1<<l))&&(t&(1<<(l+1)))) f=0;
        }
        if(!f) continue;
        if(t&(1<<j)) {
          dp[i+1][j+1]+=dp[i][j];
          dp[i+1][j+1]%=MAX;
        } else if(j-1>=0&&(t&(1<<(j-1)))) {
          dp[i+1][j-1]+=dp[i][j];
          dp[i+1][j-1]%=MAX;
        } else {
          dp[i+1][j]+=dp[i][j];
          dp[i+1][j]%=MAX;
        }
      }
    }
  }
  pr(dp[h][k-1]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import heapq

N,M = map(int,input().split())
A = list(map(int,input().split()))
A = [a*-1 for a in A]

heapq.heapify(A)

for _ in range(M):
  a = heapq.heappop(A)
  heapq.heappush(A,-(-a//2))
  
print(sum(A)*-1)

Measured memory_bytes: 20324
#include<stdio.h>

int main()
{
	int a, b;

	scanf("%d %d",&a,&b);

	if (a + b == 15)
	{
		printf("+\n");
	}
	else if (a * b == 15)
	{
		printf("*\n");
	}
	else
	{
		printf("x\n");
	}
		
		return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#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);
 
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 vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  string s,t;cin>>s>>t;
  vsort(s);
  vsort(t);
  string ans="No";
  if(s[0]<t[t.size()-1])ans="Yes";
  int n=s.size();
  int m=t.size();
  if(n<m){
    rep(i,n){
      if(s[i]!=t[i])break;
      if(i==n-1)ans="Yes";
    }
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())

arr = []
exist = []

for i in range(h):
    s = input()
    a = []
    f = 0
    for j in range(w):
        if s[j] == '#':
            a.append(1)
            f = 1
        else:
            a.append(0)
    arr.append(a)
    if f == 1:
        exist.append(1)
    else:
        exist.append(0)
    
red = [[0 for i in range(w)] for j in range(h)]
blue = [[0 for i in range(w)] for j in range(h)]

flag = 0 #0なのは今から赤を塗るとき
pre_non_exist = 0
for i in range(h):
    if i == 0:
        for j in range(w):
            red[i][j] = 1
        flag = 1
    elif exist[i] == 1 and flag == 1:
        pre_non_exist = 0
        for j in range(w):
            blue[i][j] = 1
            if arr[i][j] == 1:
                red[i][j] = 1
        flag = 0
    elif exist[i] == 1 and flag == 0:
        pre_non_exist = 0
        for j in range(w):
            red[i][j] = 1
            if arr[i][j] == 1:
                blue[i][j] = 1
        flag = 1
    else:
        if pre_non_exist == 0:
            flag = (flag + 1) % 2
        pre_non_exist = 1
        if flag == 0:
            for j in range(w):
                if j == 0 or j == w-1:
                    red[i][j] = 1
                else:
                    blue[i][j] = 1
        else:
            for j in range(w):
                if j == 0 or j == w-1:
                    blue[i][j] = 1
                else:
                    red[i][j] = 1
                    
                    
for i in range(h):
    s = ""
    for j in range(w):
        if red[i][j] == 1:
            s = s + '#'
        else:
            s = s + '.'
    print(s)

print()

for i in range(h):
    s = ""
    for j in range(w):
        if blue[i][j] == 1:
            s = s + '#'
        else:
            s = s + '.'
    print(s)

Measured memory_bytes: 11636
S = input()
count1 = 0
count0 = 0
for s in S:
  if s == '1':
    count1 += 1
  else:
    count0 += 1
if count1 == 0 or count0 == 0:
  print(0)
else:
  print(2 * min(count1, count0))

Measured memory_bytes: 3188
// Date: 2020-01-22

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) x.size()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

pii a[N];
int main() {
	FIO;
	int n;
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i].fi >> a[i].se;
	}
	sort(a+1, a+1+n);
	int ans = n, pre = 1;
	rep(i, 2, n) {
		if(a[i].fi-a[i].se < a[pre].fi + a[pre].se) {
			ans--;
			if(a[i].fi + a[i].se < a[pre].fi + a[pre].se) pre = i;
		} else pre = i;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
a, b, c, d = map(int, input().split())

if a>c:
    if d<a:
        print(0)
    elif a<=d<b:
        print(d-a)
    else:
        print(b-a)

elif a==c:
    if d<b:
        print(d-c)
    else:
        print(b-a)

else:
    if b<c:
        print(0)
    elif c<=b<d:
        print(b-c)
    else:
        print(d-c)

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

int main(){
  int N;
  float x,sum=0.0;
  string u;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> x >> u;
    if(u=="JPY"){
      sum+=x;
    }else{
      sum+=x*380000;
    }
  }
  cout << sum << endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n,m,d;cin>>n>>m>>d;
    vi a(n*m,0);
    map<int,pair<int,int>>b;
    rep(i,n){
        rep(j,m){
            int x;cin>>x;x--;
            b[x]=MP(i,j);
        }
    }
    rep(i,n*m){
        if(i+d<n*m)a[i+d]=a[i]+abs(b[i+d].F-b[i].F)+abs(b[i+d].S-b[i].S);
    }
    int q;cin>>q;
    rep(i,q){
        int x,y;cin>>x>>y;
        x--;y--;
        cout<<a[y]-a[x]<<endl;
    }
}


Measured memory_bytes: 7040
// Problem : C - Be Together
// Contest : AtCoder - AtCoder Beginner Contest 043
// URL : https://atcoder.jp/contests/abc043/tasks/arc059_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, l1, r1, l2, r2, s= 0;
	int ans1 = 0, ans2=0, ans3=0, ans4=0;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
	    cin >> v[i];
	    s+=v[i];
	}
	l1 = s/n;
	r1 = l1+1;
	sort(v.begin(), v.end());
	if(n%2){
	    l2=v[n/2];
	    r2=l2+1;
	}
	else{
	    l2 = (v[n/2] + v[n/2-1])/2;
	    r2 = l2+1; 
	}
	for(int i:v){
	    ans1+=pow(l1-i,2);
	    ans2+=pow(r1-i,2);
	    ans3+=pow(l2-i,2);
	    ans4+=pow(r2-i,2);
	}
	cout << min(min(ans1,ans2), min(ans3,ans4));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

int main(){
    ll X, T;
  	cin >> T >> X;
  	cout << setprecision(5) << (double)T / (double)X << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;

#define MAX_N 8

int N, A, B, C;
int l[MAX_N];
int ans[70000];

/*
void dfs(int n, std::vector<int> v) {
    if (n == N) {
        calc(v);
    }

    for (int i = 0; i < 4; i++) {
        v[n] = i;
        dfs(n+1, v);
    }
}
*/

int calc(std::vector<int> v) {
    int sum = INF;
    int acount = 0;
    int bcount = 0;
    int ccount = 0;
    int a = 0;
    int b = 0;
    int c = 0;

    for (int i = 0; i < N; i++) {
        if (v[i] == 0) {
            acount++;
            a += l[i];
        } else if (v[i] == 1) {
            bcount++;
            b += l[i];
        } else if (v[i] == 2) {
            ccount++;
            c += l[i];
        }
    }

    if (acount && bcount && ccount) {
        int tmpa = (acount - 1)*10 + std::abs(a - A);
        int tmpb = (bcount - 1)*10 + std::abs(b - B);
        int tmpc = (ccount - 1)*10 + std::abs(c - C);
        sum = tmpa + tmpb + tmpc;
    }

    return sum;
}

int main(int argc, char *argv[])
{
    std::cin >> N >> A >> B >> C;

    for (int i = 0; i < N; i++) {
        std::cin >> l[i];
    }

    for (int i = 0; i < 70000; i++) {
        ans[i] = INF;
    }

    for (int i = 0; i < (1<<2*N); i++) {
        std::vector<int> v(N);
        for (int j = 0; j < N; j++) {
            v[j] = (i >> 2*j) & 3;
        }
        ans[i] = calc(v);
    }

    int min = INF;
    for (int i = 0; i < 70000; i++) {
        if (min > ans[i]) {
            min = ans[i];
        }
    }

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

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n,k,ans;
    cin >> n >> k;
    ans=1;
    if(n>k) cout << 0 << endl;
    else{
        for(int i=k;i>k-n;i--){
            ans *= i;
            ans %= 1000000007;
        }
    cout << ans << endl;
    }
}



Measured memory_bytes: 3124
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
int main(void){
  int n;
  cin>>n;
  vi l(n);
  rep(i,n)cin>>l[i];
  sort(l.begin(),l.end());
  int nowl=1;
  int nowr=2;
  ll ans=0;
  int mode=0;//0が、rが伸びる１が血事務
  //cout<<"w";
  /*for(int now=0;now<n-2;now++){
    for(int nowl=now+1;nowl<n-1;nowl++){
      for(int nowr=nowl+1;nowr<n;nowr++){
        if(l[now]<l[nowr]+l[nowl] && l[nowl]<l[now]+l[nowr] && l[nowr]<l[now]+l[nowl]){
          
          cout<<"e " <<now<<" "<<nowl<<" "<<nowr<<" "<<l[now]<<" "<<l[nowl]<<" "<<l[nowr]<<" "<<endl;
        }
      }
    }
  }*/
  for(int now=0;now<n-2;now++){
    nowl=now+1;
    nowr=now+2;
    mode=0;
    while(now<n-2){
      //cout<<"e " <<now<<" "<<nowl<<" "<<nowr<<" "<<l[now]<<" "<<l[nowl]<<" "<<l[nowr]<<" "<<mode<<endl;
      if(nowl==n-1&&nowr==n-1){
        break;
      }
      if(nowr==n-1){
        if(l[now]<l[nowr]+l[nowl] && l[nowl]<l[now]+l[nowr] && l[nowr]<l[now]+l[nowl]){
          //cout<<"yyyuu";
          ans++;
        }
        nowl++;
        continue;
      }
      if(nowl==nowr){
        mode=0;
        nowr++;
        continue;
      }
      if(mode==0){
        if(l[now]<l[nowr]+l[nowl] && l[nowl]<l[now]+l[nowr] && l[nowr]<l[now]+l[nowl]){
          ans+=nowr-nowl;
          nowr++;
        }else{
          mode=1;
          nowl++;
        }
      }else{
          if(l[now]<l[nowr]+l[nowl] && l[nowl]<l[now]+l[nowr] && l[nowr]<l[now]+l[nowl]){
            //cout<<"ttt";
            ans+=nowr-nowl;
            nowr++;
          }else{
            nowl++;
          }
        
      }
    }

  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll a, b;
    cin >> a >> b;
    if(a > b){
        rep(i,a){
            cout << b;
        }
    }else{
        rep(i,b){
            cout << a;
        }
    }
}


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

int main(){
    int n;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++)
    cin>>p[i];
    int a=1,ans=0;
    for(int i=0;i<n;i++){
        if(a!=p[i])
        ans++;
        a++;
    }
    if(ans>2)
    cout<<"NO"<<endl;
    else
    cout<<"YES"<<endl;
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
  
  	bool flag = false;
  	if (s[0] == s[1])
    {
      if (s[0] == s[2])
      {
        flag = true;
      }
    }

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

    return 0;
}

Measured memory_bytes: 256
solve :: Int -> Int -> [String]
solve x y
  | x > 9 = []
  | y > 9 =	solve (x + 1) 1
  | otherwise = (show x ++ "x" ++ show y ++ "=" ++ show (x*y)) : solve x (y+1)

main = mapM_ putStrLn $ solve 1	1

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

int main()
{

    cin >> s;
    int flag = 1;
    //確実にDPの問題のはず。
    for (int i = s.size() - 1; i >= 2; i--)
    {
        if (i > 3 && (s[i] == 'e' && s[i - 1] == 's' && s[i - 2] == 'a' && s[i - 3] == 'r' && s[i - 4] == 'e'))
        {
            i -= 4;
        }
        else if (i > 3 && (s[i] == 'm' && s[i - 1] == 'a' && s[i - 2] == 'e' && s[i - 3] == 'r' && s[i - 4] == 'd'))
        {
            i -= 4;
        }
        else if (i > 4 && (s[i] == 'r' && s[i - 1] == 'e' && s[i - 2] == 's' && s[i - 3] == 'a' && s[i - 4] == 'r' && s[i - 5] == 'e'))
        {

            i -= 5;
        }
        else if (i > 5 && (s[i] == 'r' && s[i - 1] == 'e' && s[i - 2] == 'm' && s[i - 3] == 'a' && s[i - 4] == 'e' && s[i - 5] == 'r' && s[i - 6] == 'd'))
        {
            i -= 6;
        }
        else
        {
            flag = 0;
            break;
        }
    }
    if (flag)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}

Measured memory_bytes: 512
def main():
        N,Q = map(int,input().split())
        ab = [list(map(int,input().split())) for _ in range(N - 1)]
        px = [list(map(int,input().split())) for _ in range(Q)]
        ab.sort()
        # px.sort()
        plus = [0 for _ in range(N)]

        for p,x in px:
                plus[p - 1] += x 

        for a,b in ab:
                plus[b - 1] += plus[a - 1]
        for p in plus:
                print(p)

if __name__ == '__main__':
        main()

Measured memory_bytes: 111100
import itertools
X=int(input())
li=[i**5 for i in range(128)]#
for v in itertools.permutations(li, 2):
    v=list(v)
    v.sort()
    if v[1]-v[0]==X:#両方プラスの時
        A=v[1]**0.2
        B=v[0]**0.2
        print(str(int(A))+" "+str(int(B)))
        break
    elif v[0]+v[1]==X:#v[0]がマイナスの時
        A=v[1]**0.2
        B=-1*((v[0])**0.2)
        print(str(int(A))+" "+str(int(B)))
        break
#ans=(i-j)*(i**4+(i**3)*j+(i**2)*(j**2)+i*(j**3)+j**4)
#(ａ－ｂ)(ａ⁴＋ａ³ｂ＋ａ²ｂ²＋ａｂ³＋小さい

Measured memory_bytes: 68364
n = int(input())
*v, = sorted(map(int, input().split()), reverse=True)

def mix(a, l: list) -> int:
    if len(l) == 1:
        return (a + l[0])/2

    return (a + mix(l[0], l[1:]))/2

print(mix(v[0], v[1:]))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String A = in.next();
            String B = in.next();
            String C = in.next();

            System.out.println(A.charAt(A.length() - 1) == B.charAt(0) && B.charAt(B.length() - 1) == C.charAt(0) ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 26892
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n >= 1200)cout<<"ARC";
    else cout<<"ABC";


    return 0;
}


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

typedef signed long long ll;
const int MX = 1e6 + 5;

int main() {
	int n, m;
	cin >> n >> m;
	if(n == m)
		cout << "Yes\n";
	else
		cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    int W;
    int[] w,w2;
    int[] dp,dp2;
    int odd = 45,all = 180;
    int INF = 1000000, max = 1000000;

    void solve(){
        Scanner sc = new Scanner(System.in);

        int oddI = 0;
        w = new int[180];
        w2 = new int[45];
        for(int i=1,j=i*(i+1)*(i+2)/6; j<max; i++,j=i*(i+1)*(i+2)/6){
            w[i-1] = j;
            if(j%2!=0) w2[oddI++] = j;
        }

        dp();

        while(true){
            W = sc.nextInt();
            if(W==0) break;

            System.out.println(dp[W]+" "+dp2[W]);
        }
    }

    void dp(){
        dp = new int[max]; dp2 = new int[max];
        Arrays.fill(dp,INF); Arrays.fill(dp2,INF);
        dp[0] = 0; dp2[0] = 0;
        for(int i=0; i<all-1; i++){
            for(int j=0; j<max; j++){
                if(j-w[i]>=0){
                    dp[j] = Math.min(dp[j], dp[j-w[i]]+1);
                }
                if(i<odd && j-w2[i]>=0){
                    dp2[j] = Math.min(dp2[j], dp2[j-w2[i]]+1);
                }
            }
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 20000
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
    int n,k;
    cin >> n >> k;
    int s[200010] = {0};
    rep(i,n){
        int a;
        cin >> a;
        s[i+1] = s[i] + a;
    }
    vector<pair<int,int>> p(n+1);
    rep(i,n+1){
        p[i] = MP(s[i]-i*k,i);
    }
    SORT(p);
    int c[200010] = {0};
    rep(i,n+1)c[p[i].se] = i;
    int ans = 0;
    BinaryIndexedTree<int> bit(1LL<<18);
    rep(i,n+1){
        ans += bit.sum(c[i]);
        bit.add(c[i],1);
    }
    cout << ans << endl;


    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://arc075.contest.atcoder.jp/tasks/arc075_c
// rm -r -f test;oj dl http://abc107.contest.atcoder.jp/tasks/abc107_b

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n;
   cin >> n;
   set<int> s;
   for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      s.insert(x);
   }

   cout << s.size() << endl;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long cmp(long x,long y,bool b){
  return (b?x<=y:x<y);
}
int main(){
  long n,k;cin>>n>>k;
  vector<long>P,N;
  for(long i=0;i<n;i++){
    long a;cin>>a;
    if(a>0)P.push_back(a);if(a<0)N.push_back(a);
  }
  if(k<=P.size()*N.size()){//マイナス
    //プラスとマイナスの掛け算
    sort(P.begin(),P.end(),greater<long>());sort(N.begin(),N.end());
    long l=-1000000000000000001,r=0;
    while(1){
      long z=(l+r)/2;
      long c[2]={0,0};
      for(int b=0;b<2;b++){
        long d=P.size();
        for(long i=0;i<N.size();i++){
          while(d>=0&&!cmp(N[i]*P[d-1],z,b))d--;
          c[b]+=max(d,0L);
        }
      }
      if(k>c[1]){l=z;}
      else if(c[0]>=k){r=z;}
      else if(c[0]!=c[1]){
        cout<<z;return 0;
      }
    }  
  }
  else if(k>n*(n-1)/2-(P.size()*(P.size()-1)/2+N.size()*(N.size()-1)/2)){//プラス
    sort(P.begin(),P.end());sort(N.begin(),N.end(),greater<long>());
    k-=n*(n-1)/2-(P.size()*(P.size()-1)/2+N.size()*(N.size()-1)/2);//1から始まる
    long l=0,r=1000000000000000001;
    while(1){
      long z=(l+r)/2;
      long c[2]={0,0};
      for(int b=0;b<2;b++){
        long dp=P.size(),dn=N.size();
        for(long i=0;i<P.size();i++){
          while(dp>i&&!cmp(P[i]*P[dp-1],z,b))dp--;
          c[b]+=max((dp-i-1),0L);
          if(dp<=i)break;
        }
        for(long i=0;i<N.size();i++){
          while(dn>i&&!cmp(N[i]*N[dn-1],z,b))dn--;
          c[b]+=max((dn-i-1),0L);
          if(dn<=i)break;
        }    
      }
      if(k>c[1]){l=z;}
      else if(c[0]>=k){r=z;}
      else if(c[0]!=c[1]){
        cout<<z;return 0;
      }
    }  
  }
  else {  
    cout<<0;
  }
}

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

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define PI 3.141592653589

using namespace std;

void InpAr(int *array, int n){
    REP(i,n) cin >> array[i];
}

int kaijo(int n){
    if(n == 0) return 1;
    int ans = 1;
    for(int i = 1; i <= n; i++){
        ans *= i;
    }
    return ans;
}

int count(int *array, int n){
    int ans = 0;
    

    REP(i,n){
        int ctr = 0;
        REP(j,i){
            if(array[j] < array[i]) ctr++;
        }
        ans += (array[i] - 1 - ctr) * kaijo(n-i-1);
    }

    return ans;
}

int main(void){
    int n ;
    cin >> n;
    int p[n], q[n];
    REP(i,n) cin >> p[i];
    REP(i,n) cin >> q[i];

    int a = count(p,n);
    int b = count(q,n);

    if(a > b) cout << a-b;
    else cout << b-a;
    
    return 0;
}

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

int main() {
	int M, D;
	cin >> M >> D;
	int ans = 0;
	for (int x = 2; x <= 9; x++) {
		for (int y = 2; y <= 9; y++) {
			if (x * y <= M && 10 * x + y <= D)
				ans++;
		}
		
	}
	cout << ans << endl;
}

Measured memory_bytes: 256