akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll N,A,B,C,D;
int main(){
    cin>>N>>A>>B>>C>>D;
    for(ll i{};i<=N-1;++i)
        if(B>=A+i*C-(N-1-i)*D&&B<=A+i*D-(N-1-i)*C){
            cout<<"YES"<<endl;
            return 0;
        }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.IntMap as IM

type Map = IM.IntMap Int

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

solve :: Int -> Int -> Map -> [Int]
solve (-1) _ _ = []
solve n k m = min r1 r2 : solve (n - 1) k m
  where l = fromJust $ IM.lookup n m
        r = fromJust $ IM.lookup (n + k - 1) m
        r1 = abs l + abs (r - l)
        r2 = abs r + abs (r - l)

main :: IO ()
main = do
  [n, k] <- readIntsLine
  xs <- IM.fromList . zip [0..] <$> readIntsLine
  print . minimum $ solve (n - k) k xs

Measured memory_bytes: 18812
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i,a) for(ll i=0;i<a;++i)
int main(){
    string s; cin >> s;
    ll k; cin >> k;
 
    ll sz = s.size();
    vector<int>num(sz);
 
    rep(i,sz) num[i] = s[i] - '0';
    ll dp[1000][2][k+100]; 
    dp[0][0][0] = 1;
 
    rep(i,sz)rep(smaller,2)rep(j,4)
            for(int x = 0; x <= (smaller ? 9 : num[i]); ++x)// if smaller ==1 update 0~9, else update 0~num[i]
                dp[i + 1][smaller || x < num[i]][j + (x != 0)] += dp[i][smaller][j];// if x==0(位數j不變0), else +1
                // if smaller ==0 && (x>num[i]||x==0) update 0
    cout << dp[sz][0][k] + dp[sz][1][k] << endl;
 
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int n, i, j, k, card[4][13];
  char a;
  
  scanf("%d",&n);
  for( i=0; i < 4; i++){
    for( j=0; j < 13; j++){
      card[i][j] = 0;
    }
  }

  for( i = 0; i < n; i++ ){
    scanf("%s", &a);
    scanf("%d", &k);
    if( a == 'S'){
      card[0][k-1] = 1;
    }else if( a == 'H'){
      card[1][k-1] = 1;
    }else if( a == 'C'){
      card[2][k-1] = 1;
    }else{
      card[3][k-1] = 1;
    }
  }

  for( i = 0; i < 4; i++ ){
    for( j = 0; j < 13; j++ ){
      if( card[i][j] == 0 ){
	if( i == 0 ){
	  printf("S %d\n",j+1);
	}else if( i == 1){
	  printf("H %d\n",j+1);
	}else if( i == 2 ){
	  printf("C %d\n",j+1);
	}else{
	  printf("D %d\n",j+1);
	}
      }
    }
  }

  return 0;
}

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

int main() {
	queue < pair<string, int> > s;
	int n, q, t;
	cin >> n >> q;
	string name;
	for (int i = 0; i < n; i++) {
		cin >> name >> t;
		s.push(make_pair(name, t));
	}
	pair<string, int> u;
	int elaps = 0, a;
	while (!s.empty()) {
		u = s.front();
		s.pop();
		a = min(u.second, q);
		u.second -= a;
		elaps += a;
		if (u.second > 0) {
			s.push(u);
		}
		else {
			cout << u.first << " " << elaps << endl;
		}
	}
	return 0;
}

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


int main()
{
	int N;
	cin>>N;
	vector<int> a(N);
	rep(i,N)
	{
		cin>>a[i];
		a[i]--;
	}
	vector<bool> seen(N,false);
	int k=0;
	int ans=0;
	while(a[k]!=1&&!seen[k])
	{
		seen[k]=true;
		k=a[k];
		ans++;
	}
	if(a[k]!=1)
	{
		cout<<"-1"<<endl;
	}
	else
	{
		cout<<ans+1<<endl;
	}
	return 0;
}


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

int N;

void dfs(string w, char ma){
  if(w.size()==N){
    cout << w << endl;
  }else{
    for(char i='a';i<=ma+1;i++){
      dfs(w+i, max(ma,i));
    }
  }
}

int main(){
  cin >> N;
  dfs("a",'a');
  return 0;
}


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

using namespace std;

int n, m, q;
int A[50], B[50], C[50], D[50];
int max_point = 0;

void check(vector<int> &S) {
    int point = 0;
    for(int i=0; i<q; i++) {
        if(S[B[i]] - S[A[i]] == C[i]) point += D[i];
    }
    max_point = max(max_point, point);
}

void dfs(vector<int> &S, int i) {
    if(i>n){check(S); return;}
    for(int k=0; S[i-1]+k<=m; k++) {
        S[i] = S[i-1]+k;
        dfs(S, i+1);
    }
}

