akhauriyash/Code-Regression huggingface dataset:
MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))

rui = [A[0]] * N
for i in range(1, N):
	rui[i] = (rui[i - 1] + A[i]) % MOD
ans = 0
for i in range(1, N):
	ans = (ans + A[i] * rui[i - 1]) % MOD
print(ans)

Measured memory_bytes: 104944
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll unsigned long long
//#define mod 1000000007
#define NCONS 200001

using namespace std;


int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	string str; cin >> str;

	cout << str[0] << str.size() - 2 << str[str.size() - 1];

	return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let t = vec!["Sunny", "Cloudy", "Rainy"];
    let s = scan.chars();
    let sc = match s[0] {
        'S' => 0,
        'C' => 1,
        _ => 2
    };
    println!("{}", t[(sc + 1) % 3]);
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int main() {
    string s; cin >> s;
    int n = s.length();
    vector<int> ans(n);
    rep(i, n) ans[i] = 0;

    int n_even = 1, n_odd = 0;
    int idx_even, idx_odd;
    for (int i = 1; i < n; i++) {
        if (s[i-1] == 'L' && s[i] == 'R') {
            ans[idx_even] = n_even;
            ans[idx_odd] = n_odd;
            n_even = 0, n_odd = 0;
        }

        if (i % 2 == 0) n_even++;
        else n_odd++;
        if (s[i-1] == 'R' && s[i] == 'L') {
            if (i % 2 == 0) {
                idx_even = i;
                idx_odd = i - 1;
            } else {
                idx_even = i - 1;
                idx_odd = i;
            }
        }
    }
    ans[idx_even] = n_even;
    ans[idx_odd] = n_odd;

    for (auto x: ans) {
        cout << x << ' ';
    }
    cout << endl;
}


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

long POW(long a, long n, long m) {
    long ret = 1;
    for (; n > 0; n >>= 1, a = a * a % m) {
        if (n % 2 == 1) ret = ret * a % m;
    }
    return ret;
}

long C(long n, long r) {
    long X = 1, Y = 1;
    rep(i, r) {
        X = X * (n - i) % MOD;
        Y = Y * (i + 1) % MOD;
    }
    return X * POW(Y, MOD - 2, MOD) % MOD;
}

int main() {
    long n, a, b;
    cin >> n >> a >> b;
    long ans = POW(2, n, MOD) - 1 - C(n, a) - C(n, b);
    if (ans >= 0) cout << ans << endl;
    else cout << (ans + 2 * MOD) % MOD << endl;
}

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

const int N=1e6+10;

int n,pos[N],que[N];
char s[N],t[N];

void Init() {
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
}

void Solve() {
	if (s[1]!=t[1]) { printf("-1\n"); return ; }
	int ans=0,head=1,tail=0,lst=n+1; pos[n+1]=n+1;
	for (int i=n;i>=1;) {
		if (pos[i+1]>i && s[i]==t[i]) {
			pos[i]=i; lst=i; --i; head=1; tail=0;
		}else {
			int lpos=i;
			for (;lpos && t[lpos]==t[i];--lpos); lpos++;
			pos[lpos]=std::min(lpos,pos[i+1]);
			for (;pos[lpos] && s[pos[lpos]]!=t[lpos];--pos[lpos]);
			if (!pos[lpos]) { ans=-1; break;}
			else {
				if (pos[i+1]==i+1) {
					head=1; tail=0; que[++tail]=i-pos[lpos];
				}else {
					for (int j=head,k=lst-1;j<=tail+1;k-=que[j],++j) if (k<=i) {
						if (k==i) for (head=j;head<=tail && que[head]==0;++head);
						else head=j-1,que[head]=i-k;
						break;
					}
					que[++tail]=pos[i+1]-pos[lpos]-1;
				}
			}
			ans=std::max(ans,tail-head+1);
			lst=i; i=lpos-1;
		}
	}
	printf("%d\n",ans);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

 
int main() {
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  ll res = 0;
  if(a+b <= 2*c){
    res += a*x+b*y;
  }else if(x < y){
    res += 2*c*x + (y-x)*(min(b,2*c));
  }else{
    res += 2*y*c + (x-y)*(min(a,2*c));
  }
  cout << res << endl;
  return 0;
}





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
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.nextLine();
		String abc ="ABC";
		String arc ="ARC";
		
		if(S.equals(abc)) {
			System.out.println(arc);
		}else {
			System.out.println(abc);
		}
		
	}

}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define Int long long




