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

using namespace std;

vector<vector<int> > a;

void f0()
{
    int p1,p2;

    cin>>p1>>p2;

    a[p1].push_back(p2);
}

void f1()
{
    int p;
    cin>>p;

    for(int i=0;i<a[p].size();i++)
    {
        if(i) cout<<" ";
        cout<<a[p][i];
    }
    cout<<endl;
}

void f2()
{
    int p;

    cin>>p;

    a[p].clear();
}

int main()
{
    int n,q;

    cin>>n>>q;

    a.resize(n);

    while(q--)
    {
        int op;
        cin>>op;

        switch(op)
        {
            case 0:f0();break;
            case 1:f1();break;
            case 2:f2();break;
        }
    }

    return 0;
}



Measured memory_bytes: 5856
#include <iostream>
using namespace std;
int main(void){
    long long N, A, B, ans;
    cin >> N >> A >> B;
 
    if( A == B )
    {
        cout << 1 << endl;
    }
    else if( (A > B) || ( N <= 1) )
    {
        cout << 0 << endl;
    }
    else
    {
        ans = (B - A) * (N - 2) + 1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &a) {
    register T x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
    a = x * flag;
}

template <class T>
inline void write(T x) {
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, a, b) for (int i = (a); i <= (b); i++) 
#define Rep(i, a, b) for (int i = (a); i >= (b); i--) 
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)

const int maxn = 13;
int a[maxn][maxn], c[maxn];
int n, m, X, sum[maxn];
int check() {
	For (i, 1, m) if (sum[i] < X) return 0;
	return 1;
}
int main() {
	read(n); read(m); read(X);
	For (i, 1, n) {
		read(c[i]);
		For (j, 1, m) {
			read(a[i][j]);
		}
	}
	int mm = 1000000000;
	for (int i = 0; i < (1 << n); i++) {
		For (j, 1, m) sum[j] = 0;
		int cc = 0;
		For (j, 1, n) {
			if (i & (1 << (j - 1))) {
				For (k, 1, m) {
					sum[k] += a[j][k];
				}
				cc += c[j];
			}
		}
		if (check()) mm = min(mm, cc);
	}
	if (mm == 1000000000)  cout << -1;
	else cout << mm;
}


Measured memory_bytes: 3648
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<Integer> one = nextIntArray();
      int A = one.get(0);
      int B = one.get(1);
      if(A < 10 && B < 10){
        myout(A * B);
      }else{
        myout(-1);
      }
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

const int MAXN = 55;
int n, m;
int a[MAXN], b[MAXN];

bool graph[MAXN][MAXN];
bool visited[MAXN];

void dfs(int v) {
  if (visited[v]) return;
  visited[v] = true;
  rep(i,n) {
    if (graph[v][i]) dfs(i);
  }
}