int main() {
    cin >> n >> m >> q;
    for(int i=0; i<q; i++) cin >> A[i] >> B[i] >> C[i] >> D[i];

    vector<int> S(n+1);
    S[0] = 1;

    dfs(S, 1);

    cout << max_point << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <cstdlib>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	ll t1, t2, a1, a2, b1, b2;
  cin>>t1>>t2>>a1>>a2>>b1>>b2;

  ll fa = t1*a1, fb = t1*b1, fd = llabs(fa-fb);
  cerr << fa SP fb SP fd << endl;
  ll sa = t2*a2, sb = t2*b2, sd = llabs(sa-sb);
  cerr << sa SP sb SP sd << endl;
  ll sum_a = fa+sa, sum_b = fb+sb, d = llabs(sum_a-sum_b);
  ll u = (fa-fb)/fd;
  ll v = 0;
  if(d!=0) v = (sum_a-sum_b)/d;

  if(u*v>0) return cout << 0 << endl,0;
  else if(d==0) return cout << "infinity" << endl,0;
  // if((fa-fb)*(sum_a-sum_b)<0){
  else{
    cerr << sum_a SP sum_b << endl;
    cerr << d SP fd << endl;
    ll tmp = fd/d;
    ll cnt = 0;
    if(tmp*d==fd) cnt++;
    ll ans = 1+tmp*2-cnt;
    cout << ans << endl;
  }

  return 0;
}


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

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

  int N; cin >> N;
  string S; cin >> S;
  int ans = 0;

  for (int i = 0; i < 1000; i++) {
    int p0 = i / 100;
    int p1 = i / 10 % 10;
    int p2 = i % 10;

    bool c0 = false, c1 = false;
    for (int j = 0; j < N; j++) {
      if (S[j] - '0' == p0 && !c0) {
        c0 = true;
      } else if ((S[j] - '0' == p1) && c0 && !c1) {
        c1 = true;
      } else if ((S[j] - '0' == p2) && c1) {
        ans++;
        break;
      }
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 384
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    long k;
    readf("%s %s", &n, &k);
    readln;

    auto a = readln.chomp.split.map!(to!int).array;
    auto f = readln.chomp.split.map!(to!int).array;
    
    a.sort();
    f.sort().reverse();
    
    bool isOk(long m, long k) {
        foreach (ae, fe; lockstep(a, f)) {
            if (ae.to!long * fe <= m) { continue; }
            
            int need = ae - (m / fe).to!int;
            k -= need;
        }
        
        return k >= 0;
    }
    
    long le = 0, r = 10L ^^ 12;
    while (le < r) {
        long m = (le + r) / 2;
        
        if (isOk(m, k)) { r = m; }
        else { le = m+1; }
    }
    
    le.writeln;
}

Measured memory_bytes: 19640
"use strict";
const main = input => {
  const alphabets = 'abcdefghijklmnopqrstuvwxyz'.split('');
  let txt = new Set(input.split('').sort());
  let ans = 'None';
  for(let i = 0; i < 26; i++) {
    if(!txt.has(alphabets[i])){
      ans = alphabets[i];
      break;
    }
  }
  console.log(ans);
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 15644
#include <iostream>
#include <vector>

using namespace std;

int dx[] = {0, 1};
int dy[] = {1, 0};

struct pkt
{
    int x, y;
};

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    pkt akt = {0, 0};
    a[0][0] = 'x';
    while (true)
    {
        bool dalej;
        for (int i = 0; i < 2; ++i)
        {
            dalej = false;
            pkt nowy = {akt.x + dx[i], akt.y + dy[i]};
            if (nowy.x >= 0 && nowy.x < n && nowy.y >= 0 && nowy.y < m)
            {
                if (a[nowy.x][nowy.y] == '#')
                {
                    a[nowy.x][nowy.y] = 'x';
                    akt = nowy;
                    dalej = true;
                    break;
                }
            }
        }
        if (!dalej)
            break;
    }
    bool db = true;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            if (a[i][j] == '#')
                db = false;
    if (db)
        cout << "Possible";
    else
        cout << "Impossible";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N;
  cin >> N;
  rep(i,N){
    ll a;
    cin >> a;
    if(a%2==1){
      cout << "first" << endl;
      return 0;
    }
  }
  cout << "second" << endl;
}

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

int n;
string s[2];
long long ans;
long long mod = 1e9+7;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	cin >> s[0] >> s[1];
	if(s[0][0] == s[1][0]) ans = 3;
	else ans = 6;
	for(int i=1; i<n; ++i){
		if(s[0][i] == s[1][i]){
			if(s[0][i-1] == s[1][i-1])
				ans *= 2;
		}else{
			if(s[0][i-1] == s[1][i-1]) ans *= 2;
			else if(i>1) ans *= 3;
			++i;
		}
		ans %= mod;
	}
	cout << ans << "\n";
}

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

using namespace std;