int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    Int n;
    cin>>n;
    Int cv=(n*(n+1))/2;
  	cv*=n;
  	for(int i = 1;i<=n;i++)
    {
        Int j = (n*(n+1))/2;
      	j-=(i)*(n-i+1);
        cv-=j;
    }
    for(int i = 1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
      	if(x>y)swap(x,y);
        cv-=x*(n-y+1);
    }
  	//assert(cv>=0);
    cout<<cv<<endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef struct Date{
    int year;
    int month;
    int day;
}tagDate;
Date str2date(char str[]){
    Date date;
    date.year = (str[0]-'0')*1000 + (str[1]-'0')*100 + (str[2]-'0')*10 + (str[3]-'0');
    date.month = (str[5]-'0')*10 + (str[6]-'0');
    date.day = (str[8]-'0')*10 + (str[9]-'0');
    return date;
}
int main(){
    Date date;
    char str[9];
    scanf("%s", str);
    string result;
    date = str2date(str);
    if(date.year<2019){
        result = "Heisei";
    }else if(date.year>2019){
        result = "TBD";
    }else{
        if(date.month<=4){
            result = "Heisei";
        }else if(date.month>4){
            result = "TBD";
        }
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	ll ans = 0;
	ll cur = 0;
	string s; cin >> s;
	int n = s.length() - 1;
	for (int i = 0; i < (1ll << n); i++) {
		ll curr = s[0] - '0';
		for (int j = 0; j < n ; j++) {
			if (i & (1ll << j)) {
				cur += curr;
				curr = s[j + 1] - '0';
			}
			else curr = curr * 10 + s[j + 1] - '0';
		}
		cur += curr;
		ans += cur;
		//cout << cur << endl;
		cur = 0;
	}
	cout << ans << endl;

}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3644
using System;

namespace AOJ.Volume0
{
    public class Differential2
    {
        public static void Main()
        {
            int loop_cnt = int.Parse(Console.ReadLine());
            for (int i = 0; i < loop_cnt; i++)
            {
                string input = Console.ReadLine();
                var num = new string[8];
                for (int j = 0; j < 8; j++) { num[j] = input.Substring(j, 1); }

                Array.Sort(num);
                string max = "";
                string min = "";
                for (int j = 0; j < 8; j++)
                {
                    min += num[j];
                    max += num[7 - j];
                }

                int dia = int.Parse(max) - int.Parse(min);
                Console.WriteLine(dia);
            }
        }
    }
}

Measured memory_bytes: 9832
import java.util.*;

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

    System.out.println(getResult(a, b));
  }

  private static String getResult(int a, int b) {
    if (a == b) {
      return "a == b";
    } else if (a > b) {
      return "a > b";
    } else {
      return "a < b";
    }
  }
}

Measured memory_bytes: 26168
#include <stdio.h>

int main ()
{
   int n, i, s[200000], max, min;

   scanf ("%d", &n);
   for (i = 0; i < n; i++) {
      scanf ("%d", &s[i]);
   }

   min = s[0]; 
   max = s[1] - s[0];
   for (i = 1; i < n; i++) {
      max = (max >= s[i] - min) ? max : s[i] - min;
      min = (min <= s[i]) ? min : s[i];
   }

   printf ("%d\n", max);

   return 0;
}

Measured memory_bytes: 1380
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
    int a, b;
    char op;
    while (true)
    {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '?')
            break;
        if (op == '+')
            printf("%d\n", a + b);
        else if (op == '-')
            printf("%d\n", a - b);
        else if (op == '*')
            printf("%d\n", a * b);
        else
            printf("%d\n", a / b);
    }
    return 0;
}



