akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		while(true){
			int n =sc.nextInt();
			if(n==0){break;}
			int[] s =new int[n];
			
			for(int i=0; i<n;i++){
				s[i]=sc.nextInt();
			}
			int low =s[0];
			int high =s[0];
			int sum=s[0];
			
			for(int i=1;i<n;i++){
				sum = sum + s[i];
			
				if(s[i]<low){
					low=s[i];
				}else if(s[i]>high){
					high=s[i];
				}
			}
			
			int ave =(sum-high-low)/(n-2);
			
		System.out.println(ave);
		}
	}
}

Measured memory_bytes: 28548
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/6/ITP1_6_D

#include <iostream>
#include <vector>

int main()
{
    using std::vector;

    int n, m;
    std::cin >> n >> m;

    // vector<vector<vector<int>>> V(B, vector<vector<int>>(F, vector<int>(R, 0)));

    vector<vector<int>> A(n, vector<int>(m, 0));
    vector<int> b(m, 0);
    vector<int> product(n, 0);

    for (auto &vec : A)
    {
        for (auto &elem : vec)
        {
            std::cin >> elem;
        }
    }

    for (auto &elem : b)
    {
        std::cin >> elem;
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            product.at(i) += A.at(i).at(j) * b.at(j);
        }
    }

    for (auto &elem : product)
    {
        std::cout << elem << std::endl;
    }
}


Measured memory_bytes: 3208
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    ll X, K, D;
    cin >> X >> K >> D;

    if (X < 0) {
        X = abs(X);
    }

    if (K >= X / D) {
        // printf("[1]: %lld or %lld\n", X % D, D - (X % D));
        int step = (X - X % D) / D;
        if (step % 2 == K % 2) {
            cout << X % D << endl;
        } else {
            cout << D - (X % D) << endl;
        }
    } else {
        // printf("[2]: %lld\n", X - K * D);
        cout << X - K * D << endl;
    }

    return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int main(void){
  string S;
  int N,A,B;
  int i;
  int res=0;
  int ai=0,bi=0;
  cin>>N>>A>>B>>S;

  for(i=0;i<N;i++){
    if(S[i]=='a'){
      if((ai+bi)<(A+B)){
        ai++;
        cout<<"Yes"<<endl;
      }
      else cout<<"No"<<endl;
    }
    else if(S[i]=='b'){
      if(((ai+bi)<(A+B))&&(bi<B)){
        bi++;
        cout<<"Yes"<<endl;
      }
      else cout<<"No"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        System.out.println(fact(n));
    }

    private static long fact(int n) {
        if (n == 0) return 1;
        return n * fact(n - 1);
    }
}

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

using namespace std;

long long dp[5][100005], ans, n, a[100005];

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= 3; j++){
            cin >> a[j];
            ans = 0;
            for (int f = 1; f <= 3; f++)
                if (j != f)
                    ans = max(ans, dp[f][i - 1]);
            dp[j][i] = a[j] + ans;
        }
    }
    ans = 0;
    for (int i = 1; i <= 3; i++)
        ans = max(ans, dp[i][n]);
    cout << ans;
}

Measured memory_bytes: 2816
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include <deque>
using namespace std;

int n, m, ansx, ansy;

int main() {
	scanf("%d%d", &n, &m);
	for (int i =1 ; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			string S;
			cin >> S;
			if (S == "snuke")
				ansx = i, ansy = j;
		}
	printf("%c%d\n", ansy + 'A' - 1, ansx);
}


Measured memory_bytes: 256
N, K, *A = map(int, open(0).read().split())

# Destination
t = [[-1] * N for _ in range(61)]
t[0] = [v - 1 for v in A]
for k in range(60):
    for i in range(N):
        t[k + 1][i] = t[k][t[k][i]]

u = 0
for k in range(61):
    if K >> k & 1:
        u = t[k][u]
        
print(u + 1)


Measured memory_bytes: 181112
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_c

x = int(input())

n = x // 100
m = x % 100
c = 0
for i in range(1, 6)[::-1]:
    c += m // i
    m %= i
