akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
 
int puzzle[3][3];
int temp[3][3];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
void empty(int *,int *);
int dfs(int,int,int,int,const int);
int cal();
void swap(int *,int *);
 
int main() {
  int i,j,ans,x,y,l;
  for(i=0;i<3;i++) {
    for(j=0;j<3;j++) scanf("%d",&puzzle[i][j]);
  }
     
  empty(&x,&y);
  for(l=0;l<100;l++) {
       
    for(i=0;i<3;i++) {
      for(j=0;j<3;j++) temp[i][j]=puzzle[i][j];
    }
    ans = dfs(x,y,-1,0,l);
    if(ans!=-1) {
      printf("%d\n",ans);
      break;
    }
 
    for(i=0;i<3;i++) {
      for(j=0;j<3;j++) puzzle[i][j] = temp[i][j];
    }
    ans = -1;
    if(l==99) printf("%d\n",ans);
  }    
  return 0;
}
 
 
void empty(int *x,int *y) {
  int i,j;
  for(i=0;i<3;i++) {
    for(j=0;j<3;j++) {
      if(!puzzle[i][j]) {
	*x = j;
	*y = i;
	return;
      }
    }
  }
}
 
 
void swap(int *a,int *b) {
  int temp;
     
  temp=*a;
  *a=*b;
  *b=temp;
}
 
 
int cal(){
  int i,a,sum=0;
     
  for(i=0;i<9;i++) {
    a=puzzle[i/3][i%3];
    if(a) {
      a--;
      sum+=abs(i/3-a/3)+abs(i%3-a%3);
    }
  }
     
  return sum;
}
 
 
int dfs(int x,int y,int p,int dep,const int lim) {
  int i,h,nx,ny,res;
     
  h = cal();
  if(h==0) return dep;
  if(dep+h>lim) return -1;
     
  for(i=0;i<4;i++) {
    nx=x+dx[i];
    ny=y+dy[i];
         
    if(~p&&i==(p+2)%4) continue;
    if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;
         
    swap(&puzzle[y][x],&puzzle[ny][nx]);
    res = dfs(nx,ny,i,dep+1,lim);
    if(~res) return res;
         
    swap(&puzzle[y][x],&puzzle[ny][nx]);
  }
     
  return -1;
}



Measured memory_bytes: 2056
#include <iostream>
#include <array>
using namespace std;
const int maxn = 1e5+6;
array<int,maxn>arr;
array<int,maxn>vis;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i = 1;i<=n;++i) {
        cin >> arr[i];
    }
    int current_button = 1;
    int tot = 0;
    while(current_button != 2 && !vis[current_button]) {
        vis[current_button] = true;
        current_button = arr[current_button];
        ++tot;
    }
    if(current_button == 2) {
        cout<<tot<<endl;
    }
    else {
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 1024
#include<stdio.h>

int main (void)
{
	char n[4];
	int i;
	scanf("%s",n);
	for(i=0;i<3;i++){
		if(n[i]=='9'){
			n[i]='1';
		}else if(n[i]=='1'){
			n[i]='9';
		}
	}
	printf("%s\n",n);
}

Measured memory_bytes: 128
def solve():
    ans = []
    for i, (x, y) in enumerate(s):
        if num[x]>num[y]: x, y = y, x
        if num[x]==num[y] and i < n-1:
            if y == s[i+1][0] or y == s[i+1][1]:
                x, y = y, x
        num[x]+=1
        num[y]-=1
        ans.append(x)
        if num[y]<0: return False
    return ans
from collections import defaultdict
n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]
num = defaultdict(int)
num['A'] = a
num['B'] = b
num['C'] = c
ans = solve()
if ans:
    print('Yes')
    print(*ans, sep = '\n')
else:
    print('No')

Measured memory_bytes: 95984
#include<stdio.h>

