akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define sint(n) scanf("%d",&n);

using namespace std;


int main(){
	while(1){
		int a,b,c;
		sint(a)
		sint(b)
		sint(c)
		
		if(a==0){break;}
		int k;
		sint(k)
		
		int buhin[301]={0};
		rep(i,301){
			buhin[i]=2;
		}
		
		int e[1000],r[1000],t[1000],u[1000];
		rep(i,k){
			scanf("%d%d%d%d",&e[i],&r[i],&t[i],&u[i]);
			if(u[i]==1){
				buhin[e[i]]=buhin[r[i]]=buhin[t[i]]=1;
			}
		}
		
		
		rep(i,k){
			if(u[i]==0){
				if(buhin[e[i]]==1 && buhin[r[i]]==1){
					buhin[t[i]]=0;
				}
				if(buhin[e[i]]==1 && buhin[t[i]]==1){
					buhin[r[i]]=0;
				}
				if(buhin[t[i]]==1 && buhin[r[i]]==1){
					buhin[e[i]]=0;
				}
			}
		}
		
		rep(i,a+b+c){
			printf("%d\n",buhin[i+1]);
		}
	}
}
/*
2 2 2
4
2 4 5 0
2 3 6 0
1 4 5 0
2 3 5 1 
*/

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <cmath>
#include <cassert>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <iomanip>
#define mkp make_pair
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
const int INF=2147483647;
const double pi=acos(-1.0);
int A[3005];
int main(){
	IOS;
	int n,L;
	cin>>n>>L;
	double x=0,y=0;
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			x+=-cos(pi*(A[i]+A[j])/L)*(j-i-1)+cos(pi*(A[i]+A[j])/L)*(n-2-j+i+1);
			y+=-sin(pi*(A[i]+A[j])/L)*(j-i-1)+sin(pi*(A[i]+A[j])/L)*(n-2-j+i+1);
		}
	}
	cout<<setprecision(20)<<x*6/n/(n-1)/(n-2)<<' '<<y*6/n/(n-1)/(n-2)<<'\n';
	return 0;
}


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

int main() {
	int n;
	int max[2];
	int a, b;
	cin >> n;
	cin >> max[0] >> max[1];
	for (int i = 1; i < n; i++) {
		cin >> a >> b;
		if (b > max[1]) {
			max[1] = b;
			max[0] = a;
		} else if (b == max[1]) {
			max[0] = min(max[0], a);
		}
	}
	cout << max[0] << " " << max[1] << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(){
 double a,b,C;
 cin >> a >> b >> C;
 double S,L,h;
 C = M_PI*C/180;

 S = a*b*sin(C)/2;
 L = a+b+sqrt(a*a+b*b-2*a*b*cos(C));
 h = 2*S/a;
 printf("%.5f\n",S);
 printf("%.5f\n",L);
 printf("%.5f\n",h);
}


Measured memory_bytes: 3388
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
N,M = map(int,input().split())
lst=[{} for f in range(N)]
for i in range(M):
 x,y=map(int,input().split())
 lst[x-1][y-1]=1
memo = {}
def cost(a):
 ans=0
 if a in memo:
  return memo[a]
 else:
  for i in lst[a]: 
   if i in memo:
    ans=max(memo[i]+1,ans)
   else:
    ans=max(cost(i)+1,ans)
  memo[a]=ans
  return ans
T=0
for i in range(N):
 T=max(T,cost(i))
print(T)

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

int main()
{
    int a[3], k, i;
    for(i=0;i<3;i++) cin>>a[i];
    cin>>k;
    for(i=1;i<3;i++){
        while(a[i]<=a[i-1]){
            a[i]*=2;
            k--;
        }
    }
    if(k<0) cout<<"No";
    else cout<<"Yes";

}


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

int main() {
  string n;
  cin >> n; 
  if (n[0] == n[1] && n[1] == n[2]){
    cout << "Yes" << endl;
  } else if (n[1] == n[2] && n[2] == n[3]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }  

}


Measured memory_bytes: 256
#include <iostream>
int main(void){
  int N;
  std::cin >> N;
  int a[N];
  for(int i = 0; i < N; i++){
    std::cin >> a[i];
  }
  for(int i = 0; i < N; i++){
    if(a[i] % 2 == 0){
      if(a[i] % 3 != 0 && a[i] % 5 != 0){
        std::cout << "DENIED" <<std::endl;
        break;
      }
    }
    if (i == N - 1){
        std::cout << "APPROVED" <<std::endl;
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

// multi-dimensional vector (require c++14)
template <typename T, typename U>
static inline vector<U> make_nd_vector(T &&n, U &&val) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
static inline decltype(auto) make_nd_vector(T &&n, Args &&... args) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<decltype(make_nd_vector(forward<Args>(args)...))>(
      forward<T>(n), make_nd_vector(forward<Args>(args)...));
}
//
// Print from Iterator
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
//
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int cumxor = 0;
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cumxor ^= a[i];
  }
  for (int i = 0; i < n; i++)
    ans[i] = cumxor ^ a[i];
  print_ite(all(ans));
}


Measured memory_bytes: 4448
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var abcd = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var (a, b, c, d) = (abcd[0], abcd[1], abcd[2], abcd[3]);

        var hp = new [] { a, c };
        var atk = new [] { b, d };
        for (int i = 0; hp[i & 1] > 0; ++i)
        {
            hp[(i & 1) ^ 1] -= atk[i & 1];
        }
        Console.WriteLine(hp[0] > 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 28300
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    long long int n,i,flag=0;
    cin>>n;
    long long int a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i]||a[i]==(b[i]+1)||a[i]==(b[i]-1))
            flag=1;
        else
        {
            flag=0;
            break;
        }
    }
    if(flag==1)
        cout<<"Yes";
    else
        cout<<"No";
}

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

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define popcnt(x) __builtin_popcount(x)
#define popcntll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class BCommonRaccoonVsMonster {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int H, N, sum = 0;
        in>>H>>N;
        REP(i, N){
            int a;
            in>>a;
            sum += a;
        }
        if(sum<H) out<<"No\n";
        else out<<"Yes\n";
    }
};


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


