akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
//include
//------------------------------------------
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int n;
int s[1000];
ll a[999];
int main() {
	cin >> n;
	REP(i,n){
		cin >> s[i];
	}
	sort(s, s+n);
	REP(i,n-1){
		a[i] = s[i+1]+s[i];
	}

	ll Mn=-1, Mm=1; // M = Mn / Mm
	int ab,cd;
	REP(i,n-1){
		ll p = s[i+1]-s[i];
		REP(j,n-1){
			if(abs(i-j)<2)continue;
			if(Mn*p <  Mm*a[j]){ // M < N
				Mn = a[j];Mm = p;
			}
		}
	}

	cout << fixed << (double)Mn / Mm;
	return 0;
}

Measured memory_bytes: 3244
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
# dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    # dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    # dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
# dump(A, B, C)
for i in range(1, N+1):
    # dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)


Measured memory_bytes: 65824
#include<cstdio>
using namespace std;
const int maxn=1005,TT=1e9+7;
int n,m,cnt,ud,lr,UD,LR;
long long K;
char mp[maxn][maxn];
struct ltl{
	long long a[2][2];
	inline ltl (int o,int p,int q,int r){
		a[0][0]=o,a[0][1]=p,a[1][0]=q,a[1][1]=r;
	}
	inline ltl operator *(ltl b){
		return ltl( (a[0][0]*b.a[0][0]+a[0][1]*b.a[1][0])%TT,
					(a[0][0]*b.a[0][1]+a[0][1]*b.a[1][1])%TT,
					(a[1][0]*b.a[0][0]+a[1][1]*b.a[1][0])%TT,
					(a[1][0]*b.a[0][1]+a[1][1]*b.a[1][1])%TT);
	}
};
inline long long pow(long long x,long long y){
	long long ret=1,w=x;
	while(1){
		if(y&1) ret=ret*w%TT;
		if(!(y>>=1)) return ret;
		w=w*w%TT;
	}
}
inline ltl pow(ltl x,long long y){
	ltl ret=ltl(1,1,0,0),w=x;
	while(1){
		if(y&1) ret=ret*w;
		if(!(y>>=1)) return ret;
		w=w*w;
	}
}
int main(){
	scanf("%d%d%lld",&n,&m,&K);
	for (int i=1;i<=n;i++) scanf("%s",mp[i]+1);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++) if(mp[i][j]=='#'){
		cnt++;
		if(i==1) ud+=mp[n][j]=='#';
		else UD+=mp[i-1][j]=='#';
		if(j==1) lr+=mp[i][m]=='#';
		else LR+=mp[i][j-1]=='#';
	}
	if(ud&&lr) puts("1");
	if(ud&&!lr) printf("%lld\n",pow(ltl(cnt,0,TT-UD,ud),K-1).a[0][0]);
	if(!ud&&lr) printf("%lld\n",pow(ltl(cnt,0,TT-LR,lr),K-1).a[0][0]);
	if(!ud&&!lr) printf("%lld\n",pow(cnt,K-1));
	return 0;
}

Measured memory_bytes: 1152
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()
  a=(l[0]+l[1])/2

  for x in l[2:]:
    a=(a+x)/2

  return a

# main()
print(main())


Measured memory_bytes: 6832
"""
重さと価値がそれぞれw_i,v_iであるようなn個の品物がある.
これらの品物の中から, 重さの総和がWを超えないように選んだ時の,
価値の総和の最大値を求めよ.
1<=n<=100, 1<=w_i<=10^7, 1<=v_i<=100, 1<=W<=10^9
"""
#-------------------------------------------------------------------------------

#入力
INF=2*10**9
n,W = map(int,input().split())
w=[0]*n
v=[0]*n
for i in range(n):
    x,y = map(int, input().split())
    w[i] = x
    v[i] = y
max_v=max(v)
dp = [[INF for i in range(n*max_v+1)] for j in range(n+1)]

#ここからメイン
dp[0][0]=0
for i in range(n):
    for j in range(n*max_v+1):
        if j<v[i]:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i])
ans=0
for i in range(n*max_v+1):
    if dp[n][i]<=W:
        ans=i
print(ans)


Measured memory_bytes: 173036
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int case1(int a, int b, int c, int d, int e, int f, int g)
{
	int ans=0;
	if(d>=1 && e>=1 && a%2)
	{
		ans+=6;
		a--;
		d--;
		e--;
	}
	ans+=b*2;
	ans+=(d/2)*4;
	ans+=(e/2)*4;
	d%=2;
	e%=2;
	ans+=(a/2)*4;
	ans/=2;
	return ans;
}

int case2(int a, int b, int c, int d, int e, int f, int g)
{
	int mn=min({a, d, e});
	int ans=0;
	ans+=6*mn;
	a-=mn;
	d-=mn;
	e-=mn;
	ans+=b*2;
	ans+=(d/2)*4;
	ans+=(e/2)*4;
	d%=2;
	e%=2;
	ans+=(a/2)*4;
	ans/=2;
	return ans;
}

int case3(int a, int b, int c, int d, int e, int f, int g)
{
	int ans=0;
	ans+=b*2;
	ans+=(d/2)*4;
	ans+=(e/2)*4;
	d%=2;
	e%=2;
	if(d==1 && e==1 && a>=1)
	{
		ans+=6;
		a--;
	}
	ans+=(a/2)*4;
	ans/=2;
	return ans;
}

