akhauriyash/Code-Regression huggingface dataset:
H, W, K = map(int, input().split())
C = []
for _ in range(H): C.append([c for c in input()])
ans = 0
for i in range(1<<H):
   for j in range(1<<W):
       cnt = 0
       for m in range(H):
           for n in range(W):
               if i>>m&1: continue
               if j>>n&1: continue
               if C[m][n] == '#': cnt += 1
       if cnt == K: ans += 1
print(ans)

Measured memory_bytes: 73052
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll p[200009];
ll power(ll x,ll y)
{
    ll res=1;
  
    while(y>0)
    {
        if(y&1)
            res=res*x;
        res%=mod;
        y=y>>1;
        x=x*x;
        x%=mod;
    } 
    return res; 
}
ll inv(ll x)
{
	return power(x,mod-2);
}
ll ncr(ll n,ll r)
{
	ll res=p[n];
	res*=inv(p[r]);
	res%=mod;
	res*=inv(p[n-r]);
	res%=mod;
	return res;
}
ll ans[3009];
int main()
{
	FAST
	#ifdef ayk_16
	    time_taken_start
		freopen("input.txt","rt",stdin);
		freopen("output.txt","wt",stdout);
	#endif
	p[0]=1;
	for(ll i=1;i<=200000;i++)
	{
		p[i]=p[i-1]*i;
		p[i]%=mod;
	}
	ll h,w,n;
	cin>>h>>w>>n;
	vpl v;
	v.pb({1,1});
	v.pb({h,w});
	ll x,y;
	for(ll i=0;i<n;i++)
	{
		cin>>x>>y;
		v.pb({x,y});
	}
	sort(v.begin(),v.end());
	for(ll i=1;i<=n+1;i++)
	{
		ans[i]=ncr(v[i].ff+v[i].ss-2,v[i].ss-1);
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=i+1;j<=n+1;j++)
		{
			if(v[i].ss>v[j].ss)
				continue;
			ll d=v[j].ff-v[i].ff+v[j].ss-v[i].ss;
			ll r=v[j].ss-v[i].ss;
			x=ans[i]*ncr(d,r);
			x%=mod;
		    ans[j]-=x;
			ans[j]+=mod;
			ans[j]%=mod;
		}
	}
	cout<<ans[n+1];
}

Measured memory_bytes: 1920
#include <stdio.h>

int main(void){
    int n,x,count=0;
    int s,t,u;
    while(1){
        count = 0;
        scanf("%d %d/n",&n,&x);
        if(n==0 && x==0){
            break;
        }else{//s+t+u=x??¨??????????????¢???
            for(s=1;s<=n-2;s++){
                for(t=s+1;t<=n-1;t++){
                    for(u=t+1;u<=n;u++){
                        if(s+t+u == x){
                            count += 1;
                        }
                    }
                }
            }
            printf("%d\n",count);
        }
    }
   return 0; /*?????????*/
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("mmx,avx,fma")
//#pragma GCC optimize ("unroll-loops")

using namespace __gnu_pbds;
using namespace std;

#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);

template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, set<T>& v){ for(auto& e : v){ out << e << d; } return out; }

#define pb push_back
#define mk make_pair
#define X first
#define Y second
#define cont continue
#define ret return
#define For(i, a, b) for (int i = a; i < b;i++)
#define forn(i, a) for (int i = 0;i < a;i++)
#define ford(i, a, b) for (int i = b - 1;i >= a;i--)
#define fordn(i, a) for (int i = a - 1;i >= 0;i--)
#define forr(x, arr) for(auto &x: arr)
#define all(x) x.begin(),x.end()
#define REE(s_) {cout << (s_) << '\n';return 0;}
#define endl '\n'
#define makeunique(x) sort(all(x)), (x).resize(unique(all(a)) - (x).begin())
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef long double ldd;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_tree;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
////const int mod = 1e9 + 7;
//const int mod = 998244353;
ll powq(ll a, ll n) {
    ll res = 1;
    while (n){
        if (n & 1) {
            res *= a;
//            res %= mod;
            --n;
        }
        else {
            a *= a;
            n >>= 1;
//            a %= mod;
        }
    }
    return res;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    sort(all(a));
    int eaten = 0;
    forn(i, n){

        if (a[i] & 1){
            cout << "first";
            return 0;

        }
    }
    cout << "second";
    return 0;
}


