akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	int ans = 0;
	FOR(k, 1, 11) {
		ll p3 = 1;
		REP(j, k) p3 *= 3;
		constexpr int num[3] = {7, 5, 3};
		
		REP(s, p3) {
			int cur = s;
			string str;
			int done[3] {};
			REP(j, k) {
				str += num[cur % 3] + '0';
				done[cur % 3] = true;
				cur /= 3;
			}
			
			ll n = stoll(str);
			bool ok = n <= N;
			REP(j, 3) ok &= done[j];
			if (ok) ++ans;
		}

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


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

int main(){
  int K, X; cin >>K >>X;
  int start, end;
  start = X-K+1;
  end = X+K-1;
  for(int i = start; i <= end; i++) cout << i << " ";
  cout << endl; 
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        for (int i = 0; i < arr.Length; i++)
        {
            if(arr[i] == 0)
            {
                Console.WriteLine(i+1);
                return;
            }
        }

    }



}




Measured memory_bytes: 18940
list_way = []
ls = []
while True:
    n, x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break
    list_way.append([n, x])
for count in range(len(list_way)):
    r = 0
    list_n = [i + 1 for i in range(list_way[count][0])]
    for count0 in range(len(list_n)):
        num = list_n[0]
        list_n.remove(num)
        # print(list_n)
        for count1 in range(len(list_n)):
            for count2 in range(len(list_n) - count1 - 1):
                if list_n[count1] + list_n[count1 + count2 + 1] == list_way[count][1] - num:
                    r = r + 1
                    # print(r)
    ls.append(r)
for count in range(len(ls)):
    print(ls[count])


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int A,B,C;
	cin>>A>>B>>C;
	
	bool f = false;
	
	if(A==B&&B!=C){
		f=true;
	}
	if(B==C&&C!=A)f=true;
	
	if(C==A&&A!=B)f=true;
	
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
    return 0;
}



Measured memory_bytes: 256
import sys
import math
a,b= map(int,input().split())
#=int(input())
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]

for i in range(1,a*2):
  print((b+i-a),end=" ")

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

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

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

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

int len=0;
set<int> st;

void rec(string s) {
	bool th =false,fi=false,se= false;
	rep(i, s.size()) {
		if (s[i] == '3')th = true;
		if (s[i] == '5')fi = true;
		if (s[i] == '7')se = true;
	}
	if (th&&fi&&se) {
		st.insert(stoi(s));
	}
	if ((double)s.size() < len) {
		rec(s + "3");
		rec(s + "5");
		rec(s + "7");
	}

}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<int, int> mp;
	rep(i, n) {
		int t = i + 1;
		range(j, 2, 101) {
			while (t%j == 0) {
				t /= j;
				mp[j]++;
			}
		}
	}
	int tw=0, fo=0, ft=0,tf=0,sf=0;
	for(pii p : mp) {
		if (2 <= p.sc)tw++;
		if (4 <= p.sc)fo++;
		if (14 <= p.sc)ft++;
		if (24 <= p.sc)tf++;
		if (74 <= p.sc)sf++;
	}
	for (pii p : mp) {
		//cout << p.fs << " " << p.sc << endl;
	}
	ll ans = 0;
	ans += (max(0, fo)*max(0, fo - 1)) / 2 * max(0, tw - 2);
	ans += tf*max(0, tw - 1);
	ans += ft*max(0, fo - 1);
	ans += sf;
	//cout << tw << " " << fo << " "<<ft<<" "<<tf<<" "<<endl;
	cout << ans << endl;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    int H, W,K;
    cin >> H >> W >> K;
    int ans = 0;
    vector<vector<char>> G(H, vector<char>(W));
    rep(i,H)rep(j,W) cin >> G[i][j];
    for (int bith = 0; bith < (1 << H); bith++)
    {
        set<int> SH;
        rep(i, H)
        {
            if (bith & (1 << i))
            {
                SH.insert(i);
            }
        }
        for (int bitw = 0; bitw < (1 << W); bitw++)
        {
            set<int> SW;
            rep(j, W)
            {
                if (bitw & (1 << j))
                {
                    SW.insert(j);
                }
            }
            int cnt = 0;
            rep(i, H) rep(j, W)
            {
                if (SH.count(i))
                    continue;
                if (SW.count(j))
                    if (G[i][j] == '#')
                        cnt++;
            }
            if(cnt == K) ans++;
        }

        
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
from bisect import bisect_left
from itertools import accumulate
N,M,*A = map(int, open(0).read().split())
A.sort()
B = list(accumulate(A[::-1]))
l = -1
r = 10**6
while l+1<r:
  s = (l+r)//2
  cnt = 0
  for c in A:
    i = bisect_left(A,s-c)
    cnt += N-i
  if cnt>=M:
    l = s
  else:
    r = s
ans = 0
for c in A:
  i = bisect_left(A,r-c)
  M -= N-i
  if i<N:
    ans += B[N-1-i]+c*(N-i)
ans += M*l
print(ans)


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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s;
	cin>>s;
	for(char c: s) {
		if(c=='7') {
			cout<<"Yes";
			return 0;
		}
	}	
	cout<<"No";

	return 0;
}

