akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int BASE = 4200;
const int MOD = 1e9 + 9;
const int MOD2 = 1e9 + 7;
int pot[26], pot2[26];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    pot[0] = pot2[0] = 1;
    fori(i, 1, 26) {
        pot[i] = (1LL * pot[i - 1] * BASE) % MOD;
        pot2[i] = (1LL * pot2[i - 1] * BASE) % MOD2;
    }
    string a, b;
    cin >> a >> b;
    vector<ii> all;
    fori(i, 0, a.size()) {
        int h = 0, h2 = 0;
        fori(j, i, a.size()) {
            h = (h + pot[a[j] - 'a']) % MOD;
            h2 = (h2 + pot2[a[j] - 'a']) % MOD2;
            all.emplace_back(h, h2);
        }
    }
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    int ans = 0;
    fori(i, 0, b.size()) {
        int h = 0, h2 = 0;
        fori(j, i, b.size()) {
            h = (h + pot[b[j] - 'a']) % MOD;
            h2 = (h2 + pot2[b[j] - 'a']) % MOD2;
            auto it = lower_bound(all.begin(), all.end(), ii(h, h2));
            if(it != all.end() && *it == ii(h, h2)) {
                ans = max(ans, j - i + 1);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 68556
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  int N, M;
  cin >> N >> M;
  
  vi X(M);
  for(int i = 0; i < M; i++){
    cin >> X.at(i);
  }
  sort(ALL(X));

  if(N >= M){
    cout << 0 << endl;
    return 0;
  }

  vi l(M-1);
  for(int i = 0; i < M-1; i++){
    l.at(i) = X.at(i+1) - X.at(i);
  }
  sort(ALL(l));
  int result = 0;
  for(int i = 0; i < M - 1 - (N - 1); i++){
    result += l.at(i);
  }
  cout << result << endl;
}

Measured memory_bytes: 1024
program grid_compression
  implicit none
  integer :: h, w, a(100,100) = 0, i, j, m = 0, x(100) = 0
  character(100) :: s
  read(*,*) h, w
  do i = 1, h
    read(*,*) s
    do j = 1, w
      if (s(j:j) == '#') a(i,j) = 1
    end do
  end do
  do j = 1, w
    if (all(a(1:h,j) == 0)) cycle
    m = m+1
    x(m) = j
  end do
  do i = 1, h
    if (all(a(i,1:w) == 0)) cycle
    do j = 1, m
      write(*,'(a)',advance='no') merge('#','.',a(i,x(j)) == 1)
    end do
    write(*,*)
  end do
end program grid_compression

Measured memory_bytes: 256
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	int n;
	cin >> n;
	map<string, vector<pair<int, int>>> scores;
	for(int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		int p;
		cin >> p;
		scores[s].eb(p, i + 1);
	}
	for(auto &score : scores)
	{
		RSRT(score.ss);
		for(auto &single : score.ss) cout << single.ss << '\n';
	}
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,w,dx[4]={0,0,-1,+1},dy[4]={-1,1,0,0};
	char ch[20][20];
	cin>>h>>w;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>ch[i][j];
		}
	}
	ll ans=0;
	for(ll i=0;i<h;i++){
		ll r[20][20];
		queue<pair<ll,ll>>q;
		for(ll j=0;j<w;j++){
			if(ch[i][j]=='#'){
				continue;
			}
		for(ll j=0;j<h;j++){
			for(ll k=0;k<w;k++){
				r[j][k]=-1;
			}
		}			
			r[i][j]=0;
			q.push(make_pair(i,j));
			while(q.size()!=0){
				pair<ll,ll>now=q.front();
				q.pop();
				for(ll i=0;i<4;i++){
					ll nexh=now.first+dx[i];
					ll nexw=now.second+dy[i];
					if(nexh<0||nexh>=h||nexw<0||nexw>=w){
						continue;
					}
					if(ch[nexh][nexw]=='#'){
						continue;
					}
					if(r[nexh][nexw]>=0){
						continue;
					}
					r[nexh][nexw]=r[now.first][now.second]+1;
					q.push(make_pair(nexh,nexw));
				}
			}
			for(ll k=0;k<h;k++){
				for(ll l=0;l<w;l++){
					if(r[k][l]==-1){
						continue;
					}
					ans=max(r[k][l],ans);
				}
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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


//      DEEP


using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fwd(i,a,n) for(int i=a;i<=n;i++)
#define bak(i,a,n) for(int i=a;i>=n;i--)
#define all(v) v.begin(),v.end()
#define pb push_back
#define lop '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll mod1=998244353;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ull gcd(ull x,ull y){
   if(y==0)return x;
   return gcd(y,x%y);
}
//                                         EXTENDED_EUCLID
vector<ll>extended_Euclid(ll a,ll b){
    vector<ll>v(3);
    if(b==0){
        v[0]=a;v[1]=1;v[2]=0;
        return v;
    }
    else{
         vector<ll>v1 = extended_Euclid(b,a%b);    //recursive call
         v[0]=v1[0];
         v[1]=v1[2];
         v[2]=v1[1]-(a/b)*v1[2];
         return v;
    }
}
                                          // DFS ( number of connected components  )
//vector<vector<ll> >adj(200001);
//bool visited[200001];
/*ll dfs(int x,int c){                         // x - > node      c - > number of edges in the component
    if(visited[x])return c;
    else{
        visited[x]=true;
        int y=c;
        for(int i=0;i<adj[x].size();i++){
            if(!visited[adj[x][i]]){
                c+=1;
                int d=dfs(adj[x][i],y);
                c+=d;
            }
        }
        return c;
    }
}
*/
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/
                               // Binary Search
/*
ll bin_search(ll y){
  while(lo<hi){
    x=lo+(hi-lo)/2;
    if(condition){
            .....
    }
    else{
                  // increase lo or decrease hi suitably
            }
   }
}
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        int n;
        cin>>n;
        cout<<n*n*n<<endl;
    }
    
}
/* Be careful about integer ranges;
   Check the corner cases before submitting.
*/





Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int S;cin>>S;
  int a=S/100,b=S%100;
  if(1<=a && a<=12 && 1<=b && b<=12)cout<<"AMBIGUOUS"<<endl;
  else if(1<=a && a<=12 && 0<=b && b<=99)cout<<"MMYY"<<endl;
  else if(0<=a && a<=99 && 1<=b && b<=12)cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = list(input())

if len(s) % 2 == 1:
    print("No")
    exit()
for i in range(0, len(s) - 1, 2):
    #print(i)
    if not(s[i] == 'h' and s[i + 1] == 'i'):
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 2940
from heapq import heappush, heappop, heapify
import math

N, M = map(int, input().strip().split())
A = list(map(int, input().strip().split()))
A = [-x for x in A]
A.sort()
for i in range(M):
  heappush(A, math.ceil(heappop(A)/2))

print(-sum(A))


Measured memory_bytes: 14532
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            double[] line = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
            double T = line[0];
            double X = line[1];
            Console.WriteLine(T / X);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];
    
    vint sum(N+1);
    REP(i,N) sum[i+1]=sum[i]+a[i];

    int ans=1e18;
    for(int i=1;i<=N-1;i++){
        int score=abs(2*sum[i]-sum[N]);
        ans=min(ans,score);
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 3328
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
    int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     string s1,s2;
     cin>>s1>>s2;k=0;j=0;
     for(i=0;i<s1.size()+s2.size();i++){
         if(k<s1.size()){cout<<s1[k++];}
         if(j<s2.size()){
            cout<<s2[j++];i++;
         }
     }
     return EXIT_SUCCESS;
}


Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        string s = Console.ReadLine();
        
        string[] oprnd = {"---","--+","-+-","+--","++-","+-+","-++","+++"};
        int[] nums = new int[4];
        for(var n = 0;n < 4;n++){
            nums[n] = int.Parse(s[n].ToString());
        }
        var target = 7 - nums[0];
 
        for(var i = 0;i < 8;i++){
            var ans = $"{nums[0]}";
            var temp = 0;
            for(var j = 0;j < 3;j++){
                if(oprnd[i][j] == '+'){
                    temp += nums[j + 1];
                    ans += $"+{nums[j + 1]}";
                }else{
                    temp -= nums[j + 1];
                    ans += $"-{nums[j + 1]}";
                }
            }
            
            if(temp == target){
                Console.WriteLine(ans + "=7");
                return;
            }
        }
        
        
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
int n,k,temp1,temp2,ans=1;
int main(){
  cin >> n >> k;
  for (size_t i = 0; i < n; i++) {
    temp1 = ans*2;
    temp2 = ans+k;
    if(temp1 <= temp2){
      ans *= 2;
    }else{
      ans += k;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stdlib.h>
using namespace std;
int main() {
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
    while (A > 0 && C > 0) {
        C -= B;
        A -= D;
    }
    if (A <= 0 && C <= 0) {
        printf("%s\n", "Yes");
    } else if (A <= 0) {
        printf("%s\n", "No");
    } else {
        printf("%s\n", "Yes");
    }
}

Measured memory_bytes: 1660
a = int(input())
b = int(input())
c = int(input())
x = int(input())

counter = 0

for i in range(0, a + 1):
	if x - (500 * i) >= 0:
		x_f = x - (500 * i)

		if x_f == 0:
			counter += 1
			break

		for j in range(0, b + 1):
			if x_f - (100 * j) >= 0:
				x_s = x_f - (100 * j)

				if x_s == 0:
					counter += 1
					break

				for k in range(0, c + 1):
					if x_s - (50 * k) >= 0:
						x_t = x_s - (50 * k)

						if x_t == 0:
							counter += 1
							break


print(counter)


Measured memory_bytes: 3188
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs = readLine()!!.split(' ').map { it.toInt() }.sorted().toIntArray()

    var ans = 0

    for (i in 0 until n - 2) {
        val a = xs[i]
        for (j in i + 1 until n - 1) {
            val b = xs[j]
            for (k in j + 1 until n) {
                if (a + b > xs[k]) {
                    ans++
                } else {
                    break
                }
            }
        }
    }

    println(ans)
}


Measured memory_bytes: 48556
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	h, w := scanInt(), scanInt()
	a := make([]string, h)
	for i := 0; i < h; i++ {
		a[i] = scanString()
	}
	for i := 0; i < h; i++ {
		t := false
		for j := 0; j < w; j++ {
			if a[i][j] == '#' {
				t = true
			}
		}
		if t {
			for j := 0; j < w; j++ {
				f := false
				for k := 0; k < h; k++ {
					if a[k][j] == '#' {
						f = true
					}
				}
				if f {
					fmt.Fprint(wr, string(a[i][j]))
				}
			}
			fmt.Fprintln(wr)
		}
	}
}


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

void solve(ll A, ll B){
    if(A > B) swap(A, B);

    if(B==A || B==A+1) cout << 2*A-2 << endl;
    else{
        ll C = floor(sqrt(A*B)) - 1;
        while(true){
            if((C+1)*(C+1)>=A*B) break;
            C++;
        }
        if(C*(C+1) >= A*B) cout << 2*C-2 << endl;
        else cout << 2*C-1 << endl;
    }
}

int main(){
    int Q;  cin >> Q;
    for(int i=0; i<Q; i++){
        ll A,B;  cin >> A >> B;
        solve(A,B);
    }
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)3005;
const int mod = (int)1e9+7;

int n, m, k, r, c, v;
int a[M][M], dp[M][M][4];

int func(int i, int j, int row_cnt = 0)
{
	if(i == n && j == m && row_cnt < 3) return a[i][j];
	else if(i == n && j == m) return 0;
	if(dp[i][j][row_cnt] != -1) return dp[i][j][row_cnt];
	int x = 0, y = 0, p = 0, q = 0;
	if(row_cnt < 3 && i < n) x = func(i+1, j, 0) + a[i][j];
	if(row_cnt < 3 && j < m) y = func(i, j+1, row_cnt+1) + a[i][j];
	if(i < n) p = func(i+1, j, 0);
	if(j < m) q = func(i, j+1, row_cnt);
	return dp[i][j][row_cnt] = max({x, y, p, q});
}

void solve()
{
	memset(a, 0, sizeof a);
	memset(dp, -1, sizeof dp);
    cin>>n>>m>>k;
    f(i, 0, k)
    {
    	cin>>r>>c>>v;
    	a[r][c] = v;
    }
    cout<<func(1, 1)<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 357112
import sys
import random


sys.setrecursionlimit(10 ** 5 + 5)
random.seed = 1

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


a = None


def dfs(root, parent):
    res = 0
    for i in a[root]:
        if i != parent:
            res ^= 1 + dfs(i, root)
    return res


def read_tree(check=False):

    if check:
        n, p = gen()
    else:
        n = read_int()
        p = [read_int_list() for i in range(n - 1)]

    global a
    a = [[] for _ in range(n)]
    for x, y in p:
        x -= 1
        y -= 1
        a[x].append(y)
        a[y].append(x)


def gen():
    n = random.randint(5, 30)

    inside = [1]
    outside = list(range(2, n + 1))
    p = []
    for i in range(n - 1):
        x = random.choice(inside)
        y = random.choice(outside)
        p.append([x, y])
        outside.remove(y)
        inside.append(y)
    return n, p


def solve():
    read_tree(check=False)
    return ['Bob', 'Alice'][dfs(0, -1) > 0]


def check():
    for i in range(1000):
        res = solve()
        print(i, res)


def main():
    # check()
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 116200
#include<iostream>
#include<set>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	set<int> cpp;
	int m, n, i, o;

	cin >> n;
	r(i, n)
	{
		cin >> o;
		cpp.insert(o);
	}

	cin >> m;
	r(i, m)
	{
		cin >> o;
		if (!cpp.count(o)) continue;
		else  cout << o << endl;
	}

	return 0;
}


Measured memory_bytes: 12456
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>

using namespace std;

int bitCount(int i){
  int ret = 0;
  while(i != 0){
    if(i%2==1){
      ret++;
    }
    i/=2;
  }
  return ret;
}

int main(int argc, const char * argv[]) {
  long n;
  cin >> n;
  vector<vector<int>> f(n,vector<int>(10,0));
  vector<int> fb(n,0);
  vector<vector<int>> p(n,vector<int>(11,0));
  int tmp;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cin >> tmp;
      fb[i] += pow(2,9-j) * tmp;
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= 10; j++){
      cin >> p[i][j];
    }
  }
  long long m = -99999999999;
  for(int i = 1; i < (1<<10); i++){
    long long sum = 0;
    for(int j = 0; j < n; j++){
      sum += p[j][bitCount(i & fb[j])];;
    }
    m = max(m,sum);
  }

  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int A[MAXN],B[MAXN],C[MAXN];
int64 sum[MAXN];
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(A[i]);
    for(int i = 1 ; i <= N ; ++i) read(B[i]);
    for(int i = 1 ; i <= N ; ++i) read(C[i]);
    sort(A + 1,A + N + 1);sort(B + 1,B + N + 1);sort(C + 1,C + N + 1);
    for(int i = 1 ; i <= N ; ++i) {
	sum[i] = lower_bound(A + 1, A + N + 1, B[i]) - A - 1;
	sum[i] += sum[i - 1];
    }
    int64 ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
	ans += sum[lower_bound(B + 1,B + N + 1,C[i]) - B - 1];
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#define N 3001
using namespace std;

int ans = 0;
void dfs(int sum, int r, int g, int b, int n) {
    // r < g < b
    if (sum > n) return;
    if ((n - sum) % b == 0) ans++;
    if (sum + r <= n) dfs(sum+r, r, g, b, n);
    if (sum + g <= n) dfs(sum+g, N, g, b, n);
}

int main ( void ) {
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    dfs(0, r, g, b, n);

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



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind
{
    vector<ll> par;
    vector<ll> rank;
    vector<ll> sz;
    UnionFind(ll n) : par(n), rank(n), sz(n)
    {
        for(ll i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    ll root(ll x)
    {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
    void unite(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y])
        {
            par[x] = y;
            sz[y] += sz[x];
        }
        else
        {
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(ll x, ll y)
    {
        return root(x) == root(y);
    }
    ll size(ll x)
    {
        x = root(x);
        return sz[x];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind tree(n);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        tree.unite(a, b);
    }
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        ans = max(ans, tree.size(i));
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

ll func(vector<ll> &v, ll x) {
    vector<ll>::iterator ite;
    ll ans = 0;
    ite = lower_bound(v.begin(), v.end(), x);

    //寺の場所が全て神社の場所未満の時
    if (ite == v.end()) {
        ll z = *(ite-1);
        ans += x-z;
    }
    //寺の場所が全て神社の場所以上の時
    else if (ite == v.begin()) {
        ll z = *ite;
        ans += z-x;
    }
    //それ以外
    else {
        ll z = *ite, w = *(ite-1);
        ans += min(z-x, x-w);
    }
    return ans;
}

int main() {
    int A, B, Q;   cin >> A >> B >> Q;
    vector<ll> temple(B), shrine(A), ans(Q);
    for (int i = 0; i < A; i++)
        cin >> shrine[i];
    for (int i = 0; i < B; i++)
        cin >> temple[i];

    sort(shrine.begin(), shrine.end());
    sort(temple.begin(), temple.end());

    for (int i = 0; i < Q; i++) {
        ll x;   cin >> x;
        //shrine から
        vector<ll>::iterator ite = lower_bound(shrine.begin(), shrine.end(), x);    //x以上の神社の場所
        //神社の場所が全てx未満の時
        if (ite == shrine.end()) {
            ite--;
            ll y = *ite;
            ans[i] = x-y;
            ans[i] += func(temple, y);
        }
        //神社の場所が全てx以上の時
        else if (ite == shrine.begin()) {
            ll y = *ite;
            ans[i] = y-x;
            ans[i] += func(temple, y);
        }
        //それ以外
        else {
            ll y = *ite;
            ite--;
            ll z = *ite;
            ans[i] = min(y-x + func(temple, y), x-z + func(temple, z));
        }
        
        ite = lower_bound(temple.begin(), temple.end(), x);
        if (ite == temple.end()) {
            ite--;
            ll y = *ite;
            ans[i] = min(x-y + func(shrine, y), ans[i]);
        }
        else if (ite == temple.begin()) {
            ll y = *ite;
            ans[i] = min(y-x + func(shrine, y), ans[i]);
        }
        else {
            ll y = *ite;
            ite--;
            ll z = *ite;
            ans[i] = min(ans[i], min(y-x + func(shrine, y), x-z + func(shrine, z)));
        }
    }

    for (int i = 0; i < Q; i++)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 5620
#include <bits/stdc++.h> 
using namespace std;
int N, A[3][3], b[10]; bool appear[3][3];
int main() {
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) cin >> A[i][j];
	}
cin >> N;
for(int i = 0; i < N; i++) cin >> b[i]; 
  for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
  appear[i][j] = false;
for(int k = 0; k < N; k++) {
if(A[i][j] == b[k]) appear[i][j] = true; 
			}
		} 
	}
string ANS = "No";
for(int i = 0; i < 3; i++) {
if(appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes"; }
for(int i = 0; i < 3; i++) {
if(appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
}
if(appear[0][0] and appear[1][1] and appear[2][2]) ANS = "Yes"; if(appear[0][2] and appear[1][1] and appear[2][0]) ANS = "Yes"; cout << ANS << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int n;
void dfs(string res,char mx){
    if(res.size() == n)printf("%s\n",res.c_str());
    else{
    for(char c = 'a';c<=mx;c++){
        dfs(res+ c,c == mx ? (char)(mx+1):mx);
    }
    }

}
int main()
{
    
    cin >>n;
    dfs("",'a');
    return 0;
}

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

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

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int d; cin >> d;
	vi c(26); rep(i, 26) cin >> c[i];
	vector<vi> s(d, vi(26));
	rep(i, d) rep(j, 26) cin >> s[i][j];

	for(auto t : s){
		//cout << (max_element(all(t))-t.begin())+1 << endl;
		cout << 15 << endl;
	}
	return 0;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;

int N,L,Q;
int nx [18] [100000];

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

	cin >> N;
	vector<int> X(N);
	FOR(i,0,N){
		cin >> X [i];
	}
	cin >> L >> Q;

	FOR(i,0,N){
		nx [0] [i] = upper_bound(ALL(X),X [i] + L) - X.begin() - 1;
	}
	FOR(i,1,18){
		FOR(j,0,N){
			nx [i] [j] = nx [i - 1] [nx [i - 1] [j]];
		}
	}

	FOR(i,0,Q){
		int A,B;
		cin >> A >> B;
		A--,B--;
		if(A > B) swap(A,B);
		int ans = 0,cur = A;
		for(int i = 17;i >= 0;i--){
			if(nx [i] [cur] < B){
				cur = nx [i] [cur];
				ans += 1 << i;
			}
		}
		if(cur < B) ans++;
		cout << ans << endl;
	}

	return 0;
}


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

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

const int MAXN = 2000;

int n, k, deg[MAXN+10], ans;
vector<int> adj[MAXN+10];

int cnt, chd, add;
void dfs(int now, int par, int dep)
{
    cnt++;
    if(dep==k/2)
    {
        chd+=deg[now]-1;
        return;
    }
    for(int nxt : adj[now])
    {
        if(nxt==par) continue;
        dfs(nxt, now, dep+1);
    }
}

int main()
{
    int i, j;

    scanf("%d%d", &n, &k);
    if(k==1) return !printf("%d", n-2);
    for(i=1; i<n; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v); deg[u]++;
        adj[v].push_back(u); deg[v]++;
    }

    for(i=1; i<=n; i++)
    {
        cnt=1, add=0;
        for(int nxt : adj[i])
        {
            chd=0;
            dfs(nxt, i, 1);
            add=max(add, chd);
        }
        if(k%2) cnt+=add;
        ans=max(ans, cnt);
    }
    printf("%d", n-ans);
}


Measured memory_bytes: 384
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int count = 0;
        int n = S.length();

        for (int i = 0; i < n/ 2; i++) {
            if (S.charAt(i) != S.charAt(n - i - 1)) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

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

  vector<int> v(n);
  rep(i, n) cin >> v[i];

  vector<int> o(1e+5 + 1, 0);
  vector<int> e(1e+5 + 1, 0);

  rep(i, n) {
    if (i % 2 == 0) {
      o[v[i]]++;
    } else {
      e[v[i]]++;
    }
  }

  int omaxnum;
  int omaxcnt = 0;
  int onmaxnum = 0;
  int onmaxcnt = 0;
  rep(i, 1e+5 + 1) {
    if (omaxcnt < o[i]) {
      onmaxnum = omaxnum;
      onmaxcnt = omaxcnt;
      omaxnum = i;
      omaxcnt = o[i];
    } else if (onmaxcnt < o[i]) {
      onmaxnum = i;
      onmaxcnt = o[i];
    }
  }

  int emaxnum;
  int emaxcnt = 0;
  int enmaxnum = 0;
  int enmaxcnt = 0;
  rep(i, 1e+5 + 1) {
    if (emaxcnt < e[i]) {
      enmaxnum = emaxnum;
      enmaxcnt = emaxcnt;
      emaxnum = i;
      emaxcnt = e[i];
    } else if (enmaxcnt < e[i]) {
      enmaxnum = i;
      enmaxcnt = e[i];
    }
  }

  int ans;
  if (omaxnum != emaxnum) {
    ans = n - omaxcnt - emaxcnt;
  } else {
    int cand1 = n - omaxcnt - enmaxcnt;
    int cand2 = n - emaxcnt - onmaxcnt;
    ans = min(cand1, cand2);
  }

  cout << ans << endl;
}

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

typedef int64_t s64;

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::vector<std::pair<int,int> > a;
	int max = 0;
	int min = 1000000001;
	for (int i = 0; i < n; i++) {
		int x = ri();
		int y = ri();
		if (x > y) std::swap(x, y);
		a.push_back({x,y});
		max = std::max(max, y);
		min = std::min(min, x);
	}
	std::sort(a.begin(), a.end());
	if (n == 1) {
		std::cout << 0 << std::endl;
		return 0;
	}
	
	s64 res;
	// min != max => min to one, max to the other
	{
		int min_max = 0;
		int max_min = 1000000001;
		for (int i = 0; i < n; i++) {
			min_max = std::max(min_max, a[i].first);
			max_min = std::min(max_min, a[i].second);
		}
		res = (min_max - min) * (s64)(max - max_min);
	}
	
	// min == max => except a[0], 
	using T = std::pair<int, int>;
	std::set<T> que;
	std::multiset<int, std::greater<int> > cur;
	// use a[0].second
	
	for (int i = 1; i < n; i++) {
		que.insert({a[i].first, i});
		cur.insert(a[i].first);
	}
	int sub_res = std::max(a[0].second, *cur.begin()) - std::min(a[0].second, *std::prev(cur.end()));
	while (que.size()) {
		T top = *que.begin(); que.erase(que.begin());
		cur.erase(cur.find(top.first));
		cur.insert(a[top.second].second);
		sub_res = std::min(sub_res, std::max(a[0].second, *cur.begin()) - std::min(a[0].second, *std::prev(cur.end())));
	}
	res = std::min(res, (max - min) * (s64)sub_res);
	std::cout << res << std::endl;
	
	
	return 0;
}


Measured memory_bytes: 21104
#include <bits/stdc++.h>
#define MOD 998244353
typedef long long ll;
using namespace std;
struct mint {
	ll x;
	mint(ll x = 0)
		: x((x % MOD + MOD) % MOD) {
	}
	mint operator-() {
		return mint(-x);
	}
	mint operator+=(mint rhs) {
		x += rhs.x;
		if (x >= MOD) x -= MOD;
		return *this;
	}
	mint operator-=(mint rhs) {
		x -= rhs.x;
		if (x < 0) x += MOD;
		return *this;
	}
	mint operator*=(mint rhs) {
		x = x * rhs.x % MOD;
		return *this;
	}
	mint operator+(mint rhs) {
		return mint(*this) += rhs;
	}
	mint operator-(mint rhs) {
		return mint(*this) -= rhs;
	}
	mint operator*(mint rhs) {
		return mint(*this) *= rhs;
	}
};
// ostream &operator<<(ostream &os, const mint &dt) {
// 	os << dt.x;
// 	return os;
// }
int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l(k), r(k);
	for (int i = 0; i < k; i++) {
		cin >> l[i] >> r[i];
	}
	vector<mint> dp(n + 10, 0);
	vector<mint> sum(n + 10, 0);
	dp[0] = 1;
	mint p = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k; j++) {
			if (i + l[j] <= n + 1)
				sum[i + l[j]] += dp[i];
			if (i + r[j] + 1 <= n + 1)
				sum[i + r[j] + 1] -= dp[i];
		}
		p += sum[i + 1];
		dp[i + 1] = p;
		// cout << "p:" << p << endl;
		// cout << "sum:";
		// for (int ii = 0; ii <= n; ii++) {
		// 	cout << sum[ii];
		// 	if (ii == n)
		// 		cout << endl;
		// 	else
		// 		cout << " ";
		// }
		// cout << "dp:";
		// for (int ii = 0; ii <= n; ii++) {
		// 	cout << dp[ii];
		// 	if (ii == n)
		// 		cout << endl;
		// 	else
		// 		cout << " ";
		// }
	}
	// for (int i = 0; i <= n; i++) {
	// 	cout << dp[i];
	// 	if (i == n)
	// 		cout << endl;
	// 	else
	// 		cout << " ";
	// }
	cout << dp[n - 1].x << endl;
	return 0;
}

Measured memory_bytes: 6408
#include<cstdio>
#include<cmath>
double keta(double x){
    if(x>=100) return 3;
    else if(x>=10) return 2;
    else return 1;
}
int main(){
    double a, b;
    scanf("%lf%lf", &a, &b);
    double k = keta(b);
    double c = pow(10, k);
    double d = c*a+b;
    double e = sqrt(d);
    if(ceil(e) == floor(e)) puts("Yes");
    else puts("No");
    return 0;

}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
	long long a, b, m, n, r;
	while(cin >> a >> b){
		if(a > b){
			m = a;
			n = b;
				while((r = m % n) != 0){
					m = n;
					n = r;
				}
			cout << n << " " << (a * b)/ n << endl;
		}
		else if(a < b){
			m = b;
			n = a;
				while((r = m % n) != 0){
					m = n;
					n = r;
				}
			cout << n << " " << (a * b)/ n << endl;
		}
		else if(a = b){
			cout << a << " " << a << endl;
		}
	}
	return(0);
}