Measured memory_bytes: 3616
import sys
input = sys.stdin.readline
import numpy as np
inf = float('inf')

H, W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
A = np.array(A)
B = [list(map(int,input().split())) for _ in range(H)]
B = np.array(B)
D = A - B
D = np.vectorize(abs)(D)

N = (H + W) * 80
M = 2*N + 1
# [-N, N] を [0,2*N] として扱う(右にNだけずらす)
dp = [[np.zeros(M, np.bool) for _ in range(W)] for _ in range(H)]
d = D[0][0]
dp[0][0][d+N] = 1
dp[0][0][-d+N] = 1

for i, Di in enumerate(D):
    for j, Dij in enumerate(Di):
        if i != 0:
            dp[i][j][Dij:M] |= dp[i-1][j][0:M-Dij]
            dp[i][j][0:M-Dij] |= dp[i-1][j][Dij:M]
        if j != 0:
            dp[i][j][Dij:M] |= dp[i][j-1][0:M-Dij]
            dp[i][j][0:M-Dij] |= dp[i][j-1][Dij:M]

ind = np.where(dp[H-1][W-1])[0]
ind -= N
ans = np.vectorize(abs)(ind).min()
print(ans)

Measured memory_bytes: 174796
N,K = list(map(int,input().split()))
data = []
def insert(num,N,K):
    x = 0
    for i in range(N):
        x += num[i][1]
        if x >= K:
            print(num[i][0])
            break
num = [list(map(int,input().split())) for i in range(N)]
num.sort(key=lambda x:x[0])
insert(num,N,K)


Measured memory_bytes: 30576
import java.util.Scanner;

public class Main {
	static int stack[] = new int[1000];
	static int counta = 0;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String input[] = (scanner.nextLine()).split(" ");

		for (int i = 0; i < input.length; i++) {
			if (input[i].equals("*")) {
				push(pop() * pop());

			} else if (input[i].equals("+")) {
				push(pop() + pop());

			} else if (input[i].equals("-")) {
				push(-pop() + pop());

			} else {
				push(Integer.parseInt(input[i]));

			}
		}
		System.out.println(pop());
	}

	public static int pop() {
		counta--;
		return stack[counta + 1];
	}

	public static void push(int i) {
		counta++;
		stack[counta] = i;
	}
}


Measured memory_bytes: 26276
//~ #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()


using namespace std;

const bool dbg_flg = 1;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n'
 
const int inf = 1e9 + 7;
const int MAXN = 3e5 + 5;

int n;
double p[3005];
double dp[3005][3005];

int main() {
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	cout.precision(9);
	cout << fixed;

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

	dp[1][1] = p[1];
	dp[1][0] = 1.0 - p[1];
	
	for (int i = 2; i <= n; i++) {
		
		dp[i][0] = dp[i - 1][0] * (1 - p[i]);
		
		for (int j = 1; j <= i; j++) {
			dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1.0 - p[i]);
		}
	}
	
	double res = 0.0;
	
	for (int i = n / 2 + 1; i <= n; i++) {
		res += dp[n][i];
	}
	
	cout << res;
	return 0;
}


Measured memory_bytes: 69120
#include <bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mod 1000000007
using namespace std;

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}