Measured memory_bytes: 3652
A,B,C = map(int,input().split(" "))
D = 0

if (A+B) >= C:
    D += B + C
elif C >= B:
    D += B * 2
    C -= B
    if C >= A:
        D += A
        C -= A
        if C >= 1:
            D += 1
print(D)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef tuple<int, int, int> state; // length, yes:0 no:1, index

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vi len(n), del(n);
	priority_queue<pii> que;
	REP(i, n)
	{
		char c; int a; cin >> c >> a;
		len[i] = a;
		del[i] = c == 'y';
		if (del[i]) que.emplace(-a, i);
	}
	vi ub(n, 1111), lb(n, -1);
	REP(i, n)
	{
		if (!del[i]) continue;
		FOR(j, i + 1, n)
		{
			if (!del[j] && len[j] >= len[i])
			{
				ub[i] = j;
				break;
			}
		}
	}
	REP(i, n)
	{
		if (!del[i]) continue;
		for(int j = i - 1; j >= 0; j--)
		{
			if (!del[j] && len[j] >= len[i])
			{
				lb[i] = j;
				break;
			}
		}
	}
	vector<bool> vis(n);
	int ans = 0;
	while (!que.empty())
	{
		int t = que.top().second;
		que.pop();
		if (vis[t]) continue;
		ans++;
		FOR(i, max(0, lb[t]), min(n, ub[t])) vis[i] = true;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int arr[n][3];
    for(int i=0; i<n; i++)
        for(int j=0; j<3; j++)
            cin >> arr[i][j];

    int dp[n][3];
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];

    for(int i=1; i<n; i++){
        for(int j=0; j<3; j++){
            int option=INT_MIN;
            for(int k=0; k<3; k++){
                if(j == k)
                    continue;
                option = max(option, dp[i-1][k] + arr[i][j]);
            }
            dp[i][j] = option;
        }
    }

    int ans=INT_MIN;
    for(int j=0; j<3; j++)
        ans = max(ans, dp[n-1][j]);

    cout << ans << endl;
}


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


struct Node {
    int idx;
    Node* child = nullptr;
    bool is_passed = false;
    int loop_idx;
};

int main() {
    int N;
    long long int K;
    std::cin >> N >> K;

    std::vector<Node> A(N);

    for (int i = 0; i < N; i++) {
        int next;
        std::cin >> next;
        A[i].idx = i;
        A[i].child = &A[next - 1];
    }

    int idx = 0, count = 0;
    while (true) {
        if (A[idx].is_passed) {
            break;
        }
        A[idx].is_passed = true;
        A[idx].loop_idx = count;
        idx = A[idx].child->idx;
        count++;
    }
    int n_head = A[idx].loop_idx;
    int n_loop = count - A[idx].loop_idx;

    if (K < n_head) {
        auto node = &A[0];
        for (int i = 0; i < K; i++) {
            node = node->child;
        }
        std::cout << node->idx + 1 << std::endl;
    } else {
        long long int n = (K - n_head) % n_loop;
        auto node = &A[idx];
        for (int i = 0; i < n; i++) {
            node = node->child;
        }
        std::cout << node->idx + 1 << std::endl;
    }
}


Measured memory_bytes: 8008
using System;
using System.Linq;
using System.Collections.Generic;

