akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;

int cnt[30];

int bin;
int bi[30];
int ans;

void dfs(int p){
	if(p == bin){
		int tmp = 99;
		for(int i=0; i<24; ++i){
			for(int j=i+1; j<24; ++j){
				if(cnt[i] && cnt[j]){
					tmp = min(tmp, min(abs(i-j), 24-abs(i-j)));
				}
			}
		}
		ans = max(ans, tmp);
		return;
	}
	++cnt[bi[p]]; dfs(p+1); --cnt[bi[p]];
	++cnt[24-bi[p]]; dfs(p+1); --cnt[24-bi[p]];
}

int main()
{
	read(n);
	vector<int>v;
	for(int i=1; i<=n; ++i){
		int x; read(x);
		if(x) v.pb(x);
		else {
			puts("0");
			return 0;
		}
	}
	cnt[0]=1;
	sort(all(v));
	n = v.size();
	for(int i=0; i<n;){
		int j=i;
		while(j<n && v[i] == v[j]) ++j;
		if(j-i > 2){
			puts("0");
			return 0;
		} else if(j-i == 2){
			if(v[i] == 12){
				puts("0");
				return 0;
			}
			cnt[v[i]]++;
			cnt[24-v[i]]++;
		} else {
			bi[bin++] = v[i];
		}
		i=j;
	}
	dfs(0);
	printf("%d\n", ans);
	return 0;
}


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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; cin >> N;
    vector<double> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }

    double tmp = 0;
    for(int i = 0; i < N; ++i){
        tmp += (1.0 / A[i]);
    }

    double ans = 1.0 / tmp;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

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

constexpr double EPS = 1e-7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
#define PI (acos(-1))

constexpr int MOD = 1e9 + 7;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}

	// union
	bool unionSet(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y) {
			if (data[y] < data[x]) {
				swap(x, y);
			}
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}

	// find
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}

	// root
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}

	// size
	int size(int x) {
		return -data[root(x)];
	}
};

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N, M;
	cin >> N >> M;

	vector<int> p(N);
	UnionFind d(N);
	map<int, int> m;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		p[i]--;
		m[p[i]] = i;
	}
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		d.unionSet(x - 1, y - 1);
	}

	int ret = 0;
	for (int i = 0; i < N; i++) {
		if (d.findSet(i, p[i])) {
			ret++;
		}
	}

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>
#include <map>
#include <string>

using namespace std;

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

    int a, p;
    cin >> a >> p;

    p = p + a * 3;

    cout << (p / 2) << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	vll b(n,0) ;
	ll cnt = 0 ;
	for(int i=n-1;i>=0;i--){
		ll sum = 0 ;
		ll pos = (i+1)*2 ;
		while(pos-1<n){
			sum += b.at(pos-1) ;
			pos += i+1 ;
		}
		b.at(i) = (a.at(i)!=sum%2) ;
		cnt += (a.at(i)!=sum%2) ;
	}
	cout << cnt << endl ;
	for(int i=0;i<n;i++){
		if(b.at(i)){
			cout << i+1 ;
			cnt-- ;
			cout << (cnt==0?'\n':' ') ;
		}
	}
}


Measured memory_bytes: 3968
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner in=new Scanner(System.in);
         String n=in.next();
         int sum=0;
         for(int i=0;i<n.length();i++){
            int x=Character.getNumericValue(n.charAt(i));
            sum=(sum+x)%9;
         }
         if(sum%9==0){
            System.out.println("Yes");
         }
         else
            System.out.println("No");
    }
}
class scan
{
    public static BufferedReader reader;
    public static StringTokenizer token;

    scan(InputStream str)
    {
        reader=new BufferedReader(new InputStreamReader(str));
        token=null;
    }

    static int nextInt()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return Integer.parseInt(token.nextToken());
    }

    static long nextLong()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return Long.parseLong(token.nextToken());
    }

    static String next()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return token.nextToken();
    }

}

Measured memory_bytes: 40448
N = int(input())
A =  [0] + list(map(int, input().split())) + [0]

a = []
for i in range(N+1):
    a.append(abs(A[i+1] - A[i]))
    
s = sum(a)

for i in range(1,N+1):
    ans = s - (a[i-1] + a[i]) + abs(A[i+1] - A[i-1])
    print(ans)

