akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace s8pc_3_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long[,] dp = new long[256, x[0] + 1]; //[xor,個数]=場合の数
            dp[0, 0] = 1; dp[a[0], 1] = 1;
            int mod = (int)Math.Pow(10, 9) + 7;
            for (int i = 1; i < x[0]; i++)
            {
                long[,] after = new long[256, x[0] + 1];
                for (int j = 0; j < 256; j++)
                {
                    for (int k = 0; k < x[0]; k++)
                    {
                        after[j, k] += dp[j, k]; after[j, k] %= mod;
                        after[j ^ a[i], k + 1] += dp[j, k]; after[j ^ a[i], k + 1] %= mod;
                    }
                }
                dp = after;
            }
            long ret = 0; long fact = 1;
            for (int i = 1; i <= x[0]; i++)
            {
                fact *= i; fact %= mod;
                ret += fact * dp[x[1], i];
                ret %= mod;
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 29664
import scala.io.StdIn.{readLine,readInt}

object Main extends App {

  var index = 1
  Iterator.continually(readInt).takeWhile ( w => w != 0).foreach { w =>
    val n = readInt
    val wv = Array.ofDim[Int](n+1,2)
    val m = Array.ofDim[Int](n+1,w+1)

    for(i<-1 to n) wv(i) = readLine.split(",").map(_.toInt)
    for(i<-1 to n;j<-0 to w) {
      if(j >= wv(i)(1)) {
        val x = wv(i)(0) + m(i-1)(j-wv(i)(1))
        if(m(i-1)(j) <= x) m(i)(j) = x else m(i)(j) = m(i-1)(j)
      } else
        m(i)(j) = m(i-1)(j)
    }
    println("Case "+index+":")
    println(m(n)(w))
    println((0 to w).find(m(n)(_) == m(n)(w)).get)
    index += 1
  }
}

Measured memory_bytes: 49736
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba"){
    	cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}


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