Measured memory_bytes: 1160
n,m,p=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=[0]*(n+1) ; b=[0]*(m+1)
for i in range(n):
    a[i+1]+=a[i]+A[i]
for j in range(m):
    b[j+1]=b[j]+B[j]
    

now=-1
import bisect as bi
for i in range(n+1):
    if a[i]>p : break
    G=p-a[i]   
    now=max(bi.bisect(b, G)+i-1, now)

print(now)


Measured memory_bytes: 48576
N = int(input())
A = list(map(int, input().split()))
kabu = 0
total = 1000

A1 = []
for i in range(1, N):
    a = A[i] - A[i-1]
    A1.append(a)
A1.append(A1[N-2])

for i in range(N):
    if A1[i] > 0:
        b = total // A[i]
        total -= A[i] * b
        kabu += b
    elif A1[i] < 0:
        total += kabu * A[i]
        kabu = 0
    else:
        continue
    #print(total, kabu)
total += kabu * A[N-1]
print(total)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
vi mul(const vi &a,const vi &b) {
    int n = a.size();
    vi c(n);
    rep(i,0,n) c[i] = a[b[i]];
    return c;
}
vi inv(const vi &a) {
    int n = a.size();
    vi b(n);
    rep(i,0,n) b[a[i]] = i;
    return b;
}
vi ident(int n) {
    vi a(n);
    rep(i,0,n) a[i] = i;
    return a;
}
vi pow(const vi &a, int k) {
    int n = a.size();
    if(k==0) return ident(n);
    vi half = pow(a,k/2);
    vi result = mul(half,half);
    if(k%2==1) result = mul(result,a);
    return result;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vi p(n), q(n);
    rep(i,0,n) {
        cin >> p[i];
        --p[i];
    }
    rep(i,0,n) {
        cin >> q[i];
        --q[i];
    }
    int sides = (k-1)/6;
    int kk = k-sides*6;
    vector<vi> seq(max(3,kk+1));
    seq[1] = p;
    seq[2] = q;
    rep(i,3,kk+1) seq[i]=mul(seq[i-1],inv(seq[i-2]));
    auto a=p, b=q,c=inv(a),d=inv(q);
    auto left = pow(mul(b,mul(c,mul(d,a))),sides);
    auto right = pow(mul(c,mul(b,mul(a,d))),sides);
    auto result = mul(left,mul(seq[kk],right));
    rep(i,0,n) cout << (result[i]+1) << " ";
    cout << "\n";
}