int main () {
  cin >> n >> m;
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  int ans = 0;
  rep(i,m) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    rep(j,n) visited[j] = false;
    dfs(0);
    rep(j,n) {
      if (!visited[j]) {
        ans++;
        break;
      }
    }
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

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

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

int main(){
int A,B;
  cin>>A>>B;
  string S;
  cin>>S;
  
  bool flag=true;
  for(int i=0; i<=A-1; i++){
   if(S[i]=='-'){flag=false;}
  }
  
  if(S[A]!='-'){flag=false;}
  
  for(int i=A+1; i<S.size(); i++){
   if(S[i]=='-'){flag=false;}
  }
  
  if(!flag){cout<<"No";}
  else{cout<<"Yes";}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	int n,nn; cin >> n;
	nn = n;

	int sum = 0;

	while (n) {
		sum += n % 10;
		n /= 10;
	}

	if (nn % sum == 0) cout << "Yes";
	else cout << "No";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template <typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}
template<class T> bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1;}
    return 0;
}
template<class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return 1;}
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    if(N %2 != 0){
        cout << "No" << endl;
        return 0;
    }
    REP(i,N/2){
        if(S[i] != S[N/2+i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3592
/// @file
/// @copyright 2018 thousand
/// @version Accepted.
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::max_element;
using std::string;
using std::stringstream;
using std::vector;

namespace {
class Ints : public vector<int> {
 public:
  string str();
};
class Intss : public vector<Ints> {
 public:
  string str(string delimiter);
};
class Intsss : public vector<Intss> {
 public:
  string str();
};
string Ints::str() {
  stringstream ss;
  for (auto it = this->begin(); it != this->end(); ++it) {
    ss << *it;
    if (it != this->end() - 1) ss << " ";
  }
  return ss.str();
}
string Intss::str(string delimiter="\n") {
  stringstream ss;
  for (auto it = this->begin(); it != this->end(); ++it) {
    ss << it->str();
    if (it != this->end() - 1) ss << delimiter;
  }
  return ss.str();
}
string Intsss::str() {
  stringstream ss;
  for (auto it = this->begin(); it != this->end(); ++it) {
    ss << it->str(" ");
    if (it != this->end() - 1) ss << endl;
  }
  return ss.str();
}
void GetInput(int* N, Intsss* F, Intss* P) {
  cin >> *N;
  for (int i = 1; i <= *N; ++i) {
    Intss intss;
    for (int j = 1; j <= 5; ++j) {
      Ints ints;
      for (int k = 1; k <= 2; ++k) {
        ints.push_back(-1);
        cin >> *--ints.end();
      }
      intss.push_back(ints);
    }
    F->push_back(intss);
  }
//  cout << F->str() << endl;
  for (int i = 1; i <= *N; ++i) {
    Ints ints;
    for (int j = 0; j <= 10; ++j) {
      ints.push_back(-1);
      cin >> *--ints.end();
    }
    P->push_back(ints);
  }
//  cout << P->str() << endl;
}
void Solve(int N, Intsss& F, Intss& P) {
  Ints profits;
  for (int b = 1; b <= 1023; ++b) {  // for each case.
    int P_sum = 0;
    for (int i = 0; i < N; ++i) {
      // "Let c_i be the number of periods during which both Shop i"
      // "and Joisino's shop are open."
      int c_i = 0;
      for (int j = 0; j < 5; ++j) {
        for (int k = 0; k < 2; ++k) {
          bool open_shop_i = F[i][j][k];
          bool open_Joisino = (b >> (2 * j + k) & 1);
          if (open_shop_i && open_Joisino) ++c_i;
        }
      }
      P_sum += P[i][c_i];
    }
    profits.push_back(P_sum);
  }
  cout << *max_element(profits.begin(), profits.end()) << endl;
}
}  // namespace

int main() {
  int N;
  Intsss F;
  Intss P;
  GetInput(&N, &F, &P);
  Solve(N, F, P);
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c;
        if (total == X) ++res;
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end
def na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
a,b = inp
if((a-b).abs < 2)
  puts "Brown"
else
  puts "Alice"
end
=begin
=end


Measured memory_bytes: 1788
import java.util.Map.Entry;
import java.util.*;

import org.w3c.dom.css.Counter;

public class Main {
//public class App {

    public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
       // 入力
       int n = Integer.parseInt(s.next());
       int n2 =Integer.parseInt(s.next());
        if(n <= n2){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
}

Measured memory_bytes: 35664
#include <stdio.h>

int main() {
    char cup = 'A';
    char a, b;
    while (scanf("%c,%c", &a, &b) != EOF) {
        if (a == cup) {
            cup = b;
        }
        else if (b == cup) {
            cup = a;
        }
    }
    printf("%c\n", cup);
    return 0;
}

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

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> ans1(n);
    vector<int> ans2(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    sort(a.begin(), a.end());

    int half = n / 2;
    int left, right;
    int count;

    ans1[0] = a[half];
    left = 0, right = n - 1;
    count = 1;
    while(true){
        ans1[count] = a[right];
        right--;
        count++;
        if(count == n) break;
        ans1[count] = a[left];
        left++;
        count++;
        if(count == n) break;
    }

    ans2[0] = a[half];
    left = 0, right = n - 1;
    count = 1;
    while(true){
        ans2[count] = a[left];
        left++;
        count++;
        if(count == n) break;
        ans2[count] = a[right];
        right--;
        count++;
        if(count == n) break;
    }

    long long sum1 = 0, sum2 = 0;
    for(int i = 0; i < n - 1; i++) sum1 += abs(ans1[i + 1] - ans1[i]);
    for(int i = 0; i < n - 1; i++) sum2 += abs(ans2[i + 1] - ans2[i]);
    cout << max(sum1, sum2) << endl;

    return 0;
}


Measured memory_bytes: 1408
def contest(N, str):
    count = {}

    for s in str:
        if s not in count:
            count[s] = 1

        else:
            count[s] +=  1
    
    ret = sorted(count.items(),key=lambda count: count[1], reverse=True)
    maxnum = ret[0][1]
    
    retVal = []

    for r in ret:
        if r[1] == maxnum:
            retVal.append(r[0])
            
        else:
            break

    result = '\n'.join(sorted(retVal))

    return result


if __name__ == "__main__":
    N = int(input())
    S = []

    for i in range(N):
        S.append(input())

    print(contest(N, S))


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

#define NM (1<<16)

int prime[NM] = {0};

int main()
{
	prime[0] = prime[1] = 1;
	for(int i=2; i*i<NM; i++)
	{
		if(!prime[i])
		{
			for(int j=i*2; j<NM; j+=i)
			{
				prime[j] = 1;
			}
		}
	}

	int n,c;
	while(cin >> n, n)
	{
		c=0;
		for(int i=2; i<=n/2; i++)
		{
			if((!prime[i])&&(!prime[n-i])) c++; 
		}
		cout << c << endl;
	}
}

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

#define Bye return 0
#define ll long long
const ll MAX = 1e9+7;

void solve(){
    char a, b; cin>>a>>b;
    cout<<(a!=b?"D":"H")<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3572
//It is made by Awson on 2018.2.3
#include <bits/stdc++.h>
#define LL long long
#define dob complex<double>
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
#define writeln(x) (write(x), putchar('\n'))
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int l1 = 10000000;
const int l2 = 25500000;
const int yzh = 1e9+7;
void read(int &x) {
    char ch; bool flag = 0;
    for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
    for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
    x *= 1-2*flag;
}
void print(int x) {if (x > 9) print(x/10); putchar(x%10+48); }
void write(int x) {if (x < 0) putchar('-'); print(Abs(x)); }

int s, f[l2+5];

int quick_pow(int a, int b) {
    int ans = 1;
    while (b) {
	if (b&1) ans = 1ll*ans*a%yzh;
	a = 1ll*a*a%yzh, b >>= 1;
    }
    return ans;
}
int count1(int n) {
    int ans = 0, r = 0, cnt = 0;
    for (int i = 1; i < l1; i++) {
	cnt -= f[i-1];
	while (cnt+f[r+1] <= s && r < l2) cnt += f[++r];
	if (cnt == s) ++ans;
	if (r == l2) break;
    }
    return ans;
}
int count2(int n) {
    int lim = n/8, ans = lim;
    for (int t = 1; t <= lim; t++)
	if (n%t == 0) {
	    int len = n/t;
	    (ans += (1ll*quick_pow(10, len-1)*9%yzh-t)%yzh) %= yzh;
	}
    return ans;
}
void work() {
    for (int i = 1, r = 10, cnt = 1; i < l1; i++, i = r, r = r*10, cnt++)
	for (int j = i; j < r; j++) f[j] = cnt;
    for (int i = l1; i <= l2; i++) f[i] = 8;
    read(s);
    writeln(((count1(s)+count2(s))%yzh+yzh)%yzh);
}
int main() {
    work();
    return 0;
}


Measured memory_bytes: 99968
#include <iostream>
using namespace std;
int main(){
  int m,f,r;
  while(1){
    cin >> m >> f >> r;
    if(m==-1&&f==-1&&r==-1) break;
    if(m==-1||f==-1) cout << 'F' << endl;
    else if(m+f>=80) cout << 'A' << endl;
    else if(m+f>=65) cout << 'B' << endl;
    else if(m+f>=50) cout << 'C' << endl;
    else if(m+f>=30){
      if(r>=50) cout << 'C' << endl;
      else cout << 'D' << endl;
    }
    else cout << 'F' << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

class UnionFind {
    // 各ノードが根である時の高さ
    // ノードが根でないときは意味をなさない
    vector<int> rank;
    // 各ノードが属する木の根
    // findSetするときのみ更新される
    vector<int> p;
    // 二つの根を結合
    void link(int rx, int ry) {
        if (rx == ry) return;
        if (rank[rx] > rank[ry]) p[ry] = rx;
        else p[rx] = ry;
        if (rank[rx] == rank[ry]) rank[ry]++;
    }
public:
    //　根を作成
    // その木の高さは0
    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }
    // 初期化
    // 入力サイズ分のノードを確保
    // それらのノードをそれぞれ根とする木を作成
    // ノードの値は 0 ~ size-1
    UnionFind(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        rep(i,size) makeSet(i);
    }
    // あるノードの属する木の根を返す
    // 根を探す過程で途中のノードの親も更新
    int findSet(int x) {
        if (x != p[x]) p[x] = findSet(p[x]);
        return p[x];
    }
    // 二つのノードが同じ木にあるか判定
    bool same(int x, int y) {return findSet(x) == findSet(y);}
    // 二つのノードの属する木を結合
    void unite(int x, int y) {link(findSet(x), findSet(y));}
};

int main() {
    fast_io
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
        p[i]--;
    }
    UnionFind u(n);
    int x, y;
    rep(i,m) {
        cin >> x >> y;
        u.unite(x-1, y-1);
    }
    int ans = 0;
    rep(i,n) {
        if (u.same(i, p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    N+=1
    H=[0]+list(map(int,input().split()))+[0]
    dp=[[INF]*(K+1) for _ in range(N+1)]
    dp[0][0]=0
    for i in range(N):
        for j in range(K+1):
            for k in range(j,K+1):
                if i-(k-j)>=0:
                    dp[i+1][k]=min(dp[i+1][k],dp[i-(k-j)][j]+max(H[i+1]-H[i-(k-j)],0))
                    pass
    print(dp[-1][-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 41840
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		System.out.println(recursive(N));
		scanner.close();
	}public static int recursive(int n) {
		if(n==1) return 1;
		else return recursive(n-1)+n;
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()


using namespace std;

const bool dbg_flg = 1;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n'
 
const int inf = 1e9 + 7;
const int MAXN = 1e6 + 5;
const ll INF = 1e18;

ll n, w;
ll dp[MAXN];
pair<ll, ll> p[MAXN];
bool used[MAXN];

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> n >> w;
	for (int i = 1; i <= n; i++) {
		ll a, b;
		cin >> a >> b;
		p[i] = mp(b, a);
	}

	sort (p + 1, p + 1 + n);
	
	int N = 200000;
	
	for (int i = 1; i <= N; i++) {
		dp[i] = INF;
	}
	
	dp[0] = 0;
	used[0] = 1;
	
	for (int i = 1; i <= n; i++) {
		for (int j = N - p[i].F; j >= 0; j--) {
			if (used[j] == 0) continue;
			dp[j + p[i].F] = min(dp[j + p[i].F], dp[j] + p[i].S);
			used[j + p[i].F] = 1;
		}
	}

	for (int i = N; i >= 0; i--) {
		if (dp[i] <= w) {
			cout << i;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <assert.h>
#include <queue>
#include <string.h>
#include <string>
#include <set>
#include <memory.h>
#include <functional>
#include <bitset>
using namespace std;
#define ll long long

const int N = 505;

int ret[N*N];
int x[N],cc[N];
int empSt[N*N];
void solve() {
    int n;
    scanf("%d",&n);
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq;
    for(int i=1;i<=n;++i) {
        scanf("%d",&x[i]);
        ret[x[i]] = i;
        cc[i] = i-1;
        pq.push(make_pair(x[i]-cc[i],i));
        empSt[x[i]+1] = i;
    }
    int lim = n*n;
    queue<pair<int,int> >q;
    for(int i=1;i<=lim;++i) {
        if(empSt[i]) {
            int id = empSt[i];
            if(n-id>0) {
                q.push(make_pair(n-id,id));
            }
        }
        if(ret[i]!=0) {
            continue;
        }
        while(!pq.empty()) {
            int id = pq.top().second;
            if(cc[id]==0) {
                pq.pop();
                continue;
            } else {
                break;
            }
        }
        if(pq.size()>0) {
            int id = pq.top().second;
            if(x[id]<i) {
                printf("No\n");
                return;
            }
            ret[i] = id;
            pq.pop();
            --cc[id];
            if(cc[id]>0) {
                pq.push(make_pair(x[id]-cc[id],id));
            }
        }
        if(ret[i]==0) {
            if(q.size()==0) {
                printf("No\n");
                return;
            }
            pair<int,int> tmp = q.front();
            q.pop();
            ret[i] = tmp.second;
            --tmp.first;
            if(tmp.first!=0) {
                q.push(tmp);
            }
        }
    }
    printf("Yes\n");
    for(int i=1;i<=lim;++i) {
        printf("%d ",ret[i]);
    }
    cout<<endl;
}

int main() {
    //freopen("/Users/gotop/Documents/ps_practice/ps_practice/input.txt", "r", stdin);
    solve();
}



Measured memory_bytes: 2944
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int[] x = new int[a];
        for (int i = 0; i < a; i++) {
            x[i] = scanner.nextInt();
        }
        int[] y = new int[a];
        for (int i = 0; i < a; i++) {
            y[i] = scanner.nextInt();
        }
        double[] p = new double[4];
        for (int i = 0; i < a; i++) {
            double p0 = Math.abs(x[i] - y[i]);
            p[1] += Math.pow(p0, 2);
            p[2] += Math.pow(p0, 3);
            p[3] = Math.max(p[3], p0);
            p[0] += p0;
        }
        p[1] = Math.sqrt(p[1]);
        p[2] = Math.cbrt(p[2]);
        for (double aa : p)
            System.out.println(aa);
    }
}


Measured memory_bytes: 26432
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define REP(i,a,b) for( int i = (int) a; i <= (int) b; i++ )
#define PER(i,a,b) for( int i = (int) a; i >= (int) b; i-- )
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
#define debugMD(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%.2lf", mat[i][j]); } printf("\n"); }
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <double, double> ii;
typedef pair <double, ii> iii;

const int MAX = 2e3+3;
const int mod = 1e9+7;


int main(){
	
	int n, k; cin >> n >> k;
	int a[n]; rep(i, 0, n) cin >> a[i];
	
	sort(a, a+n);
	int ans = 0;
	rep(i, 0, k) ans+=a[i];
	cout << ans << '\n';
	
	
	
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
        int k,s;
        int ans=0;
        cin>>k>>s;
        for(int i=0;i<=k;i++){
                for(int j=0;j<=k;j++){
                        int c=s-i-j;
                        if(0<=c&&c<=k){
                                ans++;
                        }
                }
        }
        cout<<ans;
}

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

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


   
  
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" <<endl;
  }
  
  else {
    cout << "No" <<endl;
  }


 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
#define int long long
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define ss second
#define ff first
 
const int N=2e5+5;

bool check(int a,int b,int c)
{
	if(c>b && b>a)
		return true;
	return false;
}

bool func(int k,int a,int b,int c)
{
	if(k==0)
	{
		return check(a,b,c);
	}
	bool ans=check(a,b,c);
	ans|=func(k-1,2*a,b,c);
	ans|=func(k-1,a,b,2*c);
	ans|=func(k-1,a,2*b,c);
	return ans;
}

void solve()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(func(k,a,b,c))
		cout<<"Yes";
	else
		cout<<"No";
}
 
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	
	IOS;
 
	int t=1;
	while(t--)
		solve();
 
}

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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

int main()
{

    ll N;

    ll bingo[3][3];

    for (int i = 0; i < 3; i++)
    {

        cin >> bingo[i][0] >> bingo[i][1] >> bingo[i][2];
    }

    cin >> N;

    for (int i = 0; i < N; i++)
    {
        ll tmp;
        cin >> tmp;
        for (int a = 0; a < 3; a++)
        {
            for (int b = 0; b < 3; b++)
            {
                if (bingo[a][b] == tmp)
                {
                    bingo[a][b] = 0;
                }
            }
        }
    }

    bool f = false;
    for (int a = 0; a < 3; a++)
    {
        for (int b = 0; b < 3; b++)
        {
            if (bingo[a][b] != 0)
            {
                f = false;
                break;
            }
            f = true;
        }

        if (f)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    f = false;
    for (int a = 0; a < 3; a++)
    {
        for (int b = 0; b < 3; b++)
        {
            if (bingo[b][a] != 0)
            {
                f = false;
                break;
            }
            f = true;
        }

        if (f)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    f = true;
    for (int a = 0; a < 3; a++)
    {
        if (bingo[a][a] != 0)
        {
            f = false;
            break;
        }
    }

    if (f)
    {
        cout << "Yes" << endl;
        return 0;
    }

    f = true;
    for (int a = 0; a < 3; a++)
    {
        if (bingo[a][2 - a] != 0)
        {
            f = false;
            break;
        }
    }

    if (f)
    {
        cout << "Yes" << endl;
    }
    else
    {

        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
// ll dp[100005];
// ll func(ll arr[] , ll n ,  ll ans,ll i){


// 	if(i<n && dp[i]!=0)
// 		return dp[i];

// 	if(i>n-2)
// 	{
// 		return ans;
// 	}
// 	dp[i]=min(ans+abs(arr[i]-arr[i+1]) ,ans+abs(arr[i]-arr[i+2]));
// 	return min(func(arr,n, ans+abs(arr[i]-arr[i+1]),i+1) ,func(arr,n,ans+abs(arr[i]-arr[i+2]),i+2));	
 
// }
int main()
{
	
  	// cout<<"hello";
  	ll n , i ;
  	cin>>n;
  	ll arr[n];
  	for(i=0;i<n;i++)
  		cin>>arr[i];
  	// func(arr, n ,0,0);
  	ll dp[n]={0};
  	dp[1]=abs(arr[0]-arr[1]);
  	for(i=2;i<n;i++){
  		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]) , dp[i-2] +abs(arr[i]-arr[i-2]));
  	}
  	cout<<dp[n-1];
  	return 0;
  	
}

Measured memory_bytes: 5148
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
    int N;
    ll R = 0, G = 0, B = 0;
    string S;

    cin >> N >> S;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            R++;
        } else if (S[i] == 'G') {
            G++;
        } else if (S[i] == 'B') {
            B++;
        }
    }
    ll total = R * G * B;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int d = j - i;
            if (j + d < N) {
                if (S[i] != S[j]
                    && S[j] != S[j + d]
                    && S[j + d] != S[i]) {
                        total--;
                }
            }
        }
    }

    cout << total << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

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

        long pow = Math.round(Math.pow(100, d));
        if (n <= 99) System.out.println(n * pow);
        else System.out.println(101 * pow);
    }
}

Measured memory_bytes: 35752
a,b=map(int,input().split())
s=input()
x='0123456789'
ans='Yes'
for i in range(a):
  if s[i] not in x:
    ans='No'
if s[a]!='-':
  ans='No'
for i in range(b):
  if s[a+i+1] not in x:
    ans='No'
print(ans)

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

using namespace std;

int main() {
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
    return 0;
}



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

using namespace std;
using ll = long long;


int main()
{
    ll N; cin >> N;

    for(ll n = 1; n <= 3500; n++) {
        for(ll w = 1; w <= 3500; w++) {
            ll A = w * n, B = w + n;
            if((4 * A - B*N) == 0)continue;
            if(A * N % (4 * A - B*N) == 0) {
                if((A * N) / (4 * A - B * N) <= 0)continue; 
                cout << (A * N) / (4 * A - B * N) << " " << n << " " << w << endl;
                return 0;
            }
        }
    }
    return 1;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    sc.close();

    @SuppressWarnings("unchecked")
    List<Integer>[] tree = new List[N + 1];
    for (int i = 0; i < M; i++) {
      if (tree[A[i]] == null) tree[A[i]] = new ArrayList<>();
      if (tree[B[i]] == null) tree[B[i]] = new ArrayList<>();
      tree[A[i]].add(B[i]);
      tree[B[i]].add(A[i]);
    }

    int cnt = 0;
    int[] ans = new int[N + 1];

    Deque<Integer> q = new ArrayDeque<>();
    q.addLast(1);
    while (!q.isEmpty()) {
      int n = q.pollFirst();

      List<Integer> es = tree[n];
      for (int e : es) {
        if (ans[e] != 0) continue;
        if (e == ans[n]) continue;
        cnt++;
        ans[e] = n;
        q.addLast(e);
      }
    }

    if (cnt == N - 1)
      System.out.println("Yes");
    else
      System.out.println("No");

    for (int i = 2; i < N + 1; i++)
      System.out.println(ans[i]);
  }
}


Measured memory_bytes: 76696
num=[1,4,8,16,32,64,128,256,512,9,27,81,243,729,25,125,49,343,121,144,169,196,225,256,289,324,361,400,441,484,529,576,625,676,729,784,841,900,961,1000]
num.sort()
x=int(input())
ans=1
for i in range(len(num)):
    if num[i]<=x:
        ans=max(ans,num[i])
print(ans)

Measured memory_bytes: 3064
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int n,a,b,s[1 << 17];

bool check(int x)
{
	int cnt = 0;
	for(int i = 1;i <= n;i++)
	{
		int l = 0;
		int r = 1e9;
		while(l < r)
		{
			int mid = l + r >> 1LL;
			if(((s[i] - (mid * a)) / b) + ((s[i] - (mid * a)) % b == 0 ? 0 : 1) <= x - mid) r = mid;
			else l = mid + 1;
		}
		cnt += l;
	}
	return (cnt <= x);
}


int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n >> a >> b;
	for(int i = 1;i <= n;i++) {cin >> s[i];}
	int l = 1;
	int r = 1e18;
	while(l < r)
	{
		int mid = l + r >> 1LL;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	rc(l);
}



Measured memory_bytes: 1152
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列以外を出力する
    void write(){

    }
    template<typename First, typename... Rest>
    void write(First first, Rest... rest){
        cout << first << " ";
        write(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    string T;
    io.read(T);
    if(T[0] == '?') T[0] = 'D';
    for(size_t i = 1; i < T.size() - 1; i++){
        if(T[i] == '?'){
            if(T[i - 1] == 'P' || T[i + 1] == 'P') T[i] = 'D';
            else T[i] = 'P';
        }
    }
    if(T[T.size() - 1] == '?') T[T.size() - 1] = 'D';
    cout << T;
    return 0;
}

Measured memory_bytes: 3720
s = input()

x = list(s)
x.sort()

answer1 = []
answer2 = []

for num in x:
    if len(answer1) == len(answer2):
        answer1.append(num)
    else:
        answer2.append(num)

if answer1 == answer2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9044
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	long H,W,l;
	for(int q=0;q<=301;q++){
		cin>>H>>W;
		if(H==0&&W==0)break;
		for(int i=0;i<H;i++){
			for(int j = 0; j < W; j++){
				if(i%2==1&&j%2==0||i%2==0&&j%2==1){
					cout<<".";
				}else{
					cout<<"#";
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  int n,h,max=0,ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>h;
    if(h>=max){max=h,ans++;}
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 3636
/**Bismillahir Rahmanir Rahim.**/

/**
 *    author:  nasimnoob
**/

#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<cstring>
#include<cstdio>

using namespace std;

//----------------------------------------------------------//

typedef long long int                        ll;
typedef unsigned long long int              ull;
typedef long double                          ld;

//-----------------------------------------------------------//
#define      test                       int t; cin>>t;  while(t--)

#define      cube(x)                    (x*x*x)
#define      sqr(x)                     (x*x)

#define      INPUT                      freopen("input.txt", "r", stdin)
#define      OUTPUT                     freopen("output.txt", "w", stdout)

#define      srev                       reverse(s.begin(),s.end())
#define      sortstr                    sort(s.begin(), s.end());
#define      gtl(x)                     getline(cin, (x))
#define      dot(x)                     fixed << setprecision(x)

#define      Case                       cout << "Case " << ++tt << ": " ;

#define      PI                         acos(-1) // 3.1415926535897932
#define      MIN                        9999999

#define      Faster                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);




//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


//--------------------------------------Solution------------------------------//

int main()
{
    Faster;


    int tt = 0 ;

    string s;
    int n, x, t;

    cin >> n >> x >> t ;

    if (n % x == 0)
        cout << (n /x )* t << endl;
    else
        cout << ((n / x) + 1) * t << endl;
    return 0 ;
}







Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
 
int modFac(int x){
    if(x==1)return 1;
    else return x%MOD*modFac(x-1)%MOD;
}


signed main(){
    int N,M;cin>>N>>M;
    if(M<N)swap(N,M);
    if(M-N>1)cout<<0<<endl;
    else{
        int ans=modFac(M)%MOD*modFac(N)%MOD;
      	if(M==N)ans=ans*2%MOD;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int r,c,k;
int fie[1005][1005];
PP p[1000005];
int dp[1005][1005];
int maxi[1005][1005];

int main(void){
	scanf("%d%d%d",&r,&c,&k);
	for(int i=0;i<r;i++){
		string s;
		cin >> s;
		for(int j=0;j<c;j++){
			if(s[j]=='#'){
				fie[i][j]=1;
			}
			p[i*c+j]=PP(i+j,P(i,j));
		}
	}
	sort(p,p+r*c);
	queue<P> que;
	for(int i=0;i<r*c;i++){
		que.push(p[i].second);
	}
	memset(maxi,-1,sizeof(maxi));
	while(que.size()){
		P p=que.front();
		que.pop();
		int x=p.second,y=p.first;
		if(x>0){
			maxi[y][x]=max(maxi[y][x],maxi[y][x-1]);
		}
		if(y>0){
			maxi[y][x]=max(maxi[y][x],maxi[y-1][x]-1);
		}
		if(fie[y][x]==1)continue;
		if(x<=maxi[y][x]){
			dp[y][x]=1;
		}else{
			dp[y][x]=0;
			maxi[y][x]=x+k;
		}
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			//printf("%d ",dp[i][j]);
		}
		//printf("\n");
	}
	printf("%s\n",dp[r-1][c-1]==1?"Chieno":"Cacao");
	return 0;
}



Measured memory_bytes: 34536
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val routes = Array(m) {
        readLine()!!.split(" ").map(String::toInt).let { it[0] to it[1] }
    }

    class Permutation<T> private constructor(
        private val baseIndex: Int,
        private var index: Int,
        val target: Array<T>?
    ) {
        var subPermutation: Permutation<T>? = null

        constructor(objs: Array<T>) : this(0, 0, objs.clone())

        init {
            if (target == null || target.isEmpty()) {
                throw IllegalArgumentException("")
            }

            if (this.index < this.target.size - 1) {
                this.subPermutation = Permutation(this.baseIndex + 1, this.index + 1, this.target)
            }
        }

        operator fun next(): Boolean {
            if (this.subPermutation == null) {
                return false
            }
            val result = this.subPermutation!!.next()
            if (result) {
                return true
            }
            this.swap(this.baseIndex, this.index)
            ++this.index
            if (this.target!!.size <= this.index) {
                this.index = this.baseIndex
                return false
            }
            this.swap(this.index, this.baseIndex)
            return true
        }

        private fun swap(index1: Int, index2: Int) {
            val tmp = this.target!![index1]
            this.target[index1] = this.target[index2]
            this.target[index2] = tmp
        }
    }

    val p = Permutation((2..n).toList().toTypedArray())

    var count = 0
    loop@ do {

        val list = mutableListOf(1).apply { this.addAll(p.target!!) }
        for (i in 0 until list.size - 1) {
            if (!(routes.contains(list[i] to list[i + 1]) || routes.contains(list[i + 1] to list[i]))) {
                continue@loop
            }
        }
        count++
    } while (p.next())
    println(count)
}

Measured memory_bytes: 41100
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000000+7
using namespace std;
typedef long long ll;

int main(){
  int N, M, C;  cin >> N >> M >> C;
  vector<int> B(M);
  int ans = 0;
  rep(i, 0, M)  cin >> B[i];
  rep(i, 0, N){
    int sum = 0;
    rep(j, 0, M){
      int A; cin >> A;
      sum += (A*B[j]);
    }
    if(sum + C > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,x = map(int, input().split(" "))
l = list(map(int,input().split(" ")))

y = 0
p = 0
for i in range(n+1):
  if i == 0:
    c = 0
  else:
    c = p + l[i-1]
  
  if c <= x:
    y += 1
  p = c

print(y)

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

#define f(i,a,b) for (int i = a; i < b; i++) 

int main() {
int n; cin>>n;
int mx = 0;
int ans = 0;
f(i,0,n) {
int x; cin>>x;
mx = max(x,mx);
if (mx <= x) ans++;
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
from collections import deque

k = int(input())

d = deque(range(1, 10))

cnt = 0
lc = 0
while cnt<=max(0, k-9):
	x = d[lc]
	xdr10 = x%10
	if xdr10 != 0:
		d.append(10*x+xdr10-1)
		cnt += 1
	
	d.append(10*x+xdr10)
	cnt += 1
	
	if xdr10 != 9:
		d.append(10*x+xdr10+1)
		cnt += 1
	lc += 1

print(d[k-1])

Measured memory_bytes: 7388
from sys import stdin
import numpy as np
A1 = [int(x) for x in stdin.readline().rstrip().split()]
A2 = [int(x) for x in stdin.readline().rstrip().split()]
A3 = [int(x) for x in stdin.readline().rstrip().split()]
A = [A1,A2,A3]
N = int(stdin.readline().rstrip())
B = []
for i in range(N):
    b = int(stdin.readline().rstrip())
    B.append(b)
    
ans = [[False,False,False] for i in range(3)]

for x,j in enumerate(A):
    for y,k in enumerate(j):
        if k in B:
            ans[x][y] = True

f = False
if ans[0][0] and ans[1][1] and ans[2][2]:
    f = True

if ans[0][2] and ans[1][1] and ans[2][0]:
    f = True

ans = np.array(ans)
for m in range(3):
    if all(list(ans[m])):
        f = True
        
    if all (list(ans[:,m])):
        f = True
        
if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL << 60; 

int main()
{
  ll A, B, K; 
  cin >> A >> B >> K;
  if(K <= A) cout << A-K << " " << B << endl;
  else if(K <= A+B) cout << 0 << " " << B-(K-A) << endl;
  else cout << 0 << " " << 0 << endl;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    const vector<string> youbi = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s; cin >> s;

    int today = 0;
    for(int i = 0; i < youbi.size(); i++){
        if(youbi[i] == s){ today = i; break; }
    }

    cout << 7 - today << endl;
    return 0;
}

Measured memory_bytes: 256