Measured memory_bytes: 1024
import sys
n,m = map(int, input().split())
X = list(map(int, input().split()))

if n >= m:
    print(0)
    sys.exit(0)

X.sort()
Y = []
for i in range(len(X)-1):
    Y.append(X[i+1]-X[i])
Y.sort(reverse=True)

print(X[-1]-X[0]-sum(Y[:n-1]))


Measured memory_bytes: 57384
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int sum = 0,index;
		double avg,min;
		for(int i = 0;i < n;i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}
		avg = (double)sum / (double)n;
		min = Math.abs((double)a[0] - avg);
		index = 0;
		for(int i = 1;i < n;i++) {
			if(min > Math.abs((double)a[i] - avg)){
				min = Math.abs((double)a[i] - avg);
				index = i;
			}
		}
		System.out.println(index);

	}
}

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

int main(void){
	int a,b;cin >> a >> b;
	if(a==1)a = 14;
	if(b==1)b = 14;

	if(a>b)cout << "Alice" << endl;
	else if(b>a)cout << "Bob" << endl;
	else cout << "Draw" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <functional>
using namespace std;

typedef long long ll;
const ll InF = 1e15;
const int IntInf = 1e5;

int vectormin(vector<int> &v, int a, int b) {
  int res;
  res = IntInf;
  for (int i = a; i <= b; i++) res = min(res,v[i]);
  return res;
}

int merge(vector<int> &v, int a, int b, int N) {
  if (a < 0 || b > N - 1 || a > N - 1 || b < 0) return 0;
  if (a > b) return 0;
  int vmin,first,second,sum;
  first = a;
  second = b;
  sum = 0;
  vmin = vectormin(v,a,b);
  sum += vmin;
  for (int i = a; i <= b; i++) {
    v[i] -= vmin;
    if (v[i] == 0) {
      second = i - 1;
      sum += merge(v,first,second,N);
      first = i + 1;
    }
    if (i==b) sum += merge(v,first,b,N);
  }
  return sum;
}

int main() {
  int N;
  cin>>N;
  vector<int> h(N,0);
  for (int i = 0; i < N; i++) cin>>h[i];
  int ans = merge(h,0,N-1,N);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/agc018/tasks/agc018_a

//ユークリッドの互除法と最大公約数
//https://qiita.com/drken/items/0c88a37eec520f82b788

//ユークリッドの互除法はそもそも
//「mod mにおいてa=bの時
//　GCD(a,m)=GCD(b,m)が成立する」
//という原理から来ている

//参考：https://drken1215.hatenablog.com/entry/2020/03/22/205100

//この問題は操作そのものがユークリッドの互除法になっている
//A[0]~A[N-1]全部の最大公約数(gcd)をdとおく
//gcd(a,b)=gcd(a-b,b)であることから
//操作によって作れる数はdを必ず約数に含む

//A[0]~A[N-1]のうち最大のものをA[MAX]とすると
//A[MAX]-d,A[MAX]-2d,A[MAX]-3d.....0　が全部作れる
//これはすなわち0~A[MAX]のうち、dを約数に持つものは全て作れることを表す

//よってKがこれのどれかと一致していれば良い

//ちなみにA[MAX]-d,A[MAX]-2d,A[MAX]-3d.....0　が全部作れると書いたが、
//この時、A[MAX]ではなく例えば最大値でもなんでもない適当な要素A[i]を使うと
//A[i]-d,A[i]-2d,A[i]-3d.....0
//が作れる
//しかしdはAの要素全部の最大公約数であるためA[i]はdを約数にもつ
//これによってA[i]-d,A[i]-2d,A[i]-3d.....0は
//A[MAX]-d,A[MAX]-2d,A[MAX]-3d.....0にも含まれていることとなる
//よってA[MAX]の時だけ調べれば良くなる

//適当に要素A[i],A[j]を抽出すると
//どっちもdを約数にもつのでA[i]-A[j]も必ずdを約数にもつ
//さらにそこから適当な要素を引いてもやはりdを約数にもつ
//つまり絶対に、できる数値はdの約数を持たなければならない

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//計算量はどちらもO(logN)
LL gcd(LL a,LL b) { return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b) { return a/gcd(a,b)*b;}

LL N,K;
vector<LL> A;

string ans = "IMPOSSIBLE";

void solve(){
	sort(A.begin(),A.end());//昇順
	LL gcd_A = A[N-1];
	for(int i=0;i<=N-2;i++) gcd_A = gcd(gcd_A,A[i]);

	if(K%gcd_A==0 && K<=A[N-1]) ans = "POSSIBLE";
}

int main(){
    cin >> N >> K;
    A = vector<LL>(N);
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();

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

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    MOD = 10 ** 9 + 7
    
    sum_a = sum(A)
    ans = 0
    for ai in A:
        sum_a -= ai
        ans += ai * sum_a
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 105344
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 605000
#define inf (int)1e9
#define ll long long
#define eps 1e-9
#define mm 1000000007ll
#define low(x) x&(-x)
#define pb push_back
#define PII pair<int,int>
using namespace std;
ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int pre[200500],head[26],vis[200500],ans,ans2,c,cnt,tot,o,p;
char s[200500],t[200500];
struct data{int c,fa,ch[26];
}sam[200500];
void solve(){
	queue<int> q; q.push(1);
	while (!q.empty()){
		int u=q.front(); q.pop(); 
		rep(i,0,25) {
			if (!sam[u].ch[i]) {ans=u,ans2=i; return;}
			int v=sam[u].ch[i]; if (!pre[v]) pre[v]=u;
			if (!vis[v]) vis[v]=1,q.push(v);
		}
	}
}
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("1.txt","w",stdout);
	scanf("%s",s+1);
	int n=strlen(s+1);
	tot=1;
	rep(i,0,25) head[i]=1;
    rep(i,1,n){
        o=++tot; c=s[i]-'a';
        rep(j,0,25) for (p=head[j];p&&!sam[p].ch[c];p=sam[p].fa) sam[p].ch[c]=o;    
        sam[o].fa=head[c];  sam[o].c=c; head[c]=o;
    }
    solve();
    int now=ans;
    while (pre[now]) 
		t[++cnt]=sam[now].c,now=pre[now];
    down(i,cnt,1) printf("%c",t[i]+'a');
    printf("%c\n",ans2+'a');
	return 0;
}

Measured memory_bytes: 24192
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int a,b;
  cin>>a>>b;
  for(int price=0;price<=2000;price++){
    int eight=floor(float(price)*0.08);
    int ten=floor(float(price)*0.1);
    if(eight==a&&ten==b){
      cout<<price<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;

  return 0;
}




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

int main(){
    int n,l;
    cin >> n >> l;
    int s = 0;
    int m = 0;
    if(l>=0){
        s = l+1-1;
        m = l+n-1;
        if(n*(s+m)/2==0){
          cout << n*(s+m)/2 << endl;
          return 0;
        }else{
          cout << n*(s+m)/2 -(l+1-1) << endl;
          return 0;
        }
    }else{
        s = l+1-1;
        m = l+n-1;
        if(n*(s+m)/2 >= 0){
          cout << n*(s+m)/2 << endl;
          return 0;
        }else{
          cout << n*(s+m)/2 - (l+n-1) << endl;
          return 0;
        }
    }
}




Measured memory_bytes: 256
n,s=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353
a=499122177
b=pow(2,n-1,mod)
dp=[[0]*(s+1) for i in range(n+1)]
for i in range(n+1):
  dp[0][0]=pow(2,n,mod)
for i in range(1,n+1):
  dp[i]=dp[i-1][0:s+1]
  for j in range(s+1):
    if j+A[i-1]>s:
      break
    dp[i][j+A[i-1]]=(dp[i-1][j+A[i-1]]+dp[i-1][j]*a)%mod
print(dp[-1][-1])

Measured memory_bytes: 204344
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A,B;
	cin>>A>>B;
	int sum=0;
	if(A>B){
		sum+=A;
		sum+=(A-1);
	}
	else if(A==B){
		sum+=A;
		sum+=B;
	}
	else{
		sum+=B;
		sum+=(B-1);
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
program ccc

implicit none

integer :: n, i
integer,allocatable,dimension(:) :: a, b

read(*,*) n

allocate(a(n))
allocate(b(n-1))

read(*,*) b

a(1) = b(1)
a(n) = b(n-1)

do i = 2, n-1
a(i) = min(b(i-1),b(i))
end do

write(*,'(i0)') sum(a)

end program

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int N,a=0,b=0;
	string S;
	cin>>N>>S;
 
	for(int i=0;i<N;i++){
		if(S.at(i)=='#')
			a++;
		else if(S.at(i)=='.'&&a>0){
			b++;
			a--;
		}
	}
	cout<<b<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

long long fac[1000000], finv[1000000], inv[1000000];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int X,Y;
    cin >> X >> Y;
    int a,b;
    if((2*Y-X)%3 == 0){
        b = (2*Y-X)/3;
        a = X-Y+b;
        COMinit();
        cout <<COM(a+b,a)<< "\n";
    }else{
        cout <<0<< "\n";
    }
}

Measured memory_bytes: 23680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println((X - A) % B);
		sc.close();
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

class BinarySearch {
private:
    vector<int> data;
public:
    void add(int a) {
        data.emplace_back(a);
    }

    int find(int a) {
        int s = 0;
        int e = data.size() - 1;
        while (e - s > 1) {
            int m = (s + e) / 2;
            if (data[m] == a) {
                return m;
            } else {
                if (data[m] > a) {
                    s = m;
                } else {
                    e = m;
                }
            }
        }
        return -1;
    }
};

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll n = inl();
        vl a(n);
        rep(i, n) {
            cin >> a[i];
        }

        ll s = -1;
        ll e = 2 * 1e9 + 1;
        vl ans(n);
        while (e - s > 1) {
            vl d(all(a));
            ll m = (s + e) / 2; // 1の山の降った量
            if (m % 2 == 1) m++;

            ll now = m;
            rep(i, n) {
                ans[i] = now;
                d[i] -= now / 2;
                now = d[i] * 2;
            }
            ll tmp = (ans[n - 1] + ans[0]) / 2;
            if (tmp == a.back()) break;
            else {
                if (tmp < a.back()) s = m;
                else e = m;
            }
        }
        rep(i, n) cout << ans[i] << ' ';

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll t,a=0,w=0,tle=0,re=0;
  cin>>t;
  for(ll i=0;i<t;i++)
  {
      string s;
      cin>>s;
      if(s=="AC")
      a++;
      else if(s=="WA")
      w++;
      else if(s=="TLE")
      tle++;
      else
      re++;
  }
  cout<<"AC x "<<a<<"\n";
  cout<<"WA x "<<w<<"\n";
  cout<<"TLE x "<<tle<<"\n";
  cout<<"RE x "<<re<<"\n";
 return 0;
}


Measured memory_bytes: 3628
from collections import Counter
n = int(input())
s = []
for i in range(n):
    s.append(input())
s = Counter(s)
m = int(input())
t = []
for i in range(m):
    t.append(input())
t = Counter(t)

mx = 0
for k, v in s.items():
    if k in t:
        s[k] = max(s[k]-t[k], 0)
    mx= max(mx, s[k])
print(mx)

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

/* -- template -- */

int main(){
    int N; cin >> N;
    int maxv = 0;
    int ans = 0;
    int a[N]; rep(i, N)cin >> a[i],ans += a[i] - 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::{stdout, Write, BufWriter};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: String,
    }

    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    writeln!(out, "{}", n.match_indices("2").count()).unwrap();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll k;
  cin >> k;
  ll ans = 0;
  vector<vector<ll>> dp(300, vector<ll>(300));
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      if (dp[i][j] != 0) continue;
      dp[i][j] = __gcd(i, j);
      dp[j][i] = dp[i][j];
    }
  }

  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int x = 1; x <= k; x++) {
        ans += dp[i][dp[j][x]];
      }
    }
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3992
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,a[maxn],b[maxn],ans;
const ll mod=1000000007;

