akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

bool pairw(const vector<int>& arr) {
	int n = arr.size();
	vector<int> fac(maxV);
	for(int i = 2; i < fac.size(); i++)
		for(int j = i; j < fac.size(); j += i)
			if(!fac[j]) fac[j] = i;
	
	set<int> mys;
	for(auto el: arr) {
		set<int> cr;
		while(el > 1) {
			cr.insert(fac[el]);
			el /= fac[el];
		}
		for(auto el: cr) {
			if(mys.count(el)) return false;
			mys.insert(el);
		}
	}
	return true;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n;
	cin >> n;
	vector<int> arr(n);
	for(auto& el: arr) cin >> el;
	if(pairw(arr)) {
		cout << "pairwise coprime\n";
	} else {
		int gg = 0;
		for(auto el: arr) gg = __gcd(gg, el);
		if(gg == 1) cout << "setwise coprime\n";
		else cout << "not coprime\n";
	}
}



Measured memory_bytes: 11156
def make_divisors(n):  # 任意の整数の約数をリストで返す関数
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


N = int(input())

if N == 2:
    print("1")
else:

    hoge = make_divisors(N - 1)
    hoge.append(N)
    X = make_divisors(N)

    for i in range(1,len(X)):
        a = X[i]
        while a <= N:    
            if N % a != 0:
                break
                
            if (N // a) % X[i] == 1:
                hoge.append(X[i])
                
            a *= X[i]

    print(len(set(hoge))-1)


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long k,a,b;cin>>k>>a>>b;
    //printf("%I64d %I64d %I64d %d\n",a,k+2,b,a>=k+2);
    if (b<=a+1) {
        cout<<k+1<<endl;
        return 0;
    }
    if (k-(a-1)<=1) {
        cout<<k+1<<endl;
        return 0;
    }
    k-=a+1;
    cout<<b+k/2*(b-a)+(k&1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    string s;
    cin>>s;
    rep(0,i,3){
        string s0=s.substr(i,1);
        if(s.substr(i,2)==s0+s0){
            cout<<"Bad";
            return 0;
        }
    }
    cout<<"Good";
    
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long a[100008];
int main()
{
    long long  n;
    cin>>n;
    int x,l=0;
    long long  ans=0,s=0;
    for(int i=1;i<=n;i++){cin>>a[i];s+=a[i];}
    a[n+1]=a[1];
    long long int u=n*(n+1LL)/2LL;
    if(s%u!=0){cout<<"NO"<<endl;return 0;}
    long long w=s/u;
    long long k=0;
    for(int i=1;i<=n;i++)
    {
        long long h=a[i]-a[i+1];
        h+=w;
        if(h%n!=0){cout<<"NO"<<endl;return 0;}
        h=h/n;
        if(h<0){cout<<"NO"<<endl;return 0;}
        k+=h;
    }
    if(k==w)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;


}


Measured memory_bytes: 1024
<?php

fscanf(STDIN, "%s", $S);
$r = [
    0 => [
        'word' => 'dreamer',
        'len' => 7,
    ],
    1 => [
        'word' => 'dream',
        'len' => 5,
    ],
    2 => [
    'word' => 'eraser',
        'len' => 6,
    ],
    3 => [
        'word' => 'erase',
        'len' => 5,
    ],
];

for ($i=0; $i < count($r); $i++) {
  $len = $r[$i]['len'];
  $tem = substr($S, -$len);
  if ($tem === $r[$i]['word']) {
    $S = substr($S, 0, strlen($S) - $len);
    $i = -1;
  }
}
echo empty($S) ? 'YES':'NO';

?>

Measured memory_bytes: 4728
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<vector<int>>field(N, vector<int>(N));
		vector<vector<int>>flag(N, vector<int>(N));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cin >> field[i][j];
			}
		}
		for (int i = 0; i < N; ++i) {
			pair<int, int>p(INT_MAX, 100);
			for (int j = 0; j < N; ++j) {
				p = min(p, make_pair(field[i][j], j));
			}
			for (int j = 0; j < N; ++j) {
				if (field[i][j] == p.first)flag[i][j]++;
			}
		}
		for (int j = 0; j < N; ++j) {
			pair<int, int>p(-1, 100);
			for (int i = 0; i < N; ++i) {
				p = max(p, make_pair(field[i][j], i));
			}
			for (int i = 0; i < N; ++i) {
				if (field[i][j] == p.first)flag[i][j]++;
			}
		}
		pair<int, int>ans(-1, 0);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (flag[i][j] == 2)ans = make_pair(i, j);
			}
		}
		if (ans.first == -1)cout << 0 << endl;
		else cout << field[ans.first][ans.second] << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
/*  I love Cara Delevingne */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

ll n, a[MAXN][5], dp[MAXN][5];


int main() {

    cin >> n;
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= 3; j++) {
    		cin >> a[i][j];
    	}
    } 
    for (int i = 1; i <= 3; i++) {
    	dp[1][i] = a[1][i];
    }
    for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= 3; j++) {
			for (int k = 1; k <= 3; k++) {
				if (j == k) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
			}
		}        
	}
    ll mx = 0;
    for (int i = 1; i <= 3; i++) {
    	mx = max(dp[n][i], mx);
    }
    cout << mx;
	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n;
	cin >> n;
	n = n * (n - 1) / 2;
	cout << n << endl;

	return 0;
}

