akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using ll = long long;
auto chmin = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto chmax = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
 
template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }
 
template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}
 
int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; 
    cin >> n;
    vector<int> a(n);
    cin>>a;
    sort(all(a));
    cout << ((a.end()==unique(all(a)))?"YES":"NO") << endl;
    return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=2e5+5,mod=1e9+7,bit=61;



signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll ans=0;
        f(i,1,n)
        {
            if(i%3 and i%5)
            {
                ans+=i;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
















Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <cmath>
#include <cstring>
#include <sstream>
#include <stdlib.h>
#include <iomanip>
//#include <vector>

using namespace std;

int main (void)
{
	int n,a[100];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int i = 1; i < n; i++)
	{
		int o = 0;
		o = a[i];
		for (int k = 0; k < n - 1; k++)
		{
			cout << a[k] << " "; // 出力
		}
		cout << a[n - 1] << endl;

		for (int j = i - 1; j >= 0; j--)
		{
			if (a[j] <= o)
			{
				break;
			}
			else
			{
				int p = 0,q = 0;
				p = a[j];
				q = a[j + 1];
				a[j + 1] = 0;
				a[j] = 0;
				a[j + 1] = p;
				a[j] = q;
			}
		}
	}

	for (int k = 0; k < n - 1; k++)
	{
		cout << a[k] << " ";
	}
	cout << a[n - 1] << endl;
}






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

namespace Main
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            char[] input = Console.ReadLine().ToCharArray();
            int size = input.Length;
            int d1 = 0; 
            int d2 = 0;
            for (int i = 0; i < size; i++)
            {
                if (i % 2 == 0)
                {
                    if (input[i] == '0')
                    {
                        d2++;
                    }
                    else
                    {
                        d1++;
                    }
                }
                else
                {
                    if (input[i] == '0')
                    {
                        d1++;
                    }
                    else
                    {
                        d2++;
                    }
                }
            }
            Console.WriteLine(Math.Min(d1, d2));
        }
    }
}