int main(void) {
    int64_t X, Y;
    cin >> X >> Y;
    if(abs(X-Y) <= 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll D,S,T;
int main(){
    cin>>D>>T>>S;
    if(S*T>=D){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

    return 0;
}

Measured memory_bytes: 3628
s = gets.chomp.split("")
len = s.length
q = gets.to_i
t = Array.new(q)
f = Array.new(q)
c = Array.new(q)

for i in 0..(q-1)
  ln = gets.chomp.split("")
  if ln.length == 1
    t[i] = ln[0].to_i
    f[i] = 0
    c[i] = "."
  elsif ln.length == 5
    t[i] = ln[0].to_i
    f[i] = ln[2].to_i
    c[i] = ln[4]
  end
end

rev = 0
t.each{|tn| rev = (rev+(tn%2)) % 2}
enrev = rev
head = Array.new(0)
hn = 0
ends = Array.new(0)
en = 0

ps = 0
for i in 0..(q-1)
  if t[i] == 1
    rev = (rev+1) % 2
  elsif t[i] == 2
    f[i] = (f[i]+1) % 2 if rev == 1
    if f[i] == 1
      head.push(c[i])
      hn += 1
    elsif f[i] % 2 == 0
      ends.push(c[i])
      en += 1
    end
  end
end

s = s.reverse if enrev == 1
if hn > 0
  head = head.reverse
  head.each{|hc| print hc}
end
s.each{|ch| print ch}
ends.each{|ec| print ec} if en > 0
puts ""

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

using namespace std;


int main(int argc,char *argv[]) {

	int A,B,C,D,E,F;
	cin >> A >> B >> C >> D >> E >> F;
	vector<int> W(F+10), S(F+10);
	A*=100;
	B*=100;
	W[0] = 1;
	S[0] = 1;
	for (int i = A; i < W.size(); ++i) {
		if(W[i-A])W[i] = 1;
	}
	for (int i = B; i < W.size(); ++i) {
		if(W[i-B])W[i] = 1;
	}
	for (int i = C; i < S.size(); ++i) {
		if(S[i-C])S[i] = 1;
	}
	for (int i = D; i < S.size(); ++i) {
		if(S[i-D])S[i] = 1;
	}
	int a = A, b = 0;
	for (int i = 0; i <= F; ++i) {
		if(!W[i])continue;
		int ls = (i / 100) * E;
		for (int j = 0; j <= ls && i+j <= F; ++j) {
			if(!S[j])continue;
			int na = i, nb = j;
			if(nb * (a+b) > b *(na + nb)){
				a = na;
				b = nb;
			}
		}
	}
	cout << a+b << " " << b << endl;
	
	
}
	


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

int main(){
  int a,b,n,f=0;
  string s;
  for(;cin>>n,n;){
    if(f)cout<<endl;
    vector<pair<int,string> >v;
    for(f=0;f<n;v.push_back(make_pair(a*3+b,s)),f++)
      cin>>s>>a>>b>>b;
    for(a=0;a<n;a++)
      for(b=0;b<n-1;b++)
        if(v[b].first<v[b+1].first)iter_swap(v.begin()+b,v.begin()+b+1);
    for(a=0;a<n;a++)
      cout<<v[a].second<<','<<v[a].first<<endl;
    f=1;
  }
}

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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) cerr<<#x<<" = " << (x) << endl
#define pnl(x) cout << x << '\n'
#define pns(x) cout << x << ' '
#define read(x) cin >> x
#define read2(x,y) cin >> x >> y
#define read3(x, y, z) cin >> x >> y >> z
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	vector<int>	vi;
typedef pair<int,int>	ii;
typedef vector<string>	vs;
typedef vector<ii>	vii;
typedef vector<Arrete>	vg;
typedef vector<long long>	vl;
typedef	long long ll;

const int MAXN = 1e5;
const ll MOD =1e9 + 7;
const int BLACK = 0;
const int WHITE = 1;

ll dp[2][MAXN];
vector<int> G[MAXN];

ll run(int node, int p, int color)
{
	if (dp[color][node] != -1)
		return dp[color][node];

	dp[color][node] = 1;
	for (auto v : G[node])
		if (v != p)
		{
			if (color == BLACK)
				dp[color][node] *= run(v, node, WHITE);
			else
				dp[color][node] *= (run(v, node, BLACK) + run(v, node, WHITE))%MOD;
			dp[color][node] %= MOD;
		}
	return dp[color][node];
}



int main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int N;
	read(N);
	FOR(i,0, N)
		dp[0][i] = dp[1][i] = -1;
	FOR(i,1,N)
	{
		int u, v;
		read2(u, v);
		u--, v--;
		G[u].pb(v);
		G[v].pb(u);
	}

	pnl( (run(0, -1, 0) + run(0, -1, 1))%MOD);
}



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

int main() {
  string S;
  cin >> S;
  int l = S.length();
  while(l--){
  	cout << "x";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if k < b-a:
  print(':(')
elif k < c-a:
  print(':(')
elif k < d-a:
  print(':(')
elif k < e-a:
  print(':(')
elif k < c-b:
  print(':(')
elif k < d-b:
  print(':(')
elif k < e-b:
  print(':(')
elif k < d-c:
  print(':(')
elif k < e-c:
  print(':(')
elif k < e-d:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>

using namespace std;
const int MAX_N = 100000;
long long N, M, A[MAX_N];
long long dp[MAX_N + 1];

void solve() {
    long long res = 0;
    map<long long, long long> mp;

    for (int i = 0; i < N; i++) {
        dp[i + 1] = (dp[i] + A[i]) % M;
        mp[dp[i + 1]] = mp[dp[i + 1]] + 1;
    }

    for (auto const &val: mp) {
        res += val.second * (val.second - 1) / 2;
        if (val.first == 0) {
            res += val.second;
        }
    }

    printf("%lld\n", res);
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] = A[i] % M;
    }
    solve();
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>

#define PI 3.14159265359

#define INF 1000000;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

typedef long long ll;

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/

int prime[1000000];
bool is_prime[1000001];

int sieve(int n)
{
	int p = 0;
	
	for (int i=0; i<=n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i=2; i<=n; i++)
	{
		if (is_prime[i])
		{
			prime[p++] = i;
			for (int j=2*i; j<=n; j+=i) is_prime[j] = false;
		}
	}
	
	return p;
}


int main()
{
	int n;
	
	while (cin >> n)
	{
		cout << sieve(n) << endl;
	}
	
	return 0;
}

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

int main()
{
	int a,b,c,N;
	cin >> N;
	for(int i = 0;i < N;i++){
		cin >> a >> b >> c;
		a *= a;
		b *= b;
		c *= c;
		if(a == b + c || b == a + c || c == a + b)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){

  int N, M, C; cin >> N >> M >> C;
  int A[21][21], B[21];

  for(int i = 0; i < M; i++)
    cin >> B[i];
   
  for(int i = 0; i < N; i++)
    for(int j = 0; j < M; j++)
      cin >> A[i][j];

  int ans = 0;
  for(int i = 0; i < N; i++)
  {
    int sum = 0;
    for(int j = 0; j < M; j++)
    {
      sum += A[i][j] * B[j];
    }
    sum += C;

    if(sum > 0)
      ans++;
  }
    
  pr(ans);

 return 0;

}


Measured memory_bytes: 256
while line = gets.split.map(&:to_i)
    total = line[0] + line[1]

    if line[0] == -1 and line[1] == -1 and line[2]==-1
        break
    end
    if line[0] == -1 or line[1] == -1
        puts "F"
        next
    end
    if total >= 80
        puts "A"
    elsif total >= 65
        puts "B"
    elsif total >=50
        puts "C"
    elsif total >=30
        if line[2] >=50
            puts "C"
        else
            puts "D"
        end
    else
        puts "F"
    end
end


Measured memory_bytes: 6864
import sys, math, itertools, bisect, copy, re, heapq
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint


INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N = int(input())
s = input()
t = input()

for i in range(N):
    # print("--- {} ---".format(i))
    # print(s[i:])
    # print(t[:N - i])
    ss = s[i:]
    tt = t[:N - i]
    if ss == tt:
        print(2 * N - (N - i))
        sys.exit()

print(2 * N)


Measured memory_bytes: 3824
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int n,x,t;
    cin>>n>>x>>t;
    cout<<(n/x)*t+(n%x==0?0:t)<<endl;
    
return 0;
}


Measured memory_bytes: 3628
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val g = Graph(N, 0L, 1e16.toLong()) { a, b -> a + b }

    for (i in 1..M) {
        val (L, R, C) = readLine()!!.split(" ").map{it.toLong()}
        g.edges[L.toInt() - 1].add(Edge(L - 1, R - 1, C))
    }

    for (i in 1 until N) {
        g.edges[i].add(Edge(i, i - 1, 0L))
    }

    val d = dijkstra(g, 0).first

    println(if (d[N - 1] == g.inf) -1 else d[N - 1])
}

data class Edge<T: Comparable<T>>(val from: Int, val to: Int, val weight: T): Comparable<Edge<T>> {
    constructor(from: Long, to: Long, weight: T) : this(from.toInt(), to.toInt(), weight)

    override fun compareTo(other: Edge<T>) = weight.compareTo(other.weight)
}

class Graph<T: Comparable<T>>(val n: Int, val zero: T, val inf: T, val plus: (T, T) -> T) {
    val edges = Array(n) { ArrayList<Edge<T>>() }
}
inline fun <reified T: Comparable<T>>dijkstra(g: Graph<T>, s: Int): Pair<Array<T>, Array<Int>> {
    val N = g.n
    val dist = Array(N) { g.inf }
    val prev = Array(N) {-1}

    val Q = PriorityQueue<Edge<T>>()

    dist[s] = g.zero
    Q.add(Edge(-2, s, g.zero))

    while(Q.isNotEmpty()) {
        val e = Q.peek()
        val v = e.to
        Q.poll()

        if (prev[v] != -1) continue
        prev[v] = e.from
        for (i in g.edges[v]) {
            val d = g.plus(dist[v], i.weight)
            if (dist[i.to] > d) {
                dist[i.to] = d
                Q.add(Edge(i.from, i.to, d))
            }
        }
    }

    return Pair(dist, prev)
}


Measured memory_bytes: 85292
import math


def main():
    a, b, x = list(map(int, input().split(' ')))
    side_area = x / a
    if side_area > a * b / 2:
        blank_side_area = a * b - side_area
        blank_side_edge = 2 * blank_side_area / a
        angle_rad = math.atan(blank_side_edge / a)
    else:
        bottom_edge = 2 * side_area / b
        angle_rad = math.atan(b / bottom_edge)
    angle_deg = 360 * angle_rad / (2 * math.pi)
    print(angle_deg)


if __name__ == '__main__':
    main()

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


using namespace std;

int main(){
   int n;
   cin>>n;
   int flag=1;
   
 for(int i=1;i<=9;i++){
     if(n%i==0&&(n/i)<=9){
         cout<<"Yes";
         flag=0;
         break;
     }
 }
 if(flag==1){
     cout<<"No";
 }


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

vector<bool> IsPrime;

void sieve(int max){
  if(max+1 > IsPrime.size()){
    IsPrime.resize(max+1,true);
  }
  IsPrime[0] = false;
  IsPrime[1] = false;

  for(int i=2; i*i<=max; ++i){
    if(IsPrime[i]){
      for(int j=2; i*j<=max; ++j){
        IsPrime[i*j] = false;
      }
    }
  }
}

int main()
{
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  sieve(200000);
  int N;cin>>N;
  while(true){
    if(IsPrime[N]){
      cout<<N<<endl;
      break;
    }
    N++;
  }
}


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

using namespace std;

int main(){

string str;
				
cin>>str;

int len=str.size();


if(str[3-1]==str[4-1]&&str[5-1]==str[6-1]){
				cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long n,m,i,j,k,a,b,ans=1,cnt=1;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	for(i=a;i<=b;i++){
		if(i%n==0){
			printf("OK\n");
			return 0;
		}
	}
	printf("NG\n");
	return 0;
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long N;
	scanf("%lld",&N);
	std::vector<long long> P(N);
	for(int i = 0 ; i < N ; i++){
		scanf("%lld",&P[i]);
	}
	std::vector<long long> Q(N);
	for(int i = 0 ; i < N ; i++){
		scanf("%lld",&Q[i]);
	}

	std::vector<ll> a(N);
	iota(a.begin(), a.end(), 1);
	ll i = 0;
	ll p_id = -1, q_id = -1;
	do
	{
		bool p_ok = true, q_ok = true;
		for (ll j = 0; j < N && p_ok; ++j)
		{
			if (P[j] == a[j])	continue;
			p_ok = false;
		}
		if (p_ok)	p_id = i;
		for (ll j = 0; j < N && q_ok; ++j)
		{
			if (Q[j] == a[j])	continue;
			q_ok = false;
		}
		if (q_ok)	q_id = i;
		++i;
	}
	while(next_permutation(a.begin(), a.end()));

	cout << abs(p_id - q_id) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int N = 5 * 100000 + 100;
const int MOD = 1000000007;
const int oo = 1e9;

int n , m, dsu[N], sp[N][12], jp[N][12], d[N],p[N];
bool used[N];
ll S, X;
vector<pii> g[N];
struct edge {
	int u , v , w;
	bool operator<(const edge &rhs )const {
		return w < rhs.w;
	}
};
edge E[N];
int find(int u) {
	return dsu[u] == u ? u : dsu[u] = find(dsu[u]);
}
void dfs(int u , int p) {
	jp[u][0] = p;
	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i].x;
		if (v == p)continue;
		sp[v][0] = g[u][i].y;
		d[v] = d[u] + 1;
		dfs(v, u);
	}
}
int lca(int u , int v) {
	if (d[v] > d[u])
		swap(v, u);
	for (int k = 11 ; k >= 0 ; --k) {
		if (d[u] - (1 << k) >= d[v]) {
			u = jp[u][k];
		}
	}
	if (u == v)return u;
	for (int k = 11 ; k >= 0 ; --k) {
		if (jp[u][k] != jp[v][k]) {
			u = jp[u][k];
			v = jp[v][k];
		}
	}
	return jp[u][0];
}
int maxLca(int u , int v){
	int ans = 0;
	for(int k = 11 ; k >= 0 ; --k){
		if(d[u]-(1<<k)>= d[v]){
			ans = max(ans,sp[u][k]);
			u = jp[u][k];
		}
	}
	return ans;
}
int maxH(int u , int v){
	return max(maxLca(u,lca(u,v)),maxLca(v,lca(u,v)));
}
ll fast(ll a , ll b){
	if(!b)return 1ll;
	ll res = fast(a,b/2);
	res = (res*res)%MOD;
	if(b&1)
		return (res*a)%MOD;
	return res;
}
int main() {
	scanf("%d%d", &n, &m);
	scanf("%lld", &X);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d%d", &E[i].u, &E[i].v, &E[i].w);
	}
	for (int i = 1; i <= n ; ++i)dsu[i] = i;
	sort(E, E + m);
	for (int i = 0; i < m; ++i) {
		if (find(E[i].u) != find(E[i].v)) {
			used[i]=1;
			S += E[i].w;
			g[E[i].u].pb(mp(E[i].v, E[i].w));
			g[E[i].v].pb(mp(E[i].u, E[i].w));
			dsu[find(E[i].u)] = find(E[i].v);
		}
	}
	ll D = X - S;
	if (D < 0) {
		puts("0");
		return 0;
	}
	dfs(1, -1);
	for (int k = 1; (1 << k) <= n ; ++k) {
		for (int u = 1 ; u <= n ; ++u) {
			if (jp[u][k - 1] == -1)continue;
			jp[u][k] = jp[jp[u][k-1]][k-1];
			sp[u][k] = max(sp[u][k - 1], sp[jp[u][k - 1]][k - 1]);
		}
	}
	int eq = 0 , upper = 0;
	for (int i = 0; i < m; ++i){
		if(used[i])continue;
		p[i] = E[i].w-maxH(E[i].u,E[i].v);
		if(p[i]==D){
			eq++;
		}
		if(p[i]> D)upper++;
	}
	ll res = ((fast(2,eq)-1)*2*fast(2,upper))%MOD;
	if(D == 0){
		ll fn = ((fast(2,n-1)-2+MOD)%MOD*fast(2,m-(n-1)))%MOD;
		fn = (fn+res)%MOD;
		printf("%lld\n",fn );
		return 0;
	}
	printf("%lld\n", res);

	return 0;
}

Measured memory_bytes: 22912
h, w = map(int, input().split())
a1 = []
s = input()
for j in range(w):
    if s[j] == "#":
        a1.append(j)
a =[]
for i in range(h - 1):
    s = input()
    for j in range(w):
        if s[j] == "#":
            a.append(j)
    if a[0] < a1[len(a1) - 1]:
        print("Impossible")
        raise SystemExit
    a1 = [i for i in a]
    a = []
print("Possible")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
/*
int n;

int main(){
  cin >> n;
  string ana[10010];//anagram
  for(int i=0;i<n;i++){
    cin >> ana[i];
  }
  sort(ana,ana+n);

  int sub;//subtotal
  int total;//total

  for(int i=0;i<n;i++){
    if(ana[i]==ana[i-1]){
      sub++;
      total+=sub;
    }
    else{
      sub=0;
    }
  }
  cout << total <<endl;
  return 0;
}
*/

int main(){
  int n;
  cin >> n;
  vector<string> vs;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    vs.push_back(s);
  }
  sort(vs.begin(),vs.end());
  long long cnt=0;
  int conti=0;
  for(int i=1;i<n;i++){
    if(vs[i]==vs[i-1]){
      ++conti;
      cnt+=conti;
    }else{
      conti=0;
    }
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 5748
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int N; ll W;
int main() {
	cin >> N >> W;
	vector<ll> v(N), w(N);
	for (int i = 0; i < N; i++) cin >> v[i] >> w[i];
	int lc = N / 2, rc = N - lc;
	vector<pair<ll, ll> > p;
	for (int i = 0; i < 1 << lc; i++) {
		ll sv = 0, sw = 0;
		for (int j = 0; j < lc; j++) {
			if (i & (1 << j)) sv += v[j], sw += w[j];
		}
		if (sw <= W) p.push_back(make_pair(sw, sv));
	}
	sort(p.begin(), p.end());
	vector<ll> pv(p.size()), pw(p.size());
	for (int i = 1; i < p.size(); i++) {
		pv[i] = max(pv[i - 1], p[i].second);
		pw[i] = p[i].first;
	}
	ll ret = 0;
	for (int i = 0; i < 1 << rc; i++) {
		ll sv = 0, sw = 0;
		for (int j = 0; j < rc; j++) {
			if (i & (1 << j)) sv += v[j + lc], sw += w[j + lc];
		}
		if (sw > W) continue;
		int ptr = lower_bound(pw.begin(), pw.end(), W - sw + 1) - pw.begin() - 1;
		ret = max(ret, pv[ptr] + sv);
	}
	cout << ret << endl;
	return 0;
}

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

int main () {
  int n, q;
  string s;

  cin >> n >> q;
  cin >> s;

  vector<int> S(n+1, 0);
  for(int i = 2; i <= n; i++) {
    S[i] = (s[i-2] == 'A' && s[i-1] == 'C') ? S[i-1] + 1 : S[i-1];
  }

  int l,r, ans;
  rep(i,q) {
    cin >> l >> r;
    l--; r--;
    ans = S[r+1] - S[l];
    if(l > 0 && s[l] == 'C' && s[l-1] == 'A') ans--;
    cout << ans << endl;
  }

  return 0;
}


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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int a,b,c;

signed main(){
    cin>>a>>b>>c;
    set<int> ans;
    ans.insert(a);
    ans.insert(b);
    ans.insert(c);
    int cnt=0;
    for(auto e:ans){
        cnt++;
    }
    cout<<cnt<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

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

int main(){
  long long Q,H,S,D;
  long long N;
  cin>>Q>>H>>S>>D>>N;
  
  double QQ,QH,QS,QD;
  QQ=4*Q;
  QH=2*H;
  QS=S;
  QD=0.5*D;
  
  //cout<<Q<<" "<<Q<<" "<<S<<" "<<D<<endl;
  //cout<<QQ<<" "<<QH<<" "<<QS<<" "<<QD<<endl;
  
  if((QS<=QQ)&&(QS<=QH)&&(QS<=QD)){
    cout<<(int)N*S<<endl;
    return 0;
  }
  if((QH<=QQ)&&(QH<=QS)&&(QH<=QD)){
    cout<<(int)N*2*H<<endl;
    return 0;
  } 
  if((QQ<=QH)&&(QQ<=QS)&&(QQ<=QD)){
    cout<<(int)N*4*Q<<endl;
    return 0;
  } 

  if((QD<=QH)&&(QD<=QS)&&(QD<=QQ)){
    if(N%2==0){
      cout<<N/2*D<<endl;
      return 0;
    }
    if((QS<=QQ)&&(QS<=QH)){
      cout<<(N/2)*D+S<<endl;
      return 0;
    }
    if((QH<=QQ)&&(QH<=QS)){
      cout<<(N/2)*D+2*H<<endl;
      return 0;
    }
    cout<< (N/2)*D+4*Q<<endl;
    return 0;
  } 
  return 0;
}

    
 

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

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    ans += (n-1) * n / 2;
    cout << ans<< endl;
 }

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

int main() {
  int h, w;
  std::cin >> h >> w;
  auto index = [=](auto i, auto j) {return i * w + j;};

  std::vector<bool> s(h * w);
  int black = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      std::cin >> c;
      if (c == '#') {
        s[index(i, j)] = false;
        black++;
      } else {
        s[index(i, j)] = true;
      }
    }
  }
  const auto max = h * w;
  std::vector<int> ans(h * w, max), tmp(h * w, max);
  tmp[index(0, 0)] = 1;

  while (true) {
    const auto pos = std::distance(tmp.begin(),
      std::min_element(tmp.begin(), tmp.end()));
    if (tmp[pos] == max) {
      break;
    }
    const auto i = pos / w;
    const auto j = pos % w;
    const auto val = tmp[pos] + 1;
    if (0 < i && ans[index(i - 1, j)] == max && s[index(i - 1, j)]) {
      tmp[index(i - 1, j)] = std::min(tmp[index(i - 1, j)], val);
    }
    if (i < h - 1 && ans[index(i + 1, j)] == max && s[index(i + 1, j)]) {
      tmp[index(i + 1, j)] = std::min(tmp[index(i + 1, j)], val);
    }
    if (0 < j && ans[index(i, j - 1)] == max && s[index(i, j - 1)]) {
      tmp[index(i, j - 1)] = std::min(tmp[index(i, j - 1)], val);
    }
    if (j < w - 1 && ans[index(i, j + 1)] == max && s[index(i, j + 1)]) {
      tmp[index(i, j + 1)] = std::min(tmp[index(i, j + 1)], val);
    }
    ans[pos] = tmp[pos];
    tmp[pos] = max;
  }

  if (ans[h * w - 1] == max) {
    std::cout << "-1" << std::endl;
  } else {
    std::cout << h * w - ans[h * w - 1] - black << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dp[205][205][2],c[205][205];
int n,V;
vector<int>edge[205];
bool in[205];
void dfs(int v){
	for(int i=0;i<edge[v].size();i++){
		dfs(edge[v][i]);
	}
	dp[v][0][0] = 1;
	int cur = 0,nxt = 1;
	for(int i=0;i<edge[v].size();i++){
		for(int b=0;b<=n;b++) dp[v][b][nxt] = 0;
		for(int a=0;a<=n;a++){
			if(!dp[v][a][cur]) continue;
			for(int b=0;b<=n;b++){
				if(!dp[edge[v][i]][b][0]) continue;
				for(int d=max(a,b);d<=a+b;d++){
					long long t = 1LL* dp[v][a][cur] * dp[edge[v][i]][b][0];
					t %= mod;
					t *= c[d][a];
					t %= mod;
					t *= c[a][b-(d-a)];
					t %= mod;
					dp[v][d][nxt] += t;
					if(dp[v][d][nxt]>=mod) dp[v][d][nxt]-=mod;
				}
			}
		}
		swap(cur,nxt);
	}
	{
		for(int i=203;i>=0;i--) dp[v][i+1][0] = dp[v][i][cur];
		dp[v][0][0] = 0;
	}
	//cout << dp[v][1][0] << " " << dp[v][2][0] << " " << dp[v][3][0] << endl;
}
int main(){
	cin >> n;
	for(int i=1;i<n;i++){
		int a,b;
		cin >> a >> b;
		edge[a].push_back(b);
		in[b] = 1;
	}
	for(int i=0;i<n;i++) if(!in[i]) V = i;
	c[0][0] = 1;
	for(int i=1;i<=200;i++) for(int j=0;j<=i;j++){
		c[i][j] = (c[i-1][j]+(j?c[i-1][j-1]:0))%mod;
	}
	dfs(V);
	int ans = 0;
	for(int i=1;i<=n;i++) ans = (ans+dp[V][i][0])%mod;
	cout << ans <<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    cin>>s;
    int l,r;
    rep(i,s.size()) if(s[i]=='A'){
        l=i;break;
    }
    for(int i=s.size()-1;i>=0;--i) if(s[i]=='Z'){
        r=i;break;
    }
    cout<<r-l+1<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <functional>
#include <queue>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10,18);
const int MOD = pow(10,9) + 7;
/* contest template */
int N;
char s[100];
bool flag;

int main()
{
    cin >> N;
    for (int i = 0; i < N;i++){
        cin >> s[i];
        if(s[i]=='Y'){
            flag = true;
        }
    }
    if(flag){
        cout << "Four" << endl;
    }
    else {
        cout << "Three" << endl;
    }
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

struct ModCombination {
	vector<ll> inv;
	vector<ll> fac;
	vector<ll> ifac;
	ll MOD;

	ModCombination(const size_t Size, const ll mod) {
		MOD = mod;
		inv.assign(Size, 0);
		fac.assign(Size, 0);
		ifac.assign(Size, 0);
		inv[0] = inv[1] = 1;
		fac[0] = fac[1] = 1;
		ifac[0] = ifac[1] = 1;
		for (int i = 2; i < Size; ++i) {
			inv[i] = ((-MOD / i) * inv[MOD % i]) % MOD;
			fac[i] = (fac[i - 1] * i) % MOD;
			ifac[i] = (ifac[i - 1] * inv[i]) % MOD;
		}
	}
	
	ll nCr(int n, int r) {
		return (((fac[n] * ifac[r]) % MOD) * ifac[n - r]) % MOD;
	}
};

int main() {
	const ll MOD = 1e9 + 7;
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	ModCombination Comb(N + 1, MOD);
	vector<vector<ll>> dp(B + 1, vector<ll>(N + 1, 0));
	dp[A - 1][0] = 1;
	for (int i = A; i <= B; ++i) {
		for (int j = 0; j <= N; ++j) {
			if (dp[i - 1][j] == 0) { continue; }
			dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;

			ll tmp = 1;
			for (int k = 1; (k <= D) && (j + i*k <= N); ++k) {
				int n = N - j - i*(k - 1);
				tmp = (((tmp * Comb.nCr(n, i)) % MOD) * Comb.inv[k]) % MOD;
				if (k >= C) {
					dp[i][j + i*k] = (dp[i][j + i*k] + dp[i - 1][j]*tmp + MOD) % MOD;
				}
			}
		}
	}

	ll res = (dp[B][N] + MOD) % MOD;
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 8192
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();

		int count = 0;
		int f = 0;
		for(int i=0; i<N; i++) {
			f = S.indexOf("ABC", f);
			if(f >= 0) {
				count++;
				f+=2;
			} else {
				break;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21716
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 32;

int main() {
  ll n;
  string s, t;
  string ans = "";
  cin >> n >> s >> t;

  for (ll i = 0; i < n; i++) {
    ans += s.substr(i, 1);
    ans += t.substr(i, 1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int a,b,n;
int arr[1000][1000];
int main(int argc, char** argv) {
	cin >> a >> b >> n;
	vector<int> v1,v2;
	int n1 = 2e5, n2 = 2e5;
	for(int i = 0; i< a; i++) {
		int x;
		cin >> x;
		n1 = min(n1, x);
		v1.push_back(x);
	}
	
	for(int i = 0; i< b; i++) {
		int x;
		cin >> x;
		n2 = min(n2, x);
		v2.push_back(x);
	}
	int m = n1 + n2;
	for(int i = 0; i< n; i++) {
		int x, y, z;
		cin >> x>> y>> z;
		m = min(m, v1[x-1] + v2[y-1] - z);
	}
	cout << m;
	return 0;
}

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

int main() {
  int N, A, B;
  string op;
  cin >> N >> A >> B;

  if ( N * A > B ) {
    cout << B << endl;
  }
  /*else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else if (op == "*") {
    cout << A * B << endl;
  }
  else if (op == "?" || op == "=" || op == "!" || op == "=" || B == 0 ) {
    cout << "error" << endl;
  }*/
  else {
    cout << N * A << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF= 1e18L+5;

int main() {
	int n,k;
	cin >> n >> k;
	bool dp[k+1] ={false};
	int a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<=k; i++){
		for(int j=0; j<n; j++){
			if(a[j]<=i && !dp[i-a[j]])
				dp[i]=true;
		}
	}
	if(dp[k])
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	string s; cin>>s;
	ll cost=0;

	rep1(i,s.sz-1){
		if(s[i]=='E') cost++;
	}
	ll ans=cost;
	rep1(i,s.sz-1){
		if(s[i-1]=='W') cost++;
		if(s[i]=='E') cost--;

		if(cost<ans) ans=cost;
	}
	cout<<ans;
}

Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int k;
    cin >> k;
    if(k%2 == 0){
        cout << (k/2)*(k/2) << endl;
    }
    else{
        cout << (k/2)*(k+1)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
struct Writer {
    s: String,
}
#[allow(unused_imports)]
use std::fmt::Display;
#[allow(dead_code)]
impl Writer {
    #[allow(dead_code)]
    pub fn new() -> Writer {
        Writer { s: String::new() }
    }
    #[allow(dead_code)]
    pub fn flush(&mut self) {
        print!("{}", self.s);
        self.s.clear();
    }
    pub fn write<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
    }
    pub fn writeln<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
        self.s.push('\n');
    }
    #[allow(dead_code)]
    pub fn write_vec<T: Display>(&mut self, xs: &Vec<T>) {
        if xs.len() == 0 {
            self.writeln("");
            return;
        }
        self.write(&format!("{}", xs[0]));
        for i in 1..xs.len() {
            self.write(&format!(" {}", xs[i]));
        }
        self.writeln("");
    }
}
#[allow(dead_code)]
fn main() {
    input!{
        a: i64,
        op: String,
        b: i64
    }
    if op == "+" {
        println!("{}", a + b);
    } else {
        println!("{}", a - b);
    }
}

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

int main(void){
  int a, b, k;
  cin >> a >> b >> k;
  int cnt = 0;
  for(int i=100;i>0;--i){
    if(a%i==0 && b%i==0) ++cnt;
    if(cnt==k) {cout << i << endl;
    break;
  }
  }
}


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

int main() {
  char c;
  cin >> c;
  bool ans = 0;
  if (c == 'a' || c == 'i') {
    ans = 1;
  }
  else if (c == 'u' || c == 'e') {
    ans = 1;
  }
  else if (c == 'o') {
    ans = 1;
  }
  if (ans) {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    int R, G, B, N;
    cin >> R >> G >> B >> N;
    
    int ans = 0;
    
   
    
    for (int r = 0; r <= int(N/R); r++) {
        int ss = N - r*R;
        for (int g = 0; g <= int(ss/G); g++) {
            int vv = ss - g*G;
            if(vv%B == 0){
                ans += 1;
            }
            
        }
    }
    
    
    
    
    cout << ans << endl;
    
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 256