akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

double dist(int *pt1, int *pt2, int D)
{
  double distance = 0;
  for (auto i = 0; i < D; i++) {
    distance += pow(pt2[i] - pt1[i], 2);
  }
  return (double)sqrt(distance);
}

int main()
{
  int N, D;
  
  cin >> N >> D;
  
  int pt[N][D];
  for (auto i = 0; i < N; i++) {
    for (auto j = 0; j < D; j++) {
      cin >> pt[i][j];
    }
  }
  
  double distance;
  int c = 0;
  for (auto i = 0; i < N; i++) {
    for (auto j = i + 1; j < N; j++) {
      distance = dist(pt[i], pt[j], D);
      if ((int)ceil(distance) == (int)distance) c++;
    }
  }
  cout << c;
}

Measured memory_bytes: 256
n,m,k=map(int,input().split())
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

print((n*m*(m-1)*(m+1)*k*(k-1)*cmb(n*m,k)//(6*m*(n*m-1))+m*n*(n-1)*(n+1)*k*(k-1)*cmb(n*m,k)//(6*n*(n*m-1)))%(10**9+7))

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    int ans = 1 + (n-1)/2 ;

    cout << ans ; line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm;

void main()
{
    bool[3] cups;
    cups[0] = true;
    while(true)
    {
        auto line = readln;
        if(!line)break;
        auto f = line.chomp.split(",");
        swap(cups[f[0][0] - 'A'], cups[f[1][0] - 'A']);
    }
    foreach(i, cup; cups)
    {
        if(cup) writeln(cast(char)('A' + i));
    }
}

Measured memory_bytes: 1052
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
#define MAXN 2005
#define INF 1000000007

vector <int> divisores(int n)
{
	vector <int> ans;
	forr(i,1,sqrt(n)+1)
	{
		if(n%i == 0) 
		{
			ans.pb(i);
			if(i*i != n) ans.pb(n/i);
		}
		
	}
	sort(all(ans));
	return ans;
}

int main()
{ 
	FIN;
	
	#ifdef input
		//freopen("test1.txt", "r", stdin);
	#endif
	
	vector <int> visto(1000005,0);
	int n;
	cin >> n;
	vector <int> v(n);
	forn(i,n) cin >> v[i];
	forn(i,n) visto[v[i]]++;
	int ans = 0;
	forn(i,n)
	{
		vector <int> div = divisores(v[i]);
		bool d=false;
		visto[v[i]]--;
		for(auto u : div)
		{
			if(visto[u]>0) d=true;
		}
		if(d==true) ans++;
		visto[v[i]]++;
	}
	cout << n-ans << endl;
	return 0;
}


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

using i64 = std::int_fast64_t;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
  i64 N, M;
  cin >> N >> M;
  vector<i64> A(N);
  cin >> A;
  sort(ALL(A));
  vector<i64> S(N + 1);
  REP(i, N) S[i + 1] = S[i] + A[i];
  i64 h_ng = 0;
  i64 h_ok = A[N - 1] * 2 + 1;
  i64 h = h_ok;
  i64 ans = 0;
  while (h_ok > h_ng + 1) {
    h = (h_ok + h_ng) / 2;
    i64 s = 0;
    i64 q = 0;
    i64 r = 0;
    i64 ge = 0;
    i64 gt = 0;
    RREP(i, N) {
      while (ge < N && !(A[i] + A[ge] >= h)) ge++;
      while (gt < N && !(A[i] + A[gt] > h)) gt++;
      q += N - gt;
      if (q > M) {
        h_ng = h;
        goto L;
      }
      r += gt - ge;
      s += S[N] - S[gt] + A[i] * (N - gt);
    }
    h_ok = h;
    if (M <= q + r) {
      cout << (s + (M - q) * h) << endl;
      exit(0);
    }
    L:;
  }
}


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

int cnt[2010];

int main() {
	string s;
	cin >> s;
	int num = 0, t = 1, res = 0;
	cnt[0] = 1;
	for(int i = s.size() - 1; i>=0; i--) {
		num = (num + (s[i] - '0') * t) % 2019;
		res += cnt[num];cnt[num]++;
		t = t * 10 % 2019;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3852
#include <cstdio>
#include <vector>
#include <functional>
using namespace std;

int main() {
  int N, M; scanf("%d%d", &N, &M);
  vector<vector<int>> graph(N);
  for(int i = 0; i < M; ++i) {
    int A, B; scanf("%d%d", &A, &B); --A; --B;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }
  vector<char> parity(N, -1);
  int parity_cnt[2] = {0, 0};
  bool has_odd_cycle = false;
  function<void(int, int)> dfs = [&](int v, int p) {
    if(parity[v] == (p ^ 1)) has_odd_cycle = true;
    if(parity[v] != -1) return;
    parity[v] = p;
    ++parity_cnt[p];
    for(int w : graph[v]) dfs(w, p ^ 1);
  };
  dfs(0, 0);
  long long edges = has_odd_cycle ?
    (long long)N * (N - 1) / 2 :
    (long long)parity_cnt[0] * parity_cnt[1];
  printf("%lld\n", edges - M);
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int sum=700;
    REP(i,3){
        if(s[i]=='o')sum+=100;
    }
    cout << sum <<endl;
}


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

int main(){
  int n,now=1;ll k;cin>>n>>k;
  int b[200001],a[200001];
  REP(i,n) cin>>b[i];

  for(;k>0;k/=2){
    if(k%2) now=b[now];
    REP(i,n) a[i]=b[b[i]];
    REP(i,n) b[i]=a[i];
  }
  cout<<now;
}

Measured memory_bytes: 5176
import itertools
while True:
    n=raw_input()
    if n=="0 0":break
    else:
        k=input()
    if k==0:break
    L=[raw_input() for i in range(int(n))]
    S=set()
    for t in itertools.permutations(L,k):
        S.add("".join(t))
    print len(S)

Measured memory_bytes: 4648
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, K = MI()
A = LMI()

from math import log2

# next[k][i] := i番目の要素の2^k個次の要素
next = [[0] * N for _ in range(int(log2(K)) + 1)]

# 構築 O(NlogK)
next[0] = [a - 1 for a in A]
for k in range(int(log2(K))):
    for i in range(N):
        # i番目の要素の2^(k+1)個次の要素 := next[k][i](i番目の要素の2^k個次の要素)の2^k個先
        next[k + 1][i] = next[k][next[k][i]]

# クエリ O(logK)
# p番目の要素のQ個次の要素を求める
p = 0
for i in reversed(range(int(log2(K)) + 1)):
    if (K >> i) & 1:
        p = next[i][p]
print(p + 1)


Measured memory_bytes: 176764
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

using namespace std;

#define li long long int
#define ld double_t
#define mod (li)(1e9+7)
const int MX1=1e5+5;
const int MX2=1e6+5;
const li inf=1e18;

li power(li a,li b){li res=1;while(b){if(b%2)res=(res*a)%mod;
a=(a*a)%mod;b/=2;}return res;}

li mmi(li a){return power(a,mod-2);}

li cntbit(li n){li cnt=0;while(n){n&=(n-1);cnt++;}return cnt;}

int n;
li a,b,arr[MX1];

void solve(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	li ans=0;
	for(int i=2;i<=n;i++){
		if((arr[i]-arr[i-1])*a>b) ans+=b;
		else ans+=(arr[i]-arr[i-1])*a;
	}
	cout<<ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 1024
def c_tsundoku():
    from itertools import accumulate
    N, M, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]

    a_cumsum, b_cumsum = [0] + list(accumulate(A)), [0] + list(accumulate(B))

    ans, j = 0, M
    for i in range(N + 1):  # 机 A から i 冊の本を読む
        if a_cumsum[i] > K:
            break  # i 冊読めない。終了
        while b_cumsum[j] > K - a_cumsum[i]:
            j -= 1  # i 冊読んだあと読めるだけ読む (毎度 M にセットしないことに注意)
        ans = max(ans, i + j)
    return ans

print(c_tsundoku())

Measured memory_bytes: 49140
n = input()
a = map(int, raw_input().split())
a = sorted(a)

cumsums = []
cum = 0
for i in xrange(n):
    cum += a[i]
    cumsums.append(cum)
i = n - 1
survivors = 1
while i > 0:
    if a[i] <= cumsums[i-1] * 2:
        survivors += 1
        i -= 1
        continue
    break
print survivors


Measured memory_bytes: 11320
from collections import deque

N=int(input())
b=list(map(int,input().split()))

op=[0]*N

for i in range(N-1,-1,-1):
    for j in range(len(b)-1,-1,-1):
        if b[j]==j+1:
            op[i]=j+1
            break
    
    if op[i]==0:
        print(-1)
        exit(0)

    b=[b[i] for i in range(op[i]-1)]+[b[i] for i in range(op[i],len(b))]

for op1 in op:
    print(op1)


Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <algorithm>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const int E = numeric_limits<int>::min();

int main(void)
{
    int N;
    cin >> N;
    int AC = 0, WA = 0, TLE = 0, RE = 0;
    rep(i, N){
        string testCase;
        cin >> testCase;
        if (!testCase.compare("AC")){
            AC++;
        }else if (!testCase.compare("WA")){
            WA++;
        }else if (!testCase.compare("TLE")){
            TLE++;
        }else if (!testCase.compare("RE")){
            RE++;
        }
    }

    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;

    return 0;
}

Measured memory_bytes: 3620
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var used;
  var dp = new Array(N + 1);
  var list = new Array(N);
  dp[0] = new Array(3).fill(0);
  for(var i = 1; i <= N; i++){
    dp[i] = new Array(3);
    list[i - 1] = nextIntArray();
  }
  for(var i = 0; i < N; i++){
    dp[i + 1][0] = Math.max(dp[i][1],dp[i][2]) + list[i][0];
    dp[i + 1][1] = Math.max(dp[i][0],dp[i][2]) + list[i][1];
    dp[i + 1][2] = Math.max(dp[i][0],dp[i][1]) + list[i][2];
  }
  myout(Math.max.apply(null,dp[N]));
}

Measured memory_bytes: 58928
n,m=map(int,input().split())
AC=[0]*n
penalty1=[0]*n 
penalty2=[0]*n 

for _ in range(m):
    P,S=map(str,input().split()) 
    p=int(P)-1
    if AC[p]==1:
        continue 
    else:
        if S=="AC":
            AC[p]=1 
            penalty2[p]=penalty1[p]
        else:
            penalty1[p]+=1 
            
print(sum(AC),sum(penalty2))

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

int main(){
    string s; cin >> s;
    char start=s.at(0);
    bool judge=false;
    for (char c: s){
        if (c!=start) {
            judge=true;
            break;
        }
    }
    if (judge) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

struct edge{
	int to,time;
};

const int INF=100000000;

class Situation{
public:
	int cost;
	int idx;
	int leftMin;

	Situation(int cost_,int idx_,int leftMin_){
		cost=cost_;
		idx=idx_;
		leftMin=leftMin_;
	}
	Situation();

	bool operator<(const Situation &s)const{
		return s.cost < this->cost;
	}
};

int d[101][101];
bool isColdable[101];
vector<edge> G[101];
int n,m,l,k,a,h;

void dijkstra(int s){
	priority_queue<Situation> que;
	for(int i = 0; i < 101; i++)
		fill(d[i],d[i]+101,INF);
	d[s][m] = 0;
	que.push(Situation(0,s,m));
	while(!que.empty()){
		Situation p = que.top();
		que.pop();
		int node = p.idx;
		int leftMin=p.leftMin;
		if(d[node][leftMin] < p.cost)
			continue;
		for(int i = 0; i < G[node].size(); i++){
			edge e = G[node][i];
			if(leftMin-e.time>=0){
				if(!isColdable[e.to]){
					if(d[e.to][leftMin-e.time] > d[node][leftMin] + e.time){
						d[e.to][leftMin-e.time] = d[node][leftMin]+e.time;
						que.push(Situation(d[e.to][leftMin-e.time],e.to,leftMin-e.time));
					}
				}
				else{
					for(int j = 0; j+leftMin-e.time<=m; j++){
						if(d[e.to][leftMin-e.time+j] > d[node][leftMin] + e.time+j){
							d[e.to][leftMin-e.time+j] = d[node][leftMin]+e.time+j;
							que.push(Situation(d[e.to][leftMin-e.time+j],e.to,leftMin-e.time+j));
						}
					}
				}
			}
		}
	}
}

int main(){

	while(cin>>n>>m>>l>>k>>a>>h&&!(n==0&&m==0&&l==0&&k==0&&a==0&&h==0)){
		// d[i][j]->¬iÉcèÔjÌtðÁÄ­é½ßÉ©©éÅ¬Ô
		fill(isColdable,isColdable+101,false);
		for(int i = 0; i < 101; i++)
			G[i].clear();
		for(int i = 0; i < l; i++){
			int num;
			cin>>num;
			isColdable[num]=true;
		}
		for(int i = 0; i < k; i++){
			int a,b,t;
			cin>>a>>b>>t;
			edge e;
			e.to=b;
			e.time=t;
			G[a].push_back(e);
			e.to=a;
			G[b].push_back(e);
		}
		dijkstra(a);
		int minTime=INF;
		for(int i = 0; i < 101; i++)
			minTime=min(d[h][i],minTime);
		if(minTime==INF)
			cout<<"Help!"<<endl;
		else
			cout<<minTime<<endl;
	}
	return 0;
}

Measured memory_bytes: 1404
#include <stdio.h>
#include <ctype.h>

int main(){
    int i, c;
    int count[26] = { 0 };
    
    while((c = getchar()) != EOF){
        if(isalpha(c)){
            if(isupper(c)){
                c = tolower(c);
            }
            
            ++count[c - 'a'];
        }
    }
    
    for(i = 0; i < 26; ++i){
        printf("%c : %d\n", 'a' + i, count[i]);
    }
    
    return 0;
}


Measured memory_bytes: 2608
n = int(input())
tmpa = list(map(int, input().split()))
A = [0] * (n+2)
A[0] = 0
A[n+1] = 0
for i in range(1,n+1,1): A[i] = tmpa[i-1]


#普通に総和を出す
sum = 0
for i, a in enumerate(A):
  if i == n+1: break #n+1はゴールなので先に行かない
  sum += abs(a - A[i+1]) #a:A[i]
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)


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

using namespace std;
typedef long long ll;

ll X,Y;
ll MOD = 1e9 + 7;

ll powmod(ll a, ll b){
    ll ans = 1;
    bitset<64> bt(b);
    for(int i=0;i<64;i++){
        if(bt[i] == 1) ans *= a;
        a *= a;
        ans %= MOD;
        a %= MOD;
    }
    return ans;
}

ll inv(ll n){
    return powmod(n, MOD-2);
}

ll fact(ll n){
    ll ans = 1;
    for(int i=2;i<=n;i++){
        ans *= i;
        ans %= MOD;
    }
    return ans;
}

ll comb(ll n, ll l){
    ll a = fact(n);
    ll b = fact(l) * fact(n-l);
    b %= MOD;
    b = inv(b);
    return (a * b) % MOD;
}

int main(){
    cin >> X >> Y;
    if((X+Y)%3 != 0  || min(X,Y) * 2 < max(X,Y)){
        cout << 0 << endl;
        return 0;
    }
    ll n = (X+Y) / 3;
    ll d = max(X,Y) - min(X,Y);
    cout << comb(n, (n-d)/2) << endl;
    return 0;
}

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

using namespace std;
const long long MOD=998244353;
long long dp[3009][3009];

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  dp[a][b]=1;
  for(int i=a+1;i<=c;i++){
    dp[i][b]=(b*dp[i-1][b])%MOD;
  }
  for(int i=b+1;i<=d;i++){
    dp[a][i]=(a*dp[a][i-1])%MOD;
  }

  for(int i=a+1;i<=c;i++){
    for(int j=b+1;j<=d;j++){
      dp[i][j] = (i*dp[i][j-1])%MOD;
      dp[i][j] = (dp[i][j] + (j*dp[i-1][j])%MOD)%MOD;
      dp[i][j] = (dp[i][j] - ((i-1)*(j-1)*dp[i-1][j-1])%MOD + MOD)%MOD;
    }
  }
  cout << dp[c][d] << endl;
}



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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    ll ta = A, tb = B, tc = C;
    int n = 0;
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
    {
        ll a = A / 2, b = B / 2, c = C / 2;
        A = b + c;
        B = a + c;
        C = a + b;
        n++;
        if (A == ta && B == tb && C == tc)
        {
            n = -1;
            break;
        }
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            string X = line[0];
            string Y = line[1];
            int nX = Convert.ToInt32(X, 16);
            int nY = Convert.ToInt32(Y, 16);
            if (nX == nY)
            {
                Console.WriteLine("=");
            }
            else if (nX < nY)
            {
                Console.WriteLine("<");
            }
            else
            {
                Console.WriteLine(">");
            }
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll f(ll a,ll b)
{
    ll k=0;
    while(b)
    {
        if(b&1) k=(k+a)%mod;
        a=(a+a)%mod;
        b>>=1;
    }
    return k;
}
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int main(){
   // ll e=power(10,100);
    ll e=226732710;
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ll l=i*(i-1)/2;
        ll r=(n+n-i+1)*i/2;
        //cout<<l<<" "<<r<<" "<<(l+r)%mod*(r-l+1)/2<<endl;
        //if(l!=r) ans=(ans+f(i,e)+(l+r)%mod*(r-l+1)/2)%mod;
        //else ans=(ans+f(i,e)+l)%mod;
        ans=(ans+r-l+1)%mod;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3624
#include <stdio.h>
int main(void) {
    int n,i,j,row,column;
    while (1) {
        scanf("%d",&n);
        if (n==0) break;
        int square[n][n];
        for (i=0; i<n; i++) {
            for (j=0; j<n; j++) square[i][j]=0;
        }
        for (i=1;i<=n*n;i++) {
            if (i==1) {
                row = n/2+1;
                column = n/2;
                square[row][column]=i;
                row++;
                column++;
            } else {
                if (column>=n&&row>=n) {
                	row = 1;
                	column = n-1;
                }
                if (column>=n) {
                    column = 0;
                    i--;
                    continue;
                }
                if (row>=n) {
                    row = 0;
                    i--;
                    continue;
                }
                if (square[row][column]!=0) {
                    row++;
                    column--;
                    i--;
                    continue;
                }
                square[row][column]=i;
                row++;
                column++;
            }
            
        }
        for (i=0; i<n; i++) {
            for (j=0; j<n; j++) printf("%4d",square[i][j]);
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 616
while True:
    m,f,r=map(int,input().split())
    a=0
    if m ==-1 and f==-1 and r==-1:
        break
    elif m==-1 or f==-1:
        a="F"
    elif m+f>=80:
        a="A"
    elif m+f>=65 and m+f<=79:
        a="B"
    elif m+f>=50 and m+f<=65:
        a="C"
    elif m+f>=30 and m+f<=49:
        if r>=50:
            a="C"
        else:
            a="D"
    elif m+f<=29:
        a="F"
    print(a)


Measured memory_bytes: 5596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    uint N, T; cin >> N >> T;
    vector<pair<int,int>> vCT(N); for(uint i=0; i<N; ++i){ cin >> vCT[i].first >> vCT[i].second; }
    sort(vCT.begin(), vCT.end());
    
    uint i=0;
    for(; i<N; ++i){
        if(vCT[i].second<=(int)T){ break; }
    }
    if(i!=N){ cout << vCT[i].first << endl;
    }  else { cout << "TLE" << endl; }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

  static int count;
  static int SENTINEL = 1000000001;

  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = Integer.parseInt(sc.next());
    int[] elements = new int[size];
    for (int i = 0; i < size; i++) {
      elements[i] = Integer.parseInt(sc.next());
    }

    mergeSort(elements, 0, size);

    for (int i = 0 ; i < size - 1; i++) {
      System.out.print(elements[i] + " ");
    }

    System.out.println(elements[size - 1]);
    System.out.println(count);
  }

  public static void mergeSort(int[] elements, int left, int right) {
    if (left + 1 < right) {
      int mid = (left + right) / 2;
      mergeSort(elements, left, mid);
      mergeSort(elements, mid, right);
      merge(elements, left, mid, right);
    }
  }

  public static void merge(int[] elements, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;

    int[] l = new int[n1+1];
    int[] r = new int[n2+1];

    for (int i = 0; i < n1; i++) {
      l[i] = elements[left + i];
    }
    for (int i = 0; i < n2; i++) {
      r[i] = elements[mid + i];
    }
    l[n1] = SENTINEL;
    r[n2] = SENTINEL;

    int i = 0 ;
    int j = 0;
    for (int k = left; k <= right; k++) {
      if (l[i] <= r[j] && l[i] != SENTINEL) {
        elements[k] = l[i];
        count++;
        i++;
      } else if (r[j] != SENTINEL) {
        elements[k] = r[j];
        count++;
        j++;
      }
    }
  }
}



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


int main() {


    char b;
    cin>>b;

    if(b=='A')
        cout<<'T'<<endl;
    else if(b=='T')
        cout<<'A'<<endl;
    else if(b=='C')
        cout<<'G'<<endl;
    else if(b=='G')
        cout<<'C'<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<int> even(n/2), odd(n/2);
    for (int i = 0; i < n; i++){
        if (i % 2 == 0) cin >> even[i/2];
        else cin >> odd[i/2];
    }

    map<int, int> count_even, count_odd;
    for (int i = 0; i < n/2; i++){
        count_even[even[i]] = 0;
        count_odd[odd[i]] = 0;
    }
    for (int i = 0; i < n/2; i++){
        count_even[even[i]]++;
        count_odd[odd[i]]++;
    }

    int e_argmax_int;
    int e_max_int = 0;
    for (pair<int, int> item : count_even){
        int key = item.first;
        int value = item.second;
        if (e_max_int < value){
            e_max_int = value;
            e_argmax_int = key;
        }
    }
    int o_argmax_int;
    int o_max_int = 0;
    for (pair<int, int> item : count_odd){
        int key = item.first;
        int value = item.second;
        if (o_max_int < value){
            o_max_int = value;
            o_argmax_int = key;
        }
    }

    // 2nd argmax
    int e_2nd_argmax_int = -1234567;
    int e_2nd_max_int = 0;
    for (pair<int, int> item : count_even){
        int key = item.first;
        int value = item.second;
        if (e_2nd_max_int < value && key != e_argmax_int){
            e_2nd_max_int = value;
            e_2nd_argmax_int = key;
        }
    }
    int o_2nd_argmax_int = -1234567;
    int o_2nd_max_int = 0;
    for (pair<int, int> item : count_odd){
        int key = item.first;
        int value = item.second;
        if (o_2nd_max_int < value && key != o_argmax_int){
            o_2nd_max_int = value;
            o_2nd_argmax_int = key;
        }
    }

    if (e_argmax_int != o_argmax_int){
        cout << abs(n/2 - e_max_int) + abs(n/2 - o_max_int) << endl;
    }else{
        cout << min(abs(n/2 - e_max_int) + abs(n/2 - o_2nd_max_int), abs(n/2 - e_2nd_max_int) + abs(n/2 - o_max_int)) << endl;
    }

    return 0;
}
















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

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < 4; ++i){
        if(s[i] == '+')ans++;
        else ans--;
    }
    cout << ans;
    return 0;

}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {
	int s = 0;
	vector<int> a(3); for (int i = 0; i <= 2; i++) cin >> a[i], s += a[i];

	if (s >= 22) cout << "bust";
	else cout << "win";

	return 0;
}

Measured memory_bytes: 3604
s = input().rstrip().split(' ')
A = int(s[0])
B = int(s[1])
total = 0
for i in range(2):
    if A >= B:
        total = total + A 
        A = A - 1
    elif A < B:
        total = total + B
        B = B - 1
print(total)


Measured memory_bytes: 2940
#include <stdio.h>
void count_f(int n,int p,int s,int sum,int num,int *count){
	if(n == p){
		if(s == sum)(*count)++;
		return;
	}
	
	if(s < sum)return;
	for(;num <= 9;num++)
		count_f(n,p+1,s,sum+num,num+1,count);
}
int main(void){
	int n,s,c;
	
	while(1){
		scanf("%d %d",&n,&s);
		if(n==0&&s==0)break;
		
		c = 0;
		count_f(n,0,s,0,0,&c);
		printf("%d\n",c);
	}
		
	return 0;
}

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

int main() {
  int h, w, k;
  cin>>h>>w>>k;
  long long mod = 1e9 + 7;

  long long dp1[3][w];
  dp1[0][0] = dp1[0][1] = 1;
  dp1[0][2] = dp1[1][2] = 1;
  dp1[1][1] = dp1[1][0] = 0;
  for (int i=3; i<w; i++) {
    dp1[0][i] = (dp1[0][i-1] + dp1[1][i-1]) % mod;
    dp1[1][i] = dp1[0][i-1];
  }
  for (int i=0; i<w; i++) dp1[2][i] = (dp1[0][i] + dp1[1][i]) % mod;

  long long ans[h+1][w];
  for (int i=0; i<=h; i++) {
    for (int j=0; j<w; j++) {
      ans[i][j] = 0;
    }
  }
  ans[0][0] = 1;
  for (int i=1; i<=h; i++) {
    for (int j=0; j<w; j++) {
      if (j > 0) {
        ans[i][j] += (((ans[i-1][j-1] * dp1[2][j-1]) % mod) * dp1[2][w-j-1]) % mod;
        ans[i][j] %= mod;
      }
      ans[i][j] += (((ans[i-1][j] * dp1[2][j]) % mod) * dp1[2][w-j-1]) % mod;
      ans[i][j] %= mod;
      if (j < w - 1) {
        ans[i][j] += (((ans[i-1][j+1] * dp1[2][j]) % mod) * dp1[2][w-j-2]) % mod;
        ans[i][j] %= mod;
      }
    }
  }
  cout<<ans[h][k-1]<<endl;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;

const int mod = 1e9 + 7;


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

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

	if(a < 10 && b < 10){
		cout << a * b << endl;
	}else{
		cout << -1 << endl;
	}


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
queue<long long> f;int n;
int main(){
	cin>>n;
	for(int i=1;i<=9;++i)f.push(i);int i=0;
	while(!f.empty()){
		long long k=f.front();f.pop();
		i++;
		if(i==n){cout<<k<<endl;break;}
		else for(long long l=k%10-1;l<=k%10+1;++l){
			if(l<0 || l==10)continue;
			f.push(k*10+l);
		}
	}
	return 0;
}

Measured memory_bytes: 1792
import sys
input=sys.stdin.readline
#K = int(input())
#S = input()[:-1]
a,b,x = map(int,input().split())

#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
import math
v = a*a*b
if x <= v/2:
    d = 2 * x / (a*b*b)
    th = math.degrees(math.atan(d))
    print(90-th)
elif x <= v:
    
    d = 2*(v-x)/(a*a*a)
    th = math.degrees(math.atan(d))
    print(th)


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

ll N, A, flag=0;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        cin >> A;
        if(A%2==0) {
            if(A%3*A%5!=0) flag=1;
        }
    }
    if(flag) cout << "DENIED" << endl;
    else cout << "APPROVED" << endl;
    return 0;
}

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

int main() {
  int parking_hours, price_per_1hour, price_of_no_related_hour;
  cin >> parking_hours >> price_per_1hour >> price_of_no_related_hour;
  
  if (parking_hours*price_per_1hour < price_of_no_related_hour) {
    cout << parking_hours*price_per_1hour << endl;
  } else {
    cout << price_of_no_related_hour << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

a, b = map(int, input().split())
_min, _max = min(a, b), max(a, b)
prime_factors = []
i = 2
while i ** 2 <= _min:
    ext = 0
    while _min % i == 0:
        ext += 1
        _min //= i
    if ext:
        prime_factors.append((i, ext))
    i += 1
if _min != 1:
    prime_factors.append((_min, 1))

ans = 1
for pf, _ in prime_factors:
    if _max % pf == 0:
        ans += 1
print(ans)


Measured memory_bytes: 63668
#include <bits/stdc++.h>
#define MOD 998244353LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<18;
	int dp[1<<19];
	segtree(){
		memset(dp,0,sizeof(dp));
	}
	void update(int k,int v){
		k+=N-1;
		dp[k]=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=max(dp[k*2+1],dp[k*2+2]);
		}
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		return max(vl,vr);
	}
};

int n;
P p[200005];
int to[200005];
segtree seg;
ll dp[200005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&p[i].first,&p[i].second);
	}
	sort(p,p+n);
	to[n-1]=n-1;
	seg.update(n-1,n-1);
	for(int i=n-2;i>=0;i--){
		int pos=lower_bound(p,p+n,P(p[i].first+p[i].second,0))-p;
		seg.update(i,i);
		int val=seg.query(i,pos);
		to[i]=val;
		seg.update(i,val);
	}
	dp[0]=1;
	ll ans=0;
	for(int i=0;i<n;i++){
		dp[i+1]+=dp[i];
		dp[i+1]%=MOD;
		dp[to[i]+1]+=dp[i];
		dp[to[i]+1]%=MOD;
	}
	ans+=dp[n];
	ans%=MOD;
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// 01Trie BIT CHT DFT FFT avl cmd cusum dijkstra dinic geo2 gin graph kruskal lca lcm matrix ncm next_combination ppuf segtree st tmp topcoder uf vi 

