akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){

  int x, y;
  int a[1000][1000];

  cin>>x>>y;

  for(int i=0; i<x; i++){
    a[i][y]=0;
    for(int j=0; j<y; j++){
      cin>>a[i][j];
      a[i][y]=a[i][y]+a[i][j];
    }
  }

  for(int j=0; j<y; j++){
    a[x][j]=0;
    for(int i=0; i<x; i++){
      a[x][j]=a[x][j]+a[i][j];
    }
  }

  for(int i=0; i<x; i++){
    a[x][y]=0;
    for(int j=0; j<y; j++){
      a[x][y]=a[x][y]+a[x][j];
    }
  }

  for(int i=0; i<x+1; i++){
    for(int j=0; j<y+1; j++){
      cout<<a[i][j];
      if(j!=y){
        cout<<" ";
      }
    }
    cout<<endl;
  }
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define FOR(I,N) for(I=0;I<N;++I)
ll n;
vector<ll> h, memo;

ll DP(ll x)
{
	if(memo[x] != -1)
		return memo[x];
	ll p = DP(x+1)+abs(h[x]-h[x+1]);
	ll q = DP(x+2)+abs(h[x]-h[x+2]);
	memo[x]=min(p,q);
	return memo[x];
}

int main()
{
	ll i,j;
	cin>>n;	
	FOR(i,n)
	{
		cin>>j;
		h.pb(j);
		memo.pb(-1);
	}
	memo[n-1]=0;
	memo[n-2]= abs(h[n-1]-h[n-2]);
	cout<<DP(0);
}

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

ll gcd(ll x, ll y){
	while(1){
		if(x < y) swap(x, y);
		if(!y) break;
		x %= y;
	}
	return x;
}

int main(){
	int n; cin >> n;
	double a;
	if(n%2 == 0){
		a = n/2;
	}else{
		a = (n+1)/2;
	}
	cout << setprecision(7) << a/double(n) << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n;
    cin>>n;
    int p=1000;
    while(p<n) p+=1000;
    cout<<p-n<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

bool isMatch(string sub, string obj) {
  for (int i = 0; i < sub.size(); i++) {
    if (!(sub[i] == '?' || sub[i] == obj[i])) {
      return false;
    }
  }
  return true;
}

int main() {
  int pos = -1;
  string sd, t, tmp;
  cin >> sd;
  cin >> t;
  vector<string> ans;
  bool flag = false;

  if (sd.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = sd.size() - t.size(); i >= 0; i--) {
    if (isMatch(sd.substr(i, t.size()), t)) {
      tmp = sd;
      for (int j = 0; j < sd.size(); j++) {
        if (i <= j && j < i + t.size()) {
          tmp[j] = t[j - i];
        } else if (sd[j] == '?') {
          tmp[j] = 'a';
        }
      }
      ans.push_back(tmp);
    }
  }
  if (ans.empty()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

var po int64 = 1e9 + 7

func main() {
	var N, K int64
	fmt.Scan(&N, &K)

	var ans int64 = 0

	are := make(map[int64]int64)
	for i := K; i > 0; i-- {
		are[i] = pow(K/i, N) % po
		for j := int64(2); j*i <= K; j++ {
			are[i] = (are[i] - are[j*i] + po) % po
		}
		ans = (ans + (are[i]*i)%po) % po
	}

	fmt.Println(ans)
}

func pow(x, n int64) int64 {
	ans := int64(1)
	for n > 0 {
		if n%int64(2) != 0 {
			ans = (ans * x) % po
		}
		x = (x * x) % po
		n /= int64(2)
	}
	return ans
}


Measured memory_bytes: 7600
INF=10**30
from heapq import heappush,heappop,heapify
def dijkstra(G,coin,s,n):
    que=[(0,[coin,s])]
    dist=[[INF]*n for i in range(2501)]
    dist[coin][s]=0
    while que:
        mincost,co=heappop(que)
        nowc,nowv=co[0],co[1]
        if(mincost>dist[nowc][nowv]):
            continue
        for v,c,x in G[nowc][nowv]:
            if(dist[nowc][nowv]+c<dist[x][v]):
                dist[x][v]=dist[nowc][nowv]+c
                heappush(que,(dist[x][v],[x,v]))
    return dist

N,M,S=map(int,input().split())
if(S>=2500):
    S=2500
G=[[[] for i in range(N)] for i in range(2501)]
for i in range(M):
    u,v,a,b=map(int,input().split())
    u,v=u-1,v-1
    for i in range(2501):
        if i-a>=0:
            G[i][u].append([v,b,i-a])
            G[i][v].append([u,b,i-a])
for i in range(N):
    c,d=map(int,input().split())
    for j in range(2500):
        if j+c<=2500:
            G[j][i].append([i,d,j+c])

dist=dijkstra(G,S,0,N)

for i in range(1,N):
    res=10**30
    for j in range(2501):
        res=min(res,dist[j][i])
    print(res)

Measured memory_bytes: 169596
def main():
    N=int(input())
    for h in range(1,3501):
        for n in range(h,3501):
            a=4*h*n-N*(h+n)
            b=N*h*n
            if a>0 and b%a==0:
                print(h,n,b//a)
                return

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
temp_diff = 10**6
ans = 0
for i in range(n):
    if abs(t-h[i]*0.006-a) < temp_diff:
        temp_diff = abs(t-h[i]*0.006-a)
        ans = i+1
print(ans)

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

int main(){
    int a,b,c,p,q,r;
	cin >> a >> b >> c;
     p = a+b;
     q = a+c;
     r = b+c;
    if(p>=q){
        if(q >= r){
            cout << r;
        }else{
            cout << q;
        }
    }else{
        if(p >= r){
            cout << r;
        }else{
            cout << p;
        }
    }
}

Measured memory_bytes: 3620
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{

    ll i,j,k=0,c1=0,c2=0;
    ll n;
    cin>>n;
    for(i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        if(x%2)
            c1++;
    }
    if(c1%2==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;
 
int main()
{
    NFS
 	ll n,a,b;
 	cin>>n>>a>>b;
 	ll di=n/(a+b);
 	ll r=n%(a+b);
 	ll ans=di*a;
 	if(r<a)
 		ans+=r;
 	else
 		ans+=a;
 	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[])
{
  using namespace std;
  int t;
  cin >> t;
  int h = t / 3600;
  int m = (t - h * 3600) / 60;
  int s = t - h * 3600 - m * 60;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[])
{
    int n, x, t;
    cin >> n >> x >> t;

    int ans = n / x * t;
    if (n % x != 0)
    {
        ans += t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 2e5+1)
	sc.Buffer(buf, 2e5+1)

	sc.Scan()
	S := sc.Bytes()
	count := 0
	for i := 0; i < len(S); {
		if i == len(S)-1 {
			count++
			break
		} else if i == len(S)-2 {
			if S[i] == S[i+1] {
				count++
				break
			} else {
				count += 2
				break
			}
		} else {
			if S[i] == S[i+1] {
				count += 2
				i += 3
			} else {
				count++
				i++
			}
		}
	}
	fmt.Println(count)
}


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

using namespace std;

int n, m, k;

int main()
{
    while(~scanf("%d %d %d", &n, &m, &k)){
        int ans=0;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=m;j++){
                if((i*abs(m-j)+j*abs(n-i))==k){
                    ans=1;
                    //cout<<i<<"  "<<j<<endl;
                }
            }
            if(ans)break;
        }
        printf("%s\n", ans?"Yes":"No");
    }
    return 0;
}


Measured memory_bytes: 256
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll gcd(ll a, ll b)
{
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x %= p;
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll po(ll base, ll powerRaised)
{
  if (powerRaised != 0)
    return (base * po(base, powerRaised - 1));
  else
    return 1;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k;
  cin >> n >> k;
  vector<ll> v;
  for (int i = 0; i < n; i++)
  {
    ll x;
    cin >> x;
    v.pb(x);
  }
  sort(v.begin(), v.end());
  ll sum = 0;
  for (int i = 0; i < n - k; i++)
    sum += v[i];
  cout << sum;
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define cases           int T;cin>>T;for(int TC=1;TC<=T;TC++)
#define FastRead        ios_base::sync_with_stdio(0)
#define power(n,i)      (long long)ceil(pow(n,i))
#define ABS(x)          ((x)<0?-(x):(x))
const long long inf = 10000000000000;
int h[100005];
long long dp[100005];
int n;
long long call(int i)
{
    if(i==n-1)
      return 0;
    else if(i>=n)
      return inf;
 
    if(dp[i]!=-1)
      return dp[i];
 
    long long p1=call(i+1)+ABS(h[i]-h[i+1]); 
    long long p2=call(i+2)+ABS(h[i]-h[i+2]);
 
    return dp[i]=min(p1,p2);
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)
      cin>>h[i];
    cout<<call(0)<<endl;
   
}

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	ll n;
	cin >> n;
	while (n > 0) {
		int a = (int)sqrt(n);
		if (a*a==n) {
			cout << n << endl;
			break;
		}
		n--;
	}
	return 0;
}



Measured memory_bytes: 256
class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
def diff(p1, p2):
    return abs(p1.x - p2.x) + abs(p1.y - p2.y)
N, M = map(int, raw_input().split())
S = []
for i in xrange(N):
    x, y = map(int, raw_input().split())
    s = Point(x, y)
    S.append(s)
C = []
for i in xrange(M):
    x, y = map(int, raw_input().split())
    c = Point(x, y)
    C.append(c)
for s in S:
    index = None
    dist = 1e9
    for i, c in enumerate(C):
        d = diff(s, c) 
        if d < dist:
            dist = d
            index = i
    print index + 1

Measured memory_bytes: 2696
#include <iostream>

using namespace std;

int main()
{
	unsigned int n;
	unsigned int a[100];

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



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

int main() {
  int N, M, count = 0;
  cin >> N >> M;
  vector<int> ver(N);
  for (int i = 1; i <= N; i++) {
    ver.at(i - 1) = i;
  }
  bool judge = false;
  bool judge2 = true;
  vector<int> a(M), b(M);
  for (int i = 0; i < M; i++) cin >> a.at(i) >> b.at(i);
  do {
    if (ver.at(0) != 1) break;
    judge2 = true;
    for (int j = 0; j < N - 1; j++) {
      judge = false;
      for (int k = 0; k < M; k++) {
        if (ver.at(j) == a.at(k)) {
          if (ver.at(j + 1) == b.at(k)) {
            judge = true;
            break;
          }
        }
        if (ver.at(j) == b.at(k)) {
          if (ver.at(j + 1) == a.at(k)) {         
            judge = true;
            break;
          }
        }
      }
      if (!judge) {
        judge2 = false;
        break;
      }
    }
    if (judge2) {
      count++;
    }
  } while(next_permutation(ver.begin(), ver.end()));
  cout << count << endl;
}

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

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) 
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) 
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) 
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) 
#define forrc(i,r,l) for (int i= (int)(r); i>= (int)(l); --i)

#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 


#define tr(c,i) for(_typeof_((c)).begin() i = (c).begin(); i != (c).end(); i++)


#define present(c,x) ((c).find(x) != (c).end())


#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
typedef long long ll;
typedef unsigned long long int ull;

const int MOD=1000000007;
int no_of_bits(long long n)
{
    int count=0;
    while(n>0)
    {
        n=n>>1;
        count++;
    }
    return count;
}
long long gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
void printFrequency(vector<int> v) 
{ 
    unordered_map<int, int> M; 
  
     
    for (int i = 1; i<v.size(); i++) { 
  
        if (M.find(v[i]) == M.end()) { 
            M.insert(make_pair(v[i], 1)); 
        } 
 
        else { 
            M[v[i]]++; 
        } 
    } 

}
void add_self(int &a, int b){
  a+=b;
  if(a>=MOD){
    a-=MOD;
  }
}

void sub_self(int &a, int b){
  a-=b;
  if(a<0){
    a+=MOD;
  }
}

int search(vi x,int n,int i){
  int l=0,h=n-1,mid;
  while(l<=h){
    mid=(l+h)/2;
    if(x[mid]<i){
      l=mid+1;
    }else{
      h=mid-1;
    }
  }
  return l;
}
bool check9(string s){
    for(int i=0;i<s.size();i++) if(s[i]!='9') return 0;
    return 1;
}
void swap(int &a,int &b){
    int c=a;
    a=b;
    b=c;
}
const int INF=-2000;
const ll INF_=1e13;
void solve(){
   int n;
  cin>>n;
  vector<int> v(100000);
  long long sum=0;
  for(int i=0;i<n;i++)
  {
    int x;
     cin>>x;
    sum+=x;
    v[x-1]++;
  }
  int m;
  cin>>m;
  for(int i=0;i<m;i++)
  {
    int b,c;
    cin>>b>>c;
    v[c-1]=v[c-1]+v[b-1];
    
    sum+=(c-b)*v[b-1];
    v[b-1]=0;
	cout<<sum<<endl;    
  }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

  int t;
//   cin>>t;
t=1;
  while(t--){
      solve();
  }
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=100001 ;
int main()
{
   fast ;
   ll n ; cin>>n ;
   vector<ll>v(n) ;
   vector<ll>b(n-1) ;
   for(ll i=0;i<n-1;i++) cin>>b[i] ;

   v[0]=v[1]=b[0] ;
   for(ll i=1;i<n-1;i++)
   {
       if(b[i]>=v[i]) v[i+1]=b[i] ;
       else {
        v[i]=b[i] ;
        v[i+1]=b[i] ;
       }
   }
   ll ans=0 ;
   for(ll i=0;i<n;i++) ans+=v[i] ;

   cout<<ans ;



}




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

cnt = 0
chk = [False for i in range(n)]
for i in range(n):
	if chk[i]:
		continue
	chk[i] = True
	if i+1 == a[a[i]-1]:
		chk[a[i]-1] = True
		cnt += 1
print (cnt)

Measured memory_bytes: 14008
M = 10 ** 9 + 7
N, K = map(int, input().split())


def combmod(n, k):
    if k > n - k:
        k = n - k
    num, den = 1, 1
    for i in range(k):
        num = num * (n - i) % M
        den = den * (i + 1) % M
    inv_dev = pow(den, M - 2, M)
    return num * inv_dev % M


for i in range(1, K + 1):
    if i <= N - K + 1:
        print(combmod(K - 1, i - 1) * combmod(N - K + 1, i) % M)
    else:
        print(0)


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nk = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var dic = new Dictionary<int, int>();
        for (var i = 0; i < nk[0]; i++)
            if (dic.ContainsKey(ar[i]))
                dic[ar[i]]++;
            else dic[ar[i]] = 1;
        var va=dic.Values.ToArray();
        Array.Sort(va);
        for (var i = 0; i < nk[1]; i++)
            nk[0] -= nk[0]!=0?va[va.Length - 1 - i]:0;
        WriteLine(nk[0]);
    }
}


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


int main(void) {
	
	char w[101];
	scanf("%s", w);
	int X[100] = { 0 };
	int a;

	int flag = 0;

	for (int i = 0;i<strlen(w);i++) {
		a = w[i]-97;
		X[a] ++;
		
	}

	for (int i = 0; i <= 25; i++) {
		if (X[i] % 2 != 0) {
			flag = 1;
			printf("No");
			break;
		}
	}

	if (flag == 0) {
		printf("Yes");
	}


		return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
struct edge{ll to, cost;};
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1000000000000
#define ALL(a)  (a).begin(),(a).end()

int main(){
    ll a,b;
    cin >> a >> b;
    ll ans = a * b;
    cout << ans << endl;
}

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

pair<pair<string,int>,int> p[110];
int main(){
  int n,score;
  char name[120];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> name >> score;
    p[i] = make_pair(make_pair(name,-score),i);
  }
  sort(p,p+n);
  for(int i=0; i<n;i++){
    cout << p[i].second+1 <<endl;
  }
}

    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

vector<int> ansV(100100, -1);

int ans(int N)
{
  if (N < 0) return inf;
  if (N == 0) return 0;
  if (ansV.at(N) > -1) return ansV.at(N);
  int ret;
  if (N <= 5) ret = N;
  else
  {
    ret = ans(N - 1) + 1;
    for (int i = 1; i <= 6; i++)
    {
      chmin(ret, ans(N - pow(6, i)) + 1);
    }
    for (int i = 1; i <= 5; i++)
    {
      chmin(ret, ans(N - pow(9, i)) + 1);
    }
  }
  ansV.at(N) = ret;
  return ret;
}

int main()
{
  int N;
  cin >> N;
  cout << ans(N) << endl;
}

Measured memory_bytes: 6912
import bisect
import copy
import heapq
import sys
import itertools
import math
from functools import lru_cache
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, K = read_values()
    A = read_list()
    for i in range(N - K):
        print("Yes" if A[i] < A[i + K] else "No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 32188
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
long long INF = (long long)1E17;
#define i_7 (long long)(1E9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

//typedef long long ll;
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

//配列のSIZEは問題ごとに定義する必要がある。
const int SIZE = 2'000'010;
long long inv[SIZE+1];//各iの逆元を格納する配列。
long long kai[SIZE+1];//i!のmodを格納する配列。
long long invkai[SIZE+1];//各i!の逆元を格納する配列。
const int MOD=i_7;
void invinit(){//上の配列を初期化する関数。
    inv[1]=1;
    for(int i=2;i<=SIZE;i++){
        inv[i] = MOD - ((MOD/i)*inv[MOD%i])%MOD;
    }
    
    kai[0]=invkai[0]=1;
    for(int i=1;i<=SIZE;i++){
        kai[i]=(kai[i-1]*i)%MOD;
        invkai[i]=(invkai[i-1]*inv[i])%MOD;
    }
}

long long comb(long long a, long long b){
    if(b<0 || a<b){
        return 0;
    }
    return mod(kai[a]*mod(invkai[b]*invkai[a-b]));
}

int main(){
  invinit();
  using namespace std;
  long long r1, c1, r2, c2;
  cin>>r1>>c1>>r2>>c2;
  long long s = comb(r1 + c1, r1);
  long long l = comb(r2 + c1 + 1, c1);
  long long r = comb(r1 + c2 + 1, c2 + 1);
  long long ans = 0;
  for(long long i = r1 + c1; i <= r2 + c2; i++){
    if(i == r1 + c1){
      ans += s;
      ans = mod(ans);
    }else{
      s = mod(2 * s);
      s += comb(i - 1, c1 - 1);
      s = mod(s);
      s += comb(i - 1, r1 - 1);
      s = mod(s);
      ans += s;
      ans = mod(ans);
    }
  }
  for(long long i = r2 + c1 + 1; i<= r2 + c2; i++){
    if(i == r2 + c1 + 1){
      ans -= l;
      ans = mod(ans);
    }else{
      l = mod(2 * l);
      l += comb(i - 1, c1 - 1);
      l = mod(l);
      l += comb(i - 1, r2);
      l = mod(l);
      ans -= l;
      ans = mod(ans);
    }
  }
  for(long long i = r1 + c2 + 1; i<= r2 + c2; i++){
    if(i == r1 + c2 + 1){
      ans -= r;
      ans = mod(ans);
    }else{
      r = mod(2 * r);
      r += comb(i - 1, r1 - 1);
      r = mod(r);
      r += comb(i - 1, c2);
      r = mod(r);
      ans -= r;
      ans = mod(ans);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 47104
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        boolean up = true;
        boolean down = true;
        
        int prev = sc.nextInt();
        n--;
        int count = 0;
        while (n-- > 0) {
            int next = sc.nextInt();
            if (prev < next) down = false;
            if (prev > next) up = false;
            
            if (!up && !down) {
                count++;
                up = true;
                down = true;
            }
            prev = next;
        }
        System.out.println(count+1);
        
    }
}

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

typedef long long ll;

int main(){
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ans += a[0]-1;
    ll p = 2;
    for(int i=1;i<n;i++){
        ll cnt = (a[i]-1)/p;
        ans += cnt;
        if(a[i] == p) p++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAX_INT  100005
#define MAX_N  100
#define MAX_W  10000
using namespace std;


//??\???
int N, W;
int w[MAX_N], v[MAX_N];

// dp table
int dp[MAX_N + 1][MAX_W + 1];


// i: i????????\?????? item ?????????
// rw: ?????????????????? w ??\???
// return: ???????????????????????§???
int rec(int i, int rw) {
  // dp lookup
  if (dp[i][rw] > 0) {
    return dp[i][rw];
  }

  int res;
  if(i == N) {
    // ?????????????????????
    res = 0;
  } else if ( rw < w[i] ) {
    // ??\?????????
    res = rec(i + 1, rw);
  } else {
    // ??\???????????¨????????????
    // ??\????????´?????¨??\???????????´??????????????????
    res = max( rec(i + 1, rw), rec(i + 1, rw - w[i]) + v[i] );
  }

  dp[i][rw] = res;
  return res;

}



int main() {

  memset(dp, -1, sizeof(dp));

  cin >> N >> W;
  for (int i = 0; i < N; i++) {
    cin >> v[i] >> w[i];
  }

  cout << rec(0, W) << endl;

}

Measured memory_bytes: 7076
#ABC129 B

N = int(input())
W = list(map(int,input().split()))
T = []
for t in range(1,N):
    Q = [W[i] for i in range(t)]
    R = [W[i] for i in range(t,N)]
    T.append(abs(sum(Q)-sum(R)))
    

print(min(T))
            

Measured memory_bytes: 9184
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans[ohara],a,b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rep(i,n-1)cin>>b[i];
    rep(i,n)ans[i]=LINF;
    rep(i,n-1){
        ans[i]=min(b[i],ans[i]);
        ans[i+1]=min(b[i],ans[i+1]);
    }
    rep(i,n)cnt+=ans[i];
    Cout(cnt);
    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

void solve(){
    int n;
    cin>>n;
    int m;
    cin>>m;
    vi A(n+1,1);
    for(int i=0;i<m;i++){
        int temp;
        cin>>temp;
        A[temp]=0;
    }
    for(int i=1;i<=n;i++){
        if(A[i]==1){
            A[i]=A[i-1];
            if(i-2>=0){
                A[i]+=A[i-2];
                A[i]%=MOD;
            }
        }
    }
    out(A[n]);

}

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 200000;
const int mod = 1000000007;

int n;
long long a[N + 1];
long long pref[N + 1];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    
    pref[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
        pref[i] %= mod;
    }
    
    long long ans = 0;
    for (int i = n; i >= 2; i--)
        ans = (ans + a[i] * pref[i - 1]) % mod;
    
    cout << ans;
    
    return 0;
}


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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

const ll MAX = 1e5;

int main() {
  vector<bool> list(MAX + 1, true);
  list[0] = list[1] = false;
  for (int i = 2; i <= MAX; i++) {
    for (int j = i * 2; j <= MAX; j+=i) {
      if (!list[j]) continue;
      list[j] = false;
    }
  }

  vector<int> n2017(MAX + 1, 0);
  for (int i = 0; i <= MAX; i++) {
    if (i % 2 == 0) continue; // 奇数
    if (list[i] && list[(i+1)/2]) {
      n2017[i] = 1;
    }
  }

  vector<ll> rw(MAX + 1, 0);
  for (int i = 0; i < MAX; i++) {
    rw[i + 1] = rw[i] + n2017[i];
  }

  int Q;
  cin >> Q;
  while(Q--) {
    int a, b;
    cin >> a >> b;
    cout << rw[b+1] - rw[a] << endl;
  }
  return 0;
}


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

const int M = 105, N = 105;

int m, n, it, a[M][N], b[M][N], c[M][N], mat[M], chk[M];
bool use[M][N];
vector<int> adj[M];

void init()
{
    it = 1;
    for (int i = 1; i <= m; i++)
    {
        adj[i].clear();
        mat[i] = chk[i] = 0;
    }
}

bool DFS(int u)
{
    chk[u] = it;
    for (int &v : adj[u])
        if (mat[v] == 0)
        {
            mat[v] = u;
            return true;
        }
    for (int &v : adj[u])
        if (chk[mat[v]] < it && DFS(mat[v]))
        {
            mat[v] = u;
            return true;
        }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> m >> n;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
        {
            cin >> a[i][j];
            a[i][j]--;
        }
    for (int r = 1; r <= n; r++)
    {
        init();
        for (int i = 1; i <= m; i++)
            for (int j = 1; j <= n; j++)
                if (!use[i][j])
                    adj[i].push_back(a[i][j] / n + 1);
        for (int i = 1; i <= m; i++)
            if (DFS(i))
                ++it;
        for (int i = 1; i <= m; i++)
        {
            int row = mat[i];
            for (int j = 1; j <= n; j++)
                if (!use[row][j] && a[row][j] / n + 1 == i)
                {
                    b[row][r] = c[i][r] = a[row][j];
                    use[row][j] = true;
                    break;
                }
        }
    }
    for (int i = 1; i <= m; i++, cout << '\n')
        for (int j = 1; j <= n; j++)
            cout << b[i][j] + 1 << " ";
    for (int i = 1; i <= m; i++, cout << '\n')
        for (int j = 1; j <= n; j++)
            cout << c[i][j] + 1 << " ";
}


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

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i%2 == 0) ans += a[i];
        else ans -= a[i];
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int main() {
  double n,m,b,c=0;
  cin >> n >> m;
  b=1/(4*m);
  string s="Yes";
  vector<int> a(n);
  r1(i, n) {
    cin >> a.at(i);
    c+=a.at(i);
  }
  b=b*c;
  sort(a.begin(),a.end(), greater<int>());
  r1(i, m) if(a.at(i)<b) s="No";
  cout << s << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    # ??????A?????\???
    matrix = []
    matrix_size = [int(x) for x in input().split(' ')]
    for i in range(matrix_size[0]):
        matrix.append([int(x) for x in input().split(' ')])

    # ???????????????b?????\???
    vector_b = []
    for i in range(matrix_size[1]):
        vector_b.append(int(input()))

    # ??????
    result = []
    for i in range(matrix_size[0]):
        row = []
        for x, y in zip(matrix[i], vector_b):
            row.append(x*y)
        result.append(row)

    # ???????????????
    for r in result:
        print(sum(r))

Measured memory_bytes: 8344
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;

class Program
{


    static void Main(string[] args)
	{
        string S = Console.ReadLine();
        string T = Console.ReadLine();


        int count = 0;
        int maxCount = 0;
        for (int i = 0; i < S.Length - T.Length + 1; i++)
        {
            count = 0;
            int k = i;
            for (int j = 0; j < T.Length; j++)
            {
                if (S[k] == T[j]) count++;
                k++;
            }

            if (maxCount < count) maxCount = count;
        }

        Console.WriteLine(T.Length - maxCount);

    }
}

Measured memory_bytes: 17580
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

count = 0
for t in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == t:
            count += 1
            break
        elif S[mid] > t:
            right = mid
        else:
            left = mid + 1
print(count)


Measured memory_bytes: 16704
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());

        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = Integer.parseInt(scanner.next());
        }
        scanner.close();

        int count = 0;
        for (int height : arr) {
            if (height >= K) {
                count++;
            }
        }

        System.out.println(count);
    }
}


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

