akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var s = sc.str;
        int ans = 700;
        if (s[0] == 'o') ans += 100;
        if (s[1] == 'o') ans += 100;
        if (s[2] == 'o') ans += 100;

        wr.wri(ans);


    }


}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	class Vertex {
		int id;
		int[] vertices;
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		Vertex[] vertices = new Vertex[n];
		int discovered[] = new int[n];
		int completed[] = new int[n];
		for (int i = 0; i < n; i++) {
			vertices[i] = new Vertex();
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int id = Integer.parseInt(st.nextToken());
			vertices[i].id = id;
			int cnt = Integer.parseInt(st.nextToken());
			vertices[i].vertices = new int[cnt];
			for (int j = 0; j < cnt; j++) {
				vertices[i].vertices[j] = Integer.parseInt(st.nextToken());
			}
			discovered[i] = completed[i] = -1;
		}
		reader.close();
		
		DFS(vertices, completed, discovered, n);
		
		for (int i = 0; i < n; i++) {
			Vertex vertex = vertices[i];
			System.out.println(vertex.id + " " + completed[i] + " " + discovered[i]);
		}
	}

	private void DFS(Vertex[] vertices, int[] discovered, int[] completed, int n) {
		int time = 0;
		for (int i = 0; i < n; i++) {
			Vertex vertex = vertices[i];
			Stack<Integer> stack = new Stack<Integer>();
			if (discovered[vertex.id - 1] == -1) {
				stack.push(vertex.id);
			}
			while (!stack.isEmpty()) {
				vertex = vertices[stack.peek()-1];
				if (discovered[vertex.id - 1] == -1) {
					discovered[vertex.id - 1] = ++time;
				}
				int id = next(vertices, discovered, vertex);
				if (id != -1) {
					discovered[id-1] = ++time;
					stack.push(id);
				} else {
					completed[vertex.id - 1] = ++time;
					stack.pop();
				}
			}
		}
	}

	private int next(Vertex[] vertices, int[] discovered, Vertex vertex) {
		for (int i = 0; i < vertex.vertices.length; i++) {
			int id = vertex.vertices[i];
			if (discovered[id - 1] == -1) return id;
		}
		return -1;
	}
}



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