Measured memory_bytes: 3204
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long N = scn.nextInt();
		scn.close();
		long sum = 0;
		for(long i = N;i>0;i--) {
			if(i%3 == 0) {
			}else if(i%5 == 0){
			}else {
			sum =sum+i;
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 27184
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
    int z;
    if(b==0){
        z=1;
        z%=c;
        return z;
    }
    if(b==1){
        z=a;
        z%=c;
        return z;
    }
    else{
        return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
    }
}

int main(){
  int n,m;
  cin>>n>>m;
  long double vec[n][2];
  vec[0][0]=10000,vec[0][1]=1;
  for(int i=1;i<n;i++){
    vec[i][0]=0;
    vec[i][1]=1;
  }
  int p,q;
  for(int i=0;i<m;i++){
    cin>>p>>q;
    if(vec[p-1][1]==1){
      vec[q-1][0]+=vec[p-1][0];
      vec[p-1][0]=0;
      vec[q-1][1]+=1;
      vec[p-1][1]-=1;
    }
    else{
      vec[q-1][0]+=vec[p-1][0];
      vec[q-1][1]+=1;
      vec[p-1][1]-=1; 
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(vec[i][0]>0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main() {
	int ans=0;
	string s,s1="CODEFESTIVAL2016";
	cin>>s;
	for(int i=0;i<16;i++){
		if(s[i]!=s1[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	ll n;cin>>n;
	vl a(n),b(n);
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	sort(been(a));
	sort(been(b));
	if(n%2){
		cout<<b[(n)/2]-a[(n)/2]+1<<endl;
	}
	else{
		cout<<(b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1])+1<<endl;
	}
	
}

Measured memory_bytes: 6428
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define MAXN 1000
#define MAXM 2000
#define MO 1000000007
using namespace std;
typedef long long LL;
struct node
{
	int to;
	int val;
	node(){};
	node(int _to,int _val):to(_to),val(_val){}
};
struct edge
{
	int u,v,len;
}line[MAXM+5];
vector<node> G[MAXN+5];
int N,M;
LL X;
LL diff[MAXM+5];
int fa[MAXN+5],fal[MAXN+5];
int depth[MAXN+5];
int Pow[MAXM+5];
bool used[MAXM+5];
int cnt=0;
LL sum=0;
bool operator < (edge a,edge b)
{
	return a.len<b.len;
}
void Init()
{
	Pow[0]=1;
	for(int i=1;i<=MAXM;i++)
		Pow[i]=2LL*Pow[i-1]%MO;
}
int FindSet(int i)
{
	if(fa[i]==0)
		return i;
	return fa[i]=FindSet(fa[i]);
}
bool UniteSet(int x,int y)
{
	int fx=FindSet(x);
	int fy=FindSet(y);
	if(fx==fy)
		return false;
	fa[fx]=fy;
	return true;
}
void Build(int u,int fa1)
{
	fa[u]=fa1;
	depth[u]=depth[fa1]+1;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i].to;
		if(v==fa1)
			fal[u]=G[u][i].val;
		else
			Build(v,u);
	}
}
int Find_MaxEdge(int x,int y)
{
	int ret=0;
	if(depth[x]<depth[y])
		swap(x,y);
	while(depth[x]!=depth[y])
	{
		ret=max(ret,fal[x]);
		x=fa[x];
	}
	while(x!=y)
	{
		ret=max(ret,max(fal[x],fal[y]));
		x=fa[x];
		y=fa[y];
	}
	return ret;
}
int main()
{
	Init();
	scanf("%d %d %lld",&N,&M,&X);
	int u,v,len;
	for(int i=1;i<=M;i++)
	{
		scanf("%d %d %d",&u,&v,&len);
		line[i].u=u;
		line[i].v=v;
		line[i].len=len;
	}
	sort(line+1,line+1+M);
	for(int i=1;i<=M;i++)
		if(UniteSet(line[i].u,line[i].v))
		{
			used[i]=true;
			G[line[i].u].push_back(node(line[i].v,line[i].len));
			G[line[i].v].push_back(node(line[i].u,line[i].len));
			sum+=1LL*line[i].len;
		}
	memset(fa,0,sizeof(fa));
	X=X-sum;
	if(X<0)
	{
		printf("0");
		return 0;
	}
	Build(1,0);
	for(int i=1;i<=M;i++)
		if(used[i]==false)
		{
			int maxd=Find_MaxEdge(line[i].u,line[i].v);
			diff[++cnt]=line[i].len-maxd;
		}
	LL res=0;
	sort(diff+1,diff+1+cnt);
	if(X==0)
		res=(1LL*Pow[M]-2LL*Pow[M-N+1]%MO+2LL*MO)%MO;
	for(int i=1;i<=cnt;i++)
		if(X==diff[i])
			res=(1LL*res+2LL*Pow[cnt-i]%MO)%MO;
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }

int N;
int P[20011];
int A[20011], B[20011];

int main() {

    scanf("%d", &N);
    REP (i, N) scanf("%d", P+i), P[i]--;


    REP (i, N) {
	A[i] += i * 20000 + 1;
	B[N-1-i] += i * 20000 + 1;
	A[P[i]] += i;
    }

    REP (i, N) printf("%d%c", A[i], i==N-1? '\n': ' ');
    REP (i, N) printf("%d%c", B[i], i==N-1? '\n': ' ');
    // REP (i, N) eprintf("%d%c", A[i] + B[i], i==N-1? '\n': ' ');

    return 0;
}



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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0006

int main() {
	string str;
	cin >> str;
	for (int i = str.size() - 1; i >= 0; i--)
		cout << str[i];
		
	cout << endl;
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A == 1) A = 14;
  if (B == 1) B = 14;
  if (A == B)
    cout << "Draw" << endl;
  else
    cout << (A > B ? "Alice" : "Bob") << endl;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N;

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

  cin >> N;
  vector< int > s(N);
  int mn = INF;
  int ans = 0;
  REP(i, N) {
    cin >> s[i];
    ans += s[i];
    mn = min(mn, (s[i] % 10 == 0 ? INF : s[i]));
  }

  if (ans % 10 == 0) ans -= mn;
  if (ans < 0) ans = 0;
  cout << ans << endl;
  

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
long N,P;
int main (){
  cin >>N>>P;
  long t=2;
  long ret=1;
  long x=1;
  if  (N==1){
    cout << P << endl;
    return 0;
  }
  int toolargeN=0;
  while (1){
    x=1;
    for (long i=0;i<N;i++){
      x*=t;
      if (x>P){
        toolargeN=1;break;
      }
    }
    if (toolargeN==1){
      cout << ret << endl;
      return 0;
    }
    long i=0;
    while (1){
      i++;
      if (P%t!=0) break;
      P/=t;
      if (i%N==0)ret*=t;
      if (t>P)break;
    }
    t++;

  }
  cout << ret << endl;
}


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

int sum(int n){
    int s = 0;
    while(n > 0){
        int d;
        d = n % 10;
        s += d;
        n /= 10;
    }
    return(s);
}

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    int total = 0;
    for(int i=1;i<=n;i++){
        int s;
        s = sum(i);
        if((a <= s) && (s <= b)){
            total += i;
        }
    }
    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <math.h>

#define nl '\n'

using namespace std;

string n;

int main(){

    cin >> n;

    if(n[0] == n[1] && n[0] == n[2]){
        cout << "Yes";
    } else if(n[1] == n[2] && n[1] == n[3]){
        cout << "Yes";
    } else{
        cout << "No";
    }


}

//g++ -std=c++14 comp.cpp -o b; ./b.exealso

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

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

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//------------------------


int32_t main()
{ 
  io;
 
  

  set<char> st={'A','C','G','T'};
  string s;
  cin>>s;

  int cnt=0,mx=0;

  for(int i=0;i<s.size();i++)
  {
    if(st.find(s[i])!=st.end())
      cnt++;
    else
    {
      mx=max(cnt,mx);
      cnt=0;
    }
  }
  mx=max(mx,cnt);
  cout<<mx;
 return 0;
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N, A, B; cin >> N >> A >> B;
    ll res = -1;
    if ((B-A) % 2 == 0) res = (B-A)/2;
    else {
        res = min(B-1,N-A); // 早くついたほうがひたすら待っている場合
        res -= (abs(B-A) - 1)/2;
    }
    cout << res << endl;
    return 0;
}


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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int f[128];
int m,n;
char memo[1<<11][1<<11];

int solve(int mask, int np){
  if(memo[mask][np] != -1) return memo[mask][np];
  int cnt = 0;
  REP(i,n) if((f[i] & mask) == np) cnt++;
  if(cnt <= 1) return 0;

  int tmp = ((1 << m) - 1) & (~mask);
  int ff = tmp;
  int ret = 1000;
  while(ff){
    int tt = ff & (-ff);

    int cc = 0;
    REP(i,n) if((f[i] & mask) == np)
      if(f[i] & tt) cc++;
    if(cc != 0 && cc != cnt){
      ret = min(ret, 1 +
                max(solve(mask | tt, np | tt),
                    solve(mask | tt, np)));
    }
    ff ^= tt;
  }
  return memo[mask][np] = ret;
}

int main(){
  while(scanf("%d%d ",&m,&n), m+n){
    REP(i,n){
      f[i] = 0;
      REP(j,m){
        char c;
        scanf("%c ",&c);
        f[i] |= (c - '0') << j;
      }
    }
    memset(memo,-1,sizeof(memo));
    print(solve(0,0));
  }

  return 0;
}

Measured memory_bytes: 4984
#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007LL
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
 
ll gcd(ll n1,ll n2){
    if(n2==0)
        return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
    if(exponent<0) exponent+=MOD-1;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%MOD;
        base=(base*base)%MOD;
        exponent/=2;
    }
    return ans;
}
int a[MAX],a1[MAX],a2[MAX],ans11,ans12,ans21,ans22;
set<int> s;
int main()
{
    csl;
 //   freopen("in.txt","r",stdin);
   // freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i%2==1)
        {
            a1[a[i]]++;
        }
        else
        {
            a2[a[i]]++;
        }
        s.insert(a[i]);
    }
    for(int i=1;i<=100000;i++)
    {
        if(a1[i]>=a1[ans11])
        {
            ans12=i;
            swap(ans11,ans12);
        }
        else if(a2[i]>a1[ans12])
            ans12=i;

        if(a2[i]>=a2[ans21])
        {
            ans22=i;
            swap(ans21,ans22);
        }
        else if(a2[i]>a2[ans22])
            ans22=i;
    }
    if(ans11==ans21)
        cout<<min(n-a1[ans11]-a2[ans22],n-a2[ans21]-a1[ans12])<<endl;
    else
    cout<<n-a1[ans11]-a2[ans21]<<endl;
}

Measured memory_bytes: 13568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353;

vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}
int main(){
    mod_build(12345678);
    int n;
    cin>>n;
    ll ans = powmod(3,n);
    vector<ll> sum(n/2+1);
    ll p = powmod(2,n/2);
    rep(i,n/2+1){
        sum[i]=comb(n/2,i)*p%mod;
        p*=inv[2];
        p%=mod;
    }
    rep(i,n/2){
        sum[n/2-i-1]+=sum[n/2-i];
        sum[n/2-i]%=mod;
    }
    ll res = 0;
    p = powmod(2,n/2);
    rep(i,n/2+1){
        if(i==0)continue;
        res+=comb(n/2,i)*p%mod*sum[n/2+1-i]%mod;
        p*=inv[2];
        p%=mod;
    }
    cout<<(ans-res%mod+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 328704
(stdin => {
  // Define Function
  const menseki = (tate, yoko) => tate * yoko
  const syui = (tate, yoko) => (tate + yoko) * 2
 
  // Declare Variable
  const inputs = stdin.toString().trim().split(' ')
  const tate = parseInt(inputs[0], 10)
  const yoko = parseInt(inputs[1], 10)
 
  console.log(menseki(tate, yoko), syui(tate, yoko))
})(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 15136
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    while (true) {
        int x, y, s;
        scan(x, y, s);

        if (!x && !y && !s) return;

        solve(x, y, s);
    }
}

void solve(int x, int y, int s) {
    int ans;

    foreach (p ; 1 .. s) {
        int q = s - p;
        int pp = calckmax(p, x);
        int qq = calckmax(q, x);

        if (!pp || !qq) continue;

        int pz = calczei(pp, y);
        int qz = calczei(qq, y);
        ans = max(ans, pz + qz);
    }

    writeln(ans);
}

int calczei(int p, int x) {
    return p*(100+x)/100;
}

int calckmax(int p, int x) {
    int btm = 0, top = 2*p;

    while (top - btm > 1) {
        int mid = (btm + top) / 2;
        if (mid*(100+x)/100 <= p) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    if (btm*(100+x)/100 == p) {
        return btm;
    }
    else {
        return 0;
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 2436
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,k,x;
    cin>>n>>k;

    if(n==0)
    {
        cout<<"0";
    }

    /*if(n%2==1&&k%2==1)
    {
        if(n%k==0)
        {
            cout<<"0";
        }
        else
        {
            cout<<"1";
        }
    }
    else if(n%2==0&&k%2==0)
    {
        if(n%k==0)
        {
            cout<<"0";
        }
        else
        {
            cout<<"2";
        }
        //cout<<"2";
    }*/
    else if(n==k)
    {
        cout<<"0";
    }

    else
    {
        if(n%k==0)
        {
            cout<<"0";
        }
        else
        {
            x=n;
            ll d,e;
            d=n%k;
            x=min(x,d);
            d=n/k;
            d++;
            e=abs(d*k-n);
            x=min(x,e);
            //e=abs(d*k-n);
            /*x=min(x,e);
            d++;
            e=abs(d*k-n);
            x=min(x,e);*/
            /*while(n>k)
            {
                ll d;
                d=abs(n-k);
                n=d;
                x=min(x,d);
            }*/
            cout<<x;
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = [int(str) for str in input().split()]
c = [0]*a

for n in range(a):
  if b[n]%2 == 0:
    if b[n]%3 != 0 and b[n]%5 != 0:
      c[n] = 1

if sum(c) == 0:
  print('APPROVED')
else:
  print('DENIED')


Measured memory_bytes: 2940
class UnionFind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]  #親のノード番号
        self.rank = [0]*(n+1)
    def find(self,x):  #xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self,x,y):  #x,yが同じグループか否か
        return self.find(x) == self.find(y)
    def union(self,x,y):  #x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[y] = x
            self.rank[x] += 1

N,K,L = map(int,input().split())
A = [list(map(int,input().split())) for i in range(K)]
B = [list(map(int,input().split())) for i in range(L)]

road = UnionFind(N)
train = UnionFind(N)

for i in range(K):
    road.union(A[i][0],A[i][1])
for i in range(L):
    train.union(B[i][0],B[i][1])

pair = [(road.find(i),train.find(i)) for i in range(1,N+1)]

from collections import Counter

#根が同じなら道路or鉄道でつなげる

c = Counter(pair)
print(*[c[i] for i in pair])

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    vector<int> arr(n);
    int i;
    for(i=0;i<n;++i){
        cin>>arr[i];
    }
    vector<int> dp(n);
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    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];
}

Measured memory_bytes: 3956
n, x, y = map(int, input().split())
x = x - 1
y = y - 1
kl = [0] * (n - 1)

for s in range(n - 1):
    for e in range(s+1, n):
        d = e-s
        if (e <= x)or(s >= y):
            kl[d - 1] += 1
        else:
            kl[min(d, abs(s-x)+abs(e-y)+1)-1] += 1

for i in kl:
    print(i)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define MOD 1e9+7
#define EPS 1e-8
#define INF 1e9+10
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  rep(i,1,10){
    if(N%i==0&&N/i<=9){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  
}



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

int main(){
  int n;
  while(std::cin >> n, n){
    int page[n];
    for (int i = 0; i < n; i++) {
      std::cin >> page[i];
    }
    std::cout << page[0];
    int prev = page[0];
    for (int i = 1; i < n; i++) {
      if(page[i - 1] + 1 == page[i])continue;
      if(prev != page[i - 1]){
        std::cout << "-" << page[i - 1] << " " << page[i];
      }else{
        std::cout << " " << page[i];
      }
      prev = page[i];
    }
    if(prev != page[n - 1]){
      std::cout << "-" << page[n - 1] << std::endl; 
    }else{
      std::cout << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1156
#include <string>
#include <iostream>
using namespace std;
long long n, w[19];
long long check(long long x) {
	long long ret = 0, d = to_string(x).size();
	if (d != 1) ret += 5;
	for (int i = 2; i < d; i++) ret += w[i - 2] * i * 48;
	ret += ((x - w[d - 1] + 1) - (x / 3 - (w[d - 1] - 1) / 3) - (x / 5 - (w[d - 1] - 1) / 5) + (x / 15 - (w[d - 1] - 1) / 15)) * d;
	return ret + (x / 3 + x / 5) * 4;
}
int main() {
	cin >> n;
	w[0] = 1; for (int i = 1; i < 19; i++) w[i] = w[i - 1] * 10;
	long long l = 1, r = w[17];
	while (r - l > 1) {
		long long m = (l + r) / 2;
		if (check(m) <= n) l = m;
		else r = m;
	}
	long long d = n - check(l - 1); string ret;
	for (long long i = l; i < l + 20; i++) {
		if (i % 15 == 0) ret += "FizzBuzz";
		else if (i % 3 == 0) ret += "Fizz";
		else if (i % 5 == 0) ret += "Buzz";
		else ret += to_string(i);
	}
	cout << ret.substr(d - 1, 20) << endl;
	return 0;
}

Measured memory_bytes: 3268
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define N 100000+5
using namespace std;
int n;
ll a[N],l=2,r=2;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=n;i>0;i--)
	{
        if(l % a[i]) l /= a[i],l = l*a[i]+a[i];
        r = (r/a[i]+1)*a[i]-1;
    }
    if(l > r) printf("-1");
    else printf("%lld %lld",l,r);
    printf("\n");
    return 0;
}

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

using namespace std;

typedef pair<int, int> pii;

int k;

void color(int v, vector<vector<pii>>& r, vector<int>& col, int fcol) {
    int cc = 1;
    if (r[v].size() > k) {
        k = r[v].size();
    }
    for (int i = 0; i < r[v].size(); ++i) {
        if (col[r[v][i].second] != -1) {
            continue;
        }
        if (cc == fcol) {
            ++cc;
        }
        col[r[v][i].second] = cc;
        color(r[v][i].first, r, col, cc);
        ++cc;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<vector<pii>> r(n);
    vector<pii> e(n - 1);
    k = 0;
    for (int i = 0; i < n - 1; ++i) {
        cin >> e[i].first >> e[i].second;
        --e[i].first;
        --e[i].second;
        r[e[i].first].push_back({e[i].second, i});
        r[e[i].second].push_back({e[i].first, i});
    }
    vector<int> col(n - 1, -1);
    color(0, r, col, -2);
    cout << k << '\n';
    for (int i = 0; i < n - 1; ++i) {
        cout << col[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 8832
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
		while (true) {
			final String[] data = sc.nextLine().split(" ");
			final int n = Integer.parseInt(data[0]);
			final int x = Integer.parseInt(data[1]);
			if (n == 0 && x == 0)
				break;
			int count = 0;
			for (int i = 1; i <= n - 2; i++) {
				for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if ((i + j + k) == x)
							count++;
					}
				}
			}
			System.out.println(count);

		}
	}

}

Measured memory_bytes: 26552
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,X;
    cin>>N>>X;
    vector<int> m(N);
    for(int i=0;i<N;i++){
        cin>>m.at(i);
        X -= m.at(i);
    }
    sort(m.begin(),m.end());
    int j=0;
    for(int i=0;i<10*10*10*10*10;i++){
        if(X<m.at(0)){
            cout<<N+j<<endl;
            break;
        }
        else{
            X-=m.at(0);
            j++;
        }
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=110;
const int inf=0x3f3f3f3f;
const LL mod=1e9+7;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,K;
char str[N];
int st[N],a[N],len,p[N];
LL fac[N],ifac[N],C[N][N],ans;
inline void Add(LL&x,LL y){x=x+y<mod?x+y:x+y-mod;}
inline LL qpow(LL a,LL b)
{
	LL ret=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ret=ret*a%mod;
	return ret;
}
inline bool check(int tot)
{
	int cnt=0,cntr=tot,cntb=tot;
	For(i,1,K)
	if(str[i]=='r')
	{
		if(cntr)cntr--;
		else cnt-=cnt>0;
	}
	else
	{
		if(cntb>cntr&&cntb&&st[cntb])cnt+=st[cntb--]-1;
		else cnt-=cnt>0;
	}
	return !cnt&&!cntr&&(!cntb||st[cntb]==0);
}
LL b[N],r[N],w[N],f[N],g[N];
inline LL CC(int a,int b){return !b?!a:C[a+b-1][b-1];}
inline LL Solve(int tot,int res)
{
	int bcnt=0,rcnt=0,wcnt=0;
	For(i,1,tot)bcnt+=st[i],rcnt+=st[i]+1;wcnt=tot+1;
	For(i,0,res)f[i]=g[i]=0;
	For(i,0,res)
		For(j,0,res-i)
			Add(f[i+j],CC(i,rcnt)*CC(j,bcnt)%mod);
	For(i,0,res)
		For(j,0,res-i)
			Add(g[i+j],f[i]*CC(j,wcnt)%mod);
	return g[res];
}
inline void dfs(int cnt,int res,int now,LL val)
{
	if(res-max(now*2-1,1)-1<0)
	{
		if(check(cnt))Add(ans,Solve(cnt,res)*fac[cnt]%mod*val%mod);
		return;
	}
	dfs(cnt,res,now+1,val);
	For(i,1,res)
	{
		st[cnt+i]=now;
		int l=res-max(now*2-1,1)*i-i;
		if(l>=0)dfs(cnt+i,l,now+1,val*ifac[i]%mod);
		else break;
	}
}
inline void init(int n)
{
	fac[0]=ifac[0]=1;
	For(i,1,n)fac[i]=fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	rFor(i,n,2)ifac[i-1]=ifac[i]*i%mod;
	C[0][0]=1;
	For(i,1,n)For(j,0,i)C[i][j]=(C[i-1][j]+(j?C[i-1][j-1]:0))%mod;
}
int main()
{
	file();
	read(n),read(K);
	init(100);
	scanf("%s",str+1);
	dfs(0,n+1,0,1);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin
from collections import deque

UNVISITED, VISITED_IN_QUEUE, POPPED_OUT = 0, 1, 2


def generate_adj_matrix(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
        init_in_deg_list[v_to] += 1
    return init_adj_table, init_in_deg_list


def topological_sort():
    for v in range(vertices):
        if not in_deg_list[v] and status[v] is UNVISITED:
            bfs(v)

    return ans


def bfs(v):
    v_queue.append(v)
    status[v] = VISITED_IN_QUEUE

    while v_queue:
        current = v_queue.popleft()

        ans.append(current)

        for v_adj in adj_table[current]:
            in_deg_list[v_adj] -= 1
            if not in_deg_list[v_adj] and status[v_adj] is UNVISITED:
                status[v_adj] = VISITED_IN_QUEUE
                v_queue.appendleft(v_adj)

        status[current] = POPPED_OUT

    return None


if __name__ == '__main__':
    _input = stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    status = [UNVISITED] * vertices
    v_queue = deque()
    init_adj_table = tuple([] for _ in range(vertices))
    init_in_deg_list = [0] * vertices

    ans = []
    adj_table, in_deg_list = generate_adj_matrix(v_info)
    print(*topological_sort())

Measured memory_bytes: 14684
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;

using namespace std;

int N[100001][3];


int main()
{
  int n, m;
  cin >> n >> m;
  vector<VI> E(n+1);
  REP(i,m) {
    int u, v;
    cin >> u >> v;
    E[u].push_back(v);
  }
  int s, t;
  cin >> s >> t;
  std::queue<pair<int,int>> queue;
  queue.push(make_pair(s, 0));
  while(!queue.empty())
  {
    auto pos = queue.front();
    queue.pop();
    N[pos.first][pos.second%3] = 1;

    if (pos.first == t && pos.second%3 == 0)
    {
      cout << pos.second / 3 << endl;
      return 0;
    }
    for (auto v : E[pos.first])
    {
      int nv = (pos.second+1)%3;
      if (N[v][nv] == 1) continue;
      queue.push(make_pair(v, pos.second+1));
      N[v][nv] = 1;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m, ans;
    ans = 0;
    cin >> n >> m;
    vector<int> h(n);
    for (int i = 0; i < n; i++){
        cin >> h[i];
    }
    int a, b;
    vector<int>g(n,1);
    for (int i = 0; i < m; i++){
        cin >> a >> b;
        if (h[a - 1] <= h[b - 1]) {
            g[a - 1] = 0;
        }
        if (h[a - 1] >= h[b - 1]) {
            g[b - 1] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        ans += g[i];
    }
    cout << ans << endl;

}


Measured memory_bytes: 3932
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final long a = scanner.nextLong();
        final long b = scanner.nextLong();

        final long fa = get(a - 1);
        final long fb = get(b);
        System.out.println(fa ^ fb);
    }

    private static long get(final long a) {
        switch ((int) (a % 4)) {
            case 0:
                return a;
            case 1:
                return 1;
            case 2:
                return a ^ 1;
            case 3:
                return 0;
        }
      
      return 0;
    }
}


Measured memory_bytes: 23124
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int A = I.nextInt();
		int B = I.nextInt();
		String S = I.next();
		boolean bad=false;
		for (int i = 0; i <= A+B; i++) {
			if (i!=A&&S.charAt(i)=='-') bad=true;
			else if (i==A&&S.charAt(i)!='-') bad=true;
		}
		O.pln(bad?"No":"Yes");
	}
	public static void sort(long[] a) {Arrays.sort(a);}
	public static void sort(int[] a) {Arrays.sort(a);}
	public static void sort(String[] a) {Arrays.sort(a);}
	public static void sort(char[] a) {Arrays.sort(a);}
	public static void sort(StringBuilder[] a) {Arrays.sort(a);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(boolean x) {w.println(x);w.flush();}
	}
}


Measured memory_bytes: 25620
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};

int main(){
    int k,l;cin>>k;
    if(k%2==0||k%5==0){
        cout<<-1<<endl;
        return 0;
    }else if(k%7==0){
        l = 9*k/7;
    }else l = 9*k;
    int x,r;
    int sz = to_string(l).length();
    x = pow(10,sz);
    r = (int)x % l;
    while(r!=1){
        r *= 10;
        r = r%l;
        sz++;
    }
    cout<<sz<<endl;
    return 0;
}

Measured memory_bytes: 4104
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    stack<char> st[3];
    string s[3];
    for(int i=0;i<3;i++){
        cin>>s[i];
        for(int j=s[i].length();j>=0;j--){
            st[i].push(s[i][j]);
        }
    }
    int k = 0;
    while(!st[k].empty()){
        char c = st[k].top();
        st[k].pop();
        if(st[k].empty()){
            break;
        }
        k = c-'a';
    }
    char m = k+'A';
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    int n;
    int i;
    int flag;
    
    flag=0;
    scanf("%d", &n);
    int array[n];
    
    for(i=0;n>i;i++){
        scanf("%d",&array[i]);
    }
    
    for(i=0;n>i;i++){
        if(0==array[i]%2 && flag!=2){
            if(!((0==array[i]%3)||(0==array[i]%5))){
                printf("DENIED");
                return 0;
            }
        }
    }
    printf("APPROVED");
    return 0;
}



Measured memory_bytes: 128
n = int(input())
t = list(map(int,input().split()))
m = int(input())
res = sum(t)
px = [list(map(int,input().split()))for _ in range(m)]
for i in range(m):
    p = px[i][0]-1
    x = px[i][1]
    ans = res -t[p]+x
    print(ans)
    

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> v(n+1);
  rep(i,n){
    int x;
    cin >> x;
    v[x]++;
  }
  sort(v.begin(),v.end(),greater<int>());
  int res = 0;
  rep(i,k)res+=v[i];
  cout << n-res << endl;
  return 0;
}

Measured memory_bytes: 1024
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;
ll chk[200001] = {0};
ll ans[200001] = {0};

int main(){
  int k,n;
  cin >> k >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  int b = 0;
  rep(i,n-1){
    b = max(b,a[i+1]-a[i]);
  }
  b = max(b,k-a[n-1]+a[0]);
  printf("%d\n", k-b);
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(a>=b)printf("delicious\n");
	else{
		if((b-a)<=x)printf("safe\n");
		else printf("dangerous\n");
	}
	return 0;
}

Measured memory_bytes: 128