akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
#include <vector>
#include <numeric>

using namespace std;

long long gcd(long long a, long long b) {
	while (a % b != 0) {
		long long t = a;
		a = b;
		b = t % b;
	}
	return b;
}

long long lcm(long long a, long long b) {
	long long g = gcd(a, b);
	return g * (a / g) * (b / g);
}

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	vector<long long> T(N);
	for (int i = 0; i < N; i++) cin >> T[i];

	long long ans = T[0];
	for (int i = 1; i < N; i++) ans = lcm(ans, T[i]);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int n;
int t,a,b;
int sum;

bool check(void)
{
	cin>>t>>a>>b;
	
	sum = a + b;
	
	if(t >= sum && (t - sum) % 2 == 0)
		return true;
	
	return false;
}

int main(void)
{
	cin>>n;
	
	while(n--)
	{
		if(!check())
		{
			cout<<"No\n";
			return 0;
		}
	}
	
	cout<<"Yes\n";
	
	return 0;
}

Measured memory_bytes: 256
//default
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

class G_info{
public:
  int to;
  int length;
  G_info(int _to,int _length):to(_to),length(_length){}
};
using Graph = vector<vector<G_info>>;

// 深さ優先探索
vector<int> color;
void dfs(const Graph &G, int v,int clr) {
    //seen[v] = true; // v を訪問済にする

    for (auto next_v : G[v]) {
//next_v.to next_v.length
        if (color[next_v.to]!=-1) continue; // next_v が探索済だったらスルー
        int next_clr;
        if(next_v.length%2==0){
          next_clr=clr;
        }
        else next_clr=1-clr;
        color[next_v.to]=next_clr;
        dfs(G, next_v.to, next_clr); // 再帰的に探索
    }
}

signed main(){
  int N;
  cin >> N;

  // グラフ
  Graph G(N+1);
  for (int i = 1; i <= N-1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back(G_info(v,w));

    // 無向グラフの場合は以下を追加
    G[v].push_back(G_info(u,w));
  }

  // 頂点 0 をスタートとした探索
  color.assign(N+1, -1); // 全頂点を「未訪問」に初期化
  color[1]=0;
  dfs(G, 1, 0);
  for (int i = 1; i <= N; ++i) {
    cout << color[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 49664
#include <algorithm>
#include <cstring>
#include <cstdio>
int lst[100005], to[200005], pre[200005], tot; 
int dp[100005], del_cnt, ans; 
bool del[100005]; 
char col[100005]; 
inline void add_edge(int u, int v)
{
	to[tot] = v; 
	pre[tot] = lst[u];
	lst[u] = tot++; 
}
void dfs(int u, int fa = -1)
{
	int son = 0; 
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (to[i] == fa)
			continue; 
		dfs(to[i], u); 
		son += !del[to[i]]; 
	}
	if (!son && col[u] == 'B')
	{
		del_cnt++; 
		del[u] = true; 
	}
}
int calc(int u, int fa = -1)
{
	int res = 0, mx = 0, cur = (col[u] == 'W') ^ (fa != -1); 
	for (int i = lst[u]; ~i; i = pre[i])
	{
		int v = to[i]; 
		if (v == fa || del[v])
			continue; 
		cur ^= 1; 
		res = std::max(res, calc(v, u)); 
		mx = std::max(mx, dp[u] + dp[v]); 
		dp[u] = std::max(dp[u], dp[v]); 
	}
	dp[u] += cur; 
	ans += cur; 
	return std::max(res, mx + cur); 
}
int main()
{
	// freopen("ARC097-F.in", "r", stdin); 
	memset(lst, -1, sizeof(lst)); 
	int n, rt = -1; 
	scanf("%d", &n); 
	for (int i = 1; i < n; i++)
	{
		int u, v; 
		scanf("%d%d", &u, &v); 
		add_edge(--u, --v); 
		add_edge(v, u); 
	}
	scanf("%s", col); 
	for (int i = 0; i < n; i++)
	{
		if (col[i] == 'W')
			rt = i; 
	}
	if (rt == -1)
	{
		puts("0"); 
		return 0; 
	}
	dfs(rt); 
	if (del_cnt == n - 1)
	{
		puts("1"); 
		return 0; 
	}
	ans = n - del_cnt - 1 << 1; 
	ans -= calc(rt) << 1; 
	printf("%d\n", ans);
	return 0; 
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	unordered_map<ll, ll> ump;
	rep(i, n){
		ll a;
		cin >> a;
		ump[a]++;
	}

	Vec cs1(n+1), cs2(n+1);
	for(P i : ump){
		cs1[i.sc]++;
	}

	repn(i, n){
		cs2[i] = i*cs1[i];
		cs1[i] += cs1[i-1];
		cs2[i] += cs2[i-1];
	}

	repn(i, n){
		ll l = 0, r = n+1;
		while(r-l > 1){
			ll mid = (l+r)/2;
			ll sum = cs2[mid]+mid*(ump.size()-cs1[mid]);
			if(sum/mid >= i) l = mid;
			else r = mid;
		}
		co(l);
	}

	return 0;
}


Measured memory_bytes: 18420
#include <stdio.h>

int main(void)
{
	int m, f, r;

	while (1)
	{
		scanf("%d%d%d", &m, &f, &r);

		if (m == -1 && f == -1 && r == -1)
		{
			break;
		}
		if ((m == -1 || f == -1) || m + f < 30)
		{
			printf("F\n");
		}
		else
		{
			if (m + f >= 80)
			{
				printf("A\n");
			}
			else
			{

				if (m + f >= 65)
				{
					printf("B\n");
				}
				else
				{
					if (m + f >= 50 || (m + f <= 30 && r >= 50))
					{
						printf("C\n");
					}
					else
					{
						printf("D\n");
					}
				}
			}
		}
	}
	return 0;

}


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

int lcs(string x,string y);

int main(){
	int n; cin>>n;
	string x,y;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		cout<<lcs(x,y)<<endl;
	}
	cin.get();cin.get();
}

int lcs(string x,string y){
	int m = x.size() , n = y.size();
	x = ' '+x; y = ' '+y;
	int **c;
	c = new int*[m+1]; for(int i=0;i<=m;i++) c[i] = new int[n+1];
	for(int i=0;i<=m;i++) c[i][0] = 0; for(int j=0;j<=n;j++) c[0][j] = 0;
	int maxl = 0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(x[i]==y[j])
				c[i][j] = c[i-1][j-1]+1;
			else
				c[i][j] = max(c[i-1][j],c[i][j-1]);
			maxl = max(maxl,c[i][j]);
		}
	}
	for(int i=0;i<=m;i++) delete [] c[i]; delete [] c;
	return maxl;
}