class Program{
  static void Main(){
    string[] NK = Console.ReadLine().Split(' ');
    int N = int.Parse(NK[0]);
    int K = int.Parse(NK[1]);
    string[] V = ("0 " + Console.ReadLine()).Split(' ');　// 1-indexed
    
    int m = Math.Min(N, K);
    long result = int.MinValue;
    
    // A, B の回数を全探索
    for (int A = 0; A <= m; A++){
      var listA = new List<long>();
      // 左から A 個追加
      for (int i = 1; i <= A; i++){
        listA.Add(long.Parse(V[i]));
      }
      
      for (int B = 0; B <= m - A; B++){
        var listB = new List<long>();
        // 右から B 個追加
        for (int j = N; j >= N-B+1; j--){
          listB.Add(long.Parse(V[j]));
        }
        listB.AddRange(listA);
        listB.Sort();
        
        int diff = 0; // 誤差
        for (int k = 1; k <= K-A-B; k++){
          if ((k-diff) > listB.Count() || listB[k-1-diff] >= 0)
            break;
          listB.Remove(listB[k-1-diff]);
          diff ++;
        }
        result = Math.Max(listB.Sum(), result);
      }
    }
    
    Console.WriteLine(result);
  }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<ll, ll>;

const int MAXN = 3030;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}

int n, m;
string a, b;
int lcs[MAXN][MAXN], dp[MAXN][MAXN];

int solve(int i, int j) {
	if (i == n || j == m) return 0;
	if(dp[i][j] != -1) return dp[i][j];
	if (a[i] == b[j]) {
		lcs[i][j] = 3;
		return dp[i][j] = 1 + solve(i + 1, j + 1);
	} else {
		int lenA = solve(i + 1, j);
		int lenB = solve(i, j + 1);

		if (lenA > lenB) {
			lcs[i][j] = 1;
			return dp[i][j] = lenA;
		} else {
			lcs[i][j] = 2;
			return dp[i][j] = lenB;
		}
	}

}

void printLCS(int i, int j) {
	if (i == n || j == m) return ;
	if (lcs[i][j] == 3) {
		cout << a[i];
		printLCS(i + 1, j + 1);
	} else if (lcs[i][j] == 1) {
		printLCS(i + 1, j);
	} else if (lcs[i][j] == 2) {
		printLCS(i, j + 1);
	}
}

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

	memset(dp, -1, sizeof dp);

	cin >> a >> b;

	n = sz(a);
	m = sz(b);

	int len = solve(0, 0);
	printLCS(0, 0);

	return 0;
}

Measured memory_bytes: 72192
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string a;
    string b;

    cin >> a >> b;

    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
    } else if(a.size() < b.size()) {
        cout << "LESS" << endl;
    } else {
        if (a > b) {
            cout << "GREATER" << endl;
        } else if (a < b) {
            cout << "LESS" << endl;
        } else {
            cout << "EQUAL" << endl;
        }
    }

    return 0;
}


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

using namespace std;

#define Rep(b, e, i) for (ll i = b; i <= e; i++)
#define Repr(e, b, i) for (ll i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T, vector<T>, greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false) std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<vec> mat;
typedef vector<vecll> matll;
typedef vector<vecd> matd;

template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
	o << "{";
	for (int i = 0; i < (int)v.size(); i++)
		o << (i > 0 ? ", " : "") << v[i];
	o << "}";
	return o;
}

const int MAX = 1000010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const ll INFL = 1e18;
const ll MOD = 1e9+7;

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

//********************************template END****************************************//