int main(){
    fast();
    ll t=1;
//    cin>>t;
    while(t--){
    	ll n;
    	cin>>n;
    	ll a[10005]={0};
    	for(ll i=1;i<=100;i++){
    		for(ll j=1;j<=100;j++){
    			for(ll k=1;k<=100;k++){
    				ll val=i*i+j*j+k*k+i*j+i*k+j*k;
					if(val<=10000)
    				a[val]++;
				}
			}
		}
		for(ll i=1;i<=n;i++)cout<<a[i]<<'\n';
	}
}

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

int main() {
	int n; cin >> n;
	for (int i = n; n > 0; i--) {
		int root = sqrt(i);
		if (root * root == i) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
struct edge{int from,to,cost;};
vector<edge> es;
int p[100];
void init(int N){rep(i,N) p[i]=i;}
int find(int x){
	if(x==p[x]) return x;
	return p[x]=find(p[x]);
}
int same(int x,int y){
	return find(x)==find(y);
}
void unite(int x,int y){
	x=find(x),y=find(y);
	p[x]=y;
}
bool comp(const edge& x,const edge& y){
	return x.cost<y.cost;
}
vector<int> cs;
int N,M;
int main(){
	while(true){
		cin>>N>>M;
		if(N==0) break;
		es.clear();
		cs.clear();
		rep(i,M){
			int a,b,c;
			cin>>a>>b>>c;
			es.pb({a-1,b-1,c});
			cs.pb(c);
		}
		sort(all(es),comp);
		int ans=1e9;
		for(int a:cs){
			init(N);
			int mx=0,cnt=0;
			for(edge e:es){
				if(e.cost<a) continue;
				if(!same(e.from,e.to)){
					unite(e.from,e.to);
					mx=e.cost;
					cnt++;
				}
			}
			if(cnt==N-1) ans=min(ans,mx-a);
		}
		if(ans==1e9) ans=-1;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1344
program main
  implicit none
  integer :: i, n, x, m(1000), rem, add
  read(*, *) n, x
  m(:) = 0
  read(*, *) (m(i), i = 1, n)
  rem = x - sum(m)
  add = rem / minval(m(1:n))
  write(*, "(i0)") n + add
end program main


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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int W, H, N;
	cin >> W >> H >> N;
	vector<P> point(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> point[i].first >> point[i].second;
	}
	int ans = 0;
	P current;
	current.first = point[0].first;
	current.second = point[0].second;
	for (int i = 1; i < N; ++i)
	{
		int step = 0;
		if ((current.first <= point[i].first && current.second >= point[i].second) || (current.first >= point[i].first && current.second <= point[i].second))
		{
			step = abs(point[i].first - current.first) + abs(point[i].second - current.second);
		}
		else
		{
			step = min(abs(point[i].first - current.first), abs(point[i].second - current.second));
			if (step - abs(point[i].first - current.first) == 0)
			{
				step += abs(point[i].second - current.second) - step;
			}
			else
			{
				step += abs(point[i].first - current.first) - step;
			}
		}
		current.first = point[i].first;
		current.second = point[i].second;
		ans += step;
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1200
n = int(input())
a = [int(ai) for ai in input().split()]
if n % 2 == 0:
    s = [0,0]
    for i in range(n // 2):
        s = [max(s[q] for q in range(p+1)) + a[i*2+p] for p in range(2)]
    print(max(s))
else:
    s = [0,0,0]
    for i in range(n // 2):
        s = [max(s[q] for q in range(p+1)) + a[i*2+p] for p in range(3)]
    print(max(s))


Measured memory_bytes: 31700
scale = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
index = Hash[*([scale, (0...scale.size).to_a].transpose).flatten]

gets.to_i.times do
  n, m = gets.split.map(&:to_i)
  t = gets.split
  s = gets.split
  ok = false
  nowT = n-1
  nowS = m-1
  m.times do
    case t[nowT]
      when scale[index[s[nowS]]]
        nowT -= 1
      when scale[(index[s[nowS]] + 1) % scale.size]
        nowT += 1
      when scale[(index[s[nowS]] - 1 + scale.size) % scale.size]
        nowT -= 2
      else
        break
    end
    nowS -= 1
    ok = true if nowT == 0 && nowS == 0
    ok = true if nowT == -1 && nowS == -1
    break if nowT < 0 || n <= nowT
  end
  nowT = n-2
  nowS = m-1
  m.times do
    case t[nowT]
      when scale[index[s[nowS]]]
        nowT -= 1
      when scale[(index[s[nowS]] + 1) % scale.size]
        nowT += 1
      when scale[(index[s[nowS]] - 1 + scale.size) % scale.size]
        nowT -= 2
      else
        break
    end
    nowS -= 1
    ok = true if nowT == 0 && nowS == 0
    ok = true if nowT == -1 && nowS == -1
    break if nowT < 0 || n <= nowT
  end
  puts ok ? "Yes" : "No"
end

Measured memory_bytes: 19600
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k,ans=0;;
  cin>>k;
  for(int i=1;i<=k;i++)
    for(int j=1;j<=k;j++)
        for(int g=1;g<=k;g++)
          ans+=__gcd(g,__gcd(i,j));
  cout<<ans;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define SF scanf
#define PF printf
#define MAXN 100010
#define INF 1000000000000000ll
#define EPS 1e-7
using namespace std;
typedef long long ll;
int n,m;
ll vis[MAXN][2];
ll ans[MAXN];
vector<pair<int,ll> >a[2][MAXN];
queue<int> q;
bool inq[MAXN];
void spfa(int x,int y){
	while(!q.empty())
		q.pop();
	vis[x][y]=0;
	q.push(x);
	while(!q.empty()){
		int v=q.front();
		q.pop();
		inq[v]=0;
		for(int i=0;i<a[y][v].size();i++){
			int u=a[y][v][i].first;
			if(vis[u][y]==-1||vis[u][y]>a[y][v][i].second+vis[v][y]){
				vis[u][y]=a[y][v][i].second+vis[v][y];
				if(inq[u]==0){
					inq[u]=1;
					q.push(u);	
				}
			}
		}
	}
}
int main(){
	int s,t,u,v,x,y;
	memset(vis,-1,sizeof vis);
	SF("%d%d%d%d",&n,&m,&s,&t);
	for(int i=1;i<=m;i++){
		SF("%d%d%d%d",&u,&v,&x,&y);	
		a[0][u].push_back(make_pair(v,x));
		a[0][v].push_back(make_pair(u,x));
		a[1][u].push_back(make_pair(v,y));
		a[1][v].push_back(make_pair(u,y));
	}
	spfa(s,0);
	spfa(t,1);
	for(int i=1;i<=n;i++)
		ans[i]=vis[i][0]+vis[i][1];
	for(int i=n-1;i>0;i--)
		ans[i]=min(ans[i],ans[i+1]);
	for(int i=1;i<=n;i++)
		PF("%lld\n",INF-ans[i]);
}

Measured memory_bytes: 19200
a, b = map(int, input().split())
grid = [["#" for j in range(100)] for i in range(100)]
for i in range(50, 100):
	for j in range(100):
		grid[i][j] = "."
for i in range(a-1):
	grid[(i//50)*2][(i%50)*2] = "."
for i in range(b-1):
	grid[(i//50)*2+51][(i%50)*2] = "#"
print(100, 100)
for i in range(100):
	print("".join(grid[i]))

Measured memory_bytes: 3444
import sys,math
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

n=int(input())
N=200005

def f(n):
    if n<2:return 0
    return n*(n-1)//2

a=list(IA())

vis=[0 for i in range(0,n+1)]

for it in a:
    vis[it]+=1

    
sum1=0

for i in range(1,n+1):
    sum1+=f(vis[i])
ans=[int(-1) for i in range(0,n+1)]
for it in a:
    if ans[it]==-1:
        ans[it]=sum1-f(vis[it])+f(vis[it]-1)
    print(ans[it])

    



            



Measured memory_bytes: 26888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
using namespace std;

char s[55];

int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len-8; i++){
		cout << s[i];
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
int main(void) {
	int N;
	cin >> N;
	vector<int> h(N);
	rep(i,N) cin >> h[i];
	
	int res = 0;
	while(true){
		if(*max_element(h.begin(), h.end()) == 0) break;
		
		int i = 0;
		while(i < N){
			if(h[i] == 0) ++i;
			else{
				++res;
				while(i < N && h[i] > 0){
					--h[i];
					++i;
				}
			}
		}
	}
	cout << res << endl;
}


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

int gcd(int a, int b);

int main() {
  int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}

int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}



Measured memory_bytes: 3116
array = [[int(x) for x in input().split()] for y in range(3)]
tmp = [[] for x in range(5)]
for a, b in array:
    tmp[a].append(b)
    tmp[b].append(a)
for i in tmp:
    if len(i) == 3:
        print("NO")
        break
else:
    print("YES")




Measured memory_bytes: 3060
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdint>

int main() {
  int N, M;
  scanf("%d %d", &N, &M);

  std::vector<intmax_t> P(M);
  for (int i=0; i<M; ++i) {
    scanf("%jd", &P[i]);
  }

  std::vector<intmax_t> imos(N+2);
  for (int i=1; i<M; ++i) {
    int L=P[i-1], R=P[i];
    if (L > R) std::swap(L, R);
    ++imos[L];
    --imos[R];
  }

  for (int i=1; i<=N; ++i)
    imos[i] += imos[i-1];

  intmax_t res=0;
  for (int i=1; i<N; ++i) {
    intmax_t A, B, C;
    scanf("%jd %jd %jd", &A, &B, &C);

    intmax_t t=imos[i];
    res += std::min(A*t, t*B+C);
  }

  printf("%jd\n", res);
  return 0;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
 
using namespace std;
const ll maxn=3000+100,inf=1e18,LOG=23,mod=1e9 + 7;
 
#define int ll
 
int n, h, w, dp[maxn], fact[210000], rev[210000], x[maxn], y[maxn], ans, ind[maxn];
 
bool comp(int a, int b)
{
	return x[a] + y[a] < x[b] + y[b];
}
 
int binom(int k, int n)
{
	return (fact[n] % mod * rev[k] % mod) * rev[n - k] % mod;
}
 
int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n % 2)
		{
			res *= a;
			res %= mod;
		}
		a *= a;
		a %= mod;
		n /= 2;
	}
	return res % mod;
}
 
main()
{
	IOS
	fact[1] = 1;
	rev[1] = 1;
	fact[0] = 1;
	rev[0] = 1;
	forn(2, i, 201000)
	{
		fact[i] = (fact[i - 1] % mod * i) % mod;
		rev[i] = binpow(fact[i], mod - 2) % mod;
	}
	cin >> h >> w >> n;
	forn(1, i, n)
	{
		cin >> x[i] >> y[i];
		ind[i] = i;
	}
	n++;
	ind[n] = n;
	x[n] = h;
	y[n] = w;
	sort(ind + 1, ind + 1 + n, comp);
	forn(1, it, n)
	{
		int i = ind[it];
		int kol = binom(x[i] - 1, x[i] - 1 + y[i] - 1) % mod;
		//cout << kol << endl;
		int kol2 = 0;
		forn(1, jt, it - 1)
		{
			int j = ind[jt];
			if(i == j || !(x[i] >= x[j] && y[i] >= y[j])) continue;
			kol2 = (kol2 + (binom(x[i] - x[j], x[i] - x[j] + y[i] - y[j]) % mod * dp[j] % mod) % mod) % mod;
			kol2 %= mod;
		}
		kol = (((kol - kol2) % mod) + mod) % mod;
		dp[i] = kol;
	}
	cout << dp[n] % mod;
}

Measured memory_bytes: 3456
use std::cmp::max;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn lcs(x: Vec<char>, y: Vec<char>) -> u16 {
    let x_len = x.len();
    let y_len = y.len();
    let mut matrix: Vec<Vec<u16>> = vec![vec![0; y_len]; x_len];
    let mut input_number = 0;

    for i in 0..(x_len) {
        if x[i] == y[0] {
            input_number = 1;
        }
        matrix[i][0] = input_number;
    }
    input_number = 0;
    for j in 0..(y_len) {
        if x[0] == y[j] {
            input_number = 1;
        }
        matrix[0][j] = input_number;
    }

    for i in 1..(x_len) {
        for j in 1..(y_len) {
            if x[i] == y[j] {
                matrix[i][j] = matrix[i - 1][j - 1] + 1
            } else {
                matrix[i][j] = max(matrix[i][j - 1], matrix[i - 1][j])
            }
        }
    }
    return matrix[x_len - 1][y_len - 1];
}

fn main() {
    let q: usize = read();
    for _ in 0..q {
        let x_string: String = read();
        let y_string: String = read();
        println!(
            "{}",
            lcs(x_string.chars().collect(), y_string.chars().collect())
        );
    }
}



Measured memory_bytes: 7076
#include <cstdio>
#include <algorithm>

using namespace std;

namespace io {
	const int maxb = 1 << 15;
	char b[maxb], *s = b, *t = b;
	
	bool getchar(char &ch) {
		return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s++;
	}
	
	int getint() {
		char ch;
		while (getchar(ch) && (ch < '0' || ch > '9'));
		int s = ch - '0';
		while (getchar(ch) && ch >= '0' && ch <= '9') {
			s = s * 10 + ch - '0';
		}
		return s;
	}
}

using io::getint;

const int maxn = 3e5 + 10;

void put_no() {
	puts("No");
	exit(0);
}

int p[maxn];

bool check(int l, int r) {
	int last_lef = 0, last_rig = 0;
	for (int i = l; i <= r; i += 2) {
		if (p[i] < l || p[i] > r) put_no();
		if (p[i] < i) {
			if (p[i] < last_lef) put_no();
			last_lef = p[i];
		} else {
			if (p[i] < last_rig) put_no();
			last_rig = p[i];
		}
	}
	return true;
}

int main() {
	int n = getint(), last = 0;
	for (int i = 1; i <= n; ++i) {
		p[i] = getint();
		if (p[i] == i) {
			if (!last || p[i - 1] != i - 1) continue;
			check(last, i - 2);
			last = 0;
			continue;
		}
		if (!last) {
			last = i;
			continue;
		}
		if (p[i - 1] == i - 1) continue;
		check(last, i - 1);
		last = i;
	}
	if (last) {
		check(last, p[n] == n ? n - 1 : n);
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define pb push_back
#define ss second
#define ff first
#define mp make_pair

using namespace std;

vector<int> vec;

int ar[1000050];


int main() 
{
    int n,m,t,p,q,r,s,a,b,c,d,e,f,g,h,sum,res,flag,u,v,i,j,l,k,z,x,y,len;
    
    string str,ptr;
    
    vector<int>::iterator it;
    
    cin>>x>>a>>b;
    
    if(abs(x-a)>abs(x-b))
    cout<<"B";
    else
    cout<<"A";
     
     
   
    return 0;
}


Measured memory_bytes: 256
import sys

def resolve():
        input = sys.stdin.readline
        N=int(input().rstrip())

        A=[[0] * 3 for i in range(N)]
        for i in range(N):
            A[i][:]=list(map(int,input().rstrip().split()))

        dp=[[0] * 3 for i in range(N)]
        for j in range(3):
            dp[0]=A[0]

        for i in range(1,N,1):
            for j in range(3):
                for k in range(3):
                    if(k!=j):
                        dp[i][j]=max(dp[i][j],dp[i-1][k]+A[i][j])
       
        print(max(dp[N-1]))
          
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
10 40 70
20 50 80
30 60 90"""
        output = """210"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1
100 10 1"""
        output = """100"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1"""
        output = """46"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 76776
#include<iostream>
using namespace std;
int dy[2]={1,0};
int dx[2]={0,1};

int y,x,ny,nx,a,b;
int H,W,N;
int t[1001][1001];
int u[1001][1001];

int main(){
  while(cin>>H>>W>>N&&H&&W&&N){
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++){
	cin>>t[i][j];
	u[i][j]=0;
      }
    }
    u[1][1]=N;
    y=x=1;
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++){
	if(u[i][j]==0)continue;
	a=t[i][j];
	b=1-a;
	ny=i+dy[a],nx=j+dx[a];
	u[ny][nx]+=(u[i][j]-u[i][j]/2);
	ny=i+dy[b],nx=j+dx[b];
	u[ny][nx]+=(u[i][j]/2);
	if(y==i&&x==j){
	  if(u[i][j]%2==1)y=y+dy[a],x=x+dx[a];
	  else y=y+dy[b],x=x+dx[b];
	}
      }
    }
    cout<<y<<' '<<x<<endl;
  }
  return 0;
}

Measured memory_bytes: 8988
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

void solve()
{
    int n;cin>>n;
    int ans=0;
   for(int i=1;i<=n-1;i++)
   {
       int temp=i;
       for(int j=1;j<(double)n/(double)temp;j++)
       {
           ans++;
       }
   }
   cout<<ans;
}
int32_t main() 
{

    rapido;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3648
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort(key=lambda x: (x[1], x[0]))
cnt = 0
for a, b in X:
    if cnt + a <= b:
        cnt += a
    else:
        print('No')
        break
else:
    print('Yes')


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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    st s;
    cin >> s;
    ll a = 0, z = s.size() - 1;
    while(s.at(a) != 'A') a++;
    while(s.at(z) != 'Z') z--;
    cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli n;
	cin>>n;
	vll a(n);
	loop(i, 0, n)	cin>>a[i];
	vector<vector<pii> > dp(n, vector<pii> (n, {0, 0}));
	loop(len, 1, n+1){
		loop(j, len-1, n){
			lli i = j - (len-1);
			if(len == 1)
				dp[i][j] = {a[i], 0};
			else{
				pii t1 = {dp[i+1][j].s + a[i], dp[i+1][j].f};
				pii t2 = {dp[i][j-1].s + a[j], dp[i][j-1].f};
				if(t1.f == t2.f){
					if(t1.s <= t2.s)
						dp[i][j] = t1;
					else
						dp[i][j] = t2;
				}
				else{
					if(t1.f <= t2.f)
						dp[i][j] = t2;
					else
						dp[i][j] = t1;
				}
			}
//			cout<<"("<<dp[i][j].f<<" "<<dp[i][j].s<<") ";
		}
//		cout<<"\n";
	}
	cout<<(dp[0][n-1].f - dp[0][n-1].s)<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 141056
#include<cstdio>
using namespace std;
#define ll long long
int n,k;
ll ans;
int main(void){
	register int i,j;
	scanf("%d%d",&n,&k);
	for(i=k+1;i<=n;++i)
		ans+=(n/i)*(i-k)+(n%i>=k?n%i-k+1-(k==0):0);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
#include<map>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n; cin >> n;
	if (n != 17 && n != 13 && n != 10 && n != 9 && n != 6 && n != 5 && n >= 4)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BMaximumDifference {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    vector<ll> a(n);
	    for(int i=0; i<n; i++){
	        in >> a[i];
	    }

	    sort(a.begin(), a.end());

	    out << a[n-1] - a[0] << endl;
	}
};


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	string s;
	int n;
	cin >> s;
	cin >> n;
	int reverse = 0;
	string begin, end;
	for (int i = 0; i < n; ++i)
	{
		int t;
		cin >> t;
		if (t == 1)
			reverse = !reverse;
		else
		{
			int f;
			char c;
			cin >> f;
			cin >> c;
			if (f == 1)
			{
				if (!reverse)
					begin.push_back(c);
				else
					end.push_back(c);

			}
			else
			{
				if (reverse)
					begin.push_back(c);
				else
					end.push_back(c);

			}
		}
	}
	if (!reverse)
	{
		for (int i = begin.size() - 1; i>=0; --i)
		{
			cout << begin[i];
		}
		for (int i = 0; i < s.size(); ++i)
		{
			cout << s[i];
		}
		for (int i = 0; i < end.size(); ++i)
		{
			cout << end[i];
		}
		cout << endl;
	}
	else
	{
		for (int i = end.size() - 1; i>=0; --i)
		{
			cout << end[i];
		}
		for (int i = s.size()-1; i >= 0; --i)
		{
			cout << s[i];
		}
		for (int i = 0; i < begin.size(); ++i)
		{
			cout << begin[i];
		}
		cout << endl;

	}

	return 0;
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

vector<pair<ll,ll>> range;


int main(){cout<<fixed<<setprecision(10);
		   ll n;
           cin>>n;
           vll t(n),a(n);
           rep(i,0,n)cin>>t[i];
           rep(i,0,n)cin>>a[i];
           range.resize(n);
           ll mn=0,mx=0;
           rep(i,0,n){
             if(t[i]>mx){
              mx=t[i];
              mn=t[i];
             }
             else{
              mn=1; 
             }
             range[i]=mp(mn,mx);
           }
           //a
           mn=0;mx=0;
           rep(i,0,n){
             mn=1;
             
             if(a[n-1-i]>mx){
               mx=a[n-1-i];
               mn=mx;
             }
             ll p,q;
             p=range[n-1-i].first;
             q=range[n-1-i].second;
             if(q<mn||mx<p){
              cout<<0<<endl;
               return 0;
             }
             mn=max(mn,p);
             range[n-1-i]=mp(mn,min(mx,q));
           }
           ll ans=1;
           rep(i,0,n){
            ans*=range[i].second-range[i].first+1;
             ans%=inf;
           }
           cout<<ans<<endl;
}

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

int dfs(vector<string> a,int id){
    int ret;
    if(a[id].back()=='*'){
        ret=1;
        for(int i=id+1;i<a.size();i++){
            if(a[id].size()+1==a[i].size()){
                if(a[i].back()=='+'||a[i].back()=='*'){
                    ret*=dfs(a,i);
                }else{
                    ret*=a[i].back()-'0';
                }
            }else if(a[i].size()<=a[id].size()){
                break;
            }
        }
    }else if(a[id].back()=='+'){
        ret=0;
        for(int i=id+1;i<a.size();i++){
            if(a[id].size()+1==a[i].size()){
                if(a[i].back()=='+'||a[i].back()=='*'){
                    ret+=dfs(a,i);
                }else{
                    ret+=a[i].back()-'0';
                }
            }else if(a[i].size()<=a[id].size()){
                break;
            }
        }
    }else{
        return a[id].back()-'0';
    }
    return ret;
}

int main(){

    while(1){
        int n;
        cin >> n;
        if(n==0)break;
        vector<string> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        int ans=dfs(a,0);
        cout << ans << endl;
    }

    return 0;
}


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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;



//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n,m;
    cin >> n >> m;
    //vector<int> s(m),c(m);
    vector<int> s(m),c(m);
    map<int,int> mp;
    map<int, int>::iterator itr;
    int keta=0;
    int flag=0;
    rep(i,m){
        cin >> s[i] >> c[i];
        if(n>=2&&s[i]==1&&c[i]==0){
            flag=1;
        }
    }

    rep(i,m){
        if(mp.count(s[i])==0){
            mp[s[i]]=c[i];
        }else{
            if(mp[s[i]]!=c[i]){
                flag=1;
            }
        }
    }

    if(flag==1){
        cout << "-1" <<endl;
        return 0;
    }

    int j=0;
    rep(i,n){
        if(mp.count(i+1)==0){
            if(n>=2&&(i+1)==1){
                cout << 1;
            }else{
                cout << 0;
            }
        }else{
            cout << mp[i+1];
        }
    }
}

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

int n, m ;

int a[100010] ;

vector < int > g[100010] ;

bool vis[100010] ;

int group[100010], nGroup ;

void dfs(int u){
	vis[u] = true ; group[u] = nGroup ;
	for (int i = 0; i < (int)g[u].size(); ++ i){
		int v = g[u][i] ;
		if(!vis[v]) dfs(v) ;
		
	}
}

int main(){
	#define NAME ""
	//freopen( NAME".inp" , "r" , stdin ) ; freopen( NAME".out" , "w" , stdout ) ;

	ios_base :: sync_with_stdio(false) ;

	cin >> n >> m ;

	for (int i = 1; i <= n; ++ i) cin >> a[i] ; 

	for (int i = 1; i <= m; ++ i){
		int x, y ; cin >> x >> y ;
		g[x].push_back(y) ; g[y].push_back(x) ;
	}

	for (int i = 1; i <= n; ++ i){
		if(!vis[i]) nGroup ++, dfs(i) ;
	}

	int ans = 0 ;

	for (int i = 1; i <= n; ++ i) if(group[i] == group[a[i]]) ans ++ ;

	cout << ans << endl ;

	return 0 ;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,m,ans=0;
	cin>>n>>m;
	vector<pair<int,int>>ship(m);
	vector<int>s(n),g(n),sg(n);
	rep(i,m){
	    cin>>ship[i].first>>ship[i].second;
	    if(ship[i].first==1)s[ship[i].second]++;
	    else if(ship[i].second==n)g[ship[i].first]++;
	}
	rep(k,n){
	    sg[k]=s[k]*g[k];
	    ans+=sg[k];
	}
	if(ans)cout<<"POSSIBLE";
	else cout<<"IMPOSSIBLE";
	return 0;
}


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

int main() {
  	string S;
    cin >> S;
    int ans , A, B, C, D;
  	A = S[0] - '0';
  	B = S[1] - '0';
  	C = S[2] - '0';
  	D = S[3] - '0';
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                ans = A;
                ans = (i ? ans + B : ans - B);
                ans = (j ? ans + C : ans - C);
                ans = (k ? ans + D : ans - D);

                if (ans == 7) {
                    cout << A << (i ? "+" : "-");
                    cout << B << (j ? "+" : "-");
                    cout << C << (k ? "+" : "-");
                    cout << D << "=7" << endl;
                  return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

int main()
{
	int N, K;

	cin >> N >> K;
	vector<int> h(N);
	for (auto& hi : h)
	{
		cin >> hi;
	}

	vector<int> dp(N);
	dp[1] = abs(h[1] - h[0]);
	for (auto i = 2; i < N; ++i)
	{
		dp[i] = INT_MAX;
		for (auto k = 1; k <= K; ++k)
		{
			if (k > i)
			{
				break;
			}

			dp[i] = min(dp[i - k] + abs(h[i] - h[i - k]), dp[i]);
		}
	}

	cout << dp[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int main() {
	int a, b, c; cin >> a >> b >> c;
	int d = a % b;
	int tmp = 0;
	for (int i = 0; i < 100; i++) {
		tmp = (tmp + d) % b;
		if (tmp == c) {
			cout << "YES" << endl; return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		scanner.close();
		
		String s = null;
		String sb  = null;
		String s1 = null;
		String s3 = null;

		int cnt = 0;
		
	
		for (int i = a; i <= b; i++) {
			s = String.valueOf(i);
			s1 = s.substring(0, 2);
			s3 = s.substring(3, 5);
			StringBuffer reBuff = new StringBuffer(s3).reverse();
			if (s1.equals(reBuff.toString())) {
				cnt++;
			}
			
		}
		
		System.out.println(cnt);
		
	}

}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        string s = sc.Next();

        int answer = 0;
        for (int i = 0; i <= 9; i++)
        {
            for (int j = 0; j <= 9; j++)
            {
                for (int k = 0; k <= 9; k++)
                {
                    if (IsValid(s, i, j, k))
                    {
                        answer++;
                    }
                }
            }
        }

        Console.WriteLine(answer);
    }

    private static bool IsValid(string s, int a, int b, int c)
    {
        if (s.IndexOf(a.ToString()) == -1)
        {
            return false;
        }
        s = s.Substring(s.IndexOf(a.ToString()) + 1);

        if (s.IndexOf(b.ToString()) == -1)
        {
            return false;
        }
        s = s.Substring(s.IndexOf(b.ToString()) + 1);

        if (s.IndexOf(c.ToString()) == -1)
        {
            return false;
        }

        return true;
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 31840