akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define N 256

int main(){
	char ch;
	int num[N]={};
	while((ch = getchar()) !=EOF){
		if(ch>=65 && ch<=90){
			ch=ch+32;
			num[ch-97]++;
		}else if(ch>=97 && ch<=122){
			num[ch-97]++;
		}
	}
	for(int i=0; i<26; i++){
		printf("%c : %d\n",i+97,num[i]);
	}
	return 0;
}



Measured memory_bytes: 2704
#include<bits/stdc++.h>
#define assn(n,a,b) assert(n<=b && n>=a)
using namespace std;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,b) for(i=0;i<b;i++)
#define rep1(i,b) for(i=1;i<=b;i++)
#define pdn(n) printf("%d\n",n)
#define sl(n) scanf("%lld",&n)
#define sd(n) scanf("%d",&n)
#define pn printf("\n")
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
#define MOD 1000000007
LL mpow(LL a, LL n)
{LL ret=1;LL b=a;while(n) {if(n&1)
    ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
return (LL)ret;}
#define MAXK 100000
#define MAXN 1000000000
int ar[MAXK];
int get(int n, int k){
    int i=0;
    while(i<k and ar[i]<=n)i++;
    return n-i;
}
typedef unsigned long long int ULL;
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

bool isSafe(int r, int c, vector<vector<int> > arr) {
	int n = arr.size();
	int m = arr[0].size();
	return (r>=0 && r<n && c>=0 && c<m);
}

/////////////////////////////////////////////////////////////
bool diffSign(int a,int b) {
	return ((a>0 && b<0) || (a<0 && b>0));
}  

string func(int n) {
	while(n) {
		if(n%10 == 9) return "Yes";
		n/=10;
	}
	return "No";
}

int main() 
{ 
	int n;
	cin>>n;
	cout<<func(n);
	return 0; 
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10,mod=1e9+7;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
int mul(int a, int b) {
  return (int) ((long long) a * b % mod);
}
int power(int a,int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
int n,u,v,k,fac[maxn],invf[maxn];
vector<int> a[maxn];
int ncr(int N,int R){
    if(R==0||R==N)return 1;
    return mul(fac[N],mul(invf[R],invf[N-R]));
}
int pnr(int N,int R){
    if(R>N){
        printf("0");
        exit(0);
    }
    if(R==N)return fac[N];
    return mul(fac[N],invf[N-R]);
}
int dfs(int nod,int pa,int dep){
    int res=1;
    if((int)a[nod].size()==1&&nod!=1)return 1;
    for(int i:a[nod]){
        if(i!=pa){
            res=mul(res,dfs(i,nod,dep+1));
           // if(nod==1)cout<<res<<' ';
        }
    }
    res=mul(res,dep>0?pnr(k-2,(int)a[nod].size()-1):pnr(k,(int)a[nod].size()+1));
    return res;
}

int main(){
    scanf("%d%d",&n,&k);
    fac[0]=1;
    for(int i=1;i<=100000;i++){
        fac[i]=mul(fac[i-1],i);
    }
    invf[100000]=power(fac[100000],mod-2);
    for(int i=99999;i>=1;i--){
        invf[i]=mul(i+1,invf[i+1]);
    }
    invf[0]=1;
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
    }
    printf("%d\n",dfs(1,0,0));
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int n, m;
vector<int> h, w;
/**********************************************/

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

    while(cin >> n >> m, n != 0 || m != 0){
        h.resize(n);
        w.resize(m);
        REP(i, n) cin >> h[i];
        REP(i, m) cin >> w[i];

        map<int, int> mph, mpw;
        REP(i, n){
            int curh = 0;
            for(int j = i; j < n; j++){
                curh += h[j];
                mph[curh]++;
            }
        }
        
        REP(i, m){
            int curw = 0;
            for(int j = i; j < m; j++){
                curw += w[j];
                mpw[curw]++;
            }
        }
        LL ans = 0;
        for(auto x: mph){
            if(mpw[x.first] != 0) ans += mph[x.first] * mpw[x.first];
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 34316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final String s = scanner.next();
        System.out.println(s.substring(0, 3));
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 32560
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

const p = 1000000007

func Memo(M *[][][][]int, L, R *[]int, k, x, y, b int) int {
  if k < 0 { return 1 }
  if 0 <= (*M)[k][x][y][b] { return (*M)[k][x][y][b] }
  m := 0
  if x | (1 - (*L)[k]) == 1 { m += Memo(M, L, R, k - 1, x, y | (*R)[k], b) }
  if y | (*R)[k] == 1 { m += Memo(M, L, R, k - 1, x | (1 - (*L)[k]), y, 1) }
  if (x | (1 - (*L)[k]) == 1) && (y | (*R)[k] == 1) && (b == 1) { m += Memo(M, L, R, k - 1, x, y, b) }
  m %= p
  (*M)[k][x][y][b] = m
  return m
}

func Solve() {
  var L, R int
  NextInt(&L, &R)
  Lb := make([]int, 60)
  for l, i := L, 0; i < 60; l, i = l / 2, i + 1 {
    Lb[i] = l % 2
  }
  Rb := make([]int, 60)
  for r, i := R, 0; i < 60; r, i = r / 2, i + 1 {
    Rb[i] = r % 2
  }
  M := make([][][][]int, 60)
  for i := range M {
    M[i] = make([][][]int, 2)
    for x := range M[i] {
      M[i][x] = make([][]int, 2)
      for y := range M[i][x] {
        M[i][x][y] = make([]int, 2)
        for b := range M[i][x][y] {
          M[i][x][y][b] = -1
        }
      }
    }
  }
  Write(Memo(&M, &Lb, &Rb, 59, 0, 0, 0))
}

func main() {
  Solve()
  Output()
}

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

int k, s;

int main(){
  cin >> k >> s;
  int res = 0;
  for(int x = 0; x <= k; x++){
    for(int y = 0; y <= k; y++){
      if(x + y + k < s || x + y > s) continue;
      res++;
    }
  }
  cout << res << endl;
  return 0;
}


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

#define TSUBO 3.305785

int main(void) {
	int a, b;
	double S;
	
	cin>> a >> b;
	
	S = a * b;
	
	printf("%.6lf\n", S / TSUBO);
	
	return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

bool dp[5010];

bool check(int c, int K, const vector<int> &a) {
	memset(dp, 0, sizeof(dp));

	dp[0] = true;
	for(int i = 0; i < a.size(); ++i) {
		if(i == c) continue;
		for(int j = K; j >= a[i]; --j) {
			dp[j] |= dp[j - a[i]];
		}
	}

	//cout << a[c] << ":";
	//for(int i = 0; i <= K; ++i) cout << dp[i];
	//cout << endl;
	for(int i = max(K - a[c], 0LL); i < K; ++i) {
		if(dp[i]) return true;
	}
	return false;
}

signed main(){
	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for(int i = 0; i < N; ++i) cin >> a[i];
	sort(ALL(a));
	int l = -1, u = N;
	while(u - l > 1) {
		int c = (l + u) / 2;
		if(check(c, K, a)) {
			u = c;
		} else {
			l = c;
		}
	}
	cout << u << endl;
	return 0;
}


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

int main(){
  int H,W;
  cin>>H>>W;
  long long int q=1000000007;
  long long int dp[H+1][W+1];
  for(int i=0;i<H+1;i++) dp[i][0]=0;
  for(int j=0;j<W+1;j++) dp[0][j]=0;
  dp[0][1]=1;
  for(int i=1;i<H+1;i++){
    string a;
    cin>>a;
    for(int j=1;j<W+1;j++){
      if(a[j-1] == '.'){
        dp[i][j] = (dp[i-1][j]+dp[i][j-1])%q;
      }
      else dp[i][j] = 0;
    }
  }
  cout << dp[H][W] <<endl;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  ll N,M,R;
  cin >> N >> M >>R;
  ll r[R];
  rep(i,R){
    cin >> r[i];
    r[i]--;
  }
    
  sort(r,r+R);
  ll cost[N][N];
  rep(i,N) rep(j,N) cost[i][j]=INT_MAX;
  rep(i,N) cost[i][i]=0;
  ll a,b,c;
  rep(i,M){
    cin >> a >> b >>c;
    a--;b--;
    cost[a][b]=c;
    cost[b][a]=c;
  }
  rep(k,N)rep(i,N)rep(j,N) cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
  
  ll ans=1e17;
  do{
    ll t=0;
    rep1(i,R-1){
      t+=cost[r[i-1]][r[i]];
    }
    ans = min(ans,t);
    //    cout << ans << endl;
  }while(next_permutation(r,r+R));
  
  cout << ans << endl;
  
  
  
  return 0;

}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll a[6],i;

    for(i=1; i<=5; i++){
        cin >> a[i];

        if(a[i]!=i) cout << i << endl;
    }

    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
	map<int,int>m;
	int fg=0;
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		int t;
		cin >> t;
		m[t]++;
		if(m[t]==2){
			fg=1;
		}
	}
	if(fg)
	cout << "NO" << endl;
	else
	cout << "YES" << endl;
	return 0;
} 

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

int main(){
  ll N;
  cin>>N;
  vector<ll> m;
  ll tmp;
  for(ll i=1;i<=sqrt(N);i++){
    if(N%i==0){
      tmp=N/i;
      if(tmp-1>i) m.push_back(tmp);
    }
  }
  ll total=0;
  for(ll i=0;i<m.size();i++){
    total+=(m[i]-1);
  }
  cout<<total<<endl;
  return 0;
}

Measured memory_bytes: 384
#AC x 3
#WA x 1
#TLE x 2
#RE x 0

N = int(input())
C0 = C1 = C2 = C3 = 0
for _ in range(N):
    C = input()
    if C == 'AC':
        C0+=1
    elif C == 'WA':
        C1+=1
    elif C == 'TLE':
        C2+=1
    elif C == 'RE':
        C3+=1
print('AC x', C0)
print('WA x', C1)
print('TLE x', C2)
print('RE x', C3)


Measured memory_bytes: 9128
#累積和の利用！！！！！！！！
from itertools import accumulate
n,k = map(int,input().split())
p = list(map(int,input().split()))

m = [(e + 1) / 2 for e in p]
    
m = [0] + m
m = list(accumulate(m))

ans = []
for i in range(n-k+1):
    ans.append(m[i+k] - m[i])
    
print(max(ans))

Measured memory_bytes: 25508
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));


struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5+5;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("output.txt", "w", stdout);
    ll n; cin >> n;
    string s = "";
    while(n > 0) {
        n--;
        s += 'a' + (n) % 26;
        n /= 26;        
    }
    reverse(all(s));
    cout << s << endl;
    return 0;
}

/*

*/

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	int h[n];
	for(int i=0;i<n;i++) cin >> h[i];

	int cur=0;
	int ans=0;
	while(cur<n){
		while(h[cur]==0 && cur<n) cur++;
		if(cur==n) break;
		for(int i=cur;i<n;i++){
			if(h[i]==0) break;
			h[i]--;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> v = { 1 };
	while (v.back() <= n)
	{
		v.push_back(v.back() * 2);
	}
	if (v.back() > n)
		v.pop_back();
	cout << v.back();
	//system("pause");
	return 0;
}


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

int main()
{
     int h,w;
  cin >> h >> w;
  while(h!=0 && w!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	cout << "#";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
    return 0;
}



Measured memory_bytes: 3084
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <iostream>
#include <iomanip>

using namespace std;

#define N 1000000000000000

int main() {
    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    sort(A, A + 3);

    cout << A[2] - A[1] + A[1] - A[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N; cin >> N;
int A[N];
unsigned long long all=0;
for(int i=1; i<N; i++){ cin >> A[i]; all+=A[i]; } 
cin >> A[0]; all=(all+A[0])/2;
int ans[N];
for(int i=1; i<=N-2; i+=2){ all-=A[i]; }
ans[0]=all;
for(int i=1; i<N; i++){ ans[i]=A[i-1]-ans[i-1]; cout << 2*ans[i] << " "; }
cout << 2*ans[0] << "\n";
}

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N; cin >> N;
    int minabs = (int) pow(10.0, 9.0);
    int A[N];
    rep(i, N){
        int a; cin >> a;
        if(abs(a) < minabs) minabs = abs(a);
        A[i] = a;   
    }
    //全部+にできるか, aを犠牲にするか
    ll kari_ans = 0;
    rep(i, N) kari_ans += abs(A[i]);
    rep(i, N-1){
        if(A[i] < 0){
            A[i] *= -1;
            A[i+1] *= -1;
        }
    }
    if(A[N-1] >= 0) cout << kari_ans << endl;
    else cout << kari_ans - 2*minabs << endl;

    return 0;
}

void solve(){}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

	vector<ll> S(N+1);
	S[0] = 0;
	REP(i, N) S[i+1] = S[i] + A[i];

	ll res = LLONG_MAX/3;
	for(int i=1;i<N-2;i++){
		//printf("i: %d\n", i);

		int l = 0-1;
		int u = (i-1)+1;
		while(u-l>1){
			int m = (l+u)/2;
			if(S[m+1]-S[0]<=S[i+1]-S[m+1]){
				l = m;
			}else{
				u = m;
			}
		}
		int leftj = u-1;
		if (leftj==-1) leftj=0;
		//printf("leftj: %d\n", leftj);
		if(leftj != i-1){
			ll cand1 = abs((S[leftj+1]-S[0]) - (S[i+1]-S[leftj+1]));
			ll cand2 = abs((S[leftj+2]-S[0]) - (S[i+1]-S[leftj+2]));
			if (cand2<cand1) leftj +=1;
		}

		l = (i+1)-1;
		u = (N-2)+1;
		while(u-l>1){
			int m = (l+u)/2;
			if(S[m+1]-S[i+1]<=S[N]-S[m+1]){
				l = m;
			}else{
				u = m;
			}
		}
		int rightj = u-1;
		if(rightj==i) rightj=i+1;
		//printf("rightj: %d\n", rightj);
		if(rightj != N-2){
			ll cand1 = abs((S[rightj+1]-S[i+1]) - (S[N]-S[rightj+1]));
			ll cand2 = abs((S[rightj+2]-S[i+1]) - (S[N]-S[rightj+2]));
			if (cand2<cand1) rightj +=1;
		}

		ll p = S[leftj+1] - S[0];
		ll q = S[i+1] - S[leftj+1];
		ll r = S[rightj+1] - S[i+1];
		ll s = S[N] - S[rightj+1];
		ll mi = min(min(min(p, q), r), s); 
		ll ma = max(max(max(p, q), r), s);
		res = min(res, abs(mi-ma));
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 3328
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, s;

    for(;;){
      n = sc.nextInt();
      s = sc.nextInt();
      if(n == 0 && s == 0)break;
      else if(s > 45)out.println(0);
      else out.println(solve(n, s, 9));
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static int solve(int n, int s, int r){
    if(n == 0 && s == 0)return 1;
    else if(n == 0 || s < 0 || r == -1)return 0;
    else return solve(n, s, r - 1) + solve(n - 1, s - r, r - 1);
  }
}

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

    ll n;
    cin>> n ;

vector<ll > arr (n) ;
for(ll i =0;i < arr.size() ;i++)
    cin>>arr[i] ;

ll ans = 0 ;
    unordered_map<ll ,ll> brr ;
    for( ll i =0;i < n ;i++ )
    {
        ll sear = i- arr[i] ;

if(brr.find(sear)!=brr.end())
    ans+= brr[sear] ;
ll inser = arr[i]+ i ;
if(brr.find(inser)==brr.end())
    brr[inser] = 0 ;

    brr[inser]++ ;

    }

    cout<<ans<<endl ;

}


Measured memory_bytes: 13032
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int n = sc.nextInt();
        int max = -1;
        int maxNum = -1;
        for (int i = 1; i <= n; ++i) {
            int ct = 0;
            int j = i;
            while (j % 2 == 0) {
                ++ct;
                j /= 2;
            }
            if (ct > max) {
                max = ct;
                maxNum = i;
            }
        }
        _out.println(maxNum);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long int ar[n+1],ar1[n];
	for(int i=0;i<n+1;++i)
		cin>>ar[i];
	for(int i=0;i<n;++i)
		cin>>ar1[i];
	long long int sum=0;
	for(int i=0;i<n;++i)
	{
		if(ar[i]<=ar1[i])
		{
			ar1[i]=ar1[i]-ar[i];
			sum+=ar[i];
			ar[i]=0;
		}
		else 
		{
			ar[i]=ar[i]-ar1[i];
			sum+=ar1[i];
			ar1[i]=0;
		}
		if(ar[i+1]<=ar1[i])
		{
			ar1[i]=ar1[i]-ar[i+1];
			sum+=ar[i+1];
			ar[i+1]=0;
		}
		else
		{
			ar[i+1]=ar[i+1]-ar1[i];
			sum+=ar1[i];
			ar1[i]=0;
		}

	}
	cout<<sum;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;
ll gcd(ll x,ll y){
    if(x>y)swap(x,y);
    if(y%x==0)return x;
    else return gcd(y%x,x);
}
bool solve(ll a,ll b,ll c,ll d){
    if(b>d)return false;
    if(a<b)return false;
    if(c+1-b>=b)return true;
    ll ret=gcd(b,d);
    ll u=b-1;
    ll pos=(a-c-1)/ret;
    a-=ret*pos;
    if(c+1<=a&&a<=u)return false;
    return true;
}
int main(){
    int t;
    cin>>t;
    rep(i,t){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        if(solve(a,b,c,d))cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

int linearSearch(int [], int [], int i, int n);


main(){

  int i, c=0, n, q, s, t, S[10001], T[10001];

  scanf("%d", &n);

  for(i=0 ; i<n ; i++){

    scanf("%d", &s);
    S[i] = s;
  }

  scanf("%d", &q);

  for(i=0 ; i<q ; i++){

    scanf("%d", &t);
    T[i] = t;
  }

  for(i=0 ; i<q ; i++){
    c += linearSearch(S,T,i,n);
  }

  printf("%d\n", c);

  return 0;
}


int linearSearch(int S[], int T[], int i, int n)
{
int j = 0;
  S[n] = T[i];

  while(S[j] != S[n]){
    j++;
  }

  if(j == n){
    return 0;
  }
  return 1;
}

Measured memory_bytes: 648
#include <cstdio>
#include <algorithm>

typedef long long int64;

const int MAXN = 200000 + 10;

int n;
int64 m;
int a[MAXN], f[MAXN];

int main() {
	int i;
	int64 l, r, mid;
	int64 t;
	
	scanf("%d %lld", &n, &m);
	for(i=1; i<=n; i++) 
		scanf("%d", &a[i]);
	for(i=1; i<=n; i++)
		scanf("%d", &f[i]);
	
	std::sort(a+1, a+1+n);
	std::sort(f+1, f+1+n);
	std::reverse(f+1, f+1+n);
	l = 0;
	r = 1ll * a[n] * f[1];
	
	while(l ^ r){
		mid = (l+r)>>1;
		
		t = 0;
		for(i=1; i<=n and t<=m; i++)
			if(1ll * a[i] * f[i] > mid) 
				t += a[i] - mid / f[i];
		if(t<=m)
			r=mid;
		else
			l=mid+1;
	}
	printf("%lld\n", l);
	return 0;
}

Measured memory_bytes: 1664
N = int(input())
L = [int(x) for x in input().split()]
L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i] + L[j] > L[k] and L[i] != L[j] and L[j] != L[k]:
                ans += 1
print(ans)


Measured memory_bytes: 9184
# Educational DP Contest D-knapsack

def knapsack(N, W, wv):
    # initialize
    dp = [list(0 for _ in range(W+1)) for j in range(N+1)]
    
    # DP
    for i in range(N):
        for j in range(W+1):
            if j >= wv[i][0]:
                dp[i+1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
            else:
                dp[i+1][j] = dp[i][j]
    return dp[N][W]

if __name__ == "__main__":
    N, W = map(int, input().split())
    wv = []
    for _ in range(N):
        wv.append(list(map(int, input().split())))
    print(knapsack(N, W, wv))

Measured memory_bytes: 144484
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {

	string s;
	cin >> s;

	if (s == "SUN") { cout << 7; }
	if (s == "MON") { cout << 6; }
	if (s == "TUE") { cout << 5; }
	if (s == "WED") { cout << 4; }
	if (s == "THU") { cout << 3; }
	if (s == "FRI") { cout << 2; }
	if (s == "SAT") { cout << 1; }


	system("PAUSE");
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
double Sequence(double a,int n)
{
    if(n==10)return a*2;
    if(n%2==0)return a*2+Sequence(a*2,n+1);
    return a/3+Sequence(a/3,n+1);
}
int main()
{
    double n=0,a;
    while(cin>>a){
        n=a+Sequence(a,2);
        cout<<setprecision(8)<<n<<endl;
    }
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n, x = 0;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
    x ^= a.at(i);
  } 
  if(x == 0) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 640
/*  
     author : masaow    
     g++ : 17.3.20  
*/        
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- \n  "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+7;  
/*  
    time : 10 : 14    
    date : 24.01.2020
*/    

// int L,R,mid,target,idx ;
int tests(){
  int n,k,i ; 
  cin  >> n >> k  ;
  int h[N] = {0} ;
  ll ans = 0 ;   
  forn(i,0,n)
    cin >> h[i] ; 
  sort(h,h+n) ; 
  reverse(h,h+n) ; 
  forn(i,k,n)
    ans += (ll) h[i] ; 
  cout << ans  << '\n' ;     
  return 0 ; 
}
int main(){
    I__O ;  
    int cases = 1 ; 
    // cin >> cases;  
    while(cases--)
      tests(); 
  return 0 ; 
}

Measured memory_bytes: 1024
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}

bool check(int x,int k,vll& v){
	int ans=0;
	for(auto&z:v)ans+=((z-1)/x);
	return ans<=k;
}
int32_t main() {
    IOS;

        ll n,k;
        cin>>n>>k;
        vll v(n);
        rep(i,0,n-1) cin>>v[i];
        int low=1,high=2e9,mid,ans=-1;
        while(low<=high){
        	mid=(low+high)/2;
        	if(check(mid,k,v)){
        		ans=mid;
        		high=mid-1;
        	}
        	else low=mid+1;
        }
        cout<<ans;


        cout<<'\n';
    return 0;
}

Measured memory_bytes: 4768
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

int h, w;
std::vector<std::string> a;

int main(){
	std::cin >> h >> w;
	for(int i=0; i<h; ++i){
		std::string s;
		std::cin >> s;
		a.push_back(s);
	}
	for(int i=0; i<w+2; ++i) std::cout << "#";
	std::cout << std::endl;
	for(int i=0; i<h; ++i) std::cout << "#" << a[i] << "#" << std::endl;
	for(int i=0; i<w+2; ++i) std::cout << "#";
	std::cout << std::endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner cin = new Scanner(System.in);
		String line;
		for (; cin.hasNext();) {
			line = cin.nextLine();
			int N = Integer.valueOf(line); // 整数値の個数
			line = cin.nextLine();
			String[] inputGroup = line.split(" ");  //2行目の文字列を配列に分割

			int targetNum = 0;
			for(String a : inputGroup){
				targetNum += Integer.valueOf(a);
			}
			float targetNum2 = (float)targetNum / inputGroup.length;
			targetNum = Math.round(targetNum2);

			int cost = 0;
			for(String a : inputGroup){
				cost += (Integer.valueOf(a) - targetNum) * (Integer.valueOf(a) - targetNum);
			}

			System.out.println(cost);
		}
	}
}

Measured memory_bytes: 9428
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		int co; int temp;
		
		for(co=1;co<=n;co++){
		if(co%3==0){System.out.print(" "+co);continue;}
		
		else{temp=co;
		while(temp>0){
		if(temp%10==3){System.out.print(" "+co);break;}
		temp=temp/10;
	}
}
	}
		System.out.println("");	
	}	
}

Measured memory_bytes: 24416
N = int(input())
A = int(input())
ans = A//2
amari = A % 2
for _ in range(N-1):
    A = int(input())
    ans += (amari+A)//2
    if A == 0:
        amari = 0
    else:
        amari = (amari+A) % 2
print(ans)


Measured memory_bytes: 9188
//074
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n,k,x;
    int ans=0;
    cin >> n >> k;
    rep(i,n){
        cin >> x;
        ans +=min(x, abs(k-x));
    }
    cout << 2*ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
#include <list>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef ll Weight;
const Weight INF = (1L<<50);
struct Edge{
    int src,dst;
    Weight weight;
    int rev;
    Edge(int f, int t, Weight c, int rev=0):src(f),dst(t),weight(c),rev(rev){}
    bool operator < (const Edge& re)const{ return weight > re.weight;}
};
typedef vector<vector<Edge> > Graph;
void add_edge(Graph &G, int s, int t, Weight cap){
    G[s].push_back(Edge(s, t, cap, G[t].size()));
}
void shortestPath(const Graph &g, int s, vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;
  for(Q.push(Edge(-2, s, 0)); !Q.empty();){
    Edge e = Q.top(); Q.pop();
        if(prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight){
            dist[f->dst] = e.weight+f->weight;
            Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u]) path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}

int main(void){
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--; t--;
	Graph g(n), g2(n);
	REP(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--; v--;
		add_edge(g, u, v, a);
		add_edge(g, v, u, a);
		add_edge(g2, u, v, b);
		add_edge(g2, v, u, b);
	}
	vector<Weight> d, d2;
	vi p, p2;
	shortestPath(g, s, d, p);
	shortestPath(g2, t, d2, p2);
	vector<pair<ll, int> > ans;
	REP(i, n) {
		ans.push_back(pair<ll, int>(d[i] + d2[i], i));
	}
	sort(ALL(ans));
	
/*
	REP(i, d.size()){
		cout << d[i] << ":";
	} cout << endl;

	REP(i, d2.size()){
		cout << d2[i] << ":"; } cout << endl;

	REP(i, n){
		cout << ans[i].first << " " << ans[i].second << endl;
	}	
	*/
	int r = 0;
	REP(i, n){
		while(ans[r].second < i) r++;
		cout << 1000000000000000L - ans[r].first << endl;
	}
}


Measured memory_bytes: 25280
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    ll n; cin >> n;

    ll ans = (n / 500L) * 1000L;

    ans += (((n % 500L) / 5L) * 5);

    cout << ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=a-1;i>=b;i--)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

void Fast_IO() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
   freopen("in.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
} 

vector<vector<ll> >vii;
int main(){
   //Fast_IO();
   ll n;
   cin>>n;
   ll k = n%10;
   if(k==2 || k==4 || k==5|| k==7||k==9||k==2) cout<<"hon"<<endl;
   else if(k==0||k==1||k==6||k==8) cout<<"pon"<<endl;
   else cout<<"bon"<<endl;
   
}


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

int main(){
    int N;
    cin>>N;
    int A[N],X[N];
    for(int i=0;i<N;i++){
    
        cin>>X[i];
        A[i]=X[i];
    }
    sort(X,X+N);

    for(int i=0;i<N;i++){
        if(A[i]<=X[N/2-1])cout<<X[N/2]<<"\n";
        else cout<<X[N/2-1]<<"\n";
    }

    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=1e5+500;
const ll mod=1e9+7;
const ll inf=1e9+500;

bool ispr[maxn];
ll a[maxn];

vector<ll> t3;
map<ll,ll> ml;
set<ll> st;

ll ok(ll a){
    for(auto v:t3){
        while(a%(v*v*v)==0){
            a/=(v*v*v);
        }
    }
    return a;
}
ll rev(ll a){
    ll yek=1;
    ll doo=1;
    for(auto v:t3){
        if(a%(v*v)==0){
            doo*=v;
            a/=(v*v);
        }
        if(a%v==0){
            yek*=v;
            a/=v;
        }
    }
    ll sq=sqrt(a);
    if(sq*sq==a){
        return sq*yek*yek*doo;
    }else{
        return a*a*yek*yek*doo;
    }
}
int main(){
    fill(ispr,ispr+maxn,1);
    for(ll i=2;i<maxn;i++){
        for(ll j=i*i;j<maxn;j+=i){
            ispr[j]=0;
        }
    }
    ispr[1]=0;
    for(ll i=1;i*i*i<=1e10;i++){
        if(ispr[i]){
            t3.pb(i);
        }
    }

    ll n,ans=0;
    cin>>n;
    for(ll i=0;i<n;i++){
        ll v;
        cin>>v;
        v=ok(v);
        if(v==1){
            ans=1;
        }else{
            ml[v]++;
            st.insert(v);
        }
    }
    for(auto v:st){
        ll r=rev(v);
        ans+=max(ml[v],ml[r]);
        ml.erase(v);
        ml.erase(r);
    }
    cout<<ans;
}


Measured memory_bytes: 13312
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	map<int,int>mp;
	for (int n = 0;n<N;++n) {
		int num;
		cin >> num;
		mp[num] = n;
	}
	set<int>S; 
	S.insert(-1); 
	S.insert(N);
	long long ans = 0;
	for (int n = N; n > 0; --n) {
		int num = mp[n];
		S.insert(num);
		set<int>::iterator it = S.find(num);
		int l1, l2;
		int r1, r2;
		{
			it--;
			l2 = *it;
			if (-1 != *it) {
				it--;
			}
			l1 = *it;
		}
		{
			it = S.find(num);
			it++;
			r1 = *it;
			if (N != *it) {
				it++;
			}
			r2 = *it;
		}
		ans += (long long)n*(r2 - r1)*(num-l2);
		ans += (long long)n*(l2 - l1)*(r1-num);
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 12932
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
int main(void){
    int a,b;
    cin >>a>>b;
    if(a<=5) cout<< 0<<endl;
    else if(a<=12) cout<<(b/2)<<endl;
    else cout<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m,q=(int(i) for i in input().strip().split(" "))
from collections import defaultdict
d=defaultdict(int)
for _ in range(m):
    a,b=(int(i) for i in input().strip().split(" "))
    d[(a,b)]+=1
for i in range(1,n+1):
    for j in range(1,n+1):
        d[(i,j)]+=d[(i,j-1)]

for i in range(1,n+1):
    for j in range(1,n+1):
        d[(i,j)]+=d[(i-1,j)]

for i in range(q):
    l,r = (int(i) for i in input().strip().split(" "))
    print(d[(r,r)]+d[(l-1,l-1)]-d[(l-1,r)]-d[(r,l-1)])


Measured memory_bytes: 137856
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, i, j;
	cin >> n;
	int a[n];
	for (i = 0; i < n; i++)
		cin >> a[i];
	
	int q, m, e, x, k;

	cin >> q;
	while (q--)
	{
		cin >> x >> m >> e;
		for (k = 0; k < m-x; k++)
		{
			i = x + k;
			j = e + k;
			swap(a[i], a[j]);
		}	
	}

	for (i = 0; i < n; i++)
	{
		if (i)cout << " ";
		cout << a[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>
int main()
{
	char a[10];
	int i,p;
	while(~scanf("%s",&a))
	{
		p=0;
		for(i=0;i<3;i++)
		{
			if(a[i]==a[i+1])
			p++;
		}
		if(p==0)
		printf("Good\n");
		else
		printf("Bad\n");
	}
	return 0;
}

Measured memory_bytes: 128
from itertools import combinations_with_replacement


def main():
    n,m,q = map(int,input().split())
    num_lst = []
    for i in range(q):
        num_lst.append(list(map(int,input().split())))
    l = list(range(1,m+1))
    A = list(combinations_with_replacement(l,n))

    mx = 0
    for now_A in A:
        score = 0
        for nums in num_lst:
            a,b,c,d = nums
            if now_A[b-1] - now_A[a-1] == c:
                score += d
        mx = max(mx,score)
    print(mx)



if __name__ == '__main__':
    main()


Measured memory_bytes: 21476
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);
	      	  
	      	  int A,B;
	      	  string s;
	      	  cin >> A >> B >> s;
	      	  
	      	  int n=s.size();
	      	  if(n!=A+B+1){
	      		  cout << "No" << endl;
	      		  return 0;
	      	  }
	      	  REP(i,n){
	      		  if(i>=0 && i<A){
	      			  if(!(s[i]-'0'>=0 && s[i]-'0'<=9)){
	      				  cout << "No" << endl;
	      				  return 0;
	      			  }
	      		  }
	      		  else if(i==A){
	      			  if(s[i]!='-'){
	      				  cout << "No" << endl;
	      				  return 0;
	      			  }
	      		  }
	      		  else{
	      			  if(!(s[i]-'0'>=0 && s[i]-'0'<=9)){
	      				  cout << "No" << endl;
	      				  return 0;
	      		  }
	      	  }
	      	  }
	      		  
	      		  cout << "Yes" << endl;
	      	  

	          return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int dfs(string s, int n) {
    if(stol(s) > n) return 0;
 
    int cnt3 = 0, cnt5 = 0, cnt7 = 0;

    for(int i = 0; i < s.size(); i++){
        if(s[i] == '3') cnt3++;
        if(s[i] == '5') cnt5++;
        if(s[i] == '7') cnt7++;
    }
 
    int res = 0;
    if(cnt3 > 0 && cnt5 > 0 && cnt7 > 0) res++;
 
    res += dfs(s + '3', n);
    res += dfs(s + '5', n);
    res += dfs(s + '7', n);
 
    return res;
}
 
 
int main(){
    int n;
    cin >> n;
 
    cout << dfs("0", n) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll n;
vector<vector<int>> vt;
ll a[200010];
ll ch[300010];
ll up[300010];
int main()
{
	int cnt = 0;
	scanf("%lld", &n);
	vt.resize(n + 1);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	int update = 0;
	for (int i = 1; i < n; i++)
	{
		if (a[i - 1] < a[i]);
		else
			update = 1;
	}
	if (!update)
	{
		puts("1");
		return 0;
	}
	for (int i = 1; i < n; i++)
	{
		if (a[i - 1] < a[i]) {
			if (vt[cnt].size())
				cnt++;
		}
		else
		{
			if (a[i] >= 300000)continue;
			vt[cnt].push_back(a[i]);
		}
	}
	if (vt[cnt].size())
		cnt++;
	int dap = n;
	int left = 2;
	int right = n;
	while (left <= right)
	{
		memset(ch, 0, sizeof(ch));
		memset(up, -1, sizeof(up));
		int mid = (left + right) / 2;
		for (int i = 0; i < cnt; i++)
		{
			for (int y = 0; y < vt[i].size(); y++)
			{
				if (i)
				{
					if (vt[i][y] > vt[i - 1][vt[i - 1].size() - 1] && up[vt[i][y]] != i)
					{
						ch[vt[i][y]] = 0;
						up[vt[i][y]] = i;
					}
				}
				ch[vt[i][y]]++;
				for (int z = vt[i][y]; z >= 1; z--)
				{
					if (i) {
						if (z - 1 > vt[i - 1][vt[i - 1].size() - 1] && up[z - 1] != i)
						{
							ch[z - 1] = 0;
							up[z - 1] = i;
						}
					}
					if (ch[z] / mid) {
						ch[z - 1] = ch[z - 1] + (ch[z] / mid);
					}
					else
						break;
					ch[z] = ch[z]%mid;
				}
			}
		}
		if (ch[0])
		{
			left = mid + 1;
		}
		else
		{
			right = mid - 1;
			dap = min(dap, mid);
		}
	}
	printf("%d", dap);
}

Measured memory_bytes: 13440
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1e9+7;
ll n,m,i,j,f[5010][5010],g[5010][5010];
int main(){
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=m;i++)f[0][i]=1;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			g[i-1][j]=(g[i-1][j-1]*2%p+f[i-1][j]*j%p)%p;
			f[i][j]=(g[i-1][j-1]+f[i-1][j]*(j+1))%p;
		}
	}
	printf("%lld",f[n][m]);
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll s;
bool ok[6000000];
int _div, si;

void init() {
    int num = 9000000;
    int i = 7;
    while (num * i >= s) {
        num /= 10;
        i--;
    }
    _div = i;
    si = num;
    num /= 10;
    i--;
    int pos = 0;
    for ( ; i >= 1; i--) {
        for (int j = 0; j < num; j++) {
            pos += i;
            ok[pos] = true;
        }
        num /= 10;
    }
}

ll mod_pow(ll x, ll y) {
    ll ret = 1;
    while (y) {
        if (y&1) ret = ret * x % MOD;
        x = x * x % MOD;
        y /= 2;
    }
    return ret;
}

ll rnk(ll x, ll y) {
    return (mod_pow(10LL, x)-mod_pow(10LL, x-1)-y+1+3*MOD)%MOD;
}

ll ans = 0;

int main(){
    cin >> s;
    init();
    for (int i = 1; i*i <= s; i++) {
        if (s%i == 0) {
            if (i > _div) {
                ans = (ans + rnk(i, s/i) - 1 + MOD)%MOD;
            }
            if (i*i == s) continue;
            int j = s/i;
            if (j > _div) {
                ans = (ans + rnk(j, s/j) -1 + MOD)%MOD;
            }
        }
    }
    ans += s / (_div+1);
    for (int i = 1; i <= si; i++) {
        if ((s-i*_div)%(_div+1) == 0) {
            ans++;
        }
    }
    for (int i = 0; i < 6000000; i++) {
        if (!ok[i]) continue;
        int tmp = s-i;
        if (tmp <= _div*si) {
            if (tmp%_div == 0) ans++;
        } else {
            if ((tmp-_div*si)%(_div+1) == 0) ans++;
        }
    }
    cout << ans%MOD << endl;
}
































Measured memory_bytes: 6016