void solve()
{
	int N, M;
	cin >> N >> M;
	vector<int> adj[N];
	int root = -1;
	vec dim(N);
	rep(N+M-1, i)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		adj[a].pb(b);
		dim[b]++;
	}
	rep(N, i)
	{
		if (!dim[i]) root = i;
	}
	vec par(N), vst(N);
	queue<int> q;
	q.push(root);
	while (!q.empty())
	{
		int v = q.front();
		q.pop();
		if (vst[v]) continue;
		for (int nv : adj[v])
		{
			dim[nv]--;
			if (!dim[nv])
			{
				par[nv] = v+1;
				q.push(nv);
			}
		}
	}
	rep(N, i)
	{
		cout << par[i] << endl;
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 7552
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= printRes . solve
    where
        printRes = putStrLn . unwords . map show 

solve :: [Int] -> [Int]
solve [n, a, b] = [maxv, minv]
    where
        maxv = min a b
        minv = max 0 $ a + b - n

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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


int main()
{
	int H,W,D;
	cin>>H>>W>>D;
	vector<pair<int,int>> pos(H*W+1,pair<int,int>());
	rep(i,H)
	{
		rep(j,W)
		{
			int a;
			cin>>a;
			pos[a].first=j;
			pos[a].second=i;
		}
	}
	vector<ll> table(H*W+1);
	rep(i,D)
	{
		table[i+1]=0;
		for(int j=i+1+D;j<=H*W;j+=D)
		{
			table[j]=abs(pos[j-D].first-pos[j].first)+abs(pos[j-D].second-pos[j].second)+table[j-D];
		}
	}
	int Q;
	cin>>Q;
	//rep(i,H*W+1)
	//{
	//	cout<<table[i]<<endl;
	//}
	rep(cnt,Q)
	{
		int l,r;
		cin>>l>>r;
		cout<<table[r]-table[l]<<endl;
	}
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vvs vector<vs>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

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

  if (S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  int cnt = 0;
  rep(i, 1, S.size()) {
    if (isupper(S[i])) {
      if (i == 1 || i == S.size() - 1 || S[i] != 'C') {
        cout << "WA" << endl;
        return 0;
      }
      cnt++;
    }
    if (cnt == 2) {
      cout << "WA" << endl;
      return 0;
    }
  }

  if (cnt == 0) {
    cout << "WA" << endl;
  } else {
    cout << "AC" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<math.h>

struct Point {
  double x;
  double y;
};
struct Point *p;
void qsort1(int left, int right);
void msort(int left, int right);
double closest_pair(int left, int right);
int main(void)
{
  int i, n;
  scanf("%d", &n);
  p = (struct Point*)malloc(sizeof(struct Point) * n);
  for (i = 0; i < n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
  qsort1(0, n - 1);
  printf("%.6f\n", closest_pair(0, n - 1));
  free(p);
}
void qsort1(int left, int right)
{
  int i, j;
  struct Point pivot;
  if (left >= right) return;
  i = left;
  j = right;
  pivot = p[(i + j) / 2];
  do {
    while (p[i].x < pivot.x) i++;
    while (p[j].x > pivot.x) j--;
    if (i <= j) {
      struct Point temp = p[i];
      p[i] = p[j];
      p[j] = temp;
      i++;
      j--;
    }
  } while(i <= j);
  qsort1(left, j);
  qsort1(i, right);
}
void msort(int left, int right)
{
  int middle, num, base, i, j;
  struct Point *work;
  middle = (left + right) / 2;
  work = (struct Point*)malloc(sizeof(struct Point) * (middle - left + 1));
  for (num = 0, i = left; i <= middle; i++) work[num++] = p[i];
  j = 0;
  base = left;
  while (i <= right && j < num) {
    if (p[i].y < work[j].y) p[base++] = p[i++];
    else p[base++] = work[j++];
  }
  while (j < num) p[base++] = work[j++];
  free(work);
}
double closest_pair(int left , int right)
{
  int middle, num, i, j;
  double x, d, dtemp;
  struct Point *work;
  if (left >= right) return INT_MAX;
  middle = (left + right) / 2;
  x = p[middle].x;
  d = closest_pair(left, middle);
  dtemp = closest_pair(middle + 1, right);
  msort(left, right);
  if (d > dtemp) d = dtemp;
  work = (struct Point*)malloc(sizeof(struct Point) * (right - left + 1));
  num = 0;
  for (i = left; i <= right; i++) {
    if (fabs(p[i].x - x) >= d) continue;
    for (j = 0; j < num; j++) {
      double dx = p[i].x - work[num - 1 - j].x, dy = p[i].y - work[num - 1 - j].y;
      if (dy >= d) break;
      dtemp = sqrt(dx * dx + dy * dy);
      if (d > dtemp) d = dtemp;
    }
    work[num++] = p[i];
  }
  free(work);
  return d;
}


Measured memory_bytes: 4948
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;


int main(){
	int n;
	bool f=false;
	while(cin >> n&&n){
		if(f) cout << "\n";
		f=true;
		vector<string> name;
		vector<int> point;
		
		for(int i=0; i<n; ++i){
			int win,lose,draw;
			string s;
			cin >> s >> win >> lose >> draw;
			name.push_back(s);
			point.push_back(win*3+draw);
		}
		
		for(int i=1; i<n; ++i){
			string s_tmp=name[i];
			int i_tmp=point[i];
			int j;
			for(j=i; ; --j){
				if(j==0||point[j-1]>=i_tmp) break;
				point[j]=point[j-1];
				name[j]=name[j-1];
			}
			point[j]=i_tmp;
			name[j]=s_tmp;
		}
		
		for(int i=0; i<n; ++i){
			cout << name[i] << "," << point[i] << "\n";
		}
	}
}

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

int main(){
  int n;
  cin >> n;
  ll x;
  vector<ll> a;
  vector<ll> b;
  REP(i,n){
    cin >> x;
    if(i % 2 == 0)a.push_back(x);
    else b.push_back(x);
  }
  if(n % 2 == 0){
    reverse(b.begin(),b.end());
    REP(i,n/2)cout << b[i] << " ";
    REP(i,n/2)cout << a[i] << " ";
  }else{
    reverse(a.begin(),a.end());
    REP(i,(n+1)/2)cout << a[i] << " ";
    REP(i,n/2)cout << b[i] << " ";
  }
}

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

using namespace std;

/*
say that |x| + |y| <= 2^{i+1}
We are adding/subtracting F_i.
Assume wlog |x| >= |y|. There are two cases:
(1) |x| >= F_i. Then |x'| = |x|-F_i and |x'|+|y'| <= T - F_i
(2) |x| < F_i. Then |x'| = F_i-|x| and |x'|+|y'| = F_i-|x|+|y| <= F_i
*/

struct Point {
    int x, y;
    Point() {}
    friend istream& operator>>(istream& in, Point& p) {
        return in >> p.x >> p.y;
    }
    string directions(vector<int>& ds) {
        string s = "";
        int x0 = x, y0 = y;
        for (auto d : ds) {
            if (abs(x0) > abs(y0)) {
                if (x0 > 0) {
                    s += "R";
                    x0 -= d;
                } else {
                    s += "L";
                    x0 += d;
                }
            } else {
                if (y0 > 0) {
                    s += "U";
                    y0 -= d;
                } else {
                    s += "D";
                    y0 += d;
                }
            }
        }
        return s;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<Point> points(n);
    for (auto& point : points) {
        cin >> point;
        if (((point.x + point.y)&1) != ((points[0].x + points[0].y)&1)) {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> ds;
    for (int i = 30; i >= 0; --i) {
        ds.push_back(1 << i);
    }
    if (((points[0].x + points[0].y)&1) == 0) {
        ds.push_back(1);
    }
    cout << ds.size() << endl;
    for (auto d : ds) {
        cout << d << " ";
    }
    cout << endl;
    for (auto point : points) {
        cout << point.directions(ds) << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func fn(ans, t, i int) (_ans, _t int) {
	j := pow(-1, i%2)
	if t*j <= 0 {
		ans += abs(j - t)
		t = j
	}
	return ans, t
}

func main() {
	var n, pAns, qAns, pT, qT int
	fmt.Scan(&n)

	for i := range make([]struct{}, n) {
		var a int
		fmt.Scan(&a)
		pT += a
		qT += a

		pAns, pT = fn(pAns, pT, i)
		qAns, qT = fn(qAns, qT, i+1)
	}
	fmt.Println(min(pAns, qAns))
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func pow(a, b int) int {
	res := 1
	for range make([]struct{}, b) {
		res *= a
	}
	return res
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
int main() {
    int ara[100],mark[100],i,j,k;
    memset(mark,0,sizeof(mark));
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>ara[i];
        int s=0;
    for(int i=1; i<n; i++) {
        if(ara[i]!=i)
        {
            s++;

        }

    }
    if(s<=2)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}


Measured memory_bytes: 256
import math

h1,m1,h2,m2,k=map(int,input().split())
start=60*h1+m1
end=60*h2+m2


print(end-start-k)
"""

a=[]
temp=input().split()
for i in range(n):
    a.append(int(temp[i])-1)

routetemp=[]
routetemp.append(0)
while True:
    if a[routetemp[-1]] in routetemp:
        roop=len(routetemp)-routetemp.index(a[routetemp[-1]])
        pre=routetemp.index(a[routetemp[-1]])
        break
    routetemp.append(a[routetemp[-1]])
#print(routetemp)
#print(a)
#print(roop)
#print(pre)
num=(k-pre)%roop
#print(num)
print(routetemp[pre+num]+1)
"""

Measured memory_bytes: 62036
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int a, b,max;
	vector<int> n(3);
	cin >> a >> b;
	n[0] = a + b;
	n[1] = a * b;
	n[2] = a - b;
	sort(n.begin(),n.end());
	max = n[2];
	cout << max << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
itn M;
int d[202020], c[202020];
void solve() {
    int ans = 0;
    int SUM = 0;
    int SUM2 = 0;
    FOR(i, 0, M) {
        SUM += d[i] * c[i];
        SUM2 += c[i];
    }
    ans += SUM / 9;
    if (SUM % 9 == 0)
        ans--;
    ans += SUM2 - 1;
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> M;
    FOR(i, 0, M) {
        cin >> d[i] >> c[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ll long long int  
vector<ll>v[200005];
ll a[200005],in[200005],out[200005],ctr;
void dfs(ll s,ll pa=-1){
    ctr+=1;
    in[s]=ctr;
    for(auto i:v[s]){
        if(i!=pa) dfs(i,s);
    }
    out[s]=ctr;
}

int main() {
	// your code goes here
	ll i,j,k,n,m,q;
	cin>>n>>q;
	for(i=1;i<n;i++){
	    ll x,y;
	    cin>>x>>y;
	    v[x].push_back(y);
	    v[y].push_back(x);
	}
	dfs(1);
	while(q--){
	    ll x,y;
	    cin>>x>>y;
	    a[in[x]]+=y;
	    a[out[x]+1]-=y;
	}
	for(i=2;i<=ctr;i++){
	    a[i]+=a[i-1];
	}
	for(i=1;i<=n;i++){
	    cout<<a[in[i]]<<" ";
	}
	return 0;
}


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

int main(int argc, char const *argv[])
{
  int a, b, c;
  int s1, s2;
  cin >> a >> b >> c;
  s1 = min(min(a, b), c);
  s2 = max(max(a, b), c);
  if(s1 == 5 && s2 == 7 && (a+b+c)-(s1+s2) == 5)
    cout << "YES" << flush;
  else
    cout << "NO" << flush;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
signed main(void){
    double n; cin>>n;
    rep(i,50000){
        double j = i;
        if(floor (j * 1.08) == n){
            cout<<j<<endl;
            return 0;
        } 
    }
    cout<<":("<<endl;

}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int x;
	scanf("%d", &x);
	if (x <= 599)puts("8");
	else if (x <= 799)puts("7");
	else if (x <= 999)puts("6");
	else if (x <= 1199)puts("5");
	else if (x <= 1399)puts("4");
	else if (x <= 1599)puts("3");
	else if (x <= 1799)puts("2");
	else puts("1");

	Please AC;
}

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

#include <iomanip>
void _130() {
    int w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << fixed << setprecision(10);
    cout << (double)w * h / 2 << " " << (2 * x == w && 2 * y == h) << endl;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K,T,m,n;cin>>K>>T;cin>>m;
  for(int i=1;i<T;i++){
    cin>>n;m=max(m,n);
  }
  cout<<max(0,2*m-K-1)<<endl;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

mod = 10 **9 +7
kinds = 0

def mod_factorial(nr, nl, m):
    r = 1
    for i in range(nl+1, nr+1):
        r *= i
        r %= m
    return r

def mod_inv_factorial(n1, n2, m):
    n = max(n1, n2)
    invs = [0] * (n + 1)
    invs[1] = 1
    for i in range(2, n + 1):
        invs[i] = m - invs[m % i] * (m//i) % m
        
    r1 = 1
    r2 = 1
    for i in range(1, n1+1):
        r1 *= invs[i]
        r1 %= m
    for i in range(1, n2+1):
        r2 *= invs[i]
        r2 %= m
    return r1, r2
        
        



kinds = 2 ** n -1

la = max(a, n-a)
sa = min(a, n-a)
lb = max(b, n-b)
sb = min(b, n-b)

upper1 = mod_factorial(n, la, mod)
upper2 = mod_factorial(n, lb, mod)

r1, r2 = mod_inv_factorial(sa, sb, mod)

print((kinds - upper1 * r1 - upper2 * r2)% mod)
t = 0

Measured memory_bytes: 404840
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	ll a,b;
	cin>>a>>b;
	if(a>b){
		for(int i=1;i<=a;i++)cout<<b;
		cout<<endl;
	} 
	else{
		for(int i=1;i<=b;i++)cout<<a;
		cout<<endl;
	}
}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{ 
 
 
    static long mod=1000000007;
    static int dx[]={1,-1,0,0};
    static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
 
    public  static void main(String[] args)   throws Exception, IOException{
     
        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
     
        int n=sc.nextInt();
        // long n=sc.nextLong();
        // char c[][] = new char[h][w];
        // long a[] = new long [n];
        // for (int i=0; i<n; i++) {a[i]=sc.nextInct();}
        // char c[] = sc.nextString().toCharArray();
        int max=100000;
        // max=100;
        boolean p[]=new boolean[max+1];
        boolean e[]=new boolean[max+1];

        for (int i=2;i*i<=max;i++) {
            if(!p[i])for (int t=i*i; t<=max;t+=i ) {
                p[t]=true;        
            }    
        }
        p[0]=p[1]=true;
        int d[] = new int[max+1];
        for (int i=3; i<max; i+=2) {
            if(!p[i] && !(p[i+1 >>1])){
                d[i]++;
                e[i]=true;
            }
            d[i]+=d[i-2];
        }
    
        for (int i=0; i<n ; i++) {
            int l=sc.nextInt();
            int r=sc.nextInt();
            out.println(d[r]-d[l]+(e[l]?1:0));
        }

        out.println();
        out.flush();
    }

    static void db(Object... os){
     
        System.err.println(Arrays.deepToString(os));
     
    }
     
    static boolean validpos(int x,int y,int r, int c){
        
        return x<r && 0<=x && y<c && 0<=y;
        
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class XY {
    int x,y,d;
    XY(int x, int y, int d) {
        this.x=x;
        this.y=y;
        this.d=d;
    } 
}
 
class P implements Comparable<P>{
    int x,y;
    P(int x, int y) {
        this.x=x;
        this.y=y;
    } 
      
    public int compareTo(P p){
        return -x + p.x;//des
    } 
}
 
class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 48868
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long N,arr[55];
	long long count=0;


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

	while(true) {
		sort(arr,arr+N);
		if(arr[N-1]<N)
			break;

		for(int i=0; i<N-1; i++) {
			arr[i]+=arr[N-1]/N;
		}
		count+=arr[N-1]/N;
		arr[N-1]%=N;
	}
	cout<<count<<endl;

	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if ((n & 1) == 0 || n % 5 == 0) {
        cout << -1;
        return 0;
    }
    int i = 1;
    int s = 7;
    while (true) {
        s = s % n;
        if (s % n == 0) {
            cout << i;
            return 0;
        }
        i++;
        s = 10*s + 7;
    }
}


Measured memory_bytes: 3624
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    X, Y, Z = MI()
    A = [Z, X, Y]
    print(' '.join(map(str, A)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 74636
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1])
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int N=5e5+5,mo=998244353;
int n,m,f[N],g[N],fac[N<<1],inv[N<<1];
int qmi(int x,int n)
{
	int t=1;
	for(x%=mo;n;n>>=1,x=(ll)x*x%mo) if(n&1) t=(ll)t*x%mo;
	return t;
}
int C(int m,int n){return (ll)fac[m]*inv[n]%mo*inv[m-n]%mo;}
int main()
{
	n=read(),m=read();if(n<m) swap(n,m);
	fac[0]=inv[0]=1;
	fo(i,1,n<<1) fac[i]=(ll)fac[i-1]*i%mo;
	inv[n<<1]=qmi(fac[n<<1],mo-2);
	fd(i,(n<<1)-1,1) inv[i]=(ll)inv[i+1]*(i+1)%mo;
	int ans=0;
	fo(i,1,m) ans=(ans+(ll)C(i+i,i)*C(n-i+m-i,n-i)%mo)%mo;
	ans=(ll)ans*qmi((ll)2*C(n+m,n)%mo,mo-2)%mo;
	printf("%d",(ans+n)%mo);
	return 0;
}

Measured memory_bytes: 8320
N=int(input())
A,X,Y=[],[],[]
for n in range(N):
    An=int(input())
    Xn,Yn=[],[]
    for a in range(An):
        x,y=map(int,input().split())
        Xn.append(x-1)
        Yn.append(y)
    A.append(An)
    X.append(Xn)
    Y.append(Yn)

max_count=0
for k in range(2**N):
    P=[int(_) for _ in bin(k)[2:].zfill(N)]
    ok=True
    for i in range(N):
        for j in range(A[i]):
            if P[i]==1 and P[X[i][j]]!=Y[i][j]:
                ok=False
    if ok:
        max_count=max(max_count,sum(P))
print(max_count)


Measured memory_bytes: 3064
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, k: usize, p: [u1; n], c: [i128; n]);
    let mut points: Vec<i128> = vec![];
    let mut ret = std::i128::MIN;
    for i in 0..n {
        points.clear();
        assert_eq!(points.len(), 0);
        let mut cur = i;
        loop {
            cur = p[cur];
            points.push(*points.last().unwrap_or(&0) + c[cur]);
            if cur == i {
                break;
            }
        }
        let pret = if k <= points.len() {
            *points[..k].iter().max().unwrap()
        } else {
            let s: i128 = *points.last().unwrap();
            if s <= 0 {
                *points.iter().max().unwrap()
            } else {
                let l = k % points.len();
                let a = k / points.len();
                let x = s * ((a - 1) as i128);
                let res = *points.iter().max().unwrap();
                let res = max(res, s + *points[..l].iter().max().unwrap_or(&0));
                x + res
            }
        };
        ret = max(ret, pret);
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2420
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define MAX 1000001
using namespace std;
typedef long long ll;

int main(){
  int n;  cin >> n;
  string s; cin >> s;
  string l, r;
  int ans = 0;
  rep(i, 1, n){
    l = s.substr(0, i);
    r = s.substr(i, n-i);
    set<char> st;
    int cnt=0;
    rep(j, 0, i){
      if(st.find(l[j])!=st.end()) continue;
      st.insert(l[j]);
      rep(k, 0, n-i){
        if(l[j]==r[k])  {
          cnt++;
          break;
        }
      }
    }
    ans = max(ans, cnt);
  }

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


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

typedef long long ll;

ll gcd(ll x, ll y) {
	while(y) {
		x%=y;
		swap(x, y);
	}
	return x;
}

int main() {
	ll n, x, ans=1;
	for(scanf("%lld", &n); n; n--) {
		scanf("%lld", &x);
		ans*=x/gcd(x, ans);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a<b){
    if(a<c&&c<b){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  else{if(b<c&&c<a){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
}



Measured memory_bytes: 128
//
//  ALDS_12_B.cpp
//  
//
//  Created by 杵鞭俊 on 2018/07/24.
//

#include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n ,M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX],color[MAX];
    for (int i=0; i<n; i++) {
        d[i]=INFTY;
        color[i]=WHITE;
    }
    
    d[0]=0;
    color[0]=GRAY;
    while (1) {
        minv=INFTY;
        int u=-1;
        for (int i=0; i<n; i++) {
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        
        if(u==-1) break;
        color[u]=BLACK;
        for (int v=0; v<n; v++) {
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
                if (d[v]>d[u]+M[u][v]) {
                    d[v]=d[u]+M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }
    for (int i=0; i<n; i++) {
        cout << i << " "<<(d[i]==INFTY?-1:d[i]) <<endl;
    }
}

int main(){
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            M[i][j]=INFTY;
        }
    }
    int k,c,u,v;
    for (int i=0; i<n; i++) {
        cin >> u >> k;
        for (int j=0; j<k; j++) {
            cin >> v >> c;
            M[u][v]=c;
        }
    }
    
    dijkstra();
    return 0;
}



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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> A(n);
  rep(i,n){
    cin >> A[i];
  }
  rep(i,n-k){
    if(A[i]<A[i+k])cout << "Yes"<<endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 4040
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[][] coord = new int[n][2];
      for(int i = 0; i < n; i++) {
        coord[i][0] = sc.nextInt();
        coord[i][1] = sc.nextInt();
      }
      Map<String, Integer> cntMap = new HashMap<>();
      for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
          if(i == j) continue;
          long dx = (long)coord[j][0] - (long)coord[i][0];
          long dy = (long)coord[j][1] - (long)coord[i][1];
          String key = dx + "," + dy;
          //System.out.println(key);
          cntMap.put(key, cntMap.getOrDefault(key, 0) + 1);
        }
      }
      int max = 0;
      for(Integer cnt : cntMap.values()) {
        max = Math.max(max, cnt);
      }
      System.out.println(n - max);
  }
}

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

int main()
{
int X;
int Y;
int Z;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> X;
	cin >> Y;
	cin >> Z;

	cout << ( X - Z ) / ( Y + Z ) << endl;

	return 0;
}






Measured memory_bytes: 256