int main(){
  int N;
  string S;
  cin>>N>>S;
  // 半分に分割し、右側は反転
  string L = S.substr(0,N);
  string R = S.substr(N,2*N);
  reverse(R.begin(),R.end());
  // 左側の塗分け方を全探索
  map<P,ll> mp;
  for(int i=0;i<(1<<N);i++){
    string red = "";
    string blue = "";
    for(int j=0;j<N;j++){
      if(i & (1<<j)) red += L[j];
      else blue += L[j];
    }
    mp[{red,blue}]++;
  }
  // 右側の塗分け方を全探索
  ll ans = 0;
  for(int i=0;i<(1<<N);i++){
    string red = "";
    string blue = "";
    for(int j=0;j<N;j++){
      if(i & (1<<j)) red += R[j];
      else blue += R[j];
    }
    ans += mp[{red,blue}];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 91904
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin >> n;
    vector<float> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(), v.end());
    float ans = (v[0] + v[1]) / 2;
    for(int i = 2; i < n; i++) {
        ans = (ans + v[i]) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

using ull_t = unsigned long long;

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

    auto judge = [&]()
    {
        if (S.size() % 2 != 0)
            return false;
        for (int i = 0; i < S.size(); ++i)
        {
            switch (i % 2)
            {
            case 0:
                if (S[i] != 'h') return false;
                break;
            case 1:
                if (S[i] != 'i') return false;
                break;
            }
        }
        return true;
    };

    cout << (judge() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string s,t; cin >> s >> t;
    bool ans = false;
    REP(i,s.size()) {
        bool tmp = true;
        REP(j,s.size()) {
            if (s[(i+j) % s.size()] != t[j]) {
                tmp = false;
                break;
            }
        }
        if (tmp) {
            ans = true;
            break;
        }
    }

    ATYN(ans)

    return 0;
}

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

vector<int> edge[100010];
vector<bool> visit(100010, false);

int main(){
    ios::sync_with_stdio(false);
    int a, b, n, m;  cin >> n >> m;
    for(int i=0;m>i;i++){
        cin >> a >> b;
        edge[a].push_back(b);   edge[b].push_back(a);
    }
    deque<int> ans; ans.push_back(a); ans.push_back(b);
    visit[a]=visit[b]=true; bool check=true;
    while(check){
        check=false;
        int p=ans.front();   int q=ans.back();
        for(int i=0;edge[p].size()>i;i++){
            if(!visit[edge[p][i]]){
                check=true; visit[edge[p][i]]=1;    ans.push_front(edge[p][i]); break;
            }
        }
        for(int i=0;edge[q].size()>i;i++){
            if(!visit[edge[q][i]]){
                check=true; visit[edge[q][i]]=1;    ans.push_back(edge[q][i]); break;
            }
        }
    }
    cout << ans.size() << "\n";
    for(int i=0;ans.size()>i;i++){
        cout << ans[i] << " ";
    }

}


























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

int main(){
    int n;
    cin >> n;
    map<int, int> a;

    for(int i=0,in; i<n; i++){
        cin >> in;
        if(a.count(in) == 0){
            a[in] = 1;
        }else{
            a[in]++;
        }
        if(a.count(in+1) == 0){
            a[in+1] = 1;
        }else{
            a[in+1]++;
        }
        if(a.count(in-1) == 0){
            a[in-1] = 1;
        }else{
            a[in-1]++;
        }
    }
    int num=0;
    for(auto ele : a){
        if(ele.second > num){
            num = ele.second;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 4736
#include <stdio.h>

int main(){
	char c1,c2,c3;

	scanf("%c %c %c", &c1, &c2, &c3);

	if(c1 == '5'){
		if((c2 == '5' && c3 == '7') ||
			(c2 == '7' && c3 == '5')){
			printf("YES\n");
			return 0;
		}
	}
	if(c1 == '7'){
		if(c2 == '5' && c3 == '5'){
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;


}


Measured memory_bytes: 128
n = int(input())
t, a = map(int, input().split())
listH = list(map(int, input().split()))

nearA=10000000
number=0
index=0
while index < len(listH):
    h = listH[index]
    if index ==0:
        nearA = max(t-h*0.006, a)-min(t-h*0.006, a)
        number = index+1
    elif max(t-h*0.006, a)-min(t-h*0.006, a)< nearA:
        nearA = max(t-h*0.006, a)-min(t-h*0.006, a)
        number = index+1
    index+=1

print(number)
    


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

int main(){
  long n;
  cin >> n;
  for(long i=long(sqrt(n)); i>=1; i--){
    if(n%i==0){
      cout << (i-1)+(n/i-1);
      return 0;
    }
  }
  return 0;
}

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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=2e5 + 5;
const int M=1e5 + 5;

ll a[N],b[N],sum=0;
int main()
{
	ios_base::sync_with_stdio(false);
	int n,i;
	
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i]>>b[i];
		
		sum+=a[i];
	}
	bool ok=false;
	ll ans;
	for(i=0;i<n;i++){
		if(a[i]>b[i]){
			if(!ok){
				ok=true;
				ans=sum-b[i];
			}
			else{
				ans=max(ans,sum-b[i]);
			}
		}
	}
	if(ok) cout<<ans<<endl;
	else cout<<0<<endl;
		
	
		
	return 0;
}

Measured memory_bytes: 640
h, w, k = gets.split.map &:to_i
map = h.times.map { gets.chomp }
cnt = 0
(1<<h).times do |hs|
  (1<<w).times do |ws|
    c = 0
    h.times do |i|
      w.times do |j|
        if hs[i] == 0 and ws[j] == 0 and map[i][j] == '#'
          c += 1
        end
      end
    end
    if c == k
      cnt += 1
    end
  end
end

p cnt

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < n; i++) {
    int f = 0;
    for (int j = 0; i + j < n; j++) {
      if (a[j + i] != b[j]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      cout << n + i << '\n';
      return;
    }
  }
  cout << n + n << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3608
A=int(input())
B=int(input())
C=int(input())
X=int(input())

sum=[]
count=0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            s=500*a+100*b+50*c
            if s==X:
                count+=1
                sum.append([a,b,c])

print(count)


Measured memory_bytes: 8980
import sys

input = sys.stdin.readline


def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))


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

namespace AOJ.Volume2
{
    public class AtExpenseOfBoss
    {
        public static int Main()
        {
            // 1000000以下の素数を求める
            var prime = new List<int>() { 2 };
            bool is_prime;
            for (int i = 3; i <= 1000000; i = i + 2)
            {
                is_prime = true;
                foreach (var p in prime)
                {
                    if (i % p == 0)
                    {
                        is_prime = false;
                        break;
                    }
                    if (p * p >= i) { break; }
                }
                if (is_prime) { prime.Add(i); }
            }

            while (true)
            {
                var n_x = Console.ReadLine().Split(' ');
                int n = int.Parse(n_x[0]);
                int x = int.Parse(n_x[1]);
                if (n == 0 && x == 0) { break; }

                var price = new int[n];
                for (int i = 0; i < n; i++) { price[i] = int.Parse(Console.ReadLine()); }

                // 動的計画法で注文可能な金額を求める
                var dp = new bool[x + 1];
                dp[0] = true;
                foreach (var p in price)
                {
                    for (int i = 0; i <= x - p; i++)
                    {
                        if (dp[i]) { dp[i + p] = true; }
                    }
                }

                // 素数リストを大きい方からたどって最大の値を求める
                int answer = 0;
                foreach (var p in prime.Where(a => a <= x).OrderByDescending(b => b))
                {
                    if (dp[p])
                    {
                        answer = p;
                        break;
                    }
                }
                Console.WriteLine(answer == 0 ? "NA" : answer.ToString());
            }
            return 0;
        }
    }
}

Measured memory_bytes: 15456
#include <iostream>                                                                                       
#include <vector>                                                                                         
                                                                                                          
using namespace std;                                                                                      
                                                                                                          
int main (void) {                                                                                         
  int n, a;                                                                                               
  cin >> n;                                                                                               
  vector<int> v;                                                                                          
  for (int i=0; i<n; i++) {                                                                               
    cin >> a;                                                                                             
    v.push_back(a);                                                                                       
  }                                                                                                       
  for (int i=0; i<n; i++) {                                                                               
    if (i!=0) {                                                                                           
      cout << " " << flush;                                                                               
    }                                                                                                     
    cout << v[v.size()-1-i] << flush;                                                                     
  }                                                                                                       
  cout << endl;                                                                                           
}                                                                                                         
                                    

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

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

  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for (int i = 0; i < N; ++i) {
    cin >> l.at(i);
  }

  sort(l.rbegin(), l.rend());
  int ans = 0;
  for (int i = 0; i < K; ++i) {
    ans += l.at(i);
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
typedef long long ll;
#define PI 3.14159265
ll exponent(ll x,ll n,ll m)
{  if(n==0)
    return 1;
    if(n%2!=0)
    {
        return (x*exponent(((x%m)*(x%m))%m,(n-1)/2,m))%m;
    }
    else
    return exponent(((x%m)*(x%m))%m,n/2,m);
}
ll find(ll fact[],ll invfact[],ll n,ll a,ll r)
{
    if(r>a)
        return 0;
    ll ans=fact[a];
    ans=(ans%mod*invfact[r]%mod)%mod;
    ans=(ans%mod*invfact[a-r]%mod)%mod;
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(NULL);
    ll k,x;
    cin>>k>>x;
    if(500*k>=x)
        cout<<"Yes";
        else
            cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int a, b;
  cin>>a>>b;

  string sa = string(b, char(a + '0'));
  string sb = string(a, char(b + '0'));
  string ans = min(sa, sb);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
N=int(input())

def isprime(n):
	for i in range(2,int(n**.5)+1):
		if n%i==0:return False
	return True


A=[]
cnt=0
c=6

while True:
	if isprime(c):
		A.append(c)
		cnt+=1
	if cnt>=N:break
	c+=5

print(*A)

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

using namespace std;
int main()
{
    int x, sum = 0;
    int i = 0;
    cin >> x;
    for (; sum < x; i++)
    {
        sum += i;
        if (sum == x)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << i - 1 << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var t=sc.S;
		int n=t.Length;
		bool b=true;StringBuilder sb=new StringBuilder();
		int g=1;
		for(int i = 0;i<n-1;i++) {
			if(i<n/2){
				if(t[i]!=t[n-i-2]){
					b=false;
					break;
				}
			}
			sb.Append(g+" "+(i+2)+"\n");
			if(i<n/2&&t[i]=='1'){g=i+2;}

		}
		if(t[n-1]=='1'||t[0]=='0'){b=false;}
		if(!b){Console.WriteLine("{0}",-1);}
		else{Console.Write(sb);}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


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

int main(void){
    // Your code here!
    int N,L;
    char str[100][101],tmp[101];
    int i,j;
    
    scanf("%d%d",&N,&L);
    
    for(i=0;i<N;i++){
        scanf("%100s",str[i]);
    }
    
    for(i=0;i<N;i++){
        for(j=N-1;j>i;j--){
            if(strcmp(str[j-1],str[j]) > 0){
                strcpy(tmp,str[j-1]);
                strcpy(str[j-1],str[j]);
                strcpy(str[j],tmp);
            }
        } 
    }
    
    for(i=0;i<N;i++){
        printf("%s",str[i]);
    }
}


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

int main() {
	long n,m,ans=0;
  	cin >> n >> m;
  	vector<long> a(m);
  	for(long i = 0; i<m; i++){
      cin >> a[i];
      ans= ans+a[i];
    }
  	if(n<ans){
      cout << -1 << endl;
    }
  	else{
  	cout << n-ans << endl;
    }
}


Measured memory_bytes: 3692
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

LL modpow(LL a, LL b) {
  LL r = 1;
  while (b) {
    if (b % 2 == 1) r = r * a;
    a = a * a;
    b /= 2;
  }
  return r;
}

LL dp[200];

int main() {
  LL X; cin >> X;
  for (int i = 0; i < 200; ++i) {
    dp[i] = modpow(i, 5);
  }

  for (int i = 0; i < 200; ++i) {
    for (int j = 0; j < 200; ++j) {
      if (dp[i]-dp[j] == X) {
        cout << i << " " << j << endl;
        return 0;
      }
      if (dp[i]+dp[j] == X) {
        cout << i << " " << -j << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3632
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	hs := make([]int, n)
	for i := range hs {
		fmt.Scan(&hs[i])
	}

	count := 1
	if n != 1 {
		for i := 1; i < n; i++ {
			if f(hs, i) {
				count++
			}
		}
	}

	fmt.Print(count)
}

func f(hs []int, idx int) bool {
	h := hs[idx]
	for i := 0; i < idx; i++ {
		if h < hs[i] {
			return false
		}
	}
	return true
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdio>
#include <unordered_map>
#include <vector>
#define task ""
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e5 + 2;
int n, x;
bool ck[N];
vector<int> a;

void Read(){
	cin >> x >> n;
	while(n--){
		int a;
		cin >> a;
		if(a >= 0)
			ck[a] = 1;
	}
	for(int i = 0; i <= 200; ++i)
		if(!ck[i])
			a.push_back(i);
}

void Solve(){
	int j = lower_bound(a.begin(), a.end(), x) - a.begin();
	cout << (abs(a[j] - x) >= abs(a[j - 1] - x) ? a[j - 1] : a[j]);
}

main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	Read();
	Solve();
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;


int main(void){
	ll N;cin>>N;
	ll A[N + 1];rep(i,N+1)cin>>A[i];
	ll B[N];rep(j,N)cin>>B[j];
	ll sum = 0;

	for(ll t = 0; t < N; t++){
		if(A[t] <= B[t]){
			sum += A[t];
			if(A[t+1]>= B[t]-A[t]){
				A[t+1] -= B[t] - A[t];
				sum += B[t]-A[t];
			}
			else{
				sum += A[t+1];
				A[t+1]=0;

			}
		}
		else {
			sum += B[t];

		}
	}

	cout<<sum;

}


Measured memory_bytes: 1792
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

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

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  int X, Y;
  cin >> X >> Y;
  if (Y % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  int a = 2 * X - Y / 2;
  if (a < 0 || a > X) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>

using std::max;
using std::min;
using std::cerr;
using std::endl;

inline void read(int &x)
{
    int s = 0, w = 1;
    char c = getchar();
    while(!isdigit(c)){if(c == '-')w = -1; c = getchar();}
    while(isdigit(c)){s = (s << 3) + (s << 1) + c - '0', c = getchar();}
    x = s * w;
}

typedef long long ll;
#define rg register int

const int N = 200010, mod = 1e9 + 7;

inline int ksm(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = (ll) res * a %mod;
        a = (ll) a * a % mod, b >>= 1;
    }
    return res;
}

int fac[N], ifac[N], a, b, c, n;

inline int calc(int x, int y)
{
    return (ll) fac[x + y - 1] * ifac[y] % mod * ifac[x - 1] % mod;
}

int ans;

int main()
{
    read(n), read(a), read(b), read(c);
    a = (ll) a * ksm(100, mod - 2) % mod;
    b = (ll) b * ksm(100, mod - 2) % mod;
    c = (ll) c * ksm(100, mod - 2) % mod;
    c = ksm(mod + 1 - c, mod - 2);
    fac[0] = 1;
    for (rg i = 1; i <= (n << 1); i++)
        fac[i] = (ll) fac[i - 1] * i %mod;
    ifac[n << 1] = ksm(fac[n << 1], mod - 2);
    for (rg i = (n << 1); i;i--)
        ifac[i - 1] = (ll) ifac[i] * i % mod;
    int tmp = (a + b) % mod;
    //cerr << a << " " << b <<endl;
    a = (ll) a * ksm(tmp, mod - 2) % mod;
    b = (ll) b * ksm(tmp, mod - 2) % mod;
    for (rg i = 0; i < n; i++)
        (ans += (ll) calc(n, i) * ksm(a, i) % mod * ksm(b, n) % mod * (i + n) % mod) %= mod,
        (ans += (ll) calc(n, i) * ksm(b, i) % mod * ksm(a, n) % mod * (i + n) % mod) %= mod;
    ans = (ll) ans * c % mod;
    printf("%d\n",ans);
}

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


int main()
{
	int n,m;
	cin>>n>>m;
	vector<int> votes(n);
	double total=0;
	for(int i=0;i<n;i++){
		cin>>votes[i];
		total += votes[i];
	}
	double qualify = (total/4)/m;
	sort(votes.rbegin(),votes.rend());
	
	
	if(votes[m-1]<qualify) cout<<"No";
	else cout<<"Yes";
	
	
}

Measured memory_bytes: 256
#include<cstdio>

const int N = 65555;
int prime[N] = {0},num_prime = 0;
int isNotPrime[N] = {1, 1};

int main()
{
    int n;
    for(long i=2; i<(2<<16); i++)
    {
        if(!isNotPrime[i])
            prime[num_prime++]=i;
        for(long j = 0 ; j < num_prime && i * prime[j] <  N ; j ++)
        {
            isNotPrime[i * prime[j]] = 1;
            if( !(i % prime[j] ) )
                break;
        }
    }
    while(~scanf("%d",&n),n)
    {
        int cnt = 0;
        for(int i=0; prime[i]<n; i++)
            for(int j=i; prime[j]<n; j++)
                if(prime[i] + prime[j] == n)
                    cnt++;
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 1540
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 507;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
char s[maxN][maxN];
char t[2][maxN][maxN];

int main() {

	n = ri(), m = ri();
	rep (i, 1, n) scanf("%s", s[i]+1);

	rep (i, 1, n) rep (j, 1, m) t[0][i][j] = t[1][i][j] = '.';
	For (i, 2, n) rep (j, 1, m) t[j & 1][i][j] = '#';
	rep (j, 1, m) t[0][1][j] = t[1][n][j] = '#';
	rep (i, 1, n) rep (j, 1, m) if (s[i][j] == '#') t[(j + 1) & 1][i][j] = '#';
	
	rep (i, 1, n) puts(t[0][i]+1);
	puts("");
	rep (i, 1, n) puts(t[1][i]+1);

	return 0;
}


Measured memory_bytes: 1408
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

import math

def check(l, N):
    ls = [i for i in range(N)]
    number = 0
    for i in range(N-1):
        number += math.factorial(N-1-i) * ls.index(l[i]-1)
        ls.remove(l[i]-1)
    number += 1
    return number

ans = check(P, N) - check(Q, N)
print(abs(ans))

Measured memory_bytes: 9024
#include <bits/stdc++.h>
#define ll long long
#define inf 0x6fffffff
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
    int R=read(),G=read(),B=read(),N=read();
    int ans=0;
    for(int i=0;i<=N;i++)
        for(int j=0;j<=N;j++)
        {
            int k=N-i*R-j*G;
            if(k%B!=0||k<0)continue;
            ans++;
        }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let n: u8 = read();
    let s: String = read();

    let shifted_s: String = String::from_utf8(s.chars().map(|x| {
        (x as u8 - 'A' as u8 + n) % 26 + 'A' as u8
    }).collect::<Vec<u8>>()).unwrap();

    println!("{}", shifted_s);
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
using System;

namespace ITP1_9
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] s = new int[2] { 0, 0 };
            int l = int.Parse(Console.ReadLine());

            for (int i = 0; i < l; i++)
            {
                string[] cards = Console.ReadLine().Trim('\n').Split(' ');
                if (cards[0] == cards[1])
                {
                    s[0]++;
                    s[1]++;
                    continue;
                }
                string[] judge = new string[2];
                Array.Copy(cards, 0, judge, 0, 2); Array.Sort(judge);
                s[judge[1] == cards[1] ? 1 : 0]+=3;
            }

            Console.WriteLine("{0} {1}", s[0], s[1]);
        }
    }
}

Measured memory_bytes: 10168
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define itoc(c)               ((char)(((int)'0')+c))
#define vl                    vector<ll>
#define SZ(x)                 (x).size()
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define sv()                  ll t,n; scanf("%lld",&t);n=t; while(t--)
#define tcase()               ll t,n; cin>>t;n=t; while(t--)
#define iscn(num)             scanf("%d",&num);
#define scn(num)              scanf("%lld",&num);
#define dbg(x)                cout <<"( "<<#x << " = " << x << " )"<<endl
using namespace std;
const ll INF = 2e18 + 99;
typedef pair<ll,ll> Pair;
typedef vector<ll> vec;;
void FAST_IO();
////////////////////////

int main()
{
	int a, b, c;
	scanf("%d%d%d",&a,&b,&c);
	if(b<a)
		swap(a,b);
	if(a<=c && c<=b)
		puts("Yes");
	else
		puts("No");
	
   return 0;
}

void FAST_IO()
{
    // ios_base::sync_with_stdio(0);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  int x, y, z, k; cin>>x>>y>>z>>k;
  vector<long long> a(x), b(y), c(z);
  rep(i, x) cin>>a[i];
  rep(i, y) cin>>b[i];
  rep(i, z) cin>>c[i];

  vector<long long> ab;
  rep(i, x) rep(j, y) ab.emplace_back(a[i]+b[j]);
  sort(ab.begin(), ab.end(), greater<long long>());

  vector<long long> abc;
  rep(i, min((int)ab.size(), k)) rep(j, z) abc.emplace_back(ab[i]+c[j]);
  sort(abc.begin(), abc.end(), greater<long long>());

  rep(i, k) print(abc[i]);

  return 0;
}

Measured memory_bytes: 43112
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define PI 3.141592653
int main()
{
	ll n,k;
	cin>>k>>n;
	ll a[n];
	ll sum=0;
	rep(i,0,n)
	{
		cin>>a[i];
		sum+=a[i];
	}
	k-sum<0?cout<<"-1\n":cout<<k-sum<<"\n";
	return 0;
}

Measured memory_bytes: 3668
N = int(input())
D, X = map(int, input().split())
A = [int(input()) for _ in range(N)]
I = [1] * N

ans = X

for j in range(1, D + 1):
    for i in range(N):
        if I[i] == j:
            ans += 1
            I[i] += A[i]

print(ans)


Measured memory_bytes: 9180
use std::io;

fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

fn read_ints() -> Vec<i32>{
    let s = read_line();
    let split:Vec<&str> = s.trim().split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

fn main(){
    //let array = read_ints();
    //let x = array[0];
    //let y = array[1];
    
    let xyz = read_ints();
    let x = xyz[0];
    let y = xyz[1];
    let z = xyz[2];
    
    let n = (x-z) / (y+z);
    println!("{}",n);
}



Measured memory_bytes: 4352
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

void swap(int &x, int &y){
  int tmp;
  tmp=y;
  y=x;
  x=tmp;
}

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  swap(a,b);
  swap(a,c);
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S; cin >> S;
    int x,y; cin >> x >> y;

    int acc = 0;
    VI move;
    REP(i,S.length())
    {
        if(S[i] == 'F') acc++;
        else{
            move.eb(acc);
            acc = 0;
        }
    }
    move.eb(acc);
    VI xmove,ymove;

    int cnt = 0;
    for(auto p : move)
    {
        if(cnt % 2 == 0) xmove.eb(p);
        else ymove.eb(p);

        cnt++;
    }
    VI dpx(20000,0);
    VI dpy(20000,0);
    // init: 10000, 100000

    if(S[0] == 'F'){
        dpx[10000+xmove[0]] = 1;
        dpy[10000] = 1;
    }
    else{
        dpx[10000] = 1;
        dpy[10000] = 1;
    }

    xmove.erase(xmove.begin());

    //cout << printVector(xmove) << endl;
    //cout << printVector(ymove) << endl;


    for(auto p : xmove)
    {
        VI truelist;
        REP(i,20000){
            if(dpx[i] == 1){
                truelist.eb(i+p);
                truelist.eb(i-p);
            }
        }
        dpx.assign(20000, 0);
        for(auto p : truelist){
            dump(p)
            dpx[p] = 1;
        }
    }

    dump("ymove")
    for(auto p : ymove)
    {
        VI truelist;
        REP(i,20000){
            if(dpy[i] == 1){
                truelist.eb(i+p);
                truelist.eb(i-p);
            }
        }
        dpy.assign(20000, 0);
        for(auto p : truelist){

            dump(p)
            dpy[p] = 1;
        }
    }

    if(dpx[10000+x] == 1 && dpy[10000+y] == 1) cout << "Yes" << endl;
    else cout << "No" << endl;


}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const int bits = 50;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (auto& x : A) cin >> x;
    ll X = A[0], Y = A[1], Z = 0;
    for (int i = 2; i < N; i++) Z ^= A[i];
    ll S = X + Y;
    if ((S - Z) < 0 || (S - Z) % 2 == 1) {
      cout << -1 << endl;
      continue;
    }
    ll D = (S - Z) / 2;
    auto dp = make_v(bits + 1, 2, -1ll);
    dp[bits][0] = 0;
    for (int i = bits - 1; i >= 0; i--) {
      int x = (X >> i) & 1, z = (Z >> i) & 1, d = (D >> i) & 1;
      for (int less = 0; less < 2; less++) {
        ll value = dp[i + 1][less];
        if (value < 0) continue;
        for (int a = 0; a < 2; a++) {
          if (!less && a > x) continue;
          if ((a & (z ^ a)) != d) continue;
          chmax(dp[i][less | (a < x)], value * 2 + a);
        }
      }
    }
    ll sub = max(dp[0][0], dp[0][1]);
    if (sub <= 0) {
      cout << -1 << endl;
    } else {
      cout << X - sub << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3544
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

void solve(ll N){
    --N;
    string res = "";
    while (N >= 0){
        char c = ('a' + N % 26);
        N /= 26;
        --N;
        res = c + res;
    }
    cout << res << endl;
}

int main(void){
    ll N; cin >> N;
    solve(N);
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n-1);
    vector<ll>hist(n+3); 
    REP(i,n+3){
        hist[i] = 0;
    }
    REP(i,n-1){
        cin >> a[i];
        hist[a[i]]++;
    }

    FOR(i,1,n+1)cout << hist[i] << endl;
    

    

    return 0;
}

Measured memory_bytes: 6376
n = input()
aa = list(map(int, input().split()))
max_a = aa[0]
step = 0
for i in range(1, len(aa)):
    if max_a > aa[i]:
        # 踏み台必要
        step += max_a - aa[i]
    else:
        max_a = aa[i]
print(step)


Measured memory_bytes: 32236
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define endll '\n'
#define C getchar()
//using ll=long long;
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pii pair<int,int>
const int MAXN = 1e6 + 10;
#define lowbit(x) ((x) & (-x))
#define Temp template <typename T>
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)

int main()
{    
   int n;
   cin>>n;
   if(n%2==0)
   {
       cout<<n;
   }
else cout<<2*n;
    return 0;
}



Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: String = scan(tokens);
    let k: usize = scan(tokens);
    let n: Vec<usize> = n
        .chars()
        .map(|c| (c as i32 - '0' as i32) as usize)
        .collect();
    fn f(n: &[usize], k: usize) -> usize {
        if k == 0 {
            1
        } else if n.is_empty() {
            0
        } else if n[0] == 0 {
            f(&n[1..], k)
        } else {
            g(n.len() - 1, k) + (n[0] - 1) * g(n.len() - 1, k - 1) + f(&n[1..], k - 1)
        }
    }
    fn g(l: usize, k: usize) -> usize {
        let mut numer = 1;
        let mut denom = 1;
        for i in 0..k {
            numer *= l - i;
            numer *= 9;
            denom *= k - i;
        }
        numer / denom
    }
    println!("{}", f(&n, k));
}


Measured memory_bytes: 4352
A = int(input())

if A == 111:
    print(999)
elif A == 119:
    print(991)
elif A == 199:
    print(911)
elif A == 999:
    print(111)
elif A == 991:
    print(119)
elif A == 911:
    print(199)
elif A == 919:
    print(191)
elif A == 191:
    print(919)


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100005;
int spf[MAXN];
ll fac1[MAXN],fac2[MAXN],inv[MAXN];
ll gcd(ll x, ll y){ return y?gcd(y,x%y):x; }

void sieve(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

void pre(){
    fac1[0]=fac2[0]=inv[1]=1;
    for(int i=1;i<MAXN;i++){
        fac1[i]=(fac1[i-1]*i)%mod;
        if(i>1) inv[i]=( mod - ((ll)(mod/i)*inv[mod%i])%mod ) %mod;
    }
    for(int i=1;i<MAXN;i++) fac2[i]=(fac2[i-1]*inv[i])%mod;
}
ll C(int n,int k){
    if(n<k) return 0;
    return ((fac1[n]*fac2[n-k]%mod)*fac2[k]%mod);
}

vi ad[100005];
bool vis[100005];

void dfs(int v,int p=-1){
    vis[v]=1;
    All(x,ad[v]){
        if(!vis[x] && x!=p) dfs(x,v);
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,m,t=1;
    // cin>>t;
    while(t--){
        cin>>n>>m;
        ing(m,ad);
        rep(i,n) vis[i]=0;
        int cnt=0;
        rep(i,n){
            if(!vis[i]) {dfs(i); cnt++;}
        }
        cout<<cnt-1<<nl;
    }
    return 0;
}

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

int cmp(const void*a,const void*b){
	long long temp;
	temp = *(long long*)a - *(long long*)b;
	if(temp>0)return 1;
	if(temp==0)return 0;
	if(temp<0)return -1;
}

long long combi(long n,long r) {
		if (r == 0) {
		return 1;
	}
	return (n - r + 1) * combi(n, r - 1) / r;
}
int main(void){
	int N,M;
	scanf("%d %d",&N,&M);
	long long B[N+1];
	int i,j;
	long long temp;
	long long ans = 0;
	long long count;
	B[0]=0;
	for(i=1;i<=N;i++){
		scanf("%lld",&temp);
		B[i]=B[i-1]+temp;
	}
	long long C[N+1];
	for(i=0;i<=N;i++){
		C[i]=B[i]%M;
	}
	i = 0;
	qsort(C,N+1,sizeof(long long),cmp);
	for(i=0;i<=N;i++){
		count=1;
		while(C[i]==C[i+1]){
			count++;
			i++;
		}
		ans += count*(count-1)/2;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2556
import itertools

N = int(input())
N_list = [i for i in range(1, N+1)]

A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

N_pattern = list(itertools.permutations(N_list))

print(abs(N_pattern.index(A) - N_pattern.index(B)))


Measured memory_bytes: 8052
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}



int main() {

	string S, T;
	cin >> S >> T;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] != T[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;

}


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

using namespace std;

int main() {
  int N, X;
  cin >> N >> X;
  int sum = 0;
  int cnt = 1;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    sum += a;
    if (sum <= X) cnt++;
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256