Measured memory_bytes: 3640
def gcd(x, y):
    """Greatest Common Divisor: O(min(x,y,))"""
    if y == 0:
        return x
    return gcd(y, x % y)


def lcm(x, y):
    """Lowest Common Multiple O(min(x,y,))"""
    return x * y // gcd(x, y)


def div_count(x, l, r):
    """Count Divisors"""
    return r // x - (l - 1) // x


# inputs
a, b, c, d = [int(i) for i in input().split()]

# solve
div_cd = div_count(c, a, b) + div_count(d, a, b) - div_count(lcm(c, d), a, b)

print(b - a + 1 - div_cd)


Measured memory_bytes: 3060
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
using namespace std;
int main()
{
    int  a,b,c,i,sum=0,cnt=0;
    vi v;
    cin>>a>>b;
    for(i=0; i<a; i++)
    {
        cin>>c;
        v.pb(c);
        sum+=c;

    }
    double vo=(double)sum/4/b;
    //cout<<vo<<endl;
    for(i=0 ; i<v.size() ; i++)
    {
        if(v[i]>=vo)
            cnt++;
    }
    if(cnt>=b)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;



    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
#include<iostream>

using namespace std;
typedef long long ll;
int n,a[10005],b[10005];
ll c,d,e;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		d += a[i];
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
		e += b[i];
		if(a[i] < b[i]){
			c += (b[i] - a[i] + 1)/2;
		}
	}
	if(c <= e - d) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 384
//===================== Author Info ==================
//  Khaled Alam (Ninjo)   ~   khaledalam.net@gmail.com
//====================================================
#include <bits/stdc++.h>
using namespace std;
#define  sz           size()
#define  fi           first
#define  se           second
#define  mp           make_pair
#define  pb           push_back
#define  ll           long long int
#define  ones         __builtin_popcount
#define  all(a)       (a).begin(), (a).end()
#define  iFile(a)     freopen(#a, "r", stdin)
#define  oFile(a)     freopen(#a, "w", stdout)
#define  rep(i,a,z)   for(auto i=(a);i<(z);i++)
#define  ios          ios_base::sync_with_stdio(false)
#define  tm           fprintf(stderr,"%.3f s\n",(float)clock()/1000);

int main() {
//iFile(input.txt);
//oFile(output.txt);
	string s,ans;
	cin>>s;
	for(auto c : s){
		if(c =='0'){
			ans += '0';
		}else if(c == '1'){
			ans += '1';
		}else{
			if(ans.sz > 0)ans.pop_back();
		}
	}
	cout<<ans;

}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

ll min(ll a, ll b) {
  return a > b ? b : a;
}

ll max(ll a, ll b) {
  return a > b ? a : b;
}

int main(void) {
  ll i, j, k, a, b, c, x, y, ans;
  scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &x, &y);
  c *= 2;
  if(c < a + b) ans = c * min(x, y) + a * (x - min(x, y)) + b * (y - min(x, y));
  else ans = a * x + b * y;
  if(ans > c * max(x, y)) ans = c * max(x, y);
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
package main
 
import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}
 
func nextString() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var ANS int
func main() {
	N := nextInt()
	D := nextInt()
	for i := 0; i < N; i++ {
		x := nextInt()
		y := nextInt()
		if x * x + y * y <= D * D {
			ANS++
		}
	}
	fmt.Println(ANS)
}


Measured memory_bytes: 5864
N = gets.to_i
a = []
a[0] = gets.split.map(&:to_i)
a[1] = gets.split.map(&:to_i)

#上の段a[0]
N.times do |j|
  if(j < N-1)
    a[0][j+1] = a[0][j+1] + a[0][j]
  end
end

#下の段a[1]
N.times do |j|
  if(j > 0)
    a[1][j] = [a[0][j], a[1][j-1]].max + a[1][j]
  else
    a[1][0] = a[1][0] + a[0][0]
  end
end

puts a[1][N-1]

Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>


using namespace std;
const int MOD = 1000000009; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

bool b[21][21];

int main(){

	int n;
	while(cin>>n,n){
		int ans = 0;
		for(int i = 1; i < n; i++){
			int x = n;
			for(int j = i; x > 0; j++){
				x -= j;
			}
			if(x == 0) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M), cities(N);

    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < M; i++){
        cities[a[i] - 1]++;
        cities[b[i] - 1]++;
    }
    for(int j = 0; j < N; j++){
        cout << cities[j] << endl;
    }
}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MAX = 2e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int pr[MAX], ne[MAX], pos[MAX];