int main(){
    string n;
    cin >> n;
    int ans = 0;
    for(int i=0; i<n.size(); i++) ans+=n[i]-'0';
    if(ans%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3732
def search(L, x):
    low, high = 0, len(L)-1
    while low < high:
        mid = (low+high)//2
        if L[mid+1] < x < L[mid]:
            return mid
        elif x < L[mid+1]:
            low = mid+1
        else:
            high = mid
    return low

N, Q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(Q)]
B = [N-1]
Bv = [N-2]
R = [N-1]
Rv = [N-2]
ans = (N-2)**2
for f, x in query:
    x -= 1
    if f == 1:
        a = search(R, x)
        ans -= Rv[a]
        if R[-1] >= x:
            Bv[-1] = x-1
            R.append(x)
            Rv.append(Rv[-1])
    else:
        a = search(B, x)
        ans -= Bv[a]
        if B[-1] >= x:
            Rv[-1] = x-1
            B.append(x)
            Bv.append(Bv[-1])
    
print(ans)

Measured memory_bytes: 51596
sx,sy,tx,ty = map(int, input().split())

rlt = []
for _ in range(tx-sx):
  rlt.append('R')
for _ in range(ty-sy):
  rlt.append('U')
for _ in range(tx-sx):
  rlt.append('L')
for _ in range(ty-sy+1):
  rlt.append('D')
for _ in range(tx-sx+1):
  rlt.append('R')
for _ in range(ty-sy+1):
  rlt.append('U')
rlt.append('L')
rlt.append('U')
for _ in range(tx-sx+1):
  rlt.append('L')
for _ in range(ty-sy+1):
  rlt.append('D')
rlt.append('R')
  
print(''.join(rlt))

Measured memory_bytes: 9272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  int K, S;
  cin >> K >> S;
  
  //cout << "S-K: " << S-K << " S: " << S << endl;
  int ans = 0;
  for(int x=0; x<=K; x++){
    for(int y=0; y<=K; y++){
      //for(int z=0; z<=K; z++){
      //  if(x+y+z == S) ans++;
      //}
      if(S-K <= x+y  && x+y <= S){
        ans++; //zは 0～Kまで
        //cout << "x: " << x << " y: " << y << endl;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          ulong[] input = Input.ScanUlongArray();
          ulong res=input[1]/input[2];
          if(input[0] == 0)
           res += 1;
          else
            res -= (input[0]-1)/input[2];
          Console.WriteLine(res);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

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

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];
    vector<int> last(26, -1);
    int satisfy = 0;
    vector<int> ans(365);
    rep(i, 365) {
        int an=1;
        rep(j, 26) {
            int sa = satisfy;
            vector<int> la = last;
            sa += s[i][j];
            la[j] = i;
            int decrease = 0;
            rep(k, 26) decrease += c[k] * (i - last[k]);
            sa -= decrease;
            if (chmax(satisfy, sa))
                an = j;
        }
        ans.push_back(an);
    }
	rep(i,365)
        cout << ans[i]+1 << endl;
}

Measured memory_bytes: 3684
import queue

nk = input()

po = input()

N = int(nk.split(' ')[0])
K = int(nk.split(' ')[1])

p = po.split(' ')
p2 = [(int(i) + 1 )/2 for i in p]

# print(p2)
q = queue.Queue()
rui = [p2[0]]
for i in range(1,N):
    # print(i)
    # print(rui[i-1],p2[i],rui[i-1] + p2[i+1])
    rui.append(rui[i-1] + p2[i])

# print(rui)

tes = 0
maxv = 0
for i in range(K-1,N):
    # print('turn',i)
    tes = rui[i]
    if(i >= K):
        tes -= rui[i-K]
    # print(tes)
    if(maxv < tes):
        maxv = tes
print(maxv)


# tes = 0
# maxv = 0
# for i in list(range(N-K + 1)):# 連続するKこの選び方のパターン  
#     tes = 0
#     for j in range(0,K-1):
#         tes += p2[i+j]
    
#     # print(tes)
#     if (tes > maxv):
#         maxv = tes

# # print('max',maxv)
# print(maxv)


Measured memory_bytes: 31732
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, X, M[1010];
    cin >> N>>X;
    int ans = 0;
    for(int i=0; i<N; ++i)
        cin>>M[i], ans += M[i];
    cout << (X-ans)/ *min_element(M, M+N) + N <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <set>
#include <string>

const int MOD = (int)1e9 + 7;

const int N = 2000;

int binom[N + 1][N + 1], ways[N + 1][N + 1], suf[N + 1][N + 1];

std::set<std::string> all;

void gen(int a, int b, int s, std::string mask)
{
    if (a == 0 && b == 0) {
        all.insert(mask);
    } else {
        if (a > 0) {
            gen(a - 1, b, s, mask + "A");
        } else {
            gen(a, b - 1, s, mask + "B");
        }
        if (a <= s && s < a + b) {
            gen(a, b - 1, s, mask + "B");
        }
    }
}

int gao(int a, int b)
{
    all.clear();
    for (int s = 0; s < a + b; ++ s) {
        gen(a, b, s, "");
    }
    return all.size();
}

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

int main()
{
    for (int i = 0; i <= N; ++ i) {
        binom[i][0] = 1;
        for (int j = 1; j <= i; ++ j) {
            binom[i][j] = binom[i - 1][j - 1];
            update(binom[i][j], binom[i - 1][j]);
        }
    }
    for (int j = 0; j <= N; ++ j) {
        int sum = 0;
        for (int i = 0; i <= N; ++ i) {
            if (i <= j) {
                update(sum, binom[j][i]);
            }
            ways[i][j] = sum;
        }
    }
    int a, b;
    scanf("%d%d", &a, &b);
    for (int i = 0; i <= a; ++ i) {
        suf[i][0] = 1;
    }
    for (int j = 1; j <= b; ++ j) {
        suf[0][j] = 1;
        for (int i = 1; i <= a; ++ i) {
            suf[i][j] = (suf[i - 1][j] + ways[i][j - 1]) % MOD;
        }
    }
    int result = 1;
    for (int first = 0; first < a; ++ first) {
        // a - first A
        // b - 1 B
        for (int x = 0; x <= a - first && x <= b - 1; ++ x) {
            int y = (b - 1) - x;
            result += 1LL * binom[x + y][x] * suf[a - first - x][b - 1 - y] % MOD;
            if (result >= MOD) {
                result -= MOD;
            }
        }
        // b - 1
    }
    printf("%d\n", result);
}

Measured memory_bytes: 46336
#include<bits/stdc++.h>
using namespace std;
int main(){
 string a,b;
  cin>>a;
  if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]){
    b="Bad";
  }
  else{
    b="Good";
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 200005;
typedef long long ll;
vector<pair<ll,ll> >s[MAXN],a,b;
struct Edge{
	int to,next,w;
}e[MAXN<<1];
int n,head[MAXN],cnt;
inline void insert(int u,int v,int w)
{
	e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt,e[cnt].w=w;
	e[++cnt].to=u,e[cnt].next=head[v],head[v]=cnt,e[cnt].w=w;
}
inline void add(vector<pair<ll,ll> >&x,pair<ll,ll>a)
{
//	cout<<a.first<<" "<<a.second<<endl;
	if(x.size() && a.second>=x.back().second)return;
	while(x.size() && x.back().first==a.first && x.back().second>=a.second)x.pop_back();
	x.push_back(a);
}
int dfs(int x,int fa,ll mid)
{
	int v1=0,v2=0,w1=0,w2=0;
	for(int i=head[x];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa)continue;
		if(!v1)v1=v,w1=e[i].w;
		else v2=v,w2=e[i].w;
		if(!dfs(v,x,mid))return 0;
	}
	s[x].clear();
	if(v1){
//		cout<<v1<<" "<<w1<<" "<<v2<<" "<<w2<<endl;
		if(!s[v1].size() || !s[v2].size())return 0;
		a.clear(),b.clear();
		int p=0;
		for(int i=0;i<s[v1].size();++i){
			while(p<s[v2].size() && s[v1][i].first+s[v2][p].second+w1+w2>mid)++p;
			if(p>=s[v2].size())break;
			else{
				a.push_back(make_pair(s[v1][i].second+w1,s[v2][p].first+w2));
			}
		}
		p=0;
		for(int i=0;i<s[v2].size();++i){
			while(p<s[v1].size() && s[v1][p].second+s[v2][i].first+w1+w2>mid)++p;
			if(p>=s[v1].size())break;
			else{
				b.push_back(make_pair(s[v2][i].second+w2,s[v1][p].first+w1));
			}
		}
/*		cout<<"=========="<<endl;
		cout<<w1<<endl;
		for(int i=0;i<s[v1].size();++i){
			cout<<s[v1][i].first<<" "<<s[v1][i].second<<endl;
		}
		cout<<endl;
		cout<<w2<<endl;
		for(int i=0;i<s[v2].size();++i){
			cout<<s[v2][i].first<<" "<<s[v2][i].second<<endl;
		}
		cout<<"=========="<<endl;*/
//		cout<<"###  "<<x<<" "<<a.size()<<" "<<b.size()<<" "<<mid<<endl;
		int p1=a.size()-1,p2=b.size()-1;
		while(p1>=0 && p2>=0){
			if(a[p1].first<=b[p2].first)add(s[x],a[p1]),--p1;
			else add(s[x],b[p2]),--p2;
		}
		while(p1>=0)add(s[x],a[p1]),--p1;
		while(p2>=0)add(s[x],b[p2]),--p2;
/*		cout<<"Result:"<<endl;
		for(int i=0;i<s[x].size();++i){
			cout<<s[x][i].first<<" "<<s[x][i].second<<endl;			
		}
		cout<<"======================="<<endl;*/
	}else{
		s[x].push_back(make_pair(0,0));
	}
/*	if(x==1){

		cout<<w1+w2<<endl;
	}
	if(fa==1){
	for(int i=0;i<s[x].size();++i)
		cout<<s[x][i].first<<" "<<s[x][i].second<<endl;
	cout<<endl;
	}
*/
//		cout<<x<<endl;
//	for(int i=0;i<s[x].size();++i)
//		cout<<s[x][i].first<<" "<<s[x][i].second<<endl;
//	cout<<endl;
	return s[x].size();
}
ll sum=0;
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;++i){
		int f,w;
		scanf("%d%d",&f,&w),sum+=w;
		insert(f,i,w);
	}
	ll l=0,r=sum,mid,ans=0;
	while(l<=r){
		mid=(l+r)>>1;
		if(dfs(1,0,mid))r=mid-1,ans=mid;
		else l=mid+1;
	}
	printf("%lld\n",ans);