Measured memory_bytes: 13176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  if (n & 1) {
    cout << "No" << endl;
    return 0;
  }
  rep(i, n / 2) {
    if (s[i] != s[i + n / 2]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<hash_map>
#include<bitset>

using namespace std;

long long ans;
string str;
int N;

void GetAns(int s){
	vector<int>var(N,0);
	int i=0;
	while(s>0){
		if(s&1){
			var[i++]=1;
		}
		else{
			var[i++]=0;
		}
		s/=2;
	}
	long long tempAns=0;
	for(int i=0;i<N;++i){
		tempAns=tempAns*10+str[i]-'0';
		if(var[i]==1){
			ans+=tempAns;
			tempAns=0;
		}
	}
	ans+=tempAns;
}

int main(){	
	cin>>str;
	N=str.size();
	ans=0;
	for(int i=0;i<1<<(N-1);++i){
		GetAns(i);
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 256
import Control.Monad
import Data.List

isUniq :: Int -> [String] -> Bool
isUniq n w
  | n == length (nub w) = True
  | otherwise = False
  
isSiritori :: [String] -> Bool
isSiritori [_] = True
isSiritori (w0:w1:ws)
  | last w0 == head w1 = isSiritori (w1:ws)
  | otherwise = False

main = do
  n <- readLn
  w <- replicateM n getLine
  let ans = if(isUniq n w && isSiritori w)
            then "Yes"
            else "No"
  putStrLn ans
  

Measured memory_bytes: 636
#include<iostream>
#include<string>
#include<vector>
#include<sstream>

std::string toString(int a){
	std::string res;
	std::stringstream z;

	z << a;
	z >> res;

	return res;
}

void setfizzbuzz(std::vector<std::string>&v, int n){

	for (int i = 1; i <= n; i++){
		if (i % 15 == 0)v[i - 1] = "FizzBuzz";
		else if (i % 3 == 0)v[i - 1] = "Fizz";
		else if (i % 5 == 0)v[i - 1] = "Buzz";
		else v[i - 1] = toString(i);

	}

}

int main(){

	int m, n;
	while (std::cin >> m >> n){
		if (m == 0 && n == 0)break;

		std::vector<std::string>fizzbuzz(n);
		std::vector<bool>player(m, true);

		setfizzbuzz(fizzbuzz, n);

		int playnum = m;

		for (int i = 0, pnum = 0; i < n; i++, pnum++){
			if (pnum == m)pnum -= m;
			while (!player[pnum]){
				pnum++;
				if (pnum == m)pnum -= m;
			}

			std::string str;
			std::cin >> str;

			if (playnum != 1 && str != fizzbuzz[i]){
				player[pnum] = false;
				playnum--;
			}
		}

		bool ku = true;
		for (int i = 0; i < player.size(); i++){
			if (player[i]){
				if (ku)std::cout << i + 1, ku = false;
				else std::cout << " " << i + 1;
			}
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1696
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#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 repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++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 iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

int main()
{
	FAST;

	int n, h, w;
	cin >> n >> h >> w;

	cout << (n-h+1)*(n-w+1) << LF;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false) , cin.tie(0) ;
#define all(v) v.begin(),v.end()
#define w(x) cout << (#x) << " is " << x << "\n" ;

int main()
{
    fast ;
    int n,i,t;
    string s;
    map< string,int > m;
    vector< pair< int,string > >v;
    vector<string>x;
    cin >> t ;
    while(t--)
    {
        cin >> s ;
        m[s]++;
    }
    int mx=0;
    for(auto it =m.begin() ; it!= m.end() ; it++)
    {
        int a = it->second ;
        string y = it->first ;
        if(a>mx)mx=a;
        v.push_back(make_pair(a,y) ) ;
    }
    sort(v.rbegin(),v.rend());
    for(i = 0 ; i < v.size() ; i++)
    {
        if(v[i].first==mx)
            x.push_back(v[i].second);
    }
    sort(x.begin(),x.end());
    for(auto it :x)
        cout << it << "\n";
    cout << "\n";

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    for(int i = 0; i < n; i++){
        cin >> b.at(i);
    }
    for(int i = 0; i < n; i++){
        cin >> c.at(i);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    long long int res = 0;
    long long int min = 0;
    long long int max = 0;
    for(int i = 0; i < n; i++){
        //min = lower_bound(a.begin(), a.end(), b[i]);
        min = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        //max = n - upper_bound(c.begin(), c.end(), b[i]);
        max = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
        res += min * max;
    }
    cout << res << endl;
}


Measured memory_bytes: 4576
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll n; cin >> n;
    vector<ll> a(n + 1);
    rep(i, n + 1) cin >> a[i];

    if(n == 0){
        if(a[0] != 1){
            cout << -1 << endl;
        }else{
            cout << 1 << endl;
        }
        return 0;
    }else if(a[0] != 0){
        cout << -1 << endl;
        return 0;
    }

    vector<ll> a_sum(n + 2);
    a_sum[0] = 0;
    _rep(i, 1, n + 2){
        a_sum[i] = a_sum[i - 1] + a[i - 1];
    }
    ll ans = 1;
    ll b = 1;
    _rep(i, 1, n + 1){
        b = min(a_sum[n + 1] - a_sum[i], (b - a[i - 1]) * 2);
        ans += b;
        if(b < a[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i,N) cin >> A[i];

  vector<pair<int,int>> B(N);
  REP(i,N) B[i] = make_pair(A[i], i);
  sort(ALL(B));

  int res = 0;
  for(int i = 0; i < N; i += 2) {
    if(B[i].second % 2 == 1) res++;
  }
  cout << res << endl;
  return 0;
}



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

int main()
{
  int s;
  cin >> s;
  
  int first = s / 100;
  int second = s % 100;
  
  // MMYYではない
  if (first < 1 || first > 12)
  {
    if (second < 1 || second > 12)
      cout << "NA" << endl;
    else
      cout << "YYMM" << endl;
  }
  // MMYYかもしれない
  else
  {
    // MMYY確定
    if (second < 1 || second > 12)
      cout << "MMYY" << endl;
    // どっちともわからん
    else
      cout << "AMBIGUOUS" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        rec(n, "a", 'a');

    }

    private static void rec(int n, String s, char max) {
        if (n == s.length()) {
            System.out.println(s);
            return;
        }

        for (char c = 'a'; c < (char) (max + 2); c++) {
            rec(n, s + c, max > c ? max : c);
        }


    }
}


Measured memory_bytes: 44572
#include <bits/stdc++.h>
using namespace std;
int N,A,B,C;
int l[10];
long long int ma=INT_MAX;
long long int dfs(int n,int a,int b,int c){
  if (n==N) {
    if(min(a,min(b,c))>0)return abs(a-A)+abs(b-B)+abs(c-C)-30;
    else return ma;
  }
  long long int res0=dfs(n+1,a,b,c);
  long long int res1=dfs(n+1,a+l[n],b,c)+10;
  long long int res2=dfs(n+1,a,b+l[n],c)+10;
  long long int res3=dfs(n+1,a,b,c+l[n])+10;
  return min(res0,min(res1,min(res2,res3)));
}
int main(){
  cin >> N >> A >> B >> C;
  for(int i=0;i<N;i++)cin >> l[i];
  long long int ans=dfs(0,0,0,0);
  cout << ans <<endl;
}

Measured memory_bytes: 256
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a
 
def union(A, x, y):
#    bx, by = sorted([find(A,x), find(A,y)]) # bx, by = find(A,x), find(A,y)だと無限ループ。
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

#import sys
#input = sys.stdin.readline
import heapq
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    V = [ i for i in range(N)]
    q = []
    for _ in range(M):
        x, y = map( int, input().split())
        union(V, x, y)
    C = [0]*N
    T = [ [] for _ in range(N)]
    for i in range(N):
        C[find(V,i)] += 1
        heapq.heappush(T[find(V,i)], A[i])
    ans = 0
    if M == 0 and N == 1:
        print(0)
        return
    if M == 0:
        print("Impossible")
        return
    s = 0
    for i in range(N):
        if C[i] >= 2:
            if s == 0:
                q = T[i]
                heapq.heapify(q)
                s = 1
                continue
            if q:
                ans += heapq.heappop(q)
                ans += heapq.heappop(T[i])
                for a in T[i]:
                    heapq.heappush(q, a)
            else:
                print("Impossible")
                return
    for i in range(N):
        if C[i] == 1:
            if q:
                ans += heapq.heappop(q)
                ans += T[i][0]
            else:
                print("Impossible")
                return
    print(ans)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 121752
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    Array(n) {
        val (a, b) = readIntegerList()
        Pair(a,b)
    }.maxBy { it.first }!!
        .let { out.println(it.first + it.second) }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 66092
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner kbd = new Scanner(System.in);
		int a =kbd.nextInt();
		int b =kbd.nextInt();
		int c =kbd.nextInt();
		if(a<b && b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26196
#include<bits/stdc++.h>
using namespace std;
#define rep1(i,n) for(i=1;i<=n;i++)
int main(){
  int i;
  int N;
  int A[101];
  bool exist = false;
  
  cin >> N;
  
  rep1(i,N){
    cin >> A[i];
    if(A[i]%2==0){
      if(A[i]%3!=0 && A[i]%5!=0){
        exist = false;
        break;
      }
    }
    if(i==N)
      exist = true;
  }
  if(exist==false)
    cout << "DENIED";
  else
    cout << "APPROVED";
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string x, y;
    cin >> x >> y;
    if (x < y) cout << "<" << endl;
    else if (x > y) cout << ">" << endl;
    else cout << "=" << endl;
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int k = n;
	if (n % 2 == 0) cout << n;
	else {
		while (k % n != 0 || k % 2 != 0) {
			k+=k;
		}
		cout << k;
	}

	return 0;
}

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

int main(){
  string A, B, C;
  char index = 'a';
  cin >> A >> B >> C;
  
  while(1){
    if(index == 'a'){
      
      if (A[0] == 'b')
        index ='b';
      
      else if (A[0] == 'c')
        index = 'c';
      
      A = A.erase(0, 1);
      
      if(A.empty() == true && index == 'a')
        break;
    }
    
    else if (index == 'b'){
      
      if (B[0] == 'a')
        index ='a';
      
      else if (B[0] == 'c')
        index = 'c';
      
      B = B.erase(0, 1);
      if(B.empty() == true && index == 'b')
        break;
    }
    
    else{
      
      if (C[0] == 'b')
        index ='b';
      
      else if (C[0] == 'a')
        index = 'a';
      
      C = C.erase(0, 1);
      if(C.empty() == true && index == 'c')
        break;
    }
  }
    
    if(A.empty() == true && index == 'a')
      cout << 'A' << endl;
    
    if(B.empty() == true && index == 'b')
      cout << 'B' << endl;
    
    if(C.empty() == true && index == 'c')
      cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
 
const int N=2e5+10;
const ll MOD2=998244353;
const ll MOD=1e9+7;

ll dp[100][2][2][2],P2[100];

int main(){
    fastio;
    srng;
    #ifdef ALEXPC
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll l,r;
    cin>>l>>r;
    P2[1]=1;
    FORT(i,2,61){
        P2[i]=P2[i-1]*2ll;
    }
    FOR(pl,2)FOR(pr,2)FOR(ar,2)dp[0][pl][pr][ar]=1;
    FORT(i,1,61)FOR(pl,2)FOR(pr,2)FOR(ar,2){
        bool col00=true,col11=true,col01=true;
        if (pl && l&P2[i]){
            col00=false;
            col01=false;
        }
        if (pr && (r&P2[i])==0){
            col01=false;
            col11=false;
        }
        if (ar){
            col01=false;
        }
        int npr=pr,npl=pl,nar=ar;
        if (col00){
            if (r&P2[i])npr=0;
            dp[i][pl][pr][ar]+=dp[i-1][npl][npr][nar];
            dp[i][pl][pr][ar]%=MOD;
            if (r&P2[i])npr=pr;   
        }
        if (col01){
            dp[i][pl][pr][ar]+=dp[i-1][npl][npr][nar];
            dp[i][pl][pr][ar]%=MOD;
        }
        if (col11){
            nar=0;
            if ((l&P2[i])==0)npl=0;
            dp[i][pl][pr][ar]+=dp[i-1][npl][npr][nar];
            dp[i][pl][pr][ar]%=MOD;
            if ((l&P2[i])==0)npl=pl;
            nar=ar;
        }
        //cout<<dp[i][pl][pr][ar]<<endl;
    }
    cout<<dp[61][1][1][1]<<endl;
    return 0;
}

Measured memory_bytes: 256
Q, H, S, D = [int(_) for _ in input().split()]
N = int(input())

H = min(H, Q*2)
S = min(S, H*2)
D = min(D, S*2)

if N % 2 == 0:
    print(D * (N // 2))
else:
    print(D * (N // 2) + S)


Measured memory_bytes: 9164
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int h,a;
	cin>>h>>a;
	int ans = h/a;
	if(h%a != 0)ans++;
	cout<<ans;	

	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String sp=" ";
        String[] f=br.readLine().split(sp);
        int n=Integer.parseInt(f[0]);
        int m=Integer.parseInt(f[1]);
        int l=Integer.parseInt(f[2]);
        int[][] A=new int[n][m];
        int[][] B=new int[m][l];
        String[] s;
        for(int i=0;i<n;i++){
        	s=br.readLine().split(sp);
        	for(int j=0;j<m;j++) A[i][j]=Integer.parseInt(s[j]);
        }
        for(int i=0;i<m;i++){
        	s=br.readLine().split(sp);
        	for(int j=0;j<l;j++) B[i][j]=Integer.parseInt(s[j]);
        }
    	StringBuilder sb = new StringBuilder();
    	long b;
        for(int ni=0;ni<n;ni++){
        	for(int li=0;li<l;li++){
        		b=0;
            	for(int mi=0;mi<m;mi++) b+=A[ni][mi]*B[mi][li];
            	sb.append(b);
            	if(li!=l-1) sb.append(sp);
        	}
        	sb.append("\n");
        }
    	System.out.print(sb);
	}
}

Measured memory_bytes: 33176
#include <algorithm>
#include <cstring>
#include <cstdio>
struct point
{
	int x, y; 
} arr[300005], st1[300005], st2[300005]; 
int mx[1200005], lazy[1200005], n, w, h, ans; 
void modify(int u, int l, int r, int L, int R, int x)
{
	if (L <= l && r <= R)
	{
		mx[u] += x; 
		lazy[u] += x; 
		return; 
	}
	int m = l + r >> 1; 
	if (L <= m)
		modify(u << 1, l, m, L, R, x); 
	if (m < R)
		modify(u << 1 | 1, m + 1, r, L, R, x); 
	mx[u] = std::max(mx[u << 1], mx[u << 1 | 1]) + lazy[u]; 
}
void work()
{
	std::sort(arr, arr + n, [&] (const point &a, const point &b) { return a.x < b.x; }); 
	memset(mx, -0x3f, sizeof(mx)); 
	memset(lazy, 0, sizeof(lazy)); 
	int tp1 = 0, tp2 = 0; 
	for (int i = 0; i < n - 1; i++)
	{
		auto *st = arr[i].y <= h / 2 ? st1 : st2; 
		int nxt = i - 1, &tp = arr[i].y <= h / 2 ? tp1 : tp2; 
		while (tp && ((st[tp - 1].y < arr[i].y) ^ (arr[i].y > h / 2)))
		{
			modify(1, 0, n - 1, st[tp - 1].x, nxt, (st[tp - 1].y - arr[i].y) * (arr[i].y <= h / 2 ? 1 : -1)); 
			nxt = st[--tp].x - 1; 
		}
		if (nxt != i - 1)
			st[tp++] = {nxt + 1, arr[i].y}; 
		st1[tp1++] = {i, 0}; 
		st2[tp2++] = {i, h}; 
		modify(1, 0, n - 1, i, i, -mx[0] + h - arr[i].x); 
		ans = std::max(ans, mx[1] + arr[i + 1].x); 
	}
}
int main()
{
	// freopen("ARC063-F.in", "r", stdin); 
	scanf("%d%d%d", &w, &h, &n); 
	for (int i = 0; i < n; i++)
		scanf("%d%d", &arr[i].x, &arr[i].y); 
	arr[n++] = {0, 0}; 
	arr[n++] = {w, h}; 
	work(); 
	std::swap(w, h); 
	for (int i = 0; i < n; i++)
		std::swap(arr[i].x, arr[i].y); 
	work(); 
	printf("%d\n", ans << 1);
	return 0;
}


Measured memory_bytes: 16512
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
int n, m;
vector<int> card, tmp;

scanf("%d%d", &n, &m);
n *= 2;
card.resize(n);
tmp.resize(n);

for(int i = 0; i < n; ++i)
card[i] = 1 + i;

for(int i = 0; i < m; ++i) {

int k;

scanf("%d", &k);

if(k == 0) {

for(int i = 0; i < n / 2; ++i) {
tmp[i * 2] = card[i];
tmp[i * 2 + 1] = card[i + n / 2];
}
} else {
for(int i = 0; i < n - k; ++i)
tmp[i] = card[i + k];
for(int i = 0; i < k; ++i)
tmp[n - k + i] = card[i];
}
card = tmp;
}
for(int i = 0; i < n; ++i)
printf("%d\n", card[i]);
return 0;
}

Measured memory_bytes: 1052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int a = N;
  int b = 0;
  while (a != 0) {
    b += a % 10;
    a /= 10;
  }
  
  if (N % b == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for C - Grand Garden
	var N int
	fmt.Scanf("%d", &N)

	h := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &h[i])
	}

	var count int
	var flag int = 0

	if N == 1 {
		count = h[0]
	} else {
		if h[0] <= h[1] {
			flag = 0
		} else {
			count += h[0]
			flag = 1
		}

		for i := 0; i < N-1; i++ {
			if h[i] > h[i+1] && flag == 0 {
				count += h[i]
				flag = 1
			}

			if h[i] < h[i+1] && flag == 1 {
				count -= h[i]
				flag = 0
			}
		}

		if flag == 0 {
			count += h[N-1]
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 1836
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int lon;
	string s,ans;
	cin >> s;
	lon = s.length();
	for (int i = 0; i < lon; i++) {
		if (s[i] == '0')ans.push_back('0');
		else if (s[i] == '1')ans.push_back('1');
		else if (s[i] == 'B'){
		    if(ans.length()!=0)ans.pop_back();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N, L, T = map(int, input().split())

s = 0
X = [0] * N
for i in range(N):
    x, w = map(int, input().split())
    if w == 1:
        x += T
    else:
        x -= T
    # xが0点を通る回数を足す
    s += x // L
    X[i] = x % L

X.sort()
for i in range(N):
    print(X[(i+s) % N])


Measured memory_bytes: 8108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (const auto& vv : v) {
    for (const auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

void solve() {
    int n, d;
    cin >> n >> d;


    ll cnt = 0;
    F0R(i, n) {
        ll a, b;
        cin >> a >> b;

        double dist = sqrt(a*a + b*b);
        if(dist <= d) cnt++;
    }

    cout << cnt << endl;
}

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

    int tc = 1;
    FOR(i, 1, tc + 1) {
        //cout << "Case #" << i << ": ";
        solve();
    }
}



Measured memory_bytes: 3696
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/16/20 21:00:53
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<int> A(n); for (auto& a:A) cin>>a;
  int l = 0;
  int xa = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    while (l < i and (xa & A[i]) != 0) {
      xa ^= A[l++];
    }
    xa ^= A[i];
    ans += i-l+1;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define ZERO 0
#define M_TATE 12
#define M_YOKO 13 

void b_island(int x, int y, char island[M_TATE][M_YOKO]);

int main(void)
{
    char island[M_TATE][M_YOKO];
    int i;
    int x,y;
    int count;

    while (scanf("%s", island[0]) == 1){
        for (i = 1; i < M_TATE; i++){
            scanf("%s", island[i]);
        }
        count = 0;
        for (y = 0; y < M_TATE; y++){
            for (x = 0; x < M_TATE; x++){
                if (island[y][x] == '1'){
                    count++;
                    b_island(x, y, island);
                }
            }
        }
        printf("%d\n", count);
    }

    return (0);
}
void b_island(int x, int y, char island[M_TATE][M_YOKO])
{
    if (island[y][x] != '1'){
        return;
    }
    island[y][x] = '0';
    if (x > 0){
        b_island(x - 1, y, island);
    }
    if (y > 0){
        b_island(x, y - 1, island);
    }
    if (x < 11){
        b_island(x + 1, y, island);
    }
    if (y < 11){
        b_island(x, y + 1, island);
    }
}


Measured memory_bytes: 2028
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

if N%2 == 1:
  AB.sort(key=lambda x:x[1])
  Mmax = AB[N//2][1]
  AB.sort()
  Mmin = AB[N//2][0]
  nowB = 0
  empty = 0
  for A, B in AB:
    if A <= Mmin:
      nowB = max(nowB, B)
    else:
      if nowB >= Mmax:
        break
      if A > nowB+1:
        empty += (min(A,Mmax+1) -nowB -1)
      nowB = B
  print(Mmax -(Mmin-1) -empty)
else:
  AB.sort(key=lambda x:x[1])
  Mmax = (AB[N//2-1][1] + AB[N//2][1])
  AB.sort()
  Mmin = (AB[N//2-1][0] + AB[N//2][0])
  nowB = 0
  empty = 0
  for A, B in AB:
    if A <= Mmin:
      nowB = max(nowB, B)
    else:
      if nowB >= Mmax:
        break
      if A > nowB+1:
        empty += (min(A,Mmax+1) -nowB -1)
      nowB = B
  print(Mmax -(Mmin-1))
      
      
      

Measured memory_bytes: 48696
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define re0 return 0
#define pb push_back
const ll mod = 1000000007;
const ll INF = 1e16;

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    sort(rall(a));

    ll A = 0, B = 0;
    for(ll i = 0; i < n; i++) {
        if(i%2 == 0) {
            A += a[i];
        }
        else {
            B += a[i];
        }
    }

    out(A-B);
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int ans = 0;
  int currMin = INF;
  rep(i,n) {
    if (currMin < p[i]) continue;

    currMin = min(currMin, p[i]);
    ans++;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3992
from collections import deque
N, *L = map(int, open(0).read().split())
E = [[] for i in range(N+1)]
for a,b  in zip(*[iter(L)]*2):
  E[a].append(b)
  E[b].append(a)
q = deque([1])
dist = [-1]*(N+1)
dist[1] = 0
dic = [[1],[]]
while q:
  u = q.popleft()
  for v in E[u]:
    if dist[v]==-1:
      dist[v] = dist[u]+1
      q.append(v)
      dic[dist[v]%2].append(v)

a = len(dic[0])
b = len(dic[1])
#print(dic)
seq = set(range(1,N+1))
ver = set(range(1,N+1))
ans = [0]*(N+1)
if a>N//3 and b>N//3:
  for i in range(1,N+1,3):
    v = dic[1].pop()
    ans[v] = i
  q = 0
  for i in range(2,N+1,3):
    v = dic[0].pop()
    ans[v] = i
  m = 3
  while dic[0]:
    v = dic[0].pop()
    ans[v] = m
    m += 3
  while dic[1]:
    v = dic[1].pop()
    ans[v] = m
    m += 3
elif a<=N//3:
  seq = set(range(1,N+1))
  m = 3
  while dic[0]:
    v = dic[0].pop()
    ans[v] = m
    seq.remove(m)
    m += 3
  seq = list(seq)
  while dic[1]:
    v = dic[1].pop()
    ans[v] = seq.pop()
else:
  seq = set(range(1,N+1))
  m = 3
  while dic[1]:
    v = dic[1].pop()
    ans[v] = m
    seq.remove(m)
    m += 3
  seq = list(seq)
  while dic[0]:
    v = dic[0].pop()
    ans[v] = seq.pop()
print(*ans[1:])

Measured memory_bytes: 91760
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		long L = sc.nextLong();

		long bunsi = L * L * L;
		double ans = bunsi / 27.0;

		BigDecimal bd = new BigDecimal(ans);
		System.out.println(bd.setScale(12, RoundingMode.HALF_UP));

	}

}


Measured memory_bytes: 21844
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int W = in.nextInt();
            D.Item[] items = new D.Item[N];
            for (int i = 0; i < N; i++) {
                items[i] = new D.Item(in.nextInt(), in.nextInt());
            }

            long[][] sum = new long[N + 1][W + 1];
            for (int i = 1; i <= N; i++) {
                for (int j = 0; j <= W; j++) {
                    D.Item item = items[i - 1];
                    if (j < item.w) {
                        sum[i][j] = sum[i - 1][j];
                    } else {
                        sum[i][j] = Math.max(sum[i - 1][j - item.w] + item.v, sum[i - 1][j]);
                    }
                }
            }
            out.println(sum[N][W]);
        }

        static class Item {
            int w;
            int v;

            Item(int w, int v) {
                this.w = w;
                this.v = v;
            }

        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

#define pb push_back
#define ff first
#define ss second

const int MAXN = 100 + 21, MAXK = 1e5 + 21, inf = 1e9 + 21;

bool flag;
int n, k;
int mn = inf;
int a[MAXN];
string dp[MAXK];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
	cin >> a[i];
	mn = min(mn, a[i]);
    }
    
    for (int i = 0; i < mn; i++)
	dp[i] = "Second";

    for (int i = mn; i <= k; i++) {
	flag = false;
	for (int j = 0; j < n; j++)
	    if (i - a[j] >= 0) {
		if (dp[i - a[j]] == "Second") {
		    dp[i] = "First";
		    flag = true; 
		    break;
		}
	    }
	if (!flag)
	    dp[i] = "Second";
    }

    cout << dp[k] << '\n';
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#include <iomanip>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif

const int P1 = 876756319, B1 = 991;
const int P2 = 799898821, B2 = 2333;
int n, fac1[N], fac2[N], f1[N], f2[N], vis[N], now[N];
string s[N];
pii f[N];
map<pii,int> mp,mp2;

int main() {
	fac1[0] = fac2[0] = 1;
	for (int i=1; i<N; ++i) {
		fac1[i] = (long long)fac1[i-1]*B1%P1;
		fac2[i] = (long long)fac2[i-1]*B2%P2;
	}
	ios::sync_with_stdio(0);	
	cin>>n;
	REP(i,1,n) { 
		cin>>s[i];
		if (s[i].size()==1) { 
			now[s[i][0]] = 1;
			continue;
		}
		int x = 0, y = 0, sz = s[i].size();
		for (int j=1; j<sz; ++j) {
			x = ((ll)x*B1+s[i][j]-'a'+1)%P1;
			y = ((ll)y*B2+s[i][j]-'a'+1)%P2;
		}
		mp2[{x,y}] ^= 1<<s[i][0]-'a';
		x = (x+(s[i][0]-'a'+1ll)*fac1[sz-1])%P1;
		y = (y+(s[i][0]-'a'+1ll)*fac2[sz-1])%P2;
		++mp[{x,y}];
	}
	ll ans = 0;
	REP(i,1,n) if (s[i].size()>1) {
		int x = 0, y = 0, sz = s[i].size();
		for (int j=sz-1; j>=0; --j) {
			x = (x+(s[i][j]-'a'+1ll)*fac1[sz-j-1])%P1;
			y = (y+(s[i][j]-'a'+1ll)*fac2[sz-j-1])%P2;
			f[j] = {x,y};
		}
		REP(i,'a','z') vis[i] = 0;
		int sta = 0;
		for (int j=0; j<sz; ++j) {
			if (j>=2) {
				int w = sta&mp2[f[j]];
				if (w>>s[i][j-1]-'a'&1) w ^= 1<<s[i][j-1]-'a';
				ans += __builtin_popcount(w);
			}
			if (j) { 
				vis[s[i][j-1]] = 1;
				sta |= 1<<s[i][j-1]-'a';
				if (sz-j>1) ans += mp[f[j]];
			}
		}
		vis[s[i][sz-1]] = 1;
		REP(c,'a','z') if (vis[c]&&now[c]) ++ans;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 174128
#include <cstdio>

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if ((a+b)%3 == 0)
	{
		printf("Possible");
	}
	else if (a%3 == 0)
	{
		printf("Possible");
	}
	else if (b%3 == 0)
	{
		printf("Possible");
	}
	else
	{
		printf("Impossible");
	}
}


Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> g;
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		g.push_back(t);
	}
	sort(g.begin(),g.end());
	cout<<g[g.size()-1]-g[0]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint k, n;
    cin >> k >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    a.push_back(a[0] + k);
    lint ret = inf;
    for (int i = 0; i < n; ++i) {
        chmin(ret, k - (a[i + 1] - a[i]));
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4992
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();


    let mut ans = 0;
    for _ in 0..n {
        let l: u64 = read().unwrap();
        let r: u64 = read().unwrap();
        ans += r - l + 1;
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n,i;cin>>n>>i;
    cout<<n-i+1;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int in;
	int i;
	
	while (scanf("%d", &in) != EOF){
		int flag = 0;
		for (i = 0; i < 10; i++){
			if (in & (1 << i)){
				if (flag) printf(" ");
				printf("%d", 1 << i);
				flag = 1;
			}
		}
		puts("");
	}
	
	return (0);
}

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

int main() {
	int64_t N,K,R,S,P;
	string T;
	cin >>N>>K>>R>>S>>P>>T;
	char k;
	vector<char> taka(N);
	map<char,int64_t> te;
	te['p']=P;
	te['s']=S;
	te['r']=R;
	te['z']=0;
	
	for(int64_t i=0;i<N;i++){
		k=T.at(i);
		// cout<<k<<endl;
		if(k=='r')taka[i]='p';
		else if(k=='s')taka[i]='r';
		else if(k=='p')taka[i]='s';
		// cout<<taka[i]<<endl;
	}

	for(int64_t i=K;i<N;i++){
		if(taka.at(i)==taka.at(i-K)){
			taka.at(i)='z';
		}
		// cout<<taka.at(i)<<endl;
	}
	int64_t ans=0;
	for(int64_t i=0;i<N;i++){
		// cout<<taka.at(i)<<endl;
		ans+=te[taka.at(i)];
	}
	cout<<ans<<endl;
}

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

typedef long long ll;
using namespace std;

int main(void) {
  ll N;
  cin >> N;
  vector<ll> dp[2] = {vector<ll>(N), vector<ll>(N)};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> dp[i][j];
    }
  }
  for (int i = 1; i < N; i++) {
    dp[0][i] += dp[0][i - 1];
  }
  dp[1][0] += dp[0][0];
  for (int i = 1; i < N; i++) {
    dp[1][i] += max(dp[1][i - 1], dp[0][i]);
  }
  cout << dp[1][N - 1] << endl;
}

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

int main()
{
  int n;
  cin >> n;
  vector<string> vec(n);
  for(int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  vector<int> cnt(n);
  int pla = 0;
  int dif = 1;
  int maxs = 0;
  while(pla + dif < n) {
    if(vec.at(pla) == vec.at(pla + dif)) {
      cnt.at(pla)++;
      dif++;
      maxs = max(maxs, cnt.at(pla));
    }
    else {
      pla = pla + dif;
      dif = 1;
    }
  }
  for(int i = 0; i < n; i++) {
    if(cnt.at(i) == maxs) {
      cout << vec.at(i) << endl;
    }
  }
    
  
  return 0;
}

Measured memory_bytes: 15104
package main

import (
	"fmt"
)

func main() {
	var n int
	var lastW string
	ok := true
	set := make(map[string]bool)
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var w string
		fmt.Scanf("%s", &w)
		if i > 0 {
			if _, exists := set[w]; exists || w[0] != lastW[len(lastW)-1] {
				ok = false
				break
			}
		}
		set[w] = true
		lastW = w
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextInt();
    long k = sc.nextInt();
    //long sum = (n*(n+1))/2;
    //System.out.println(sum);
    long ans =0;
    for(long i=k;i<=n+1;i++){
      long max = (n*(n+1))/2 - ((n-i)*(n-i+1))/2;
      long min = (i*(i-1))/2;
      long value = max-min+1;
      ans = ans+value%1000000007;
    }
    ans = ans%1000000007;
    System.out.println(ans);
  }
}

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

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





Measured memory_bytes: 256