int main() {
  // 入力
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  for (int i = 0; i < N; i++) {
    a[i]--;
    pos[a[i]] = i;
  }
  for (int i = 0; i < N; i++) {
    pr[i] = i - 1;
    ne[i] = i + 1;
  }

  // 大きいものから見ていく
  ll ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    int j = pos[i];
    ans += 1LL * (i + 1) * (j - pr[j]) * (ne[j] - j);
    pr[ne[j]] = pr[j];
    ne[pr[j]] = ne[j];
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
import sys
X = sys.stdin.readline() 
x = int(X)
n = 1
m = 1
ans = 1
for i in range(9):
    n=1
    b = i+2
    a = 1
    while n <= x:
        a+=1
        n = a**b
        if n<=x and n>=ans:
            ans = n
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cctype>

using namespace std;

string toUpper(string s){
	string t = s;
	for(int i=0;i<s.size();i++){
		t[i] = toupper(s[i]);
	}
	return t;
}

int main(){
	string target, source;

	cin >> target;
	target = toUpper(target);

	int cnt = 0;

	while(1){
		cin >> source;
		if(source == "END_OF_TEXT") break;
		source = toUpper(source);
		if(target == source) cnt++;
	}

	cout << cnt << endl;

	return 0;
}

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

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int n;
    bool res=false;
    vector<pair<int,int>>v;
    cin>>n;
    for(int x,y,i=0;i<n;i++){
    	cin>>x>>y;
    	v.push_back({x,y});
    }
    for(int i=0;i<=n-3;i++){
    	bool ok=true;
    	for(int j=i;j<=i+3-1;j++){
    		if(v[j].first!=v[j].second)ok=false;
    	}
    	if(ok)res=true;
    }
    cout<<(res?"Yes":"No");

    
}

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

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

    if (N <= 9) {
        cout << N << "\n";
    } else if (N <= 99) {
        cout << 9 << "\n";
    } else if (N <= 999) {
        cout << N - 90 << "\n";
    } else if (N <= 9999) {
        cout << 909 << "\n";
    } else if (N <= 99999) {
        cout << N - 9090 << "\n";
    } else {
        cout << 90909 << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long A, B, N;
  cin >> A >> B >> N;
  long long ans = (__int128_t)A * min(B - 1, N) / B;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,dis[305][305],l,m,ans[305][305];pii d[305];bool vis[305];
void dijkstra(int x){
    rep(i,1,n) d[i]=mpr(inf,0),vis[i]=0;
    d[x]=mpr(0,0);
    rep(i,1,n){
        int ind=-1;
        rep(j,1,n) if(!vis[j]&&(ind==-1||d[ind]>d[j])) ind=j;
        rep(j,1,n) if(j!=ind&&dis[ind][j]<=l){
            int g=d[ind].se+dis[ind][j];
            if(g>l) d[j]=min(d[j],mpr(d[ind].fi+1,dis[ind][j]));
            else d[j]=min(d[j],mpr(d[ind].fi,g));
        }
        vis[ind]=1;
    }
    //printf("%d\n",x);
    //rep(i,1,n) printf("%d %d\n",d[i].fi,d[i].se);
    rep(i,1,n) ans[x][i]=d[i].fi;
}
int main()
{
    scanf("%d%d%d",&n,&m,&l);
    rep(i,1,n) rep(j,1,n) dis[i][j]=inf;
    rep(i,1,m){
        int t1,t2,t3;
        scanf("%d%d%d",&t1,&t2,&t3);
        dis[t1][t2]=dis[t2][t1]=t3;
    }
    rep(i,1,n) dijkstra(i);
    int q;scanf("%d",&q);
    while(q--){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        if(ans[t1][t2]>n) printf("-1\n");
        else printf("%d\n",ans[t1][t2]);
    }
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

// dp[a][b][c][d]
// a: 桁数
// b: 後ろから3文字目の値
// c: 後ろから2文字目の値
// d: 後ろから1文字目の値
ll dp[102][4][4][4] = {};

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

  //初期化
  for(int num=0;num<=2;num++){
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
        for(int k=0;k<4;k++){
          dp[num][i][j][k] = 0;
        }
      }
    }
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        dp[3][i][j][k] = 1;
      }
    }
  }
  dp[3][0][1][2] = 0;
  dp[3][1][0][2] = 0;
  dp[3][0][2][1] = 0;

  for(int num=3;num<=N;num++){
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++){
        for(int c=0;c<4;c++){
          dp[num][a][b][c] %= MOD;
          if(b==0 && c==1) {
            dp[num+1][b][c][0] += dp[num][a][b][c];
            dp[num+1][b][c][1] += dp[num][a][b][c];
            dp[num+1][b][c][2] += 0;
            dp[num+1][b][c][3] += dp[num][a][b][c];
            continue;
          }else if(b==1 && c==0) {
            dp[num+1][b][c][0] += dp[num][a][b][c];
            dp[num+1][b][c][1] += dp[num][a][b][c];
            dp[num+1][b][c][2] += 0;
            dp[num+1][b][c][3] += dp[num][a][b][c];
            continue;
          }else if(b==0 && c==2) {
            dp[num+1][b][c][0] += dp[num][a][b][c];
            dp[num+1][b][c][1] += 0;
            dp[num+1][b][c][2] += dp[num][a][b][c];
            dp[num+1][b][c][3] += dp[num][a][b][c];
            continue;
          }
          if(a==0 && c==1) {
            dp[num+1][b][1][0] += dp[num][a][b][c];
            dp[num+1][b][1][1] += dp[num][a][b][c];
            dp[num+1][b][1][2] += 0;
            dp[num+1][b][1][3] += dp[num][a][b][c];
            continue;
          }else if(a==0 && b==1){
            dp[num+1][1][c][0] += dp[num][a][b][c];
            dp[num+1][1][c][1] += dp[num][a][b][c];
            dp[num+1][1][c][2] += 0;
            dp[num+1][1][c][3] += dp[num][a][b][c];
            continue;
          }

          for(int key=0;key<4;key++)
            dp[num+1][b][c][key] += dp[num][a][b][c];
        }
      }
    }
  }

  ll ans = 0;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        ans += dp[N][i][j][k];
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	vector<int> p(n);
	for(auto &i:p) cin >> i;
	vector<double> e(n);
	for(int i=0; i<n; ++i)
		e[i] = (double)(p[i] + 1) / 2;