Measured memory_bytes: 13920
//解説あり
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int a[3005], b[3005], t, n;
int dp1[3005][3005], dp2[3005][3005];

int main(void) {
  cin >> n >> t;
  rep(i, 1, n+1) scanf("%d %d", &a[i], &b[i]);

  //両側DP

// 1〜iまでの料理を食べた時の最大値
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=t-1; j++) {
      if (j-a[i]<0) dp1[i][j] = dp1[i-1][j];
      else dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-a[i]]+b[i]);
    }
  }

  // i〜nまでの料理を食べた時の最大値
  for (int i=n; i>=1; i--) {
    for (int j=1; j<=t-1; j++) {
      if (j-a[i]<0) dp2[i][j] = dp2[i+1][j];
      else dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-a[i]]+b[i]);
    }
  }

  int ans = -1;
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=t-1; j++) {
      ans = max(ans, dp1[i-1][j] + b[i] + dp2[i+1][t-1-j]);
    }
  }
    

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 70784
// AtCoder Express 2 / 
// 所要時間 分
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n, m, Q;
    cin >> n >> m >> Q;
    vector<vector<int>> a(n+1, vector<int>(n+1));
    rep(i, m){
        int l, r;
        cin >> l >> r;
        a[l][r]++;
    }

    vector<vector<int>> cum(n+1, vector<int>(n+1));
    rep(i, n){
        rep(j, n){
            cum[i+1][j+1] = cum[i][j+1] + cum[i+1][j] - cum[i][j] + a[i+1][j+1];
        }
    }

    vector<int> ans(Q);
    rep(i, Q){
        int p, q;
        cin >> p >> q;
        --p;
        ans[i] = cum[q][q] - cum[p][q] - cum[q][p] + cum[p][p];
    }
    rep(i, Q){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3328
//ABC138 B - Resistors in Parallel
//20190902

using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.WriteLine("Hello World!");
            int N = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            
            string[] array = new string[N];
            array = input.Split(' ');

            int[] A = new int[N];

            for(int i=0;i<N;i++)
            {
                A[i] = int.Parse(array[i]);
            }

            double ANS = 0;

            for(int i=0;i<N;i++)
            {
                ANS += (1d/A[i]);
            }

            ANS = 1/ANS;

            Console.WriteLine(ANS);

        }
    }
}


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