Measured memory_bytes: 7732
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io
    
    ll n, k;
    cin>>n>>k;
    vector<ll> A(n);
    vector<bool> flag(n, false);
    rep(i,n) {
        cin>>A[i];
        A[i]--;
    }
    ll next=A[0];
    ll cnt=1;
    flag[0]=true;
    //cout<<0<<"=>"<<next<<endl;
    while(flag[next]==false){
        //cout<<next<<"=>";
        flag[next]=true;
        next=A[next];
        //cout<<next<<endl;
        cnt++;
        if(cnt>=k){
            cout<<next+1<<endl;
            return 0;
        }
    }
    //cout<<next<<endl;
    ll e=0;//1ループの移動回数
    
        while(flag[next]){
            flag[next]=false;
            next=A[next];
            e++;
        }
        //cout<<"e="<<e<<endl;
        ll diff=cnt-e;
        k-=diff;
        k%=e;
        for(int i=0;i<k;i++){
            next=A[next];
        }
        cout<<next+1<<endl;
        return 0;
    
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define ll long long
#define viit(a) vector<int>::iterator a
#define IT iterater
#define REP(i,a,n) for(ll i=a;i<(n);i++)
#define FOR(i,a,n) for(ll i=a;i<=(n);i++)
#define V vector
#define RE return
#define B(s) s.back()
#define all(a) a.begin(),a.end()
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define Fill(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define pb push_back
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    ll n,sum[200001]={0},h;
    cin>>n;
    REP(i,1,n){
    	cin>>h;
    	sum[h]++;
	}
	REP(i,1,n+1){
		cout<<sum[i];
		cout<<endl;
	}
    RE 0;
}