using Weight = int;
using Flow = int;
struct Edge {
    int s, d; Weight w; Flow c;
    Edge() {};
    Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
    g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
    addArc(g, a, b, w);
    addArc(g, b, a, w);
}

bool mm(vvi &data, vi &dg, int p, int num)
{
    dg[p] = num;
    bool ret = true;
    rep(i, data.size()) {
        if (i != p && data[i][p]) {
            if (!dg[i]) {
                ret &= mm(data, dg, i, (num == 1LL ? 2LL : 1LL));
            } else if (dg[i] == dg[p]) {
                return false;
            }
        }
    }
    return ret;
}

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

    Int(n);
    vvi data(n, vi(n, 0));
    vi digraph(n, 0);

    vector<string> shami(n);
    rep(i, n) {
        cin >> shami[i];
    }

    rep(i, n) {
        rep(j, n) {
            data[i][j] = shami[i][j] - '0';
        }
    }

    bool ret = true;
    rep(i, n) {
        if (!digraph[i]) {
            ret &= mm(data, digraph, i, 1LL);
        }
    }

    if (!ret) {
        std::cout << -1 << std::endl;
        return 0;
    }

    rep(i, n) {
        rep(j, n) {
            if (i == j) continue;
            if (data[i][j] == 0) data[i][j] = INF;
        }
    }
    
    rep(k, n) rep(i, n) rep(j, n)
        data[i][j] = min(data[i][j], data[i][k] + data[k][j]);

    int ans = 0;
    rep(i, n) {
        rep(j, n) {
            if (data[i][j] != INF) ans = max(ans, data[i][j]);
        }
    }

    std::cout << ans + 1 << std::endl;


    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