int main(int argc, char const *argv[])
{
	int a,b;
	scanf("%d %d",&a,&b);
	int x=1,y=0;
	while(x<b)
	{
		x=x-1+a;
		y++;
	}
	printf("%d\n", y);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int h, w, K; cin >> h >> w >> K;
  vector<string> s(h); REP(i, h) cin >> s[i];
  int ue = 0;
  for (; ue < h; ++ue) {
    if (count(ALL(s[ue]), '#') > 0) break;
  }
  vector<vector<int> > ans(h, vector<int>(w, -1));
  for (int i = h - 1; i >= 0;) {
    int j = i;
    while (j >= 0 && count(ALL(s[j]), '#') == 0) --j;
    int hid = 0;
    for (; hid < w; ++hid) {
      if (s[j][hid] == '#') break;
    }
    int jjj = j;
    if (j == ue) jjj = 0;
    for (int k = w - 1; k >= 0;) {
      int l = k;
      while (l >= 0 && s[j][l] == '.') --l;
      if (l == hid) l = 0;
      FOR(y, jjj, i + 1) FOR(x, l, k + 1) ans[y][x] = K;
      --K;
      k = l - 1;
    }
    i = jjj - 1;
  }
  REP(i, h) {
    REP(j, w) cout << ans[i][j] << (j + 1 == w ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;

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

int main() {
    int N, K;
    cin >> N>>K;
    int L[100];
    rep(i, N)cin >> L[i];
    sort(L, L + N,greater<int>());
    cout << accumulate(L, L + K, 0) << endl;
}

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

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

using namespace std;
typedef long long ll;

ll n, k;

ll SumVector(vector<ll>& rsl){
    ll ans = 1;
    rep(i, k) ans *= rsl[i];
    return ans;
}

int main(){
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> rsl(k);
    int cnt = 0;
    ll tmp;
    int i;
    for(i = 0; i < n; ++i){
        cin >> tmp;
        rsl[cnt++] = tmp;
        if(cnt == k){
            a[i] = SumVector(rsl);
            ++i;
            break;
        }
    }
    for(i; i < n; ++i){
        cin >> tmp;
        if(tmp > rsl[0]) a[i] = 1;
        else a[i] = 0;
        rsl.erase(rsl.begin());
        rsl.push_back(tmp);
    }

    for(int j = k; j < n; ++j){
        if(a[j] == 1) cout << "Yes" << endl;
        else          cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 6372
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    ll cntA = 0;
    for (int i = 1; i < n; i++) {
        if (s[i-1] == 'B' && s[i] == 'C') {
            ans += cntA;
            i++;
        } else if (s[i-1] == 'A') {
            cntA++;
        } else {
            cntA = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  
  int num;
  
  if(b==100){
  num=a*1000+b;
  }
  
  else if(b<100&&b>=10){
    num=a*100+b;
  }
  else if(b<10){
    num=a*10+b;
  }
  
  for(int i=0;i<num;i++){
    if(i*i==num){
      cout<<"Yes"<<endl;
    break;
    }
    if(i==num-1){
      cout<<"No"<<endl;
    }
  }
}

    


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int unsigned long long
//----------------------------------------------------
int n;
int a[100];
int b[100];
bool c[100];
//使えるものはどれか
bool d[100];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	int ans = 0;
	for (int i = 1; i <= 50; i++) c[i] = 1;
	for (int i = 50; i >= 1; i--) {
		c[i] = 0;
		for (int j = 0; j < n; j++) {
			for (int z = 0; z <= 50; z++) {
				d[z] = 0;
			}
			d[a[j]] = 1;
			for (int z = 50; z > 0; z--) {
				for (int r = 1; r <= 50; r++) {
					if (c[r]) {
						d[z%r] |= d[z];
					}
				}
			}
			if (!d[b[j]]) {
				if (i == 50) {
					cout << -1 << endl;
					return 0;
				}
				c[i] = 1;
				ans += 1ll << i;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k;
  string s;
  cin >> k >> s;
  int lens = s.size();
  if( lens <= k ) {
    cout << s << endl;
  }
  else {
    s = s.substr(0,k);
    s += "...";
    cout << s << endl;
  }
  return 0;
}



Measured memory_bytes: 3132
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
#define INF 1000000007
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int n,m,xa,ya,xb,yb,dist[1010][1010];
char c[1010][1010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	cin>>xa>>ya>>xb>>yb;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c[i][j];
			dist[i][j]=INF;
		}
	}
	dist[xa][ya]=0;
	deque<pair<int,int> > q;
	q.push_front(make_pair(xa,ya));
	while(!q.empty()){
		pair<int,int> t=q.front();q.pop_front();
		for(int dir=0;dir<4;dir++){
			int nx=t.first+dx[dir],ny=t.second+dy[dir];
			if(nx<1||ny<1||nx>n||ny>m) continue;
			if(c[nx][ny]=='#') continue;
			if(dist[nx][ny]>dist[t.first][t.second]){
				dist[nx][ny]=dist[t.first][t.second];
				q.push_front(make_pair(nx,ny));
			}
		}
		for(int dir1=-2;dir1<=2;dir1++){
			for(int dir2=-2;dir2<=2;dir2++){
				int nx=t.first+dir1,ny=t.second+dir2;
				if(nx<1||ny<1||nx>n||ny>m) continue;
				if(c[nx][ny]=='#') continue;
				if(dist[nx][ny]>dist[t.first][t.second]+1){
					dist[nx][ny]=dist[t.first][t.second]+1;
					q.push_back(make_pair(nx,ny)); 
				}
			} 
		}
	}
	if(dist[xb][yb]==INF) cout<<-1<<endl;
	else cout<<dist[xb][yb]<<endl;
	return 0;
}

Measured memory_bytes: 8664
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 2000009
#define mx 10000000000008
#define mod 1000000007
ll n,m,i,j,k,l,t,arr[sz],brr[sz],crr[sz];
vector<ll>v,v1[sz];
int main()
{
     t=1;
  //  scanf("%lld",&t);
    while(t--)
    {
    for(i=3;i*i<=sz-100;i+=2)
    {
        if(crr[i])
            continue;
        for(j=i*i;j<=sz-100;j+=2*i)
            crr[j]=1;
    }
    v.push_back(2);
    for(i=3;i<=1000000;i+=2)
    {
        if(crr[i]==0)
            v.push_back(i);
    }
    for(i=0;i<v.size();i++)
    {
        for(j=v[i];j<=1000000;j+=v[i])
            v1[j].push_back(v[i]);
    }
    j=0;
    k=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&arr[i]);
        j=__gcd(j,arr[i]);
        for(l=0;l<v1[arr[i]].size();l++)
        {
            m=v1[arr[i]][l];
            if(brr[m])
                k++;
            brr[m]++;
        }
    }
    if(k==0)
    {
        printf("pairwise coprime\n");
    }
    else if(j==1)
    {
        printf("setwise coprime\n");
    }
    else
    {
        printf("not coprime\n");
    }
    }
    return 0;
}


Measured memory_bytes: 128584
#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 n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
    if (A.size() == n+1) {
        int now = 0;
        rep(i,q) {
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
      cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[200];
    if(n == 1){
        printf("0");
        return 0;
    }
    int maxx = -99999999;
    int minn = 99999999;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        maxx = max(maxx, a[i]);
        minn = min(minn, a[i]);
    }
    int ans = 999999999;
    for(int i = minn; i <= maxx; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum+=(a[j]-i)*(a[j]-i);
        }
        ans = min(ans, sum);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
A = gets.split(' ').map(&:to_i)

prev = nil
cnt = 1
chanks = []
(A + [nil]).each do |n|
  if n == prev
    cnt += 1
  else
    if cnt != 1
      chanks << cnt
      cnt = 1
    end
  end

  prev = n
end

cnt = 0
chanks.each do |c|
  cnt += c / 2
end
puts cnt


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

const int N = 100005;
int n, a[N], deg[N], pre[N], nxt[N];
bool del[N];
vector<int> p;

void dfs(int u) {
	if (p.size() == n) {
		for (int x : p) printf("%d ", x);
		puts("");
		exit(0);
	}
	if (!del[a[u]] && deg[a[u]] == n - p.size()) return;
	for (int x = nxt[0]; x <= n; x = nxt[x]) {
		if (x == a[u]) continue;
		--deg[a[u]];
		nxt[pre[x]] = nxt[x];
		pre[nxt[x]] = pre[x];
		p.push_back(x);
		del[x] = true;
		dfs(x);
		del[x] = false;
		nxt[pre[x]] = pre[nxt[x]] = x;
		p.pop_back();
		++deg[a[u]];
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i), ++deg[a[i]];
	for (int i = 1; i <= n; ++i) pre[i] = i - 1, nxt[i] = i + 1;
	for (int i = 1; i <= n; ++i) {
		del[i] = true, nxt[i - 1] = i + 1, pre[i + 1] = i - 1;
		p.push_back(i), dfs(i), p.pop_back();
		del[i] = false, nxt[i - 1] = pre[i + 1] = i;
	}
	puts("-1");
}


Measured memory_bytes: 7672
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <iomanip>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

double dp[3000][3000] = {};

int main(){

  int n;
  cin >> n;

  vector<double> p(n);
  REP(i,n){
    cin >> p[i];
  }


  dp[0][0] = 1.0;

  REP(i,n){
    REP(j,i+1){
      dp[i+1][j+1] += dp[i][j] * p[i];
      dp[i+1][j] += dp[i][j] * (1.0 - p[i]);

    }
  }
  double ans = 0;
  FOR(i,(n+1)/2,n+1){
    ans += dp[n][i];
  }

  cout << setprecision(10) << ans << endl;

  return 0;
}



Measured memory_bytes: 68992
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define umapi unordered_map<ll, ll>
#define umapc unordered_map<char, int>
#define endl "\n"
#define pui pair<int, pair<int,int> >
using namespace std;
 
 
void solve(){
    
    int a , b;
    cin >>a>>b;

    cout<<a*b;


   
}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(10);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}



Measured memory_bytes: 3624
#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 = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){ 
    string S, T;
    int N;

    cin >> S >> T;

    N = S.size();

    bool flag = true;

    rep(i,N) {
        if (!(S.at(i) == T.at(i))) flag = false;
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
  int n; cin >> n;
  vector<string> blue(n);
  for(int i = 0; i < n; ++i) cin >> blue[i];
  int m; cin >> m;
  vector<string> red(m);
  for(int i = 0; i < m; ++i) cin >> red[i];

  int ans = 0;
  auto calc = [&](string s){
    int buf = 0;
    for(string t: blue){
      if(t == s)buf++;
    }
    for(string t: red){
      if(t == s) buf--;
    }
    return buf;
  };

  for(string t: blue){
    ans = max(ans, calc(t));
  }

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


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

int main() {

    int x, a, b;
    cin >> x >> a >> b;

    if (a >= b) cout << "delicious" << endl;
    else {
        if (b-a <= x) cout << "safe" << endl;
        else cout << "dangerous" << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
char a[5];
int main()
{
    cin >> a;
    for(int i = 0; i < 3; i++){
        if(a[i] == '1'){
            a[i] = '9';
        }else if(a[i] == '9'){
            a[i] = '1';
        }
    }
    cout << a;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		TreeSet<Long> ts = new TreeSet<Long>();

		while (n-- > 0) {

			long tmp = sc.nextLong();
			if (ts.remove(tmp)) {
				continue;
			} else {
				ts.add(tmp);
			}

		}

		System.out.println(ts.size());

	}
}

Measured memory_bytes: 63392
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll max = 0;
    cin >> N;
    int H[N];
    for(int i = 0; i < N;i++){
        cin >> H[i];
    }
    int count = 0;
    for(int i = 0; i < N;i++){
        if(max <= H[i]){
            count++;
            max = H[i];
        }
    }
    cout << count << endl;


    


    return 0;
}

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

int main(){
	long long K;
	cin >> K;

	set<long long> done;
	long long mod = 7;
	long long idx = 0;
	while(true) {
		if(mod%K == 0) {
			cout << idx + 1<< endl;
			return 0;
		}
		if(done.count(mod) > 0) {
			cout << -1  << endl;
			return 0;
		}
		done.insert(mod);
		mod *= 10;
		mod += 7;
		mod %= K;
		idx++;
	}

}

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

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int x, n;
	cin >> x >> n;
	if (n == 0) {
		cout << x;
		return 0;
	}

	unordered_set<int> s;
	int temp;

	for (int i = 0; i < n; i++) {
		cin >> temp;
		s.insert(temp);
	}

	int i = 0, ans = 0;
	while (i < 150) {
		if (s.find(x - i) == s.end()) {
			ans = x - i;
			break;
		}
		if (s.find(x + i) == s.end()) {
			ans = x + i;
			break;
		}
		i++;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

class CardSet{
    public:
        bool isempty();
        char pop();
        void init();
    private:
        char S[110];
        int cur = 0;
};

void CardSet::init(){
    cin >> S;
}

char CardSet::pop(){
    return S[cur++];
}

bool CardSet::isempty(){
    return cur > strlen(S)-1;
}

int main()
{
    CardSet A[3];
    REP(i, 0, 3) A[i].init();
    int now = 0;
    while(!A[now].isempty()) {
        char c = A[now].pop();
        //cout << c << " ->";
        if     (c == 'a')   now = 0;
        else if(c == 'b')   now = 1;
        else                now = 2;
    }
    //cout << endl;
    cout << (char)(now + 'A') << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a[4]={0};
	int n,m;
	cin>>n>>m;
	int vis[4]={0};
	for(int i=1;i<=m;++i)
	{
		int l,r;
		cin>>l>>r;
		if(vis[l]&&a[l]!=r){cout<<-1;return 0;}
		else {a[l]=r;vis[l]=1;}
	}
	if(n>1&&vis[1]&&a[1]==0){cout<<-1;return 0;}
	if(n==1&&a[1]==0){cout<<0;return 0;}
	if(n>1&&a[1]==0)a[1]=1;
	for(int i=1;i<=n;++i)cout<<a[i];
}

Measured memory_bytes: 256
import math

def prime(a):
    for i in range(2, int(math.sqrt(a))+1):
        if a%i==0:
            return False
    else:
        return True

m = 5555
xs = []
for i in range(1, m):
    if prime(i*10 + 1):
        xs.append(i*10+1)
        if len(xs) > 55:
            break

n = int(input())
print(*xs[:n])

Measured memory_bytes: 3064
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
    return a * b // gcd(a, b)

def akarabmadecde(a: int, b: int, c: int):
    if a % c == 0:
        return (b // c) - (a // c) + 1
    else:
        return (b // c) - (a // c + 1) + 1

def main():
    input_str = input()

    a, b, c, d = input_str.split()

    a = int(a)
    b = int(b)
    c = int(c)
    d = int(d)

    x = akarabmadecde(a, b, c)
    y = akarabmadecde(a, b, d)
    z = akarabmadecde(a, b, lcm(c, d))

    print((b - a + 1) - (x + y - z))

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}
 
 
signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n;
    cin>>n;
    int ind=0;
    for(int i=1;i<=5*n;i++)
    {
        if((i-1)*i==2*n)
        {
            ind=i;
            break;
        }
    }

    if(ind==0)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes\n";
        vector<int>v[ind];
        int x=ind-1;
        int cnt=0;
        for(int j=0;j<ind;j++,x--)
        {
            vector<int>temp;
            for(int i=1;i<=x;i++)
            {
                v[j].push_back(++cnt);
                temp.push_back(cnt);
            }
            for(int k=ind-1;k>=j+1;k--)
            {
                v[k].push_back(temp.back());
                temp.pop_back();
            }
        }
        cout<<ind<<endl;
        for(int i=0;i<ind;i++)
        {
            cout<<ind-1<<" " ;
            for(auto j:v[i])
                cout<<j<<" ";
            cout<<'\n';
        }
    }
    

} 

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

const int LIM = 100000;
int n, a[LIM], b[LIM], deff[LIM], ans, num, l, r;

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) deff[i] = a[i] - b[i];
    sort(deff, deff + n);
    r = n - 1;

    while (l <= r) {
        if (deff[l] >= 0) break;
        if (-deff[l] > num) {
            if (l >= r || deff[r] <= 0) {
                cout << -1 << endl;
                return 0;
            } else {
                num += deff[r--];
                ans++;
            }
        } else {
            num += deff[l++];
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define outl2(x,y) cout<< (x) << ' ' << (y) << '\n'
using pii = pair<int,int>;
using ll = long long;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
static constexpr int INF = 0x3f3f3f3f;


int main()
{
    cin.tie(0), ios::sync_with_stdio(false);
    int a, b;
    cin >>a >> b;
    bool f = false;
    for (int i=1; i <= 3; ++i) {
        if (a * b * i % 2 == 1) f = true;
    }

    outl(f ? "Yes" : "No");

    return 0;
}



Measured memory_bytes: 256
from collections import deque

s = input()
q = deque()

for si in s:
    if si == "S":
        q.append(si)
    elif si == "T" and len(q) == 0:
        q.append(si)
    elif q[-1] == "T":
        q.append(si)
    elif q[-1] == "S":
        q.pop()
print(len(q))

Measured memory_bytes: 10676
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int B[n+2];
    B[0] = INF;
    B[n] = INF;
    FOR(i,1,n) cin >> B[i];
    int ans = 0;
    REP(i,n){
        ans += min(B[i],B[i+1]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = float("inf")
    
    if N == 2:
        print(abs(A[0] - A[1]))
        sys.exit()
    
    a_sp = []
    for i, val in enumerate(A):
        if i == 0:
            a_sp.append(val)
            continue
        tmp = val + a_sp[i-1]
        a_sp.append(tmp)
        
    for i, val in enumerate(a_sp):
        if i == (len(a_sp)-1):
            break
            
        tmp = abs(val - ((a_sp[-1])-val))
        
        if tmp < ans:
            ans = tmp
            
    print(ans)
        
if __name__ == "__main__":
	main()


Measured memory_bytes: 85708
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = int((f-g)%mod)
k = int(k%mod)

#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
#print(int(( (k%mod*g%mod)%mod + (t*(0.5*((k-1)%mod*k%mod)) ) %mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
ans1 = int((k*g%mod)%mod)
#ans2 = t*(0.5* (k-1)%mod * k%mod ) %mod
#ans2 = t*(0.5*((k-1)%mod*k%mod))%mod
ans2 = int(t*(((k-1)%mod*k%mod)%mod)//2%mod)
ans = g*k + t*k*(k-1)//2
print( ans%mod)
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()



Measured memory_bytes: 42460
#include<bits/stdc++.h>
#define ll   long long int  
#define pb push_back
const int M=1e9 + 7;
using namespace std;
int N=1000000+1;
void dfs(vector<int>* g,int st,bool* visited,int* dp)
{
	visited[st]=true;
	for(int i=0;i<g[st].size();i++)
	{
		if(visited[g[st][i]]==false)
		{
			dfs(g,g[st][i],visited,dp);
		}
		dp[st]=max(dp[st],1+dp[g[st][i]]);
	}
}
int main() {
   
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m;cin>>n>>m;
    vector<int>* g=new vector<int>[n+1];
    for(int i=1;i<=m;i++)
    {
    	int u,v;cin>>u>>v;
    	g[u].pb(v);
	}
	bool* visited=new bool[n+1]();
	int* dp=new int[n+1];
	for(int i=0;i<=n;i++)
	{
		dp[i]=0;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(visited[i]==false){
			dfs(g,i,visited,dp);
			
		}
	}
	for(int i=0;i<=n;i++)
	{
		ans=max(ans,dp[i]);
	}
	
	cout<<ans<<endl;
	return 0;
}










Measured memory_bytes: 9600
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) // <a> must be sorted in advance

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}


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

    int N, K;
    cin >> N >> K;

    int ans = 1;
    REP(i, N) {
        if(ans*2 < ans+K) ans *= 2;
        else ans += K;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
int T,N,M,C,mi=1,fi=0;
int a[20][20];
int b[20],c[20];
//int retu(int i){

//}
int main(){
	cin>>T>>N>>M;
	for(int i=0;i<T;i++){
		cin>>b[i];mi+=b[i];
		for(int j=0;j<N;j++){
			cin>>a[i][j];
		}
	}
	fi=mi;
	int l=pow(2,double(T));
	for(int k=0;k<(1<<T);k++){
		int sum=0;
		for(int i=0;i<20;i++)c[i]=0;
		for(int j=0;j<T;j++){
			if((k>>j)&1){
				sum+=b[j];
				for(int i=0;i<N;i++){
					//cout<<a[j][i]<<" ";
					c[i]+=a[j][i];
				}
				//cout<<endl;
			}
		}
		int f=1;
		for(int i=0;i<N;i++){
			if(c[i]<M){f=0;break;f=0;}
			//cout<<c[i]<<" ";
		}
		//cout<<endl;continue;
		if(f)mi=min(mi,sum);
	}
	if(mi==fi)cout<<"-1\n";
	else cout<<mi<<endl;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
   string R,G;cin>>R>>G;
   cout<<((R[0]==G[2] && R[1]==G[1] && R[2]==G[0])?"YES":"NO")<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map> 
using namespace std;
typedef long long ll;
const int N = 800005;
struct data{ll x,h;}dt[N],t[N];
int n,pre,l,r;
ll d,ans,times,a,s[N];
bool cmp(data p,data q){return p.x < q.x;}

int main(){
	scanf("%d%lld%lld",&n,&d,&a);
	for(int i=1;i<=n;++i){
		scanf("%lld%lld",&dt[i].x,&dt[i].h);
	}
	sort(dt+1,dt+n+1,cmp);

	l=1;r=0;
	for(int i=1;i<=n;++i){
		while(l<=r&&dt[i].x-t[l].x>2*d) ++l;
		dt[i].h -= (s[r]-s[l-1]);
		/*
		for(int j=l;j<=r;++j)
			dt[i].h -= t[j].h;*/
		if(dt[i].h <= 0) continue;

		times = 0;
		if(dt[i].h%a==0) times = dt[i].h/a;
		 else times = (dt[i].h/a)+1;
		
		t[++r] = (data){dt[i].x,(ll)times*a};
		s[r] = s[r-1] + t[r].h;
		
		ans += times;
	} 
	printf("%lld\n",ans);
}

Measured memory_bytes: 9984
import itertools


def main():
    N, Q = list(map(int, input().split(' ')))
    S = input()
    ac_flag = [0 for _ in range(N + 1)]
    before_c = None
    for i, c in enumerate(S):
        if (before_c, c) == ('A', 'C'):
            ac_flag[i + 1] = 1
        before_c = c
    ac_count = list(itertools.accumulate(ac_flag))
    answer = list()
    for _ in range(Q):
        L, R = list(map(int, input().split(' ')))
        answer.append(ac_count[R] - ac_count[L])
    for a in answer:
        print(a)


if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> done(n, 0);
  for (int i=0; i<n; i++) {
    cin >> a[i];
  }
  int acount = 0;
  int now = 1;
  while(true) {
    if (done[now-1] == 1) {
      cout << -1 << endl;
      return 0;
    }
    done[now-1] = 1;
    now = a[now-1];
    acount++;
    if (now == 2) {
      cout << acount << endl;
      return 0;
    }
  }
}
  


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n, k; cin >> n >> k;

    vector<ll> cnt(k, 0);
    for (ll i = 1; i <= n; ++i) {
        cnt[i % k]++;
    }

    ll ans = 0;
    // a % k で全探索
    for (ll a = 0; a < k; ++a) {
        ll b = (k - a) % k;
        ll c = (k - a) % k;

        if ((b + c) % k != 0) {
            continue;
        }

        ans += cnt[a] * cnt[b] * cnt[c];
    }

    cout << ans << endl;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
long long x,k,d;
int main(){
	cin>>x>>k>>d;
	if(k==0){
		cout<<abs(x);
		return 0;
	}
	else{
		long long t=abs(x/d);
		if(t>k){
			if(x>=0)
			{
				cout<<x-k*d;
				return 0;
			}
			else{
				cout<<abs(x+k*d);
				return 0;
			}
		}
		if(x>=0){
			cout<<abs(x-t*d-(k-t)%2*d);
			return 0;
		}
		else{
			cout<<abs(x+t*d+(k-t)%2*d);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  int x,t,ans=0;
  cin>>t;
  for(int i=1;i<n;i++){
    cin>>x;
    ans+=min((x-t)*a,b);
    t=x;
  }
  cout<<ans<<endl;
  return 0;
}


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

double n;
//int a[512];
double p[905][605][305];
int cnt[4];

double gao(int a,int b,int c){
	if(p[a][b][c]!=-1) return p[a][b][c];
	p[a][b][c]=0;
	double m=a+b+c;
	if(b>0) p[a][b][c]+=gao(a,b-1,c+1)*(c+1)/m;
	if(a>0) p[a][b][c]+=gao(a-1,b+1,c)*(b+1)/m;
	if(a+b+c<n)p[a][b][c]+=gao(a+1,b,c)*(a+1)/(m+1);
	return p[a][b][c];
}

int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		int a;cin>>a;
		cnt[a]++;
	}
	
	for(int i=0;i<=cnt[1]+cnt[2]+cnt[3]+1;++i){
		for(int j=0;j<=cnt[2]+cnt[3]+1;++j){
			for(int k=0;k<=cnt[3]+1;++k){
				if(i>cnt[1]+cnt[2]+cnt[3]||j>cnt[3]+cnt[2]||k>cnt[3]) p[i][j][k]=0;
				else p[i][j][k]=-1;
			}
		}
	}
	p[cnt[1]][cnt[2]][cnt[3]]=1;
	
	double ans=0;
	for(int i=0;i<=cnt[1]+cnt[2]+cnt[3];++i){
		for(int j=0;j<=cnt[2]+cnt[3];++j){
			for(int k=0;k<=cnt[3];++k){
				if(i==0&&j==0&&k==0) continue;
				ans+=gao(i,j,k)*n/(double)(i+j+k);
			}
		}
	}
	cout<<fixed<<setprecision(14)<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 435840
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 205
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
db d,x;
void Solve() {
    read(N);
    scanf("%lf%lf",&d,&x);
    db ans = 0;
    while(N) {
	ans += d + (2 * N - 1) / 2.00 * x;
	d = 1.0 * (N + 1) / N * d + 5 * x / (2 * N);
	x = 1.0 * (N + 2) / N * x;
	--N;
    }
    printf("%.10lf\n",ans);
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256