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

int main()
{
  int n;
  cin >> n;
  for(int i = 1; i <= 9; i++)
  {
    for(int j = 1; j <= 9; j++)
    {
		if(n == i * j)
        {
          cout << "Yes" << endl;
          return 0;
        }	
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
from _collections import deque

K = int(input())
c = 9
A = [1,2,3,4,5,6,7,8,9]
q = deque(A)

if K <= 9:
    print(K)
else:
    while(True):
        a = q.popleft()
        if a % 10 == 0:
            c += 1
            if c == K:
                print(a*10)
                sys.exit()
            q.append(a*10)
            c += 1
            if c == K:
                print(a*10+1)
                sys.exit()
            q.append(a*10+1)
        elif a % 10 == 9:
            c += 1
            if c == K:
                print(a*10+9-1)
                sys.exit()
            q.append(a*10+9-1)
            c += 1
            if c == K:
                print(a*10+9)
                sys.exit()
            q.append(a*10+9)
        else:
            c += 1
            if c == K:
                print(a*10+a%10-1)
                sys.exit()
            q.append(a*10+a%10-1)
            c += 1
            if c == K:
                print(a*10+a%10)
                sys.exit()
            q.append(a*10+a%10)
            c += 1
            if c == K:
                print(a*10+a%10+1)
                sys.exit()
            q.append(a*10+a%10+1)

Measured memory_bytes: 41328
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int r; cin >> r; cout << 3 * r * r << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long

int main(void){
  ll x;
  cin>>x;
  ll sum1;
  for(ll sum11=0;sum11<100000;sum11++){
    if(100*sum11<=x && x <= 105*sum11){
      cout<<1<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 256
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000003
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
ll fact[mod+1];
ll modexp(ll a, ll b)
{
	a%=mod;
	if(a<=1)return a;
	if(b==0)return 1;
	if(b%2==0)
	{
		ll val=modexp(a,b/2);
		return (val*val)%mod;
	}
	return (a*modexp(a,b-1))%mod;
}

int main()
{
	sync;
	ll t;
	cin>>t;
	fact[0]=1;
	for(ll i=1;i<mod+1;i++)
	fact[i]=(fact[i-1]*i)%mod;
	while(t--)
	{
		ll x,n,d;
		cin>>x>>d>>n;
		if(d==0)
		{
			cout<<modexp(x,n)<<"\n";
			continue;
		}
		if(n>=mod)
		{
			cout<<0<<"\n";
			continue;
		}
		ll ans=modexp(d,n);
		ll val=(x*modexp(d,mod-2))%mod;
		if((val+1)>mod||(val+n-1)<mod)
		{
			ans=ans*(fact[(val+n-1)%mod]*(modexp(fact[(val-1)%mod],mod-2)))%mod;
			ans%=mod;
		}
		else
		ans=0;
		cout<<ans<<"\n";
	}
}


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

const string searchingString = "AC";

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

    vector<int> ACnumVec(1, 0);

    bool isPrevA = false;
    int ACnum = 0;
    for (const char &singleChar : s)
    {
        if (singleChar == 'A')
        {
            isPrevA = true;
        }
        else if (isPrevA && singleChar == 'C')
        {
            ++ACnum;
            isPrevA = false;
        }
        else
        {
            isPrevA = false;
        }

        ACnumVec.push_back(ACnum);
    }

    vector<int> ansVec;

    for (int i = 0; i < q; ++i)
    {
        int l, r;
        cin >> l >> r;

        int singleAns = ACnumVec.at(r) - ACnumVec.at(l);

        ansVec.push_back(singleAns);
    }

    for (const int &singleAns : ansVec)
    {
        cout << singleAns << endl;
    }
}

Measured memory_bytes: 1976
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll t;
    //cin>>t;
    //while(t--)
    {
      ll i,j,k,l,m,n,a,b,d,c,cnt=0,o=1;
        cin>>a>>b>>c>>d;
        while(a>0 && c>0)
        {
            if(o==1)
            {
                c=c-b;
                o=2;
            }
            else
            {

                a=a-d;
                o=1;
            }



        }
        if(c<=0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }


}


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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long max;
  max = a*c;
  if (max < a*d) {
    max = a*d;
  }
  if (max < b*c) {
    max = b*c;
  }
  if (max < b*d) {
    max = b*d;
  }

  cout << max << endl;
}


Measured memory_bytes: 3632
MOD = 10**9 + 7
H, W, K = map(int,input().split())
dp = [[0 for k in range(W)] for l in range(H+1)]
dp[0][0] = 1
A = []  # ありうる横棒のリスト
for b in range(2**(W-1)):
    if "11" not in bin(b):
        A.append(bin(b)[2:].zfill(W-1))

for k in range(H):
    for e in A:
        for i in range(W):
            if i < W-1 and e[i] == "1": # 右に行くパターン
                dp[k+1][i+1] += dp[k][i]
                dp[k+1][i+1] %= MOD
            elif i >= 1 and e[i-1] == "1": # 左に行くパターン
                dp[k+1][i-1] += dp[k][i]
                dp[k+1][i-1] %= MOD
            else:
                dp[k+1][i] += dp[k][i]
                dp[k+1][i] %= MOD

print(dp[H][K-1])


Measured memory_bytes: 41712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll w;cin>>w;
    if(n<=w) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = 0
b = 0
c = 0
d = 0
for i in range(n):
    s = str(input())
    if s == 'AC' :
        a += 1
    elif s == 'WA':
        b += 1
    elif s == 'TLE':
        c += 1
    else:
        d += 1
print('AC x {}'.format(a))
print('WA x {}'.format(b))
print('TLE x {}'.format(c))
print('RE x {}'.format(d))

Measured memory_bytes: 9220
#include<iostream>
#include<cstdio>
using namespace std;
int n,a,b,c,Ans;
int main()
{
	scanf("%d",&n);
	a=1000000001;b=1;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&c);
		if (b)
		{
			if (b==1)
				{
					if (c>=a) a=c;else a=c,b=0,Ans++;
				}
			else
			{
				if (c<=a) a=c;else a=c,b=0,Ans++;
			}
		}
		else
		{
			if (a==c) continue;
			b=a<c?1:2;
			a=c;
		}
	}
	printf("%d\n",Ans);
}

Measured memory_bytes: 256
def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


N = int(input())

result = []
prime_table = make_prime_table(55555)
for i in range(3, 55555 + 1, 2):
    if prime_table[i] == i and i % 5 == 1:
        result.append(i)
    if len(result) == N:
        break
print(*result)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

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

ll mod = 998244353;

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

  int k;
  cin >> k;
  if(k <= 9){cout << k << endl;return 0;}
  vvi dp(k,vi(10));
  vi sum(k+1);
  rep(i,10){
    dp[1][i] = 1;
  }
  sum[1] = 9;
  int num = 1;
  for(num = 2;num <= k;num++){
    sum[num] = sum[num-1];
    rep(d,10){
      dp[num][d] = dp[num-1][d];
      if(d){
        dp[num][d] += dp[num-1][d-1];
      }
      if(d < 9){
        dp[num][d] += dp[num-1][d+1];
      }
      if(d)sum[num] += dp[num][d];
    }
    if(sum[num] >= k)break;
  }
  string ret = "";
  int cnt = sum[num-1];
  int prev = 0;
  for(int d = 1;d <= 9;d++){
    if(cnt + dp[num][d] >= k){
      prev = d;
      ret += '0'+d;
      break;
    }
    else cnt += dp[num][d];
  }
  num--;
  while(num){
    for(int d = prev - 1;d <= prev + 1;d++){
      if(d >= 0 && d <= 9){
        if(cnt + dp[num][d] >= k){
          prev = d;
          ret += '0'+d;
          break;
        }else{
          cnt += dp[num][d];
        }
      }
    }
    num--;
  }
  cout << ret << endl;
}

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

using namespace std;
#define LL long long

const int MAXN = 212345;

LL n, v[MAXN];

// last position < k

LL bs (LL k) {
	
	LL l = 0, r = n - 1, best = -1; 
	
	while (l <= r)  {

		LL m = (l + r) / 2;

		if (v[m] < k) {
			best = m;
			l = m + 1;
		}	
		else {
			r = m - 1;
		}
	}

	return best;
}

int main () {

	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n;

	for (int i = 0; i < n; ++i) cin >> v[i];

	sort (v, v + n);

	LL cnt = 0;

	for (LL k = 1; k <= v[n-1]; ++k) {
		
		LL p = bs (k);

		// cout << p << '\n';



		if (p + 1 == n - 1 - p) ++cnt;
	}

	cout << cnt << '\n';




	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;


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

Measured memory_bytes: 256
import kotlin.math.max

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    var ans = 0L
    for (i in 1 until n) {
        val d = max(a[i - 1] - a[i], 0)
        a[i] += d
        ans += d
    }
    println(ans)
}


Measured memory_bytes: 64744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		double a = 0;
		double b = 0;

		Scanner in = new Scanner(System.in);

		a = in.nextDouble();
		b = in.nextDouble();

		int d = (int) (a / b);
		int r = (int) (a % b);
		double f = a / b;

		String F = String.format("%f", f);

		System.out.println(d + " " + r + " " + F);

	}

}

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

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

    vector<bool> trick(N+1, false);
    trick[0] = true;

    for(int i=0; i<K; i++){
        int d;
        cin >> d;

        for(int j=0; j<d; j++){
            int A;
            cin >> A;

            trick[A] = true;
        }
    }

    int ans = 0;

    for(int i=0; i<=N; i++){
        if(!trick[i]) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
function main (input) {
    var N = parseInt(input,10);
    const keta = input.split('').length
    var tmp = N;
    var sum = 0;
    var ans;

    for (var n = 0; n < keta; n ++) {
        sum = sum + Math.floor(tmp%10);
        tmp = Math.floor(tmp/10);
    }

    if (N%sum === 0) {
        ans = 'Yes';
    } else {
        ans = 'No';
    }
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
N = int(input())
Wx = list(map(int, input().split()))

allSum = sum(Wx)
abs_val = allSum

for i in range(N):
    W_1 = Wx[i:]
    W_2 = Wx[:i]
    
    test = abs(sum(W_1) - sum(W_2))
    if test < abs_val:
        abs_val = test
    
print(abs_val)

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

int main(){
    long long int a,b,k;
    cin>>a>>b>>k;
    if(a+b<=k){
        a=0;
        b=0;
    }else if (k>=a && a+b>=k){
        b=a+b-k;
        a=0;
    }else{a=a-k;}
    cout<<a<< " "<<b<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int k = n;
  int sum=0;
  while (k>0)
  {
    sum+=k%10;
    k/=10;
  }
  if (n%sum==0) cout << "Yes"; else cout << "No";
  return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Flat Subsequence
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 300000;
const int MAX_A = 300000;
const int MAX_E2 = 1 << 20; // = 1048576

/* typedef */

template <typename T, const int MAX_E2>
struct SegTreeMax {
  int e2;
  T nodes[MAX_E2], defv;
  SegTreeMax() {}

  void init(int n, T _defv) {
    defv = _defv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(nodes, nodes + MAX_E2, defv);
  }

  T &get(int i) { return nodes[e2 - 1 + i]; }

  void set(int i, T v) {
    int j = e2 - 1 + i;
    nodes[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      nodes[j] = max(nodes[j * 2 + 1], nodes[j * 2 + 2]);
    }
  }

  T max_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return defv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = max_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = max_range(r0, r1, k * 2 + 2, im, i1);
    return max(v0, v1);
  }
  T max_range(int r0, int r1) { return max_range(r0, r1, 0, 0, e2); }
};

/* global variables */

int as[MAX_N];
SegTreeMax<int,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int maxa = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", as + i);
    if (maxa < as[i]) maxa = as[i];
  }

  st.init(maxa + 1, 0);

  for (int i = 0; i < n; i++) {
    int d = st.max_range(max(0, as[i] - k), min(maxa, as[i] + k) + 1);
    st.set(as[i], d + 1);
    //printf("%d: %d: %d\n", i, as[i], d + 1);
  }

  printf("%d\n", st.max_range(0, maxa + 1));
  return 0;
}