typedef pair<int,int> P;

stack<int> down;
stack<P> area;
int tot;
void get_input() {

}

void solve() {
    char c;
    int num=0;
    while(scanf("%c",&c)!=EOF) {
        if(c=='\\') {
            down.push(num);
        } else if(c=='/') {
            if(!down.empty()) {
                int t1=down.top();
                down.pop();
                int t2=num-t1;
                tot+=t2;
                while(!area.empty()) {
                    P t=area.top();
                    if(t.first>t1) {
                        area.pop();
                        t2+=t.second;
                    } else {
                        break;
                    }
                }
                area.push(make_pair(t1,t2));
            }
        }
        num++;
    }
}

void display_output() {
    printf("%d\n%d",tot,area.size());
    vector<int> ans;
    while(!area.empty()) {
        ans.push_back(area.top().second);
        area.pop();
    }
    for(int i=ans.size()-1;i>=0;i--) {
        printf(" %d",ans[i]);
    }
    printf("\n");

}

int main() {
#ifdef debug
    freopen("in.txt","r",stdin);
#endif
    get_input();
    solve();
    display_output();
}

Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
#define int long long
const int N = 2333;
int n, ans;
char s[N], t[N], str[N];

inline bool ok(int l) {
	rep (i, n) str[i] = s[i], str[l - i + 1] = t[n - i + 1];
	rep (i, n) if (str[i] != s[i]) return false;
	return true;
}