//	for(int i=0; i<n; ++i)
//		cerr << i << " " << e[i] << "\n";
	for(int i=1; i<n; ++i)
		e[i] += e[i-1];
	double ans = e[k-1];
	for(int i=k; i<n; ++i)
		ans = max(ans, e[i] - e[i-k]);
	cout << fixed << setprecision(10) << ans << "\n";
}

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

const int MOD = 1e9+7;


int main(){
    int S;
    cin >> S;
    vector<long long> dp(2010, 0);
    dp[0] = 1;

    for(int i=0; i<2010; ++i){
        for(int j=0; j<=i-3; ++j){
            dp[i] += dp[j];
            dp[i] %= MOD;
        }
    }

    cout << dp[S] << endl;

}

Measured memory_bytes: 3580
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {

   int N;
   cin >> N;
   bool F[N][10];
   for (int i = 0; i < N; i++) {
      for (int j = 0; j < 10; j++) {
         cin >> F[i][j];
      }
   }
   int P[N][11];
   for (int i = 0; i < N; i++) {
      for (int j = 0; j < 11; j++) {
         cin >> P[i][j];
      }
   }
   
   int ans;
   int D = 10;
   for (int mask = 0; mask < (1 << D); ++mask) {
      int tmp = 0;
      for (int iStore = 0; iStore < N; ++iStore) {
         int cnt = 0;
         for (int i = 0; i < D; ++i) {
            if (F[iStore][i] && ((mask >> i) & 1)) cnt++;
            // cout << mask << "の" << i << "桁目: " << ((mask >> i) & 1) << endl;
         }
         // cout << iStore << " " << cnt << endl; 
         tmp += P[iStore][cnt];
      }
      // cout << mask << " " << tmp << endl;
      if (mask == 1) ans = tmp;
      if (mask != 0 && tmp > ans) ans = tmp;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
h_base=list(map(int,input().split()))
h={}
road={}
for i in range(1,n+1):
    h[i]=h_base[i-1]
    road[i]=[]

for i in range(m):
    a,b=map(int,input().split())
    road[a].append(b)
    road[b].append(a)

ans=0
for i in road.keys():
    if len(road[i])==0:
        ans+=1
    else:
        count=0
        for each in road[i]:
            if h[i]<=h[each]:
                count+=1
        if count==0:
            ans+=1
print(ans)


Measured memory_bytes: 43756
#include <stdio.h>

int main(void)
{
    int n,m;
    scanf("%d %d",&n,&m);
    int h[n+1];
    int x[n+1];
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
        x[i]=1;
    }
    int a,b;
    for(int i=0;i<m;i++){
        scanf("%d %d",&a,&b);
        a--;
        b--;
        if(h[a]>h[b]){
            x[b]=0;
        }else if(h[a]<h[b]){
            x[a]=0;
        }else{
            x[a]=0;
            x[b]=0;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(x[i]==1){
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

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

template <typename T>
class BinaryIndexedTree
{
    vector<T> arr;
    T initial_value;
    long long size;

public:
    BinaryIndexedTree(const long long N, T init)
    {
        set_size(N);
        set_initial_value(init);
        initialize_array();
    }

    void set_size(const long long N)
    {
        this->size = N + 1;
    }

    void set_initial_value(const T init)
    {
        this->initial_value = init;
    }

    void initialize_array()
    {
        this->arr = vector<T>(size, initial_value);
    }

    void initialize_array(const T init)
    {
        set_initial_value(init);
        initialize_array();
    }

    void update(long long idx, T value)
    {
        while (idx <= this->size)
        {
            this->arr[idx] = this->arr[idx] + value;
            idx += (idx & -idx);
        }
    }

    T query(long long idx)
    {
        T ret = this->initial_value;
        while (idx > 0)
        {
            ret = ret + this->arr[idx];
            idx -= (idx & -idx);
        }
        return ret;
    }
};

int main()
{
    long long N, D, A;
    cin >> N >> D >> A;

    BinaryIndexedTree<long long> bit(N * 3, 0);
    vector<pair<long long, long long>> xh(N);
    long long X, H;
    for (long long i = 0; i < N; i++)
    {
        cin >> X >> H;
        xh[i] = make_pair(X, H);
    }
    sort(xh.begin(), xh.end());
    vector<long long> idxs;
    for (int i = 0; i < N; i++)
    {
        idxs.push_back(xh[i].first);
        idxs.push_back(xh[i].first - D - 1);
        idxs.push_back(xh[i].first + D);
    }
    sort(idxs.begin(), idxs.end());
    unique(idxs.begin(), idxs.end());
    map<long long, long long> inv;
    for (long long i = 0; i < idxs.size(); i++)
    {
        inv[idxs[i]] = i;
    }

    long long ans = 0;
    for (long long i = 0; i < N; i++)
    {
        long long minimum = inv[xh[i].first - D - 1];
        long long maximum = inv[xh[i].first + D];
        long long current = bit.query(maximum) - bit.query(minimum);
        if (current >= xh[i].second)
        {
            continue;
        }
        long long add = (xh[i].second - current) / A;
        if (add * A < xh[i].second - current)
        {
            add++;
        }
        ans += add;
        bit.update(maximum, A * add);
    }
    cout << ans << endl;
}


Measured memory_bytes: 51560
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
int m = max({a,b,c});
  cout <<  a + b + c + m * 9 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int[] al = new int[26];
    for (int i = 0; i < S.length(); i++) {
      al[S.charAt(i) - 'a']++;
    }
    boolean dif = true;
    for (int i = 0; i < 26; i++) {
      if (al[i] > 1) {
        dif = false;
      }
    }
    if (dif) {
      System.out.println("yes");
    } else {
      System.out.println("no");
    }
  }
}

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

int main(void){
  int num[2]={0,0};
  string mes[4]={"NA","MMYY","YYMM","AMBIGUOUS"};
  
  for (int i=0; i<4; i++){
    char c;
    cin >> c;
    num[i/2] = num[i/2]*10+(c-'0');
    if (i%2){
      num[i/2] = (num[i/2]>0&&num[i/2]<=12)?1:0;
    }
  }
  cout << mes[num[0]+num[1]*2] << endl;
  return 0;
}
  
  
  

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int c[4][4];
int main(){
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			scanf("%d",&c[i][j]);
			int q,w,e;
			q=c[1][1]+c[2][2]+c[3][3];
			w=c[1][2]+c[2][3]+c[3][1];
			e=c[3][2]+c[2][1]+c[1][3];
	if(q==w&&e==w)
	printf("Yes");
	else printf("No");
}


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

string s,t;

bool isOK(int mid, int num, vector<int> &vec){
  if(vec[mid]>num) return true;
  else return false;
}

int nibutan(int &num, vector<int> &vec){
  int ng=-1, ok=vec.size();
  while(ok-ng>1){
    int mid=(ok+ng)/2;
    if(isOK(mid,num,vec)) ok=mid;
    else ng=mid;
  }
  int p=num;
  if(ok==vec.size()){
    num=vec[0];
    return s.size()-p+vec[0];
  }
  else{
    num=vec[ok];
    return vec[ok]-p;
  }
}

int main(){
  cin>>s>>t;
  vector<int> cn[26];
  rep(i,s.size()){
    cn[(int)(s[i]-'a')].push_back(i+1);
  }
  int tmp=0;
  ll ans=0;
  rep(i,t.size()){
    if(cn[(int)(t[i]-'a')].empty()){
      ans=-1; break;
    }
    ans+=nibutan(tmp,cn[(int)(t[i]-'a')]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigboi        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 


void solve(){
	int mat[3][3], mark[3][3];
	FOR(i, 0, 3){
		FOR(j, 0, 3){
			mark[i][i]=0;
		}
	}
	FOR(i, 0, 3){
		FOR(j, 0, 3){
			cin>>mat[i][j];
		}
	}
	int n;
	cin>>n;
	FOR(i, 0, n){
		int x;
		cin>>x;
		FOR(j, 0, 3){
			FOR(k, 0, 3){
				if(mat[j][k]==x) mark[j][k] = 1;
			}
		}
	}
	FOR(i, 0, 3){
		int temp=0;
		FOR(j, 0, 3){
			temp+=mark[i][j];
		}	
		if(temp==3){
			cout<<"Yes"<<endl;
			return;
		}
	}
	FOR(i, 0, 3){
		int temp=0;
		FOR(j, 0, 3){
			temp+=mark[j][i];
		}
		if(temp==3){
			cout<<"Yes"<<endl;
			return;
		}
	}
	int temp=0;
	temp+=mark[0][0], temp+=mark[1][1], temp+=mark[2][2];
	if(temp==3){
		cout<<"Yes"<<endl;
		return;
	}
	temp=0;
	temp+=mark[0][2], temp+=mark[1][1], temp+=mark[2][0];
	if(temp==3){
		cout<<"Yes"<<endl;
		return;
	}
	cout<<"No"<<endl;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
	//	cout<<"Case #"<<i<<":"<<endl;
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int N, M, K[20];
vector<int> s[20];
int p[20];

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> K[i];
        for(int j = 0; j < K[i]; j++){
            int S;
            cin >> S;
            s[i].push_back(S - 1);
        }
    }
    for(int i = 0; i < M; i++){
        cin >> p[i];
    }
    int ans = 0;
    for(int i = 0; i < (1 << N); i++){
        bool flag = true;

        for(int j = 0; j < M; j++){
            int cnt = 0;
            for(auto u : s[j]){
                if((i >> u) & 1) cnt++;
            }
            if(cnt % 2 != p[j]) flag = false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	long long min=0x3f3f3f3f;
	long long max=-10000000;
	scanf("%d",&n);
	int wz1=-1,wz2=-1;
	long long a[55];
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		if(a[i]>0&&a[i]>max)
		{
			max=a[i];
			wz1=i;
		}
		else
		{
			if(a[i]<0&&a[i]<min)
			{
				min=a[i];
				wz2=i;
			}
			
		}
	}
	int lose=1;
	for(int i=0;i<n;i++)
		if(a[i]>a[i+1])
		{
			lose=0;
			break;
		}
	
	if(lose)
	{
		printf("0\n");
	}
	else
	{
	
		printf("%d\n",2*n-2);
		int ww;

			if(wz1==-1)
				ww=2;
			else
			if(wz2==-1)
				ww=1;
			else
			if(a[wz1]>-a[wz2])
			ww=1;
			else
				ww=2;
		switch(ww)
		{
			case 1:for(int i=0;i<n;i++)
					{
					if(i!=wz1)
					{
						a[i]=a[i]+a[wz1];
						printf("%d %d\n",wz1+1,i+1);
					}
					
					}
					break;
			case 2:for(int i=0;i<n;i++)
					{
					if(i!=wz2)
					{
						a[i]=a[i]+a[wz2];
						printf("%d %d\n",wz2+1,i+1);
					}
					
					}
					break;
		}
		
	
		if(a[0]>=0)
		{
			for(int i=1;i<n;i++)
			{
				
				printf("%d %d\n",i-1+1,i+1);
				
			}
			
			
		}
		else
		{
			for(int i=n-1;i>=1;i--)
			{
				printf("%d %d\n",i+1,i-1+1);
			}
			
			
		}
		
		
		
		
		
		
		
	
	
	}

	
	
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define SC scanf
using namespace std;

int len[200001];

int main()
{
	long long n,l;
	SC("%lld %lld",&n,&l);
	for(long long i = 1; i <= n; i++)
	{
		SC("%d",&len[i]);
	}
	for(int i = 1; i < n; i++)
	{
		if(len[i] + len[i+1] >= l)
		{
			printf("Possible\n");
			for(int j = 1; j <= i-1; j++)
			{
				printf("%d\n",j);
			}
			for(int j = n-1; j >= i+1; j--)
			{
				printf("%d\n",j);
			}
			printf("%d",i);
			return 0;
		}
	}
	printf("Impossible");
	return 0;
}

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

void update(vector<int> &bit, int i, int x){
    int n=bit.size();
    while(i<n){
        bit[i]+=x;
        i+=i & -i;
    }
}

int sum(vector<int> &bit, int i){
    int res=0;
    while (i>0)
    {
        res+=bit[i];
        i-=i&-i;
    }
    return res;
}
int sum(vector<int> &bit, int i,int j){
    return sum(bit,j)-sum(bit,i-1);
}
int main() {
    int N,Q;
    cin>>N>>Q;
    vector<int> pos_col(N+1,0);//position of the rightmost color[i]
    vector<int> c(N+1);
    for (int i = 1; i <= N; i++){
        cin>>c[i];
    }
    vector<tuple<int,int,int>> queries(Q);
    for (int i = 0; i < Q; i++){
        int l,r;
        cin>>l>>r;
        get<0>(queries[i])=r;
        get<1>(queries[i])=l;
        get<2>(queries[i])=i;
    }
    sort(queries.begin(),queries.end());
    vector<int> bit(N+1,0);
    vector<int> res(Q,0);
    int cp=1;//current position
    for (int i = 0; i < Q; i++){
        while(cp<=get<0>(queries[i])){
            int cc=c[cp]; //current color
            if(pos_col[cc]!=0)update(bit,pos_col[cc],-1);
            update(bit,cp,1);
            pos_col[cc]=cp;
            cp++;
        }
        res[get<2>(queries[i])]=sum(bit,get<1>(queries[i]),get<0>(queries[i]));
    }
    for (int i = 0; i < Q; i++){
        cout<<res[i]<<endl;
    }
}

Measured memory_bytes: 17464
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k,q = list(map(int, input().split()))
a = [int(input()) for _ in range(q)]
vs = [k-q]*n
for i in range(q):
    vs[a[i]-1] += 1
for i in range(n):
    if vs[i]>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 77920
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    ll x;
    cin >> x;
    ll ans = floor(x / 11) * 2, a = x % 11;
    if (a > 6) {
        ans += 2;
    }
    else if (a > 0) {
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#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>;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<ll> factorList(ll x) {
    vector<ll> res;
    for (int p : primes) {
      while (x%p == 0) {
        res.push_back(p);
        x /= p;
      }
    }
    if (x != 1) res.push_back(x);
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<ll> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<pair<ll,int>> res(1, P(fl[0], 0));
    for (ll p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

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

  vector<pair<ll,int>> fs;
  for (ll i = 2; i*i <= n; ++i) {
    int x = 0;
    while (n%i == 0) {
      n /= i;
      ++x;
    }
    fs.emplace_back(i,x);
  }
  if (n != 1) fs.emplace_back(n,1);

  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19752
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main()
{
	int  n,hr,min,sec;
	cin>>n;
	hr=abs(n/3600);
	
	min= abs((n/60))-(hr *60);
	sec = n - (hr * 60*60);
	
	sec=sec%60;
	cout<<hr<<":"<<min<<":"<<sec<<endl;
	return 0;
	
	
}
	



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

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

    int ans = 2*min(count(s.begin(), s.end(), '0'), count(s.begin(), s.end(), '1'));

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


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<vi> g(n);
    vi tocnt(n,0);
    REP(i,m){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        g[x].emplace_back(y);
        tocnt[y]++;
    }

    int dp[100005]={};
    queue<int> que;
    int ans=0;

    REP(i,n){
        if (tocnt[i] == 0) que.push(i);
    }

    while(!que.empty()){
        auto v = que.front();
        que.pop();

        REP(i, g[v].size()){
            if(chmax(dp[g[v][i]], dp[v]+1)){
                chmax(ans, dp[g[v][i]]);
            }
            tocnt[g[v][i]]--;
            if(tocnt[g[v][i]]==0){
                que.push(g[v][i]);
            }
        }
    }

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

Measured memory_bytes: 6528
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>

int N;
unsigned long long K;

int main()
{
	scanf("%d %lld", &N, &K);
	int* A = (int*)malloc(sizeof(int) * N);
	int* visitedFlag = (int*)malloc(sizeof(int) * N);

	int i = 0;
	for (; i < N; i++)
	{
		scanf("%d", &A[i]);
		visitedFlag[i] = 0;
	}
	i = 0;
	while (!visitedFlag[i])
	{
		visitedFlag[i] = 1;
		i = A[i] - 1;
	}
	int circle = i;
	i = 0;
	int stepNums[2] = {0, 1};
	while (i != circle)
	{
		stepNums[0]++;
		i = A[i] - 1;
	}
	i = A[i] - 1;
	while (i != circle)
	{
		stepNums[1]++;
		i = A[i] - 1;
	}
	if (K > stepNums[0])
	{
		K = (K - stepNums[0]) % stepNums[1];
		i = circle;
		while (K != 0)
		{
			i = A[i] - 1;
			K--;
		}
	}
	else
	{
		i = 0;
		while (K != 0)
		{
			i = A[i] - 1;
			K--;
		}
	}
	printf("%d", i + 1);
	return 0;
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int N;
  cin>>N;
  if(N==1){
    cout<<"Hello World"<<endl;
  }else{
    int A,B;
    cin>>A>>B;
    cout<<A+B<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int W,H,x,y,r;

	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=W && 0<x && 0<y && x<W && y<H){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

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

using namespace std;

#define LL long long
#define N 600000

const LL mod1=998244353,mod2=353448299;
LL n,B1,iB1,B2,iB2,ans,pw1[N],ipw1[N],h1[N],pw2[N],ipw2[N],h2[N],p[N];
char s[N];
map<LL,map<LL,LL> > mp;

LL inv1(LL x){return x==1?1:(mod1-mod1/x)*inv1(mod1%x)%mod1;}

LL inv2(LL x){return x==1?1:(mod2-mod2/x)*inv2(mod2%x)%mod2;}

int main(){
	scanf("%lld%s",&n,s+1);
	pw1[0]=ipw1[0]=1; iB1=inv1(B1=233);
	pw2[0]=ipw2[0]=1; iB2=inv2(B2=377);
	for (LL i=1;i<=n*2;++i){
		pw1[i]=pw1[i-1]*B1%mod1;
		ipw1[i]=ipw1[i-1]*iB1%mod1;
		pw2[i]=pw2[i-1]*B2%mod2;
		ipw2[i]=ipw2[i-1]*iB2%mod2;
	}
	p[0]=n;
	for (LL i=1;i<=n;++i){
		if (s[i]=='+'){
			p[i]=p[i-1];
			h1[i]=(h1[i-1]+pw1[p[i]])%mod1;
			h2[i]=(h2[i-1]+pw2[p[i]])%mod2;
		}
		if (s[i]=='-'){
			p[i]=p[i-1];
			h1[i]=(h1[i-1]-pw1[p[i]]+mod1)%mod1;
			h2[i]=(h2[i-1]-pw2[p[i]]+mod2)%mod2;
		}
		if (s[i]=='>'){
			p[i]=p[i-1]+1;
			h1[i]=h1[i-1]; h2[i]=h2[i-1];
		}
		if (s[i]=='<'){
			p[i]=p[i-1]-1;
			h1[i]=h1[i-1]; h2[i]=h2[i-1];
		}
		++mp[h1[i]][h2[i]];
	}
	for (LL i=1;i<=n;++i){
 		LL d=p[i-1]-p[0],t1=h1[n],t2=h2[n];
		if (d>=0){t1=t1*pw1[d]%mod1; t2=t2*pw2[d]%mod2;}
		else{t1=t1*ipw1[-d]%mod1; t2=t2*ipw2[-d]%mod2;}
		t1=(t1+h1[i-1]+mod1)%mod1; t2=(t2+h2[i-1]+mod2)%mod2;
		ans+=mp[t1][t2];
		--mp[h1[i]][h2[i]];
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 110720
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1ll << 60;
int b=1,d=3,N,A;
int main(){
  cin >> N;
  vector<long long> sum(N + 1);
  sum[0] = 0;
  for(int i=1;i<=N;i++)
  {
	cin>>A;
    sum[i]=A; 
	sum[i]+=sum[i - 1];
  }
  long long diff=INF;
  for(int c=2;c<N-1;c++){
    while(b+1<c&&abs(sum[c]-2*sum[b])>abs(sum[c]-2*sum[b + 1]))		b++;
    while(d<=c) 	d++;
    while(d+1<N&&abs(sum[N]-2*sum[d]+sum[c])>abs(sum[N]-2*sum[d+1]+sum[c]))		d++;
    long long P = sum[b];long long Q = sum[c] - sum[b];
    long long R = sum[d] - sum[c];long long S = sum[N] - sum[d];
    diff = min(max(max(P, Q), max(R, S)) - min(min(P, Q), min(R, S)), diff);
  }
  cout << diff << endl;
  return 0;
}

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

int main(){
  int a, b;
  char c;
  
  cin >> a >>  c >> b;
  
  if(c == '+'){
    
    cout << a+b;
    return 0;
  }
  else{
      cout << a-b;
  }
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  vector<int>a(5);
  for(int i=0;i<5;i++){
    cin>>a[i];
  }
  int k;
  cin>>k;
  if(a[4]-a[0]>k)puts(":(");
  else puts("Yay!");
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)











int main(){
    ll n;
    while(cin >> n, n){
        ll ans = 0;
        for(ll i = 1; i < n; i++){
            ll sum = i;
            for(ll j = i + 1; j < n; j++){
                sum += j;
                if(sum > n) break;
                else if(sum == n){
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> P;
map <string,int> M;
vector <P> e[201];
int C[201],used[201];

bool check(int ima,int cost){
  if(used[ima])return (cost-C[ima])==0;
  used[ima]=1,C[ima]=cost;
  for(int i=0;i<e[ima].size();i++)
    if(!check(e[ima][i].f,cost+e[ima][i].s))return 0;
  return 1;
}

int main(){
  int n;
  while(cin>>n,n){;
    for(int i=0;i<2*n;i++)e[i].clear();
    M.clear();

    int N=0;
    for(int i=0;i<n;i++){
      string a,b,c,d,E;
      cin>>a>>b>>c>>d>>E;
      if(!M.count(b))M[b]=N++;
      if(!M.count(E))M[E]=N++;
      int num=0,j=3,flg=1;
      if(d[3]=='-')flg=-1,j=4;
      while(j<d.size())num=num*10+d[j++]-'0';
      e[M[b]].push_back(P(M[E],num*flg));
      e[M[E]].push_back(P(M[b],-num*flg));
    }

    int ans=1;
    for(int i=0;i<N;i++){
      memset(used,0,sizeof(used)),memset(C,0,sizeof(C));
      ans*=check(i,0);
    }
    cout <<(ans? "Yes":"No")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

int n, k;
int a, b;

int daypasta[110];
int dp[10][110][10];

int main(){
	cin >> n >> k;
	REP(i, k){
		cin >> a >> b;
		daypasta[a] = b;
	}
	if (daypasta[1] == 0){
		dp[1][1][1] = 1;
		dp[2][1][1] = 1;
		dp[3][1][1] = 1;
	}
	else{
		dp[daypasta[1]][1][1] = 1;
	}
	FOR(i, 1, n){
		if (daypasta[i + 1] == 0){
			dp[1][i + 1][1] = dp[2][i][1] + dp[2][i][2] + dp[3][i][1] + dp[3][i][2];
			dp[1][i + 1][2] = dp[1][i][1];

			dp[2][i + 1][1] = dp[1][i][1] + dp[1][i][2] + dp[3][i][1] + dp[3][i][2];
			dp[2][i + 1][2] = dp[2][i][1];

			dp[3][i + 1][1] = dp[1][i][1] + dp[1][i][2] + dp[2][i][1] + dp[2][i][2];
			dp[3][i + 1][2] = dp[3][i][1];
		}
		else{
			if (daypasta[i + 1] == 1){
				dp[1][i + 1][1]
					= dp[2][i][1] + dp[2][i][2] + dp[3][i][1] + dp[3][i][2];
			}
			else if (daypasta[i + 1] == 2){
				dp[2][i + 1][1]
					= dp[1][i][1] + dp[1][i][2] + dp[3][i][1] + dp[3][i][2];
			}
			else{
				dp[3][i + 1][1]
					= dp[1][i][1] + dp[1][i][2] + dp[2][i][1] + dp[2][i][2];
			}
			dp[daypasta[i + 1]][i + 1][2] = dp[daypasta[i + 1]][i][1];
		}
		FOR(j, 1, 4){
			FOR(k, 1, 3){
				dp[j][i + 1][k] %= 10000;
			}
		}
	}
	int ans = 0;
	FOR(j, 1, 4){
		FOR(k, 1, 3){
			ans += dp[j][n][k];
			ans %= 10000;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1184