akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
using namespace std;
typedef long long LL;
const int maxN = 2e5 + 7;
const int INF = 1e9 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n;
int depth[maxN];
int sz[maxN], tot;
LL ans;

char s[maxN];
struct Vec {
	static const int maxE = maxN;
	int g[maxN], te; 
	struct edge {int y, nxt;} e[maxE << 1];
	inline void push(int x, int y) { e[++te] = (edge){y, g[x]}; g[x] = te; }
	inline void link(int x, int y) { push(x, y), push(y, x); }
	inline int& operator () (int x) { return g[x]; }
	inline edge& operator [] (int x) { return e[x]; }
}e;

void dfs1(int x, int fa) {
	depth[x] = 1;
	sz[x] = s[x] == '1';
	fore (e, x, y) if (y != fa) {
		dfs1(y, x);
		depth[x] = max(depth[x], depth[y] + 1);
		sz[x] += sz[y];
	}
}

void dfs2(int x, int fa) {
	int mx = 0, sec = 0, id = 0, least = s[x] == '1' ? 0 : INF;
	fore (e, x, y) {
		if (depth[y] > mx) sec = mx, mx = depth[y], id = y;
		else if (depth[y] > sec) sec = depth[y];
		if (s[x] == '0' && sz[y]) least = min(least, depth[y]);
	}
	ans += max(0, min(mx-1, sec+1) - least + 1);
	fore (e, x, y) if (y != fa) {
		sz[x] = tot - sz[y];
		if (y != id) depth[x] = mx+1, dfs2(y, x);
		else depth[x] = sec+1, dfs2(y, x);
	}
}

int main() {
	n = ri();
	For (i, 1, n) e.link(ri(), ri());
	scanf("%s", s+1);
	rep (i, 1, n) if (s[i] == '1') ++ tot;

	dfs1(1, 0);
	dfs2(1, 0);

	printf("%lld\n", ans+1);

	return 0;
}


Measured memory_bytes: 17792
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    String result =  "";
    if(x<1200){
      result = "ABC";
    }else{
     result = "ARC";
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 23764
import _pickle as cPickle

from collections import deque
h,w=map(int,input().split())
p=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
b=cPickle.loads(cPickle.dumps(p, -1))
ans=0
for i in range(1,h+1):
    for j in range(1,w+1):
        p=cPickle.loads(cPickle.dumps(b, -1))
        if p[i][j]=='.':
            s0=i
            s1=j
            p[s0][s1]=0
            d=[(1,0),(-1,0),(0,1),(0,-1)]
            q=deque([[s0,s1]])
            while q:
                x,y=q.popleft()
                for dx,dy in d:
                    if p[x+dx][y+dy]==".":
                        p[x+dx][y+dy]=p[x][y]+1
                        q.append([x+dx,y+dy])
                        if ans<p[x+dx][y+dy]:
                            ans=p[x+dx][y+dy]
print(ans)


Measured memory_bytes: 3444
using System;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        var N = scan.NextInt();
        var T = scan.ArrayInt(N);
        var M = scan.NextInt();
        var sb = new StringBuilder();
        var sum = 0;
        for (int i = 0; i < N; i++) {
            sum += T[i];
        }
        for (int i = 0; i < M; i++) {
            var p = scan.NextInt() - 1;
            var x = scan.NextInt();
            sb.Append(sum - T[p] + x).AppendLine();
        }
        return sb.ToString();
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public int[] ArrayInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = NextInt() + add;
        return array;
    }
}

Measured memory_bytes: 27548
n=int(input())
t,a=map(int,input().split())
H=list(map(int,input().split()))
sub=10000000
x=0
for i in range(n):
  if (a-(t-0.006*H[i]))**2<sub:
    sub= (a-(t-0.006*H[i]))**2
    x=i
  i+=1
print(x+1)

Measured memory_bytes: 3064
from collections import deque

from collections import deque


def main():
    K = int(input())

    q = deque()

    for i in range(1, 10):
        q.append(i)

    while True:
        v = q.popleft()
        K -= 1
        if K == 0:
            print(v)
            exit()
        u = v % 10
        nv = v * 10 + u

        if u == 0:
            q.append(nv)
            q.append(nv + 1)
        elif u == 9:
            q.append(nv - 1)
            q.append(nv)
        else:
            q.append(nv - 1)
            q.append(nv)
            q.append(nv + 1)


main()


