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

#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin>>x
#define print(x) cout<<x
#define pii pair<int,int>
#define pll pair<ll,ll>
#define gcd(a,b) __gcd(a,b)
#define reset(d,val) memset(d,val,sizeof(d))
#define sort(v) sort(v.begin(),v.end())
#define sort_arr(arr,i,f) sort(arr+i,arr+f)
#define pq priority_queue<int,vector<int>,greater<int> >
#define pq1 priority_queue<pll,vector<pll>,greater<pll> >

const int mod = 1e9+7;

int n;
ll dp[405][405],arr[405];

ll sm (int i,int j){
	ll ans = 0;
	for (int k = i; k <=j; ++k)
	{
		ans +=arr[k];
	}
	return ans;
}

ll f(int i,int j){
	if(i>=j) { 
		return 0;
	}
	if(dp[i][j]!=-1) return dp[i][j];
	ll ans = 1e18;
	for (int k = i; k <j ; ++k)
	{
		ans = min(ans,f(i,k)+f(k+1,j)+sm(i,j));
	}
	return dp[i][j]=ans;
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<f(0,n-1);
	return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int n, k, res = 0;
	cin>>n>>k;
	for (int i = 1; i <= n; i++) {
		int v;
		cin>>v;
		res += (v >= k);
	}	
	cout<<res;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N;
vector<vector<long long int> > kohuku, dp;

int main() {
    cin >> N;
    
    kohuku.resize(N, vector<long long int>(3));
    dp.resize(N, vector<long long int>(3, 0));
    for(int i=0; i<N; i++) {
        for(int j=0; j<3; j++) {
            cin >> kohuku[i][j];
            if(i==0) {
                dp[i][j]=kohuku[i][j];
            }
        }
        if(i>0) {
            for(int j=0; j<3; j++) {
                if(j==0) {
                    dp[i][j]=max(dp[i-1][1], dp[i-1][2])+kohuku[i][j];
                } else if(j==1) {
                    dp[i][j]=max(dp[i-1][0], dp[i-1][2])+kohuku[i][j];
                } else {
                    dp[i][j]=max(dp[i-1][0], dp[i-1][1])+kohuku[i][j];
                }
            }
        }
    }
    
    cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;

    return 0;
    
}

Measured memory_bytes: 11136
# ABC098 B - Cut and Count
n = int(input())
s = input()

ans=0
for i in range(n-1):
    start = s[0:i+1]
    end = s[i+1:]
    start = ''.join(set(start))
    c = 0
    for j in range(len(start)):
        if start[j] in end:
            c += 1
            ans = max(ans,c)
print(ans)


Measured memory_bytes: 3060
def main():

    count = dict()
    for _ in range(3):
        a, b = map(int, input().split())
        count[a] = count.get(a, 0) + 1
        count[b] = count.get(b, 0) + 1
    if sorted(count.values()) == [1, 1, 2, 2]:
        return "YES"
    return "NO"


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_M 28

using namespace std;

int C[MAX_M];
bool D[MAX_M][MAX_M];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    D[a - 1][b - 1] = true;
    D[b - 1][a - 1] = true;
  }

  for (int i = 0; i < N; ++i) {
    C[i] = i;
  }

  int cnt = 0;
  do {
    bool flg = true;
    for (int i = 0; i < N - 1; ++i) {
      if (!D[C[i]][C[i + 1]]) {
        flg = false;
        break;
      }
    }
    cnt += flg;
  } while (next_permutation(C + 1, C + N));
  printf("%d\n", cnt);
}

Measured memory_bytes: 3220
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
 
int main()
{
  int n, k;
  std::cin >> n >> k;
 
  double prob = 0.0;
  for(int i=1; i<=n; i++)
  {
    prob += std::pow(0.5, std::max<int>(0,std::ceil(std::log2(k/(double)i)))) / (double)n;
  }
  std::cout << std::setprecision(17) << prob;
}

Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
using namespace std;
int count;

void Func(int n,int s,int j){
	if(n==0){
		if(s==0)++count;
		return;
	}
	for(int i=j+1;i<=9;++i){
		Func(n-1,s-i,i);
	}
}

