akhauriyash/Code-Regression huggingface dataset:
n = int(input())  # nは入力回数
m = [input() for _ in range(n)]

print('AC x ' + str(m.count('AC')))
print('WA x ' + str(m.count('WA')))
print('TLE x ' + str(m.count('TLE')))
print('RE x ' + str(m.count('RE')))


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

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

#define REPR(i,n) for(int i =n; i >=0; --i)

#define _REP(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

using namespace std;

int main(){
    int n,k;

    int cnt = 0;

    cin >> n >> k;
    REP(i,n){
        int a;
        cin >> a;
        if(a >= k)cnt++;
    }

    cout << cnt << endl;
    

    return 0;
}

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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n;
    cin>>n;
    int a[n];
    for(int i = 0;i < n;i++) cin>>a[i];
    int x = 0;
    for(int i = 0;i < n;i++) {
        if(a[i] != i+1) x++;
    }
    if(x <= 2) cout<<"YES\n";
    else cout<<"NO\n";
    
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;
    map<int, int> cnt;
    rep(i, n) {
        int a;
        cin >> a;
        ++cnt[a];
    }

    int ans = 0;
    each(x, cnt) ans += x.first * x.second;

    int q;
    cin >> q;
    rep(i, q) {
        int b, c;
        cin >> b >> c;
        ans += (c - b) * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << ans << '\n';
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

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

long long int n, k;
long long int* h=new long long int[100005];
long long int* arr=new long long int[100005];


long long int mod(long long int n)
{
	if(n<0)
	return -1*n;
	return n;
}

long long int solve(long long int i)
{
	long long int min=0, s=0, j;
	if(i==n-1)
	return 0;
	else if(i==n-2)
	{
		arr[i]=mod(h[i+1]-h[i]);
		return arr[i];
	}
	else
	{
		for(j=1;j<=k&&i+j<n;j++)
		{
			if(j==1)
			{
				min=mod(h[i+j]-h[i])+solve(i+j);
			}
			else if(arr[i+j]!=-1)
			{
				s=mod(h[i+j]-h[i])+arr[i+j];
				if(s<min)
				min=s;
			}
			else
			{
				s=mod(h[i+j]-h[i])+solve(i+j);
				if(s<min)
				min=s;	
			}
			
		}
		arr[i]=min;
		return arr[i];
	}
}

int main() {
	// your code goes here
	cin>>n>>k;
	for(long long int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	
	for(long long int i=0;i<n+3;i++)
	{
		arr[i]=-1;
	}
	
	cout<<solve(0)<<endl;
	
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}

Measured memory_bytes: 3636
// by Isaunoya
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct io {
	char buf[1 << 25 | 3], *s;
	int f;
	io() { f = 0, buf[fread(s = buf, 1, 1 << 25, stdin)] = '\n'; }
	io& operator >> (int&x) {
		for(x = f = 0; !isdigit(*s); ++s) f |= *s  == '-';
		while(isdigit(*s)) x = x * 10 + (*s++ ^ 48);
		return x = f ? -x : x, *this;
	}
};

signed main() {
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
#endif
	io in;
	int a, b;
	in >> a >> b;
	if(a > b) cout << "safe" << '\n';
	else cout << "unsafe" << '\n';
	return 0;
}


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



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

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    if ((a*b)==(c))
        cout << a*b << endl;
    if ((a*b)<(c))
        cout << a*b << endl;
    if (((a*b)>(c)))
        cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string str;
void solve()
{
    vector < int > tag;
    int i,xtag=-1,len=str.length();
    for (i=0;i<26;i++)
        tag.push_back(0);
    for (i=0;i<len;i++)
        if (str[i]>='a'&&str[i]<='z') tag[str[i]-'a']++;
    for (i=0;i<26;i++)
        if (!tag[i]) {xtag=i;break;}
    if (xtag==-1) cout<<"None";
    else cout<<(char)('a'+xtag);
    cout<<endl;
}
int main()
{
    while(cin>>str)
        solve();
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder02
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Console.ReadLine().ToCharArray().Sum(x => int.Parse(x.ToString())));
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<vector<int> > a(n, vector<int>(n-1));
    rep(i, n) {
        rep(j, n-1){
            cin >> a[i][j];
            a[i][j]--;
        }
        reverse(a[i].begin(), a[i].end());
    }
    vector<P> q;
    auto check = [&](int i) {
        if(a[i].size() == 0) return;
        int j = a[i].back();
        if(a[j].size() == 0) return;
        if(a[j].back() == i) {
            P p(i, j);
            if(p.second < p.first) swap(p.first, p.second);
            q.push_back(p);
        }
    };
    rep(i, n){
        check(i);
    }
    int day = 0;
    while(q.size() > 0){
        day++;
        sort(q.begin(), q.end());
        q.erase(unique(q.begin(), q.end()), q.end());
        vector<P> prevQ;
        swap(prevQ, q); // qをクリア
        for (P p : prevQ){
            int i = p.first, j = p.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for (P p : prevQ){
            int i = p.first, j = p.second;
            check(i);
            check(j);
        }
    }
    rep(i, n){
        if(a[i].size() != 0){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << day << endl;
}



Measured memory_bytes: 7556
#include <vector>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
int n, m, r, q = 5;
int main() {
	while (scanf("%d%*d%d%d", &n, &m, &r), n) {
		vector<int> sum(r + q + 1, 0);
		vector<int> w; w.push_back(n);
		if (m == 1) for (int i = 1; i < n; i++) w.push_back(n * i);
		for (int i : w) {
			vector<int> p(r + q + 2, 0);
			int z = 1;
			for (int j = 0; j <= r + q + 1; j++) {
				p[j] = z / i;
				z = z % i * 10;
			}
			if (p[r + q + 1] >= 5) {
				for (int j = r + q; j >= 0; j--) {
					p[j] += 1;
					if (p[j] >= 10) p[j] -= 10;
					else break;
				}
			}
			for (int j = r + q; j >= 0; j--) {
				sum[j] += p[j];
				if (sum[j] >= 10) sum[j] -= 10, sum[j - 1]++;
			}
		}
		cout << sum[0] << '.';
		for (int i = 1; i <= r; i++) cout << sum[i];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    LL(n,m);
    int ans=1;
    if(n==1){
        out(m);
        return 0;
    }
    for(ll i=2;n*i<=m;i++){
        if(n*i<=m&&(m%(n*i)==0||(m%(n*i))%i==0)){
            ans=i;
        }
    }
    out(ans);
}

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

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

int main()
{
	long n[3];
	long even = 0;
	long d;
	long sum = 1;
	rep (i , 3)
	{
		cin >> n[i];
		if (n[i] % 2 == 0)
		{
			cout << 0 << endl; return 0;
		}
		sum *= n[i];
	}
	qsort(n, sizeof (n) / sizeof (*n) , sizeof (*n), asc);
	long r = n[0] * n[1];
	cout << r << endl;
	return (0);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long n,a,x[111];
long long dp[55][2555],ddp[55][2555],ans;
int main()
{
	cin>>n>>a;
	for (int i=1;i<=n;i++) cin>>x[i];
	ddp[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=i;j++)
		{
			for (int k=0;k<=2500;k++)
			dp[j][k]=ddp[j][k];
		}
		for (int j=1;j<=i;j++)
		{
			for (int k=x[i];k<=2500;k++)
			{
				dp[j][k]+=ddp[j-1][k-x[i]];
			}
		}
		for (int j=1;j<=i;j++)
		{
			for (int k=0;k<=2500;k++)
			ddp[j][k]=dp[j][k];
		}
	}
	for (int j=1;j<=n;j++)
	{
		ans+=dp[j][j*a];
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 2304
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#define F first
#define S second
using namespace std;
int N,M,K,Q;


struct edge{
  int to,cost;
  edge(int to,int cost):to(to),cost(cost){}
};


//dijkstra
int fes[111111];
pair< int,pair<int,int> > allv[222222];
vector<edge> v[111111];
int d[111111];

void dijkstra(){
  fill(d,d+N+1,1<<28);
  priority_queue< pair<int,int> ,vector< pair<int,int> > ,greater< pair<int,int> > > que;
  for(int i = 0; i < K; i++){
    que.push( make_pair(0,fes[i]) );
    d[fes[i]] = 0;
  }
  while(!que.empty()){
    int c = que.top().F;
    int e = que.top().S;
    que.pop();
    if(d[e] < c) continue;
    for(int i = 0; i < (int)v[e].size(); i++){
      if(d[v[e][i].to] > d[e] + v[e][i].cost){
	d[v[e][i].to] = d[e] + v[e][i].cost;
	que.push( make_pair(d[v[e][i].to],v[e][i].to) );
      }
    }
  }
}



//unionfind
int par[111111];

void init(){ for(int i = 1; i <= N; i++) par[i] = i; }
int find(int x){ return par[x] = par[x]==x?x:find(par[x]); }
bool same(int x,int y){ return find(x) == find(y); }
void merge(int x,int y){ par[find(x)] = find(y); }



//LCA
vector<int> G[111111];
int parent[20][111111];
int depth[111111];
int mini[20][111111];

void dfs(int v,int p,int dep){
  parent[0][v] = p;
  mini[0][v] = min(d[v],p>0?d[p]:1<<28);
  depth[v] = dep;
  for(int i = 0; i < (int)G[v].size(); i++){
    if(G[v][i] != p){
      dfs(G[v][i],v,dep+1);
    }
  }
}

void lca_init(){
  dfs(1,-1,0);
  for(int k = 0; k + 1 < 20; k++){
    for(int i = 1; i <= N; i++){
      if(parent[k][i] < 0) parent[k+1][i] = -1;
      else{
	parent[k+1][i] = parent[k][parent[k][i]];
	mini[k+1][i] = min(mini[k][i],mini[k][parent[k][i]]);
      }
    }
  }
}

int lca(int a,int b){
  int res = 1 << 28;
  if(depth[a] > depth[b]) swap(a,b);
  for(int k = 0; k < 20; k++){
    if( (depth[b] - depth[a]) >> k & 1){
      res = min(res,mini[k][b]);
      b = parent[k][b];
    }
  }
  if(a == b) return min(res,d[a]);
  for(int k = 19; k >= 0; k--){
    if(parent[k][a] != parent[k][b]){
      res = min(res,min(mini[k][a],mini[k][b]));
      a = parent[k][a];
      b = parent[k][b];
    }
  }
  return min(res,min(mini[0][a],mini[0][b]));
}




int main(void){
  cin >> N >> M >> K >> Q;


  for(int i = 0; i < M; i++){
    int a,b,c;
    cin >> a >> b >> c;
    allv[i] = make_pair( 0,make_pair(a,b) );
    v[a].push_back(edge(b,c));
    v[b].push_back(edge(a,c));
  }
  for(int i = 0; i < K; i++){
    cin >> fes[i];
  }
  dijkstra();


  for(int i = 0; i < M; i++){
    int a = allv[i].S.F;
    int b = allv[i].S.S;
    allv[i].F = min(d[a],d[b]);
  }
  sort(allv,allv+M,greater< pair<int,pair<int,int> > >() );
  init();


  for(int i = 0; i < M; i++){
    int a = allv[i].S.F;
    int b = allv[i].S.S;
    if(same(a,b)) continue;
    merge(a,b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  lca_init();


  for(int i = 0; i < Q; i++){
    int a,b;
    cin >> a >> b;
    cout << lca(a,b) << endl;
  }
}

Measured memory_bytes: 37300
N,M = map(int, input().split())

G = [[] for _ in range(N+1)]

for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)

D = [None]*(N+1)
D[1] = 0

Q = set([1])

while len(Q) > 0:
    Q2 = set()
    for q in Q:
        for r in G[q]:
            if D[r] == None:
                D[r] = q
                Q2.add(r)

    Q = Q2


print('Yes')
for d in D[2:]:
    print(d)
    



Measured memory_bytes: 37436
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	vector <char> s(4);
	for (int i =0;i<4;i++) {
		cin >> s[i];
	}
	int count =1;
	int ma = 0;
	for (int i =1;i<4;i++) {
		if (s[i] == s[i-1]) count ++;
		else count =1;
		ma = max(ma,count);
	}
	if (ma >=3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
ans = 100000000000

def sumpow(a, x):
    res = 0
    for i in range(len(a)):
        res += (x - a[i]) ** 2
    return res


for x in range(-105, 105):
    ans = min(ans, sumpow(a, x))
print(ans)

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

int main() {
    char c;
    cin >> c;

    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 3572
//Littleboy123 Template 1.7
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

//pragmas

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")


typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef unsigned long long int ull;
typedef long double ld;
typedef unsigned long long ull;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define TC(n) cout << "Case #" << (n) << ": "
#define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n';
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void infile(){
    freopen("output.out", "r", stdin);
}

void outfile(){
    freopen("output.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1)
        tmp = (tmp * a) % mod;
    return tmp;
}

//End of template

int main(){
    init();

    ll k;
    cin >> k;
    if(k % 2 == 0 || k % 10 == 5){
        cout << -1 << endl;
        return 0;
    }
    ll modulo = 0;
    ll cnt = 0;
    while(true){
        cnt++;
        modulo = modulo*10;
        modulo += 7;
        modulo %= k;
        if(modulo == 0){
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3656
text = input()

q = int(input())

for _ in range(q):

    list_command = list(input().split())
    
    a = int(list_command[1])
    b = int(list_command[2])

    if   list_command[0] == "print":
        print(text[a:b + 1])
    elif list_command[0] == "reverse":
        text = text[:a] + text[a:b+1][::-1] + text[b + 1:]
    elif list_command[0] == "replace":
        text = text[:a] + list_command[3] + text[b + 1:]
    else:
        raise



Measured memory_bytes: 5608
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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 COMB(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;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
string s;
signed main() {
	cin >> s;
	cout << s[0] << s[1] << s[2] << endl;
	ggr
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void)
{
	int r, c, tmp;
	int i, j;
	int column[100] = {0};
	int row = 0;

	scanf("%d %d", &r, &c);
	for(i=0; i<r; i++){
		for(j=0; j<c; j++){
			scanf("%d", &tmp);
			printf("%d ", tmp);
			row += tmp;
			column[j] += tmp;
		}
		printf("%d\n", row);
		row = 0;
	}
	for(i=0; i<c; i++){
		printf("%d ", column[i]);
		row +=column[i];
	}
	printf("%d\n", row);
	return 0;

}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		String str = scan.next();

		// 出力値
		int i = 0;
		if (str.equals("SUN")) {
			i = 7;
		} else if (str.equals("MON")) {
			i = 6;
		} else if (str.equals("TUE")) {
			i = 5;
		} else if (str.equals("WED")) {
			i = 4;
		} else if (str.equals("THU")) {
			i = 3;
		} else if (str.equals("FRI")) {
			i = 2;
		} else if (str.equals("SAT")) {
			i = 1;
		}

		System.out.println(i);
	}
}

Measured memory_bytes: 23252
MOD = 10**9 + 7
S = int(input())

dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
    for j in range(0, (i-3)+1):
        dp[i] += dp[j]
        dp[i] %= MOD

print(dp[S])

Measured memory_bytes: 9020
#include <bits/stdc++.h>
using namespace std;
long long A[3];
int main()
{
long long a,b,i,c=0,d=0,n,m,t,j;
cin>>n;
for(i=0;i<n;i++)
{
  cin>>a>>b;
  c+=(b-a+1);
}
std::cout <<c<< '\n';
return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int m,a,b,p[205],c,d;

int main(){
  while(1){
    cin>>m>>a>>b;
    if(!m&&!a&&!b)break;
    c=d=0;
    for(int i=0;i<m;i++)cin>>p[i];
    for(int i=b-1;i>=a-1;i--)
      if(p[i]-p[i+1]>c)c=p[i]-p[i+1],d=i+1;
    cout<<d<<endl;
  }
  return 0;
}

Measured memory_bytes: 3080
s=input()
l=['AKIHABARA','KIHABARA','AKIHBARA','AKIHABRA','AKIHABAR',
   'KIHBARA','AKIHBRA','AKIHABR','KIHABRA',
   'AKIHBAR','KIHABAR',
   'KIHBRA','AKIHBR','KIHABR','KIHBAR','KIHBR']

if s in l:
    print("YES")
else:
    print("NO")

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

using namespace std;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while (true)
    {
        C -= B;
        if (C <= 0)
        {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0)
        {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include<climits>
#include<vector>
using namespace std;
struct Activity{
    int A,B,C;
};
int solve(vector<Activity> ar,int n)
{
    int dp[n+1][3];
    dp[1][0] = ar[1].A;
    dp[1][1] = ar[1].B;
    dp[1][2] = ar[1].C;
    for(int i = 2;i <=n ;i++)
    {
        dp[i][0] = ar[i].A + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = ar[i].B + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = ar[i].C + max(dp[i-1][0],dp[i-1][1]);
    }
    return max(max(dp[n][0],dp[n][1]),dp[n][2]);
}
int main() {
    int n;
    cin>>n;
    vector<Activity> ar(n+1);
    for(int i = 1;i <= n;i++)
    {
        cin>>ar[i].A;
        cin>>ar[i].B;
        cin>>ar[i].C;
    }
    cout<<solve(ar,n);
}

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

using namespace std;

int main(){
    int N;
    double T,A,htd[1000];

    cin >> N >> T >> A;

    for(int i=0; i<N; i++){
        cin >> htd[i];
        htd[i] = abs(A - (T - htd[i] * 0.006));
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        if(htd[i] < htd[ans]){
            ans = i;
        }
    }

    cout << ans + 1 << endl;
}

Measured memory_bytes: 256
D,G = map(int, input().split())
L = []
for i in range(D):
    L.append([int(x) for x in input().split()])
    
for i in range(D):
    L[i].append(L[i][0]*(i+1)*100+L[i][1])
    
ans_list = []
for i in range(2**D):
    temp = bin(i)
    score = 0
    cnt = 0
    used = []
    for j in range(len(temp)-2):
        if temp[-1-j] == "1":
            score += L[j][2]
            used.append(j)
            cnt += L[j][0]
    num = D-1
    while num in used:
        num -= 1
    for j in range(L[num][0]-1):
        if score < G:
            score += (num+1)*100
            cnt += 1
    if score >= G:
        ans_list.append(cnt)
    
print(min(ans_list))

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cstdio>
 
using namespace std;
void sort(char *str){
    int len, len2 = 0;
    char work; 
    len = strlen(str);
 
    for(len = len - 1; len > len2; len--, len2++){
        work = str[len];
        str[len] = str[len2];
        str[len2] = work;
    }
}
 
int main(){
    char str[21];
 
    cin >> str;
    sort(str);
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll N,i,ans=1e15+5;
    cin>>N;
    for(i=1;i<=sqrt(N);i++)
    {
        if(N%i==0) ans=min(ans,i+N/i-2);
    }
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 300005;

/* ...o(^-^)o... */

int main(){
    int n,a,b,c,d; string s;
    cin>>n>>a>>b>>c>>d>>s;
    a--; b--; c--; d--;

    for(int i = a; i < c; i++){
        if(s[i]=='#' && s[i+1]=='#'){
            out("No"); return 0;
        }
    }
    for(int i = b; i < d; i++){
        if(s[i]=='#' && s[i+1]=='#'){
            out("No"); return 0;
        }
    }

    if(c<d){
        out("Yes"); return 0;
    }
    for(int i = b; i <= d; i++){
        if(i == n-1) continue;
        if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
            out("Yes"); return 0;
        }
    }
    out("No");
}

Measured memory_bytes: 640
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (!set.add(a)) {
				System.out.println("NO");
				return;
			}
		}
		
		System.out.println("YES");
	}
}


Measured memory_bytes: 100456
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[100010];
ll n;

int main(){
	scanf("%s",s);
	n=strlen(s);
	ll pcnt=0;
	rep(i,0,n)pcnt+=(s[i]=='p');
	//全部グーだと-pcnt点、そこからn/2
	printf("%lld\n",n/2-pcnt);
}

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

#define M 1046527
#define L 14

int Insert(char *);
int Find(char *);
int h1(int);
int h2(int);
int Atoi(char);
long long Keyget(char *);

char H[M][L];

int main()
{
  int i;
  int n;
  char moji[10], inp[L];
  
  scanf("%d", &n);
  for( i = 0 ; i < M ; i++ ) H[i][0] = '\0';
  
  for( i = 0 ; i < n ; i++ ){
    scanf("%s %s", moji, inp);
    if( strcmp(moji, "insert") == 0 ) {
      Insert(inp);
    }
    else {
      if( Find(inp) ) printf("yes\n");
      else printf("no\n");              
    }
  }

  return 0;
}

int Insert(char inp[])
{
  long long i, key, h;
  
  key = Keyget(inp);
  for( i = 0 ; ; i++ ){
    h = (h1(key) + i * h2(key)) % M;
    if( strcmp(H[h], inp) == 0 ) {
      return 1;
    }
    else if( strlen(H[h]) == 0 ){
      strcpy(H[h], inp);
      return 0;
    }
  }
  return 0;
}

int Find(char inp[])
{
  long long i, key, h;

  key = Keyget(inp);
  for( i = 0 ; ; i++ ){
    h = (h1(key) + i * h2(key)) % M;
    if( strcmp(H[h], inp) == 0 ) return 1;
    else if( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

long long Keyget(char inp[])
{
  long long i, sum=0, a=1;

  for( i = 0 ; i < strlen(inp) ; i++ ){
    sum += a*(Atoi(inp[i]));
    a *= 5;
  }
  
  return sum;
}

int Atoi(char c)
{
  if( c == 'A' ) return 1;
  else if( c == 'C' ) return 2;
  else if( c == 'G' ) return 3;
  else if( c == 'T' ) return 4;
  else return 0;
}

int h1(int key)
{
  return key % M;
}

int h2(int key)
{
  return 1 + (key % (M - 1));
}

Measured memory_bytes: 14916
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N, D;
  cin >> N >> D;
  long ans = 0;
  ans += N / (D * 2 + 1);
  if (N % (D * 2 + 1)) ans++;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,n,j,l,t,r,d,ans=0,arr[1000000];
    string s;
    cin>>n;
    d=n/500;
    r=n%500;
    ans=1000*d;
    n=r;
    d=n/5;
    r=n%5;
    ans+=5*d;
    cout<<ans;
}

Measured memory_bytes: 256
# Try AtCoder
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gf() gets.to_f end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
MV4 = [[0, 1], [1, 0], [0, -1], [-1, 0]]
MV8 = MV4 + [[1, 1], [1, -1], [-1, -1], [-1, 1]]
DV7 = 7 + 10 ** 9
############################################################
 
# 解説読後
# http://agc002.contest.atcoder.jp/data/agc/002/editorial.pdf 

N, L = gis
A = gis
k = -1
(N - 1).times do |i|
    if A[i] + A[i + 1] >= L
        k = i
        break
    end
end

if k < 0
    puts 'Impossible'
    exit
end

puts 'Possible'
ans = []
ans += (1..k).to_a if k > 0
ans += (k+2...N).to_a.reverse if k < N - 2
ans << [k + 1]
puts ans * "\n"



Measured memory_bytes: 14960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
  {
    int n;
    cin >> n;
    vector<double> vec(n + 1);
    cout << fixed << setprecision(6);
    for (int i = 1; i <= n; i++)
    {
      cin >> vec[i];
    }
    double ans = 0;
    for (int i = 1; i < n; i++)
    {

      sort(vec.begin(), vec.end());
      ans = (vec[i] + vec[i + 1]) / 2;
      vec[i + 1] = ans;
    }
    cout << vec[n] << endl;
  }

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding Space*/
int main(){
  string s;
  cin >> s;
  if(s == "KIHABARA" || s == "AKIHBARA" || s == "AKIHABRA" || s == "AKIHABAR" ||
     s == "AKIHABR"  || s == "AKIHBRA"  || s == "AKIHBAR"  || s == "KIHABAR"  ||
     s == "KIHABRA"  || s == "KIHBARA"  || s == "AKIHBR"   || s == "KIHABR"   ||
     s == "KIHBAR"   || s == "KIHBRA"   || s == "AKIHABARA" || s == "KIHBR")
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

vector<pair<ll, ll>> primes;
vector<int> cnt;
ll ans = 1LL << 60;

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; p++) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            num++;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));

    return res;
}

ll f(ll a, ll b) {
    ll cnt_a = 1;
    while (a / 10) {
        cnt_a++;
        a /= 10;
    }

    ll cnt_b = 1;
    while (b / 10) {
        cnt_b++;
        b /= 10;
    }
    return max(cnt_a, cnt_b);
}

void rec(int i) {
    if (i == primes.size()) {
        ll num1 = 1;
        ll num2 = 1;
        rep(i, cnt.size()) {
            rep(j, cnt[i]) num1 *= primes[i].first;
            rep(j, primes[i].second - cnt[i]) num2 *= primes[i].first;
        }
        chmin(ans, f(num1, num2));
        return;
    }

    rep(j, primes[i].second + 1) {
        cnt[i] = j;
        rec(i + 1);
    }
}

int main() {
    ll N;
    cin >> N;
    primes = prime_factorize(N);
    cnt.resize(primes.size());
    rec(0);
    cout << ans << endl;
}

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

int main(void) {
  int d;

  if(scanf("%d", &d) == 1);

  if(d == 25) {
    printf("Christmas");
  } else if (d == 24) {
    printf("Christmas Eve");
  } else if (d == 23) {
    printf("Christmas Eve Eve");
  } else {
    printf("Christmas Eve Eve Eve");
  }

  return 0;
}

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

int main ()
{
	multiset <int> s;
	int i, num;
	for( i= 0; i < 10; i++)
	{
     cin >> num;
	 s.insert(num);
	}
	multiset <int>::iterator j ;
	j= s.end();
	for(i = 0; i < 3; i++)
	{
	  j--;
      cout << *j << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

int main(){fastio
    ll n;cin>>n;
    vector<l_l>v[n+1];
    rep(i,1,n-1){
        ll a,b;cin>>a>>b;
        v[a].pb(l_l(b,i));
        v[b].pb(l_l(a,i));
    }
    vector<ll>path[n+1][n+1];
    rep(i,1,n){
        queue<ll>q;q.push(i);
        while(!q.empty()){
            ll t=q.front();q.pop();
            for(auto x:v[t]){
                if(i==x.first)continue;
                if(path[i][x.first].size()==0){
                    path[i][x.first]=path[i][t];
                    path[i][x.first].pb(x.second);
                    q.push(x.first);
                }
            }
        }
    }
    /*
    rep(i,1,n){
        rep(j,1,n){
            cout<<i<<","<<j<<":";
            for(auto x:path[i][j]){
                cout<<x<<" ";
            }cout<<endl;
        }
    }*/
    
    ll m;cin>>m;
    ll a[m],b[m];
    rep(i,0,m-1)cin>>a[i]>>b[i];
    ll ans=0;
    rep(i,0,(1<<m)-1){
        vector<ll>ng;
        bool used[n];memset(used,false,sizeof(used));
        rep(j,0,m-1){
            if((i>>j)&1){
                ng.pb(j);
            }
        }
        for(auto num:ng){
            for(auto y:path[a[num]][b[num]]){
                used[y]=true;
            }
        }
        ll us=0;
        rep(x,1,n-1)if(!used[x])us++;
        ll res=1ll<<us;
        if(ng.size()%2==0){
            ans+=res;
        }else{
            ans-=res;
        }
        //cout<<i<<" "<<res<<endl;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
ans=[1]
for i in range(2,1000):
  cnt=2
  while i**cnt<=1000:
    ans.append(i**cnt)
    cnt+=1

x=int(input())
ans.sort()
for i in range(len(ans)):
  if ans[i]==x:
    print(ans[i])
    break
  elif ans[i]>x:
    print(ans[i-1])
    break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> iP;
typedef pair< LL, LL > LP;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 300005;

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i ) {
            ret.pb( i );
            if( i * i != n ) ret.pb( n / i );

        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    set< int > st;
    for( int i = 0; i < n; ++i ) {
        int a;
        cin >> a;
        st.insert( a );

    }

    cout << st.size() << endl;
    return 0;
}



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

const int MaxN = 1e5 + 10;
int n, m;
vector <int> e[MaxN];
int col[MaxN];
long long a, b, c;

bool bip(int x) {
    bool ret = true;
    for (int y : e[x]) {
        if (col[y] == 0) {
            col[y] = 3 - col[x];
            ret &= bip(y);
        } else if (col[y] == col[x])
            ret = false;
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    while (m--) {
        int x, y;
        cin >> x >> y;
        e[--x].push_back(--y);
        e[y].push_back(x);
    }
    for (int i = 0; i < n; i++) {
        if (col[i]) continue;
        if (e[i].size() == 0)
           c++;
        else {
            col[i] = 1;
            if (bip(i))
                a++;
            else
                b++;
        }
    }
    cout << 2*a*a + b*b + 2*a*b + 2*c*n - c*c;
    return 0;
}

Measured memory_bytes: 10112
#include <stdio.h>
int main(void){
       int i=0, j, k;
       long int a=1000000000;
       long int x[20];
       int y[10][10];
 
       for(i=0; i<=20; i++){
 
             if(scanf("%ld", &x[i]) != EOF){
 
                 for(j=0; j<10 ;j++){
                     y[0][j] = (x[i]/a)%10;
                     a/=10;
                 }
 
                 for(j=1; j<10; j++){
                     for(k=0; k<9; k++){
                     y[j][k] = (y[j-1][k]+y[j-1][k+1])%10;
                     }
                 }
                                                                                 
                 printf("%ld\n",y[9][0]);
                 a = 1000000000;
             }else{
                  break;
             }
       }
       return 0;
 }



Measured memory_bytes: 2036
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x := iSScan(4)
	ans := []int{x[2] - x[3] + x[1], x[3] + x[2] - x[0], x[0] - x[3] + x[1], x[1] + x[2] - x[0]}
	fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
string s;
ll ans=0;
void backtrack(int u, ll n, ll res){
    if(u==s.size()) ans+=res+n;
    else{
        n=n*10+s[u]-48;
        backtrack(u+1, n, res);
        backtrack(u+1, 0, res+n);
    }
}
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    cin>>s;
    backtrack(0, 0, 0);
    write(ans/2);
}

Measured memory_bytes: 256
program prob2
    implicit none
    character(len=200005)::s
    integer::i, l, r, p
    read(*,*) s
    p = 0
    do i = 1, len_trim(s)
        if(s(i:i) .eq. 'A' .and. p == 0) then
            l = i
            p = 1
        end if
        if(s(i:i) .eq. 'Z') r = i
    end do
    write(*,*) r - l + 1
    stop
end program

Measured memory_bytes: 3216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
map<int,int>p;
char a[200000];
int main()
{
	ll m,n,i,j,t,k,ans=0;
	cin>>n>>a;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			k=2*j-i;
			if(k<n&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
			{
				ans++;
			}
		}
	}
	ll q=0,w=0,e=0;
	for(i=0;i<n;i++)
	{
		if(a[i]=='R') q++;
		else if(a[i]=='G') w++;
		else e++;
	}
	cout<<q*w*e-ans;
 } 

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

inline long long int f(long long int n){
	return (n*(n-1))/2;
}


int main(){
	
	ios_base::sync_with_stdio(false);
	map<string,long long int> m;
	string s;
	long long int n;
	cin>> n;
	while(n--){
		cin >> s;
		sort(s.begin(),s.end());
		m[s] ++;
	}
	
	long long int mx = 0;
	for(auto x : m)
		mx += f(x.second);
	
	cout << mx <<"\n";
	return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <queue>
#include <vector>

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

int n,k;

char s[10050],ans[10050];

int main()
{
	n=read(),k=read();
	cin >> (s+1);
	for (int i=1;i<=n;i++)
		s[n*2-i+1]=s[i];
	for (int i=1;i<=n;i++)
		ans[i]=s[i];
	for (int i=1;i<=n;i++)
	{
		bool flag=true;
		for (int j=i;j<=n+i-1 && flag;j++)
		{
			if (ans[j-i+1]<s[j])
				flag=false;
			else if (ans[j-i+1]>s[j])
				break;
		}
		if (flag)
		{
			for (int j=i;j<=n+i-1;j++)
				ans[j-i+1]=s[j];
		}
	}
	int len=1;
	while (len<=n && ans[len]==ans[1])
		len++;
	len--;
	if (k>15 || len*(1<<(k-1))>=n)
	{
		for (int i=1;i<=n;i++)
			cout << ans[1];
	}
	else
	{
		int res=n-(len*(1<<(k-1)));
		for (int i=1;i<=n-res;i++)
			cout << ans[1];
		for (int i=1;i<=res;i++)
			cout << ans[i+len];
	}
	return 0;
}

Measured memory_bytes: 256