Measured memory_bytes: 11876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
string odata;
void solve(){
    if(odata.at(2)==odata.at(3)&&odata.at(4)==odata.at(5)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main(){
    cin>>odata;

    solve();
    return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int N;

    cin >> N;

    vector<vector<int>> F(N, vector<int>(10)), P(N, vector<int>(11));
    rep(i, N) {
        rep(j, 10) {
            cin >> F[i][j];
        }
    }

    rep(i, N) {
        rep(j, 11) {
            cin >> P[i][j];
        }
    }

    int ans = -1000000000;

    for (int i = 1; i < (1 << 10); i++) {
        vector<int> check(N, 0);
        for (int cnt = 0; cnt < 10; cnt++) {
            if (i & (1 << cnt)) {
                rep(j, N) {
                    if (F[j][cnt]) {
                        check[j]++;
                    }
                }
            }
        }
        int value = 0;
        int cnt = 0;
        
        rep(j, N) {
            if (check[j] == 0) cnt++;
            value += P[j][check[j]];
            //cout << j << ":" << P[j][check[j]] << endl;
        }

        if (cnt < N) ans = max(ans, value);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

int main()
{
	int n,x;scanf("%d%d",&n,&x);
	n=2*n-1;
	if (x==1||x==n) {puts("No");return 0;}
	puts("Yes");
	int m=(n+1)/2,k=1;
	if (x==2)
	{
		int k=3;
		for (int i=1;i<m;i++)
		{
			printf("%d\n",k);k++;
		}
		puts("2");puts("1");
		for (int i=1;i<m-1;i++)
		{
			printf("%d\n",k);k++;
		}
		return 0;
	}
	if (x==n-1)
	{
		int k=1;
		for (int i=1;i<m;i++)
		{
			printf("%d\n",k);k++;
		}
		printf("%d\n%d\n",n-1,n);
		for (int i=1;i<m-1;i++)
		{
			printf("%d\n",k);k++;
		}
		return 0;
	}
	for (int i=1;i<m-2;i++)
	{
		if (k==x-2) k=x+3;
		printf("%d\n",k);
		k++;
	}
	for (int i=-2;i<=2;i++) printf("%d\n",x+i);
	for (int i=m+3;i<=n;i++)
	{
		if (k==x-2) k=x+3;
		printf("%d\n",k);
		k++;
	}
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
//#define mp make_pair
#define pb push_back
#define tp make_tuple
#define srt(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr(a) printf("%lld\n",a)
#define r0 return 0
using namespace std;

int main()
{
    ll n,m,i,j,k,t,x,y,d;

    cin>>n;

    k=0;


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

         cin>>x;

        if(i%2 && x%2)k++;
    }

    cout<<k<<endl;

}



Measured memory_bytes: 3644
/*
 * ID: 0002
 * Problem: Digit number
 */

#include <stdio.h>
#include <math.h>

int main(void)
{
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF)
        printf("%d\n", (int)(log10(a+b)) + 1);

    return 0;
}



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 22222;
int N, M;
bool flag[MAX_N];
struct _data{int t, s, d;};

inline bool operator < (const _data& x, const _data& y){ return x.t < y.t; }

int main()
{
  while(cin >> N >> M, N){
    rep(i, N) flag[i] = false;
    vector<_data> data(M);

    rep(i, M) cin >> data[i].t >> data[i].s >> data[i].d;
    sort(ALL(data));

    flag[0] = true;
    rep(i, M) flag[data[i].d - 1] |= flag[data[i].s - 1];

    int res = 0;
    rep(i, N) if(flag[i]) res += 1;

    cout << res << endl;
  }

  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

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

	cout<<n-k+1<<endl;


}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int a;
	int b;
	int s;
		scanf("%d %d", &a,&b);
	s = b;
	for (int i = 1; i < a; i++){
		s = s*(b - 1);
	}
	printf("%d\n", s);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main() {
	while (1) {
		int n; cin >> n; if (n==0) break;
		
		vector<int> score(n);
		for (int i=0; i<n; i++) cin >> score[i];
		
		sort(score.begin(), score.end());
		int sum = 0;
		for (int i=1; i<n-1; i++) sum += score[i];
		cout << sum/(n-2) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#define rep0(i, n) for(int i=0; i<(int)(n);i++)
typedef int64_t lint;
using namespace std;

int main(){
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n);
    rep0(i, n){
        cin >> a[i];
    }
    lint kk = k * (k - 1) / 2;
    lint ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            lint left = 0; //中に
            lint right = 0; //中に
            if(a[i] > a[j]){
                if(i > j)left ++ ;
                if(i < j)right ++ ;
            }
            ans += (right + left) * kk + right * k; //中に
            ans %= 1000000007; //中に
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

//Repeated Substitution with Sed
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			String[] a = new String[n];
			String[] b = new String[n];
			for(int i=0;i<n;i++){
				a[i] = sc.next(); b[i] = sc.next();
			}
			String init = sc.next(), g = sc.next();
			List<String> l = new ArrayList<String>();
			Set<String> set = new HashSet<String>();
			l.add(init); set.add(init);
			int res = -1, step = 0;
			while(!l.isEmpty()){
				List<String> next = new ArrayList<String>();
				for(String s:l){
					if(g.equals(s)){
						res = step; next.clear(); break;
					}
					for(int i=0;i<n;i++){
						String r = "";
						String sub = s;
						while(sub.length()>0){
							if(sub.startsWith(a[i])){
								r+=b[i];
								sub = sub.substring(a[i].length());
							}
							else{
								r+=sub.charAt(0);
								sub = sub.substring(1);
							}
						}
						if(r.length()<=g.length()&&!set.contains(r)){
							next.add(r); set.add(r);
						}
					}
				}
				l = next;
				step++;
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
typedef long long ll;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,a[N];
char s[N];
ll ans;

int main() {
	scanf("%s",s+1),n=strlen(s+1)+1;
	int len=0;
	for(int i=2;i<=n;i++) {
		if(s[i-1]=='<') ++len;
		else len=0;
		a[i]=max(a[i],len);
	}
	len=0;
	for(int i=n-1;i;i--) {
		if(s[i]=='>') ++len;
		else len=0;
		a[i]=max(a[i],len);
	}
	for(int i=1;i<=n;i++) ans+=a[i];
	cout<<ans;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  bool flag = true;
  for (int i = 0; i < N; i++) {
    if (A.at(i) % 2 == 0) {
      if (A.at(i) % 3 != 0 && A.at(i) % 5 != 0) {
        flag = false;
        break;
      }
    }
  }
  if (flag) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 3600
a,c=map(int,input().split())
b,d=map(int,input().split())
T=int(input())
if a<b:
  if a+(c*T)>=b+(d*T):
    print("YES")
  else:
    print("NO")
else:
  if a-(c*T)<=b-(d*T):
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 9192
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll cnt = 0;
ll N;

void solve(){
    if(N % 2 == 1){
        cout << 0 << endl;
        return;
    }

    N /= 2;

    while(N > 0){
        cnt += N / 5;
        N/= 5;
    }
    
    cout << cnt << endl;
}

int main(){
    cin >> N;

    solve();
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    A, B, C = map(int, input().split())

    diff_1 = A * B * (C % 2)
    diff_2 = A * (B % 2) * C
    diff_3 = (A % 2) * B * C
    
    ans = min(diff_1, diff_2, diff_3)
    print(ans)


if __name__ == "__main__":
    main()


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

const int MOD = 1000000007;

class ModInt
{
public:
    int64_t x;
    ModInt(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
    ModInt operator-() const { return ModInt(-x); }
    ModInt &operator+=(const ModInt a)
    {
        if ((x += a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    ModInt &operator-=(const ModInt a)
    {
        if ((x += MOD - a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    ModInt &operator*=(const ModInt a)
    {
        (x *= a.x) %= MOD;
        return *this;
    }
    ModInt operator+(const ModInt a) const { return ModInt(*this) += a; }
    ModInt operator-(const ModInt a) const { return ModInt(*this) -= a; }
    ModInt operator*(const ModInt a) const { return ModInt(*this) *= a; }
    ModInt pow(int64_t n) const
    {
        if (n == 0)
            return 1;
        ModInt t = pow(n >> 1);
        t *= t;
        if (n & 1)
            t *= *this;
        return t;
    }
    ModInt inv() const { return pow(MOD - 2); }
    ModInt &operator/=(const ModInt a) { return *this *= a.inv(); }
    ModInt operator/(const ModInt a) const { return ModInt(*this) /= a; }
};
istream &operator>>(istream &is, const ModInt &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x; }

void solve(int N, vector<int> A)
{
    vector<ModInt> acc(N + 1);
    for (int i = N - 1; i >= 0; i--)
    {
        acc.at(i) = acc.at(i + 1) + A.at(i);
    }
    ModInt res = 0;
    for (int i = 0; i < N - 1; i++)
    {
        res += acc.at(i + 1) * A.at(i);
    }
    cout << res << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18+7107;
int n,a[100005];
ll f[405][405],sum[100005];
ll solve(int l,int r)
{
	if(f[l][r]!=-1) return f[l][r];
	if(l==r) return f[l][r]=0;
	ll ret=INF;
	for(int i=l;i<r;i++) ret=min(ret,solve(l,i)+solve(i+1,r));
	return f[l][r]=ret+sum[r]-sum[l-1];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	memset(f,-1,sizeof(f));
	printf("%lld\n",solve(1,n));
	return 0;
}

Measured memory_bytes: 1536
n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:x[0])

ans = 0
for i in range(n):
    if ab[i][1] < m:
        ans += ab[i][0] * ab[i][1]
        m -= ab[i][1]
    else:
        ans += ab[i][0] * m
        break

print(ans)


Measured memory_bytes: 29788
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define inf 0x3f3f3f3f
#define mod 1000000007
#define N 200005
using namespace std;
using ll = long long;
using vi = vector <int>;
inline int read() {
    int x = 0, f = 1, c = getchar();
    for (;!isdigit(c);c = getchar()) if (c == '-') f = 0;
    for (; isdigit(c);c = getchar()) x = x * 10 + c - 48;
    return f ? x : -x;
}
inline void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    int stk[25], tp = 0;
    if (!x) stk[tp ++] = 0;
    for (; x; x /= 10) stk[tp ++] = x % 10;
    for (; tp; putchar(48 + stk[-- tp]));
}
int qp(int x, int n) {return !n ? 1 : 1LL * qp(1LL * x * x % mod, n >> 1) * (n & 1 ? x : 1) % mod;}
int inv(int x) {return qp(x, mod - 2);}
int fac[N], invfac[N];
void ini() {
    fac[0] = invfac[0] = 1;
    for (int i = 1; i < N; ++ i) {
        fac[i] = 1LL * fac[i - 1] * i % mod;
        invfac[i] = inv(fac[i]);
    }
}
int C(int n, int m) {return 1LL * fac[n] * invfac[m] % mod * invfac[n - m] % mod;}
int main() {
    ini();
    int n, a, b, c; n = read(), a = read(), b = read(), c = read();
    int ans = 0;
    for (int i = 0; i < n; ++ i) {
        int x = 1LL * (n + i) * 100 % mod * inv(100 - c) % mod;
        int y = (1LL * qp(a, n) * qp(b, i) % mod + 1LL * qp(a, i) * qp(b, n) % mod) % mod * qp(inv(a + b), n + i) % mod * C(n + i - 1, n - 1) % mod;
        int cur = 1LL * x * y % mod;
        (ans += cur) %= mod;
    }
    write(ans), putchar(10);
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793
int main(void){
	double a,b,c,d,e,f,h,S,L;
	scanf("%lf %lf %lf",&a,&b,&c);
	h=b*sin(c*PI/180);
	e=180-c-90;
	d=b*sin(e*PI/180);
	f=sqrt(pow(h,2)+pow((a-d),2));
	S=a*h/2;
	L=a+b+f;
	printf("%.8lf\n%.8lf\n%.8lf\n",S,L,h);
	return 0;
}

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

int main(){
	int l,r,d;  cin>>l>>r>>d;
	int cnt=0;
	for(int i=l; i<=r; i++){
		if(i%d==0) cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
  int n,i,j,min=1000000000,cost;
  cin>>n;
  int list[n];
   for(i=0;i<n;i++)
     cin>>list[i];
  sort(list,list+n);
  for(i=list[0];i<=list[n-1];i++)
  {   
      cost=0;
     for(j=0;j<n;j++)
     {
       cost+=pow(i-list[j],2);
     }
    if(cost<min)
       min=cost;
  }
  cout<<min;
  return 0;
}
  
  

Measured memory_bytes: 256
/*Made by Shivam Solanki*/
#include<bits/stdc++.h> 
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define repllr(i,k,n) for (ll i = n; i >= k; --i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;

void solve(){
    int h,a;
    cin>>h>>a;
    int ctr=0;
    while(h>0){
        h-=a;
        ctr++;
    }
    cout<<ctr;
}
    
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    // fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a1, a2 = Array.fill(n)(sc.nextInt())
  val b1 = a1.scanLeft(0)(_ + _).tail
  val b2 = a2.scanRight(0)(_ + _).init
  val ans = b1.zip(b2).map{case (x, y) => x + y}.max
  println(ans)
}

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

int main(){
  int n,sum = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
  }
  for(int i = 0;i<n;i++){
    cin >> b.at(i);
    sum += b.at(i);
  }
  for(int i = 0;i<n-1;i++){
    cin >> c.at(i);
  }
  for(int i = 0;i<n-1;i++){
    if(a.at(i)+1==a.at(i+1)){
      sum += c.at(a.at(i)-1);
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a,b,c;
  cin>>a>>b>>c;
 if(a>=c>0){
   a-=c;
   c=0;
 }
   else if(c>=a>0){
     c-=a;
     a=0;
   }
     if(b>=c>0){
       b-=c;
     }
  else if(c>=b>0){
  b=0;
  }
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
void solve() {
  string cur;
  for (int j = 0; j < m; j++) cur += '0';
  vector<vector<int>> c(m, vector<int>(n, 1));
  while (q--) {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (t[j] != cur[j]) {
          if (s[i] == '0') c[j][i] = 0;
        } else {
          if (s[i] == '1') c[j][i] = 0;
        }
      }
    }
    cur = t;
  }
  string ans;
  for (int j = 0; j < m; j++) {
    int cnt = 0;
    char r;
    for (int i = 0; i < n; i++) {
      cnt += c[j][i];
      if (c[j][i]) {
        if (i < 10) r = i + '0';
        else r = 'A' + i - 10;
      }
    }
    if (cnt > 1) ans += '?';
    else ans += r;
  }
  cout << ans << '\n';
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> n) {
    cin >> m >> q;
    if (n == 0) {
      return 0;
    } else {
      solve();
    }
  }
  return 0;
}


Measured memory_bytes: 3240
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int A,B,K; cin >> A >> B >> K;
    set<int> dic;
    rep(i,K) {
        if (A+i<=B) dic.emplace(A+i);
        if (B-i>=A) dic.emplace(B-i);
    }

    for (auto i : dic) cout << i << ln;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int ans = 0;
    int memo = 0;
    for (int i = 0; i < 5; i++) {
        int dish;
        cin >> dish;
        int memo2 = ((dish - 1) / 10 + 1) * 10;
        ans += memo2;
        memo = max(memo, memo2 - dish);
    }
    cout << ans - memo << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG nikkei2019/a.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int n, a, b;
    cin >> n >> a >> b;
    if(a > b){
        cout << b << " ";
    }else{
        cout << a << " ";
    }
    if(a + b > n){
        cout << a + b - n << "\n";
    }else{
        cout << 0 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque

di = [-1,0,1,0]
dj = [0,-1,0,1]

H,W = map(int, input().split())
si ,sj = map(int, input().split())
ti, tj = map(int, input().split())

si -= 1
sj -= 1
ti -= 1
tj -= 1
inf = 10**9
s = list()
for i in range(H):
  s.append(input())

dist = [[inf] * W for i in range(H)]
q = deque()
dist[si][sj] = 0
q.append([si,sj])

while len(q) > 0:
  tmp = q.popleft()
  i = tmp[0]
  j = tmp[1]
  d = dist[i][j]
  for v in range(4):
    ni = i + di[v]
    nj = j + dj[v]
    if (ni < 0) or (ni >= H) or (nj < 0) or (nj >= W):
      continue
    if s[ni][nj] == '#':
      continue
    if dist[ni][nj] <= d:
      continue
    dist[ni][nj] = d
    q.appendleft([ni,nj])
    
  for ei in range(-2, 3, 1):
    for ej in range(-2, 3, 1):
      ni = i + ei
      nj = j + ej
      if (ni < 0) or (ni >= H) or (nj < 0) or (nj >= W):
        continue
      if s[ni][nj] == '#':
        continue
      if dist[ni][nj] <= d+1:
        continue
      dist[ni][nj] = d+1
      q.append([ni,nj])
    
ans = dist[ti][tj]
if ans == inf:
  ans = -1
print(ans)


Measured memory_bytes: 99192
#include <stdio.h>

#define N 200
#define SHIRO 0
#define HAI 1
#define KURO 2

void aaaaa();
void bbbbb(int);

int n,A[N][N];
int color[N],d[N],f[N];
int TT;

int main() {

  int u,k,v;
  int i,j;


  scanf("%d",&n);

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

  aaaaa();

  return 0;
}


void aaaaa() {
  int u,i;

  for(i=0;i<n;i++){
    color[i] = SHIRO;
  }
    
  TT = 0;

  for(u=0;u<n;u++){
    if(color[u] == SHIRO){
      bbbbb(u);
    }
  }

  for(i = 0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}

void bbbbb(int k) {
  int v;
  color[k] = HAI;
  TT++;
  d[k] = TT;
  for(v=0;v<n;v++){
    if(A[k][v] == 0) continue;
    if(color[v] == SHIRO){
      bbbbb(v);
    }
  }
  color[k] = KURO;
  f[k] = ++TT;
}

Measured memory_bytes: 676
#include <iostream>

int main() {
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    std::cout << (std::abs(c - a) > d ? (std::abs(b - a) <= d && std::abs(c - b) <= d ? "Yes" : "No") : "Yes") << std::endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))

a_dict = {}
for a in a_list:
    if not(a in a_dict):
        a_dict[a] = 0
    a_dict[a] += 1
    
ans = sum(map(lambda x: x*(x-1)//2, a_dict.values()))

for i in range(n):
    k = a_list[i]
    before = a_dict[k]*(a_dict[k]-1) // 2
    after = (a_dict[k]-1)*(a_dict[k]-2) // 2
    print(ans - (before - after))

Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
int main(){
    int i, n, l[10000], ans=0, j, k;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> l[i];
        }
    
    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
            for(k=j+1;k<n;k++){
                if((l[i]!=l[j] && l[i]!=l[k] && l[j]!=l[k]) 
                && (l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j])) ans++;
            }
        }
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

typedef vector<int> V;
typedef queue<V> Q;
typedef map<V, int> M;

class Solver {
    private:
        M min_count;
    public:
        Solver() {
            V p0(8);
            Q q;
            int zi;
            for (int i = 0; i < 8; ++i) {
                p0[i] = i;
            }
            q.push(p0);
            min_count[p0] = 0;
            while (!q.empty()) {
                V p = q.front();
                int n = min_count[p];
                q.pop();
                zi = 0;
                while (p[zi] != 0) {
                    ++zi;
                }
                if (zi != 0 && zi != 4) {
                    V p2 = p;
                    swap(p2[zi], p2[zi - 1]);
                    if (min_count.find(p2) == min_count.end()) {
                        min_count[p2] = n + 1;
                        q.push(p2);
                    }
                }
                if (zi != 3 && zi != 7) {
                    V p2 = p;
                    swap(p2[zi], p2[zi + 1]);
                    if (min_count.find(p2) == min_count.end()) {
                        min_count[p2] = n + 1;
                        q.push(p2);
                    }
                }
                if (zi < 4) {
                    V p2 = p;
                    swap(p2[zi], p2[zi + 4]);
                    if (min_count.find(p2) == min_count.end()) {
                        min_count[p2] = n + 1;
                        q.push(p2);
                    }
                } else {
                    V p2 = p;
                    swap(p2[zi], p2[zi - 4]);
                    if (min_count.find(p2) == min_count.end()) {
                        min_count[p2] = n + 1;
                        q.push(p2);
                    }
                }
            }
        }
        int solve(int puzzle[]) {
            V p(8);
            for (int i = 0; i < 8; ++i) {
                p[i] = puzzle[i];
            }
            return min_count[p];
        }
};

int main() {
    int puzzle[8];
    Solver s;
    while (true) {
        for (int i = 0; i < 8; ++i) {
            cin >> puzzle[i];
        }
        if (cin.eof()) {
            return 0;
        }
        cout << s.solve(puzzle) << endl;
    }
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
    ll n; cin >> n;

    vector<ll> lucas(n + 1);
    lucas[0] = 2;
    lucas[1] = 1;

    for (ll i = 2; i <= n; ++i) {
        lucas[i] = lucas[i - 1] + lucas[i - 2];
    }
    print(lucas[n]);
}

Measured memory_bytes: 256
import java.util.Scanner;
   
class Main{
 public static void main(String[] arge){
     
 Scanner sc=new Scanner(System.in);
   
 int x=sc.nextInt();
 int y=sc.nextInt();
 
 int a=x/y;
 int b=x%y;
 

System.out.println(a+" "+b+" "+String.format("%.8f", (double)x/(double)y));
}}



Measured memory_bytes: 26548
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    string op; 
    
    
    while(true){
        cin >> a >> op >> b;
        
        if (op=="?"){
            break;   
        }else if(op=="+"){
            cout << a+b << endl;            
        }else if(op=="-"){
            cout << a-b << endl;            
        }else if(op=="*"){
            cout << a*b << endl;            
        }else{
            cout << a/b << endl;            
        }
    }

    return 0;
}



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

using namespace std;

#define M_DEBUG if (0)

/******************************************************************************
	typedef
******************************************************************************/
typedef unsigned long long int ullint;

/******************************************************************************
	関数テンプレ
******************************************************************************/

/*! n 以下の素数を取得 */
void getPrimes(ullint n, vector<ullint> *primes)
{
	primes->push_back(2);
	for (ullint i = 3; i <= n; i++)
	{
		bool is_prime = true;
		for (auto a : *primes)
		{
			if (i % a == 0)
			{
				is_prime = false;
				break;
			}
		}
		if (is_prime)
		{
			primes->push_back(i);
		}
	}
}

/*! n が素数かどうか判定する*/
bool isPrime(ullint n)
{
	vector<ullint> primes;
	getPrimes(sqrtl(n), &primes);
	bool is_prime = true;
	for (auto a : primes)
	{
		if (n % a == 0)
		{
			is_prime = false;
		}
	}
	return is_prime;
}

/******************************************************************************
	Main
******************************************************************************/
int main()
{
    int x = -1;
    cin >> x;
    assert(x >= 0 && x <= 100000);

    vector<ullint> primes;

    getPrimes(2*x, &primes); // 2はでかくない？sqrt(3)くらいでいいんだけど。多分。
    for (auto i : primes) {
    	if (i >= x) {
            cout << i << endl;
            break;
        }
    }
	return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1
#define j0 gray_cat_j0

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
ll MOD;

const int MAXN = 2e3 + 5;

ll c[3 * MAXN][3 * MAXN];

ll dp3[3 * MAXN], dp2[3 * MAXN];

void solve(){
	int n;
	cin >> n >> MOD;
	REPN(i, 0, 3 * n) {
		c[i][0] = c[i][i] = 1;
		REP(j, 1, i) {
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
		}
	}
	dp2[0] = dp3[0] = 1;
	REPN(i, 1, n) {
		dp2[i] = (dp2[i - 1] * (2 * i - 1)) % MOD;
		dp3[i] = (dp3[i - 1] * (3 * i - 1) * (3 * i - 2)) % MOD;
	}
	ll ans = 0ll;
	REPN(i, 0, n) {
		ll mul = (c[3 * n][3 * n - 3 * i] * dp3[n - i]) % MOD;
		ll add = 0ll;
		REPN(j, 0, i) {
			add = (add + c[3 * i][2 * j] * dp2[j]) % MOD;
		}
		ans = (ans + add * mul) % MOD;
	}
	cout << ans << endl;
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

A = [int(x) for x in input().split()]

x = 0
y = 0
for a in range(0,N):
  if a in A and a < X:
    x += 1
  elif a in A and X < a:
    y += 1
  else:
    continue

print(x if x < y else y)

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

int N;
int main (){
    cin >> N;
    int T[N];
    int sum = 0;
    for(int i=1; i<N+1; i++){
        cin >> T[i];
        sum += T[i];
    }
    int M;
    cin >> M;
    for(int i=0; i<M; i++){
        int P,X;
        cin >> P >> X;
        cout << sum - ( T[P] - X )<< endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
a=Base_10_to_n(N,K)
print(len(a))

Measured memory_bytes: 3060
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int H,W,K;
    cin>>H>>W>>K;
    auto S=make_vec<char>(H,W);
    REP(i,H){
        REP(j,W){
            cin>>S[i][j];
        }
    }

    int ans=INF;
    int tmp;
    REP(bit,1<<H-1){
        bool flag=false;
        int num=1;
        REP(i,H-1){
            if(bit&(1<<i)) num++;
        }
        tmp=num-1;
        vector<vector<int>> sum(num,vector<int>(W+1,0));
        int cnt=0;
        REP(i,H){
            REP(j,W){
                if(S[i][j]=='1') sum[cnt][j+1]++;
            }
            if(bit&(1<<i)) cnt++;
        }

        REP(i,num){
            REP(j,W){
                sum[i][j+1]+=sum[i][j];
                if(sum[i][j+1]-sum[i][j]>K) flag=true;
            }
        }
        if(flag) continue;

        int l;
        l=0;
        REP2(r,1,W+1){
            REP(i,num){
                if(sum[i][r]-sum[i][l]>K){
                    tmp++;
                    l=r-1;
                    break;
                }
            }
        }
        ans=min(tmp,ans);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline())
M = [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        v -= 1
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt)
for i in range(0, n):
    if not sndf[i][0]:
        dfs(i)
    print(*sndf[i][1:])

Measured memory_bytes: 7840
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  string s;
  cin >> n >> s;
  int r = 0;
  rep(i, 0, n) {
    if(s[i] == 'R') r++;
  }
  if((n - r) < r) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}


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

int n, m;
int map[9][9];
int a, b;
int list[9];
int ans = 0;

void search(int c, int l) {
  int i;
  if (list[l] == 1) {
    return;
  } else {
    list[l] = 1;
  }
  if (c == n) {
    ans++;
    list[l] = 0;
    return;
  }

  for (i = 1; i <= n; i++) {
    if (map[l][i] == 1) {
      search(c + 1, i);
    }
  }
  list[l] = 0;
  return;
}

int main() {
  int i, j;

  for (i = 0; i < 9; i++) {
    for (j = 0; j < 9; j++) {
      map[i][j] = 0;
    }
    list[i] = 0;
  }
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    map[a][b] = 1;
    map[b][a] = 1;
  }

  search(1, 1);

  printf("%d", ans);

  return 0;
}

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

string A, B, C;

int main(void){
	cin >> A >> B >> C;
	if(A[A.length() - 1] == B[0] && B[B.length() - 1] == C[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define N 100000
using namespace std;
int PSTs[N+1];
int PSTt[N+1];
string s, t;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> s >> t;
	int n = s.length();
	s = "$"+s;
	t = "$"+t;

	PSTs[0] = PSTt[0] = 0;
	for(int i = 1; i <= n; i++)
	{
		PSTs[i] = PSTs[i-1]+(s[i]=='A' ? 1 : -1);
		PSTt[i] = PSTt[i-1]+(t[i]=='A' ? 1 : -1);
	}

	int Q; cin >> Q;
	while(Q--)
	{
		int a, b, c, d; cin >> a >> b >> c >> d;
		cout<<(((PSTs[b]-PSTs[a-1])-(PSTt[d]-PSTt[c-1]))%3==0 ? "YES" : "NO")<<'\n';
	}
	cout<<flush;
	return 0;
}

Measured memory_bytes: 1644
#include <stdio.h>

int main(void)
{
	int a,b;
	
	scanf("%d",&a);
	
	scanf("%d",&b);
	
	if(a>b)
	printf("a > b\n");
	
	else if(a==b)
	printf("a == b\n");
	
	else
	printf("a < b\n");
	
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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


  ll x;
  cin>>x;
  ll ans=8-(x-400)/200;
  cout<<ans<<endl;
}



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

typedef long long ll;
ll mod=1e9+7;

int main(){
  ll n;
  cin >> n;
  ll a[n],b[n];
  for(ll i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  ll x[n];
  for(ll i=0;i<n;i++){
    x[i]=b[i]*mod-a[i];
  }
  sort(x,x+n);
  for(ll i=0;i<n;i++){
    a[i]=(mod-(x[i]%mod))%mod;
    b[i]=(x[i]+a[i])/mod;
  }
  bool ans=true;
  ll sum=0;
  for(ll i=0;i<n;i++){
    sum+=a[i];
    if(sum>b[i]) ans=false;
  }
  cout << (ans?"Yes":"No") << endl;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int H, W, D;
	cin >> H >> W >> D;

	pair<int, int> A[H * W + 1];
	rep(i, 0, H) rep(j, 0, W) {
		int a;
		cin >> a;
		A[a] = make_pair(i, j);
	}

	int dp[H * W + 1];
	rep(i, 1, H * W + 1) {
		if(i <= D) dp[i] = 0;
		else {
			int x1 = A[i - D].first, y1 = A[i - D].second;
			int x2 = A[i].first, y2 = A[i].second;

			dp[i] = dp[i - D] + abs(x2 - x1) + abs(y2 - y1);
		}
	}

	int Q;
	cin >> Q;

	rep(i, 0, Q) {
		int L, R;
		cin >> L >> R;
		cout << dp[R] - dp[L] << endl;
	}

}


Measured memory_bytes: 2176