int main()
{
	b[0]=1; rep(i,1,maxn-5) b[i]=(b[i-1]*2)%mod;
	n=read(); rep(i,1,n) a[i]=read(); sort(a+1,a+n+1);
	rep(i,1,n)
	{
		ll tmp=b[n-1]+(n-i)*b[n-2]; tmp%=mod;
		ans=(ans+tmp*a[i])%mod;
	}
	cout<<(ans*b[n])%mod<<endl;
	return 0;
}

Measured memory_bytes: 13004
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

vector<ll> k(400001);//kの階乗
vector<ll> f(400001);//kの逆元

ll mod_pow(ll x, ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}

void comb_init(void) {
	ll cur = 1;
	k[0] = f[0] = 1;
	FOR(i, 1, 400001) {
		cur = (cur * i) % mod;
		k[i] = cur;
		f[i] = mod_pow(cur, mod - 2);
	}
}

ll combination(ll n, ll s) {
	ll ret = (((k[n] * f[n - s]) % mod) * f[s]) % mod;
	return ret;
}

ll permutation(ll n, ll s) {
	ll ret = (k[n] * f[n - s]) % mod;
	return ret;
}



int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	ll N, K,ans=0;
	cin >> N >> K;

	comb_init();

	FOR(i, 		0, N) {
		if (i > K)continue;
		ans = (ans+combination(N, i)*combination(i+(N-i-1), i)) % mod;
		
	}
	cout << ans << endl;







}