int main() {
	string s;
	cin>>s;
	int n=s.length();
	
	int count=0;
	for(int i=0;i<=n/2-1;i++){
		if(s[i]!=s[n-1-i])count++;
	}
	
	cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int a[100011];
ll ans[100011];
ll fact[101111];
ll ifact[101111];

const int MOD = 1e9 + 7;

ll add(ll a, ll b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}

ll mult(ll a, ll b)
{
	return (a*b)%MOD;
}

ll c(ll a, ll b)
{
	if(b<0) return 0;
	if(a<b) return 0;
	if(b==0) return 1;
	ll ans = fact[a];
	ans=mult(ans,mult(ifact[a-b],ifact[b]));
	if(ans<0) ans+=MOD;
	return ans;
}

ll modpow(ll a, ll b)
{
	ll r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}

int used[100011];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	memset(used,-1,sizeof(used));
	int d=-1;
	for(int i=0;i<n+1;i++) 
	{
		cin>>a[i];
		if(used[a[i]]>=0)
		{
			d=i-used[a[i]]-1;
		}
		used[a[i]]=i;
	}
	fact[0]=1;
	ifact[0]=1;
	for(int i=1;i<=n+2;i++)
	{
		fact[i]=mult(fact[i-1],i);
		ifact[i]=modpow(fact[i],MOD-2);
	}
	for(int k=1;k<=n+1;k++)
	{
		ans[k] = add(c(n-1,k),c(n-1,k-2));
		//cerr<<c(n-1-d,k-1)<<' '<<c(n-1,k-1)<<'\n';
		//cerr<<k<<' '<<ans[k]<<' '<<add(c(n-1-d,k-1),mult(2,add(c(n-1,k-1),MOD-c(n-1-d,k-1))))<<'\n';
		ans[k] = add(ans[k],add(c(n-1-d,k-1),mult(2,add(c(n-1,k-1),MOD-c(n-1-d,k-1)))));
	}
	for(int i=1;i<=n+1;i++)
	{
		cout<<ans[i]<<'\n';
	}
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>

using namespace std;

int main()
{
	int x;
	cin >> x;
	cout << x * x * x << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define ll long long
#define sz size()
#define all(x) x.begin(), x.end()
#define forn(x) for(ll i=1;i<=x;i++) 
#define sforn(x, y) for(ll i=1;i<=x;i++)for(ll j=1;j<=y;j++)
#define pii pair<ll, ll>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

/*
    LOL KEK CHEBUREK
 
    PIHALITI
 
 */

int main(){ speed;
    ll n, k;
    cin >> n >> k;
    ll cnt = 0;
    for(ll i=1;i<=n;i++){
        ll a;
        cin >> a;
        if(a >= k) ++ cnt;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[4],b[4],sum1=0,sum2=0,i;
  for(i=0;i<4;i++){
    scanf("%d",&a[i]);
    sum1+=a[i];
  }
  for(i=0;i<4;i++){
    scanf("%d",&b[i]);
    sum2+=b[i];
  }
  if(sum1>sum2){
    printf("%d\n",sum1);
  } else if (sum1<sum2){
    printf("%d\n",sum2);
  } else {
    printf("%d\n",sum1);
  }
  return 0;
}

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

int n, a[202020], balls[202020];

int main(){
  cin >> n;
  rep(i, n) cin >> a[i + 1];
  
  vector<int> res(0);
  for(int i = n; i >= 1; i--){
    int cnt = 0;
    for(int j = i; j <= n; j += i){
      cnt += balls[j];
    }
    if(cnt % 2 == a[i]){
      balls[i] = 0;
    }else{
      balls[i] = 1;
      res.push_back(i);
    }
  }
  //for(int i = 1; i <= n; i++) cout << balls[i] << " ";cout << endl;
  
  cout << res.size() << endl;
  for(int x : res){
    cout << x << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3064
import sys
from collections import deque

N = int(sys.stdin.readline().strip())

edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, sys.stdin.readline().strip().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

visited = set()
q = {"fennec": deque([0]), "snuke": deque([N-1])}


count = {"fennec": 0, "snuke": 0}
while q["fennec"] or q["snuke"]:
    for user in ("fennec", "snuke"):
        if not q[user]:
            continue
        nq = deque()
        while q[user]:
            point = q[user].popleft()
            for point_next in edges[point]:
                if point_next in visited:
                    continue
                visited.add(point_next)
                count[user] += 1
                nq.append(point_next)
        q[user] = nq

if count["fennec"] > count["snuke"]:
    print("Fennec")
else:
    print("Snuke")

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

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    list<int> lst;
    rep(i,0,n){
        string s;
        cin>>s;
        int in;
        if(s=="insert"){
            scanf("%d",&in);
            lst.push_front(in);
        }
        else if(s=="delete"){
            scanf("%d",&in);
            for(list<int>::iterator it=lst.begin();it!=lst.end();it++){
                if(*it==in){
                    lst.erase(it);
                    break;
                }
            }
        }
        else if(s=="deleteFirst"){
            lst.pop_front();
        }
        else {
            lst.pop_back();
        }
    }
    int i=0;
    for(list<int>::iterator it=lst.begin();it!=lst.end();it++){
        if(i++)printf(" ");
        printf("%d",*it);
    }
    cout<<endl;
    return 0;
}





Measured memory_bytes: 34444
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var ans = new long[3];
        ans[0] = a & b;
        ans[1] = a | b;
        ans[2] = a ^ b;
        for (int i = 0; i < 3; i++)
        {
            var w = Convert.ToString(ans[i], 2);
            Console.WriteLine(format(w));
        }
    }
    public static string format(string s)
    {
        var sL = s.Length;
        string ans;
        if (sL < 32) ans = new string('0', 32 - sL) + s;
        else ans = s.Substring(sL - 32);
        return ans;
    }
}


Measured memory_bytes: 17888
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

template<class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//--------------------------- Solve ---------------------------//

int dp[3005][3005];

void solve() {
    int N, T; cin >> N >> T;
    vector<pair<int, int>> p(N);
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(p.begin(), p.end());

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < T; j++) {
            chmax(dp[i+1][j], dp[i][j]);
            int nj = j + p[i].first;
            if (nj < T) chmax(dp[i+1][nj], dp[i][j]+p[i].second);
        }
        int tmp = dp[i][T-1] + p[i].second;
        chmax(ans, tmp);
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 38836
#include <bits/stdc++.h>
#define LL long long
using namespace std;

const int MAXN = 1e5 + 100;
LL k, arr[MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  cin >> k;
  for(int i = 1; i <= k; i++) {
    cin >> arr[i];
  }
  if(arr[k] != 2) {
    cout << -1 << endl;
    return 0;
  }
  if(k == 1) {
    cout << 2 << " " << 3 << endl;
    return 0;
  }
  LL l = 2, r = 3;
  for(int i = k - 1; i > 0; i--) {
    LL u_x = r / arr[i], l_x = (l + arr[i] - 1) / arr[i];
    if(u_x < l_x) {
      cout << -1 << endl;
      return 0;
    }
    l = arr[i] * l_x, r = arr[i] * u_x + (arr[i] - 1);
  }
  cout << l << " " << r << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
#define lcm(a,b) a*b/__gcd(a,b)
#define sz(x) (int)x.size()
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define cmp complex<double>
int power(int x,int y){
    int res=1;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        x=(x*x)%mod;
        y/=2;
    }
    return res;
}
void precompute(){
}
void dfs(vector<int> adj[],int x,vector<bool> &vis){
    vis[x]=1;
    for(auto it: adj[x]){
        if(!vis[it]){
            dfs(adj,it,vis);
        }
    }
}
void solve(int tc){
    int n,m;
    cin>>n>>m;
    vector<int> adj[n+1];
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    vector<bool> vis(n+1);
    int no=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(adj,i,vis);
            no++;
        }
    }
    cout<<no-1<<"\n";
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(12);
    int t=1,ctr=0;
    // precompute();
    // cin>>t;
    while(t--){
        solve(ctr+1);
        ctr++;
    }
}