int32_t main()
{
	IOS;
	int a, b, c, d, e, f, g;
	cin>>a>>b>>c>>d>>e>>f>>g;
	int ans=case1(a, b, c, d, e, f, g);
	int ans2=case2(a, b, c, d, e, f, g);
	int ans3=case3(a, b, c, d, e, f, g);
	cout<<max({ans, ans2, ans3});
	return 0;
}


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

int main() {
  int N, M, X, K, L;
  cin >> N >> M >> X;
  
  K = X-N;
  if(K < 0){
      cout << "NO" << endl;
  }
  else if(M < K){
      cout << "NO" << endl;
}
  else
  cout << "YES" << endl;
}


Measured memory_bytes: 256
n, q = map(int,(input().split()))
s = input()

lst = [0]
count = 0
for i in range(n-1):
    if s[i:i+2] == 'AC':
        count += 1
    lst.append(count)
    
for _ in range(q):
    l,r = map(int, input().split())
    print(lst[r-1] - lst[l-1])

Measured memory_bytes: 6100
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::prelude::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

const MOD: isize = 1_000_000_007;

fn main() {
    let N: usize = rd();
    // N以下の（A,B）の組
    // dp[i][10][10] // i 以下の数でAの末尾が{},Bの末尾が{}
    let mut cnt = vec![vec![0usize; 10]; 10];

    for i in 1..N + 1 {
        let (h, t) = hd(i);
        cnt[h][t] += 1;
    }

    let mut ans = 0usize;
    for i in 1..10 {
        for j in 1..10 {
            ans += cnt[i][j] * cnt[j][i];
        }
    }

    println!("{}", ans);
}
fn hd(n: usize) -> (usize, usize) {
    let t = n % 10;
    let mut h = t;
    let mut nt = n;
    while nt > 0 {
        h = nt % 10;
        nt /= 10;
    }
    (h, t)
}
fn rd<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let next: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    next.parse().ok().unwrap()
}


Measured memory_bytes: 4352
n=int(input())
li=list(map(int,input().split()))

if 0 in li:
  print(0)
  exit()
else:
  ans=1
  for i in li:
    ans*=i
    if ans>10**18:
        print(-1)
        exit()
    else:
        continue
    
print(ans)


Measured memory_bytes: 21484
#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(){
  string s;
  cin >> s;
  ll ans=0;
  rep1(i,s.size()-1){
    if(s[i]!=s[i-1]) ans++;   
  }
  ll ans2=0;
  for(int i=s.size()-2;i>=0;i--){
    if(s[i]!=s[i+1]) ans2++;
  }
  cout << min(ans, ans2) << endl;
  
  return 0;

}


Measured memory_bytes: 512
a, b = map(int, input().split())
def kansu(a):
    if a == 1:
        return 300000
    if a == 2:
        return 200000
    if a == 3:
        return 100000
    else:
        return 0
    
if a == 1 and b == 1:
    print(1000000)
    