int main(void)
{
   int i, a[2]={0};
   char s[5];

   scanf("%s",s);
   if(((s[0]=='0')&&(s[1]!='0'))||((s[0]=='1')&&(s[1]<'3')))
      a[0]=1;
   if(((s[2]=='0')&&(s[3]!='0'))||((s[2]=='1')&&(s[3]<'3')))
      a[1]=1;
   if((a[0]==1)&&(a[1]==1))
      printf("AMBIGUOUS\n");
   else if(a[0]==1)
      printf("MMYY\n");
   else if(a[1]==1)
      printf("YYMM\n");
   else
      printf("NA\n");
   return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {

    val s = readLine()!!
    val s2 = s.substring(0, s.length/2)
    val s3 = s.reversed().substring(0, s.length/2)
    var cnt = 0

    for(i in 0 until s.length/2) {
        if(s2[i] != s3[i]) {
            cnt++
        }
    }
    println(cnt)
}

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

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,0,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define d(a) if(isDebugMode) cout<<#a<<"="<<a<<"."
#define d2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<"."
#define d3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"."
#define d4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d<<"."
#define da(arr,N){if(isDebugMode){rep(i,N){if(arr[i]==INF)printf("INF ");else cout<<arr[i]<<" ";} cout<<endl;}}
#define da2(arr,N,M){if(isDebugMode)rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");else printf(" %3d",arr[i][j]);}cout<<endl;}}
#define pb push_back
#define pob pop_back

auto chmax =[](int &a,int b){ a = max(a, b);};
auto chmin =[](int &a,int b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = { 0, 1, 0,-1};
const int dy[4] = { 1, 0,-1, 0};

bool isDebugMode=1;
//--------------------------------------//
int N,X;
int x[100001];

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

void solve(){
	sort(x,x+N+1);
	int ans=x[1]-x[0];
	rep(i,N){
		ans=gcd(ans,x[i+1]-x[i]);
	}
	cout<<ans<<endl;
}

int main(){
	cin>>N>>X;
	rep(i,N) {
		cin>>x[i];
	}
	x[N]=X;
	solve();
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
main(){
	double x[2][3],n,ans[2],tmp;
	while(cin>>x[0][0]>>x[0][1]>>x[0][2]>>x[1][0]>>x[1][1]>>x[1][2]){
		for(int i=0;i<=1;++i){
				ans[i]=0;
		}
		n=x[0][0]*x[1][1]-x[0][1]*x[1][0];
		for(int i=0;i<=1;++i){
			for(int j=0;j<=1;++j){
				x[i][j]/=n;
			}
		}
		double tmp;
		tmp=x[1][1];
		x[1][1]=x[0][0];
		x[0][0]=tmp;
		x[0][1]*=-1;
		x[1][0]*=-1;

		for(int i=0;i<=1;++i){
			for(int j=0;j<=1;++j){
				ans[i]+=x[i][j]*x[j][2];
			}
		}
		cout<<fixed<<setprecision(3)<<ans[0]<<" "<<ans[1]<<endl;
	}
}

Measured memory_bytes: 1280
a = [input().split() for l in range(3)]

n=int(input())
b = [(input()) for i in range(n)]
s=[]
for i in range(n):
  for j in range(3):
    if b[i] in a[j]:
      k=a[j].index(b[i])
      s.append([j,k])
      if [j,0] in s and [j,1] in s and [j,2] in s:
        print("Yes")
        break
      elif [0,k] in s and [1,k] in s and [2,k] in s:
        print("Yes")
        break
      elif j==k:
        if [0,0] in s and [1,1] in s and [2,2] in s:
          print("Yes")
          break
        elif [0,2] in s and [1,1] in s and [2,0] in s:
          print("Yes")
          break
  else:
    continue
  break
else:
  print("No")
    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef double db;
const int N = 10005, mod = 1000000007;
int n, m, k, a[N];
ll f[N], ans;
// struct arr { int x; };
ll mypow(ll x, int y) {
	ll z = 1;
	while (y) {
		if (y & 1) (z *= x) %= mod;
		y >>= 1; (x *= x) %= mod;
	}
	return z;
}
int main()
{
	scanf ("%d%d", &n, &k);
	for (int i = 1; i * i <= n; i ++) {
		if (n % i == 0) {
			a[++ m] = i;
			if (i * i != n) {
				a[++ m] = n / i;
			}
		}
	}
	sort(a + 1, a + m + 1);
	Rep(i, 1, m) {
		int x = a[i];
		f[i] = mypow(k, (x + 1) / 2);
		Rep(j, 1, i - 1) if (x % a[j] == 0) f[i] = (f[i] - f[j] + mod) % mod;
		// cout << f[i]<<endl;
		if (x & 1) ans += f[i] * x;
		else ans += f[i] * x / 2;
	}
	printf("%lld\n", ans % mod);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    string S;
    cin >> S;
    int N = sz(S);
    int sum = 0;
    rep(i, N) sum += (S[i]-'0');
    cout << (sum%9 == 0? "Yes" : "No") << endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
ll ans[55],c[55],d[55],f[55][10005];
struct E{ll to,a,b;};
struct P{ll t,pos,s;};
bool operator <(const P &a,const P &b){return a.t>b.t;}
vector<E> edge[55];
priority_queue<P> q;
int main(){
    ll n,m,k,sum=0;
    cin>>n>>m>>k;
    for(ll i=1;i<=m;i++){
        ll u,v,x,y;
        cin>>u>>v>>x>>y;
        edge[u].push_back({v,x,y});
        edge[v].push_back({u,x,y});
    }
    for(ll i=1;i<=n;i++){
        cin>>c[i]>>d[i];
        c[i]=min(c[i],(ll)5000);
    }
    k=min(k,(ll)5000);
    q.push({1,1,k});
    while(!q.empty()&&sum<n){
        ll x=q.top().t,p=q.top().pos,num=q.top().s;q.pop();
        if(f[p][num]) continue;
        f[p][num]=x;
        if(!ans[p]) ans[p]=x,sum++;
        for(E i:edge[p]){
            if(i.a<=num&&!f[i.to][num-i.a]) q.push({x+i.b,i.to,num-i.a});
            if(num+c[p]<=10000) q.push({x+d[p],p,num+c[p]});
        }
    }
    for(int i=2;i<=n;i++){
        cout<<ans[i]-1<<endl;
    }
}

Measured memory_bytes: 55976
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class ETravelByCar {
public:

    vector<int> graph[303];

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, m, l; cin >> n >> m >> l;
      vector<vector<ll>> mat(n, vector<ll>(n, LLONG_MAX/2));
      rep(i, m) {
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        chmin(mat[a][b], c);
        chmin(mat[b][a], c);
      }

      rep(k, n) {
        rep(i, n) {
          rep(j, n) {
            chmin(mat[i][j], mat[i][k] + mat[k][j]);
          }
        }
      }

      rep(i, n) {
        rep(j, n) {
          if (i==j) continue;
          if (mat[i][j] <= l) {
            graph[i].push_back(j);
            graph[j].push_back(i);
          }
        }
      }

      vector<vector<ll>> ans(n, vector<ll>(n, LLONG_MAX/2));

      rep(i, n) {
        deque<P> que;
        que.emplace_back(i, 0);
        ans[i][i] = 0;
        while(!que.empty()) {
          P p = que.front(); que.pop_front();
          int s = p.first;
          int c = p.second;
          if (ans[i][s] < c) continue;
          for(auto t: graph[s]) {
            if (ans[i][t] > c+1) {
              ans[i][t] = c+1;
              que.emplace_back(t, c+1);
            }
          }
        }
      }

      int q; cin >> q;
      while(q--) {
        int s, t; cin >> s >> t;
        s--; t--;
        if (ans[s][t] == LLONG_MAX/2) {
          cout << -1 << '\n';
        } else {
          cout << ans[s][t]-1 << '\n';
        }
      }


    }
};

signed main() {
  ETravelByCar solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string S;
    int K;
    cin >> S >> K;
    int N = S.size();

    vec<vec<vec<ll>>> dp(2, vec<vec<ll>>(K + 2, vec<ll>(N + 1, 0)));
    dp[0][0][0] = 1;
    dp[1][0][0] = 0;
    rep(i, N) rep(k, K + 1) {
        int n = S[i] - '0';
        if (n == 0) {
            dp[0][k][i + 1] += dp[0][k][i];
            dp[1][k + 1][i + 1] += dp[1][k][i] * 9;
            dp[1][k][i + 1] += dp[1][k][i];
        } else {
            dp[0][k+1][i+1] += dp[0][k][i];
            dp[1][k+1][i+1] += dp[0][k][i]*(n-1);
            dp[1][k+1][i+1] += dp[1][k][i]*9;
            dp[1][k][i+1] += dp[0][k][i] + dp[1][k][i];
        }
    }
    cout << dp[0][K][N] + dp[1][K][N] << endl;
}


Measured memory_bytes: 3652
import math
def S(a,b):
    s = b+a/2.0
    return math.sqrt(s*(s-a)*(s-b)**2)

while True:
    try:
        a,l,x = map(int, raw_input().split())
        print S(a,l)+2*S(l,(l+x)/2.0)
    except:
            break

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

int main() {
  string a,b;
  cin >> a >> b;
  if (a.size() > b.size()) {
    cout << "GREATER";
  } else if (a.size() < b.size()) {
    cout << "LESS";
  } else {
    if (a > b) cout << "GREATER";
    else if (a==b) cout << "EQUAL";
    else cout << "LESS";
  }
  cout << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    set<string> st;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << (int)st.size() << endl;
    return 0;
}


Measured memory_bytes: 19256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define siz 100005

typedef pair< pair<int,int> , pair<int,int> > ppp;

int cost[siz];
vector<int>adj[siz];

int DFS(int v){
    if(cost[v]!=0) return cost[v];
    for(auto nx:adj[v]){
        cost[v]=max(cost[v],DFS(nx)+1);
    }
    return cost[v]=max(0,cost[v]);
}

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

  // freopen("street.in","r",stdin);
    //freopen("out.txt","w",stdout);

    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        adj[x].push_back(y);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,DFS(i));
    }

    printf("%d",ans);

return 0;

}