Measured memory_bytes: 9096
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    X = int(input().rstrip())
    i = 0
    sum = i
    while True:
        if X <= sum: 
            ans = i
            break
        else:
            i+=1
            sum += i

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


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

ll mod = 998244353;

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll R=0, G=0, B=0, RG=0, GB=0, RB=0;
    ll ans = 1;
    for (int i = 0; i < 3*N; i++) {
        if (S[i] == 'R') {
            if (GB > 0) {
                ans = ans * GB % mod;
                GB--;
            }else if (B > 0) {
                ans = ans * B % mod;
                RB++;
                B--;
            }else if (G > 0) {
                ans = ans * G % mod;
                RG++;
                G--;
            }else R++;
        }
        if (S[i] == 'G') {
            if (RB > 0) {
                ans = ans * RB % mod;
                RB--;
            }else if (B > 0) {
                ans = ans * B % mod;
                GB++;
                B--;
            }else if (R > 0) {
                ans = ans * R % mod;
                RG++;
                R--;
            }else G++;
        }
        if (S[i] == 'B') {
            if (RG > 0) {
                ans = ans * RG % mod;
                RG--;
            }else if (R > 0) {
                ans = ans * R % mod;
                RB++;
                R--;
            }else if (G > 0) {
                ans = ans * G % mod;
                GB++;
                G--;
            }else B++;
        }
    }
    
    
    for (int i = 1; i <= N; i++) ans = ans * i % mod;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 900