//	dfs(1,0,1441152);
	return 0;
}


Measured memory_bytes: 34012
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    int n;
    std::cin >> n;
    std::vector<i64> cost(n), p2(n + 1);
    for (auto &e : cost) std::cin >> e;
    std::sort(cost.begin(), cost.end());
    p2[0] = 1;
    for (int i = 1; i <= n; i++) p2[i] = p2[i - 1] * 2 % mod;

    i64 ret = p2[n - 1] % mod * cost.back() % mod;
    for (int i = 0; i + 1 < n; i++) {
        ret = (ret + p2[i] * (n - i + 1) % mod * p2[n - i - 2] % mod * cost[i] % mod) % mod;
    }

    std::cout << ret * p2[n] % mod << std::endl;

    return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
const int N=1e5+10;
int n,x[N],m,a[N],di[N],top,stk[N],pos[N],vis[N];
LL k,ans[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline void swp(I&a,I&b){a^=b; b^=a; a^=b;}
int main()
{
	//freopen("Rabbit Exercise.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++) read(x[i]), di[i]=x[i]-x[i-1], pos[i]=i;
	read(m,k);
	for(int i=1;i<=m;i++)
	{
		read(a[i]);
		swp(pos[a[i]],pos[a[i]+1]);
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			top=0;
			for(int j=i;!vis[j];j=pos[j]) stk[++top]=j, vis[j]=1;
			for(int j=1;j<=top;j++)
			{
				ans[stk[j]]=di[stk[(LL)(j+k-1)%top+1]];
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",ans[i]+=ans[i-1]);
	}
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
#include <stddef.h>

int main(void)
{
    char s[200001];
    scanf("%s", s);
    char *p = strchr(s, 'A');
    char *q = strrchr(s, 'Z');
    ptrdiff_t d = q - p + 1;
    printf("%td\n", d);
    return 0;
}


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

const int N = (int)1e5;
const long long MOD = (long long)1e9+7;

long long fast(long long a, long long p) {
    if (p == 0) return (long long)1;
    long long res = fast(a, p >> 1);
    res = (res * res) % MOD;
    if (p & 1) res = (res * a) % MOD;
    return res;
}

pair<long long, long long> fact[N+5];
int start() {
    fact[0].first = fact[0].second = (long long)1;
    for (int i=1; i<N+3; i++) {
        fact[i].first = (fact[i-1].first * (long long)i) % MOD;
        fact[i].second = fast(fact[i].first, MOD-2);
    }
    return 0;
}

long long nCk(int n, int k) {
    if (n < k) return 0;
    long long num = fact[n].first;
    long long denum = (fact[n-k].second * fact[k].second) % MOD;
    return (num * denum) % MOD;
}

int dat[N+5];

int main() {
    start();

    int n,k; scanf("%d %d", &n, &k);
    for (int i=1; i<=n; i++) scanf("%d", dat+i);
    sort(dat+1, dat+1+n);

    long long mini = 0;
    long long maxi = 0;
    for (int i=1; i<=n; i++) {
        long long reta = (nCk(i-1, k-1) * (long long)dat[i]) % MOD;
        long long retb = (nCk(n-i, k-1) * (long long)dat[i]) % MOD;
        mini = (mini + retb) % MOD;
        maxi = (maxi + reta) % MOD;
    }

    printf("%lld\n", (maxi - mini + MOD) % MOD);
    return 0;
}


Measured memory_bytes: 2176
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
ll n,a,b,ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    cin>>a>>b;
    if(a>b) swap(a,b);
    ans=min(b-1,n-a);
    if((b-a)%2==0){
        ans=min(ans,(b-a)/2);
    }    
    else{
        ans=min(ans,a+((b-a)-1) /2);
        ans=min(ans,n-b+1 +(n-(a+n-b+1)) /2);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void)
{
    int i,j,N,K,d,a,t;
    int A[100];
    t = 0;
    scanf("%d%d",&N,&K);
    for(i = 1;i <= 100;i++){
        if(i <= N) A[i-1] = 0;
        else A[i-1] = 100; 
    }
    for(i = 1;i <= K;i++){
        scanf("%d",&d);
        for(j = 1;j <= d;j++){
            scanf("%d",&a);
            A[a - 1] = 100;
        }
    }
    for(i = 1;i <= N;i++){
        if(A[i-1] == 0) t++;
    }
    printf("%d\n",t);
	return 0;
}

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

int n,dist[2][100001];
vector<int> adj[100001];

void dfs(int cur,int p,int c,int d) {
    dist[c][cur]=d;
    for(auto &it:adj[cur]) if(it!=p) dfs(it,cur,c,d+1);
}
int main() {
    scanf("%d",&n);
    for(int i=1,u,v;i<n;i++) {
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1,0,0,0);
    dfs(n,0,1,0);

    int cnt[2];
    for(int i=1;i<=n;i++) {
        if(dist[0][i] <= dist[1][i]) cnt[0]++;
        else cnt[1]++;
    }
    if(cnt[0]<=cnt[1]) puts("Snuke");
    else puts("Fennec");
    
    return 0;
}


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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

int R, C, K;
int a[3001][3001];
int dp[3001][3001][4];

int solve(int i, int j, int past = 0) {
    if(i == R and j == C) {
        if(past < 3) {
            return a[i][j];
        }
        return 0;
    }
    if(i > R or i <= 0 or j > C or j <= 0) {
        return -1e18;
    }
    if(dp[i][j][past] != -1) {
        return dp[i][j][past];
    }
    int ans = max(solve(i + 1, j), solve(i, j + 1, past));
    if(past < 3 and a[i][j] > 0) {
        ans = max(ans, a[i][j] + solve(i, j + 1, past + 1));
        ans = max(ans, a[i][j] + solve(i + 1, j, 0));
    }
    return dp[i][j][past] = ans;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> R >> C >> K;
    for(int i = 0; i < K; i++) {
        int x, y, v;
        cin >> x >> y >> v;
        a[x][y] = v;
    }
    memset(dp, -1, sizeof dp);
    cout << solve(1, 1) << endl;

    return 0;
}



Measured memory_bytes: 355856
#include<iostream>
#include<string>
#include<vector>
#include<iterator>
using namespace std;
int main()
{
  int n,ta=0,ha=0;
  string a,b;
  cin >> n;
  vector<string> taro;
  vector<string> hana;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    taro.push_back(a);
    hana.push_back(b);
    for(int j=0;j<10000;j++){
      if(taro[i] == hana[i]){
	ta++;
	ha++;
	break;
      }
      if(taro[i].substr(0,j) > hana[i].substr(0,j)){
	ta += 3;
	break;
      }
      else if(hana[i].substr(0,j) > taro[i].substr(0,j)){
	ha+=3;
	break;
      }
    }
  }
  cout << ta <<" "<< ha << endl;
  return 0;
}

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

using ll = long long;
// #define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int x, y;
  cin >> x >> y;
  if(x == y) {
    cout << 0 << endl;
    return 0;
  }

  if(x == 0) {
    if(y > 0) {
      cout << y << endl;
    } else {
      cout << abs(y) + 1 << endl;
    }
    return 0;
  }
  if(y == 0) {
    if(x > 0) {
      cout << x + 1 << endl;
    } else {
      cout << abs(x) << endl;
    }
    return 0;
  }

  if(x > 0 && y > 0) {
    if(x < y) {
      cout << y - x << endl;
    } else {
      cout << x - y + 2 << endl;
    }
    return 0;
  }
  if(x < 0 && y < 0) {
    if(x < y) {
      cout << y - x << endl;
    } else {
      cout << x - y + 2 << endl;
    }
    return 0;
  }
  cout << abs(abs(x) - abs(y)) + 1 << endl;
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end());

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    string s;
    cin>>s;
    bool flag=false;
    REP(i,s.size()-1)if(s[i]=='A'&&s[i+1]=='C')flag=true;
    Yes(flag);

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1e5+10;
int a[MAXN]={};
int main(){
   int n,up=0;
   scanf("%d",&n);
   for(int i=0;i<n;++i){
      int tmp;
      scanf("%d",&tmp);
      up=max(up,tmp);
      ++a[tmp];
   }
   int ans=1;
   for(int i=0;i<=up;++i) ans=max(ans,a[i]);
   for(int i=1;i<up;++i) ans=max(ans,a[i-1]+a[i]+a[i+1]);
   printf("%d",ans);
   return 0;
}

Measured memory_bytes: 512
import numpy as np
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

total = np.sum(a)
thresh = total / (4 * m)

a = np.sort(np.array(a))[::-1]

mask = a >= thresh
if np.sum(mask) >= m:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 21516
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        for(int i = 1; i < 180; i++){
            if((360*i) % n == 0){
                System.out.println((360*i)/n);
                return;
            }
        }
        
    }
    
    public static int solve(int[] arr){
        int max = arr.length;
        int ret = 0;
        for(int i = 0; i < max-2; i++){
            int[] chk = {arr[i],arr[i+1],arr[i+2]};
            Arrays.sort(chk);
            if(arr[i+1] == chk[1]){
                ret++;
            }
        }
        return ret;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

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

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

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 25356
D = int(input())
C = list(map(int, input().split()))
#  S = [[1st day], [2nd day],  ..., [D-th day]]
S = []
for i in range(D):
    Si = list(map(int, input().split()))
    S.append(Si)
I = 26

last = [0]*I

score = S[1]
contest = score.index(max(score))

last = [x+1 for x in last]
last[contest] = 0

print(contest + 1)

for day in range(1, D):
    ddc = sum([C[i]*(last[i]+1) for i in range(I)])
    score = [-ddc + C[i]*(last[i]+1) + S[day][i] for i in range(I)]
    contest = score.index(max(score))

    last = [x+1 for x in last]
    last[contest] = 0

    print(contest + 1)

Measured memory_bytes: 9372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

int main() {
    int n; cin >> n;
    int ans = 10000000;
    for(int i = 0;i < n;i++){
        int a; cin >> a;
        int cnt = 0;
        while(a % 2 == 0){
            a/=2;
            cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

bool check(const string &str, const string &pattern) {
	rep(i, str.size()) {
		if(pattern[i] != '?' && str[i] != pattern[i]) return false;
	}
	return true;
}

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

	for(int n, m; cin >> n >> m && (n | m);) {
		vector<pair<bool, string>> rules;

		rep(i, n) {
			string which, source, destination;
			cin >> which >> source >> destination;

			const string sum = source + destination;
			const bool is_permit = (which[0] == 'p');
			rules.emplace_back(is_permit, sum);
		}

		reverse(ALL(rules));
		vector<tuple<string, string, string>> match;
		match.reserve(m);

		rep(i, m) {
			string source, destination, body;
			cin >> source >> destination >> body;

			const string sum = source + destination;

			for(const auto &rule : rules) {
				if(check(sum, rule.second)) {
					if(rule.first) match.emplace_back(source, destination, body);
					break;
				}
			}
		}

		cout << match.size() << endl;
		for(const auto &e : match) {
			cout << get<0>(e) << " " << get<1>(e) << " " << get<2>(e) << endl;
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1352
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

using ll = long long;
using ld = long double;

#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}



signed main() {
    accell();
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n & 1) {
        cout << "No";
        return 0;
    }
    string a = s.substr(0, n / 2);
    string p = a + a;
    if (p == s) {
        cout << "Yes";
    }
    else
        cout << "No";
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int ans = 1000;
    for (char c = 'a'; c <= 'z'; ++c) {
        int prev = 0;
        int len = 0;
        for (int i = 0; i < s.length(); ++i) {
            if (s[i] != c) {
                continue;
            }
            len = max(len, i - prev);
            prev = i + 1;
        }
        len = max(len, int(s.length()) - prev);
        ans = min(ans, len);
    }
    cout << ans;
    return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

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

typedef long long ll;
typedef pair<int, int> p;
ll res = LLONG_MAX;
int k, n;

void full_search(vector<p> v){
  for (int i = 0; i < n-1; i++) {
    for (int j = 0; j < n; j++) {
      for (int test = 0; test < n; test++) {
        for (int test2 = 0; test2 < n; test2++) {
        ll max_x = max(v[i].first, v[test].first);
        ll min_x = min(v[i].first, v[test].first);
        ll max_y = max(v[test2].second, v[j].second);
        ll min_y = min(v[test2].second, v[j].second);
        if(max_x == min_x || max_y == min_y) continue;
        int count = 0;
        ll area = (max_x - min_x) * (max_y - min_y);
        for (int k = 0; k < n; k++) {
          int nx = v[k].first;
          int ny = v[k].second;
          bool is_inner_point = (nx >= min_x && nx <= max_x && ny >= min_y && ny <= max_y);
          if(is_inner_point){
            count++;
          }
        }
        // cout << max_x-min_x << " : " << max_y-min_y << endl;
        // cout << area << endl;
        if(count >= k) res = min(area, res);
        }
      }
    }
  }
}

int main(){
  cin >> n >> k;
  vector<p> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  full_search(v);
  cout << res << endl;
}


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

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	std::map<int, int> num;
	for (int i{}; i < N; i++)
	{
		int A;
		scanf("%d", &A);
		num[A]++;
	}
	for (int i{}; i < M; i++)
	{
		int B, C;
		scanf("%d%d", &B, &C);
		num[C] += B;
	}
	long long sum{};
	int count{};
	for (auto it{num.rbegin()}; it != num.rend(); it++)
	{
		if (it->second + count >= N)
		{
			sum += (long long)it->first * (N - count);
			break;
		}
		else
		{
			sum += (long long)it->first * it->second;
			count += it->second;
		}
	}
	printf("%lld\n", sum);

	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans, n, m;
int s[15][15], p[15], k[15];

int main(void) {
    cin >> n >> m;
    rep(i, 0, m) {
        cin >> k[i];
        rep(j, 0, k[i]) {
            int ss;
            cin >> ss;
            s[i][j] = ss - 1;
        }
    }

    rep(i, 0, m) cin >> p[i];

    for (int i=0; i<(1<<n); i++) {
        int sum = 0;
        rep(j, 0, m) {
            int on = 0;
            rep(l, 0, k[j]) {
                if ((i>>s[j][l])&1) on++;
            }
            if (on%2==p[j]) sum++;
        }
        if (sum==m) ans++;

    }


    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iterator>
#include<vector>
#include<string>
#include<map>
using namespace std;


#define mod(cans) cans%10**9+7
#define cin_pl(x,y) for(int i=0;i<x;i++){cin>>y[i];}
#define pl_twin(x,y,z) for(int i=0;i<x;i++){cin>>y[i]>>z[i];}
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define st(s) size_t size = s.length()
#define prians(Answer) cout<<Answer<<"\n"
#define make_pair m_p;
#define com_div(x,Co) for(int i=1;i<x+1;i++){if(x%i==0){Co++;}}
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int,int> pr;
typedef greater<int> gi;

int main(void)
{
    int n;
    cin>>n;
    vi a;
    rep(i,n)
    {
        int qwer;
        cin>>qwer;
        a.push_back(qwer);
    }
    sort(rall(a));
    int ans=0;
    rep(i,n)
    {
        if(i%2==0)
        {
            ans+=a[i];
        }
        else
        {
            ans-=a[i];
        }
        
    }
    prians(ans);
    return 0;
}

Measured memory_bytes: 256
(defun solve(a b c)
    (let ((r (- c a))
	  (s (- c b)))
      (cond
	((and (evenp r) (evenp s)) (truncate (+ r s) 2))
	((and (evenp r) (oddp s)) (+ 2 (truncate (+ r s) 2)))
	((and (oddp r) (evenp s)) (+ 2 (truncate (+ r s) 2)))
	(t (truncate (+ r s) 2)))))
		

(defun main()
    (let ((l (sort (read-from-string (concatenate 'string "(" (read-line) ")")) #'<=)))
      (destructuring-bind (a b c) l
	(princ (solve a b c))
	(fresh-line))))

(main)


Measured memory_bytes: 24544
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;

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

long long int a[3][100001];

int main() {
	int a, b, c;
	cin >> a;
	b = a / 100;
	c = a - b* 100;
	if (0 < b && b <= 12) {
		if (0 < c && c <= 12) {
			cout << "AMBIGUOUS";
		}
		else {
			cout << "MMYY";
		}
	}
	else {
		if (0 < c && c <= 12) {
			cout << "YYMM";
		}
		else {
			cout << "NA";
		}
	}
	cout << endl;
}

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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	ll sum = 1;
	vector<ll> A(N);

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

	for (int i = K; i < N; ++i) {
		if (A[i] > A[i - K]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4824
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		sc.close();

		String result = (a+(d-1))/d >= (c+(b-1))/b ? "Yes" : "No";

		System.out.println(result);

	}

}


Measured memory_bytes: 35760
#include<cstdio>
#include<algorithm>
using namespace std;

const int Maxn=1e5;

int N,M;
int cnt[Maxn+5];
bool vis[Maxn+5];

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&M);
	fill(cnt+1,cnt+N+1,1);
	vis[1]=true;
	while(M--) {
		int a,b;
		scanf("%d %d",&a,&b);
		if(vis[a])vis[b]=true;
		cnt[a]--;cnt[b]++;
		if(cnt[a]<=0)vis[a]=false;
	}
	int ans=0;
	for(int i=1;i<=N;i++)
		if(vis[i])ans++;
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int n; cin >> n;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define CAKE 4 //ケーキは4ドル
#define DONUT 7 //ドーナツは7ドル

int main(void)
{
	//変数を定義
	int n, flag = 0;
	//入力
	scanf("%d", &n);

	//変数flagがカウントされたらYes。されなかったらNo。
	for (int i = 0; i <= 100 ;i++) {
		for (int j = 0; j <= 100 ; j++) {
			//ケーキとドーナツを組み合わせて買う際の全通りを試す
			if (n == CAKE * i + DONUT * j) {
				flag++;
				break;
			}
			//入力した値段を超えたらbreak
			else if(n < CAKE * i + DONUT * j){
				break;
			}
		}
	}

	//変数flagが0かどうかで出力を分岐
	if (flag) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}



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

int main(){
    int n;
    cin >> n;
    ull power=1;
    for(int i=1;i<=n;++i){
        power=(ull)(power*i)%(ull)(pow(10,9)+7);
    }
    cout << power << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
char s[12];
ll ans,len;
void dfs(ll x,ll pre,ll suf)
{
	if(x==len)
	{
		ans+=pre+suf;
		return;
	}
	dfs(x+1,pre,suf*10+s[x]-'0');
	dfs(x+1,pre+suf,s[x]-'0'); 
}
int main()
{
	scanf("%s",s);
	len=strlen(s);
	dfs(1,0,s[0]-'0');
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int k, n;
    cin >> n >> k;
    vi l(n);
    rep(i, n) cin >> l[i];
    sort(all(l), greater<int>());
    cout << accumulate(l.begin(), l.begin() + k, 0) << endl;
}


Measured memory_bytes: 256
n, k = map(int,input().split())
a_l = list(map(int,input().split()))
mod = 10**9+7

count1 = 0
for i in range(n):
    for j in range(i+1,n):
        if a_l[i] > a_l[j]:
            count1 += 1

a_l += a_l
count2 = 0
for i in range(n*2):
    for j in range(i+1,n*2):
        if a_l[i] > a_l[j]:
            count2 += 1
count2 -= count1*2

ans = count2*(k-1)*k//2 + count1*k
ans%=mod

print (ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define all(x) x.begin(),x.end()
#define int long long

/* 
ll exp(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}



int nCrModPFermat(int n, int r, int p)
{
   if (r==0)
      return 1;
    int fac[n+1];
    fac[0] = 1;
    for (int i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;
 
    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}
*/
/*struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
 
*/
 
/*vector<bool> sieve(100007,true);
 
void help(){
     sieve[0] = false;
     sieve[1] = false;
 
     for(int i=2;i*i<100007;++i){
        if(sieve[i]){
            for(int j=i*i;j<100007;j+=i)
                sieve[j] = false;
 
        }
     }
 
}*/
/*
ll expo(ll a,ll b){ll r=1;a=a%mod;while(b){if(b%2)r=(r*a)%mod;a=(a*a)%mod;b=b/2;}
return r;}
 
 
 */
 int n,s;
 const int mod = 1000000007;
  const int N = 200009;
  int arr[N];
  int sum ; 
  bool check(int mid)
  {
      
     int v[n];
     

      fo(i,n)
        v[i] = arr[i] + (i+1)*mid; 

      sort(v,v+n);
     int sum = 0;
      for(int i=0;i<mid;++i)
        sum+= v[i];
      
     return sum>s;
  }
  
  

    int32_t main() {
     fastIO
     
     string a,b;
     cin>>a>>b;
     ll ct = 0;
     for(int i=0;i<a.size();++i)
     {
        if(a[i]!=b[i])
            ct++;
     }
 
    cout<<a.size()-ct;
 
     return 0;
      }
// always test the corner cases ALWAYS;

Measured memory_bytes: 256
while True:
	N, A, B, C, X = (int(x) for x in raw_input().split())
	if N == 0: break
	Y = [int(x) for x in raw_input().split()]
	for frame in xrange(10001):
		if X == Y[0]:
			Y.pop(0)
			if not Y:
				print frame
				break
		X = (A * X + B) % C
	else:
		print -1

Measured memory_bytes: 4216
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
//最大公約数
ll gcd(ll a, ll b){
  if(b == 0)return a;
  else return gcd(b, a % b);
}



int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
        if(i != 0)a[i] += a[i - 1];
    }
    ll res = INF * INF;
    rep(i, n){
        res = min(res, abs(a[i] * 2 - a[n - 1]));
    }
    cout << res << endl;
}





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

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

    long long add_a = 0, add_b = 0;
    for (int i = 0; i < n; i++) {
        int diff = b[i] - a[i];
        if (diff > 0) {
            if (diff % 2 == 0) {
                add_a += diff / 2;
            } else {
                add_a += diff / 2 + 1;
                add_b += 1;
            }
        } else {
            add_b += -1 * diff;
        }
    }

    // cout << add_a << " " << add_b << endl;
    if (add_a >= add_b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
N, M = map(int, input().split())
X = list(map(int, input().split()))
ans = 0
if (M-1)-(N-1) <= 0:
    pass
else:
    X.sort()
    dist = [X[i+1]-X[i] for i in range(M-1)]
    dist.sort()
    for i in range((M-1)-(N-1)):
        ans += dist[i]
print(ans)

Measured memory_bytes: 13968
from itertools import permutations
N,M=map(int,input().split())
k=[int(input())-1 for i in range(M)]
g=[i for i in range(N)]
for i in range(N):
    for j in k:
        if g[i]==j:
            g[i]=j+1
        elif g[i]==j+1:
            g[i]=j
s=10
for K in permutations(k):
    G=[i for i in range(N)]
    for i in range(N):
        for j in K:
            if G[i]==j:
                G[i]=j+1
            elif G[i]==j+1:
                G[i]=j
    if G!=g:
        continue

    l=[0]*N
    for i in range(M):
        a=K[i]
        b=max(l[a],l[a+1])
        l[a]=b+1
        l[a+1]=b+1
    s=min(s,max(l))
print(s)



Measured memory_bytes: 5652