Measured memory_bytes: 5220
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

ll id2x[60];
ll id2y[60];

struct P {
  ll x, y;
};

P ps[60];
int cs[60][60];

int main(void) {
  int n, k;
  scanf("%d%d", &n, &k);
  REP(i, n) {
    scanf("%lld%lld", &ps[i].x, &ps[i].y);
    id2x[i] = ps[i].x;
    id2y[i] = ps[i].y;
  }
  id2x[n+1] = 1000000000 + 1;
  id2y[n+1] = 1000000000 + 1;
  sort(id2x, id2x + n+1);
  sort(id2y, id2y + n+1);
  REP(ix, n+1) {
    REP(iy, n+1) {
      ll x = id2x[ix];
      ll y = id2y[iy];
      int cnt = 0;
      REP(i, n) {
        if(ps[i].x <= x && ps[i].y <= y) {
          ++cnt;
        }
      }
      cs[ix+1][iy+1] = cnt;
    }
  }
  ll res = 4e18;
  REP(ix2, n+1) {
    REP(ix1, ix2) {
      REP(iy2, n+1) {
        REP(iy1, iy2) {
          int cnt = cs[ix2+1][iy2+1] - cs[ix2+1][iy1] - cs[ix1][iy2+1] + cs[ix1][iy1];
          // cerr << cnt << " " << endl;
          if(cnt == k) {
            ll area = (id2x[ix2] - id2x[ix1]) * (id2y[iy2] - id2y[iy1]);
            if(area < res) {
              res = area;
            }
          }
        }
      }
    }
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 256
from collections import deque


def main():
    input()  # n
    array = [int(x) for x in input().split()]
    array.sort()
    coming = deque(array)

    edges = deque()
    noob = coming.pop()
    edges.append(noob)
    ans = 0
    while coming:
        ans += edges.popleft()
        noob = coming.pop()
        edges.append(noob)
        edges.append(noob)
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int N,M;
  cin>>M>>N;
  vector<int> a(2*N);
  for(int i=0;i<2*N;i++) {
    cin>>a.at(i);
  }
  for(int i=1;i<M+1;i++) {
    int s=0;
    for(int j=0;j<2*N;j++) {
      if(a.at(j)==i)
        s++;
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 3564
import math
X, Y = map(int, input().split())
p = (((X+Y)/3)+Y-X)/2
m = p+X-Y


def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


if p % 1 != 0 or p<0 or m<0:
    ans = 0

else:
    q = p+m
    q = int(q)
    p = int(p)
    ans = comb(q,p,10**9+7)
  

print(ans)

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

// 同じ文字を圧縮する
// O(N)
vector<int> run_length(string &s) {
    vector<int> ans(1, 1);
    for (int i = 1; i < s.size(); i++) {
        if (s[i - 1] == s[i])
            ans[ans.size() - 1]++;
        else
            ans.emplace_back(1);
    }
    return ans;
}

int main() {
    string S;
    ll K;
    cin >> S >> K;

    auto run = run_length(S);
    ll ans   = 0;
    // 全部同じ文字のとき
    if (run.size() == 1) {
        ans = ((ll)run[0]) * K / 2;
        cout << ans << endl;
        exit(0);
    }

    for (auto &&i : run) {
        ans += i / 2;
    }
    ans *= K;
    // 両端が同じ文字のとき
    if (S[0] == S[S.size() - 1]) {
        ll cnt = run[0] + run[run.size() - 1];
        if (cnt % 2 == 0) {
            ans += K - 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int a,b,c; cin >>a >>b >>c;
  set<int> s;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  if (s.size() == 2) cout <<"Yes" <<endl;
  else cout <<"No" <<endl;
}

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

vector<int> z_algorithm(const vector<int>& S){
    int N = S.size(), c = 0;
    vector<int> ret(N, 0);
    for(int i=1; i<N; i++){
        if(i + ret[i-c] < c + ret[c]){
            ret[i] = ret[i-c];
        }else{
            int j = max(0, c + ret[c] - i);
            while(i+j < N && S[j] == S[i+j]) j++;
            ret[i] = j;
            c = i;
        }
    }
    ret[0] = N;
    return ret;
}

vector<int> z_algorithm(const string& S){
    int N = S.size();
    vector<int> s(N);
    for(int i=0; i<N; i++) s[i] = S[i];
    return z_algorithm(s);
}

vector<int> z_algorithm(string& A, string& B){
    string S = A + '!' + B;
    auto z = z_algorithm(S);
    vector<int> ret(B.size());
    for(int i=0; i<(int)B.size(); i++){
        ret[i] = z[i+A.size()+1];
    }
    return ret;
}

int main(){
    string s, T;
    cin >> s >> T;
    string S;
    while(S.size() < T.size()) for(char c : s) S.push_back(c);
    int N = S.size(), M = T.size();
    S += S;
    auto z = z_algorithm(T, S);
    vector<int> len(N, -1);
    for(int s=0; s<N; s++){
        if(len[s] >= 0) continue;
        int pt = s, l = 0;
        while(z[pt] == M){
            l++;
            pt = (pt+M) % N;
            if(pt == s){
                cout << -1 << endl;
                return 0;
            }
            if(len[pt] >= 0){
                l += len[pt];
                break;
            }
            len[pt] = 0;
        }
        len[s] = l;
    }
    cout << *max_element(len.begin(), len.end()) << endl;
}


Measured memory_bytes: 25656
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <limits.h>
int a[10001];
int min(int a, int b){
	return a < b ? a : b;
}
int max(int a, int b){
	return a > b ? a : b;
}
int main(void) {
	int n,i;
	int MIN = INT_MAX;
	int MAX = INT_MIN;
	long Sum = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i) scanf("%d", &a[i]);
	for (i = 0; i < n; ++i){
		Sum += a[i];
		MIN = min(MIN, a[i]);
		MAX = max(MAX, a[i]);
	}
	printf("%d %d %ld\n", MIN, MAX, Sum);
	return 0;
}

Measured memory_bytes: 636
def calc(S):
    N = len(S)
    result = 1
    temp = S[0]
    T = ''
    i = 1
    while (i < N):
        T += S[i]
        if (temp != T):
            temp = T
            T = ''
            result += 1
        i += 1
    return result


print(calc(input()))

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

using namespace std;

int main() {
    int N,m;
    cin >> N;
    m = N;
    vector<int> a;
    int Max = 0;
    while(N--){
        int x;
        scanf("%d",&x);
        
        //if(find(a.begin(),a.end(),x) == a.end() || (Max < x)){
            a.push_back(x);
            //Max = max(x,Max);
        //}else{
            //a.erase(find(a.begin(),a.end(),x));
        //}
        
    }
    sort(a.begin(),a.end());
    for(int i=1; i<=99999;i++){
        int l = upper_bound(a.begin(),a.end(),i+1) - lower_bound(a.begin(),a.end(),i-1);
        Max = max(Max,l);
    }
    cout << Max << endl;
    return 0;
}


Measured memory_bytes: 892