Measured memory_bytes: 9392
#include <cstdio>
#include <iostream>
#include <cstring>
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int m ,n;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a > b)
    {
        cout<<(a-1)<<endl;
    }else {
        cout<<a<<endl;
    }
    return 0;
}


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

int main() {
	int n, a = 0;
	cin >> n;

	int digit = 10;
	while (true) {
		if (n < digit/10)break;
		int digitnum = (n - (n / digit)*digit) / (digit / 10);
		a += digitnum;
		digit *= 10;
		//cout << "a:" << a << " digitnum:" << digitnum << "digit:" << digit << endl;
	}

	if (n%a == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int H, W;
vector<vector<char>> field;

bool solve(int i, int j) {
    if (
        (i - 1 >= 0 && field[i - 1][j] == '#') ||
        (i + 1 < W && field[i + 1][j] == '#') ||
        (j - 1 >= 0 && field[i][j - 1] == '#') ||
        (j + 1 < H && field[i][j + 1] == '#')) {
        return true;
    } else
        return false;
}

int search() {
    for (int i = 0; i < field.size(); i++) {
        for (int j = 0; j < field[i].size(); j++) {
            if (field[i][j] == '#') {
                if (!solve(i, j)) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    for (int w = 0; w < W; w++) {
        vector<char> res;
        for (int h = 0; h < H; h++) {
            char tmp;
            cin >> tmp;
            res.push_back(tmp);
        }
        field.push_back(res);
    }
    search();
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,i,m;
	int c[6]={500,100,50,10,5,1};
	while(1)
	{
		scanf("%d", &n);
		if(n==0)
		break;
		i=0;
		m=0;
		n=1000-n;
		while(n>0)
		{
			if(n>=c[i])
			{
				n-=c[i];
				m++;
			}
			else
			i++;
		}
		printf("%d\n", m);
	}
	
	return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a, b;
  cin >> a >> b;

  if(a % 2 == 0 || b % 2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


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

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

int main(void){
  char c;
  cin >> c;
  if(c == 'A') cout << 'T' << endl;
  if(c == 'C') cout << 'G' << endl;
  if(c == 'G') cout << 'C' << endl;
  if(c == 'T') cout << 'A' << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
	long S[12];
	int fig=0; //桁数
	long ans=0;
	int x;
	
	S[0]=getc(stdin)-'0';
	ans+=S[0];
	
	for(fig=1;fig<10;fig++){
		S[fig]=getchar()-'0';
		if(S[fig]>9||S[fig]<1) break;
		ans*=10;
		for(x=1;x<=fig;x++)ans+=S[x-1]*pow(2,fig-1);
		ans+=S[fig]*pow(2,fig);
	}
	
	printf("%ld\n",ans);
	
	return 0;
		
		
	
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,i=0,s=0;
  char c;
  cin >> n;
  for(i;i<n;i++){
    cin >> c;
    if(c =='Y')
      s++;
    else
      continue;
  }
  if(s)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

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

a = []

for i in range(n):
    a.append(int(input()))

tmp = a[:]
max1 = max(tmp)
tmp.remove(max1)
max2 = max(tmp)

if(max1 == max2):
    for i in range(n):
        print(max1)
else:
    for i in range(n):
        if(a[i] != max1):
            print(max1)
        else:
            print(max2)

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

int gcd(int a, int b) {
    while (true)
    {
        if (b == 0) return a;
        a %= b;
        if (a == 0) return b;
        b %= a;
    }
}

int main() {
    int w, h, c;
    cin >> w >> h >> c;
    int g = gcd(w, h);
    cout << c * (h / g) * (w / g) << endl;
}



Measured memory_bytes: 3116
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * Node;
Node nil;


Node listSearch(int key){
  Node x;
   
  x = nil->next;
   
  while(x != nil && x->key != key){
    x = x->next;
  }
  return x;
   
}
 
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}
 
void printList(){
  Node cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
 
void deleteNode(Node t){
  if ( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
 
}
 
void deleteFirst(){
  deleteNode(nil->next);
}
 
void deleteLast(){
  deleteNode(nil->prev);
}
 
void delete(int key){
  Node x;
 
  if((x = listSearch(key))!=NULL){
 
    deleteNode(x);
  }
  
}
 
 
void insert(int key){
  Node x;
  x = malloc(sizeof(struct node));
  x->key = key;
 
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
   
}
 
int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }
 
  printList();
  return 0;
}

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

int main(){
    string st1,st2;
    cin>>st1;
   
    
    int cnt=0;
    while(cin>>st2){
     
      rep(i,st2.size())  st2[i]=tolower(st2[i]);
      
      if(st2==st1) cnt++;
    }
    
    
    cout<<cnt<<endl;
      
}


Measured memory_bytes: 3136
def examA():
    C = [SI()for _ in range(3)]
    ans = C[0][0]+C[1][1]+C[2][2]
    print(ans)
    return

def examB():
    N, M = LI()
    P = [0]*N
    S = [LSI()for _ in range(M)]
    pena = 0
    ac = set()
    for p,s in S:
        p = int(p)-1
        if s=="WA":
            P[p] += 1
        else:
            if p in ac:
                continue
            ac.add(p)
            pena += P[p]

    print(len(ac),pena)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

using namespace std;

const int maxn = 1e5 + 5;
char s1[maxn], s2[maxn];
int gcd(int a,int b)
{
    while(b){
        a = a % b;
        swap(a,b);
    }
    return a;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    scanf("%s%s",s1,s2);
    int t = gcd(n,m);
    //printf("%d\n",t);
    n = n / t;
    m = m / t;
    bool flag=0;
    for(int i=0;i<t;i++)
    {
        if(s1[i*n] != s2[i*m]){
            flag=1;break;
        }
    }
    printf("%lld\n",flag?-1:(1LL*n*m*t));
    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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

// 参考: https://betrue12.hateblo.jp/entry/2018/12/08/225123

ll len[55], pat[55];

ll rec(ll k, ll x){
  if(x==len[k]) return pat[k];
  
  ll ans=0;
  
  x--;
  
  if(x>0){
    ll l=min(x, len[k-1]);
    ans+=rec(k-1, l);
    x-=l;
  }
  
  if(x>0) ans++;
  x--;
  
  if(x>0){
    ll l=min(x, len[k-1]);
    ans+=rec(k-1, l);
  }
  
  return ans;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,x; cin>>n>>x;
  
  len[0]=pat[0]=1;
  reps(i,n){
    len[i]=len[i-1]*2+3;
    pat[i]=pat[i-1]*2+1;
  }
  
  cout<<rec(n,x)<<endl;
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import defaultdict

N=raw_input()
K=input()

dp=defaultdict(lambda: 0)  #未満T or F , i桁目, 0でない数値がちょうどk個

l=len(N)

for i in range(l):
    x=int(N[i])
    i+=1
    if i==1:
        if x==1:
            dp[("T",i,0)]=1
            dp[("F",i,1)]=1
        else:
            dp[("T",i,0)]=1
            dp[("T",i,1)]=x-1
            dp[("F",i,1)]=1
    else:
        for k in range(K+1):
            dp[("T",i,k)]+=dp[("T",i-1,k)]
            dp[("T",i,k+1)]+=dp[("T",i-1,k)]*9
            if 0<x:
                dp[("T",i,k+1)]+=dp[("F",i-1,k)]*(x-1) #k桁目の数字pが0<p<xなのは、x-1通り
                dp[("T",i,k)]+=dp[("F",i-1,k)]  #k桁目の数字pが0の場合は1通り
                dp[("F",i,k+1)]+=dp[("F",i-1,k)]*1 #k桁目の数字p=xの場合はゼロでない数字が1個増える
            else: #k桁の目の数字xが0の場合
                dp[("F",i,k)]+=dp[("F",i-1,k)]*1
        
print dp[("T",l,K)]+dp[("F",l,K)]


Measured memory_bytes: 32236
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include<vector>
#include <list>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#include <tuple>
#include <string>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
#define FORk(N) for(int k=0;k<N;++k)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
void swap(ll &a,ll &b){
  ll tmp=a;
  a=b;
  b=tmp;
}
int main(){
  ll N,X;
  cin>>N>>X;
  vector<ll> L(N);
  FORi(N){
    cin>>L[i];
  }
  vector<ll> D(N+1);
  D[0]=0;
  FORi(N){
    D[i+1]=D[i]+L[i];
    if(D[i+1]>X){
      cout<<i+1<<endl;
      return 0;
    }
  }
  cout<<N+1<<endl;
  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <vector>
#include <iostream>

using namespace std;


vector<bool> erast(size_t max) {
  vector<bool> isPrime(1);
  if (max+1 > isPrime.size()) {
    isPrime.resize(max+1, true);
  }
  isPrime[0] = false;
  isPrime[1] = false;
  for (size_t i = 2; i*i<=max; ++i) {
    if (isPrime[i]) {
      for (size_t j=2; i*j <= max; ++j) {
        isPrime[i*j] = false;
      }
    }
  }
  return isPrime;
}

int main() {
  vector<bool> binaryMap = erast(100003);
  int x;
  scanf("%d", &x);
  for (int i = x; i<=100003; i++) {
    if (binaryMap[i]) {
      printf("%d", i);
      break;
    }
  }
  return 0;
}

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long a, b;
        cin >> a >> b;

        if (a >= 1 and a <= 9 and b >= 1 and b <= 9) {
            printf("%lld\n", a*b);
        } else {
            puts("-1");
        }
    }
}


Measured memory_bytes: 3764
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
}*NP;

NP nil;

NP listSearch(int key){
  NP cur = nil->next;
  while(cur != nil && cur->key != key){
  	cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NP cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NP t){
  if( t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NP t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  deleteNode(listSearch(key));
}


void insert(int key){
  NP x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


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

void dfs(Graph &G, int v, int p, vector<int> &color,
         int clr){
  color[v] = clr;
  for (auto next_v : G[v]){
    if (next_v.first == p) continue;
    if (color[next_v.first] != -1) continue;
    if (next_v.second % 2 == 0){
      dfs(G,next_v.first,v,color,clr);
    }else{
      dfs(G,next_v.first,v,color,1-clr);
    }
  }
  return;
}

int main() {
  int n; cin >>n;
  // 辺の数はn-1で固定
  Graph G(n);
  rep (i,n-1){
    int a,b,c;
    cin >>a >>b >>c;
    a--; b--;
    G[a].push_back(make_pair(b,c));
    G[b].push_back(make_pair(a,c));
  }
  vector<int> color(n,-1);
  dfs(G,0,-1,color,0);
  
  rep(i,n){
    cout <<color[i] <<endl;
  }
}


Measured memory_bytes: 9728
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll fmemo[100002];
ll imemo[100002];
ll ifmemo[100002];

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

ll fact(ll n){
    if(n == 0) return 1;
    if(fmemo[n]) return fmemo[n];
    return fmemo[n] = n * fact(n - 1) % MOD;
}

ll ifact(ll n){
    if(n == 0) return 1;
    if(ifmemo[n]) return ifmemo[n];
    return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
}

ll com(ll n, ll k){
    if(k > n) return 0;
    if(k == n || k == 0) return 1;
    return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
}

int main()
{
    ll n;
    cin >> n;
    for(ll i = 1; i <= 100001; i++){
        imemo[i] = modpow(i, MOD - 2);
    }
    ll a[100002];
    ll b[100002];
    fill(b, b + 100001, -1);
    ll dist;
    for(int i = 0; i <= n; i++){
        cin >> a[i];
        if(b[a[i]] == -1) b[a[i]] = i;
        else dist = i - b[a[i]];
    }
    for(ll k = 1; k <= n + 1; k++){
        cout << (com(n + 1, k) - com(n - dist, k - 1) + MOD) % MOD << endl;
    }
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  string s;
  cin >> s;
  rep(i,s.size()){
    cout << 'x';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string s1, s2;

  while(1){
    cin >> s1 >> s2;
    if(s1 == "0" && s2 == "0"){
      break;
    }
    int h=0, b=0;

    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
	if(s1[i] == s2[j]){
	  if(i == j){
	    h++;
	  } else {
	    b++;
	  }
	}
      }
    }

    cout << h << " " << b << endl;
  }

  return 0;
}

Measured memory_bytes: 912
#include <stdio.h>
int main(){
    int N, M, A[10000];
    scanf("%d%d", &N, &M);
    for (int i = 0; i < M; i++)
    {
        scanf("%d", &A[i]);
        N = N - A[i];
    }
    if(N < 0){
        printf("%d", -1);
    }
    else{
        printf("%d", N);
    }
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    int L;
    cin >> L;
    
    int v = 1,e = 0;
    ve<ve<int>> g;
    int l = 1;
    while (l*2-1 < L) {
        v++;
        e+=2;
        g.push_back({v-1,v,0});
        g.push_back({v-1,v,l});
        l*=2;
    }
    
    int A = L-l;
    int B = l;
    //out(A);out(B);
    while (A > 0) {
        int c = 1,d=1;;
        while (c*2 <= A) {
            c*=2;d++;
        }
        
        A -= c;
        e++;
        //cout << " A" << A << endl;
        
        
        g.push_back({d,v,B});
        B += c;
        //cout << " B" << B<< endl;
     }
    
    
    
    
    cout << v << " " << e << endl;
    rep(i,e){
        cout << g[i][0] << " " << g[i][1] << " " << g[i][2] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A[9][9];
    for(int i=1; i<=9; i++)
    {
        for(int j=1; j<=9; j++)
        {
            A[i-1][j-1]=i*j;
        }
    }
    bool B=false;
    int n;
    cin >> n;
    for(int i=0; i<9; i++)
    {
        for(int j=0; j<9; j++)
        {
            if(A[i][j]==n)
            {
                B=true;
            }
        }
    }
    if(B)
    {
        cout << "Yes" <<endl;
    }
    else
    {
        cout << "No" <<endl;
    }
    

}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll mod(ll a, ll b) { return (a%b+b)%b; }
ll gcd(ll x, ll y) { return __gcd(x, y); }
ll lcm(ll x, ll y) { return x * 1ll * y / gcd(x, y); }
 
 
const ll MAXN = 1e18;
const ll SIZE = 1e5 + 5;
const ll MOD  = 1e9 + 7;

ll n, id = 2, res;
vector<ll> primes;
unordered_map<ll, ll> cnt;

int main() { speedhack()

	cin >> n;

	while (n >= id * id) {
		if (n % id == 0) {
			primes.push_back(id);
			while (n % id == 0) {
				++cnt[id];
				n /= id;
			}
		}
		++id;
	}
	if (n != 1) {
		primes.push_back(n);
		++cnt[n];
	}

	for (ll prime : primes) {
		ll count = 1;
		while (cnt[prime] >= count) {
			++res;
			cnt[prime] -= count;
			++count;
		}
	}	cout << res;
	

	return 0;
}


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


int main() {
    ll A, B; cin >> A >> B;
    string ans; 
    if(A <= 0 && 0 <= B)ans = "Zero";
    else if(0 < A) ans = "Positive";
    else if(B < 0) {
        if((B-A+1)%2==1) ans = "Negative";
        else ans = "Positive";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,cnt=0;
  char str[6];
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    int temp=i;
    for(int j=0;j<5;j++){
      str[j]='0'+temp%10;
      temp/=10;
    }
    if(str[0]==str[4]&&str[1]==str[3])cnt++;
  }
  cout<<cnt<<endl;
  return(0);
}

Measured memory_bytes: 256
N, K = gets.chomp.split.map(&:to_i)

A = N.times.map { gets.to_i }

newA =A.sort!

i = 0

reselt =[]

@S = 0

while i + K - 1 < N do
     @S = newA[i + K - 1] - newA[i] 
     reselt << @S
     i += 1
 end

 puts reselt.min

Measured memory_bytes: 4640
import sys
input=sys.stdin.readline

class UnionFind:
    def __init__(self,n):
        self.par=[i for i in range(n)]
        self.rank=[0]*n
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1
    def same_check(self,x,y):
        return self.find(x)==self.find(y)

def main():
    n,m,q=map(int,input().split())
    E=[]
    uf=UnionFind(n)
    for _ in range(q):
        a,b,c=map(int,input().split())
        if c:
            E.append((a,b)) 
        else:
            uf.union(a,b)
    s=set()
    for i in range(n):
        s.add(uf.find(i))
    k=len(s)
    if E and (k<=2 or m==n-1):
        print('No')
        return
    for a,b in E:
        if uf.same_check(a,b):
            print('No')
            return
    print('Yes' if m<=n+k*(k-3)//2 else 'No')

if __name__=='__main__':
    main()

Measured memory_bytes: 70364