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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int x[200000], y[200000];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (a == 0) y[b] = 1;
    if (b == n - 1) x[a] = 1;
  }

  bool f = false;
  rep(i, n) if (x[i] && y[i]) f = true;

  cout << (f ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;


int main(){
	int n;
	cin>>n;
	rep(i,n){
		pii ro=mkp(0,0);
		//cin>>ro.F>>ro.S;
		int a,b;
		pii ans=mkp(0,0);
		while(cin>>a>>b,a||b){
			//cout<<ro.F<<" "<<ro.S<<endl;
			ro.F+=a; ro.S+=b;
			if(ans.F*ans.F+ans.S*ans.S<ro.F*ro.F+ro.S*ro.S){
				ans=ro;
			}
			else if(ans.F*ans.F+ans.S*ans.S==ro.F*ro.F+ro.S*ro.S&&ans.F<ro.F){
				ans=ro;
			}
		}
		cout<<ans.F<<" "<<ans.S<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 2e5 + 5;


ll gcd(ll a, ll b) {
	if (a == 0) return b;
	return gcd(b % a, a);
}

bool prime(ll x) {
	if (x <= 1) return 0;
	if (x == 2) return 1;
	for (ll i = 2; i * i <= x; i++) {
		if (x % i == 0) return 0;
	}
	return 1;
}

ll a, b;
int main() {	

	cin >> a >> b;
	ll x = gcd(a, b);
	ll res = 0;
	for (ll i = 1; i * i <= x; i++) {
		if (x % i == 0) {
			if (i == 1) res++;
			else if (i == 2) res++;
			else if (i == 3) res++;
			else if (i == 5) res++;
			else if (prime(i)) res++;
			if (i * i != x) {
				if (x / i == 1) res++;
				else if (x / i == 2) res++;
				else if (x / i == 3) res++;
				else if (x / i == 5) res++;
				else if (prime(x / i)) res++;
			}
		}
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
flag = True

for i in a:
    if (i % 2 == 0) and (i % 3 != 0) and (i % 5 != 0):
        flag = False
        break

if flag == True:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint ans = modpow(10, n);
	ans += mod - modpow(9, n) * 2 % mod, ans %= mod;
	ans += modpow(8, n), ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3652
require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,k=gsmi
puts n.to_s(k).length

Measured memory_bytes: 2044
h, w, k = gets.split.map(&:to_i)

c = []
h.times do
  c << gets.chomp
end

count = 0
(2 ** h).times do |i|
  i_str = sprintf("%0#{h}b", i)
  (2 ** w).times do |j|
    j_str = sprintf("%0#{w}b", j)


    black = 0
    i_str.each_char.with_index do |hi, iind|
      j_str.each_char.with_index do |wi, jind|
        black += 1 if hi == "0" && wi == "0" && c[iind][jind] == "#"
      end
    end
    count += 1 if black == k
  end
end
puts count

Measured memory_bytes: 14368
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  char c[2];
  int a;
}Point;

int partition(Point *, int, int);
int quickSort(Point *, int, int);
void merge(Point *,int, int, int);
void mergeSort(Point *,int, int);

int n;

int main()
{
  int flag=0, i;
  Point A1[100000], A2[100000];
  
  scanf("%d",&n);
  
  for( i=0 ; i<n ; i++ ){
    scanf(" %s%d",A1[i].c,&A1[i].a);
    A2[i] = A1[i];
  }

  quickSort(&A1[0],0,n-1);
  mergeSort(&A2[0],0,n);

  

  for( i=0 ; i<n ; i++ ){
    if(A1[i].c[0]!=A2[i].c[0] || A1[i].a!=A2[i].a)
      flag = 1;
  }
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");

  for( i=0 ; i<n-1 ; i++ ){
    printf("%c %d\n",A1[i].c[0],A1[i].a);
  }
  printf("%c %d\n",A1[i].c[0],A1[i].a);
  
  return 0;
}

int partition(Point *A, int p, int r)
{
  int i, j;
  Point x, str;
  x = A[r];
  i = p-1;
  for( j=p ; j<=r-1 ; j++ ){
    if(A[j].a<=x.a){
      i++;
      str = A[i];
      A[i] = A[j];
      A[j] = str;
    }
  }
  A[r] = A[i+1];
  A[i+1] = x;
  return i+1;
}

int quickSort(Point *A, int p, int r)
{
  int q;
  if(p<r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

void merge(Point *A, int left, int mid, int right)
{
  int n1, n2, i, j, k;
  Point L[50001],R[50001];
  n1 = mid-left;
  n2 = right - mid;
  for( i=0 ; i<n1 ; i++ ){
    L[i] = A[left+i];
  }
  for( i=0 ; i<n2 ; i++ ){
    R[i] = A[mid+i];
  }
  L[n1].a=1000000100;
  R[n2].a=1000000100;
  i=0;
  j=0;
  for( k=left ; k<right ; k++ ){
    if(L[i].a<=R[j].a){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
  }
}
void mergeSort(Point *A,int left, int right)
{
  int mid;
  if((left+1)<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

Measured memory_bytes: 2952
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        int N = Integer.parseInt(s);

        StringBuilder sb = new StringBuilder();

        while (0 != N) {
            if (Math.abs(N % 2) == 1) {
                sb.insert(0, "1");
                N -= 1;
            } else {
                sb.insert(0, "0");
            }

            N /= -2;
        }

        if (sb.length() == 0) sb.append("0");

        System.out.println(sb);
    }
}


Measured memory_bytes: 24660
input_data = input().split(' ')

data = [int(input_data[i]) for i in range(2)]
if(data[0] < data[1]):
    local = data[0]
    data[0] = data[1]
    data[1] = local

def gcd(a,b):
    while(b!=0):
        local = a
        a = b
        b = local % b
    return(a)


def lcm(a,b):
    return(a*b//gcd(a,b))

print(lcm(data[0], data[1]))


Measured memory_bytes: 3064
//
// Created by admin on 2020/8/2.
//
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,k,a[5000010];
bool check(int l)
{
    int cnt=0;
    for(int i=1;i<=n;i++)
        cnt+=(a[i]-1)/l;
    return cnt<=k;
}
signed main()
{
    int tem=0;
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        tem=max(tem,a[i]);
    }
    int l=1,r=tem,mid;
    while(r>=l)
    {
        mid=(l+r)/2;
        if(check(mid))
            r=mid-1;
        else
            l=mid+1;
    }
    printf("%lld\n",l);
    return 0;
}


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

const int maxn=5e2+10;
int n,a[maxn*maxn],l[maxn],r[maxn];
pair<int,int> x[maxn];

int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>x[i].first;
		x[i].second=i;
		a[x[i].first]=i;
		l[i]=i-1;
		r[i]=n-i;
	}
	sort(x+1,x+n+1);
	for(int i=1,j=1;i<=n*n;++i){
		while(j<=n&&!l[x[j].second])
			++j;
		if(a[i]){
			if(j<=n&&a[i]==x[j].second){
				puts("No");
				return 0;
			}
		}
		else{
			if(j<=n){
				a[i]=x[j].second;
				--l[x[j].second];
			}
		}
	}
	for(int i=n*n,j=n;i;--i){
		while(j&&!r[x[j].second])
			--j;
		if(a[i]){
			if(j&&a[i]==x[j].second){
				puts("No");
				return 0;
			}
		}
		else{
			if(j){
				a[i]=x[j].second;
				--r[x[j].second];
			}
		}
	}
	puts("Yes");
	for(int i=1;i<=n*n;++i)
		printf("%d ",a[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 2176
#include"bits/stdc++.h"
using namespace std;
int main() {
	char str[3];
	memset(str, NULL, sizeof(str));
	cin >> str;
	for (int i = 0; i < 3; i++) {
		if (str[i] == '9') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "list"
using namespace std;


int main() {
	int n, w, ans = 0;
	cin >> n >> w;
	vector <int> wt(n+1), val(n+1);
	for (int i=1; i<=n; i++) {
		cin >> wt[i] >> val[i];
	}
	const int max_value = 1e5;
	const long long inf_weight = 1e12;
	vector < vector <long long> > dp(max_value + 1, vector <long long> (n+1, inf_weight));
	// dp[v][x] = minimum weight to get value "v" using first "x" items
	for (int i=0; i<=n; i++) {
		dp[0][i] = 0;
	}
	for (int v=1; v<=max_value; v++) {
		for (int x=1; x<=n; x++) {
			// assume this item is not going to be included
			dp[v][x] = dp[v][x - 1];
			// if this item can fit (in value)
			if (val[x] <= v) {
				// find the resulting weight of adding this item
				dp[v][x] = min(dp[v][x], dp[v - val[x]][x - 1] + wt[x]);
				if (dp[v][x] <= w) {
					ans = max(ans, v);
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 84988
import java.util.*;
class   Team{   
	int     teamnum;   
    int     teampoint;   
    public Team(int v1, int v2)
    {   teamnum= v1;
        teampoint= v2;
    }
}
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		Team [] team = new Team [num + 1];
		int teamrank[] = new int [num + 1];
		for(int i = 1; i < num + 1; i++){
			teamrank[i] = 1;
		}
		for(int i = 1; i < num + 1; i++){
			team[i] = new Team(i, 0);
		}
		for(int i = 0; i < num * (num - 1) / 2; i++){
			int team1 = in.nextInt();
			int team2 = in.nextInt();
			int point1 = in.nextInt();
			int point2 = in.nextInt();
			if(point1 < point2){
				team[team1].teampoint += 0;
				team[team2].teampoint += 3;
			}
			else if(point1 == point2){
				team[team1].teampoint += 1;
				team[team2].teampoint += 1;
			}
			else {
				team[team1].teampoint += 3;
				team[team2].teampoint += 0;
			}
		}
		for(int i = 1; i <= num; i++){
			for(int k = i + 1;k <= num; k++){
				if(team[i].teampoint < team[k].teampoint){
					teamrank[i]++;
				}
				else if(team[i].teampoint > team[k].teampoint){
					teamrank[k]++;
				}
			}
			System.out.println(teamrank[i]);
		}
	}
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int n; cin >> n;
        string s; cin >> s;
        vector<int> w(n), e(n);
        for (int i = 0; i < n; i++) {
                if (i) w[i] = w[i - 1];
                w[i] += s[i] == 'W';
        }

        for (int i = n - 1; i >= 0; i--) {
                if (i + 1 < n) e[i] = e[i + 1];
                e[i] += s[i] == 'E';
        }

        int ans = n;
        for (int i = 0; i < n; i++) {
                ans = min(ans, (i ? w[i - 1] : 0) + (i + 1 < n ? e[i + 1] : 0));
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

long long fib(int n){
    long long a=0,b=1,c;
    for(int i=0;i<n;i++){
        c=(a+b)%1000000007;
        a=b;
        b=c;
    }
    return b;
}
int main(){
    int n,m;
    cin >> n >> m;
    int d[m];
    for(int i=0;i<m;i++)cin >> d[i];
    sort(d,d+m);
    for(int i=0;i<m-1;i++){
        if(d[i+1]-d[i]==1){
            cout << 0 << endl;
            return 0;
        }
    }
    long long ans=0;
    if(m==0){
        cout << fib(n) << endl;
        return 0;
    }
    for(int i=0;i<m;i++){
        if(i==0){
            ans=fib(d[i]-1)%1000000007;
        }
        else{
            ans=(ans*fib(d[i]-d[i-1]-2))%1000000007;
        }
    }
    ans = (ans*fib(n-d[m-1]-1))%1000000007;
    cout << ans << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC064
{
    class Program
    {
        static void Main(string[] args)
        {
            int r, g, b;
            string[] vals = Console.ReadLine().Split(' ');
            r = int.Parse(vals[0]);
            g = int.Parse(vals[1]);
            b = int.Parse(vals[2]);

            int num = r * 100 + g * 10 + b;

            if(num % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int op(int lhs, int rhs, int ope){
	if(ope == 0) return lhs+rhs;
	if(ope == 1) return lhs-rhs;
	if(ope == 2) return lhs*rhs;
}

bool calc(int a, int b, int c, int d, int o1, int o2, int o3){
	string ope = "+-*";
	if( op(op(op(a, b, o1), c, o2), d, o3) == 10){ // 1->2->3
		printf("(((%d %c %d) %c %d) %c %d)\n", a, ope[o1], b, ope[o2], c, ope[o3], d);
		return true;
	}
	if(	op(op(a, b, o1), op(c, d, o3), o2) == 10){// 1->3->2 (== 3->1->2)
		printf("((%d %c %d) %c (%d %c %d))\n", a, ope[o1], b, ope[o2], c, ope[o3], d);
		return true; 
	}
	return false;
}

bool solve(int a, int b, int c, int d){
	rep(o1, 3) rep(o2, 3) rep(o3, 3){
		bool res = calc(a, b, c, d, o1, o2, o3);
		if(res) return true;
	}
	return false;
}

int main(){
	vi a(4);
	while(1){
		rep(i, 4) cin >> a[i];
		if(!a[0]) break;
		sort(all(a));
		bool ok;
		do{
			ok = solve(a[0], a[1], a[2], a[3]);
		}while(!ok && next_permutation(all(a)));
		if(!ok) cout << "0" << endl;
	}

	return 0;
}

Measured memory_bytes: 1244
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int mx = 0;
    int tmp = 0;

    for (int i = 0; i < N - 1; i++) {
        if (A[i+1] <= A[i]) {
            tmp++;
        } else {
            mx = max(mx, tmp);
            tmp = 0;
        }
    }

    mx = max(mx, tmp);

    cout << mx << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
    string t;cin >> t;
    for (auto k:{0,3,4,5}) {if (t.length()>=5 and t[k]=='A') t=t.substr(0,k)+t.substr(k+1,string::npos);}
    cout<<(t=="KIHBR"?"YES":"NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long lint;

lint dp[1 << 16];

int main()
{
	int N;
	
	while (scanf("%d", &N) && N){
		memset(dp, 0, sizeof(dp));
		lint ans = 0;
		
		for (int i = 0; i < N; i++){
			int M, b = 0;
			lint l;
			scanf("%d %lld", &M, &l);
			for (int j = 0; j < M; j++){
				int x, y;
				scanf("%d %d", &x, &y);
				for (int k = x - 6; k < y - 6; k++) b |= (1 << k);
			}
			
			for (int j = (1 << 16) - 1; j >= 0; j--){
				if ((j & b) == 0){
					dp[j] = max(dp[j], dp[j ^ b] + l);
					ans = max(ans, dp[j]);
				}
			}
		}
		printf("%lld\n", ans);
	}
	
}

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

using namespace std;

int main()
{
    long long n;
    cin >> n;
    if(n&1) cout << 0 << endl;
    else
    {
        n/=10;
        long long res=n;
        long long e=5;
        while(e<=n)
        {
            res+=(n/e);
            e*=5;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
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; } 
using ll=long long;
 int main(){
   int n=1;
 rep(i,5){
   int a=0;
   cin>>a;
   if(!a){
   cout<<n<<endl;
     return 0;
   }
   n++;
 }
}


Measured memory_bytes: 3568
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
sides = [0, 0]

for i in a.keys():
    if a[i] >= 4:
        sides.append(i)
        sides.append(i)
    elif a[i] >= 2:
        sides.append(i)

sides.sort(reverse=True)
print(sides[0] * sides[1])

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

string s;
int sum=0;

int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='x') sum++;
	}
	
	if(sum<=7) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
input()
l=list(map(int,input().split(" ")))
N=len(l)
r=[]
for i,x in enumerate(l):
  if x-1 > i:
    r=None
    break
  r.insert(x-1,x)

if r==None:
  print(-1)
else:
  for z in r:
    print(z)

Measured memory_bytes: 3060
from collections import deque
def readinput():
    n=int(input())
    nList=[]
    for _ in range(n+1):
        nList.append([])
    edges=[]
    for _ in range(n-1):
        a,b=map(int,input().split())
        edges.append((a,b))
        nList[a].append(b)
        nList[b].append(a)
    return n,nList,edges

def bfs(s,nList):
    #print(nList)
    WHITE=0
    GRAY=1
    BLACK=2
    status=[WHITE]*(n+1)
    parent=[0]*(n+1)
    color=[0]*(n+1)
    maxcolor=0
    Q=deque([])
    Q.append(s)
    while(len(Q)>0):
        u=Q.popleft()
        usedcolor=color[u]
        col=1
        for t in nList[u]:
            if status[t]==WHITE:
                status[t]=GRAY
                parent[t]=u
                if col==usedcolor:
                    col+=1
                color[t]=col
                Q.append(t)
                col+=1
        maxcolor=max(maxcolor,col-1)
        status[u]=BLACK
        #print(u,usedcolor)
    return color, maxcolor


def main(n,nList,edges):
    color, maxcolor=bfs(1,nList)
    print(maxcolor)
    for a,b in edges:
        print(color[b])

if __name__=='__main__':
    n,nList,edges=readinput()
    main(n,nList,edges)


Measured memory_bytes: 35336
#include <bits/stdc++.h>
#define tt long t;cin>>t;while(t--)
#define tez ios_base::sync_with_stdio(false); cin.tie(NULL);
#define lli long long int
#define plli pair<lli,lli>
#define vlli vector<lli>
#define vplli vector<plli>
#define pqlli priority_queue <lli>
#define pqplli priority_queue <plli>
#define mplli map<lli,lli>
#define all(v) v.begin(),v.end()
#define alll(s) s.begin(),s.end(),s.begin(), ::tolower
#define allu(s) s.begin(),s.end(),s.begin(), ::toupper

#define mod 1000000007
#define ff first
#define ss second
#define fori(i,a,b)    for(int i=a;i<b;i++)
#define ford(i,a,b)    for(int i=a;i>=b;i--)
#define br cout<<endl
#define sz(v) (long)v.size()
#define YS cout<<"YES"<<endl
#define ys cout<<"yes"<<endl
#define Ys cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define no cout<<"no"<<endl
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define bs binary_search
#define mp make_pair
#define llmn LLONG_MIN
#define llmx  LLONG_MAX
#define stp setprecision
#define fxd fixed
#define tu (char)toupper
#define tl (char)tolower
#define coutv(v) for(lli index=0;index<v.size();index++) {cout<<v[index]<<" ";} br;

using namespace std;

/*
lli count01(string s,char ch){
  lli mx=0,c=0;
  if(ch=='0'){

   fori(i,0,sz(s)){
     if(s[i]=='0'){
        c++;}
     else{
        c=0;}
        if(c>mx){mx=c;}

   }

  }
  else{

    fori(i,0,sz(s)){
     if(s[i]=='1'){
        c++;}
     else{
        c=0;}
        if(c>mx){mx=c;}

    }

  }
return mx;

}*/
/*
vector<lli> prime(lli n){
  bool a[n+1];
  memset(a,true,sizeof(a));
  for(lli i=2;i*i<=n;i++){
    if(a[i]){
      for(lli j=i*i;j<=n;j+=i)
      {  a[j]=false;}
    }
  }
  vector<lli>v;
  for(lli i=2;i<=n;i++){
    if(a[i]){
      v.pb(i);
    }
  }
  return v;
}

*/
void solve(){
    lli n,m;
    cin>>n;
    lli a[1000000]={0};
    lli ans=0;
    for(lli i=0;i<n;i++){
        lli aa;
        cin>>aa;
        a[aa]++;
        ans+=aa;
    }
    cin>>m;
    while(m--){
        lli l,r;
        cin>>l>>r;
        ans-=(a[l]*l);
        ans+=(r*a[l]);
        a[r]+=a[l];
        a[l]=0;
        cout<<ans<<endl;
    }


}

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


Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> P(N);
  for (auto& x : P) cin >> x;
  vector<i64> A(N), B(N);
  REP(i, N) { A[i] = 1LL + i * 20000LL; }
  REP(i, N) { B[N - 1 - i] = 1LL + i * 20000LL; }
  i64 prev = 0;
  REP(i, N) {
    int p = P[i] - 1;
    i64 v = A[p] + B[p];
    if (v <= prev) {
      i64 gap = prev - v;
      A[p] += gap / 2 + 1;
      B[p] += gap / 2 + 1;
      prev = A[p] + B[p];
    } else {
      prev = v;
    }
  }
  REP(i, N) { cout << (i == 0 ? "" : " ") << A[i]; }
  cout << endl;
  REP(i, N) { cout << (i == 0 ? "" : " ") << B[i]; }
  cout << endl;
}

Measured memory_bytes: 3732
# -*- coding: utf-8 -*-


def main():
    x, y, a, b, c = map(int, input().split())
    red_delis = list(map(int, input().split()))
    green_delis = list(map(int, input().split()))
    musyoku_delis = list(map(int, input().split()))

    red_delis.sort(reverse=True)
    green_delis.sort(reverse=True)
    musyoku_delis.sort(reverse=True)

    new_red_delis = red_delis[:x]
    new_green_delis = green_delis[:y]

    return sum(sorted(new_red_delis + new_green_delis + musyoku_delis, reverse=True)[:x + y])


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 23996
n = int(input())
import math

cum_l = []

s = 0
for i in range(1,10000001):
    s += i
    cum_l.append(s)

ans = 0 
for i in range(1,n+1):
    k = n // i
    ans += (i*(cum_l[k-1]))

print(ans)

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


void solve(long long X, long long Y, long long Z){
    cout << Z <<" "<< X <<" "<<Y<< endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    solve(X, Y, Z);
    return 0;
}


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

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

using namespace std;

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

int main() {
  string s;
  cin >> s;

  int s1 = s[0] - '0';
  int s2 = s[1] - '0';
  int s3 = s[2] - '0';
  int s4 = s[3] - '0';
  if ((s1 == s2 && s2 == s3) || (s2 == s3 && s3 == s4)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

int arrr[10] = {};

ll arr[200][200];



int main() {

	int n, m, r;
	cin >> n >> m >> r;

	for (int i = 0; i < r; i++)
		cin >> arrr[i];

	for (int i = 0; i < 200; i++)
		for (int j = 0; j < 200; j++) {
			if (i == j)
				arr[i][j] = 0;
			else
				arr[i][j] = INF;
		}

	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;

		arr[a][b] = c;
		arr[b][a] = c;

	}

	//warshall_floyd
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				arr[j][k] = min(arr[j][k], arr[j][i] + arr[i][k]);
			}
		}
	}
/*

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << arr[i][j] << " ";
		}
		cout << endl;
	}*/

	ll answer = INF;

	sort(arrr,arrr+r);

	do {

		ll t = 0;

		for (int i = 0; i < r-1; i++) {
			t += arr[arrr[i] - 1][arrr[i + 1] - 1];
			//cout << arr[arrr[i]-1][arrr[i + 1]-1] << " ";
		}
		//cout << endl;

		//cout << t << endl;

		answer = min(answer,t);

	} while (next_permutation(arrr,arrr+r));

	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=5e3+5,INF=1e9,mod=998244353;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
int n,a[N],mn=1e9,mx;
void die(){puts("No");exit(0);}
int main(){
	read(n);rep(i,1,n)read(a[i]),gmin(mn,a[i]),gmax(mx,a[i]);
	if(mx-mn>1||mx>n-1)die();
	if(mx==mn){
		if(mx==n-1);else
		if(mx*2>n)die();
	}else{
		int c=0;rep(i,1,n)if(a[i]==mn)c++;
		if(n<c||mx<c)die();
		n-=c;mx-=c;
		if(mx<=0||n<2*mx)die();
	}
	puts("Yes");
}

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

using namespace std;

int main()
{
    int N;
    while(cin>>N)
    {
        int a[105];
        int i;
        for(i=0; i<N; i++)
            cin>>a[i];
        int j,s[105];
        for(i=1; i<N; i++)
        {
            int p=0,q=0;
            for(j=0; j<i; j++)
                p+=a[j];
            for(j=i; j<N; j++)
                q+=a[j];
            s[i-1]=q-p;
            if(s[i-1]<0)
                s[i-1]=-s[i-1];
        }
        sort(s,s+N-1);
        cout<<s[0]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int X, A;

		X = scan.nextInt();
		A = scan.nextInt();

		if (X < A) {
			System.out.println("0");
		} else {
			System.out.println("10");
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){
  if(a == 0) return b;
  else return gcd(b%a, a);
}

int32_t main(){
  DESYNC;
  int a,b;
  cin >> a >> b;
  a += b;
  if(a%2) cout << "IMPOSSIBLE"<<endl;
  else cout << a/2 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
int dp[110][4][2];

int main() {
  string s; cin >> s;
  int n = s.size();
  int K; cin >> K;
  dp[0][0][0] = 1;
  rep(i, n) rep(j, 4) rep(k, 2) {
    int nd = s[i] - '0';
    rep(d, 10) {
      int ni = i + 1, nj = j, nk = k;
      if(d != 0) nj++;
      if(nj > K) continue;
      if(k == 0) {
        if(d > nd) continue;
        if(d < nd) nk = 1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }
  int ans = dp[n][K][0] + dp[n][K][1];
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
    int k;
    string s;
    cin >> k >> s;
    if(s.length() <= k)
        cout << s << endl;
    else
    {
        cout << s.substr(0, k) + "..." << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3636
N=int(input())
ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())

dp=[i for i in range(N+1)]
for i in range(ga,N+1):
    dp[i]=max(dp[i],dp[i-ga]+gb)
for i in range(sa,N+1):
    dp[i]=max(dp[i],dp[i-sa]+sb)
for i in range(ba,N+1):
    dp[i]=max(dp[i],dp[i-ba]+bb)
N=dp[-1]
dp=[i for i in range(N+1)]
for i in range(gb,N+1):
    dp[i]=max(dp[i],dp[i-gb]+ga)
for i in range(sb,N+1):
    dp[i]=max(dp[i],dp[i-sb]+sa)
for i in range(bb,N+1):
    dp[i]=max(dp[i],dp[i-bb]+ba)
print(dp[-1])

Measured memory_bytes: 425392
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI

using namespace std;

int main() {

	string S;
	cin >> S;

	if (S[1] == 'B') {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}
	
	return 0;

}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=2e5+10;

int N;
int A[MAX];

void input(){
	cin>>N;
	rep1(i, N){
		cin>>A[i];
	}
}

void solve(){
	vector<int> v(N);;
	rep1(i, N) v[i-1] = i + A[i];
	sort(all(v));
	ll ans = 0;
	rep1(i, N){
		ans += ll(upper_bound(all(v), i-A[i])-lower_bound(all(v), i-A[i]));
	}
	cout<<ans;
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 4844
#include <stdio.h>
#include <string.h>

#define N 1000

int lcs(char x[], char y[]) {
  int m = strlen(x) , n = strlen(y);
  int c[N + 1][N + 1];
  int i, j;
  int max = 0;
  for (i = 0; i <= m; i++) {
    c[i][0] = 0;
  }
  for (i = 0; i <= n; i++) {
    c[0][i] = 0;
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (x[i] == y[j]) {
        c[i + 1][j + 1] = c[i][j] + 1;
      } else {
        c[i + 1][j + 1] = c[i][j + 1] > c[i + 1][j] ? c[i][j + 1] : c[i + 1][j];
      }
      max = max > c[i + 1][j + 1] ? max : c[i + 1][j + 1];
    }
  }

  return max;
}

int main() {
  int num;
  int i;
  char x[N + 1], y[N + 1];
  scanf("%d", &num);
  for (i = 0; i < num; i++) {
    scanf("%s %s", x, y);
    printf("%d\n", lcs(x, y));
  }

  return 0;
}



Measured memory_bytes: 5704
def solve(n, aaa):
    dp = [[-1] * n for _ in range(n)]
    dp_max = [-1] * n
    ans = 0

    a0, a1 = sorted(aaa[:2])
    dp[a0][a1] = 0
    dp_max[a0] = 0
    dp_max[a1] = 0

    for k in range(n - 1):
        a0, a1, a2 = sorted(aaa[2 + 3 * k:5 + 3 * k])
        if a0 == a1 and a1 == a2:
            ans += 1
            continue

        dp_max_max = max(dp_max)
        update_tasks = []

        if a0 == a1 or a1 == a2:
            rev = a1 == a2
            if rev:
                a0, a2 = a2, a0

            for b in range(n):
                c, d = min(a0, b), max(a0, b)
                e, f = min(a2, b), max(a2, b)
                update_tasks.append((e, f, dp_max[b]))
                if dp[c][d] != -1:
                    update_tasks.append((e, f, dp[c][d] + 1))

            update_tasks.append((a0, a0, dp_max_max))
            if dp[a2][a2] != -1:
                update_tasks.append((a0, a0, dp[a2][a2] + 1))

            if rev:
                update_tasks.append((a2, a0, dp_max_max))
            else:
                update_tasks.append((a0, a2, dp_max_max))

        else:
            update_tasks.append((a0, a1, dp_max_max))
            update_tasks.append((a0, a2, dp_max_max))
            update_tasks.append((a1, a2, dp_max_max))
            if dp[a0][a0] != -1:
                update_tasks.append((a1, a2, dp[a0][a0] + 1))
            if dp[a1][a1] != -1:
                update_tasks.append((a0, a2, dp[a1][a1] + 1))
            if dp[a2][a2] != -1:
                update_tasks.append((a0, a1, dp[a2][a2] + 1))

            for b in range(n):
                b_max = dp_max[b]
                for a in (a0, a1, a2):
                    c, d = min(a, b), max(a, b)
                    update_tasks.append((c, d, b_max))

        for a, b, c in update_tasks:
            dp[a][b] = max(dp[a][b], c)
            dp_max[a] = max(dp_max[a], c)
            dp_max[b] = max(dp_max[b], c)

    a = aaa[-1]
    dp[a][a] += 1

    return max(map(max, dp)) + ans


n = int(input())
aaa = [a - 1 for a in map(int, input().split())]
ans = solve(n, aaa)
print(ans)


Measured memory_bytes: 215132
c = list
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
c=[p,q,r]
br = 0
for i in range(2):
  for j in range(2):
    if(c[i][j]+c[i+1][j+1]==c[i][j+1]+c[i+1][j]):
      None
    else:
      br+=1
      break
if(br==0):
  print("Yes")
else:
  print("No")



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
const int N = 5000;
#define ll long long
int cmp(int a,int b){
	return a>b;
}	
int gcd(int x, int y)
{
    while(y^=x^=y^=x%=y);
    return x;
}

int gcd(int x,int y,int z){
	return gcd(gcd(x,y),z);
} 
int main(){
	int  n;
	cin >> n;
	ll s=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				s+=gcd(i,j,k);
			}
		}
	}
	cout << s <<endl;
	return 0;
}



Measured memory_bytes: 3596
module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Array
import           Data.Char

main = do
  n <- (read :: String -> Int) <$> getLine
  let x = last . filter (\a -> n `mod` a == 0) . takeWhile (\a -> a * a <= n) $ [1..]
  print . countDigit $ n `div `x

countDigit::Int -> Int
countDigit x
  | x == 0 = 0
  | otherwise  = 1 + countDigit (x `div` 10)


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;

int main2() {
  int N = nextInt();
  int K = nextInt();

  vector<vector<int>> v(N);
  REP(i, N) {
    int t = nextInt() - 1;
    int d = nextInt();
    v[t].push_back(d);
  }
  REP(t, N) {
    sort(ALL(v[t]));
    reverse(ALL(v[t]));
  }

  typedef pair<int,int> P;
  vector<P> ps;

  vector<ll> X, Y;
  REP(t, N) {
    REP(i, v[t].size()) {
      if (i == 0) Y.push_back(v[t][i]);
      else X.push_back(v[t][i]);
    }
  }
  sort(ALL(X)); reverse(ALL(X));
  sort(ALL(Y)); reverse(ALL(Y));
  
  vector<ll> sx(X.size() + 1);
  vector<ll> sy(Y.size() + 1);
  REP(i, X.size()) sx[i+1] = sx[i] + X[i];
  REP(i, Y.size()) sy[i+1] = sy[i] + Y[i];

  ll ans = 0;
  for (int y = 1; y <= (int)Y.size(); y++) {
    if (y <= K && K-y <= (int)X.size()) {
      ll cur = (ll)y*y + sy[y] + sx[K-y];
      chmax(ans, cur);
    }
  }
  

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

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 7540
#include <iostream>
#include <map>
#include <string>
#include <functional>
static void e(int *a) {
    int t = a[1];
    a[1] = a[4];
    a[4] = a[6];
    a[6] = a[3];
    a[3] = t;
}
static void n(int *a) {
    int t = a[1];
    a[1] = a[2];
    a[2] = a[6];
    a[6] = a[5];
    a[5] = t;
}
static void s(int *a) {
    int t = a[1];
    a[1] = a[5];
    a[5] = a[6];
    a[6] = a[2];
    a[2] = t;
}
static void w(int *a) {
    int t = a[1];
    a[1] = a[3];
    a[3] = a[6];
    a[6] = a[4];
    a[4] = t;
}
int main() {
    std::map<char, std::function<void(int *)>> m = { { 'E', e }, { 'N', n }, { 'S', s }, { 'W', w } };
    int a[7];
    std::string op;
    for (int i = 1; i <= 6; ++i) {
        std::cin >> a[i];
    }
    std::cin >> op;
    for (auto&& e: op) {
        (m[e])(a);
    }
    std::cout << a[1] << std::endl;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int Xmin=0,Xmax,Ymin=0,Ymax,N;
  cin >> Xmax >> Ymax >> N;
  int x,y,a;
  for(int i=0;i<N;i++){
    cin >> x >> y >> a;
    if(a==1){
      Xmin=max(Xmin,x);
    }else if(a==2){
      Xmax=min(Xmax,x);
    }else if(a==3){
      Ymin=max(Ymin,y);
    }else{
      Ymax=min(Ymax,y);
    }
  }
  cout << max(0,Xmax-Xmin)*max(0,Ymax-Ymin) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
string s;
int k,f[1000005][2],ans=1e18;
int solve(string t){
	f[0][0]=0;f[0][1]=1;
	for(int i=1;i<t.size();i++){
		f[i][0]=min(f[i-1][1],f[i-1][0]+(t[i]!=t[i-1]?0ll:(ll)1e18));
		f[i][1]=min(f[i-1][1],f[i-1][0])+1;
	}
	return min(f[(int)t.size()-1][0],f[(int)t.size()-1][1]);
}
signed main(){
	cin>>s>>k;
	string t="";
	if(k<=200){
		for(int i=1;i<=k;i++)t+=s;
		cout<<solve(t)<<endl;
		return 0;
	}
	for(int i=1;i<=100+(k&1);i++)t+=s;
	int ans=solve(t);
	t+=s+s;
	int ans2=solve(t);
	cout<<ans+(k-100-(k&1))*(ans2-ans)/2<<endl;
	return 0;
}

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

bool isPrime(long long n){
    for(long long i=2;i*i<=n;i++){
        if(n%i == 0){
            return 0;
        }
    }
    return 1;
};

vector<int> p;

int main(){
    for(int i=2;i<=1000;i++){
        if(isPrime(i)) p.push_back(i);
    }
    int n;
    cin >> n;
    int cnt[1000]={0};
    for(int i=1;i<=n;i++){
        for(int j=0;j<p.size();j++){
            int m=i;
            while(m % p[j]==0){
                cnt[p[j]]++;
                m /= p[j];
            }
        }
    }
    ll ans=1;
    for(int i=0;i<p.size();i++){
        ans *= cnt[p[i]]+1;;
        ans %= 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,n,d,tmp,cnt,sum,i,j,a,b,c,mx = LLONG_MIN,mn = LLONG_MAX;

    string str,str1;
    map<int,int>mp;
    vector<int>v;
    set<int>s;


        cin>>a>>b;
        if(a>b)
            cout<<"safe\n";
        else
            cout<<"unsafe\n";

    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

int cp(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}

int main(void){
  int a,b,c,d,e,k;
  int flag=1;
  scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);
  if(b-a>k||c-a>k||d-a>k||e-a>k||c-b>k||d-b>k||e-b>k||d-c>k||e-c>k||e-d>k) puts(":(");
  else puts("Yay!");
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();

		int a_length = a.length();
		int b_length = b.length();

		int loop_cnt = a_length - b_length + 1;
		int answer = b_length;

		for (int i = 0; i < loop_cnt; i++) {
			int change_cnt = 0;
			for (int j = 0; j < b_length; j++) {
				if (a.charAt(i + j) != b.charAt(j)) {
					change_cnt++;
				}
			}
			if (change_cnt < answer) {
				answer = change_cnt;
			}
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 35728