akhauriyash/Code-Regression huggingface dataset:
import itertools
import sys
import math

def distance(p1, p2):
    return math.sqrt(pow(p1[0] - p2[0], 2) + pow(p1[1] - p2[1], 2))

n = int(input())
l = [list(map(int, line.split())) for line in sys.stdin.read().split('\n')[:-1]]
p = itertools.permutations(list(range(n)))
ans = 0
cnt = 0
for arr in p:
    cnt += 1
    for i in range(n-1):
       ans += distance(l[arr[i]], l[arr[i+1]]) 
print(ans/cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()
 
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
 
typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
 
inline int in(){int x;std::cin>>x;return x;}
 
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;
 
template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}

signed main(){
    int N;
    cin>>N;
    vector<int>a;
    int total = 0;
    rep(i,N){
        int tmp;
        cin>>tmp;
        a.pb(tmp);
        total+=tmp;
    }
    int ans = INF;
    int head_total = 0;
    rep(i,N){
        head_total += a[i];
        total -= a[i];
        ans = min(ans, abs(head_total - total));
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int digit(int n){
	int res = 0;
	while(n){
		n/=10;
		res++;
	}
	return res;
}

int pow_i(int n, int p){
	int res = 1;
	rep(i,p) res*=n;
	return res;
}

int main(void) {
	int a,b; cin >> a >> b;
	int c = a*pow_i(10,digit(b))+b;
	for(int i=1; i*i<=c; i++){
		if(i*i==c){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion
signed main() {
	int n,sum=0,max;
	cin >> n;
	vector <int> p(n);
	rep(i, n) {
		cin >> p[i];
		sum += p[i];
	}
	max = *max_element(ALL(p));
	cout << sum-max/2;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#define endl "\n"
#define SRK ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EPS 1e-6
typedef long long ll;
using namespace std;

bool check9(string s)
{
    int res = 0,i;
    for (i = 0; i < s.length(); i++)
    {
        res = (res * 10 + s[i] - '0') % 9;
    }
    if (res == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main()
{
    SRK;
    string s;
    cin >> s;
    if (check9(s))
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
}


Measured memory_bytes: 3740
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M;
    cin >> M;
    cout << 24 - M + 24 << endl;
    dump(1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi = vector<int>;
using vl= vector<ll>;
using vs=vector<string>;

ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a);}
ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}
ll power(ll a,ll b) {long long res = 1; while (b > 0) {if (b & 1)res = res * a;a = a * a;b >>= 1;} return res;}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    
    for(int p=0;p<testcase;p++){
        string s,t;
ll counter=0;
	cin>>s>>t;
	ll hashtable1[26]={0};
	ll hashtable2[26]={0};
	for(int i=0;i<s.size();i++){
	if(s[i]!=t[i])
	counter++;

}


cout<<counter;
        
        
        
        }

    return 0;
}


Measured memory_bytes: 3820
#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 a,b,c; cin>>a>>b>>c;
	set<int> st;
	st.insert(a);
	if(st.count(b)) cout<<c<<endl;
	else if(st.count(c)) cout<<b<<endl;
  else cout<<a<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int k, n; cin >> k >> n;
  vector<int> v(n), t(n+1, 0);
  rep(i, n) cin >> v[i];
  sort(All(v));
  ll ans = 1e10;
  for(int i = 0; i < n-1; i++){
    t[i+1] = abs(v[i+1]-v[i]);
  }
  t[n] = (k+v[0])-v[n-1];
  sort(All(t));
  ans = accumulate(All(t), 0) - t[n];
  cout << ans << endl;
  system("pause");
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n){
        cin>>a;
        if(a%2==1)cnt++;
    }
    if(cnt%2==1)Cout("NO");
    else Cout("YES");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	int ans = 0;
	if (a >= b) { ans += a; a--; }
	else { ans += b; b--; }

	if (a >= b) { ans += a; a--; }
	else { ans += b; b--; }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}

int main() {
  Int n;
  cin >> n;
  vector<Int> as(n);
  for (Int i = 0; i < n; i++) cin >> as[i];
  Int sum = 0;
  for (Int i = 0; i < n; i++) {
    if (~i & 1)
      sum += as[i];
    else
      sum -= as[i];
  }
  vector<Int> bs(n);
  bs[0] = sum;
  for (Int i = 1; i < n; i++) bs[i] = (as[i - 1] - bs[i - 1] / 2) * 2;
  for (Int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << bs[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4800
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    A, B = mi()
    if A >= 10 or B >= 10:
        print(-1)
    else:
        print(A * B)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}

};

int main() {
	int n, t;
	int ia, ib;
	cin >> n >> t;
	vi v;
	rep(i, n) {
		cin >> ia >> ib;
		if (ib <= t)v.push_back(ia);
	}
	sort(all(v));
	if (v.size() != 0) cout << v[0] << endl;
	else cout << "TLE" << endl;
}


Measured memory_bytes: 256
s='abcdefghijklmnopqrstuvwxyz'
n=int(input())
def number_of_alphabets(n):
    i=1
    g=0
    while g<n:
        g+=26**i
        i+=1
    return(i-1)
def what(num):
    g=0
    for i in range(num):
        g+=26**i
    return g
num=number_of_alphabets(n)
name=['a']*num
x=what(num)
n-=x
num-=1
for i in range(num,-1,-1):
    o=n//26**i
    name[num-i]=s[o]
    n=n-o*26**i
print(''.join(name))

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, k, s = 0, p, r;
    cin >> n >> k;
    for (long long b = 1; b <= n; b++) 
    {
        p = n / b;
        r = n % b;
        s += p * max((long long)0, b - k) + max((long long)0, r - k + 1);
    }
    if (k == 0) cout << s - n;
    else cout << s;
}

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

int main(){
    ll i,j,n;
    cin>>n;
    ll t,a;
    cin>>t>>a;
    ll h[n];
    for(i=0;i<n;i++){
        cin>>h[i];
    }

    ll M=2000000000000;
    ll f=-1;
    for(i=0;i<n;i++){
        if(abs(1000*t-h[i]*6-1000*a)<M){

         M=abs(1000*t-h[i]*6-1000*a);
            f=i;
        }
    }

    cout<<f+1<<endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(H: int, W: int):
    if H == 1 or W == 1:
        print(1)
        return
    elif H % 2 == 1 and W % 2 == 1:
        print(H*W//2+1)
    else:
        print(H*W//2)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(H, W)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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 main(){
    string s; cin>>s;
    ll n=s.size();
    bool ifac=true;
    if(s[0]!='A') ifac=false;
    ll cnt=0;
    for(ll i=2; i<n-1; i++){
        if(s[i]=='C') cnt++;
    }
    if(cnt!=1) ifac=false;
    rep(i,n){
        if(i==0) continue;
        if(s[i]=='C') continue;
        if(s[i]<'a' || s[i]>'z') ifac=false;
    }
    if(ifac) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}

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

using namespace std;

int d[10010]={0};//最初に訪問した時刻を入れるタイムスタンプ
int f[10010]={0};//vの隣接リストを調べ終えた時刻のタイムスタンプ

int back[10010]={0};//番号nのもときた街番号をいれる

int g[1001][1001]={{0}};//要素を0で初期化
int timestamp = 1;
int number;
int dfs(int cur){
  d[cur]= timestamp;
  timestamp += 1;
  for(int dst = 0; dst < number; dst++){
    if(g[cur][dst]==1 && d[dst]==0){
      // d[dst]=timestamp;
      back[dst]=cur;
      dfs(dst);
    }
  }
  // timestamp += 1;
  // cout << "f[cur]" <<f[cur]<<"timestamp"<<timestamp<<"cur"<<cur<<endl;
  // abort();
  if(timestamp > number*2){
    return 0;
  }
  // cout << "f[cur]" <<f[cur]<<"timestamp"<<timestamp<<"cur"<<cur<<endl;
  // abort();
  f[cur]=timestamp;
  timestamp++;
}
void ans(int n){
  for (int i = 0; i < n; ++i)
  {
    cout << i+1 << " " << d[i] <<" "<< f[i] <<endl;
  }
}

int main(){
  // int g[1001][1001]={{0}};//要素を0で初期化
  int n,a,b,c;
  cin >> n;
  number = n;
  for (int i = 0; i < n; ++i)
  {
    cin >> a >> b ;
    for (int i = 0; i < b; ++i)
    {
      cin >> c;
      g[a-1][c-1]=1;/* code */
    }
  }
  d[0]=1;
  dfs(0);
  for (int i = 0; i < number; ++i)
  {
    if(d[i]==0){
      d[i]=timestamp;
      dfs(i);
    }
  }
  // for (int i = 0; i < number; ++i)
  // {
  //   cout << back[i]<<" ";
  // }

  ans(n);
}

Measured memory_bytes: 1560
// keyence2020_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <cstring>  // std::memset
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define rep1(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define all(vec) (vec).begin(), (vec).end()
#define sum(vec) accumulate(all(vec), 0LL)  // 0 は初期値
#define min_vec(vec) min_element(all(vec))  // iterator: * を先頭につける
#define max_vec(vec) max_element(all(vec))  // iterator: * を先頭につける
#define idx(vec, element_iter) distance((vec).begin(), element_iter)
const ll INF = 1LL<<60;  // 10^18（const int inf = 1<<29;）
const double PI = acos(-1);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    // input(sunippets: inpv, inpn, inps)
    ll A, B, C;
    cin >> A >> B >> C;
    
    // calculation
    ll mx = max(A, B);
    
    cout << (C+mx-1)/mx << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    int k;
    int ans;

    cin >> n >> k;
    if(n%k==0){
        ans=0;
    }else{
        ans=1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N = in;
    vector<int> H(N);
    rep( i, N ) H[i] = in;

    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs( H[0] - H[1] );
    for( int i=2; i<N; i++ ) {
        dp[i] = min(
            dp[i-2] + abs( H[i-2] - H[i] ),
            dp[i-1] + abs( H[i-1] - H[i] ) 
        );
    }

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


Measured memory_bytes: 1024
import java.lang.Math.abs

fun main(args: Array<String>) {
  val (a, b, c, d) = readLine()!!.split(" ").map { it.toLong() }
  val dividableCNum = b / c - (a - 1) / c
  val dividableDNum = b / d - (a - 1) / d
  val dividableCDNum = b / lcm(c, d) - (a - 1) / lcm(c, d)
  println(b - a + 1 - (dividableCNum + dividableDNum - dividableCDNum))
}

fun gcd(a: Long, b: Long): Long = if(a < b) gcd(b, a) else if(b == 0L) a else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

Measured memory_bytes: 37744
D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D): s.append(list(map(int,input().split())))
ans = 0
last = [-1] * 26
for i in range(D):
    t = int(input())
    ans += s[i][t - 1]
    last[t - 1] = i
    for j in range(26):
        ans -= c[j] * (i - last[j])
    print(ans)


Measured memory_bytes: 69904
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main()
{
  string s;
  cin >> s;
  rep(i,s.size()){
    if(s.at(i)=='1'){
      s.at(i) = '9';
    }else{
      s.at(i) = '1';
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std; 

int
main(int argc, char const *argv[])
{
    uint64_t a, b, c;
    cin >> a >> b >> c;

    if ((c > a && c < b) || (c < a && c > b)) {
	cout << "Yes" << endl;
    } else {
	cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;
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; }

// ****************************************CODE***************************************//

ll n, w, weight[110], value[110];
ll dp[110][100100];

int main() {
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        cin >> weight[i] >> value[i];
    }

    for(int i = 0; i < 110; i++) for(int j = 0; j < 100100; j++) dp[i][j] = inf;

    dp[0][0] = 0;

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

            if(sum_v - value[i] >= 0) dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    ll res = 0;
    for(int sum_v = 0; sum_v < 100100; sum_v++){
        if(dp[n][sum_v] <= w) res = sum_v;
    }

    cout << res << endl;
    return 0;
}

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

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

	for (int i = 0; i < 3; ++i) {
		if (s[i] == '1') {
			s[i] = '9';
		}
		else {
			s[i] = '1';
		}
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int N=2e3+10,mo=1e9+7;
ll C[N][N];
void prework(){
	for(int i=0;i<N;i++) C[i][0]=1;
	for(int i=1;i<N;i++)
	for(int j=1;j<=i;j++)
		C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
}
int main()
{
	prework();
	int n,m;
	scanf("%d%d",&n,&m);
	ll ans=n+1;
	for(int i=1;i<m;i++){
		if(m-i>n) continue;
		for(int j=1;j<=m-i;j++){
			if((m-i)+(m-i-j)>n) continue;
			ans+=C[m-1][i-1]*C[m-i-1][j-1]%mo*C[n-(m-i)-(m-i-j)+2][2]%mo;
			ans%=mo;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 30464
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin >> X;
    cout << 10-X/200 << '\n';
}

Measured memory_bytes: 3648
#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;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#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) % MOD;
}
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;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

/*signed*/int main(void) {   
    int a, b, k;
    cin >> a >> b >> k;
    rep(i,k){
        if (i % 2 == 0) {
            a -= a % 2;
            b += a / 2;
            a /= 2;
        }
        else {
            b -= b % 2;
            a += b / 2;
            b /= 2;
        }
    }
    cout << a << " " << b << endl;
}

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

#define A 0
#define B 1
#define C 2


int main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	int n;
	cin>>n;

	vector<int> a(n+1),b(n+1),c(n+1);
	vector<array<int,3>> dp(n+1);

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

	dp[1][0]=a[1],dp[1][1]=b[1],dp[1][2]=c[1];

	for(int i=1;i<=n;i++) {
		dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c[i];
	}

	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));

	return 0;
}

Measured memory_bytes: 5508
use std::io;
use std::io::prelude::*;

fn main() {
    let mut din: Vec<u32> = vec![0];
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let uline = line.unwrap();
        let vec: Vec<&str> = uline.split_whitespace().collect();
        din.append(&mut vec.iter().map(|&x| x.parse().unwrap_or(0)).collect::<Vec<_>>());
    }
    for (i,e) in din.iter().enumerate() {
        if *e != 0 as u32 {
            println!("Case {}: {}", i, e);
        }
    }
}


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

int main(int argc, const char * argv[]) {
    int r, g, b;
    int num;
    
    
    
    cin >> r >> g >> b;
    
    num = (100*r + 10*g + 1*b);
    
    if(num % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [n, ...xy] = stdin.split('\n')
const x_y = xy.map(e=>e.split(' '))
const x = x_y.map(e=>Number(e[0]))
const y = x_y.map(e=>e[1])

function getBCV(b){
  return b * 380000
}

let sum = 0
for (let i = 0; i < x.length; i++) {
  if(y[i] === 'JPY'){
    sum += x[i]
  } else {
    sum += getBCV(x[i])
  }
}

console.log(sum)

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

void solve(long long N, std::vector<long long> A) {
    map<ll, bool> nummap;
    ll ans = 0;
    rep(i, N) {
        if (nummap[A[i]] == false) {
            nummap[A[i]] = true;
            ans++;
        } else {
            nummap[A[i]] = false;
            ans--;
        }
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 10272
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n;cin>>n;
    int ans=0;
    rep(i,0,n){
        int a;cin>>a;
        ans+=a-1;
    }cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <fstream>
#include <cstddef>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = (1<<30);
const ll NEGA=-INF*10000; 


ll ans = 0;
int n,m;
int cnt=0;

int a[4000000],b[4000000],c[4000000];
int main() 
{
 int n;
 cin>>n;
 if(n<1000) cout<<"ABC";
 else cout<<"ABD";
cout<<endl;
}



Measured memory_bytes: 256
n, a, b = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))


def enough(T):
    total = 0
    for x in h:
        if x >= b * T:
            q, r = divmod(x - b * T, a - b)
            ceiling = q + int(r != 0)
            total += ceiling
    return total <= T


l = 0
r = 10 ** 9
while r - l > 1:
    m = (l + r) // 2
    if enough(m):
        r = m
    else:
        l = m
print(r)


Measured memory_bytes: 7076
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <signal.h>
using namespace std;
using namespace __gnu_pbds;
 
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
#define ini ll_MAX
#define inl LLONG_MAX
#define MOD 1000000007
#define sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORR(i, a, b) for (ll i = a; i >= (b); i--)
#define F0RR(i, a) for (ll i = a; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define pbds tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
 
ll mod(ll a,ll b)
{
    return (b+a%b)%b;
}
 
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll pom(ll a,ll b,ll mod)
{
    if(b==0)return 1;
    ll k = pom(a,b/2,mod);
    if(b%2==0)return (k*k)%mod;
    else return ((k*k)*mod*a)%mod;
}
 
ll sqdist(ll a,ll b,ll c,ll d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
ll fact(ll n)
{
    if(n==0)return 1;
    ll ans = 1;
    FOR(i,1,n+1)ans*=i;
    return ans;
}

ll visited[200005],dist[200005],vec[200005];
ll p,q;
vector<ll> st;
void dfs(){
	
	//cout<<p<<' '<<q<<endl;
	if(visited[q])return;
	st.pb(q);
	visited[q]++;
	dist[q]=dist[p]+1;
	p = q;q = vec[q];
	dfs();
}

void solve()
{
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){cin>>vec[i];vec[i]--;}
	p = 0,q=vec[p];
	st.pb(p);
	dist[p]=0;
	dfs();
	//FOR(i,0,n)cout<<dist[i]<<' ';cout<<endl;
	//for(auto i:st)cout<<i<<' ';cout<<endl;
	if(k<dist[q])
	cout<<st[k]+1;
	else{
		k-=dist[q];
		k%=(dist[p]-dist[q]+1);
		cout<<st[dist[q]+k]+1;
	}

}
//4 5 2 3 4 1
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();


}


Measured memory_bytes: 9996
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int
const int twx=2e3+100;
const int inf=0x7fffffff;
ll read()
{
	ll sum=0;
	ll flag=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		{
			flag=-1;
		}
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		sum=((sum*10)+c-'0');
		c=getchar();
	}
	return sum*flag;
}
int n;
int l[twx];
int s[twx];
ll ans=0;
void init()
{
	n=read();
	f1(1,n,i)
	{
		l[i]=read();
        s[l[i]]++;
    }
    f1(2,2000,i)
    {
        s[i]+=s[i-1];
    }
    so2(l,n);
    ans=0;
    f1(1,n-1,i)
    {
        f1(i+1,n,j)
        {
            ans+=(s[l[j]+l[i]-1]-s[l[j]-l[i]]);
            if(l[i]>l[j]-l[i]&&l[i]<=l[j]+l[i]-1) 
            {
                --ans;
            }
		    if(l[j]>l[j]-l[i]&&l[j]<=l[j]+l[i]-1) 
            {
                --ans;
            }
        }
    }
	/*f1(1,n,i)
	{
		f1(1,n,j)
		{
			f1(1,n,k)
			{
				if(i==j||i==k||j==k)
				{
					continue ;
				}
				if(l[i]+l[j]>l[k]&&l[j]+l[k]>l[i]&&l[i]+l[k]>l[j])
				{
					ans++;
				}
			}
		}
	}*/
	printf("%lld\n",ans/3);
}
void work()
{

}
void print()
{

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

Measured memory_bytes: 256
k,s= [int(i) for i in input().split()]

x=0
j=0

for j in range(k+1):
	if s-j<=k and s-j>=0:
		x=x+s-j+1
	elif (s-j)<=2*k and s-j>=0:
		x=x+(2*k-(s-j)+1)

print(x)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	long long n;
	cin>>n;
	bool flag=0;
	while(n){
		if(n%10==7)flag=1;
		n/=10;
	}
	if(flag)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,i,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

void solve(){
	int N, T;
	int t[int(2e5+5)] = {};
	ll ans = 0;
	cin >> N >> T;

	rep(i,N) cin >> t[i];
	t[N] = inf;

	rep(i,N){
		ans += min(T, t[i+1] - t[i]);
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    k = int(input())
    a, b = input_to_int_map()

    for i in range(a, b + 1):
        if i % k == 0:
            return "OK"

    return "NG"

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9196
#include<stdio.h>
#define N 100000
#define NIL -1
 
struct Node{
  int p, l, r;
};
 
struct Node T[N];
int n, H, D[N];
 
int getDepth(int);
void print(int);
 
int main(){
  int i, j, d, v, c, l;
   
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ ){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      if ( j == 0 ){
    T[v].l = c;
      }
      else{
    T[l].r = c;
      }
      l = c;
      T[c].p = v;      
    }
  }
   
  H = 0;
  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
    if ( D[i] > H ){
      H = D[i];
    }
  }  
  for ( i = 0; i < n; i++ ){
    print(i);
  }
  return 0;
}
 
int getDepth(int u){
  int d = 0;
  while(1){
    u = T[u].p;
    if ( u == NIL ) break;
    d++;
  }
  return d;
}
 
 
void print(int u){
  int i, c;
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].p);
  printf("depth = %d, ", D[u]);
 
  if ( T[u].p == NIL ){
    printf("root, ");
  }
  else if ( T[u].l == NIL ){
    printf("leaf, ");
  }
  else{
    printf("internal node, ");
  }
 
  printf("[");
  for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if (i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}

Measured memory_bytes: 2176
def calc_50(r, max_num_50):
    if r < 0:
        return 0
    elif r / 50 <= max_num_50:
        return 1
    else:
        return 0


def calc_100(r, max_num_100, max_num_50):
    count = 0
    for num_100 in range(0, max_num_100 + 1):
        count += calc_50(r - 100 * num_100, max_num_50)
    return count


def calc_500(r, max_num_500, max_num_100, max_num_50):
    count = 0
    for num_500 in range(0, max_num_500 + 1):
        count += calc_100(r - 500 * num_500, max_num_100, max_num_50)
    return count


a = int(input())
b = int(input())
c = int(input())
x = int(input())

print(calc_500(x, a, b, c))


Measured memory_bytes: 3064
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, c, k = inintm()

print(a-b) if k % 2 == 0 else print(b-a)

Measured memory_bytes: 61608
S = gets.chomp
Q = gets.chomp.to_i

reverse = false
A = []
B = []
Q.times do |i|
  q = gets.chomp.split(" ")
  if q[0] == "1"
    reverse = !reverse
  else
    if q[1] == "1" && !reverse || q[1] == "2" && reverse
      A.unshift(q[2])
    else
      B.push(q[2])
    end
  end
end

if !reverse
  puts A.join + S + B.join
else
  puts B.reverse.join + S.reverse + A.reverse.join
end


Measured memory_bytes: 18300
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int N, M;
vector<int> g[50];
vector<int> depth, low;
set<pii> bridge;

int dfs(int u, int p, int d) {
	depth[u] = d;
	low[u] = d;
	
	REP(i, g[u].size()) {
		int v = g[u][i];
		if (v == p) continue;
		
		if (depth[v] == -1) {
			chmin(low[u], dfs(v, u, d + 1));
			if (depth[v] == low[v]) bridge.insert(pii(min(u, v), max(u, v)));
		}
		else chmin(low[u], low[v]);
	}
	
	return low[u];
}

int main() {
	cin >> N >> M;
	REP(i, M) {
		int s, t;
		scanf("%d %d", &s, &t);
		s--; t--;
		g[s].push_back(t);
		g[t].push_back(s);
	}
	
	depth.resize(N, -1);
	low.resize(N, -1);
	
	dfs(0, -1, 0);
	cout << bridge.size() << endl;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
P = [0] * (N + 1)
p = 10 ** 9 + 7
B = 0
if M > 0:
  B = int(input())
  M -= 1
P[0] = 1
P[1] = 1
if B == 1:
  P[1] = 0
  if M > 0:
    B = int(input())
    M -= 1
for i in range(2, N + 1):
  P[i] = (P[i - 1] + P[i - 2]) % p
  if i == B:
    P[i] = 0
    if M > 0:
      B = int(input())
      M -= 1
print(P[N])

Measured memory_bytes: 6900
#include <stdio.h>

int main(void)
{
    int i, j, k, n;
    int elements[101];
    int temp;

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        scanf("%d", &elements[i]);
    }
    for (i = 0; i < n; i++){
        printf("%d", elements[i]);
        if(i != n - 1) printf(" ");
    }
    putchar ('\n');
    for (i = 1; i < n; i++){
        for(j = 0; j < i; j++){
            if(elements[i] < elements[j]){
                temp = elements[i];
                elements[i] = elements[j];
                elements[j] = temp;
            }
        }
        for (k = 0; k < n; k++){
            printf("%d", elements[k]);
            if(k != n - 1) printf(" ");
        }
        putchar ('\n');
    }

    return (0);
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=302;
const int mod=1e9+7;

inline void pls(int &a,int b){ a+=b;if(a>=mod)a-=mod;}

int n,m,l[maxn],r[maxn],c[maxn];
vector<int>tor[maxn];

inline void init()
{
	n=read();m=read();
	REP(i,1,m)l[i]=read(),r[i]=read(),c[i]=read(),tor[r[i]].push_back(i);
}

int dp[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];
struct Node {
	int x,y,z;
	Node(int _x=0,int _y=0,int _z=0){ x=_x; y=_y; z=_z;}
};

queue<Node>q;

inline bool check(int now,int x,int y,int z)
{
	REP(j,0,(int)tor[now].size()-1)
	{
		int i=tor[now][j];
		if((x>=l[i])+(y>=l[i])+(z>=l[i])!=c[i])return 0;
	}
	return 1;
}

int ans;

inline void doing()
{
	dp[0][0][0]=1;
	q.push(Node(0,0,0));
	while(!q.empty())
	{
		Node t=q.front(); q.pop();
		int x=t.x,y=t.y,z=t.z,now=max(t.x,max(t.y,t.z))+1,nw=dp[x][y][z];
		if(!check(now-1,x,y,z))continue;
		if(now-1==n){ pls(ans,dp[x][y][z]); continue;}
		pls(dp[now][y][z],nw);if(!vis[now][y][z])vis[now][y][z]=1,q.push(Node(now,y,z));
		pls(dp[x][now][z],nw);if(!vis[x][now][z])vis[x][now][z]=1,q.push(Node(x,now,z));
		pls(dp[x][y][now],nw);if(!vis[x][y][now])vis[x][y][now]=1,q.push(Node(x,y,now));
	}
	printf("%d\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}



Measured memory_bytes: 137728
#include<bits/stdc++.h>
using namespace std;
int main(){
  int rp[100001] = {},n,i,j,l,r;cin >> n;bool su[100001] = {};
  vector<int> x;
  for(i=2;i<=100000;i++){
    rp[i] = rp[i-1];l = 1;
    for(auto j:x){
      if(j*j>i) break;
      if(i%j==0){
        su[i]++;break;
      }
    }
    su[i] ^= 1;
    if(su[i]) x.push_back(i);
    if(su[i] && i%2 && su[(i+1)/2]) rp[i]++;
  }
  while(cin >> l >> r) cout << rp[r]-rp[l-1] << "\n";
  return 0;
}

Measured memory_bytes: 1280
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a

n, x = map(int, input().split())
town = list(map(int, input().split()))

res = abs(town[0] - x)
for t in town[1:]:
    d = abs(t - x)
    res = gcd(res, d)

print(res)

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner stdin = new Scanner(System.in);
        int ans=0;

        double N = stdin.nextInt();
        
        for(int i=0;i<=50000;i++) {
        	if(Math.floor(i*1.08) == N) {
        		System.out.println(i);
        		break;
        	}
        	else if(i==50000) System.out.print(":(");
        }
	}
}


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


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

    int count = 0;
    for(int i=a;i<=b;i++){
        string s = to_string(i);
        string r = to_string(i);
        reverse(r.begin(),r.end());
        if(s == r) count++;
    }

    cout << count << endl;

    return 0;
}

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

using namespace std;


int main()
{
    string str;
    char tmp;

    cin >> str;

    if ((int)str.length() == 2) {
        cout << str << endl;
    } else {
        tmp = str[0];
        str[0] = str[2];
        str[2] = tmp;
        cout << str << endl;
    }
    
    return 0;   
}

Measured memory_bytes: 256