akhauriyash/Code-Regression huggingface dataset:
//
//  main.c
//  ITP1_6_D
//
//  Created by k16031kk on 2018/05/25.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n, m, a, b, c = 0;
    scanf("%d %d", &n, &m);
    int A[n][m];
    int B[m];
    int sum[m];
    
    for(int i=0; i<n; i++) {
        for(int j=0; j<m; j++) {
            scanf("%d", &a);
            A[i][j]=a;
        }
    }
    for(int i=0; i<m; i++) {
        scanf("%d", &b);
        B[i]=b;
    }
    
    for(int i=0; i<n; i++) {
        c=0;
        for(int j=0; j<m; j++) {
            sum[j]=A[i][j]*B[j];
            c+=sum[j];
        }
        printf("%d\n", c);
    }
    
    return 0;
}



Measured memory_bytes: 2112
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
void moveR(int x1, int x2) {
  for (int i = 0; i < x2 - x1; i++) {
    cout << 'R';
  }
}
 
void moveU(int y1, int y2) {
  for (int i = 0; i < y2 - y1; i++) {
    cout << 'U';
  }
}
 
void moveL(int x1, int x2) {
  for (int i = 0; i < x2 - x1; i++) {
    cout << 'L';
  }
}
 
void moveD(int y1, int y2) {
  for (int i = 0; i < y2 - y1; i++) {
    cout << 'D';
  }
}
 
int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  moveR(sx, tx);
  moveU(sy, ty);
  moveL(sx, tx);
  moveD(sy, ty);
  cout << 'D';
  moveR(sx, tx + 1);
  moveU(sy, ty + 1);
  cout << 'L' << 'U';
  moveL(sx, tx + 1);
  moveD(sy, ty + 1);
  cout << 'R' << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int a[5];
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    for(int i=0;i<5;i++){
        if(a[i]!=i+1){
            cout<<i+1<<endl;
            return 0;
        }
    }

}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

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

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> T(N);
    vector<ll> A(N);

    ll nowT = 0;
    ll nowA = 0;
    REP(i, N){
        cin >> T[i] >> A[i];
    }

    nowT = T[0];
    nowA = A[0];

    for(ll i=1; i<N; i++){
        ll n = max((nowT-1)/T[i]+1, (nowA-1)/A[i]+1);
        nowT = n*T[i];
        nowA = n*A[i];
    }

    cout << nowT + nowA << endl;
    return 0;
}