int main(){
	int n,s;
	while(cin>>n>>s,n|s){
		count = 0;
		Func(n,s,-1);
		cout << count << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 1; i < (n+1) ;i++)

using namespace std;
using p=pair<int,int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int>ans(10009);
  rep(i,100){
    rep(j,100){
      rep(o,100){
        int k=i*i+j*j+o*o+i*j+j*o+o*i;
        if(k<=n){
          if(i==j&&j==o){
            ans[k]+=1;
          }
          else if(i==j||j==o||o==i){
            ans[k]+=1;
          }
          else if(i!=j && j!=o && o!=i){
            ans[k]+=1;
          }
        }
      }
    }
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
  
  return 0;

}



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

using namespace std;

int const Month[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
string const Week[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };

int main(){
	int month, day;

	while (cin >> month >> day){
		if ((month == 0) && (day == 0)) break;
		int today = day;
		month--;
		while (month){
			today += Month[month - 1];
			month--;
		}
		cout << Week[(today + 2) % 7] << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outc(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(32);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

int gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, int k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
//ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
//Unaccepted
const int maxn = 1e6 + 5;
int sum[maxn];
int dp[2][maxn], f[2][maxn];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n, d;
    cin >> n >> d;
    cout << (n + 2 * d) / (2 * d + 1) << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<vector<char>> s(N, vector<char>(10));
  vector<string> Sfixed(N);
  for(int i=0; i<N; i++){
    for(int j=0; j<10; j++){
      cin >> s.at(i).at(j);
    }
    sort(s.at(i).begin(), s.at(i).end());
    for(int j=0; j<10; j++){
      Sfixed.at(i) += s.at(i).at(j);
    }
  }

  int64_t ans = 0;
  unordered_map<string, int> M;
  for(int i=0; i<N; i++){
    if(M.count(Sfixed.at(i))){
      ans += M.at(Sfixed.at(i));
      M.at(Sfixed.at(i))++;
    }
    else{
      M[Sfixed.at(i)] = 1;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 18468
#include<bits/stdc++.h>
#define FAST std::ios::sync_with_stdio(false);
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAX_N 100005
#define Mem(a,b) memset(a,b,sizeof(a))
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
using namespace std;

map<ll,int> mymap;
int main()
{
    FAST;
    int n;
    cin>>n;
    ll tmp;
    int ans=0;
    map<ll,int>::iterator it;
    for(int i=0;i<n;i++){
        cin>>tmp;
        it=mymap.find(tmp);
        if(it==mymap.end())
        {
            mymap[tmp]=1;
            ans++;
        }
        else
        {
            ans--;
            mymap.erase(tmp);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  vector<double> P(N);
  rep(i,N) cin>>P[i];
  vector< vector<double> > dp(N+1,vector<double>(N+1));
  dp[0][0]=(double)1;
  rep(i,N){
    rep(j,N+1){
      dp[i+1][j]+=dp[i][j]*P[i];
      dp[i+1][j+1]+=dp[i][j]*((double)1-P[i]);
    }
  }
  double ans=0;
  rep(i,(N+1)/2) ans+=dp[N][i];
  cout<<setprecision(10)<<ans<<endl;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    if (n <= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

ull gcd(ull a, ull b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

ull lcm(ull a, ull b) {
    return a * b / gcd(a, b);
}

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

    ull lcm_cd, underA, underB;
    lcm_cd = lcm(C, D);
    underA = A-1 - (A-1) / C - (A-1) / D + (A-1) / lcm_cd;
    underB = B - B / C - B / D + B / lcm_cd;

    cout << underB - underA << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 1000005;
int c[MAX_N];

int main()
{
	ll N;
	cin >> N;
	ll temp = N;
	int ans = 0;
	for (ll i = 2; i*i <= N; ++i)
	{
		while (temp % i == 0)
		{
			temp /= i;
			c[i]++;
		}
	}
	if (temp != 1)
	{
		ans++;
	}
	rep(i,MAX_N)
	{
		if (c[i] != 0)
		{
			int cnt = 1, temp2 = 0;
			while (temp2+cnt <= c[i])
			{
				temp2 += cnt;
				cnt++;
			}
			ans += cnt-1;
			//cout << ans << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);

const isPrime = n => {
    if (n < 2) return false;
    if (n === 2) return true;
    for (let i = 2; i*i <= n; i++) {
        if (n % i === 0) return false;
    }
    return true;
};

const ans = line.slice(1, line.length-1)
                .map(x => parseInt(x))
                .reduce((acc, x) => isPrime(x) ? acc + 1 : acc, 0);
console.log(ans);



Measured memory_bytes: 18192
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */



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

    int N; cin >> N;
    vector<int> a(N);
    map<int, int> mp;

    rep(i, N){
        cin >> a[i];
        ++mp[a[i]];
    }
    int cnt=0;
    for(auto itr=mp.begin(); itr!=mp.end(); ++itr) cnt += itr->second-1;

    cout << N-(cnt%2==0? cnt:cnt+1) << endl;

    return 0;
}


Measured memory_bytes: 5376
N, M = map(int, input().split())  # N個の数列, 合計がM, 求めたいのは最大公約数の最大値

divs = []
for i in range(1, int((M)**(1/2)+1)):
    if M % i == 0:
        divs.append(i)
        divs.append(M//i)

divs.sort()

ans = 0
for d in divs:
    if M//N >= d:
        ans = d
    else:
        break

print(ans)


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

int main(){
  int N, t;
  cin >> N >> t;

  if (N < t){
    cout << 0 << endl;
  }
  else
  {
    cout << N - t << endl;
  }
  
}

Measured memory_bytes: 3532
/*
Á·Ï°Ìâ£ºSave your cats_AOJ 2224 
	¼õÈ¥×îÉÙ¡¢Ð¡µÄ±ß£¬Ê¹µÃÕû¸öÆ½ÃæÁ¬Í¨£»
	¼´ÎªÇó×î´óÉú³ÉÊ÷ÎÊÌâ£¬µ«×¢ÒâÇóµÄÊÇ²ÃÈ¥µÄÂ·¾¶¡£ 
*/

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const int MAX_E=49995007, MAX_V=10007;
int mark[MAX_E];
pair<int, int> ver[MAX_V];

struct edge{
	int u, v, cost;
}; 
bool cmp(const edge& e1, const edge& e2)
{
	return e1.cost<e2.cost;
}

edge es[MAX_E];
int V, E;


//DUS start line

int par[MAX_V];//¸¸Ç× 
int hight[MAX_V];//Ê÷µÄ¸ß¶È

//³õÊ¼»¯n¸öÔªËØ
void init(int n)
{
	for(int i=0; i<n; i++)
	{
		par[i]=i;
		hight[i]=0;
	}
}

//²éÑ¯Ê÷µÄ¸ù
int find(int x)
{
	if(par[x]==x)
		return x;
	else
		return par[x]=find(par[x]);
}

//ºÏ²¢xºÍyËùÊôµÄ¼¯ºÏ
void unite(int x, int y)
{
	x=find(x);
	y=find(y);
	if(x==y)
		return ;
	if(hight[x]<hight[y])
		par[x]=y;
	else
	{
		par[y]=x;
		if(hight[x]==hight[y])
			hight[x]++;
	}
}

//ÅÐ¶ÏxºÍyÊÇ·ñÊôÓÚÍ¬Ò»¸ö¼¯ºÏ
bool same(int x, int y)
{
	return find(x)==find(y);
}

//DUS end line 


double kruskal()
{
	sort(es, es+E, cmp);
	
	init(V);
	

	double res=0;
	for(int i=0; i<E; i++)
	{
		edge e=es[i];
		if(!same(e.u, e.v))
		{
			unite(e.u, e.v);
			mark[i]=1;
		}
	}
	
	for(int i=0; i<E; i++)
	{
		if(mark[i]==0)
			res+=sqrt(-es[i].cost);
	}
	return res;
}

int main()
{
	scanf("%d%d", &V, &E);
	for(int i=0;  i<V; i++)
	{
		scanf("%d%d", &ver[i].first, &ver[i].second);
	}
	for(int i=0; i<E; i++)
	{
		edge ed;
		scanf("%d%d", &ed.u, &ed.v);
		ed.u--;
		ed.v--;
		ed.cost=-((ver[ed.u].first-ver[ed.v].first)*(ver[ed.u].first-ver[ed.v].first)+(ver[ed.u].second-ver[ed.v].second)*(ver[ed.u].second-ver[ed.v].second));
		es[i]=ed;
	}
	
	double ans=kruskal();
	printf("%.3lf\n", ans);
	
	
	return 0;
}


Measured memory_bytes: 3860
N,M =map(int, input().split())
s = []
c = []
for i in range(M):
    x1,y1=[int(i) for i in input().split()]
    s.append(x1)
    c.append(y1)
if N == 1:
	ans = 0
elif N == 2:
    ans = 10
elif N == 3:
    ans = 100
check1 = 0
check2 = 0
check3 = 0

for i in range(0,M):
    if N == 3:
        if s[i] == 3 and check1 == 0:
            ans += c[i]
            check1 = 1
        elif s[i] == 2 and check2 == 0:
            ans += c[i]*10
            check2 = 1
        elif s[i] == 1 and check3 == 0:
            ans += c[i]*100
            ans -= 100
            check3 = 1
    elif N == 2:
        if s[i] == 2 and check2 == 0:
            ans += c[i]*1
            check2 = 1
        elif s[i] == 1 and check3 == 0:
            ans += c[i]*10
            ans -= 10
            check3 = 1
    elif N == 1:
        if s[i] == 1 and check2 == 0:
            ans += c[i]*1
            check2 = 1
    
    
for i in range(0,M):
  for j in range(i,M):
    if s[i] == s[j] and c[i] != c[j]:
      ans = -1
      
if N == 3:
    for i in range(0,M):  
        if s[i] == 1 and c[i] == 0:
            ans = -1
if N == 2:
    for i in range(0,M):  
        if s[i] == 1 and c[i] == 0:
            ans = -1
        
print(ans)

      


Measured memory_bytes: 3188
from sys import stdin
import sys
sys.setrecursionlimit(10000)


def grid2adj(arr_grid,direction=4):
    def cand(i,j,direction):
        if direction == 4:
            return [[i-1,j],[i+1,j],[i,j-1],[i,j+1]]
        elif direction == 8:
            return [[i-1,j],[i+1,j],[i,j-1],[i,j+1],
                    [i-1,j-1],[i-1,j+1],[i+1,j-1],[i+1,j+1]]
        else:
            print('Error')
    
    M,N = len(arr_grid),len(arr_grid[0])
    arr_con = [[] for i in range(M*N)]
    for i in range(M):
        for j in range(N):
            v = i*N+j
            for _cand in cand(i,j,direction):
                if 0<=_cand[0]<M and 0<=_cand[1]<N:
                    next_v = _cand[0]*N+_cand[1]
                    arr_con[v].append(next_v)
    arr_val = sum(arr_grid,[])

    return arr_con, arr_val


class DFS():
    def __init__(self, con, val):
        # 隣接リスト表現
        self.con = con
        self.val = val
        self.N = len(self.con)
        # 訪問済み?
        self.seen = [False] * self.N

    def dfs(self, v):
        self.seen[v] = True
        for next_v in self.con[v]:
            if self.seen[next_v]:
                continue
            if self.val[next_v] == 1:
                self.dfs(next_v)
        return


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    io_cnt = 0
    while True:
        try:
            w,h = list(map(int,_in[io_cnt].split(' ')))  # type:list(int)
            c_arr = []
            for i in range(h):
                _ = list(map(int,_in[io_cnt+i+1].split(' ')))  # type:list(int)
                c_arr.append(_)
            io_cnt += h+1
            # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
            c_con, c_val = grid2adj(c_arr,direction=8)
            dfs = DFS(c_con,c_val)

            cnt = 0
            for v, val in enumerate(c_val):
                if val == 1:
                    if not dfs.seen[v]:
                        dfs.dfs(v)
                        cnt += 1
            # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            print(cnt)
        except:
            break



Measured memory_bytes: 9012
import itertools
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
num=list(range(1,n+1))
c=list(itertools.permutations(num))
aa=c.index(tuple(a))
bb=c.index(tuple(b))
Ans=(aa+1)-(bb+1)
if Ans>=0:
  print(Ans)
else:
  print(-Ans)

Measured memory_bytes: 8052
//
// Created by tattsun on 2017/02/13.
//

#include <iostream>
#include <vector>

using namespace std;

#define VERTEX_MAX_NUM 101
#define NIL -1

int now = 0;
int n;
int start[VERTEX_MAX_NUM];
int finish[VERTEX_MAX_NUM];
bool visited[VERTEX_MAX_NUM];
vector<int> vertexes[VERTEX_MAX_NUM];

void _dfs(int node) {
    start[node] = ++now;
    visited[node] = true;

    auto& v = vertexes[node];

    for(auto it = v.begin(); it != v.end(); it++) {
        if(visited[*it])
            continue;
        _dfs(*it);
    }

    finish[node] = ++now;
}

void dfs() {
    for(int i=1; i<=n; i++) {
        if(visited[i]) continue;
        _dfs(i);
    }
}

int main() {
    for(int i=0; i<VERTEX_MAX_NUM; i++) {
        start[i] = NIL;
        finish[i] = NIL;
        visited[i] = false;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vertexes[i].push_back(p);
        }
    }

    dfs();

    for(int i=1; i<=n; i++) {
        cout << i << " " << start[i] << " " << finish[i] << endl;
    }
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int mod;
int n,k,m,i,j,p,f[155][155],g[155][155][155],s1,s2;
int main(){
	cin>>n>>k>>mod;
	if(!(k&1)){
		f[0][0]=1;
		for(i=0;i<n;i++){
			for(j=0;j<=min(i,k/2);j++){
				(f[i+1][j+1]+=f[i][j])%=mod;
				(f[i+1][0]+=f[i][j])%=mod;
			}
		}
		for(j=0;j<=k/2;j++){
			(s1+=f[n/2][j])%=mod;
			(s2+=f[n-n/2][j])%=mod;
		}
		cout<<1ll*s1*s2%mod<<endl; 
	}
	else{
		g[0][0][0]=1;
		for(i=1;i<=n+1;i++){
			int r=i*2,l=r-k;
			bool fl=(1<=l&&l<=n),fr=(1<=r&&r<=n);
			for(j=0;j<=n;j++){
				for(p=0;p<=k+1;p++){
					(g[i][0][0]+=g[i-1][j][p])%=mod;
					if(fr){
						(g[i][j+1][0]+=g[i-1][j][p])%=mod;
					}
					if(fl&&p+1<k+2){
						(g[i][0][p?p+1:p]+=g[i-1][j][p])%=mod;
					}
					if(fl&&fr&&max(j+2,p+1)<k+2){
						(g[i][j+1][max(j+2,p+1)]+=g[i-1][j][p])%=mod;
					}
				}
			}
		}
		cout<<g[n+1][0][0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 10964
#include <iomanip>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	long long int a, b;
	cin >> a;
	long double c = sqrt(a);
	b = c;
	cout << b*b << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
n,k = map(int, input().split())
As = list(map(int, input().split()))
for i in range(k):
    imos = [0] * (n+1)
    for i,a in enumerate(As):
        l = max(0, i-a)
        r = min(n, i+a+1)
        imos[l] += 1
        imos[r] -= 1
    acc = list(accumulate(imos))
    # 指数関数的に増える
    if acc[:-1] == As:
        print(*As)
        exit()
    As = acc[:-1]
print(*As)

Measured memory_bytes: 180432
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int N;
    cin >> N;
    vl H(N);
    for (auto &x : H) cin >> x;
    REP(i, 0, N - 1) {
        if (H[i] > H[i + 1]) {
            H[i]--;
        }
        if (H[i] > H[i + 1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int q;
    cin >> q;

    multiset<long long> ms;
    auto it = ms.begin();
    long long ans = 0;
    while(--q >= 0){
        int type;
        cin >> type;
        if(type == 2){
            cout << *it << ' ' << ans << endl;
            continue;
        }

        long long a, b;
        cin >> a >> b;
        if(ms.empty()){
            ms.insert(a);
            it = ms.begin();
            ans = b;
            continue;
        }

        ms.insert(a);
        ans += abs(a - *it) + b;
        if(ms.size() % 2 == 0 && a < *it){
            -- it;
        }
        else if(ms.size() % 2 != 0 && *it <= a){
            ans += *it;
            ++ it;
            ans -= *it;
        }
    }

    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100010;
int f[N],g[N];
int main()
{
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>f[i];
		g[f[i]]++;
	}
	int sum=0;
	for(i=1;i<=100000;i++)
	{
		sum+=max(0,g[i]-1);
	}
	if(sum%2==1) sum++;
	cout<<(n-sum);
	return 0;
}

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

int main()
{
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    for(int i = 0; i < 2; i++){
        for(int j = 0; j < ty-sy+i; j++) cout << 'U';
        for(int j = 0; j < tx-sx+i; j++){
            cout << 'R';
            if(i == 1 && j == tx-sx+i-1) cout << "DR";
        }
        for(int j = 0; j < ty-sy+i; j++) cout << 'D';
        for(int j = 0; j < tx-sx+i; j++) cout << 'L'; 
        cout << (i == 0 ? "L" : "U");
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INF 1000000
#define W 0
#define G 1
#define B 2
void dijkstra(void);
int A[MAX][MAX],n;

int main()
{
  int i,j;
  int u,k,v,c;  

  scanf("%d",&n);
  //ini
  for(i=0;i<n;i++)
    for(j=0;j<n;j++) A[i][j]=INF;

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      A[u][v]=c;
    }
  }
  dijkstra();

  return 0;
}

void dijkstra(void)
{
  int i,k,kv,min;
  int cost[MAX],col[MAX];

  //ini
  for(i=0;i<n;i++){
    cost[i]=INF;
    col[i]=W;
  }

  cost[0]=0;
  while(1){
    min=INF;
    k=-1;
    for(i=0;i<n;i++){
      if(cost[i]<min && col[i]!=B){
	k=i;
	min=cost[i];
      }
    }

    if(k==-1) break;
    col[k]=B;
    for(kv=0;kv<n;kv++){
      if(col[kv]!=B && A[k][kv]!=INF){
	if(cost[k]+A[k][kv]<cost[kv]){
	  cost[kv]=cost[k]+A[k][kv];
	  col[kv]=G;
	}
      }
    }
  }

  for(i=0;i<n;i++) printf("%d %d\n",i,cost[i]);

}

Measured memory_bytes: 636
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int max =0;
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			if (A[i]>max) {
				max = A[i];
			}
		}
		int count =0;
		for (int i=0;i<max;i++) {
			int temp =0;
			while (temp<N) {
				boolean b = false;
				for (;temp<N;temp++) {
					if (A[temp]>0) {
						A[temp]--;
						b = true;
					} else if (b){
						break;
					}
				}
				if (b==true)
					count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22996
BASE_PAIRS = [['A', 'T'], ['C', 'G']]
base_b = input()
result = ''

for i in range(len(BASE_PAIRS)):
    if base_b in BASE_PAIRS[i]:
        paired_base_index = (BASE_PAIRS[i].index(base_b)+1) % 2
        result = BASE_PAIRS[i][paired_base_index]

print(result)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

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

  int Y[N];
  int s = 0;

  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      s += A[i];
    } else {
      s -= A[i];
    }
  }

    Y[0] = s;

    for (int i = 1; i < N; i++) {
      Y[i] = 2 * A[i - 1] - Y[i - 1];
    }
    for (int i = 0; i < N; i++) {
      cout << Y[i] << " ";
    }
		cout << endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
     
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int a,b;
    vector <string> v;
    cin >> a >> b;
    for(int i = 0;i < a; ++i){
        string s;
        cin >> s;
        v.pb(s);
    }
    sort(all(v));
    for(string i : v){
        cout << i;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll sum = 0, N;
	cin >> N;
	for(ll i=1;i<=N;i++){
		if((i%3) && (i%5)) sum += i;
	}
	cout << sum << '\n';
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
    A.at(i)-=1;
    B.at(i)=0;
  }
  for (int i = 0; i < N; i++){
    B.at(A.at(i))=i;
  }
  for (int i = 0; i < N; i++){
    cout << B.at(i)+1 << " ";
  }
  cout <<endl;
}

Measured memory_bytes: 1664
from collections import*

class UnionFind:
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        self.parents[x] = self.find(self.parents[x]) 
        return self.parents[x]  

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

N, K, L = map(int, input().split())

road = UnionFind(N)
rail = UnionFind(N)

for i in range(K):
    p, q = map(int, input().split())
    road.union(p-1, q-1)
for i in range(L):
    p, q = map(int, input().split()) 
    rail.union(p-1, q-1)

d = defaultdict(int)

for i in range(N):
    d[(road.find(i), rail.find(i))] += 1
print(*[d[(road.find(i), rail.find(i))] for i in range(N)])

Measured memory_bytes: 119256
local bls, brs = bit.lshift, bit.rshift
local mod = 1000003
local function badd(x, y) return (x + y) % mod end
local function bmul(x, y) return (x * y) % mod end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = brs(pow, 1)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local fact = {1}
for i = 2, mod - 1 do
  fact[i] = bmul(fact[i - 1], i)
end

local q = io.read("*n")
for iq = 1, q do
  local x, d, n = io.read("*n", "*n", "*n")
  if d == 0 then
    print(modpow(x, n))
  else
    local a = bmul(x, modinv(d))
    local lim = a + n - 1
    if mod <= lim then
      print(0)
    else
      local numer = fact[lim]
      numer = bmul(numer, modpow(d, n))
      local denom = 1
      if 1 < a then
        denom = fact[a - 1]
      end
      local ret = bmul(numer, modinv(denom))
      print(ret)
    end
  end
end


Measured memory_bytes: 10880
#include <stdio.h>

int main(void){

  int a,b;
  scanf("%d %d", &a, &b);
  int max = a+b;
  if (a-b > max) {
    max = a-b;
  }
  if (a*b > max) {
    max = a*b;
  }
  printf("%d\n", max);

  return 0;
}

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

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b){
  ll p=1;
  for(int i=0;i<b;i++){
    p*=a;
  }
  return p;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p){
  ll n=solveLinear(a,p,1);
  n=n%p;
  if(n<0)return n+p;
  return n;
}

int d2(ll a){
  int i=0;
  while(a%2==0){
    a/=2;
    i++;
  }
  return i;
}

int main(){
  int i,j,cnt=0;
  int n,k;
  cin>>n>>k;
  ll d[2001][2001];
  for(i=0;i<=2000;i++)d[i][0]=1;
  for(i=1;i<=2000;i++){
    for(j=1;j<=i;j++){
      d[i][j]=(d[i-1][j]+d[i-1][j-1])%MOD;
    }
  }
  for(i=1;i<=k;i++){
    cout<<(d[k-1][i-1]*d[n-k+1][i])%MOD<<endl;
  }
}

Measured memory_bytes: 31488
N = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
rui = [0]*N
rui[0] = a[0]
mod = 10**9+7
for i in range(1,N):
    rui[i] = rui[i-1] + a[i]
ans = 0
for i in range(1,N):
    ans = (ans + a[i] * rui[i-1])%mod
print(ans)

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

//long unsigned int N,z=2,t=0;

int main() {
  string S,T;cin>>S>>T;
  int a=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i) == T.at(i)) continue;
    else {S.at(i) = T.at(i);a++;}} 
  cout<<a<<endl;
}


Measured memory_bytes: 3912
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N + 1];
        int[] w = new int[N + 1];
        int[] s = new int[N + 1];
        int[] indice = new int[N];

        a[0] = 0;
        for (int i = 1; i <= N; i++) {
            a[i] = sc.nextInt();
        }
        //System.arraycopy(a, 0, w, 0, N + 1);
        //System.arraycopy(a, 0, s, 0, N + 1);
        //Arrays.sort(s);

        int nr_breaks = 0;
        int cur = 1;
        for (int i = 1; i <= N; i++) {
            //System.out.print("s:" + a[i]);
            //System.out.println(", c:" + cur);
            if (a[i] == cur) {
                cur++;
                //System.out.println("c:" + cur);
            } else {
                nr_breaks++;
                //System.out.println("b:" + nr_breaks);
            }
        }

        if (nr_breaks == N) {
            System.out.println(-1);
        } else {
            System.out.println(nr_breaks);
        }

        // start to run algorithm.
        // N = 5,
        // a: 1 2 3 4 5
        // s: 1 2 3 4 5
        // -> 0.
        //
        // a: 5 5 5 3 1
        // s: 1 3 5 5 5
        // -> 4.
        //
        // a: 2 2 2 3 1
        // s: 1 2 2 2 3
        // -> 4.



    }
}


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

int main() {
    int N, P=0, W=0, G=0, Y=0;
    cin >> N;

    rep(i,N) {
        string S;
        cin >> S;
        if (S == "P") P++;
        else if (S == "W") W++;
        else if (S == "G") G++;
        else if (S == "Y") Y++;        
    }
    if ((P > 0) && (W > 0) && (G > 0) && (Y > 0)) cout << "Four" << endl;
    else cout << "Three" << endl;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

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



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String result = "No";
        if (line.contains("a")) {
            if (line.contains("b")) {
                if (line.contains("c")) {
                    result = "Yes";
                }
            }
        }
        System.out.println(result);
    }
}


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

int main(void){
  int a,b,h; cin >> a >> b >> h;
  int s=(a+b)*h/2;

  cout << s << endl;  

  return 0;
}


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

int main(void) {
  long long N, K;
  cin >> N >> K;
  map<int, long long> ma;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] += b;
  }

  long long cnt = 0;
  for (auto m : ma) {
    cnt += m.second;
    if (cnt >= K) {
      cout << m.first << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String t = sc.nextLine();
        int x = s.length()+1;
        int y = t.length()+1;
        int[][] dp = new int[x][y];
        for(int i = 0; i<x;i++){
            for(int j = 0; j<y;j++){
                if(i==0||j==0){
                    dp[i][j] = 0;
                } else if (s.charAt(i-1)==t.charAt(j-1)){
                    dp[i][j]=dp[i-1][j-1]+1;
                } else {
                    dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
                }
            }
        }
        StringBuilder sol = new StringBuilder();
        int i = x-1;
        int j = y-1;
        while(true){
            if(i<=0||j<=0)
                break;
            if(s.charAt(i-1)==t.charAt(j-1)){
                sol.insert(0, Character.toString(s.charAt(i-1)));
                i--;
                j--;
            } else if(dp[i][j]==dp[i][j-1]){
                j--;
            } else if(dp[i][j]==dp[i-1][j]){
                i--;
            }

        }
        System.out.println(sol.toString());

    }
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (auto &x : a) {
		cin >> x;
	}

	vector<int> v(N, 0);

	for (int i = N - 1; i >= 0; --i) {
		int s = 0;
		for (int j = i + (i + 1); j < N; j += (i + 1)) {
			s += v[j];
		}
		if (a[i] != (s % 2)) {
			v[i] = 1;
		}
	}
	vector<int> b;
	for (int i = 0; i < N; ++i) {
		if (v[i] == 1) {
			b.push_back(i + 1);
		}
	}
	cout << b.size() << endl;
	for (auto x : b) {
		cout << x << endl;
	}
}


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

int main()
{

    string S;
    cin >> S;

    bool flag = true;
    for (int i = 0; i < S.length(); i++)
    {
        if (i % 2 == 0)
        {
            if (S[i] != 'R' && S[i] != 'U' && S[i] != 'D')
            {
                flag = false;
                break;
            }
        }
        else
        {
            if (S[i] != 'L' && S[i] != 'U' && S[i] != 'D')
            {
                flag = false;
                break;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	ll n, m;
	cin >> n >> m;
	if (n == 2 || m == 2) {
		cout << 0 << endl;
		return 0;
	} else if (n == 1 && m == 1) {
		cout << 1 << endl;
		return 0;
	} else if (n < 3 && m < 3) {
		cout << 0 << endl;
		return 0;
	} else if (n == 1) {
		cout << m - 2 << endl;
		return 0;
	} else if (m == 1) {
		cout << n - 2 << endl;
		return 0;
	} else {
		cout << (n - 2)*(m - 2) << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
///****In the name of ALLAH, most Gracious, most Compassionate****//

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cout<<endl

template < class T1,class T2>
ostream &operator <<(ostream &os,const pair < T1,T2 > &p)
{
    os<<"{"<<p.first<<","<<p.second<<"}";
    return os;
}

const int N=3e5+5;
const int oo=1e9+7;

ll a[N];
ll b[N];

ll incr(ll x,ll y)
{
    if(x%y)
    return y- x%y;
    return 0;
}

int32_t main()
{
    FastIO;
    int n;
    cin>>n;
    ll add = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(int i=n;i>=1;i--)
    {
        a[i]+=add;
        add+=incr(a[i],b[i]);
    }
    cout<<add<<"\n";
}


Measured memory_bytes: 3072
def rot(dice, I):
  #USEWND
  #NEWSUD
  a = dice[:]
  if I=='N': x=[0,4,5,1,0]
  elif I=='E': x=[0,2,5,3,0]
  elif I=='W': x=[0,3,5,2,0]
  elif I=='S': x=[0,1,5,4,0]
  for i in [0,1,2,3]: a[x[i+1]]=dice[x[i]]
  return a

dice = map(int,raw_input().split())
for c in raw_input(): dice = rot(dice,c)
print dice[0]

Measured memory_bytes: 4236
import itertools
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
if N==1:
    cmin = 1
else:
    cmin = 100
    for y in itertools.combinations(X,2):
        x1,y1 = y[0]
        x2,y2 = y[1]
        p = x2-x1
        q = y2-y1
        cnt0 = 0
        cnt1 = 0
        for i in range(N):
            x,y = X[i]
            if [x+p,y+q] in X:
                cnt0 += 1
            if [x-p,y-q] in X:
                cnt1 += 1
        cnt = max(cnt0,cnt1)
        cmin = min(cmin,N-cnt)
print(cmin)           
    

Measured memory_bytes: 43356
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, mut k: usize,
        s: Chars
    };

    let other_ch = 'X';
    let mut sum = 0;
    let mut prev = other_ch;
    let mut count = 0;
    let mut section = 0;
    for ch in s.into_iter().chain(vec![other_ch].into_iter()) {
        if ch != prev {
            section += 1;
            if count > 1 {
                sum += count - 1;
            }
            count = 1;
        } else {
            count += 1;
        }
        prev = ch;
    }

    let m = std::cmp::min(section / 2, k);
    let res = std::cmp::min(sum + m * 2, n - 1);
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2392
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

ll n,m,q;
vector<ll> a,b,c,d;
ll ans=0;

void func(vector<ll> &ar)
{
    if(ar.size()==n){
        ll cost=0;
        for(ll i=0;i<q;++i){
            if(ar[b[i]]-ar[a[i]]==c[i]){
                cost+=d[i];
            }
        }
        ans=max(ans,cost);
        return;
    }
    if(ar.size()==0){
        for(ll i=1;i<=m;++i){
            ar.pb(i);
            func(ar);
            ar.pop_back();
        }
    }
    else{
        for(ll i=ar.back();i<=m;++i){
            ar.pb(i);
            func(ar);
            ar.pop_back();
        }
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n>>m>>q;
    a.resize(q);b.resize(q);c.resize(q);d.resize(q);
    for(ll i=0;i<q;++i){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        --a[i];--b[i];
    }
    vector<ll> ar;
    func(ar);
    cout<<ans;

    return (0);
}


Measured memory_bytes: 3664
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S string
	fmt.Scan(&S)

	a := strings.Contains(S, "a")
	b := strings.Contains(S, "b")
	c := strings.Contains(S, "c")
	if a && b && c {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{

    int n;cin>>n;

    int mean = 0;

    VI a(n);
    REP(i,n){
        cin>>a[i];
        mean += a[i];
    }
    //mean /= n;
    //dump(mean)

    int result = 0;

    int diff = n*1000;
    REP(i,n){
        if(abs(mean-(a[i]*n)) < diff){
            diff = abs(mean-(a[i]*n));
            result = i;
            //dump(i)
            //dump(diff)
        }
    }

    cout<<result<<endl;


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
li_color = []
b_max = 0
for i in range(H):
    li_color.append(input())
    b_max = b_max + li_color[-1].count("#")

proc_cnt = 0

for w_bin in range(2**W):
    for h_bin in range(2**H):
        b_cnt = 0
        for w in range(W):
            for h in range(H):
                if (h_bin & (1 << h)) or (w_bin & (1 << w)) :
                    if "#" == li_color[h][w] : b_cnt = b_cnt + 1
        if b_max - b_cnt == K:
            proc_cnt = proc_cnt + 1

print(proc_cnt)



Measured memory_bytes: 9068
S=input()

pos={"AKIHABARA","KIHABARA","AKIHBARA","KIHBARA","AKIHABRA","KIHABRA","AKIHBRA","KIHBRA","AKIHABAR","KIHABAR","AKIHBAR","KIHBAR","AKIHABR","KIHABR","AKIHBR","KIHBR"}
     
if S in pos:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 9036
#include <stdio.h>

int main()
{
    int a, b, uncov_part;
    scanf("%d", &a);
    scanf("%d", &b);
    uncov_part = (a - (2 * b));
    if (uncov_part > 0)
    {
        printf("%d", uncov_part);
    }
    else
    {
        printf("%d", 0);
    }
    return 0;
}

Measured memory_bytes: 128
import sys
inp = sys.stdin.readline

N, Y = map(int,inp().split())

for i in range(N+1):
  for j in range(N+1):
    k = N-i-j
    if(k >= 0):
      if(10000*i + 5000*j + 1000*k == Y):
        print(i, j, k)
        exit()
print(-1, -1, -1)

Measured memory_bytes: 3060