signed main(void) {
	cin >> n;
	scanf("%s%s", s + 1, t + 1);
	for (ans = n; ; ans++) if (ok(ans)) {
			cout << ans << "\n";
			return 0;
		}
	
}
				


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll N=1e5+1;
const ll M=2*N+2;
ll id[M];
ll sz[M];
vector<pll>pt;


void ini()
{
    for(ll i=0;i<M;i++)
    {
        id[i]=i;
        sz[i]=1;
    }
    return;
}

ll rt(ll x)
{
    while(x!=id[x])
    {
        id[x]=id[id[x]];
        x=id[x];
    }
    return x;
}

void merg(ll x,ll y)
{
    ll rtx=rt(x);
    ll rty=rt(y);
    if(rtx==rty)return;
    if(sz[rtx]>sz[rty])
		swap(rtx, rty);

	sz[rty]+=sz[rtx];
	sz[rtx]=0;
	id[rtx]=id[rty];
	return ;
}

int main()
{
    IOS
    ini();
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        pt.pb({x,y});
        merg(x,y+N);
    }
    map<ll,set<ll> >X;
    map<ll,set<ll> >Y;
    for(ll i=0;i<n;i++)
    {
        X[rt(pt[i].first)].insert(pt[i].first);
        Y[rt(pt[i].first)].insert(pt[i].second);
    }
    ll ans=0;
    for(auto it=X.begin();it!=X.end();it++)
    {
        ll fnl=(*it).first;
        ll rows=(*it).second.size();
        ll cols=(*Y.find(fnl)).second.size();
        ans+=(rows*cols);
    }
    cout<<ans-n<<endl;
    return 0;
}