Measured memory_bytes: 3600
n=int(input())
m=[]
for _ in range(n-1):
  c,s,f=map(int,input().split())
  m.append(0)
  for i in range(len(m)):
    if m[i]>s:
      m[i]=s+((m[i]-s)//f+((m[i]-s)%f>0))*f+c
    else:#m[i]<=s
      m[i]=s+c
m.append(0)
for i in m:
  print(i)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
 
int main()
{
	long long int r = 0;
	long long int n;
	std::cin >> n;
	std::vector<std::string> s;
	s.resize(n);
	for (int i = 0; i < n; i++)
	{
		std::cin >> s[i];
		std::sort(s[i].begin(), s[i].end());
	}

    std::sort(s.begin(), s.end(), std::greater<std::string>());
	auto c = *s.begin();
	long long buf = 0;
	for (auto i = s.begin() + 1, ei = s.end(); i != ei; i++)
	{
	    if (c.compare(*i) == 0)
	    {
	        buf += 1;
	    }
	    else
	    {
	        r += (buf*(buf + 1))/2;
	        buf = 0;
	        c = *i;
	    }
	}
	if (buf != 0)
	{
	    r += (buf*(buf + 1))/2;
	}
 
	std::cout << r << '\n';
 
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
ll a[10000005];
ll f(ll n)
{
    ll divs=1;
    while(n!=1)
    {
        ll nn=n;
        ll x=a[nn];
        ll c=0;
        while(nn%x == 0)
        {
            c++;
            nn/=x;
        }
        n=nn;
        divs*=(c+1);
    }
    return divs;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i;
    cin>>n;
    for(i=1;i<10000005;i++)
        a[i]=i;
    for(i=2;i<10000005;i++)
    {
        if(a[i]==i)
        {
            for(ll j=2*i;j<10000005;j+=i)
                a[j]=i;
        }
    }
    ll ans=1;
    for(i=2;i<=n;i++)
    {
        ans+=i*f(i);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 81772
# from numba import njit
 
# @njit(cache=True)
def convolve(a, b):
    def poww(aa, bb, mm):
        ss = 1
        tt = aa
        while bb:
            if bb % 2:
                ss = ss * tt % mm
                bb -= 1
            tt = tt * tt % mm
            bb //= 2
        return ss
    def fft(n, p, g, w, invw, f):
        d = n // 2
        v = w
        while d >= 1:
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * v % p
            v = v * v % p
            d //= 2
 
    def ifft(n, p, g, w, invw, f):
        d = 1
        while d < n:
            v = poww(invw, n // (2 * d), p)
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j+d] *= u
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * v % p
            d *= 2
 
    p = 1107296257
    g = 5
    n0, n1 = len(a), len(b)
    n = 1
    while n < max(n0, n1) * 2:
        n *= 2
    a = a + [0] * (n-n0)
    b = b + [0] * (n-n1)

    w = poww(g, (p - 1) // n, p)
    invw = poww(w, p-2, p)
    fft(n, p, g, w, invw, a), fft(n, p, g, w, invw, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(n, p, g, w, invw, a)
    invn = poww(n, p - 2, p)
    for i in range(n0 + n1 - 1):
        a[i] = a[i] * invn % p
    return a[:n0 + n1 - 1]

N = 100000
A = []
B = []
s = 0
for i in range(N):
    s = (s * 3 + i * 7) % 100
    a = s
    b = (s * 3 + a * 11) % 100
    A.append(a)
    B.append(b)

AB = convolve(A, B)


#####
A, B, C, K = map(int, input().split())
if K <= A + B:
    print(min(A, K))
else:
    print(A - (K - A - B))

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

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

	int N;
	int i,k;
	int ans=0;
	int ctr=0;

	cin >> N;

	if(N==0)
		cout << 1 << endl;
	else
		cout << 0 << endl;

	return 0;
}



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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % 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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int a, b, c;
  cin >> a >> b >> c;
  if(a + b + c >= 22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }


  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
lm=0
rm=100000

for i in range(m):
    l,r=map(int,input().split())
    if lm<l:
        lm=l
    if rm>r:
        rm=r

if rm-lm<0:
    print(0)
else:
    if lm<=n:
        print(rm-lm+1)
    else:
        print(n-rm+1)


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

int main()
{
    ll n;
    cin >> n;
    unordered_map<ll,ll> factor;
    for (ll i = 2; i <= sqrt(n); i++) {
        while (n % i == 0) {
            factor[i]++;
            n /= i;
        }
    }
    if (n > 1)
        factor[n] = 1;

    ll ans = 0;
    for (auto p : factor) {
        ans += (ll)((-1.0 + sqrt(1 + 8 * p.second)) / 2.0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3728
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int k = sc.nextInt();
			int s = sc.nextInt();
			int count = 0;
			for(int x = 0 ; x <= k ; x++) {
				for(int y = 0; y <= k ; y++) {
					int z = s - x -y;
					if(z <= k && 0 <= z ) {
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}


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

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <double, double> pdd;

#define pb push_back
#define mp make_pair

int n;
string s[2];
const ll md = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    cin >> s[0] >> s[1];
    ll ans = 3;
    int i = 0;
    while(true){
        int c = 0;
        while(i < n && s[0][i] == s[0][i + 1]){
            if(c) ans *= 3;
            else ans *= 2;
            ans %= md;
            i += 2;
            c++;
        }
        int cur = 0;
        while(i < n && s[0][i] == s[1][i]){
            if(cur) ans *= 2;
            ans %= md;
            cur++;
            i++;
        }
        if(i == n) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
  int p;
  int r;
  int l;
  int s;
} Node;
int flag;
int hfunc(Node *,int,int);
void pre(Node *,int);
void in(Node *,int);
void pos(Node *,int);

int main(){
  int n,i,j,degree,point,c1,c2,depth=0,sum=0,height,root=0;
 
  Node T[25];
  for(i=0;i<25;i++){
    T[i].p=T[i].r=T[i].l=T[i].s=-1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d%d",&point,&c1,&c2);
    if(c1!=-1)sum++;
    if(c2!=-1)sum++;
    T[point].l=c1;
    T[point].r=c2;
    if(c1!=-1){
    T[c1].s=c2;
    T[c1].p=point;
    }
    if(c2!=-1){
    T[c2].s=c1;
    T[c2].p=point;
    }
  }
  for(i=0;i<=sum;i++){
    if(T[i].p==-1){root=i; break;}
  }
  printf("Preorder\n");
  pre(T,root);
  printf("\nInorder\n");
  in(T,root);
  printf("\nPostorder\n");
  pos(T,root);
  printf("\n");
    

  

  return 0;
}
void pre(Node T[],int i){
  if(T[i].l==-1 && T[i].r==-1){
    printf(" %d",i);
    return;
  }
  printf(" %d",i);
  if(T[i].l!=-1)
  pre(T,T[i].l);
  if(T[i].r!=-1)
  pre(T,T[i].r);
}
void in(Node T[],int i){
  if(T[i].l==-1 && T[i].r==-1)
  {
    printf(" %d",i);
    return;
  }
  if(T[i].l!=-1)
  in(T,T[i].l);
  printf(" %d",i);
  if(T[i].r!=-1)
  in(T,T[i].r);
}
void pos(Node T[],int i){
  if(T[i].l==-1 && T[i].r==-1)
    {
      printf(" %d",i);
      return;
    }
  if(T[i].l!=-1)
  pos(T,T[i].l);
  if(T[i].r!=-1)
  pos(T,T[i].r);
  printf(" %d",i);
}    
  
  
   
    
      
    
  
	   



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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int res = 0;
  rep(i,n-1) {
    if (p[i] == i+1) swap(p[i],p[i+1]),res++;
  }
  if (p[n-1] == n) res++;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 640
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N; cin >> N;
	vector<int> A(N);
	vector<int> v[MAX * 2];

	rep(i, N-1) {
		cin >> A[i+1];
		A[i+1]--;
		v[A[i+1]].push_back(i);
	}
	rep(i, N){
		cout << v[i].size() << endl;
	}
	return 0;
}


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

int  main()
{
	int n,x ; cin >> n >> x;
	vector<int> l(n);
	rep(i, n)
	{
		cin >> l[i];
	}
	int ans = 0;
	vector<int> q;
	// q.push_back(0);
	rep1(i, n)
	{
		if (i != 0)
			ans = l[i-1] + q.back();
		q.push_back(ans);
		// cout << ans << endl;
	}
	int cnt = 0;
	rep(i, q.size())
	{
		if (q[i] <= x)
			cnt++;
	}
	cout << cnt << endl;
	return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    vector<int> v={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin>>n;
    cout<<v[n];
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a[100001] = {0};
    int ans = 0;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        if(tmp > 100000){
            ans++;
        }else{
            a[tmp]++;
        }
    }
    for(int i = 0; i <= 100001; i++){
        if(a[i] != 0){
            if(a[i] >= i){
                ans += (a[i] - i);
            }else{
                ans += (a[i]);
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Node{
	Node(int arg_from,int arg_to,int arg_length){
		from = arg_from;
		to = arg_to;
		length = arg_length;
	}

	bool operator<(const struct Node &arg) const{
		return length < arg.length;
	};
	int from,to,length;
};

int parent[51],height[51];
int S,D,N;

int getParent(int id){
	if(parent[id] == id)return id;
	else{
		return parent[id] = getParent(parent[id]);
	}
}

bool isSame(int a, int b){
	return getParent(a) == getParent(b);
}

void unite(int a,int b){
	int a_parent = getParent(a);
	int b_parent = getParent(b);

	if(a_parent == b_parent)return;

	if(height[a_parent] > height[b_parent]){
		parent[b_parent] = a_parent;
	}else{
		if(height[a_parent] == height[b_parent])height[b_parent]++;
		parent[a_parent] = b_parent;
	}
}

void init(){
	for(int i = 0; i < N; i++){
		parent[i] = i;
		height[i] = 0;
	}
}

void func(){

	N = S+D;

	init();

	vector<Node> V;

	int tmp_length;

	for(int i = 0; i < S; i++){
		for(int k = 0; k < D; k++){
			scanf("%d",&tmp_length);
			if(tmp_length == 0)continue;
			V.push_back(Node(i,S+k,tmp_length));
		}
	}

	for(int i = 0; i < D-1; i++){
		for(int k = i+1; k < D; k++){
			scanf("%d",&tmp_length);
			if(tmp_length == 0)continue;
			V.push_back(Node(S+i,S+k,tmp_length));
		}
	}

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

	int ans = 0;

	bool is_connect[N];
	for(int i = 0; i < S; i++)is_connect[i] = true;
	for(int i = S; i < N; i++)is_connect[i] = false;

	int boss;

	for(int i = 0; i < V.size(); i++){
		if(isSame(V[i].from,V[i].to) == false && (is_connect[V[i].from] == false || is_connect[V[i].to] == false)){

			if(is_connect[V[i].from]){
				boss = getParent(V[i].to);

				for(int k = S; k < N; k++){
					if(getParent(k) == boss){
						is_connect[k] = true;
					}
				}
			}else if(is_connect[V[i].to]){
				boss = getParent(V[i].from);

				for(int k = S; k < N; k++){
					if(getParent(k) == boss){
						is_connect[k] = true;
					}
				}
			}

			unite(V[i].from,V[i].to);

			ans += V[i].length;
		}
	}

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

}


int main(){

	while(true){
		scanf("%d %d",&S,&D);
		if(S == 0 && D == 0)break;

		func();
	}


	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

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

void solve() {
  int n;
  std::cin >> n;
  cout(n / 3);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M; cin >> N >> M;
	bool flag = 1;
	for (int i = 0; i < M; i++) {
		int a; cin >> a;
		N -= a;
		if (N < 0) flag = 0;
	}

	if (flag) cout << N << '\n';
	else cout << -1 << '\n';
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 405;
ll arr[N];
ll cost[N][N];
ll dp[N][N];

ll solve(int i, int j)
{
  if(i == j)
    return 0;
  ll &ans = dp[i][j];
  if(~ans)
    return ans;
  ans = 1e18;
  for(int z = i; z <= j; z++)
  {
    ans = min(ans, cost[i][z] + solve(i, z) + solve(z + 1, j) + cost[z + 1][j]);
  }
  return ans;
}

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> arr[i];
  for(int i = 0; i < n; i++)
  {
    cost[i][i] = arr[i];
    for(int j = i + 1; j < n; j++)
      cost[i][j] = cost[i][j - 1] + arr[j];
  }
  memset(dp, -1, sizeof dp);
  cout << solve(0, n - 1);
  return 0;
}


Measured memory_bytes: 2816
object Main extends App {

  import scala.io.StdIn._
  println(if (isValid(readLine.trim.toList)) "VALID" else "INVALID")
  def isLengthOver6(str: List[Char]): Boolean = str.size >= 6
  def isIncludeNumber(str: List[Char]): Boolean = str.exists(_.isDigit)
  def isIncludeUppercase(str: List[Char]): Boolean = str.exists(_.isUpper)
  def isIncludeLowercase(str: List[Char]): Boolean = str.exists(_.isLower)
  def isValid(str: List[Char]): Boolean = isLengthOver6(str) && isIncludeNumber(str) && isIncludeUppercase(str) && isIncludeLowercase(str)
}



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

int main() {
  while (true) {
    int n, m, t, p;
    cin >> n >> m >> t >> p;
    if (n + m + t + p == 0) break;
    
    vector<vector<int>> x(m, vector<int>(n, 1));
    for (int k = 0; k < t; k++) {
      int d, c;
      cin >> d >> c;
      
      if (d == 1) {
        vector<vector<int>> y(x.size(), vector<int>(max<int>(c, x[0].size() - c), 0));
        for (int i = 0; i < x.size(); i++) {
          for (int j = 0; j < x[0].size(); j++) {
            if (j < c) y.at(i).at(c - 1 - j) += x.at(i).at(j);
            else y.at(i).at(j - c) += x.at(i).at(j);
          }
        }
        x = y;
      }
      else {
        vector<vector<int>> y(max<int>(c, x.size() - c), vector<int>(x[0].size(), 0));
        for (int j = 0; j < x[0].size(); j++) {
          for (int i = 0; i < x.size(); i++) {
            if (i < c) y.at(c - 1 - i).at(j) += x.at(i).at(j);
            else y.at(i - c).at(j) += x.at(i).at(j);
          }
        }
        x = y;
      }
    }
    
    for (int i = 0; i < p; i++) {
      int xx, yy;
      cin >> xx >> yy;
      swap(xx, yy);
      cout << x.at(xx).at(yy) << '\n';
    }
  }
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int n;
	vector<int> a;
	cin >> n;

	int f = n % 2;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		if(f){
			if(i % 2 == f){
				a.pb(t);
			}else{
				a.insert(a.begin(), t);
			}
		}else{
			if(i % 2 == f){
				a.pb(t);
			}else{
				a.insert(a.begin(), t);
			}
		}
	}
	for(int i=0; i<n; i++){
		printf("%d ", a[i]);
	}
	puts("");
	
	return 0;
}


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

using namespace std;

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

    if(a < b) {
        for (size_t i = 0 ; i < b; ++i) {
            cout << a;
        }
    }
    else {
        for (size_t i = 0; i < a; ++i) {
            cout << b;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;


signed main(){
	//cout << fixed << setprecision(10);
	ll n; cin >> n;
	vl a(n);
	rep(i,0,n) cin >>a[i];
	ll ans = 0;
	rep(i,1,n){
		if(a[i]-a[i-1]>=0)continue;
		ans += a[i-1]-a[i];
		a[i] = a[i-1];
	}
	cout << ans <<endl;

	return 0;
}

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

char a, b;

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

	cin >> a >> b;
	if (a == 'H') {
		cout << b << '\n';
	}
	else {
		if (b == 'H') {
			cout << 'D' << '\n';
		}
		else {
			cout << 'H' << '\n';
		}
	}

    return 0;
}

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

static const int N = 100;

int main(){
  int n,p[N + 1], m[N + 1][N + 1];
  cin >> n;
  for(int i = 1; i <=n; i++){
  cin >> p[i - 1] >> p[i];
 }

 for(int i = 1;i <=n; i++)m[i][i] = 0;
 for(int l = 2;l <=n; l++){
    for(int i = 1; i <= n - l + 1; i++){
    int j = i + l - 1;
    m[i][j] = (1 << 21);
    for(int k = i; k <= j - 1; k++){
    m[i][j] = min(m[i][j],m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j]);
    }
  }
}
   cout << m[1][n] << endl;

   return 0;
}

Measured memory_bytes: 3124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {

	public static int max=(int) (1e5 + 5);
	public static LinkedList<Integer>[] adjLinkedList=new LinkedList[max];
	public static int degree[]=new int[max];
	public static int dist[]=new int[max];
	public static boolean visited[]=new boolean[max];
	
	public static void dfs(int a) {
		
		
			visited[a]=true;
			for(int b:adjLinkedList[a])
			{
				dist[b]=Math.max(dist[b], dist[a]+1);
				degree[b]--;
				if(degree[b]==0)
					dfs(b);
				
			}
		
	}
	
	public static void main(String[] args) {
		FastScanner scanner=new FastScanner();
		int n=scanner.nextInt(),m=scanner.nextInt();
		//adjLinkedList
		for(int i=1;i<=n;i++)
			 adjLinkedList[i] = new LinkedList<Integer>();
		for(int i=0;i<m;i++) {
			int a=scanner.nextInt(),b=scanner.nextInt();
		
			adjLinkedList[a].add(b);
		
			degree[b]++;
		}

		for(int i=1;i<=n;i++) {
			if(!visited[i]&&degree[i]==0) {
				
				dfs(i);
			}
		}
		
		int ans=0;
		for(int i:dist) ans=Math.max(ans, i);
		System.out.println(ans);
		

	}
	static class FastScanner{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}
		
		
	}

}


Measured memory_bytes: 86184
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
using namespace std;
int mincost[10][10];
int main(void){
	int i,j,N,Y;
	cin >> N >> Y;
	for(i=0;i<=N;i++){
		for(j=0;N-j-i>=0;j++){
			if(Y==i*1000+j*5000+(N-i-j)*10000){
				cout << (N-i-j) << ' '<<j << ' '<< i;
				return 0;
			}
		}
	}
	
	cout <<-1<< ' '<<-1<< ' '<< -1;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int t,i,n,b[1234],a[1234],h,c[1234];
	
	while(1){
		scanf("%d",&n);
		if(n==0){
			return 0;
		}
		for(t=0;t<=n;t++){
			scanf("%d",&c[t]);
		}
		for(i=0;i<=n;i++){
			h=0;
			for(t=0;t<=n;t++){
				a[t]=c[t];
			}
			for(t=i;t<n;t++){
				a[t]=a[t+1];
			}
			for(t=1;t<n;t++){
				b[t-1]=a[t]-a[t-1];
			}
			for(t=1;t<n-1;t++){
				if(b[t-1]==b[t]){
					h++;
				}
			}
			if(h==n-2){
				break;
			}
		}
		printf("%d\n",c[i]);
	}
					

}

Measured memory_bytes: 616
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

int gcd(int a,int b){
    if(a<b){
        int temp=a;
        a=b;
        b=temp;
    }

    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
        
    }
    return b;
}
int main(){
    int k;
    cin>>k;
    int sum=0;
    for(int i=1;i<k+1;i++){
        for(int j=1;j<k+1;j++){
            int gcd_ab=gcd(i,j);
            for(int l=1;l<k+1;l++){
                sum+=gcd(gcd_ab,l);
            }
            
        }
    }
    cout<<sum;
    return 0;
}

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

const int MAX_N = 100030;    // Change as necessary

int A[MAX_N];
pair<int,int> B[MAX_N];

int main(){
  int n; cin >> n;
  for(int i=0;i<n;i++) cin >> A[i];
  for(int i=0;i<n;i++) B[i] = make_pair(A[i],i%2);
  
  sort(B,B+n);
  
  int ctr[2] = {0};
  for(int i=0;i<n;i++)
    if((i%2) != (B[i].second%2))
      ctr[i%2]++;
  
  assert(ctr[0] == ctr[1]);
  cout << ctr[0] << endl;
  
  return 0;
}


Measured memory_bytes: 1536
from collections import defaultdict
 
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n

	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]
	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			x, y = y, x
		self.parents[x] += self.parents[y]
		self.parents[y] = x

	def size(self, x):
		return -self.parents[self.find(x)]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def members(self, x):
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i) == root]
	def roots(self):
		return [i for i, x in enumerate(self.parents) if x < 0]
	def group_count(self):
		return len(self.roots())
	def all_group_members(self):
		ret = defaultdict(list)
		for i in range(self.n):
			ret[self.find(i)].append(i)
		return ret

	def __str__(self):
		return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

for _ in range(m):
	a,b = map(int, input().split())
	uf.union(a, b)
MA = 0
for i in range(n+1):
	if MA <= uf.size(i):
		MA = uf.size(i)
print(MA)

Measured memory_bytes: 14992
def g(l):
    n=len(l)
    for i in range(n):
        if l[i]%2==0 and (l[i]%5!=0 and l[i]%3!=0):
            return 'DENIED'
    return "APPROVED"
n=int(input())
l=list(map(int,input().split()))
print(g(l))

Measured memory_bytes: 3060
const main = async () => {
  const input = require('fs').readFileSync('/dev/stdin', 'UTF-8').trim()
  const array = input.split('\n')
  const n = array.shift()
  const results = {
    AC: 0,
    WA: 0,
    TLE: 0,
    RE: 0
  }
  array.forEach((item) => results[item]++)
  const result = ['AC', 'WA', 'TLE', 'RE'].map((item) => {
    return `${ item } x ${ results[item] }`
  })
  console.log(result.join('\n'))
}

main()

Measured memory_bytes: 36256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n;
  cin>>n;
  int a=0,w=0,t=0,r=0;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s=="AC") a++;
    else if(s=="WA") w++;
    else if(s=="TLE") t++;
    else r++;
  }
  cout<<"AC x "<<a<<endl;
  cout<<"WA x "<<w<<endl;
  cout<<"TLE x "<<t<<endl;
  cout<<"RE x "<<r<<endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAX = 1000002;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll dectobin(ll n,ll p[])
{
    ll i=0 ;
    while(n!=0)
    {
        p[i]=n%2 ;
        n/=2 ;
        i++ ;
    }
    return(i-1) ;
}
ll binarySearchCount(ll arr[], ll n, ll key) 
{ 
    ll left = 0; 
    ll right = n - 1; 
  
    ll count = 0; 
  
    while (left <= right) { 
        int mid = (right + left) / 2; 
  
        // Check if middle element is 
        // less than or equal to key 
        if (arr[mid] < key) { 
  
            // At least (mid + 1) elements are there 
            // whose values are less than 
            // or equal to key 
            count = mid + 1; 
            left = mid + 1; 
        } 
  
        // If key is smaller, ignore right half 
        else
            right = mid - 1; 
    } 
  
    return count; 
} 
void printDivisors(ll n,ll k) 
{  ll temp=1  ;
    // Note that this loop runs till square root 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            // If divisors are equal, print only one 
            if (n/i == i) 
                {
                	if(i<=k && i>temp)
                	temp=i ;
				}
  
            else // Otherwise print both 
                
                {
                if(i<=k && i>temp)
                	temp=i ;
                if(n/i<=k && n/i>temp)
                temp=n/i ;
				}
        } 
    }
	cout<<n/temp<<"\n" ;
	return ; 
} 
 
int main(int argc, char** argv)
{   sws ;
 //tcase
{
	ll n ;
	cin>>n ;
	ll a[n],b[n] ;
	forn(i,n)
	{
		cin>>a[i] ;
		cin>>b[i] ;
	}
	sort(a,a+n) ;
	sort(b,b+n) ;
	if(n%2==1)
	cout<<b[n/2]-a[n/2]+1<<"\n" ;
	else
	{
		cout<<((b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1]))+1<<"\n" ;
	}
}
return 0 ;
}
  

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

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

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int food[35];

int main(){
  int n, m, k;
  cin >> n >> m;
  REP(i, n){
    cin >> k;
    REP(j, k){
      int tmp;
      cin >> tmp;
      food[tmp-1]++;
    }
  }
  int res=0;
  REP(i, m) if(food[i]==n) res++;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N;
    R(N);
    int w[200];
    int ss=0;
    FOR(i,1,N){
        R(w[i]);
        ss+=w[i];
    }
    int now=0;
    int an=ss;
    FOR(i,1,N){
        now+=w[i];
        an=min(an,abs(now-(ss-now)));
    }
    W(an);
    return 0;
}


Measured memory_bytes: 256
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(1, n):
        min_i = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_i, i)])
    print(dp[n-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 13876
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<cassert>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()


using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


int main(int argc, char const* argv[])
{
    int n;
    cin >> n;

    if (n % 10 == 9 || n / 10 == 9) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = set()
s.add(1)
former = []
latter = []
temp = [1]
cur = a[0]
buf = 0

while True:
    if cur not in s:
        s.add(cur)
        temp.append(cur)
        cur = a[cur-1]
    else:
        buf = temp.index(cur)
        former = temp[:buf]
        latter = temp[buf:]
        break

# print('buf:', buf)
# print('former:', former)
# print('latter:', latter)

if len(latter) == 0:
    mod = k % len(temp)
    print(temp[mod])
    exit()

if k <= len(former):
    # print(former[k])
    print(temp[k])
else:
    # mod = k % len(latter)
    mod = (k-len(former)) % len(latter)
    # print('mod:', mod)
    # idx = mod - len(former)
    idx = mod
    
    print(latter[idx])

Measured memory_bytes: 126648
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
  int r;
  cin >> r;
  if(r < 1200) cout << "ABC" << endl;
  else if(r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
  return 0;
  
}



Measured memory_bytes: 256
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

W, H, x, y = mi()

ans1 = (W*H)/2

ans2 = 1 if W%2==0 and H%2==0 and x==W//2 and y==H//2 else 0

print(ans1, ans2)





Measured memory_bytes: 38256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            int k = sc.nextInt();
            int[] children = new int[k];
            for (int j = 0; j < k; j++) {
                children[j] = sc.nextInt();
            }
            nodes[id] = new Node(id, children);
        }

        solve(nodes);

        for (int i = 0; i < nodes.length; i++) {
            Node node = nodes[i];
            String type = node.type == Type.INTERNAL_NODE ? "internal node" : node.type == Type.LEAF ? "leaf" : "root";
            System.out.println("node " + node.id + ": parent = " + node.parent + ", depth = " + node.depth + ", "
                               + type + ", " + Arrays.toString(node.children));
        }
    }

    private static void solve(Node[] nodes) {
        for (int i = 0; i < nodes.length; i++) {
            Node n = nodes[i];
            for (int j = 0; j < n.children.length; j++) {
                nodes[n.children[j]].parent = n.id;
            }
        }

        int root = -1;
        for (int i = 0; i < nodes.length; i++) {
            Node n = nodes[i];
            if (n.parent == -1) {
                root = n.id;
                n.type = Type.ROOT;
                n.depth = 0;
            }
        }

        rec(nodes, root, 1);
    }

    private static void rec(Node[] nodes, int parent, int depth) {
        int[] children = nodes[parent].children;
        for (int i = 0; i < children.length; i++) {
            Node child = nodes[children[i]];
            child.depth = depth;
            if (child.children.length != 0) {
                child.type = Type.INTERNAL_NODE;
                rec(nodes, child.id, depth + 1);
            } else {
                child.type = Type.LEAF;
            }
        }
    }

    static class Node {

        Node(int id, int[] children) {
            this.id = id;
            this.children = children;
            this.parent = -1;
        }

        int id;
        int parent;
        int depth;
        int[] children;
        Type type;
    }

    enum Type {
        ROOT, INTERNAL_NODE, LEAF;
    }
}