Measured memory_bytes: 7552
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def ans(self):
        print(len(set(self.par))-1-1)

n,m=map(int,input().split())
uf=UnionFind(n)

for i in range(m):
    a,b=map(int,input().split())  
    uf.union(a,b)

for i in range(1,n+1):
    uf.find(i)
uf.ans()

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

long int N;
long int A;
long int Z;
long int i;

int main(){
cin >> N;
for(int i=1;i<=N;i++){
if (i%3==0)
A = 0;
else if (i%5==0)
A = 0;
else A = i;
Z += A;
}
std::cout << Z;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll x, y, ans = 0;
  cin >> x >> y;

  if (x == 1) {
    ans += 300000;
  }

  else if (x == 2) {
    ans += 200000;
  }

  else if (x == 3) {
    ans += 100000;
  }

  if (y == 1) {
    ans += 300000;
  }

  else if (y == 2) {
    ans += 200000;
  }

  else if (y == 3) {
    ans += 100000;
  }

  if (x == 1 && y == 1) {
    ans += 400000;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
ll dp[100003][103]={0};
bool dp2[100005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("test.txt","r",stdin);
	dp2[0]=true;
	for(ll i=1;i<=100003;i++)
		dp2[i]=false;
	ll n,k;
	cin>>n>>k;
	ll arr[n+1];
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	for(ll i=1;i<=k;i++)
	{
		for(ll j=1;j<=n;j++)
		{
			if(i<arr[j])
				dp[i][j]=-1;
			else{
				if((i-arr[j])==0){
					dp[i][j]=0;
					dp2[i]=true;
				}
				else if(dp2[i-arr[j]]==true)
					dp[i][j]=1;
				else{
					dp[i][j]=0;
					dp2[i]=true;
				}
			}
		}
	}
	bool flag=false;
	for(ll i=1;i<=n;i++)
	{
		if(dp[k][i]==0){
			flag=true;
			break;
		}
	}
	/*for(ll i=1;i<=k;i++)
	{
		for(ll j=1;j<=n;j++)
			cout<<dp[i][j]<<" ";
		cout<<endl;

	}*/
	if(flag==false)
		cout<<"Second"<<endl;
	else
		cout<<"First"<<endl;


}

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

int main(){
  int q;
  cin >> q;
  while(q--){
    int c, a, n;
    cin >> c >> a >> n;
    int ans = 0;
    int t = min({c,a,n});
    ans += t;
    c -= t, a -= t, n -= t;
    t = min(a,c/2);
    ans += t;
    a -= t, c -= 2*t;
    ans += c/3;
    cout << ans << endl;
  }
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

long long dp[300][90010];
long long dp2[300][90010];

int main(){
  
  string s;
  cin>>s;
  int n = s.size();
  REP(i,n-8){
    cout<<s[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<ll> a(n); rep(i, n)cin >> a[i];
	reverse(all(a));
	if (a[0] != 2)
	{
		cout << -1 << endl;
		return 0;
	}
	ll mn = 2;
	ll mx = 3;
	for (int i = 1; i < n; ++i)
	{
		if (mx < a[i])
		{
			cout << -1 << endl;
			return 0;
		}
		mx = (mx / a[i] + 1)*a[i] - 1;
		if (mx == -1)
		{
			cout << -1 << endl;
			return 0;
		}
		if (mn < a[i])mn = a[i];
		else mn = ((mn + a[i] - 1) / a[i]) * a[i];
		if (mn > mx)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << mn << " " << mx << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using T=long long int;

class SegmentTree{
    vector<T> dat;
    int N;
    T E;
    function<T(T,T)> merge;
    T query_impl(int a,int b,int k,int l,int r){
        if(a<=l && r<=b) return dat[k];
        if(r<=a || b<=l) return E;
        int mid=(l+r)/2;
        T c1v=query_impl(a,b,k*2+1,l,mid);
        T c2v=query_impl(a,b,k*2+2,mid,r);
        return merge(c1v,c2v);
    }
    public:
    SegmentTree(size_t N,function<T(T,T)> merge,T E):E(E),merge(merge){
        this->N=1;
        while(this->N<N){
            (this->N)*=2;
        }
        dat.assign(this->N*2-1,E);
    }
    void update(int pos,T val){
        pos+=N-1;
        dat[pos]=val;
        while(pos!=0){
            int par=(pos-1)/2;
            int c1=par*2+1;
            int c2=par*2+2;
            dat[par]=merge(dat[c1],dat[c2]);
            pos=par;
        }
    }
    T query(int a,int b){
        assert(a<=b);
        return query_impl(a,b,0,0,N);
    }
    
};

T mymin(T a,T b){return min(a,b);}
int main(){
    int n,q;
    cin>>n>>q;
    SegmentTree seg(n,mymin,int((1u<<31)-1));
    for(int i=0;i<q;i++){
        int com,x,y;
        cin>>com>>x>>y;
        if(com){
            if(x>y){
                swap(x,y);
            }
            y++;
            cout<<seg.query(x,y)<<endl;
        }
        else{
            seg.update(x,y);
        }
    }

    return 0;
}

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


int main()
{
	string S;
	cin>>S;
	int N=S.size();
	ll ans=0;
	int black=0;
	rep(i,N)
	{
		if(S[i]=='B')
		{
			black++;
		}
		else
		{
			ans+=black;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3720
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long ans = 1;
		for(int i=0;i<N;i++) ans = ans / gcd(ans, T[i]) * T[i];
		Console.WriteLine(ans);
		
	}
	
	long gcd(long a, long b){
		return a == 0 ? b : gcd(b % a, a);
	}
	
	int N;
	long[] T;
	public Sol(){
		N = ri();
		T = new long[N];
		for(int i=0;i<N;i++) T[i] = rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#include <stdio.h>
#define MAX 100
#define INFTY 1<<21
#define WHITE 0
#define GLAY 1
#define BLACK 2

int n,m[MAX][MAX];

int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];
  int i;
  for( i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  
  }
  d[0]=0;
  int sum;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }

    if(u==-1)break;
    color[u]=BLACK;
    int v;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&m[u][v]!=INFTY){
	if(d[v]>m[u][v]){
	  d[v]=m[u][v];
	  p[v]=u;
	  color[v]=GLAY;
	}
      }

      
    }
  }

  sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum +=m[i][p[i]];
  }
  return sum;
}


int main(){int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
    int e;
    scanf("%d",&e);
    m[i][j]=(e==-1)?INFTY:e;
    
    }
  }
  


  printf("%d\n",prim());
 return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  3005;
const ll mod = 1e9 + 7;

using namespace std;

ll dp[N][N]; // for   taro
void solve()
{
   ll n;
   cin>>n;
   ll a[n];
   for (int i = 0; i < n; ++i)
   {
     /* code */
    cin>>a[i];
   }
   // dp[n-1][0] - ans when all are over
  for (int i = 0; i <n ; ++i)
  {
    for(ll j = i;j>=0;j--)
    {
      if(i==j)
      dp[i][j] = a[i];
      else dp[i][j] = max(a[i] - dp[i-1][j],a[j] - dp[i][j+1]);

    }
  }
  cout<<dp[n-1][0]<<"\n";
}

signed main(){
  
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


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

int main() {
  int a;
  string s;
  cin >> a >> s;
  if(a < 3200) {
    s = "red";
  }
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Random;
class Main{
	public static void main(String[] args){
    	Scanner sc= new Scanner(System.in);
      	int x1 = sc.nextInt();
      	int x2 = sc.nextInt();
      	int x3 = sc.nextInt();
      	int x4 = sc.nextInt();
      	int x5 = sc.nextInt();
      
      	if(x1==0){System.out.println(1);}else if(x2==0){System.out.println(2);}else if(x3==0){System.out.println(3);}else if(x4==0){System.out.println(4);}else{System.out.println(5);}
    }
}

Measured memory_bytes: 26920
#include<bits/stdc++.h>
using namespace std;
int k,s,ans;
int main()
{
    cin >> k >> s;
    for (register int i=0;i<=k;i++)
        for (register int j=0;j<=k;j++)
            if (s-i-j>=0&&s-i-j<=k)
                    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,n;
  int A[45];
  A[0]=A[1]=1;
  for(i=2;i<45;i++){
    A[i]=A[i-1]+A[i-2];
}
  scanf("%d",&n);
  printf("%d\n",A[n]);
  return 0;
}



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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (500 * i + 100 * j + 50 * k == x) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
	int main(){
	vector<int> five(5);
	int i ;
	for (i=0;i<5;i++){
	cin >> five.at(i);
	}
	//配列は準備した。
	//10で割ったあまりが1以上で最小のものは最後にタス
	vector<int> amari(5);
	for ( i=0;i<5;i++){
	amari.at(i)= five.at(i)%10;
	if (amari.at(i) == 0){
	amari.at(i) = 10;
	}
	}
	
	sort(amari.begin(),amari.end());
//	cout << amari.at(0) << endl;
// amariが最小のものは取れているらしい
	int x =0 ;
	for (i = 0 ; i<5 ; i++){
	x += five.at(i);
	if (x%10 != 0){
	x +=  (10 - x%10);
	}
	}
	cout << x - (10-amari.at(0)) <<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod=1e9+7;
const int N=1e6+10;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int a[N];
int main()
{
    int n;read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    ll ans=0;
    for(int i=2;i<=n;i++) if(a[i]<a[i-1]) ans+=a[i-1]-a[i],a[i]+=a[i-1]-a[i];
    printf("%lld\n",ans);
    return 0;
}


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

int main() {
  
  int N;
  int num = 0;
  
  cin >> N;
  
  vector<int> p(N);
  
  for(int i = 0;i < N;++i){
    cin >> p[i];
  }
  
  for(int i = 0;i < N;++i){
    if(p[i - 1] > p[i] && p[i] > p[i + 1] && i >= 1 &&  i <= N - 2){
      num++;
    }
    else if(p[i - 1] < p[i] && p[i] < p[i + 1] && i >= 1 && i <= N - 2){
      num++;
    }
  }
  
  cout << num << endl;
  
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;
 
int main(){
  int a,b;
  cin >> a >> b;
  int d = b;
  int c=10;
  while(b/10>0){
	  c *=10;
	  b = b/10;
  }
  double ans  = a*c + d;
  //cout << sqrt(ans) << endl;
  bool ok = true;
  double f = (int)sqrt((double)ans);
  //cout << f << endl;
  if (f*f != ans) ok = false;
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
} 

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int D;
vector<LL> c(26);
vector<vector<LL>> s;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

LL solve(const vector<LL>& t) {
  LL ans = 0;
  vector<LL> last(26, 0);
  for (int d = 1; d <= D; ++d) {
    int i = d - 1;
    int j = t[i];
    last[j] = d;
    ans += s[i][j];
    for (int k = 0; k < 26; ++k) {
      ans -= c[k] * (d - last[k]);
    }
  }
  return ans;
}

int main() {
  cin >> D;
  cin >> c;
  s.resize(D, vector<LL>(26, 0));
  for (int i = 0; i < D; ++i) cin >> s[i];

  vector<LL> t(D);
  for (int d  =  0; d < D; ++d) t[d] = d % 26;

  LL prev = solve(t);
  for (int i = 0; i < 10000; ++i) {
    auto t_bk = t;
    t[i % D] = rand() % 26;

    LL score = solve(t);
    if (score < prev) t = t_bk;
  }

  for (int x : t) cout << x + 1 << endl;
}


Measured memory_bytes: 3732
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 
 using namespace std;
 
 
 int stringToint(const string S)
 {  
    int result=0;
    if(S[0]=='-')
    {
      for(int i=1;i<S.length();i++)
      {
        result=10*result+(S[i]-'0');        
      }             
      result=-result;
    }
    else
    {
      for(int i=0;i<S.length();i++)
      { 
        result=10*result+(S[i]-'0');      
      }
    }  
    return result;  
 }  
 
 
 int main()
 {
   string s;
   string word;
   stack<double> mm;
   while(cin>>word)
   {
     if(word=="+"||word=="-"||word=="*"||word=="/")
       {
         double a=mm.top();
         mm.pop();
         double b=mm.top();
         mm.pop();
         double result;
         if(word=="+") result=b+a;
         else if(word=="-") result=b-a;
         else if(word=="*") result=b*a;
         else result=b/a;
         mm.push(result);     
       }   
       else if(word.length()>=2&&word[0]=='-'||(isdigit(word[0]))) 
       {
         //double kk=1.0*(stringToint(word));
         int kkk=stringToint(word);
         double aa=1.0*kkk;
         mm.push(aa);
         //mm.push(kk);                                                          
       }        
     if(getchar()=='\n')
     {    
       double final_result=mm.top();
       printf("%.10lf\n",final_result);
       mm.pop();
     }           
   }  
   //while(1);
   return 0;
 }

 

Measured memory_bytes: 3284
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0;i < N;i++){
			a[i] = sc.nextInt();
		}
		long ans=0;
		for(int i = 0;i < N-1;i++){
			if(a[i] + a[i+1] > x){
				long minus = a[i] + a[i+1] - x;
				ans += minus;
				a[i+1] -= minus;
				if(a[i + 1] < 0){
					a[i + 1] = 0;
				}
			}
		}
		System.out.println(ans);


	}
}

Measured memory_bytes: 53048
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
ll mod = 2000000000;
// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

// Comb( n, r ) return nCr {{{
// Comb(ination) = nCr ( natural number )
long long unsigned int Comb( long long unsigned int n , long long unsigned int r){
    if( n < r ) return Comb(r,n);
    long long unsigned int Upper = 1;
    for(long long unsigned int i = 0; i < r; i++){
        Upper *= (n-i);
        Upper /= (i+1);
    }
    return Upper;
}
// }}}

// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
long long unsigned int PowMod( long long unsigned int base, long long unsigned int index, long long unsigned int modulo = mod ){
    if( index == 0 ) return 1;
    // O( log(index) )
    if( index % 2 ){
        return base * PowMod(base, index - 1, modulo) % modulo;
    }else{
        long long unsigned int Phalf = index / 2;
        long long unsigned int half = PowMod(base, Phalf, modulo);
        return half * half % modulo;
    }
}
// }}}
// FactMod( n, modulo ) return n! % modulo {{{
// Fact(orial) = n! % mod ( natural number )
long long unsigned int Fact( long long unsigned int n, long long unsigned int modulo = mod){
    long long unsigned int Upper = 1;
    for(long long unsigned int i = 0; i < n; i++){
        Upper = Upper * (n-i) % modulo;
    }
    return Upper;
}
// }}}

int n;
int dfs( ll k = 0, bool t7 = 0, bool t5 = 0, bool t3 = 0 ){
	if( k > n ) return 0;
    return dfs(k*10+7,t7||1,t5,t3)+dfs(k*10+5,t7,t5||1,t3)+dfs(k*10+3,t7,t5,t3||1)+(t7&&t5&&t3);
}

int main() {
    Scd(n);

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

    return 0;
}



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

using namespace std;

typedef struct dice {

	int surface[6] = { 0 };
	string str;

} Dice;

bool judge(int surface1[], int surface2[]);
bool Combination(Dice data[] ,int n);

int main() {

	Dice dice[100];
	int n = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {

		for (int u = 0; u < 6; u++) {

			cin >> dice[i].surface[u];

		}

	}

	if (Combination(dice, n)) {

		cout << "Yes" << endl;

	}
	else {

		cout << "No" << endl;

	}

}

bool judge(int surface1[], int surface2[]) {

	int need[4] = { 0 };
	int arr[3][6] =
	{
		{0,5,1,2,4,3},
		{1,4,0,3,5,2},
		{2,3,0,1,5,4}
	};

	for (int i = 0; i < 3; i++) {

		need[0] = arr[i][2];
		need[1] = arr[i][3];
		need[2] = arr[i][4];
		need[3] = arr[i][5];

		if (surface1[arr[i][0]] == surface2[arr[0][0]] && surface1[arr[i][1]] == surface2[arr[0][1]]) {

			for (int u = 0; u < 4; u++) {

				if (surface1[need[(u < 4) ? u : u - 4]] == surface2[arr[0][2]] && surface1[need[(u + 1 < 4) ? u + 1 : u + 1 - 4]] == surface2[arr[0][3]] && surface1[need[(u + 2 < 4) ? u + 2 : u + 2 - 4]] == surface2[arr[0][4]] && surface1[need[(u + 3 < 4) ? u + 3 : u + 3 - 4]] == surface2[arr[0][5]]) {

					return true;

				}
				
			}

		}
		else if (surface1[arr[i][0]] == surface2[arr[0][1]] && surface1[arr[i][1]] == surface2[arr[0][0]]) {

			for (int u = 0; u < 4; u++) {

				if (surface1[need[(u < 4) ? u : u - 4]] == surface2[arr[0][2]] && surface1[need[(u + 1 < 4) ? u + 1 : u + 1 - 4]] == surface2[arr[0][5]] && surface1[need[(u + 2 < 4) ? u + 2 : u + 2 - 4]] == surface2[arr[0][4]] && surface1[need[(u + 3 < 4) ? u + 3 : u + 3 - 4]] == surface2[arr[0][3]]) {

					return true;

				}

			}

		}
		else {

			continue;

		}

	}

	return false;

}

bool Combination(Dice data[], int n){

	for (int i = 0; i < n; i++) {

		for (int u = i + 1; u < n; u++) {

			if (judge(data[i].surface, data[u].surface)) {

				return false;

			}

		}

	}

	return true;

}








Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e14;
const ll mod = 1e9+7;
// __uint128_t


ll N, M;
ll MAX = 1e5+5;
vector<ll> DP(MAX), DP2(MAX, 1);
vector<vector<ll>> G(MAX);


int dfs(ll x, ll p){
    ll res = 1;
    for(auto v : G[x]){
        if(v == p) continue;
        res *= (dfs(v, x)+1);
        res %= M;
    }
    return DP[x] = res;
}

void dfs2(ll x, ll p = -1){
    vector<ll> pt;
    for(auto v : G[x]) if(v != p) pt.push_back(v);
    vector<ll> Acc1(pt.size()+2, 1), Acc2(pt.size()+2, 1);
    for(int i = 0; i < pt.size(); i++) Acc1[i+1] = Acc2[i+1] = DP[pt[i]]+1;

    for(int i = 0; i < Acc1.size()-1; i++) {Acc1[i+1] *= Acc1[i]; Acc1[i+1] %=M;}
    for(int i = Acc2.size()-1; i > 0; i--) {Acc2[i-1] *= Acc2[i]; Acc2[i-1] %=M;}

    for(int i = 0; i < pt.size(); i++){
        ll idx = i+1;
        ll v = pt[i];
        DP2[v] = (((Acc1[idx-1] * Acc2[idx+1])%M) * DP2[x])%M + 1;
    }
    for(auto v : G[x]){
        if(p != v)dfs2(v, x);
    }
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < N-1; i++){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1);
    dfs2(0);

    for(int i = 0; i < N; i++) cout << (DP[i]*DP2[i])%M << endl;

}

Measured memory_bytes: 24448
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()
#define draw "Draw"
#define alice "Alice"
#define bob "Bob"

signed main() {
	int a,b;
	std::cin >> a >> b;
	if(a==b) {
		print(draw);
		return 0;
	}
	if(a==1&&b!=1) {
		print(alice);
		return 0;
	}
	if(a!=1&&b==1) {
		print(bob);
		return 0;
	}
	if(a>b) {
		print(alice);
		return 0;
	}
	print(bob);

	return 0;
}


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



int main(){
  int n,y;
  cin >> n >> y;

  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n-i;j++){
      if((y - (i*10000 + j*5000)) / 1000 == n-i-j){
        cout << i << " " << j << " " << n-i-j << endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

bool ok(const string& s, const int& i) {
    return s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T';
}

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int r = i;
        while (r < n && ok(s, r)) r++;
        ans = max(ans, r - i);
        i = r;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int arr[upperlimit];
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	int n,k;
	sd(n);sd(k);
	for(int i = 1; i <= n; i++) sd(arr[i]);
	sort(arr+1,arr+n+1);
	ll sum=0;
	for(int i = 1; i <= k; i++) sum+=arr[i];
	plld(sum);
	return 0;
}

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

int dp[1000000],kisuu[1000000];
int main(){
    fill(dp,dp+1000000,1<<29);
    fill(kisuu,kisuu+1000000,1<<29);
    dp[0]=0;
    kisuu[0]=0;
    for(int i=1;i<500;i++){
	int s=i*(i+1)*(i+2)/6;
	    for(int j=s;j<1000000;j++){
	    dp[j]=min(dp[j],dp[j-s]+1);
	    }
	    if((s&1)==0)continue;
	    for(int j=s;j<1000000;j++){
	    kisuu[j]=min(kisuu[j],kisuu[j-s]+1);
	    }
	}
	int k;
	while(cin>>k,k){
	    cout<<dp[k]<<" "<<kisuu[k]<<endl;
	    }
    }

Measured memory_bytes: 10832
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	if (a >= 1 && a <= 9 && b >= 1 && b <= 9) cout << a * b;
	else cout << -1;
}


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

bool check(char bw[3][3], char x){
	for(int i=0;i<3;i++)
		if((bw[i][0] == x) && (bw[i][1] == x) && (bw[i][2] == x))
			return true;
		else if((bw[0][i] == x) && (bw[1][i] == x) && (bw[2][i] == x))
			return true;
	
	if((bw[0][0] == x) && (bw[1][1] == x) && (bw[2][2] == x))
		return true;

	if((bw[0][2] == x) && (bw[1][1] == x) && (bw[2][0] == x))
		return true;

	return false;
}

int main(){
	while(1){
		string str;
		char bw[3][3];

		cin>>str;
		if(str == "0")
			break;

		for(int j=0;j<3;j++)
			bw[0][j] = str[j];

		for(int i=1;i<3;i++){
			cin>>str;
			for(int j=0;j<3;j++)
				bw[i][j] = str[j];
		}

		if(check(bw, 'b'))
			cout<<"b"<<endl;
		else if(check(bw, 'w'))
			cout<<"w"<<endl;
		else
			cout<<"NA"<<endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));}

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

  ll ret = 0;
  REP(a,1,K+1){
    REP(b,1,K+1){
      REP(c,1,K+1){
        ret += gcd(a, gcd(b, c));
      }
    }
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,a,b,c,i,j,k,s=0;
	scanf("%d\n%d\n%d\n%d",&a,&b,&c,&x);
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			if(i*500+j*100>x)
				continue;
			for(k=0;k<=c;k++)
				if(i*500+j*100+k*50==x)
					s++;	
		}	
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 2, 0);
    REP(i, N)cin >> A[i + 1];

    int S = 0;
    REP(i, N + 1) {
        S += abs(A[i + 1] - A[i]);
    }


    REP(i, N) {
        cout << S + abs(A[i + 2] - A[i]) - abs(A[i + 2] - A[i + 1]) - abs(A[i + 1] - A[i]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
s = input()

n = len(s)

if s[n-1] == '1':
    print(-1)
    exit(0)
if s[0] == '0' or s[n-2] == '0':
    print(-1)
    exit(0)
for i in range(n-1):
    if s[i] != s[n-2-i]:
        print(-1)
        exit(0)

#rebuild tree

#record all size
ss = []

for i in range(n-1,-1,-1):
    if s[i] == '1':
        ss.append(i+1)


now_no = 1
now_siz = n
for siz in ss:
    others = now_siz - siz - 1
    for i in range(1,others+1):
        print(now_no,now_no+i)
    print(now_no,now_no+others+1)
    now_no += others+1
    now_siz = siz



Measured memory_bytes: 8500
n,t=map(int,input().split())
List=list(list(map(int,input().split())) for i in range(n))
l=[]
for i in range(n):
      if List[i][1]<=t:
            l.append(List[i][0])
      else:
            l.append(1001)
if min(l)==1001:
      print('TLE')
else:
      print(min(l))

            


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ios>//左右揃え
#include<iomanip>//setwで幅指定

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007LL

long C(long n, long r) {
    long X = 1, Y = 1;
    rep(i, r) {
        X = X * (n - i);
        Y = Y * (i + 1);
    }
    return X / Y;
}

int main(void) {
    int n, in;
    cin >> n;
    vector<int> a(n);
    vector<int> mass(n);
    rep(i, n) {
        cin >> in;
        a[i] = in;
        mass[in - 1]++;
    }
    long long int sum = 0;
    vector<int> combi(n);
    rep(i, n) {
        if (mass[i] != 0 && mass[i] != 1) {
            sum += C(mass[i], 2);
        }
    }
    //cout << sum << endl;
    rep(k, n) {
        cout << sum - mass[a[k] - 1] + 1 << endl;
    }
}

Measured memory_bytes: 4992
use std::io;

fn main() {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).unwrap();
    let input_num: i32 = buffer.trim().parse().unwrap();

    let happy_1000 = input_num / 500 * 1000;
    let happy_5 = (input_num % 500) / 5 * 5;
    println!("{}", happy_1000 + happy_5);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
char S[110];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%s",S+1);
	int n=strlen(S+1),K=gi();ll ans=0;
	int L,R;
	for(int l=1,r;l<=n;l=r+1){
		r=l;while(S[r+1]==S[r])++r;
		if(l==1)L=r-l+1;
		else if(r==n)R=r-l+1;
		else ans+=1ll*K*((r-l+1)>>1);
	}
	if(L==n)printf("%lld\n",(1ll*K*n)>>1);
	else if(S[1]!=S[n])printf("%lld\n",ans+1ll*K*((L>>1)+(R>>1)));
	else printf("%lld\n",ans+(L>>1)+(R>>1)+1ll*(K-1)*(L+R>>1));
	return 0;
}


Measured memory_bytes: 256