Measured memory_bytes: 9584
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ');
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

int main () {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  int na = sa.size();
  int nb = sb.size();
  int nc = sc.size();
  //show3(na,nb,nc);

  int ia = 0, ib = 0, ic = 0;
  char turn = 'a';
  char ans;
  while(true) {
    //show(turn);
    if (turn == 'a') {
      if (ia == na) {
        ans = 'A';
        break;
      }
      else {
        if (sa[ia] == 'b') {
          turn = 'b';
          ia++;
        }
        else if (sa[ia] == 'c') {
          turn = 'c';
          ia++;
        }
        else ia++;
      }
    }
    else if (turn == 'b') {
      if (ib == nb) {
        ans = 'B';
        break;
      }
      else {
        if (sb[ib] == 'c') {
          turn = 'c';
          ib++;
        }
        else if (sb[ib] == 'a') {
          turn = 'a';
          ib++;
        }
        else ib++;
      }
    }
    else if (turn == 'c') {
      if (ic == nc) {
        ans = 'C';
        break;
      }
      else {
        if (sc[ic] == 'a') {
          turn = 'a';
          ic++;
        }
        else if (sc[ic] == 'b') {
          turn = 'b';
          ic++;
        }
        else ic++;
      }
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (((a < c) && (c < b)) || ((b < c) && (c < a))) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  int n,flag=0;
  cin>>n;
  while(n)
  {
    int d=n%10;
    if(d==7)
    {
      flag=1;
      cout<<"Yes"<<endl;
     return 0;
    }
    n/=10; 
  }
  if(!flag)
    cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;
const int Max = 2e5;
 
int n, a[Max + 5], l, r;
long long ans;
map<int, int> cnt;

bool cmp(int m, int n){
	return m > n;
}
 
int main()
{
	scanf ("%d", &n);
	cnt.clear();
	for (int i = 1; i <= n; i++){
		scanf ("%d", &a[i]);
		cnt[a[i]]++;
	}
	l = 0;
	r = 0;
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1; i <= n; i++){
		if (cnt[a[i]] >= 2){
			if (!l)	l = a[i], cnt[a[i]]-=2;
			else r = a[i];
			if (l && r)	break;
		}
	}
	ans = (long long)l * r;
	printf ("%lld\n", ans);
}

Measured memory_bytes: 5376