Measured memory_bytes: 123404
#include "bits/stdc++.h"
using namespace std;
int n, c1, c2, c3, x; 
long double dp[303][303][303];
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> x;
		if (x==1) c1++;
		else if (x==2) c2++;
		else c3++;
	}
	for (int k=0; k<=c3; k++)
		for (int j=0; j<=(c3+c2-k); j++)
			for (int i=0; i<=(n-j-k); i++){
				if(i+j+k==0) continue; 
				dp[i][j][k] = ((long double)(n))/(i+j+k);
				if(i) dp[i][j][k] += (((long double)(i))/(i+j+k)) * dp[i-1][j][k];
				if(j) dp[i][j][k] += (((long double)(j))/(i+j+k)) * dp[i+1][j-1][k];
				if(k) dp[i][j][k] += (((long double)(k))/(i+j+k)) * dp[i][j+1][k-1];
		//		cout << i << " " << j << " " << k << "   " << dp[i][j][k] << endl;
			}
	cout << setprecision(12) << dp[c1][c2][c3];
return 0;
}

Measured memory_bytes: 213972
#include<iostream>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
ll gcd(ll a,ll b)
{
	if(b==0)return a;
	else return gcd(b,a%b);
}
int main()
{
	int t;
	cin>>t;
	ll num[105],g;
	for(int i=1;i<=t;i++)
	{
		cin>>num[i];
	}
	g=num[1];
	for(int i=2;i<=t;i++)
	{
		g=g/gcd(g,num[i])*num[i];		
	}
	cout<<g<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const double PI=3.14159265358979323846;

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

  cout << t+s << endl;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
S=list(input())
if S[K-1]=="A":
    S[K-1]="a"
elif S[K-1]=="B":
    S[K-1]="b"
elif S[K-1]=="C":
    S[K-1]="c"
print(''.join(S))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;

int father[N], dep[N], mx[N], k, ans;
vector<int > p[N];

void dfs(int x, int fa){
	dep[x] = dep[fa] + 1; mx[x] = dep[x]; 
	for (int v : p[x]){
		dfs(v, x);
		mx[x] = max(mx[x], mx[v]);
	}
	if (x != 1 && mx[x] > k + 1 && mx[x] - dep[x] == k - 1) {ans ++; mx[x] = 0; }
}

int main(){
	int n;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++){
		scanf("%d", &father[i]);
		if (i != 1) p[father[i]].push_back(i);
	}
	ans = (father[1] != 1);
	dfs(1, 0);
	printf("%d", ans);
	return 0;
}

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