Measured memory_bytes: 6848
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	char	str[256];
	
	scanf("%d %d", &a, &b);
	
	if (b==1) {
		printf("0\n");
		return 0;
	}
	
	i=1;
	while(1) {
		c = (i-1)*(a-1) + a;
		if (c>=b) break;
		i++;
	}

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


	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;

int swap(int &a,int &b){
	int c;
	c=a;
	a=b;
	b=c;

	return 0;
}



int main(){
	while(1){
		int x,y;
		cin>>x>>y;
		if(x==0&&y==0)
			break;
		if(x>y){
			cout<<y<<" "<<x<<endl;
		}else{
			cout<<x<<" "<<y<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,v[10001000],f[10001000],cnt,jj;
long long g[10001000];
vector<int> primes;
void linear(int N){
	memset(v,0,sizeof(v));
	primes.clear();
	for(int i=2;i<=N;i++){
		if(v[i]==0){v[i]=i;primes.push_back(i);}
		for(int j=0;j<primes.size();j++){
			if(primes[j]>v[i]||primes[j]>(N/i)) break;
			v[i*primes[j]]=primes[j];
		}
	}
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	linear(10000000);
	f[1]=1;
	for(int i=2;i<=10000000;i++){
		cnt=0;jj=i;
		while(jj%v[i]==0){jj/=v[i];cnt++;}
		f[i]=(f[i/v[i]]/cnt)*(cnt+1);
	}
	for(int i=1;i<=10000000;i++){
		g[i]=g[i-1];
		g[i]+=(long long)(i)*(long long)(f[i]);
	}
	int n;cin>>n;
	cout<<g[n]<<endl;
	return 0;
}


Measured memory_bytes: 162280
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
bool ispalin(string s,int l,int r)
{
    for(int i=l;i<=r;i++)
    {
        if(s[i]!=s[r-i])
            return false;
    }
    return true;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
    int n,m,i,x,y,z;
    cin>>n;
    double side=(1.0*n)/(1.0*3);
    double ans=side*side*side;
    cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
typedef pair<ll,ll> A;
vector<A> pc;
//int ABS(int a){return max(a,-a);}
//int a[100001];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        pc.push_back(A(a,b));
    }
    sort(pc.begin(),pc.end());
    ll ans=0,cnt=0;
    for(int i=0;i<n;i++){
        ll p,q;
        p=pc[i].first;
        q=pc[i].second;
        if((cnt+q)<=m) {
            ans+=p*q;
            cnt+=q;
        }
        else {
          ans+=p*(m-cnt);
          break;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2420
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            int val1 =0;
            int val2=1;
            char[][] grid = new char[h][w];
            for (int i = 0; i <h; i++){
                String s = in.next();
                for (int j = 0; j <s.length(); j++){
                    grid[i][j]=s.charAt(j);
                    if (grid[i][j]=='#')val1++;
                }
            }
            boolean ans = true;
            int i=0,j=0;
            while (i!=h-1||j!=w-1){
                    if (j+1<w && i+1<h && grid[i+1][j]=='#' && grid[i][j+1]=='#'){ans=false;break;}
                    else if (i+1<h && grid[i+1][j]=='#'){i++;val2++;}
                    else if (j+1<w && grid[i][j+1]=='#'){j++;val2++;}
                    else {ans=false;break;}
            }
            if (ans && val1==val2) System.out.println("Possible");
            else System.out.println("Impossible");
            }
        }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt(){return  Integer.parseInt(next());}
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 32980
#include <bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;

int main(){
    Fast;
    int n;
    cin>>n;
    if(360%n==0){
        cout<<360/n<<endl;
        return 0;
    }
    int cnt=0;
    int m=360;
    while(1){
        if(m%n==0){
            cnt=m/n;
            break;
        }
        else{
            m+=360;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
using namespace std;
//バブルソート　in:配列、要素数 out:ソート回数
int bubble_sort(int *A,int N){
    int sw=0;
    int i,j;
    bool flag=1;

    for(i=0;flag;i++){
        flag=0;
        for(j=N-1;j>=i+1;j--){                             
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                flag=1;
                sw++;
            }                
        }
    }
    return sw;
}

int main(void){
    int A[100],i,j,N,sw;

    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d",&A[i]);

    sw=bubble_sort(A,N);

    for(i=0;i<N;i++){
        if(i)
            putchar(' ');
        printf("%d",A[i]);
    }
    putchar('\n');
    printf("%d\n",sw);

    return 0;
}


Measured memory_bytes: 3228
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const int inf=0x3f3f3f3f;
int g[2],f[2],a[3];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read(),uf=0,ans=0;
	for(int i=1;i<=n+1;i++)
	{
		int d=0;if(i<=n)d=read();
		g[0]=d-uf,g[1]=0;if(g[0]<g[1])swap(g[0],g[1]);
		a[0]=a[1]=inf;a[2]=0;
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)a[i+j]=min(a[i+j],max(f[i]+g[j],0));
		}
		int pd=0;if(a[0]>d)pd=1;
		for(int i=0;i<2;i++)f[i]=a[i+pd];
		uf=d;ans+=pd;
	}pr2(ans);
	return 0;
}

Measured memory_bytes: 128
//
//  main.c
//  Monday-Saturday Prime Factors
//
//  Created by x15071xx on 2016/06/19.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//

#include <stdio.h>
#include <math.h>
int monsat (int a);
int monsatprime (int a);

int main(int argc, const char * argv[]) {
    
    
    while (1) {
        
        int b,i;
        
        scanf("%d",&b);
        
        if (b==1) {
            break;
        }
        
        printf("%d:",b);
        
        for (i=2; i<=b; i++) {
            if (monsat(i)) {
                if (b%i == 0) {
                    if (monsatprime(i)) {
                        printf(" %d",i);
                    }
                }
                
            }
            
        }
        
        printf("\n");
        
    }
    
    
    return 0;
}


int monsat (int a) {
    
    int x = a % 7;
    
    if (x == 1 || x == 6) {
        x = 1;
        return x;
    }
    
    x = 0;
    
    return 0;
}


int monsatprime (int a) {
    
    int i, x=1;
    
    for (i=2; i<a; i++) {
        if (monsat(i)) {
            if (a%i == 0) {
                x = 0;
                return x;
            }
        }
    }
    
    return x;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  map<int, int> m;
  bool yes = true;
  FOR(i,0,N) {
    int A;
    cin >> A;
    m[A]++;
    if (m[A] > 1) {
      yes = false;
    }
  }
  cout << (yes ? "YES" : "NO") << endl;
}


Measured memory_bytes: 9600
s=input()
t=input()
dp=[[0]*(len(t)+1) for i in range(len(s)+1)]
for i in range(1,len(dp)):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
out=''
i=len(s)
j=len(t)
while i!=0 and j!=0:
    if s[i-1]==t[j-1]:
        out+=s[i-1]
        i-=1
        j-=1
    elif dp[i][j-1]>dp[i-1][j]:
        j-=1
    else:
        i-=1
print(out[::-1])


Measured memory_bytes: 112220
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

a,b,c = readInts()

if a*b*c%2==0:
  print(0)
  exit()

x = min(a,b,c)
y = (a+b+c)-x-max(a,b,c)
print(x*y)

Measured memory_bytes: 9404
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	int cost[n];
	int h[n];
	cost[0]=0;
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	cost[1]=abs(h[1]-h[0]);
	for(i=2;i<n;i++)
	{
		cost[i]=min((cost[i-1]+abs(h[i]-h[i-1])),(cost[i-2]+abs(h[i]-h[i-2])));
	}
	cout<<cost[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    string s,t;
    ll i,j,c=0;
    cin>>s>>t;
    ll n=s.length();
    for(i=0;i<n;i++)
    {
        if(s[i]==t[i])
        {
            c++;
        }
    }
    cout<<c<<endl;
    return 0;
}


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

s = [0 for i in range(n)]
for i in range(n):
    s[i] = input()
    s[i] = "".join(sorted(s[i]))

s.sort()

i = 0
j = 0
ans = 0
while i < n:
    while j < n and s[i] == s[j]:
        j += 1
    ans += (j-i) * (j-i-1) // 2
    i = j

print(ans)







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


int main(){
  int64_t N,M,x=0;
  cin >> N >> M;
  vector<pair<int64_t,int64_t>> A(M);
  vector<vector<int64_t>> B(N, vector<int64_t>(0));
  deque<int64_t> C;
  vector<int64_t> D(N,0);
    
  for(int64_t i=0;i<M;i++){
    cin >> A.at(i).first >> A.at(i).second;
    A.at(i).first--;
    A.at(i).second--;
    B.at(A.at(i).first).push_back(A.at(i).second);
    B.at(A.at(i).second).push_back(A.at(i).first);
  }
  C.push_back(0);
  D.at(0)=1;
  while(x==0){
    for(int64_t i=0;i<B.at(C.front()).size();i++){
      if(D.at(B.at(C.front()).at(i))==0){
        D.at(B.at(C.front()).at(i))=1;
        C.push_front(B.at(C.front()).at(i));
        break;
      }
      if(i==B.at(C.front()).size()-1){
        x=1;
      }
    }
  }
  x=0;
  while(x==0){
    for(int64_t i=0;i<B.at(C.back()).size();i++){
      if(D.at(B.at(C.back()).at(i))==0){
        D.at(B.at(C.back()).at(i))=1;
        C.push_back(B.at(C.back()).at(i));
        break;
      }
      if(i==B.at(C.back()).size()-1){
        x=1;
      }
    }
  }
  cout << C.size() << endl;
  for(int64_t i=0;i<C.size();i++){
    cout << C.at(i)+1 << " ";
  }
  cout << endl;
}

Measured memory_bytes: 9472
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int maxn = 1e5 + 7;

char s[maxn];
deque<char>dq;

int main() {
    while(~scanf("%s",s)) {
        while(!dq.empty()) dq.pop_back();
        for(int i = 0 ; s[i] ; i++) dq.push_back(s[i]);
        bool flag = false; ///����Ƿ�ת
        int Q;
        scanf("%d",&Q);
        while(Q--) {
            int opt;
            scanf("%d",&opt);
            if(opt == 1) {
                flag ^= 1;
            } else {
                char ch;
                scanf("%d %c",&opt,&ch);
//                printf("opt = %d ch = %c ",opt,ch);
//                cout << "flag = " << flag << endl;
                if(flag) {
                    if(opt == 1) dq.push_back(ch);
                    else dq.push_front(ch);
                } else {
                    if(opt == 2) dq.push_back(ch);
                    else dq.push_front(ch);
                }
            }
        }
//        cout << "flag = " << flag << endl;
        if(flag) {
            while(!dq.empty()) {
                printf("%c",dq.back());
                dq.pop_back();
            }
            printf("\n");
        } else {
            while(!dq.empty()) {
                printf("%c",dq.front());
                dq.pop_front();
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int a = x.nextInt();
		String op = x.next();
		int b = x.nextInt();
		while(!op.equals("?")){
		if(op.equals("+")){
			System.out.println(a+b);
		}else if (op.equals("-")){
			System.out.println(a-b);
		}else if (op.equals("*")){
			System.out.println(a*b);
		}else if (op.equals("/")){
			System.out.println(a/b);
		}
		a = x.nextInt();
		op = x.next();
		b = x.nextInt();
		}
	}

}

Measured memory_bytes: 18024
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

typedef string::const_iterator State;

void assume(State &begin, char expected) {
    // cerr << "assume: " << *begin << " " << expected << endl;
    assert(*begin == expected);
    begin++;
}

int term(State&, vi);
int formula(State&, vi);

int term(State &begin, vi v) {
    // cerr << "term: " << *begin << endl;
    int ret = formula(begin, v);

    if (*begin == '*') {
        begin++;
        ret = min(ret, formula(begin, v));
    } else {
        assume(begin, '+');
        ret = max(ret, formula(begin, v));
    }

    return ret;
}

int formula(State &begin, vi v) {
    // cerr << "formula: " << *begin << endl;
    int ret;

    if (isdigit(*begin)) {
        ret = *begin - '0';
        begin++;
    } else if (isalpha(*begin)) {
        ret = v[*begin - 'P'];
        begin++;
    } else if (*begin == '-') {
        begin++;
        ret = 2 - formula(begin, v);
    } else {
        assume(begin, '(');
        ret = term(begin, v);
        assume(begin, ')');
    }

    return ret;
}

int solve(string s) {
    int ret = 0;
    rep(i, 27) {
        // cerr << "i = " << i << ":" << endl;
        State begin = s.begin();
        vi v({i % 3, (i / 3) % 3, i / 9});
        if (formula(begin, v) == 2) {
            ret++;
        }
    }
    return ret;
}

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

    string s;
    int t = 0;
    while (cin >> s, s[0] - '.') {
        // cerr << "--- t = " << t++ << " ---"<< endl;
        cout << solve(s) << endl;
    }
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int x = max({a, b, c});
    int ans = 2;
    if(x == a) ans = 0;
    else if(x == b) ans = 1;
    cout << "ABC"[ans] << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define lint long long
using namespace std;


int main(){
  
  lint A,B,C,K;
  cin >> A >> B >> C >> K;
  
  if(K<=A) cout << K << endl;
  else if(K<=A+B) cout << A << endl;
  else cout << A-(K-A-B) << endl;
}

Measured memory_bytes: 3624
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
N = int(input())
K = int(input())
L = len(str(N))
S = str(N)
if K>L:
  print(0)
  import sys
  sys.exit()
if K==1:
  s = ['0']*L
  cnt = 0
  for i in range(L):
    for j in range(1,10):
      s[i] = str(j)
      x = ''.join(s)
      x = int(x)
      if x<=N:
        cnt += 1
      s[i] = '0'
elif K==2:
  s = ['0']*L
  cnt = 0
  for i in range(L-1):
    for j in range(i+1,L):
      for a in range(1,10):
        for b in range(1,10):
          s[i] = str(a)
          s[j] = str(b)
          x = ''.join(s)
          x = int(x)
          if x<=N:
            cnt += 1
          s[i] = '0'
          s[j] = '0'
else:
  s = ['0']*L
  cnt = 0
  cnt += cmb(L-1,3)*(9**3) if L>3 else 0
  g = int(S[0])
  s[0] = S[0]
  for i in range(1,L-1):
    for j in range(i+1,L):
      for a in range(1,10):
        for b in range(1,10):
          s[j] = str(a)
          s[i] = str(b)
          x = ''.join(s)
          x = int(x)
#          print(x)
          if x<=N:
            cnt += g
          else:
            cnt += g-1
          s[i] = '0'
          s[j] = '0'
print(cnt)

Measured memory_bytes: 44016
#include <bits/stdc++.h>
using namespace std;
#include <string.h>
#include <map>
#define MEM(var, val) memset(var, (val), sizeof(var))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define nitro                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
//*max_element(a.begin(), a.end())
vector<vll>adj;
vll vis;
vll d;
void dfs(int v)
{
    if(vis[v])
    return ;
    vis[v]=1;
    for(int i:adj[v])
    {
        if(!vis[i])
        dfs(i);
        d[v]=MAX(d[v],1+d[i]);
    }
}
int main()
{
    ll n,m;
    cin>>n>>m;
    adj.clear();
    adj.resize(n+1);
    vis.clear();
    vis.resize(n+1,0);
    d.clear();
    d.resize(n+1,0);
    for(int i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
        
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        dfs(i);
    }
    cout<<*max_element(d.begin(),d.end());

}

Measured memory_bytes: 12168
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)
		r=(r*a)%m;
		b=b/2;
		a=(a*a)%m;
	}
	return r%m;
}


bool comp(pair<ll,ll>a , pair<ll,ll>b)
{
   
    return a.second>b.second;
}

int main(){
   ll a,b; cin>>a>>b;
   ll sum = 1;
   ll ans = 0;
   while(sum<b)
   {
       sum--;
       sum+=a;
       ans++;
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
// Reconstruction of tree by pre-order and in-order
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
void reconstruction(int, int);
int n;
std::vector<int> in,post;
std::queue<int> pre;
int main(){
  std::cin>>n;
  for(int i=0, tmp;i<n;i++) std::cin>>tmp, pre.push(tmp);
  for(int i=0, tmp;i<n;i++) std::cin>>tmp, in.push_back(tmp);
  reconstruction(0, n);
  for(int i=0;i<n;i++){
    if(i) std::cout<<" ";
    std::cout<<post[i];
  }
  std::cout<<std::endl;
  return 0;
}
void reconstruction(int l, int r){
  if(l >= r) return;
  int c;
  c=pre.front(), pre.pop();
  int m=distance(in.begin(), find(in.begin(), in.end(),c));
  reconstruction(l, m), reconstruction(m+1, r);
  post.push_back(c);
}

Measured memory_bytes: 3160
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        int[] c = new int[m];
        boolean[] u = new boolean[n];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            for (int j = 0; j < b[i]; j++) {
                int t = sc.nextInt()-1;
                c[i] = c[i] | (1 << t);
                u[t] = true;
            }
        }
        boolean able = true;
        for (int i = 0; i < n; i++) {
            if(!u[i]) {
                able = false;
                break;
            }
        }
        if(able){
            int max = 1 << n;
            int[] dp = new int[max];
            Arrays.fill(dp, Integer.MAX_VALUE);
            dp[0] = 0;
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < max; j++) {
                    if((j & c[i]) == c[i] || dp[j] == Integer.MAX_VALUE)
                        continue;
                    int next = j | c[i];
                    if(dp[j] + a[i] < dp[next]) dp[next] = dp[j] + a[i];
                }
            }
            System.out.println(dp[max-1]);
        }else{
            System.out.println(-1);
        }
        sc.close();

    }

}


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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP(i, n) {cin >> a[i]; --a[i];}

    int ans = 0;
    REP(i, n)
        if(a[a[i]] == i && a[i] > i) ++ans;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    INT x;
    cin >> x;
    for(INT i=1;i<=4000;i++){
        INT a = i*i*i*i*i;
        for(INT j=-4000;j<=4000;j++){
            INT b = j*j*j*j*j;
            if(a-b==x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
	return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int main()
{
  string s;
  cin>>s;
  FOR(i,0,s.length())if(s[i]==',')s[i]=' ';
  cout<<s<<endl;
  return 0;
}

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

using namespace std;

int x[1005], sum[1005];
vector<int> g[1005];

bool solve(int cur) {
	sum[cur] += x[cur];
	if (g[cur].empty()) return true;
	int mins = 0;
	vector<int> dp(x[cur] + 1, false);
	dp[0] = true;
	for (int nex : g[cur]) {
		if (!solve(nex)) return false;
		int minv = min(x[nex], sum[nex] - x[nex]);
		int dis = max(x[nex], sum[nex] - x[nex]) - minv;
		mins += minv;
		for (int i = x[cur]; i >= dis; i--) {
			dp[i] |= dp[i - dis];
		}
		sum[cur] += sum[nex];
	}
	for (int i = x[cur] - mins; i >= 0; i--) {
		if (dp[i]) {
			sum[cur] -= mins + i;
			return true;
		}
	}
	return false;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int p;
		cin >> p;
		p--;
		g[p].push_back(i);
	}

	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	cout << (solve(0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

//最大値を求める。
int max(int x,int y){
    if(x > y) return x;
    return y;
}
//最小値を求める
int min(int x,int y){
    if(x > y)return x;
    return y;
}

//各桁の和を求める。
int wa(int a){
    int sum;
    int dig;
    for(;;){
        dig = a % 10;
        sum += dig;
        a = a / 10;
        if(a == 0) break;
    }
    return sum;
}

//バブルソート（降べきの順）
void bsort(int a[],int b[],int n){
    int i,j,tmp2;
    for(i = 0;i < n-1;i++){
        for(j = 0;j<n-1;j++){
            if(a[b[j]]>a[b[j+1]]){
                tmp2 = b[j];
                b[j] = b[j+1];
                b[j+1] = tmp2;
            }
        }
    }
}

//最大公約数を求める
int gcd(int x,int y){
    int c;
    for(;;){
        c = x % y;
        if(c == 0)return y;
        x = y;
        y = c;
    }
}

int main(void){
    int n,tim;
    int count=10000;
    scanf("%d %d",&n,&tim);
    int c[n],t[n],b[n];
    int i;
    for(i =0;i<n;i++){
        scanf("%d %d",&c[i],&t[i]);
        b[i] = i;
    }

    bsort(c,b,n);

    for(i=0;i<n;i++){   
        if(t[b[i]]<=tim){
            count = c[b[i]];
            break;
        }
    }

    if(count == 10000)printf("TLE\n");
    else printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll cac(ll a){
    return a*a*a*a*a;
}
int main(){
    ll x;
    ll a,b;
    cin>>x;
    //cout<<cac(120)-cac(119)<<endl;
    for(int i=-300;i<=300;i++){
        for(int j=-300;j<=300;j++){
            if(cac(i)-cac(j)==x){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    return 0;
}

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 200000000000000;
constexpr auto MOD = 1000000007;


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;


	rep(i, s.size()) {
		int ab=0;
		rep(k, 26) {
			if (s[i] == 'A' + k)ab = k;
		}

		if (ab + n < 26) s[i] = (char)s[i] + n;
		else s[i] = (char)s[i] + n - 26;
	}


	cout << s << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if (a >= k) {
        ans = k;
    }
    else if (a + b >= k) {
        ans = a;
    }
    else if (a + b + c >= k) {
        ans = a - (k - a - b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544
#include <stdio.h>
#include <string.h>

int main(void) {
  char str[3];
  scanf("%s", str);
  if(strcmp(str, "ABC") == 0) {
    printf("ARC\n");
  } else if(strcmp(str, "ARC") == 0) {
    printf("ABC\n");
  } else {
    return 1;
  }
  return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>

int usercode(char letter) {
        return (letter-'a');
}


int main(void) {
        char stra[101];
        char strb[101];
        char strc[101];
        char* str[3] = {stra,strb,strc};
        //init str
        for (int i=0;i<101;i++) {
                stra[i] = 0;
                strb[i] = 0;
                strc[i] = 0;
        }
        //read
        scanf("%101s",stra);
        scanf("%101s",strb);
        scanf("%101s",strc);
        //count cards
        int num[3];
        for (int i=0;i<3;i++) {
                num[i] = 0;
                for (int j=0;j<100;j++) {
                        if (str[i][j]) num[i]++;
                }
        }
        //let the game commence
        int indexr[3];
        for (int i=0;i<3;i++) indexr[i]=0;
        int user = usercode('a');
        while(1) {
                if (indexr[user] == num[user]) break;
                indexr[user]++;
                user = usercode(str[user][indexr[user]-1]);
        }
        printf("%c\n", user+'A');

        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	vector<string> seven = {
		"aabbcc.",
		"ddee..l",
		"ffgg..l",
		"....hjm",
		"....hjm",
		"....ikn",
		"....ikn"
	};
	vector<string> four = {
		"aaef",
		"ccef",
		"bdgg",
		"bdhh"
	};
	vector<string> five = {
		"ag..h",
		"ag..h",
		"biijj",
		"b.ffe",
		"ccdde" 
	};

	int n;
	cin >> n;

	vector<string> ans(n, string(n, '.'));

	if(n == 2){
		cout << -1 << endl;
	} else {
		if(n % 3 == 0){
			rep(i,0,n/3){
				rep(t,0,2) ans[i*3 + t][i * 3] = 'a';
				rep(t,0,2) ans[i*3 + 2][i * 3 + t + 1] = 'a';
			}
		} else {
			vi pek(n+10);
			pek[0] = 1;
			rep(i,0,n) if(pek[i]){
				vi v = {4,5,7};
				trav(x,v) pek[i+x] = x;
			}
			while(n){
				int x = pek[n];
				n -= x;
				auto ls = x==4 ? four : x == 5 ? five : seven;
				rep(i,0,sz(ls)) rep(j,0,sz(ls)) ans[n+i][n+j] = ls[i][j];
			}
		}
		trav(s, ans) cout << s << endl;
	}
}


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

int main() {
  int N,i,ans;
  cin>>N;
  std::vector<int> q(11);
  q[0]=9;
  q[5]=6;
  int ww;
  ans=12345678;
  for(int i=1;i<5;i++)q[i]=q[i-1]*9;
  for(int i=6;i<11;i++)q[i]=q[i-1]*6;
  for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
      for(int k=0;k<6;k++){
        for(int l=0;l<6;l++){
          for(int m=0;m<6;m++){
            for(int n=0;n<3;n++){
              for(int o=0;o<9;o++){
                for(int p=0;p<9;p++){
                  for(int r=0;r<9;r++){
                    for(int s=0;s<2;s++){
                      for(int t=0;t<9;t++){
                        ww=N-(q[5]*i+q[6]*j+q[7]*k+q[8]*l+q[9]*m+q[10]*n+q[1]*o+q[2]*p+q[3]*r+q[4]*s+q[0]*t);
                        if(ww>=0&&ww<6)ans=min(ww+i+j+k+l+m+n+o+p+r+s+t,ans);
                        }}}}}}}}}}}
                        cout<<ans<<endl;
                      }


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
l = [-1] + list(map(int,input().split()))

dp = [-1]+[0]*n

for i in range(n,0,-1):
    j = 1
    isum = 0
    while j*i <= n:
        isum += dp[j*i]
        j += 1
    if isum%2 != l[i]%2:
        dp[i] =  1

ans = [i for i in range(1,n+1) if dp[i]==1]
print(len(ans))
if len(ans) != 0:
    print(*ans)

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

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        cout << 'x';
    }
    return 0;
}

Measured memory_bytes: 256
private class A {
    fun solve() {
        val s = nextToken()
        var ans = 0
        var cur = 0
        for (c in s) {
            if (c == 'R') cur++
            else cur = 0
            ans = Math.max(ans, cur)
        }
        println(ans)
    }

    var tokenBuffer = listOf<String>()
    var bufferPosition = 0

    private fun checkBuffer() {
        if (bufferPosition == tokenBuffer.size) {
            tokenBuffer = nextLine().split(" ")
            bufferPosition = 0
        }
    }

    fun nextLine() = readLine()!!
    fun nextInt(): Int {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toInt()
    }

    fun nextLong(): Long {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toLong()
    }

    fun nextDouble(): Double {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toDouble()
    }

    fun nextToken(): String {
        checkBuffer()
        return tokenBuffer[bufferPosition++]
    }
}

fun main() {
    val reader = A().solve()

}


Measured memory_bytes: 36508
#include <stdio.h>
int main ()
{
    int n , d , nm , fd;
    scanf("%d %d" , &n , &d);
    nm = (d * 2) + 1;
    fd = n / nm;
    if (n % nm != 0) {
        printf ("%d" , fd+1);
    }
    else {
     printf ("%d" , fd);
    }
    return 0;
}


Measured memory_bytes: 128
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
//const n = +input[0];
//const a = [];
//for(let i=0;i<n;i++){
//	a.push(input[i+1].split(" ").map((x:string):number=>+x));
//}

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);

function compareFunc(a, b){
    return a-b;
}

const [n,m]: number[] = input[0].split(' ').map((x: string): number => +x);
const ps = [];
for(let i=0;i<m;i++){
	ps.push(input[i+1].split(" "));
}

let AC: number = 0;
let WA: number = 0;
let li: number[] = new Array(n+1);
for(let i = 0; i<n+1; i++){
    li[i] = 0;
}


for(let i = 0; i < m; i++){
    const id = parseInt(ps[i][0]);
    if ( li[id] === -1 ){ continue; }
    if ( ps[i][1] ==='WA'){
        li[id] += 1;
    }else if( ps[i][1] ==='AC'){
        AC++;
        WA += li[id] || 0;
        li[id] = -1;
    }
}
console.log(AC, WA);


Measured memory_bytes: 51128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N, vector<int>(N,INF));
    map<pair<int, int>, int> dic;
    rep(i,N) G[i][i] = 0;
    rep(i,M) {
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        G[a][b] = G[b][a] = c;
        dic.emplace(minmax(a,b),c);
    }

    rep(k,N) {
        rep(i,N) {
            if (G[i][k] == INF) continue;
            rep(j,N) {
                if (G[k][j] == INF) continue;
                chmin(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    
    int ans = 0;
    for (auto i : dic) {
        int u,v;
        tie(u,v) = i.first;
        if (G[u][v] < i.second) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
import Control.Applicative

myShow :: Int -> Int -> IO ()
myShow count5 count7 | count5 == 2 && count7 == 1 = putStrLn "YES"
                     | otherwise = putStrLn "NO"

main :: IO ()
main = do
    lst <- map read . words <$> getLine
    let count5 = sum $ [1 | x <- lst, x == 5]
        count7 = sum $ [1 | x <- lst, x == 7]
    myShow count5 count7


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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18;
const int INF = 1e9;
const double EPS = 0.000000001;

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

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  puts(!(s.size() & 1) ^ (s[0] == s[s.size() - 1]) ? "Second" : "First");
  return 0;
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  int result = 0;
  if (S == "SUN") result = 7;
  else if (S == "MON") result = 6;
  else if (S == "TUE") result = 5;
  else if (S == "WED") result = 4;
  else if (S == "THU") result = 3;
  else if (S == "FRI") result = 2;
  else if (S == "SAT") result = 1;
  cout << result << endl;
  return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	ll n,m;
	ll res = 0;
	scanf("%lld", &n);
	scanf("%lld", &m);
	static ll h[100001] = {0};
	FOR(i, 1, n) {
		scanf("%lld", &h[i]);
	}
	static int isbad[100001] = {0};
	FOR(i, 1, m) {
		ll a,b;
		scanf("%lld", &a);
		scanf("%lld", &b);
		if (h[a] == h[b]) {
			isbad[a] = 1;
			isbad[b] = 1;
		}
		if (h[a] > h[b]) {
			isbad[b] = 1;
		}
		if (h[a] < h[b]) {
			isbad[a] = 1;
		}
	}
	FOR(i, 1, n) {
		if (isbad[i] == 0) {
			res++;
		}
	}
	printf("%lld\n", res);
	return(0);
}

Measured memory_bytes: 4392