N = int(input())
S = input()

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a = [i, j, k]
            l = 0
            for s in S:
                if l < 3  and a[l] == int(s):
                    l += 1
            if l == 3:
                ans += 1

print(ans)


Measured memory_bytes: 74196
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
from itertools import product as pr
x=-10**9
for ch in list(pr([0,1],repeat=10)):
  if 1 not in ch:
    continue
  s=0
  for j in range(n):
    c=0
    t=f[j]
    for k in range(10):
      if ch[k] and t[k]:
        c+=1
    s+=p[j][c]
  x=max(x,s)
print(x)

Measured memory_bytes: 3188
n,l = map(int,input().split())
ntaste = 0

for i in range(1,n+1):
    ntaste += (l+i-1)

if l > 0:
    ans = ntaste - l
elif l+n-1 < 0:
    ans = ntaste - (l+n-1)
else:
    ans = ntaste

print(ans)

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

typedef long long ll;

int N;

void dfs(string s, char mx) {
    if (s.length() == N) {
        printf("%s\n", s.c_str());
    } else {
        for (char c='a'; c<=mx; c++) {
            dfs(s+c, ((c==mx) ? (char)(mx + 1) : mx));
        }
    }
}

int main() {
    cin >> N;
    dfs("", 'a');
    return 0;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void dfs(const vector<vector<int>>& edges, vector<int>& ds, vector<int>& fs, int u, int& t) {
    if (ds[u] > 0) {
        return;
    }
    ds[u] = ++t;
    for (auto v : edges[u]) {
        dfs(edges, ds, fs, v, t);
    }
    fs[u] = ++t;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            edges[u].push_back(v);
        }
        sort(begin(edges[u]), end(edges[u]));
    }
    vector<int> ds(n, -1);
    vector<int> fs(n, -1);
    int t = 0;
    for (int i = 0; i < n; i++) {
        dfs(edges, ds, fs, i, t);
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << ds[i] << " " << fs[i] << endl;
    }
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n);
    for (int i=0; i<k; ++i) {
        int d;
        cin >> d;
        for (int j=0; j<d; ++j) {
            int a;
            cin >> a;
            ++cnt.at(a-1);
        }
    }
    cout << count(cnt.begin(), cnt.end(), 0) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3492