else:
    print(kansu(a)+kansu(b))

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX=1e5+5;
struct edge{
    int start,endd;
}h[MAX];
int cnt,n,mian=1,now=1;
char a[MAX];
int main(){
    scanf("%s",a+1);
    n=strlen(a+1);
    if(a[n]!='0' || a[1]!='1'){
        printf("-1");
        return 0;
    }
    for(int i=1;i<n;i++){
        if(a[i]!=a[n-i]){
            printf("-1");
            return 0;
        }
        h[++cnt]=edge{mian,now+1};
        now++;
        if(a[i]=='1')mian=now;
    }
    for(int i=1;i<=cnt;i++)printf("%d %d\n",h[i].start,h[i].endd);
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
 
int main(){
    long long N;

    cin >> N;

    vector<long long> A(N,0);

    for(int i = 0; i < N - 1 ; i++){
        long long m;
        cin >> m;
        A[m-1]++;
    }

    for(int i = 0; i < N ; i++){
        cout << A[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4844
N, M = map(int, input().split())
g = [[] for _ in range(N + 1)]
for _ in range(M):
    x, y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)

ans = 0
todo = [(1, list(range(2, N + 1)))]
while todo:
    p, r = todo.pop()
    for np in g[p]:
        if np in r:
            if len(r) == 1:
                ans += 1
            else:
                nr = r[:]
                nr.remove(np)
                todo.append((np, nr))
print(ans)

Measured memory_bytes: 3064
import math
a = [int(input()) for _ in range(5)]
s = 0
m = 10
for i in range(5):
  s += math.ceil(a[i] / 10) * 10
  if a[i] % 10 > 0 and a[i] % 10 < m:
    m = a[i] % 10
print(s-(10-m))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

const int  MAX_N = 100000+ 1000;
int par[MAX_N];
int _rank[MAX_N];
void init(int n) {
  REP(i,n) {
    par[i] = i;
    _rank[i] = 0;
  }
}
int find(int x) {
  if(par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if(x==y) return ;
  if(_rank[x] < _rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if(_rank[x] == _rank[y]) _rank[x]++;
  }
}
bool same(int x, int y) {
  return find(x) == find(y);
}

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }
int main() {
  int N, M; cin>>N>>M;
  init(N);
  REP(i,M) {
    int	X, Y, Z; cin>>X>>Y>>Z;
    X--; Y--;
    unite(X, Y);
  }
  int ans = 0;
  REP(i,N) {
    if(find(i) == i) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String x=stdIn.nextLine();
			char c[]=x.toCharArray();
			if(c[0]=='0')
				break;
			int ans=0;
			for(int i=0;i<x.length();i++)
				ans+=c[i]-'0';
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 26760
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	long long n,s=0,t=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	sort(a,a+n);
	s+=a[n/2]-a[0];
	for(int j=0;j<n-2;j++){
	    if(j%2==0){
	        s=s-a[j/2]+a[n-j/2-1];
	    }
	    else{
	        s=s+a[n-j/2-1]-a[j/2+1];
	    }
	    //cout<<s<<endl;
	}
	sort(a,a+n,greater<>());
	t+=a[0]-a[n/2];
	for(int j=0;j<n-2;j++){
	    if(j%2==0){
	        t=t+a[j/2]-a[n-j/2-1];
	    }
	    else{
	        t=t-a[n-j/2-1]+a[j/2+1];
	    }
	    //cout<<s<<endl;
	}
	cout<<max(t,s);
	return 0;
}


Measured memory_bytes: 640
def main():
    x = int(input())
    n5 = {i:i**5 for i in range(-130, 131)}
    for i, v1 in n5.items():
        for j, v2 in n5.items():
            if v1 - v2 == x:
                print(i, j)
                return

if __name__ == "__main__":
    main()


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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
			cin.tie(0);							 \
			cout.tie(0);
#define PI 3.141592654

using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; } return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
void add(ll& x, ll v) { x = (x + v) % MOD; if (x < 0) x += MOD; }
//ll f[500005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }

void test_case() {

}

const int mxN = 1e5 + 1;


int main() {
	fastio;
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> mp;
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		++mp[a[i]];
		sum += a[i];
	}
	int q;
	cin >> q;
	while (q--) {
		int b, c;
		cin >> b >> c;
		sum -= (ll)mp[b] * b;
		sum += (ll)mp[b] * c;
		
		mp[c] += mp[b];
		mp[b] = 0;
		cout << sum << "\n";
	}
	return 0;
}

Measured memory_bytes: 8176
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
typedef unsigned long long ull;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	ull x, y;
	cin >> x >> y;
	ull count = 0;
	for (ull i = x; x <= y; x*=2) {
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define TRUE 1
#define FALSE -1
int size,A[MAX+1];

void swap( int  *a , int  *b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

void buildmaxHeapify(int k)
{
  int left,right,big;
  left=2*k;
  right=2*k+1;

  if(left<=size && A[left]>A[k])big=left;
  else big=k;
  if(right<=size && A[right] > A[big])big=right;

  if(big!=k)
    {
      swap(&A[k],&A[big]);
      buildmaxHeapify(big);
    }
}

int extract()
{
  int max;
  if(size<1)return FALSE;
  max=A[1];
  A[1]=A[size--];
  buildmaxHeapify(1);
  return max;
}

void increase(int k,int key)
{
  if(key<A[k])return;
  A[k]=key;
  while(k>1 && A[k/2]<A[k])
    {
      swap(&A[k],&A[k/2]);
      k=k/2;
    }
}

void insert(int key)
{
  size++;
  A[size]= FALSE;
  increase(size,key);
}

int main()
{
  int key;
  char order[8];
  while(1)
    {
      scanf("%s",order);
      if(strcmp(order,"end")==0)break;
	 if(strcmp(order,"insert")==0)
	{
	  scanf("%d", &key);
	  insert(key);
	}
      else printf("%d\n",extract());
    }
  return 0;
}

Measured memory_bytes: 4696
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = []
ans = 0
for i in range(n):
    a = list(map(int, input().split()))
    an = c
    for i in range(m):
        an += a[i] * b[i]
    if an > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n,k,q,a[100005]={},b;
	cin>>n>>k>>q;
	for(int i=0;i<q;i++)
	{
		cin>>b;
		a[b]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]+k-q>0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
def readinput():
    n,m=map(int,input().split())
    l=[]
    r=[]
    for i in range(m):
        li,ri=map(int,input().split())
        l.append(li)
        r.append(ri)
    return n,m,l,r

def main(n,m,l,r):
    lmax=1
    rmin=n
    for i in range(m):
        lmax=max(lmax,l[i])
        rmin=min(rmin,r[i])
    return max(rmin-lmax+1,0)

if __name__=='__main__':
    n,m,l,r=readinput()
    ans=main(n,m,l,r)
    print(ans)


Measured memory_bytes: 16740
#include <bits/stdc++.h>
#include <string>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define endl '\n'
const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
////////////////////////////////

int dp[MAX];
int h[MAX];

int32_t main(){
    fastio
    int n, k; cin >> n >> k;
    rep(i,1,n,1) cin >> h[i];
    dp[2] = abs(h[1] - h[2]);
    rep(i,3,n,1){
        dp[i] =  MOD;
        rep(j,1,k,1){
            if(i - j < 1) break;
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1792
s =[1,2,3,4,5,6,7,8,9,10,11,12,13]
h =[1,2,3,4,5,6,7,8,9,10,11,12,13]
c =[1,2,3,4,5,6,7,8,9,10,11,12,13]
d =[1,2,3,4,5,6,7,8,9,10,11,12,13]

n = gets.to_i
n.times{
  x,y = gets.split.map(&:to_s)
  y = y.to_i
  case
  when x == "S"
    s.delete(y)
  when x == "H"
    h.delete(y)
  when x == "C"
    c.delete(y)
  when x == "D"
    d.delete(y)
  else
    puts "nothing"
  end
}

s.each do |elem|
  print "S ", elem,"\n"
end
h.each do |elem|
  print "H ", elem,"\n"
end
c.each do |elem|
  print "C ", elem,"\n"
end
d.each do |elem|
  print "D ", elem,"\n"
end



Measured memory_bytes: 6872
prime = Array.new(10**6,1)
(2..1000).each{|i|
	j = i * i
	while j < 10**6
		prime[j] = 0
		j += i
	end
}
ans = Array.new(10**6,0)
(2..10**6).each{|i|
	ans[i] = prime[i].to_i + ans[i-1].to_i
}
while gets
	p ans[$_.to_i]
end

Measured memory_bytes: 21724
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<string> tb(21,string(21,' '));
    REP(i,n){
      int x,y;cin>>x>>y;
      tb[y][x]='*';
    }
    int m;cin>>m;
    int x=10,y=10;
    REP(i,m){
      char dc;
      int d,l;
      cin>>ws>>dc>>l;
      int dx[]={0,1,0,-1};
      int dy[]={1,0,-1,0};
      switch(dc){
        case 'N':
          d=0;
          break;
        case 'E':
          d=1;
          break;
        case 'S':
          d=2;
          break;
        case 'W':
          d=3;
          break;
        default:
        cout<<"error"<<endl;
      }
      REP(j,l){
        x+=dx[d];
        y+=dy[d];
        tb[y][x]=' ';
      }
    }
    bool exist=false;
    REP(i,21)REP(j,21){
      if(tb[i][j]=='*')exist=true;
    }
    if(exist)
      cout<<"No"<<endl;
    else
      cout<<"Yes"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
n=int(input())
inp=list(map(int,input().split()))
hoge=[0 for i in range(n)]
huga=[0 for i in range(n)]
for i in inp:
  huga[i-1]+=1
  hoge[i-1]=(huga[i-1]-1)*huga[i-1]
some=sum(hoge)//2
for i in inp:
  if(huga[i-1]==2):
    print(some-1)
  else:
    print(some-int(hoge[i-1]/huga[i-1]))

Measured memory_bytes: 26140
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	long double x;
		string u;

	long double ans = 0;
	for (Int i = 0; i < N; i++) {
		cin >> x >> u;
		if (u=="JPY") {
			ans += x;
		}
		else {
			ans += x * 380000;
		}
	}

	cout << fixed << setprecision(10) << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <cassert>

using ll = long long;

using namespace std;

using P = pair<bool, int>;
#define fi first
#define se second

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    for (auto &ai:a) cin >> ai;
    for (auto &bi:b) cin >> bi;
    int ans = 10000;
    int vals[n];
    for (int i=0; (i >> n) == 0; i++) {
        set<int> cards[51][2];
        for (int j=0; j<n; j++) {
            if ((i >> j) & 1) {
                vals[j] = a[j];
                cards[a[j]][j % 2].insert(j);
            } else {
                vals[j] = b[j];
                cards[b[j]][(j+1) % 2].insert(j);
            }
        }
        sort(vals, vals+n);
        int cnt = 0;
        for (int j=0; j<n; j++) {
            if (cards[vals[j]][j%2].empty()) {
                cnt = 10000;
                break;
            }
            auto itr = cards[vals[j]][j%2].begin();
            cards[vals[j]][j%2].erase(itr);
            vals[j] = *itr;
        }
        for (int i=0; i<n; i++) {
            for (int j=n-1; j>i; j--) {
                if (vals[j] < vals[j-1]) {
                    swap(vals[j], vals[j-1]);
                    cnt++;
                }
            }
        }
        ans = min(ans, cnt);
    }
    cout << (ans < 10000 ? ans : -1) << '\n';
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#define LL long long
LL N, K;
LL ans;
LL dp[100010];
int main() {
	std::cin >> N >> K;
	if (K == 0) {
		std::cout << N*N << std::endl;
		return 0;
	}
	for (int i = 2; i <= N; i++) {
		if (i - 1 < K)continue;
		ans += (i - K)*(N / i);
		if(N%i)ans += std::max((LL)0, N%i - K + 1);
	}
	std::cout << ans << std::endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int f[n][5][2];
	ll p[n][11];
	for(int i=0; i<n; i++){
		for(int j=0; j<5; j++){
			for(int k=0; k<2; k++){
				cin >> f[i][j][k];
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<11; j++){
			cin >> p[i][j];
		}
	}

	ll ans=-(ll)1e9;
	for(int i=1; i<(1<<10); i++){
		int t=i;
		ll sum=0;
		for(int j=0; j<n; j++){
			int cnt=0;
			for(int k=0; k<5; k++){
				for(int l=0; l<2; l++){
					if(((t>>(2*k+l))%2)==1 && f[j][k][l]==1) cnt++;
				}
			}
			sum+=p[j][cnt];
		}
		ans=max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (int)1e9
#define LINF 1e18
typedef long long ll;


using mint = modint998244353;

vector<vector<mint>> ds(10,vector<mint>(300000,0));

struct S{
    mint d;
    int size;
};


S op(S a, S b){
    if(b.size==0){
        return a;
    }else if(a.size==0){
        return b;
    }else{
        return {a.d* ((mint)10).pow(b.size) + b.d, a.size+b.size};
    }
}

S e(){
    return {0,0};
}

using F = int;

S mapping(F f, S x){
    if(f==0){
        return x;
    }else{
        return {ds[f][x.size], x.size};
    }
}

F composition(F f, F g){
    return (f==0?g:f);
}

F id(){
    return 0;
}

int main() {
    int N,Q; cin >> N >> Q;

    FOR(i,1,10){
        REP(j,200500){
            ds[i][j+1] = ds[i][j]*10 + i;
        }
    }

    lazy_segtree<S,op,e,F,mapping,composition,id> seg(N);
    REP(i,N){
        seg.set(i,{1,1});
    }

    

    REP(i,Q){
        int l,r,d; cin >> l >> r >> d;
        l--;
        seg.apply(l,r,d);
        cout << seg.all_prod().d.val() << endl;
    }
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	cout << n * (n-1) / 2 + m * (m-1) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s; 
	if( s[0] == '7' or s[1] == '7' or s[2] == '7' ) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;

int main()
{
	char str[1001];
	scanf("%s", str);
	int len = strlen(str);
	int i = 0;
	int n = 0, e = 0, w = 0, s = 0;
	while (str[i])
	{
		if (str[i] == 'N')
			n++;
		if (str[i] == 'S')
			s++;
		if (str[i] == 'E')
			e++;
		if (str[i] == 'W')
			w++;
		i++;
	}
	if ((n > 0 && s == 0) || (n == 0 && s > 0))
	{
		printf("No\n");
		return (0);
	}
	if ((e > 0 && w == 0) || (e == 0 && w > 0))
	{
		printf("No\n");
		return (0);
	}
	printf("Yes\n");
	return (0);
}

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

int main(){
    long long a,b,n;
    cin >> a >> b >> n;
    long long y;
    if(b>n){
        y = floor(a*n/b);
    }
    else{
        y = floor(a*(b-1)/b);
    }
    cout << y << endl;
    return 0;
}

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

int cube_all;
int cube_num[100];
int cube_map[100][100];
int cube_where[100];

/* syo-zyun */
int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int main(void) {
	int i,j;
	int which,where;
	int which_x,which_y,where_x,where_y;
	while(1) {
		scanf("%d",&cube_all);
		if(cube_all==0)break;
		for(i=0;i<cube_all;i++) {
			cube_num[i]=1;
			cube_map[i][0]=i+1;
		}
		while(1) {
			scanf("%d%d",&which,&where);
			if(which==0 && where==0)break;
			if(which==where)continue;
			which_x=which_y=where_x=where_y=0;
			for(i=0;i<cube_all;i++) {
				for(j=0;j<cube_num[i];j++) {
					if(cube_map[i][j]==which) {
						which_x=i;
						which_y=j;
					} else if(cube_map[i][j]==where) {
						where_x=i;
						where_y=j;
					}
				}
			}
			if(where==0) {
				if(which_y>0) {
					for(i=which_y;i<cube_num[which_x];i++) {
						for(j=0;j<cube_all;j++) {
							if(cube_num[j]<=0) {
								cube_num[j]=1;
								cube_map[j][0]=cube_map[which_x][i];
								break;
							}
						}
					}
					cube_num[which_x]=which_y;
				}
			} else {
				if(which_x!=where_x) {
					for(i=which_y+1;i<cube_num[which_x];i++) {
						for(j=0;j<cube_all;j++) {
							if(cube_num[j]<=0) {
								cube_num[j]=1;
								cube_map[j][0]=cube_map[which_x][i];
								break;
							}
						}
					}
					cube_num[which_x]=which_y;
					cube_map[where_x][cube_num[where_x]++]=which;
				} else if(which_y<where_y) {
					for(i=which_y+1;i<cube_num[which_x];i++) {
						for(j=0;j<cube_all;j++) {
							if(cube_num[j]<=0) {
								cube_num[j]=1;
								cube_map[j][0]=cube_map[which_x][i];
								if(cube_map[j][0]==where) {
									where_x=j;
								}
								break;
							}
						}
					}
					cube_num[which_x]=which_y;
					cube_map[where_x][cube_num[where_x]++]=which;
				}
			}
		}
		qsort(cube_num,cube_all,sizeof(int),qsort_comp);
		for(i=0;i<cube_all;i++) {
			if(cube_num[i]>0)printf("%d\n",cube_num[i]);
		}
		puts("end");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  map<string ,int> m;
  REP(i,N){
    string S;
    cin>>S;
    m[S]++;
  }
  string A[4]={"AC","WA","TLE","RE"};
  REP(i,4)cout<<A[i]<<" x "<<m[A[i]]<<endl; 
  return 0;
}


Measured memory_bytes: 3632
a = int(input())
b_str = list(input().split())
b = [int(s) for s in b_str]

check_cnt = 0
check_flg = True

max_item = 0

for idx, item in enumerate(b):
	
	if idx == 0:
		max_item = item
		continue
	
	if max_item <= item:
		max_item = item
		continue
	elif max_item - 1 == item:
		continue
	else:
		check_flg = False
		break
		
if	check_flg:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 14864
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;
using std::make_pair;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

const int MAX_N = 507;

int A[MAX_N][MAX_N], H, W;

void solve() {
	cin >> H >> W;

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			cin >> A[i][j];

			A[i][j] &= 1;
		}
	}

	vector<pair<pii, pii>> answ;

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W - 1; ++j) {
			if(A[i][j] & 1) {
				A[i][j] ^= 1;
				A[i][j + 1] ^= 1;

				answ.emplace_back(make_pair(i, j), make_pair(i, j + 1));
			}
		}
	}

	for(int i = 0; i < H - 1; ++i) {
		if(A[i][W - 1] & 1) {
			A[i][W - 1] ^= 1;
			A[i + 1][W - 1] ^= 1;

			answ.emplace_back(make_pair(i, W - 1), make_pair(i + 1, W - 1));
		}
	}

	cout << len(answ) << '\n';

	for(auto& op: answ) {
		cout << op.first.first + 1 << ' ' << op.first.second + 1 << ' ' << op.second.first + 1 << ' ' << op.second.second + 1 << '\n';
	}
}

int main() {
	init_IO();
	solve();

	return 0;
}


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

int main(){
    using namespace std;
    unsigned long H, W, K;
    cin >> H >> W >> K;
    unsigned long c{0};
    vector<vector<unsigned long>> a(H, vector<unsigned long>(W));
    for(unsigned long i = 0; i < H; ++i){
        string s;
        cin >> s;
        for(unsigned long j = 0; j < W; ++j)if(s[j] == '#')a[i][j] = ++c;
    }
    for(auto& i : a){
        partial_sum(i.begin(), i.end(), i.begin(), [](auto a, auto b){return max(a, b);});
        for(unsigned long j = W - 1; j--; )if(!i[j])i[j] = i[j + 1];
    }
    for(unsigned long i = 1; i < H; ++i)for(unsigned long j = 0; j < W; ++j)a[i][j] = max(a[i][j], a[i - 1][j]);
    for(unsigned long i = H - 1; i--; )for(unsigned long j = 0; j < W; ++j)if(!a[i][j])a[i][j] = a[i + 1][j];
    for(const auto& i : a){
        for(const auto& j : i)cout << j << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
//Code by : Abhishek Tiwari
//codechef.com/users/devil_within || hackerearth.com/@devil_within
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int 
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repr(i,a,b) for(int i=(a);i>(b);--i)
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define pii pair<int,int> 
#define ff first
#define ss second 
#define mod 1000000007
#define inf 10000000000000
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd(a,b)
using namespace std;

/*******************************************************************************************/
/*******************************************************************************************/
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { 
    os<<"["; for(int i=0;i<v.size()-1; ++i)os<<v[i]<<", ";os<<v[v.size()-1]<<"]\n"; return os; 
} 
template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { 
    os<<"{"; for(auto it : v) { os<<it; if(it!=*v.rbegin()) os<<", "; } os<<"}\n"; 
    return os; 
}
template <typename T, typename S> ostream& operator<<(ostream& os, const map<T, S>& v) { 
    os<<"{"; for(auto it:v){ os<<"("<<it.first<<" : "<<it.second<<")"; if(it!=*v.rbegin()) os<<", "; } os<<"}\n"; 
    return os; 
}
template <typename T, typename S> ostream& operator<<(ostream& os, const pair<T, S>& v) { 
    os<<"("; os<<v.first<<", "<< v.second<<")"; 
    return os; 
} 
template<typename T> T maxi(T a,T b){return a>b ? a:b;}
template<typename T> T mini(T a,T b){return a<b ? a:b;}
/*******************************************************************************************/
/*******************************************************************************************/
int fpow(int x, int y, int p); 

int solve(int i , int j , vector<int> &a, vector<vector<int>> &dp ,int sum)
{
    if(dp[i][j]!=inf)
        return dp[i][j];
    if(i==j)
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    int ans = inf;
    int newsum = 0;
    rep(k , i , j)
    {
        newsum+=a[k];
        ans = min( ans , solve(i , k , a, dp , newsum) + solve(k+1 , j , a, dp ,sum - newsum) + sum);
    }
    dp[i][j] = ans;
    return dp[i][j];
}
int32_t main()  
{
#ifndef ONLINE_JUDGE
//freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);freopen("error.txt" , "w" , stderr);
#endif
fio;
int tcases = 1;
//cin>>tcases;
for(int tcase = 1 ; tcase <= tcases ; ++tcase)
{
    int n;
    cin>>n;
    vector<int> a(n);
    vector<vector<int>> dp(n);
    rep(i , 0 , n)
        {
            cin>>a[i];
            dp[i].resize(n , inf);
        }
    int sum = accumulate(all(a) , 0LL);  
    cout<<solve(0 , n-1 , a, dp , sum);
    //cout<<"Case #"<<tcase<<": ";
}
return 0;
}



//Functions 

int fpow(int x, int y, int p) { 
    int res = 1; 
   x = x % p;  
   while (y > 0) { 
     if (y & 1) 
        res = (res * x) % p; 
     y = y >> 1; 
        x = (x * x) % p; 
    } 
    return res; 
} 


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> H(N);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		sum += H[i];
	}
	int ans = 0;
	while (sum > 0) {
		for (int i = 0; i < N; i++) {
			if (H[i] > 0) sum--;
			else if (i > 0 && H[i - 1] >= 0) ans++;
			if (i == N - 1 && H[i] > 0) ans++;
			H[i]--;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        if (n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


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

using namespace std;

const int INF = 1000000000;

struct Edge{
  int a;
  int b;
  int c;
};

int main(){
  int N, M;
  scanf("%d%d", &N, &M);
  
  int dist[N][N];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(i == j) dist[i][j] = 0;
      else dist[i][j] = INF;
    }
  }
  
  Edge edge[M];
  for(int e = 0; e < M; e++){
    scanf("%d%d%d", &edge[e].a, &edge[e].b, &edge[e].c);
    edge[e].a--;
    edge[e].b--;
    dist[edge[e].a][edge[e].b] = edge[e].c;
    dist[edge[e].b][edge[e].a] = edge[e].c;
  }
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]);
      }
    }
  }
  
  int candidates = 0;
  
  for(int e = 0; e < M; e++){
    int s = 0;
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(dist[i][edge[e].a] + edge[e].c + dist[edge[e].b][j] == dist[i][j]){
          s = 1;
        }
      }
    }
    
    if(!s) candidates++;
  }
  
  printf("%d\n", candidates);
  
  return 0;
}

Measured memory_bytes: 256
h, w, n = gets.split.map(&:to_i)
ps = Hash.new { 0 }
n.times do
  a, b = gets.split.map(&:to_i)
  (a-1..a+1).each do |i|
    (b-1..b+1).each do |j|
      ps[[i, j]] += 1 if 1 < i && i < h && 1 < j && j < w
    end
  end
end

rs = Array.new(10) { 0 }
x = 0
ps.each do |_, n|
  x += 1
  rs[n] += 1
end
rs[0] = (h-2)*(w-2) - x

puts rs

Measured memory_bytes: 106516
/*
dpで書いたやつの解説

”i円までの最適を考える”
という感じで考える

i円集めるには高々i回
操作すればいいので
各要素をdp[i]=iで初期化

要素の個数は
9^7=4782969なので
5000000くらいあれば
十分

あとは配るdpで各要素を
最小化する

dp[n]を出力

補足として
要素数に十分ゆとりがあるから
i番目をi円集める最小
にするとわかりやすいかなと思って
出力がdp[n]でよい

では本文をどうぞ
*/
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include <vector>
#include <cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n; cin>>n;
  vll dp(5000000);
  FOR(i,1,5000000){
    dp[i]=i;
  }
  FOR(i,0,n){
    FOR(j,0,8){
      ll a=pow(6,j);
      ll b=pow(9,j);
      chmin(dp[i+a],dp[i]+1);
      chmin(dp[i+b],dp[i]+1);
    }
  }
  cout<<dp[n]<<"\n";
}

Measured memory_bytes: 42332
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 105;
int n, x[N], ans = 2e9;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", x + i);
	for (int j = 1; j <= 100; j++) {
		int cnt = 0;
		for (int i = 1; i <= n; i++) cnt += (x[i] - j) * (x[i] - j);
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    ll N;
    cin >> N;
    FOR(i, 1, 10){
        FOR(j, 1, 10){
            if (i*j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int arr[100005];
int main()
{
fast();
int a=D(),b=D();
if(max(a,b)>8)
    cout<<":("<<endl;
else
    cout<<"Yay!"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <set>
#include <queue>
#include <climits>
#include <limits>
#include <map>
#define inf 1000000000000000000

#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
#define pair(A, B) make_pair(A, B)

using namespace std;

typedef pair<ll, ll> pi;
typedef pair<pair<ll, ll>, ll> pii;

void perform() {
  string n; cin >> n;
  if(n.find("7") != string::npos) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1; //cin >> t;
  while (t--) {perform();}
}


Measured memory_bytes: 3100
from collections import Counter
N, *D = map(int, open(0).read().split())
MOD = 998244353

ctr = Counter(D)
ans = 1
for i in range(1, max(ctr) + 1):
    ans = ans * ctr[i - 1] ** ctr[i] % MOD

if ctr[0] == 1 and D[0] == 0:
    print(ans)
else:
    print(0)


Measured memory_bytes: 62008
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=105;
const int MOD=1000000007;

int n,f[N][N],h[N],w[N],m;

int ksm(int x,int y)
{
    if (y<0) return 1;
    int ans=1;
    while (y)
    {
        if (y&1) ans=(LL)ans*x%MOD;
        x=(LL)x*x%MOD;y>>=1;
    }
    return ans;
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&h[i]),w[++m]=h[i];
    std::sort(w+1,w+m+1);
    m=std::unique(w+1,w+m+1)-w-1;
    for (int i=1;i<=n;i++) h[i]=std::lower_bound(w+1,w+m+1,h[i])-w;
    f[0][0]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=h[i]+1;j<=h[i-1];j++) (f[i][0]+=f[i-1][j]*2%MOD)%=MOD;
        (f[i][0]+=f[i-1][0]*2%MOD)%=MOD;
        for (int j=1;j<=h[i];j++)
        {
            f[i][j]=(LL)f[i-1][j]*ksm(2,w[h[i]]-w[h[i-1]])%MOD;
            if (h[i-1]>=j) continue;
            if (j>1) (f[i][j]+=(LL)f[i-1][0]*(ksm(2,w[j]-w[j-1])-1)%MOD*2%MOD*ksm(2,w[h[i]]-w[j])%MOD)%=MOD;
            else (f[i][j]+=(LL)f[i-1][0]*(ksm(2,w[j])-2)%MOD*ksm(2,w[h[i]]-w[j])%MOD)%=MOD;
        }
    }
    
    
    int ans=0;
    for (int i=0;i<=m;i++) (ans+=f[n][i])%=MOD;
    printf("%d",ans);
    return 0;
    return 0;
}


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

using namespace std;

int main() 
{
    int n, q, x, y, z;
    scanf("%d %d", &n, &q);
    
    list<int> l[n];
    
    for(int i = 0; i < q; i++)
    {
        scanf("%d %d", &x, &y);
        
        if(x == 0)
        {
            scanf("%d", &z);
            l[y].push_back(z);
        }
        else if(x == 1)
        {
            if((int)l[y].size() > 0)
            {
                auto it = l[y].begin();
                for(; it != --l[y].end(); it++)
                   printf("%d ", *it);
                printf("%d\n", *it);
            }
            else
            {
                printf("\n");
            }
        }
        else if(x == 2)
        {
            scanf("%d", &z);
            l[z].splice (l[z].end(), l[y]); 
        }
    }

    return 0;
}


Measured memory_bytes: 18756
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define FR first
#define SE second
#define inf 0x3f3f3f3f3f3f3f3fLL

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pr;

ll s[100005],t[100005],maxn;
bool rev[100005];
int n;

ll calc(ll t1,ll t2,ll now) {
  int p=lower_bound(t+1,t+n+1,t1)-t;
  int q=upper_bound(t+1,t+n+1,t2)-t-1;
  now+=s[q]-s[p]+((rev[q])?1:-1)*(t2-t[q]);
  if (now<0) now=0;
  if (now>maxn) now=maxn;
  return now;
}

namespace SGT {

ll minn[400000],maxn[400000];

void build(int l,int r,int o) {
  minn[o]=inf;maxn[o]=-inf;
  if (l==r) return;
  int m=((l+r)>>1);
  build(l,m,o*2);
  build(m+1,r,o*2+1);
}

void update(int l,int r,int o,int p,pr q) {
  if (l==r) {
  	minn[o]=q.FR;maxn[o]=q.SE;
  }
  else {
  	int m=((l+r)>>1);
  	if (m>=p) update(l,m,o*2,p,q);
  	else update(m+1,r,o*2+1,p,q);
  	minn[o]=min(minn[o*2],minn[o*2+1]);
  	maxn[o]=max(maxn[o*2],maxn[o*2+1]);
  }
}

int query1(int l,int r,int o,ll p) {
  if (l==r) return l;
  else {
  	int m=((l+r)>>1);
  	if (minn[o*2]<p) return query1(l,m,o*2,p);
  	else return query1(m+1,r,o*2+1,p);
  }
}

int query2(int l,int r,int o,ll p) {
  if (l==r) return l;
  else {
  	int m=((l+r)>>1);
  	if (maxn[o*2]>p) return query2(l,m,o*2,p);
  	else return query2(m+1,r,o*2+1,p);
  }
}

}

int getnext(ll t) {
  int ans=n+1;
  ans=min(ans,SGT::query1(1,n+1,1,-t));
  ans=min(ans,SGT::query2(1,n+1,1,maxn-t));
  return ans;
}

int fa[100005][20];

int query(int x,ll t1) {
  for(int i=19;i>=0;i--)
    if (fa[x][i]&&t[fa[x][i]]<=t1) x=fa[x][i];
  return x;
}

int main() {
  scanf("%lld%d",&maxn,&n);
  n++;
  for(int i=2;i<=n;i++) {
  	scanf("%lld",&t[i]);
  	s[i]=s[i-1]+((rev[i-1])?1:-1)*(t[i]-t[i-1]);
    rev[i]=rev[i-1]^1;
  }
  SGT::build(1,n+1,1);
  SGT::update(1,n+1,1,n+1,pr(-inf,inf));
  t[n+1]=inf;
  for(int i=n;i>0;i--) {
  	fa[i][0]=getnext(((rev[i])?0:maxn)-s[i]);
  	SGT::update(1,n+1,1,i,pr(s[i],s[i]));
  }
  for(int i=n;i>0;i--)
    for(int j=1;j<20;j++) fa[i][j]=fa[fa[i][j-1]][j-1];
  int m;
  scanf("%d",&m);
  for(int i=1;i<=m;i++) {
  	ll x=0,y=0;
  	scanf("%lld%lld",&x,&y);
  	int p=getnext(y);
  	if (t[p]<=x) {
  		int q=query(p,x);
  		printf("%lld\n",calc(t[q],x,(rev[q])?0:maxn));
	  }
	else printf("%lld\n",calc(0,x,y));
  }
  return 0;
}

Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){
    
    string odd,even;
    cin>>odd>>even;
    int i=0;
    while(i<odd.l() && i<even.l()){
        cout<<odd[i]<<even[i];
        ++i;
    }
    while(i<odd.l()){
        cout<<odd[i++];
    }
    while(i<even.l()){
        cout<<even[i++];
    }
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int v4, v2, v1;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (x % 4 == 0)
            v4++;
        else if (x % 2 == 0)
            v2++;
        else
            v1++;
    }
    if (v1 <= v4 || (v1 == v4 + 1 && v1 + v4 == n))
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256