class TSort{
public:
  int V;
  vector<unordered_set<int> > in,out;
  vector<int> tp;
  TSort():V(0){}
  TSort(int V):V(V),in(V),out(V){}
  
  void add_edge(int from,int to){
    assert(from >= 0 && to >= 0);
    assert(from < V && to < V);
    out[from].insert(to);
    in[to].insert(from);
  }

  vector<int> dfs(){
    vector<int> visited(V,0);
    
    function<void(int)> dfs = [&](int pos){
      if(visited[pos]++) return;
      for(int nx:out[pos]) dfs(nx);
      tp.push_back(pos);
    };
    
    tp.clear();
    for(int i=0;i<V;i++) dfs(i);
    reverse(tp.begin(),tp.end());
    return tp;
  }

  vector<int> bfs(){
    vector<unordered_set<int> > tmp = in;
    tp.clear();
    queue<int> Q;
    for(int i=0;i<V;i++)if(in[i].empty()) Q.push(i);
    
    while(!Q.empty()){
      int v = Q.front();Q.pop();
      tp.push_back(v);
      for(int nx:out[v]){
        if(in[nx].size() == 1) Q.push(nx);
        in[nx].erase(v);
      }     
    }
    swap(in,tmp);
    for(int i=0;i<V;i++) if(!tmp[i].empty()) tp.clear(); // exist loop
    return tp;
  }
};


int main(){
  int n,m;
  cin>>n>>m;
  TSort A(n);
  
  for(int i=0,a,b;i<m;i++)cin>>a>>b,A.add_edge(a,b);
  
  A.dfs();
  for(int i=0;i<n;i++)cout<<A.tp[i]<<endl;
  return 0;
}



Measured memory_bytes: 8328