if c <= n:
    print(1)
else:
    print(0)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w,a[81][81],b[81][81],c[81][81];
	bool dp[81][81][12800];
	cin>>h>>w;
	rep(i,h){
		rep(j,w){
			cin>>a[i][j];
		}
	}
	rep(i,h){
		rep(j,w){
			cin>>b[i][j];
		}
	}
	rep(i,h){
		rep(j,w){
			c[i][j]=abs(a[i][j]-b[i][j]);
		}
	}
	rep(i,h){
		rep(j,w){
			for(int k=0;k<=(h+w-1)*80;k++){
				dp[i][j][k]=false;
			}
		}
	}
	dp[0][0][c[0][0]]=true;
	rep(i,h){
		rep(j,w){
			for(int k=0;k<=(i+j+1)*80;k++){
				if(dp[i][j][k]){
					if(i!=h-1){
						dp[i+1][j][abs(k-c[i+1][j])]=true;
						dp[i+1][j][k+c[i+1][j]]=true;
					}
					if(j!=w-1){
						dp[i][j+1][abs(k-c[i][j+1])]=true;
						dp[i][j+1][k+c[i][j+1]]=true;
					}
				}
			}
		}
	}
	for(int i=0;i<=(h+w-1)*80;i++){
		if(dp[h-1][w-1][i]){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 82304
while True:
    n,x = [int(x) for x in input().split()]
    if (n,x)==(0,0): break
    cnt=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k == x: cnt+=1
    print(cnt)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using i64 = long long;

std::vector<std::deque<int>> g;

std::pair<int, int> dfs(int v, int p) {
    std::pair<int, int> ret { v, 0 };
    for (auto c : g[v]) {
        if (c == p) continue;
        const auto q = dfs(c, v);
        if (q.second + 1 > ret.second) {
            ret.second = q.second + 1;
            ret.first = q.first;
        }
    }
    return ret;
}

int main() {
    int n;
    std::cin >> n;
    g.resize(n);
    for (int i = 1; i < n; i++) {
        int a, b;
        std::cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto d = dfs(dfs(0, -1).first, -1).second;
    std::cout << (d % 3 != 1 ? "First" : "Second") << std::endl;

    return 0;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(c,b/a) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
char s[N];
int n, k;

void solve()
{
    cin >> k >> s;
    n = strlen(s);
    for (int i = 0; i < min(n, k); ++i)
    {
        printf("%c", s[i]);
    }
    if (k < n)
        printf("...");
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";


using namespace std;

string stroka;

int main(){
FLASH;
cin>>stroka;
ll sum=0;
for(auto i:stroka)
{
  sum=sum+(i-'0');	
}


if(sum%3==0 && sum%9==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;





return 0;
} 


Measured memory_bytes: 3752
def myAnswer(w:list) -> str:
   dic = dict()
   for i in w:
      if(i in dic.keys()):
         dic[i]+=1
      else:
         dic[i]=1
   for value in dic.values():
      if(value%2 == 1):
         return "No"
   return "Yes"
         

def modelAnswer():
   tmp=1
def main():
   w = list(input())
   print(myAnswer(w))

if __name__ == '__main__':
   main()

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

int main() {

  int s,s1,s2;
  int o,tw,th,su;

  cin >> s;
  o=s/100;
  s1=s%100;
  tw=s1/10;
  s2=s1%10;
  th=s2;
  su=o+tw+th;
  cout << su << endl;
  return 0;
}


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


int main(){
    string n;
    cin >> n;
    int ans;
    if(n == "SUN"){
        ans = 7;
    }else if(n == "MON"){
        ans = 6;
    }else if(n == "TUE"){
        ans = 5;
    }else if(n == "WED"){
        ans = 4;
    }else if(n == "THU"){
        ans = 3;
    }else if(n == "FRI"){
        ans = 2;
    }else if(n == "SAT"){
        ans = 1;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if(a * b % 2 == 0 || c % 2 == 0) cout << 0 << endl;
    else cout << min(a * b, min(b * c, c * a)) << endl;
}

Measured memory_bytes: 256
#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 MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  string S;
  cin >> S;
  bool flag=true;
  REP(i,S.size()){
    if(i&1){
      if(S[i]=='R'){
        flag=false;
      }
    }else{
      if(S[i]=='L'){
        flag=false;
      }
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;
int n,c,k,T,che = 0,cnt = 0;

int t[MaxN + 5];

int main()
{
	scanf("%d%d%d",&n,&c,&k);
	for(int i = 1; i <= n;i++) scanf("%d",&t[i]);
	sort(t + 1,t + n + 1);
	T = t[1];
	for(int i = 1; i <= n;i++)
	{
         if(t[i] - T <= k) cnt++;
         if(t[i] - T > k) {che++;cnt = 1;T = t[i];}
         if(cnt > c) { che++; cnt = 1; T = t[i];}
         if(i == n && t[n] - T <= k && cnt <= c) che++;
	}
	printf("%d\n",che);
	return 0;
}



Measured memory_bytes: 512
h,w = map(int,input().split())
lis = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
li = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26"]
for i in range(h):
    s = list(map(str,input().split()))
    for m in range(w):
        if s[m] == "snuke":
            print(lis[m] + li[i])
            exit()

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

map<ll, ll> mp;
void prime_factorization(ll x){
    bool flag = true;
    while(flag){
        ll sqx = sqrt(x)+1;
        for(ll j=2;j<sqx+1;j++){
            if(x%j==0){
                mp[j]++;
                x/=j;
                break;
            }
            if(j==sqx) flag = false;
        }
    }
    if(x!=1){
        mp[x]++;
    }
}

ll Euclid(ll A, ll B){
    if(A<B) swap(A, B);
    ll C = B;
    while(C != 0){
        C = A%B;
        A = B;
        B = C;
    }
    return A;
}

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

    ll A, B;
    cin >> A >> B;
    ll G = Euclid(A, B);

    prime_factorization(G);
    ll res = 1;
    for(auto x: mp){
    	res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 1e9 + 7;

ll power(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll inverse(ll x) {
  return power(x, MOD - 2);
}

vector<ll> fact, factInv;
void initFact(int N) {
  fact.resize(N + 1);
  factInv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  factInv[N] = inverse(fact[N]);
  for (int i = N - 1; i >= 0; i--) {
    factInv[i] = factInv[i + 1] * (i + 1) % MOD;
  }
}

ll choose(int n, int k) {
  if (k > n) {
    return 0;
  } else {
    return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD;
  }
}

ll f(ll pA, ll pB, ll pC, ll N) {
  ll qA = pA * inverse((pA + pB) % MOD) % MOD;
  ll qB = pB * inverse((pA + pB) % MOD) % MOD;
  ll res = 0;
  for (int M = N; M < 2 * N; M++) {
    ll e1 = 1;
    e1 = e1 * power(qA, N) % MOD;
    e1 = e1 * power(qB, M - N) % MOD;
    ll e2 = 1;
    e2 = e2 * power(qA, M - N) % MOD;
    e2 = e2 * power(qB, N) % MOD;
    ll e = (e1 + e2) % MOD;
    e = e * choose(M - 1, N - 1) % MOD;
    e = e * M % MOD;
    e = e * inverse((1 - pC + MOD) % MOD) % MOD;
    //e = e * inverse(power((1 - pC + MOD) % MOD, M + 1)) % MOD;
    res = (res + e) %  MOD;
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  initFact(300000);
  ll N, A, B, C;
  while (cin >> N >> A >> B >> C) {
    ll pA = A * inverse(100) % MOD;
    ll pB = B * inverse(100) % MOD;
    ll pC = C * inverse(100) % MOD;
    ll res = f(pA, pB, pC, N);
    cout << res << endl;
  }
  return 0;
}


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

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

    long m=0,a=0,r=0,c=0,h=0;

    rep(i,n){
        string s;
        cin >> s;
        if(s[0]=='M') m++;
        if(s[0]=='A') a++;
        if(s[0]=='R') r++;
        if(s[0]=='C') c++;
        if(s[0]=='H') h++;
    }

    long ans=0;
    ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;

    cout << ans << endl;
}

Measured memory_bytes: 256
N = gets.to_i
S = Hash.new(0)
# 先頭文字をカウント
N.times { S[gets.chomp[0]] += 1 }

cnt = 0
# M,A,R,C,Hから３つを重複なしで配列化
"MARCH".chars.combination(3).to_a.each do |p|
  #重複なしパターンでそれぞれ3人の組合せを出す
  cnt += S[p[0]]*S[p[1]]*S[p[2]]
end
puts cnt

Measured memory_bytes: 4092
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		int n= in.nextInt();
		int m=n;
		long s=0;
		while(n--!=0)
			s+=in.nextInt();
		System.out.println(s/m);
	}

}

Measured memory_bytes: 12000
#include<iostream>
using namespace std;
void call(int n)
{
	for (int a = 1; a <= n; a++)
	{
		if (a % 3 == 0){ cout << " " << a; }
		else if (a % 10 == 3){ cout << " " << a; }
		else for (int b = a; b != 0; b /= 10)
		{
			if (b % 10 == 3)
			{
				cout << " " << a;
				b = 0;
			}
		}
	}
}

int main(){
	int n;
	cin >> n;
	call(n);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3112
#include <stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int op[N],d[N],f[N],time;

void dfs(int u){
	int v;
	op[u] = GRAY;
	d[u] = ++time;
	for(v=0;v<n;v++){
		if(M[u][v] && op[v] == 0){
			dfs(v);
		}
	}
	op[u] = BLACK;
	f[u] = ++time;

}

int main(void){

	int u,v,k,i,j;
	
	scanf("%d",&n);
	
	for(i=0;i<N;i++){
    	for(j=0;j<n;j++){
        	M[i][j]=0;
    	}
	}
	
	for(i=0;i<n;i++){
    scanf("%d %d",&u, &k);
    for(j=0;j<k;j++){
        scanf("%d",&v);
        M[u-1][v-1]=1;
   		}
    }
	
	time = 0;
     
    for(i=0; i<N; i++) {
    	op[i]=0;
    }
	
	for(i=0; i<n; i++) {
    	if (op[i]==0) dfs(i);
    }
 
    for(i=0; i<n; i++){
    	printf("%d %d %d\n", i+1, d[i], f[i]);
    }


return 0;


}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

struct Mod {
    static constexpr auto kMod = 1000000007L;

    // can be implicitly converted
    Mod(int64_t n) : n(n) {}

    Mod operator*(Mod m) const { return (n * (m.n % kMod)) % kMod; }

    Mod& operator*=(Mod m) {
        *this = *this * m;
        return *this;
    }

    Mod pow(int64_t p) {
        if (p == 0) {
            return 1;
        }
        if (p == 1) {
            return n;
        }

        int64_t r = this->pow(p / 2).n;
        if (p % 2 == 0) {
            return r * r % kMod;
        } else {
            return (r * r % kMod) * n % kMod;
        }
    }

    Mod operator/(Mod m) const {
        if (n == 0) {
            return 0;
        }

        return *this * m.pow(kMod - 2);
    }

    Mod& operator/=(Mod m) {
        *this = *this / m;
        return *this;
    }

    Mod operator+(Mod m) const { return (n + m.n) % kMod; }

    Mod& operator+=(Mod m) {
        *this = *this + m;
        return *this;
    }

    Mod operator-(Mod m) const { return (kMod + n - m.n) % kMod; }

    Mod& operator-=(Mod m) {
        *this = *this - m;
        return *this;
    }

    int64_t n;
};

Mod calc_l(int64_t l, int64_t d) {
    auto z = 0;
    Mod ret = 0;
    for (auto i : irange(0L, d) | reversed) {
        auto a = (1uL << i);

        if ((l & a) > 0) {
            continue;
        }

        ret += Mod(2).pow(z) * Mod(3).pow(i);
        ++z;
    }

    ret += Mod(2).pow(z);

    return ret;
}

Mod calc_r(int64_t r, int64_t d) { return calc_l(~r, d); }

Mod calc_lr(int64_t l, int64_t r, int64_t d) {
    Mod ret = 0;
    for (auto i : irange(0L, d) | reversed) {
        auto a = (1uL << i);

        if ((l & a) == (r & a)) {
            continue;
        }

        if ((l & a) == 0 && (r & a) > 0) {
            ret += calc_l(l, i);
            ret += calc_r(r, i);
        } else {
            return ret;
        }
    }

    ret += 1;

    return ret;
}

Mod calc(int64_t l, int64_t r) {
    Mod ans = 0;

    int64_t a = 1, b = 0;
    while ((a << 1) <= l) {
        a = (a << 1);
        ++b;
    }

    if ((a << 1) > r) {
        return calc_lr(l, r, b);
    }

    ans += calc_l(l, b);

    a = (a << 1);
    ++b;
    while ((a << 1) <= r) {
        ans += Mod(3).pow(b);
        a = (a << 1);
        ++b;
    }

    ans += calc_r(r, b);

    return ans;
}

main() {
    int64_t l, r;
    cin >> l >> r;

    cout << calc(l, r).n << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    s = list(input())

    x = 0
    ans = 0
    for i in range(n):
        if s[i] == 'I':
            x += 1
        if s[i] == 'D':
            x -= 1
        ans = max(ans, x)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(500*500)
N = int(input())
edges = [list(map(int,input().split())) for _ in range(N-1)]
A = [[]for _ in range(N+1)]
ans = [-1]*(N+1)
for u,v,w in edges:
    A[u].append([v,w%2])
    A[v].append([u,w%2])

ans[1] = 0
def dfs(r):
    for a in A[r].copy():
        n = a[0]
        d = a[1]
        if ans[n] == -1:
            ans[n] = (ans[r] + d) % 2
            dfs(n)
dfs(1)
for a in ans[1:]:
    print(a%2)


Measured memory_bytes: 103252
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define MOD 1000000007

using namespace std;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n, m; cin>>n>>m;
	
	vector<lint> b(n+1,1);
	vector<lint> pd(n+1,1);
	pd[0] = 1;
	
	for(int i=0;i<m;i++){
		int x; cin>>x;
		b[x]=0;
	
	}
	pd[1]=b[1];
	
	for(int i=2;i<=n;i++){
		pd[i] = (pd[i-1]*b[i-1] + pd[i-2]*b[i-2])%MOD;
	}
	cout<<pd[n]<<"\n";
	

	return 0;	
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N, T, A;
    cin >> N >> T >> A;
    map<double, int> place;
    for(int i = 0; i < N; i++){
        int H;
        cin >> H;
        place[abs(A - (T - 0.006 * H))] = i + 1;
    }
    cout << (*place.begin()).second << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define mer make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;
typedef pair<int,pair<int,int> > ipii;
typedef pair<pii,pii> pi4;
const int vbi=999999999;

/*void cin_bin(){
	char bin[10000];
	gets(bin);
}*/

vector<int> jz10_2(int a){
	vector<int> ans;
	while(a!=0){
		ans.pb(a%2);
		a/=2;
	}
	reverse(ans.begin(),ans.end());
	return ans;
}

int main(){
	//my new name is Veex
	//clock_t start1=clock();
	string str;
	cin>>str;
	if(str.size()==2)
		cout<<str;
	else{
		reverse(str.begin(),str.end());
		cout<<str;
	}
	//cout<<endl<<((double)(clock()-start1)/CLOCKS_PER_SEC);
	return 0;
}


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

long long  A,B,N,M;

long long F( long long X ) {

    return floor( (A*X)/B);
}

int main() {

    cin >> A >> B >> N;

    M = min(B-1,N);

    cout << F(M) << endl;
}


Measured memory_bytes: 3652
#include <stdio.h>
#define M 1000

int main(){
  int i,j,k,m,n,u;
  int Ad[M][M];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d",&m);
      Ad[u-1][m-1] = 1;
    }
  }

  for(i = 0 ; i < n ; i++){
    for (j = 0 ; j < n-1 ; j++){
      printf("%d ", Ad[i][j]);
    }
    printf("%d\n", Ad[i][j]);
  }

  return 0;
}



Measured memory_bytes: 2112
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      s: chars,
    }

    let mut ans = 0;
    let n = s.len();
    for i in 0..n/2 {
        if s[i] != s[n-i-1] {
            ans += 1;
        }
    }
    puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>

void shuffle(std::string& cards, std::size_t h)
{
    std::stringstream ss;
    for (std::size_t i = 0; i < h; ++i) {
        ss << cards[i];
    }
    cards.erase(0, h);
    cards.append(ss.str());
}

int main()
{
    while (true) {
        std::string cards;
        std::cin >> cards;
        if (cards == "-") {
            break;
        }

        std::size_t m, h;
        std::cin >> m;
        for (std::size_t i = 0; i < m; ++i) {
            std::cin >> h;
            shuffle(cards, h);
        }

        std::cout << cards << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3220
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author ACER
 */
import java.util.Scanner;
public class Main {
    



  public static void main(String [] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    System.out.println(n*n*n);
  }
}
    
    
    

Measured memory_bytes: 22740
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double ans=0;
        for (int i = 0; i < n; i++) {
            double tmp = sc.nextDouble();
            ans += (1 / tmp);
        }
        System.out.println(1 / ans);
    }
}

Measured memory_bytes: 23252
#include <stdio.h>

int main(void){
  int n, i, j, k, b, f, r, v;
  int count[4][3][10] = {0};

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d %d %d %d", &b, &f, &r, &v);
    count[b - 1][f - 1][r - 1] += v;
  }

  for(i = 0; i < 4; i++){
    if(i)
      printf("####################\n");
    for(j = 0; j < 3; j++){
      for(k = 0; k < 10; k++){
        printf(" %d", count[i][j][k]);
      }
      printf("\n");
    }
  }

  return 0;
}

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

// Template START
#define endl "\n"
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define Int long long int
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
const int mod = (int)1e9 + 7 ;
template<class T>
auto matrix( int r, int c, T v ){
    return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
template<class T>
auto matrix( int o1, int o2, int o3, T v ){ 
    return vector<vector<vector<T>>>( o1, vector<vector<T>>( o2, vector<T>( o3, v ) ) ) ;
}
#define v vector
// Template END

int power( int x, int n ){
    if( n == 0 ) return 1 ;
    else if( n & 1 ) return ( x * power( (x*x) % mod, n / 2 ) ) % mod ;
    return power( (x*x) % mod, n / 2 ) % mod ;
}



signed main(){
    int N ; cin >> N ;
    int sqrtN = sqrt(N) ;
    int ans = 0 ;
    for( int a = 1 ; a <= N ; a++ ){
        ans += ( ceil( (N * 1.0) / a ) - 1 ) ;
    }
    cout << ans ;
    return 0 ;   
}          

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

int main() {
    int N,n;
    cin >> N;
    n = N;
    int f = 0;

    while (N > 0)
    {
        f += N%10;
        N /= 10;
        
        //cout << N << " "<< f << endl;
    };

    //f += stoi(N[1]);
    if (n % f == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();
        int e = in.nextInt();
        int f = in.nextInt();
        int g = in.nextInt();
        int h = in.nextInt();
        int i = in.nextInt();

        int x = a - d;
        if (b - e != x || c - f != x) {
            out.println("No");
            return;
        }

        int y = a - g;
        if (b - h != y || c - i != y) {
            out.println("No");
            return;
        }

        out.println("Yes");
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


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

#define PI 3.1415 
  
int main(){
	
	float radius;
	float circum;
	
	scanf("%f",&radius);
	
	circum =(2 * PI * radius);
	
	
	printf("%f",circum);
	
	
	return 0;
	
}

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


int main()
{

    int n;
    cin >> n;

    double x[n],y[n],ans[4];
    vector<double> ab;

    rep(i,n){
        cin >> x[i];
    }
    rep(i,n){
        cin >> y[i];
    }

    for(int i=1;i<4;i++){
        double dist=0;
        rep(j,n){
            dist += pow(fabs(x[j] - y[j]),i);
        }
        double p=i;
        ans[i-1]=pow(dist,1/p);         
    }

    rep(i,n) ab.push_back(fabs(x[i]-y[i]));
    ans[3] = *max_element(ab.begin(),ab.end());    

    printf("%.7f\n%.7f\n%.7f\n%.7f\n",ans[0],ans[1],ans[2],ans[3]);

    return 0;

}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  int a[2][n];
  int sumu[n], sumd[n];
  rep(i, 2) rep(j, n) cin >> a[i][j];
  sumu[0] = a[0][0];
  sumd[n - 1] = a[1][n - 1];

  for (int i = 1; i < n; ++i) sumu[i] = a[0][i] + sumu[i - 1];
  for (int i = n - 2; i >= 0; --i) sumd[i] = a[1][i] + sumd[i + 1];

  int ans = -1;
  rep(i, n) ans = max(ans, sumu[i] + sumd[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let X: usize = sc.get();
    let T: usize = sc.get();
    println!("{}", (N+X-1)/X*T);
}


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

int main()
{
  int H,N;
  int a[110000];
  int res=0;
  cin >> H>>N;

  rep(i,N) cin >> a[i];

  rep(i,N){
    res += a[i];
  }
  if(res>=H) cout << "Yes" << endl;
  else cout << "No" <<endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define n_max 55


int get_distance(pair<int,int> a , pair<int ,int> b){
    return abs( a.first - b.first) + abs(a.second - b.second);
}


int main(){
    int n,m;
    cin >> n >> m;
    pair<int,int> stu[n_max],check[n_max];
    int x,y;
    REP(i,n){
        cin >>x >> y;
        stu[i] = make_pair(x,y);
    }
    REP(i,m){
        cin >> x >> y;
        check[i] = make_pair( x,y);
    }

    int ans;
    REP(i,n){
        ans=0;
        REP(j,m){
            if( get_distance(stu[i],check[j]) < get_distance(stu[i],check[ans]))ans = j;
        }
        cout << ans+1 << endl;
    }

}

Measured memory_bytes: 256
N=int(input())
P=int("".join(list(input().split())))
Q=int("".join(list(input().split())))

import itertools
A=[]
for i in range(1,N+1):
    A.append(i)

B=[]
for j in itertools.permutations(A,N):
    B.append(int("".join(map(str,j))))

p=0
q=0
for k in range(len(B)):
    if B[k]<P:
        p+=1
    if B[k]<Q:
        q+=1
print(abs(p-q))


Measured memory_bytes: 4728
#16:07
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
now = []
for i in range(n):
  j = raw[i][cnt[i]]
  if i < j and i == raw[j][cnt[j]]:
    now.append(i)
    now.append(j)
ans = 0
while now:
  ans += 1
  last = now
  now = []
  for x in last:
    cnt[x] += 1
    if cnt[x] < n-1:
      y = raw[x][cnt[x]]
      if x == raw[y][cnt[y]]:
        now.append(x)
        now.append(y)
  #print(now)
if cnt == [n-1 for _ in range(n)]:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 35060
def search(x, y, imap, acc):
  imap[x][y] = 0
  acc += 1
  ret = acc
  a = b = c = d = 0
  if imap[x - 1][y]:
    a = search(x - 1, y, imap, acc)
    if ret < a:
      ret = a
  if imap[x + 1][y]:
    b = search(x + 1, y, imap, acc)
    if ret < b:
      ret = b
  if imap[x][y - 1]:
    c = search(x, y - 1, imap, acc)
    if ret < c:
      ret = c
  if imap[x][y + 1]:
    d = search(x, y + 1, imap, acc)
    if ret < d:
      ret = d
  imap[x][y] = 1
  return ret
 

def solve():
  while True:
    m, n  = int(input()), int(input())
    if not m:
      break
    ices = [[0] + list(map(int,input().split())) + [0] for _ in range(n)]
    ices.insert(0, [0] * (m + 2),)
    ices.append([0] * (m + 2))
    score = [[0] * (m + 2) for _ in range(n + 2)]
    
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        score[x][y] = ices[x - 1][y] + ices[x + 1][y] + ices[x][y - 1] + ices[x][y + 1] 
   
    ans = 0
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        if score[x][y] in [1, 2] and ices[x][y]:
          a = search(x, y, ices, 0)
          if ans < a:
            ans = a
    
    print(ans)

solve()


Measured memory_bytes: 5812
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int conn = 0;
		int cmax = 0;
		for(int i = 0 ; i < N ; ++i){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == b){
				conn++;
				cmax = Math.max(cmax, conn);
			}else{
				conn = 0;
			}
		}
		if(cmax >= 3){
			System.out.println("Yes");
		}else{
			System.out.println("No");			
		}
	}
}


Measured memory_bytes: 36064
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);

        var aa = new char[n][];
        for (int i = 0; i < aa.Length; i++) {
            aa[i] = input.ReadLine().ToCharArray();
        }
        var bb = new char[m][];
        for (int i = 0; i < bb.Length; i++) {
            bb[i] = input.ReadLine().ToCharArray();
        }

        for(int ai=0; ai<n; ai++) {
            for(int aj=0; aj<n; aj++) {
                var ok = true;
                for (int bi = 0; bi < m; bi++) {
                    for (int bj = 0; bj < m; bj++) {
                        if(ai+bi >= n || aj+bj >= n) {
                            ok = false;
                            break;
                        }
                        ok &= aa[ai+bi][aj+bj] == bb[bi][bj];
                    }
                }
                if(ok) return Yes;
            }
        }

        return No;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
    static void SetArray<T>(T[] array, Func<T, int, T> f) {
        for (int i = 0; i < array.Length; i++)
            array[i] = f(array[i], i);
    }
    static void FillArray<T>(T[] array, T value) {
        for (int i = 0; i < array.Length; i++)
            array[i] = value;
    }
}


Measured memory_bytes: 11220
# include <cmath>
# include <iostream>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    int d, n;
    cin >> d >> n;

    int base = pow(100, d);
    int ans = base * n;

    if ((ans / (int)pow(100, d)) % 100 == 0) {
        ans = base * (n+1);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

bool is_bingo(vector<vector<int>> sheet){
    for(int i=0; i<3; i++){
        if(sheet[i][0] == 1 && sheet[i][1] == 1 && sheet[i][2])
        return true;
    }
    for(int i=0; i<3; i++){
        if(sheet[0][i] == 1 && sheet[1][i] == 1 && sheet[2][i])
        return true;
    }
    if(sheet[0][0] == 1 && sheet [1][1] == 1 && sheet[2][2] == 1)
        return true;
    else if(sheet[0][2] == 1 && sheet [1][1] == 1 && sheet[2][0] == 1)
        return true;
    else
        return false;
}

void solve(){
    
    vector<vector<int>> a(3, vector<int>(3));
    vector<vector<int>> sheet(3, vector<int>(3, 0));

    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++)
            cin >> a[i][j];
    }

    int n, ball;

    cin >> n;

    for(int k=0; k<n; k++){
        cin >> ball;
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(ball == a[i][j])
                    sheet[i][j] = 1;
            }
        }
    }

    // for(int i=0; i<3; i++){
    //     for(int j=0; j<3; j++)
    //         cout << a[i][j] << ' ';
    //     cout << endl;
    // }

    // for(int i=0; i<3; i++){
    //     for(int j=0; j<3; j++)
    //         cout << sheet[i][j] << ' ';
    //     cout << endl;
    // }
    if(is_bingo(sheet))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


Measured memory_bytes: 256