Measured memory_bytes: 10760
#include<cstdio>
typedef long long ll;
ll Q,H,S,D,x,n,ans;
ll cmin(ll a,ll b){return a<b?a:b;}
int main()
{
	scanf("%lld%lld%lld%lld%lld",&Q,&H,&S,&D,&n);
	x=cmin(Q*8,cmin(H*4,cmin(S*2,D)));
	if(n>=2)ans+=n/2*x,n=n-n/2*2;
	if(n)ans+=cmin(Q*4,cmin(H*2,S));
	return printf("%lld\n",ans),0;
}

Measured memory_bytes: 128
#include <stdio.h>
 
main(){

  int i,j,n,id,k,p,c1,c2,count;

  int C[100001][3]; 

  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      C[i][j]=-1;
    }
  }
   
  for(i=0;i<n;i++){

    scanf("%d %d",&id,&k);

    if(k>0){
      int array[k];
      for(j=0;j<k;j++){
        if(j==0){ 

      scanf("%d",&array[j]);
      C[id][1]=array[j]; 
          C[array[j]][0]=id;
    }
        else {
      scanf("%d",&array[j]);
          C[array[j-1]][2]=array[j];
      C[array[j]][0]=id;
    }
      }
    }
  }
   
    
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,C[i][0]);
     
    p=C[i][0];

    count=0;

    while(1){
      if(p==-1) break;
      p=C[p][0];
      count++;
       
    }   

    printf("depth = %d, ",count);
 
    if(C[i][0]==-1) printf("root, ");
    else if(C[i][1]==-1){
      printf("leaf, []\n");
      continue;
    }
    else printf("internal node, ");
    
 
    if(C[i][1]!=-1){
 
      c1=C[i][1];
      if(C[c1][2]!=-1)printf("[%d, ",C[i][1]);
      else printf("[%d",C[i][1]);
 
      c2=C[C[i][1]][2];
       
      while(1){ 
        if(C[c2][2]==-1) printf("%d",c2); 
    else if(c2==-1) break;

    else printf("%d, ",c2);
        c2=C[c2][2];
      }
      printf("]\n");
    }
    else printf("[]\n");
  }
  return 0;
}
 

Measured memory_bytes: 2172