#include <stdio.h>
#include <stdlib.h>

void cmon(int n,int m);

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    cmon(n,m);
    return(0);
}

void cmon(int n,int m){
    int h[n];
    int dai[n];
    int i;
    int tmp1,tmp2;
    int cnt=0;

    for(i = 0; i < n; i++){
        dai[i]=1;
    }
    for(i = 0; i < n; i++){
        scanf("%d",&h[i]);
    }
    for(i = 0; i < m; i++){
        scanf("%d %d",&tmp1,&tmp2);
        if(h[tmp1-1] < h[tmp2-1]){
            dai[tmp1-1]--;
        }else if(h[tmp1-1] > h[tmp2-1]){
            dai[tmp2-1]--;
        }else{
            dai[tmp1-1]--;
            dai[tmp2-1]--;
        }
    }
    for(i = 0; i < n; i++){
        if(dai[i] > 0){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1000000007;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

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; }

int N;

int main() {
  cin >> N;

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

  vector<int> dp(N, INF);
  dp[0] = 0;
 
  for(int i = 1; i < N; i++) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if(i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }

  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
# ペアの数だけsetで消されるからn-len(s)で差を取るとペアの数がとってこれる
# sortedとset({}で表される)がキーになっている
s = {tuple(sorted([a[i],i+1]))for i in range(n)}
print(n-len(s))

Measured memory_bytes: 22500
#![allow(unused)]

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

const INI: u64 = 1_000_000;

use std::cmp::*;

fn main() {
    input! {
        n: usize,
    }

    let mut y: BTreeSet<usize> = BTreeSet::new();

    for i in 0.. {
        if 6_usize.pow(i) > 100_000 {
            break;
        }
        y.insert(6_usize.pow(i));
    }

    for i in 0.. {
        if 9_usize.pow(i) > 100_000 {
            break;
        }
        y.insert(9_usize.pow(i));
    }

    //let y: Vec<u64> = y.iter().collect::<Vec<u64>>();
    let mut unit = Vec::new();

    for e in y {
        unit.push(e);
    }

    let mut dp = vec![INI; n + 1];

    dp[0] = 0;
    dp[1] = 1;

    for i in 0..n + 1 {
        for j in unit.iter() {
            if i + j > n {
                break;
            } else {
                dp[i + j] = min(dp[i + j], dp[i] + 1);
            }
        }
    }

    println!("{}", dp.last().unwrap());
}

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

int main()
{
  long n,m,a,ans=0,tmp,pre=0;
  map<long,unsigned> mp;
  cin >> n >> m;
  for(int i=0;i<n;i++)
  {
    cin >> tmp;
    a = tmp%m;
    tmp = (pre+a)%m;
    mp[pre]++;
    ans+=mp[tmp];
    pre = tmp;
    /*
    if(a[i]!=0)
    {
      preans=0;
      for(int j=0;j<i;j++)
      {
        a[j]=(a[j]+a[i])%m;
        if(a[j]==0)preans++;
      }
    }
    ans+=preans;
    */
  }

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


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int h, w, x, y;
  cin >> h >> w >> x >> y;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      cout << (j < x ^ i < y);
    cout << endl;
  }
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

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

int main() {
  ll t;
  cin >> t;
  while(t--) {
    ll f,e,l,a;
    cin >> f >> e >> l >> a;
    ll flag=1;
    if(f<e) flag=0;
    if(a<e) flag=0;
    if(flag&&l<e) {
      ll g=gcd(e,a);
      if(e-g+(f%g)>l) {
        flag=0;
      }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import Control.Applicative

main = do (a:b:c:_) <- map read . words <$> getLine
          let h = b * sin (pi*c/180)
              s = a*h/2
              l = a + b + sqrt (a**2 + b**2 - 2*a*b*(cos (pi*c/180)))
          putStr . unlines . map show $ [s,l,h]

Measured memory_bytes: 4064
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;



void _main() {
    string S;
    cin >> S;
    if (S == "SUN") cout << 7 << endl;
    if (S == "MON") cout << 6 << endl;
    if (S == "TUE") cout << 5 << endl;
    if (S == "WED") cout << 4 << endl;
    if (S == "THU") cout << 3 << endl;
    if (S == "FRI") cout << 2 << endl;
    if (S == "SAT") cout << 1 << endl;

}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

#define mt make_tuple
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<vi> A(N, vi(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  vi freq(M);
  vi idx(N);
  vi banned(M);
  for (int i = 0; i < N; i++) {
    freq[A[i][0]]++;
    idx[i] = 0;
  }
  int ans = *max_element(ALL(freq));
  for (;;) {
    int pos = -1;
    for (int i = 0; i < M; i++) {
      if (banned[i]) {
        continue;
      }
      if (pos == -1 || freq[i] > freq[pos]) {
        pos = i;
      }
    }
    int largestFreq = freq[pos];
    bool can = true;
    debug printf("ban %d\n", pos + 1);
    banned[pos] = true;
    for (int i = 0; i < N; i++) {
      if (A[i][idx[i]] == pos) {
        while (idx[i] < M && banned[A[i][idx[i]]]) {
          idx[i]++;
        }
        if (idx[i] == M) {
          can = false;
          break;
        }
        freq[A[i][idx[i]]]++;
      }
    }
    if (!can) {
      break;
    }
    int curMax = -1;
    for (int i = 0; i < M; i++) {
      if (!banned[i]) {
        curMax = max(curMax, freq[i]);
      }
    }
    ans = min(ans, curMax);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; j < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  string S;
  cin >> S;
  int oddb = 0,evenb = 0,oddw = 0,evenw = 0;
  int N = sz(S);
  rep(i,N) {
    if(i % 2 == 0) {
      if(S[i] == '0') {
        evenb++;
      } else {
        evenw++;
      }
    } else {
      if(S[i] == '0') {
        oddb++;
      } else {
        oddw++;
      }
    }
  }
  int ans = 0;
  if(oddw > evenw) {
    ans += evenw;
    ans += oddb;
  } else if (oddw < evenw) {
    ans += oddw;
    ans += evenb;
  } else {
    if(oddb < evenb) {
      ans += oddb;
      ans += evenw;
    } else {
      ans += oddw;
      ans += evenb;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1; // cin >> tc;
    while (tc--)
    {
        int n,a,b;
        cin >>n>> a >> b;
        if((b-a)%2==0){
            cout << (b - a) / 2 << endl;
        }
        else{
            int ans;
            cout<<min(n - b, a - 1) + 1 + (b - a - 1) / 2 << endl;

        }
    }

    return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

def candies(a, n):
    top = accumulate(a[0])
    bottom = list(accumulate(a[1][::-1]))
    bottom.reverse()
    return max(map(lambda x, y: x + y, top, bottom))


if __name__ == '__main__':
    n = int(input())
    a = [list(map(int, input().split())) for _ in range(2)]
    print(candies(a, n))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'
#define fi first
#define se second

int p[MAXN], ok[MAXN];
void init(int n){
    for(int i = 2; i <= n; i++){
        if(!ok[i]) p[++*p] = i;
        for(int j = 1; j <= *p; j++){
            if(i * p[j] > n) break;
            ok[i*p[j]] = p[j];
            if(i % p[j] == 0) break;
        }
    }
}
int n, a[MAXN], mp[MAXN];
void run(){
    init(1e6);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    int x = a[n], y, f = 1, ff = 1;
    while(ok[x]){
        mp[y=ok[x]] = 1;
        while(x % y == 0) x /= y;
    }
    if(x > 1) mp[x] = 1;
    for(int i = n - 1; i && f; i--){
        x = a[i];
        while(ok[x]){
            y = ok[x];
            if(mp[y]){ f = 0; break; }
            while(x % y == 0) x /= y;
        }
        if(x > 1){
            if(mp[x]) f = 0;
            mp[x] = 1;
        }
    }
    if(f) DEBUG("pairwise coprime");
    else{
        x = 0;
        for(int i = 1; i <= n && ff; i++)
            ff &= (x = __gcd(x, a[i])) != 1;
        DEBUG(ff ? "not coprime" : "setwise coprime");
    }
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios_base::sync_with_stdio(false);

    run(); return 0;
}


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

int main(){
  int N;
  cin >> N;
  int D, X;
  cin >> D >> X;
  
  int ans = X;
  for(int i = 0; i < N; i++){
    int diff;
    cin >> diff;
    int day = 1;
    while(day <= D){
      ans++;
      day += diff;      
    }
  }
  cout << ans << endl;


}

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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int sum1, sum2, sum3;
  sum1 = a * x + b * y;
  if (x > y)
    sum2 = c * 2 * y + (x - y) * a;
  else
    sum2 = c * 2 * x + (y - x) * b;
  sum3 = max(x, y) * 2 * c;
  cout << min({sum1, sum2, sum3}) << endl;
  return 0;
}


Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_090_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(12).
    01 maxlen PIC 9(1)  VALUE 2.
    01 cur    PIC 9(12)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).

    01 k      PIC 9(6).

    01 len    PIC 9(12).

    01 cnt    PIC 9(5).
    01 ZS     PIC Z(5)9.
    01 ans    PIC X(5).

    01 X      PIC X(6).

    01 AB1.
        03 AB11 OCCURS 2.
            05 AB PIC 9(5).

    01 DUMMY  PIC X(1).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO AB(i)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    MOVE 0 TO cnt.
    PERFORM VARYING k FROM AB(1) BY 1 UNTIL AB(2) < k
        MOVE k TO X
        IF X(2:1) = X(6:1) AND X(3:1) = X(5:1) THEN
            ADD 1 TO cnt
        END-IF
    END-PERFORM.

    MOVE cnt TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Grid BFS
//-------------------------------------------------

const int INF = 1e9;

template<typename T>
vector<vector<int> > gBFS(int si, int sj, vector<T> &field)
{
    int dx[]={0,1,0,-1};
    int dy[]={1,0,-1,0};
    int h = field.size();
    int w = field[0].size();
    using P = tuple<int,int,int>;
    deque<P> que;
    que.push_back({si,sj,0});
    vector<vector<int> > dist(h,vector<int>(w,INF));
    dist[si][sj] = 0;
    while(que.size()){
        int x,y,cost;
        tie(y,x,cost) = que.front(); que.pop_front();
        if (cost>dist[y][x]) continue;
        for(int i=0; i<4; i++){
            int tx = x+dx[i];
            int ty = y+dy[i];
            if (!(0<=tx&&tx<w&&0<=ty&&ty<h)) continue;
            if (dist[ty][tx]<=dist[y][x]) continue;
            // 壁の条件(適宜書き換える)
            if (field[ty][tx]=='#') continue;
            dist[ty][tx] = dist[y][x];
            que.push_front({ty,tx,dist[ty][tx]});
        }
        FOR(ty,y-2,y+2)FOR(tx,x-2,x+2){
            if (!(0<=tx&&tx<w&&0<=ty&&ty<h)) continue;
            if (dist[ty][tx]<=dist[y][x]+1) continue;
            if (field[ty][tx]=='#') continue;
            dist[ty][tx] = dist[y][x]+1;
            que.push_back({ty,tx,dist[ty][tx]});
        }
    }
    return dist;
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W; cin>>H>>W;
    int sy,sx; cin>>sy>>sx; sy--; sx--;
    int gy,gx; cin>>gy>>gx; gy--; gx--;
    vector<string> f(H);
    rep(i,H) cin>>f[i];
    auto dist = gBFS(sy,sx,f);
    // rep(i,H){
    //     rep(j,W) cout<<dist[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<(dist[gy][gx]==INF?-1:dist[gy][gx])<<endl;
    return 0;
}


Measured memory_bytes: 8664
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define pii         pair<int, int>
#define dint        long double


void solve() {
    string s, t; cin >> s >> t;
    int n = s.size();
    string tt = t.substr(0, n);
    if(tt==s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    // cin >> T;
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
program knapsack1
  implicit none
  integer :: n, w, wi, i
  integer(8) :: vi, dp0(0:100000), dp1(0:100000)
  dp0 = 0_8
  dp1 = 0_8
  read(*,*) n, w
  do i = 1, n
    read(*,*) wi, vi
    dp1(0:wi-1) = dp0(0:wi-1)
    dp1(wi:w) = max(dp0(wi:w),dp0(0:w-wi)+vi)
    dp0(0:w) = dp1(0:w)
  end do
  write(*,'(i0)') dp0(w)
  stop
end program knapsack1

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

def readlines(n):
    for i in range(n):
        for j, x in enumerate(input().split()):
            yield int(x), (i, j)


def main():
    N = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    print(sum(A[::2]) - sum(A[1::2]))


main()


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(n)
	m := 1000
	s := 0
	for i := 0; i < n-1; i++ {
		if a[i] < a[i+1] {
			s += m / a[i]
			m -= m / a[i] * a[i]
		} else if a[i] > a[i+1] {
			m += s * a[i]
			s = 0
		}
	}
	fmt.Println(m + s*a[n-1])
}


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

int main(){
    int N,total,k=0;
    cin >>N;
    for(int i=0;i<=25;i++){
        for(int j=0;j<=14;j++){
            total=4*i+7*j;
            if(total==N) k=1;
        }
    }

    if(k==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
    int n,a,now;
    cin >> n;
    
    vector<int> A,sortedA;
    vector<int> stcount(200000,0);
    rep(i,n){ 
        cin >> a;
        A.push_back(a);
    }
    sortedA = A;
    sort(sortedA.begin(),sortedA.end());
    
    long long count=0;
    long long sum=0;
    long long ans;
    now = sortedA.at(0);
    rep(i,n){
        if (now == sortedA.at(i)){
            count++;
        }else{
           sum += count*(count-1)/2;
           stcount.at(now) = count;
           now = sortedA.at(i);
           count=1;
        }
    }
    sum += count*(count-1)/2;
    stcount.at(now) = count;

    long long b;
    rep(i,n){
        b = stcount.at(A.at(i));
        if (b!=0){
            ans = sum - b + 1;
        }else{
            ans = sum;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5108