akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct Team{
  int id;
  int university;
  int solve;
  int penalty;

  Team(int i, int u, int s, int p) {
    id = i;
    university = u;
    solve = s;
    penalty = p;
  }
  bool operator < (const Team& o) const {
    if (solve != o.solve) return solve > o.solve;
    if (penalty != o.penalty) return penalty < o.penalty;
    return id < o.id;
  }
};

int main() {
  int n, i, u, a, p;
  while (cin >> n, n != 0) {
    vector<Team> v;
    for (int j = 0; j < n; j++) {
      cin >> i >> u >> a >> p;
      v.push_back(Team(i, u, a, p));
    }
    sort(v.begin(), v.end());
    
    int univ[n] = {}, cnt = 0;
    for (auto t : v) {
      int limit = cnt < 10 ? 3 : cnt < 20 ? 2 : cnt < 26 ? 1 : 0;
      if (univ[t.university] < limit) {
	cout << t.id << endl;
	univ[t.university]++;
	cnt++;
      }
    }
  } 
  return 0;
}


Measured memory_bytes: 3112
let rec solve (n, s) =
  let rec doit m = function
    | (0, 0) -> 1
    | (0, _) -> 0
    | (n, s) ->
      let rec aux i acc =
        if i > s || i > 9 then acc
        else acc + doit (i + 1) (n - 1, s - i) |> aux (i + 1) in
      aux m 0 in
  doit 0 (n, s)

let () =
  let rec main_loop () =
    let (n, s) = Scanf.scanf "%d %d " (fun n s -> n, s) in
    if n = 0 && s = 0 then ()
    else begin
      solve (n, s) |> Printf.printf "%d\n";
      main_loop ()
    end in
  main_loop ()

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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T>
using MaxHeap = priority_queue<T, vector<T>, less<T>>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline void input(vector<T> &vec) {
    for (auto &e: vec) {
        cin >> e;
    }
}

template <class T>
inline void input(vector<vector<T>> &mat) {
    for (auto &vec: mat) {
        input(vec);
    }
}

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

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

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

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, n, r);

    if (n >= 10) {
        print(r);
    } else {
        print(r + 100 * (10 - n));
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>

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

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main(){
    int n;
    string str;
    double val;
    cin >> n;
    long double ans = 0;
    rep(i,n){
        cin >> val >> str;
        //cout << val << str << endl;
        if(str == "JPY") ans += val;
        else{
            ans += 380000 * val;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// Problem : B - Roller Coaster
// Contest : AtCoder Beginner Contest 142
// URL : https://atcoder.jp/contests/abc142/tasks/abc142_b
// Memory Limit : 1024,000000 MB
// Time Limit : 2000,000000 milisec
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  cout.precision(16);
  cout << fixed;

  int n;
  int k;
  cin >> n >> k;

  int ans = 0;

  while (n--) {
    int t;
    cin >> t;

    ans += t >= k;
  }

  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
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; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  string s,t;cin>>s>>t;
  vector<int> a(s.size()+1,0),b(t.size()+1,0);
  rep(i,s.size()){
    a[i+1]=a[i]+(s[i]=='A'?1:2);
  }
  rep(i,t.size()){
    b[i+1]=b[i]+(t[i]=='A'?1:2);
  }
  int n;cin>>n;
  rep(i,n){
    int w,x,y,z;cin>>w>>x>>y>>z;
    if((a[x]-a[w-1])%3==(b[z]-b[y-1])%3)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}

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

int main() {
  int K;
  string S;
  cin >> K >> S;
  int n = S.size();
  if (K >= n) {
    cout << S << endl;
  }
  else {
    string t = S.at(0) + string();
    for (int i = 1; i < K; i++) {
      t += S.at(i);
    }
    t += "...";
    cout << t << endl;
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

ll cnt[26];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	int n=s.length();
	for(int i=0;i<n;i++)
	{
		cnt[s[i]-'a']++;
	}
	ll ans=1;
	for(int i=0;i<26;i++)
	{
		for(int j=i+1;j<26;j++)
		{	
			ans+=cnt[i]*cnt[j];
		}
	}
	cout<<ans<<'\n';
}


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

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

  int ans = 0;
  if (S[0]=='R') {
    ans++;
    if (S[1]=='R') {
      ans++;
      if (S[2]=='R') {
        ans++;
      }
    }
  } else {
    if (S[1]=='R') {
      ans++;
      if (S[2]=='R') {
        ans++;
      }
    } else {
      if (S[2]=='R') {
        ans++;
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}

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

int main() {
  
  int N,K;
  string S;
    cin>>N>>K>>S;
  K -=1;
if(S.at(K)=='A'){
  S.at(K)='a';
}
else if(S.at(K)=='B'){
  S.at(K)='b';
}
else if(S.at(K)=='C'){
  S.at(K)='c';
}
cout<<S<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

#n = int(input())
import sys

sys.setrecursionlimit(1000000)

h,W = [int(i) for i in input().split()]
#b = [i for i in input().split()]
board = []
for _ in range(h):
    board.append(input())

checked = [[0]*W for i in range(h)]

dx=[ 0, 1, 0,-1]
dy=[ 1, 0,-1, 0]

ans = 0

def dfs(x,y,b,w):
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
#        print(nx,ny)
#        print(checked)
        if nx < 0 or nx >= h or ny < 0 or ny >= W or checked[nx][ny]==1:
            continue
        if board[x][y] == board[nx][ny]:
            continue
#        print("ok")
        checked[nx][ny]=1
        if board[nx][ny] == '#':
            b+=1
        else:
            w+=1
        b1,w1 = dfs(nx, ny,0,0)
        b+=b1
        w+=w1
#    print(x,y,b,w)
    return b,w

#print(dfs(0,0,0,0))

for i in range(h):
    for j in range(W):
        if checked[i][j] == 1:
            continue
        checked[i][j] = 1
        if board[i][j] == '#':
            b2 = 1; w2=0
        else:
            b2 = 0; w2=1
        b1,w1 = dfs(i,j,b2,w2)
#        print(b1,w1)
        ans += b1*w1

print(ans)        
        

Measured memory_bytes: 153116
#include<bits/stdc++.h>
#define For(i, a, b)  for(int i = a, _b = b; i <= _b; ++i)
#define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i)
#define FileName      "test"
#define ll            long long
#define ld            long double
#define ull           unsigned long long
#define Print(x)      cerr << #x << "is " << x << '\n';
#define pb            push_back
#define X             first
#define Y             second
//#define Karma

using namespace std;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;

ll f[N][2];
int n, u, v;
vector<int> a[N];

void DFS(int u, int par)
{
    bool leaf = 1;
    for(int v: a[u])
    {
        if(v == par) continue;
        DFS(v, u);
        leaf = 0;
    }
    if(leaf) f[u][0] = f[u][1] = 1;
    else {
       int sz = a[u].size();
       f[u][0] = f[u][1] = 1;
       for(int i = 0; i < sz; ++i)
       {
           int v = a[u][i];
           if(v == par) continue;
           f[u][1] = (f[u][1] * f[v][0]) % mod;
           f[u][0] = ((f[v][1] + f[v][0]) % mod) * f[u][0] % mod;
       }
    }
}

void Enter()
{
     Cin(n);
     For(i, 2, n)
     {
         Cin(u, v);
         a[u].pb(v), a[v].pb(u);
     }
     DFS(1, 1);
     cout << (f[1][0] + f[1][1]) % mod;
}

void Solve()
{

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


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

int decode(int n){
	return (n/100)*60 + n%100;
}
int main(){
	int ch , from , to ;
	while(cin >> ch >> from >> to && (ch || from || to) ){
		from = decode(from);
		to = decode(to);
		vector<int> x,y;
		for(int i = 0 ; i < ch ; i++){
			int tmp; cin >> tmp;
			for(int j = 0 ; j < tmp ; j++){
				int s,t; cin >> s >> t;
				x.push_back(decode(s));
				y.push_back(decode(t));
			}
		}
		int mx = 0;
		int len = 0;
		for(int i = from ; i < to ; i++){
			int ok = 0;
			for(int j = 0 ; j < x.size() ; j++)
				ok += (x[j] <= i && i < y[j]);
			if(ok < ch)len++;
			else len = 0;
			mx = max(mx,len);
		}
		cout << mx << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
#include <list>

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")

using namespace std;

//ABC075B - Minesweeper
int Main() {
	static const char EMPTY = '.';
	static const char BOM = '#';
	int H = 0, W = 0;
	vector<vector<char>> S, ans;

	// build field
	scanf("%d", &H);
	scanf("%d", &W);
	S.resize(H);
	for (auto& s : S) {
		s.resize(W);
		for (auto& chip : s) {
			while ('\n' == (chip = getchar()));
		}
	}
	ans.resize(H);
	for (auto& s : ans)
		s.resize(W);

	// check field
#define BOMB_CHECK(y,x) (0 <= x && x < W && 0 <= y && y < H && '#' == S[y][x])
	for (int x = 0; x < W; x++) {
		for (int y = 0; y < H; y++) {
			if ('#' == S[y][x]) {
				ans[y][x] = '#';
				continue;
			}
			int bomNum =
				BOMB_CHECK(y, x) +
				BOMB_CHECK(y, x - 1) +
				BOMB_CHECK(y, x + 1) +
				BOMB_CHECK(y - 1, x) +
				BOMB_CHECK(y - 1, x - 1) +
				BOMB_CHECK(y - 1, x + 1) +
				BOMB_CHECK(y + 1, x) +
				BOMB_CHECK(y + 1, x - 1) +
				BOMB_CHECK(y + 1, x + 1);
			ans[y][x] = '0' + bomNum;
		}
	}

	// answer
	for (auto& line : ans) {
		for (auto& chip : line) {
			printf("%c", chip);
		}
		printf("\n");
	}

	return 0;
}


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

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

int main(){
    int N, K;
    cin >> N >> K;
    long long V[N];
    rep(i, N){
        cin >> V[i];
    }
    int M = min(N, K);
    priority_queue<long long, vector<long long>, greater<long long> > que[M+1][M+1];
    priority_queue<long long> ans;
    long long res[M+1][M+1];
    rep(i, M+1){
        rep(j, M-i+1){
            res[i][j] = 0;
            rep(k, i){
                que[i][j].push(V[k]);
            }
            rep2(k, N-j, N){
                que[i][j].push(V[k]);
            }
            int count = 0;
            while(!que[i][j].empty() && count < K-(i+j)){
                count++;
                if(que[i][j].top() < 0){
                    que[i][j].pop();
                }
                else break;
            }
            while(!que[i][j].empty()){
                res[i][j] += que[i][j].top();
                que[i][j].pop();
            }
            ans.push(res[i][j]);
        }
    }
    cout << ans.top() << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> s(N);
  rep(i,N) cin >> s[i];
  int sum = 0;
  rep(i,N) sum += s[i];
  if(sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }
  sort(s.begin(), s.end());

  rep(i,N){
    if(s[i]%10!=0){
      sum -= s[i];
      cout << sum << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


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

int main(){
  int H,R;
  cin >> H >> R;
  if (H+R > 0 ){
    cout << "1" << endl;
  }
 
  else if(H+R < 0){
    cout << "-1" << endl;
  }
  else if (H+R == 0){
    cout << "0" <<endl;
}
  return 0;
}

  



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
//for (int i = 0; i < N; i++){}
//for (int j = 0; j < M; j++){}

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

    for (int i = 1; 111*i <= 999; i++){
        if(N<=111*i){
            cout << 111*i << endl;
            break;
        }else{
            continue;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]H = new int[N];
    
    int see = 0;
    int cou = 0;
    for(int i=0; i<N; i++) {		
    	H[i] = sc.nextInt();
    	if(H[i] >= see) {
     		cou++;
    		see = H[i]; 
    	}		
    }
         System.out.println(cou);        
      }
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int K;
	cin >> K;

	bool ans = false;
	rep(i, K) {
		if(A >= B) B *= 2;
		else if(B >= C) C *= 2;

		if(A < B && B < C) {
			ans = true;
			break;
		}
	}

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

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int r;
	cin >> r;
	float res = 2*PI*r;
	cout << fixed << setprecision(15) << res << endl;	
	return 0;
}



Measured memory_bytes: 3808
A,B,K = map(int,input().split())
for i in range(K):
  if i%2 == 0:
    if A%2 == 1:
      A -=1
      X = A/2
      A -= X
      B += X
    else:
      X = A/2
      A -= X
      B += X
  else:
    if B%2 == 1:
      B -=1
      X = B/2
      B -= X
      A += X
    else:
      X = B/2
      B -= X
      A += X
print(int(A),int(B))

Measured memory_bytes: 9236
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) x.begin(),x.end()
#define endl '\n'

#ifndef ONLINE_JUDGE
template<typename T>		
void __p(T a) {
  cerr<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cerr<<"[";
  __p(a.first);
  cerr<<",";
  __p(a.second);
  cerr<<"]";
}
template<typename T>
void __p(std::vector<T> a) {
  cerr<<"[";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cerr<<",]"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr<<name<<" : ";
  __p(arg1);
  cerr<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cerr.write(names,comma-names)<<" : ";
  __p(arg1);
  cerr<<" | ";
  __f(comma+1,args...);
}
#define trace(...) cerr<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#endif

void test_case(){
	int n,W;
	cin>>n>>W;
	vector<pair<int,int>> wv(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>wv[i].first>>wv[i].second;
		sum+=wv[i].first;
	}
	sort(all(wv));
	vector<vector<int>> dp(W+1, vector<int> (n+1));
	for(int i=1;i<=W;i++){
		dp[i][0]=0;
	}
	for(int i=1;i<=W;i++){
		for(int k=1;k<=n;k++){
			if(i-wv[k-1].first>=0){
				dp[i][k]=max(dp[i-wv[k-1].first][k-1]+wv[k-1].second,dp[i][k-1]);
			}
			else{
				dp[i][k]=dp[i][k-1];
			}
		}
	}
	cout<<dp[W][n];
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 
    int T=1;
    //cin>>T;
    for(int TT=1; TT<=T; TT++){
        test_case();
    }

    cerr<<endl<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

    return 0;
}


Measured memory_bytes: 85224
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <utility>
#include <vector>

int main() {
  std::stack<int> s1;
  std::stack<std::pair<int, int> > s2;
  char str[20000];
  int A = 0;
  std::scanf("%s", str);
  for (int i = 0; i < std::strlen(str); ++i) {
    if (str[i] == '\\') {
      s1.push(i);
    }
    else if (!s1.empty() && str[i] == '/') {
      int j = s1.top();
      s1.pop();
      int L = i - j;
      A += L;
      while (!s2.empty() && s2.top().first > j) {
        L += s2.top().second;
        s2.pop();
      }
      s2.push(std::make_pair(j, L));
    }
  }
  std::vector<int> v;
  v.reserve(s2.size());
  while (!s2.empty()) {
    v.push_back(s2.top().second);
    s2.pop();
  }
  std::printf("%d\n", A);
  std::printf("%d", (int)v.size());
  for (int i = (int)v.size() - 1; i >= 0; --i)
    std::printf(" %d", v[i]);
  std::printf("\n");
  return 0;
}



Measured memory_bytes: 2808
#include<bits/stdc++.h>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pair<int,int> >

using namespace std;
typedef long long ll;

const int maxn = 100005;

int dp[3][maxn];

int n;

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        int a,b,c;
        scanf("%d %d %d", &a, &b, &c);
        if(i == 0){
            dp[0][i] = a; dp[1][i] = b; dp[2][i] = c;
        }
        else{
            dp[0][i] = a + max(dp[1][i-1],dp[2][i-1]);
            dp[1][i] = b + max(dp[0][i-1],dp[2][i-1]);
            dp[2][i] = c + max(dp[1][i-1],dp[0][i-1]);
        }
    }

    printf("%d", max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])));
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#define INF 10000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll d[300][300];
signed main(){
  ll n,m,l,q,s,t,ans;
  cin >> n >> m >>l;
  ll a,b,c,en,tmp;
  P ptmp;
  vector<P> G[300];
  fill(d[0],d[300],INF);
  for(int i=0;i<m;i++){
    cin >> a >> b >> c;
    a--; b--;
    d[a][b]=c;
    d[b][a]=c;
  }
  for(int i=0;i<n;i++){
    d[i][i]=0;
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(d[i][j]<=l){
        d[i][j]=1;
        d[j][i]=1;
      }else{
        d[i][j]=INF;
        d[j][i]=INF;
      }
    }
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> s >> t;
    s--;
    t--;
    if(d[s][t]==INF){
      cout <<"-1\n";
    }else{
      cout << d[s][t]-1 << endl;
    }
  }
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void cmpmax(T& reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void cmpmin(T& reference, T value) {
	reference = min(reference, value);
}

const ll mod = 1000000007;

static const ll INF = 1e15;

unordered_map<ll, ll> costs;
ll a, b, c, d;

ll dfs(ll current) {
	if (current == 0) return 0;
	if (current == 1) return d;
	if (costs.count(current)) {
		return costs[current];
	}
	ll minCosts = 1e18;
	if (current < minCosts / d) {
		minCosts = d * current;
	}
	{
		ll div = current / 5;
		ll m = current - div * 5;
		auto a1 = dfs(div) + c + d * (m);
		minCosts = min(minCosts, a1);
		if (m) {
			a1 = dfs(div+1) + c + d * (- m + 5);
			minCosts = min(minCosts, a1);
		}
	}
	{
		ll div = current / 3;
		ll m = current - div * 3;
		auto a1 = dfs(div) + b + d * (m);
		minCosts = min(minCosts, a1);
		if (m) {
			a1 = dfs(div+1) + b + d * (-m + 3);
			minCosts = min(minCosts, a1);
		}
	}
	{
		ll div = current / 2;
		ll m = current - div * 2;
		auto a1 = dfs(div) + a + d * (m);
		minCosts = min(minCosts, a1);
		if (m) {
			a1 = dfs(div+1) + a + d;
			minCosts = min(minCosts, a1);
		}
	}
	costs[current] = minCosts;
	return minCosts;
}


int main() {
	ll t;
	cin >> t;
	vector<ll> ns;
	rep(_, t) {
		ll n;
		cin >> n >> a >> b >> c >> d;
		ll mc = 1LL << 62;
		costs.clear();
		auto c = dfs(n);
		ns.push_back(c);
	}
	for (auto p : ns) {
		cout << p << endl;
	}
	return 0;
}



Measured memory_bytes: 4080
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define re register
#define rep(i,s,t) for(re int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define pt(x) putchar(x)
#define pti(x) printf("%d",x)
#define ptll(x) printf("%lld",x)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
using namespace std;
il int ci(){
	re char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	re int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}
int main(){
	int m1=ci(); ci();
	int m2=ci(); ci();
	if( m1!=m2 ) puts("1");
	else puts("0");
	return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vll b(n);
    rep(i, n) b[i] = a[i] - (i+1);
    VSORT(b);
    ll sub = 0;
    if (n%2==0) sub = (b[n/2] + b[n/2-1]) / 2;
    else sub = b[n/2];
    ll ans = 0;
    rep(i, n) ans += llabs(b[i] - sub);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

const int mod = 1000000007;
int add(int a, int b) { return (a += b) < mod? a : a - mod; }
int sub(int a, int b) { return (a -= b) >=  0? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int& a, int b) { a = add(a, b); }
void subs(int& a, int b) { a = sub(a, b); }
void muls(int& a, int b) { a = mul(a, b); }
void maxs(int& a, int b) { a = max(a, b); }
void mins(int& a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(a, pwr(a, p - 1));
    return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }
const int maxn = 1000000;
int f[maxn + 1], fi[maxn + 1];
int ncr(int n, int r) { return mul(f[n], mul(fi[r], fi[n - r])); }

void precompute()
{
    f[0] = 1;
    for (int i = 1; i <= maxn; ++i)
        f[i] = mul(f[i - 1], i);

    fi[maxn] = inv(f[maxn]);
    for (int i = maxn - 1; i >= 0; --i)
        fi[i] = mul(fi[i + 1], i + 1);
}

int main()
{
    ll n, m;
    cin >> n >> m;
    map<int, int> mp;
    for (ll i = 2; i * i <= m; ++i)
        while (m % i == 0)
            mp[i]++, m /= i;

    if (m != 1)
        mp[m]++;
    
    precompute();
    int sol = 1;
    for (auto it = mp.begin(); it != mp.end(); ++it)
        muls(sol, ncr(it->second + n - 1, n - 1));
    cout << sol;
}


Measured memory_bytes: 8064
#include<stdio.h>

int main()
{
   int a,b,c,count=0,i;
   scanf("%d%d%d",&a,&b,&c);
   for(i=a;i<=b;i++)
   {
       if(c%i==0)
       count++;
   }
   printf("%d\n",count);

}



Measured memory_bytes: 2136
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 15
#define MAXS 50000
#define MO 1000000007
using namespace std;
int n,m,all;
int cnt[MAXN+5][MAXS+5],p[MAXN+5][MAXS+5];
int dp[MAXS+5];
bool legal[MAXS+5];
int PowMod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)
			ret=1LL*ret*a%MO;
		a=1LL*a*a%MO;
		b>>=1;
	}
	return ret;
}
int LowBit(int i)
{
	return i&(-i);
}
int main()
{
	scanf("%d %d",&n,&m);
	all=1<<n;
	int  u,v;
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d",&u,&v);
		cnt[u][1<<(v-1)]=1;
	}
	for(int i=1;i<=n;i++)
		for(int s=1;s<all;s++)
		{
			int k=LowBit(s);
			cnt[i][s]=cnt[i][s-k]+cnt[i][k];
			p[i][s]=(1<<cnt[i][s])-1;
		}
	for(int s=0;s<all;s++)
		if((s&1)==((s&2)/2))
			legal[s]=true;
	dp[0]=1;
	for(int s=1;s<all;s++)
		if(legal[s])
		{
			dp[s]=1;
			for(int t=((s-1)&s);t;t=((t-1)&s))
				if(legal[t])
				{
					int res=s-t,add=dp[res];
					for(int i=0;i<n;i++)
						if((1<<i)&res)
							add=1LL*add*p[i+1][t]%MO;
						else if((1<<i)&t)
							add=1LL*add*(1LL<<cnt[i+1][res])%MO;
					dp[s]=(1LL*dp[s]+1LL*add)%MO;
				}
		}
	int ans=PowMod(2,m);
	ans=((1LL*ans-1LL*dp[all-1])+MO)%MO;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6272
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=100005;
int n,m,cnt,h[N],siz[N],fa[N],dep[N],x,y,a[N];
struct edge{int v,n;} e[N<<1];
typedef long long LL;
LL ans;

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

void addedge(int u,int v)
{
	e[cnt]=(edge){v,h[u]},h[u]=cnt++;
	e[cnt]=(edge){u,h[v]},h[v]=cnt++;
}

void dfs(int x,int f,int tp)
{
	siz[x]=tp,dep[x]=dep[f]+1,fa[x]=f;
	for(int i=h[x]; i!=-1; i=e[i].n)
		if(e[i].v!=f)
		{
			if(dep[e[i].v]) ::x=e[i].v,y=x;
			else dfs(e[i].v,x,-tp),siz[x]+=siz[e[i].v];
		}
}

int main()
{
	n=getint(),m=getint();
	memset(h,-1,sizeof(h));
	rep(i,1,m) addedge(getint(),getint());
	dfs(1,0,1);
	if(m==n-1)
	{
		if(siz[1]) return puts("-1"),0;
		rep(i,1,n) ans+=abs(siz[i]);
		return printf("%lld\n",ans),0;
	}
	if((dep[x]^dep[y])&1)
	{
		if(siz[1]) return puts("-1"),0;
		rep(i,1,n) ans+=abs(siz[i]);
		*a=1;
		while(x!=y) dep[x]>dep[y]?(a[++*a]=siz[x],ans-=abs(siz[x]),x=fa[x]):(a[++*a]=-siz[y],ans-=abs(siz[y]),y=fa[y]);
		int mid=(*a)+1>>1;
		nth_element(a+1,a+mid,a+1+*a);
		rep(i,1,*a) ans+=abs(a[i]-a[mid]);
		printf("%lld\n",ans);
	}
	else
	{
		if(siz[1]&1) return puts("-1"),0;
		int c=siz[1]>>1;
		ans=abs(c);
		while(x) siz[x]-=c,x=fa[x];
		while(y) siz[y]-=c,y=fa[y];
		rep(i,1,n) ans+=abs(siz[i]);
		printf("%lld\n",ans);
	}
	return 0;
}

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e;i++)
#define pb push_back
#define fst first
#define snd second

typedef long long ll;

const int N = 2e5;
ll a[N], n, dp[N][2];

ll calc(int i, int j) {
    if(i == n) return 0;
    ll &r = dp[i][j];
    if(r != -1e18) return r;
    ll res;
    if(i < n - 1) {
        if(j) res = max(a[i] + calc(i + 1, 1), -a[i] + calc(i + 1, 0));
        else res = max(-a[i] + calc(i + 1, 1), a[i] + calc(i + 1, 0));
    } else {
        if(j) res = -a[i] + calc(i + 1, j);
        else res = a[i] + calc(i + 1, j);
    }
    // cout << i << " " << j << " " << res << endl;
    return r = res;
}
int main() {
    cin >> n;
    fore(i, 0, n) cin >> a[i];
    fore(i, 0, n) fore(j, 0, 2) dp[i][j] = -1e18;
    cout << calc(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
	vector<string> C(2, "");
	for(int i=0; i<C.size(); i++)
		cin >> C[i];

	reverse(C[0].begin(), C[0].end());

	string ret = "NO";
	if(C[0] == C[1])
		ret = "YES";

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(T a){
	cout << a << '\n';
}
ll n,a,b;

int main(){
	g(a); g(b);
	for(int i=1;i<=3000;i++){
		int x = (i*8)/100;
		int y = (i*10)/100;
		
		if(a == x && b == y){
			o(i); return 0;
		}
	}
	o(-1);
}

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

//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back


const int N = 2e5 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

//gp_hash_table<int, int> table;

int a[N], dp[3000][3000];
bool ok[3000][3000];

int rec (int l, int r, int who) {
    if (l > r) return 0;

    if (ok[l][r]) return dp[l][r];

    ok[l][r] = 1;

    if (!who) dp[l][r] = max(rec(l + 1,  r, 1) + a[l], rec(l, r - 1, 1) + a[r]);
    else dp[l][r] = min(rec(l + 1, r, 0) - a[l], rec(l, r - 1, 0) - a[r]);
    return dp[l][r];
}

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << rec(0, n - 1, 0);
}


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

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

	int digit = n % 10;
	if (digit == 2 || digit == 4 || digit == 5 || digit == 7 || digit == 9) {
		cout << "hon";
	}
	else if (digit == 0 || digit == 1 || digit == 6 || digit == 8) {
		cout << "pon";
	}
	else {
		cout << "bon";
	}

}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif
	solve();
	return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc_163b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int days = int.Parse(input[0]);
            string[] homework = Console.ReadLine().Split(' ');
            int[] hwdays = new int[int.Parse(input[1])];
            for(int i=0;i<int.Parse(input[1]); i++)
            {
                hwdays[i] = int.Parse(homework[i]);

                days -= hwdays[i];
            }

            if(days >= 0)
            {
                Console.WriteLine(days);
            }
            else
            {
                Console.WriteLine(-1);
            }

            Console.Read();
             
        }
    }
}


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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int a, b, k;
    cin>>a>>b>>k;
    int cnt = 0;
    for (int i = min(a, b); i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            cnt++;
            if(cnt==k){
                cout<<i<<endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    vector<int> v[n*n];
    int a[n][n-1];
    rep(i,0,n){
        rep(j,0,n-1){
            cin>>a[i][j];
            a[i][j]--;
            if(j>0){
                int pa=a[i][j-1];
                int np=i;
                if(np>pa)swap(np,pa);
                int paa=a[i][j];
                int nnp=i;
                if(nnp>paa)swap(nnp,paa);
                v[pa*n+np].push_back(paa*n+nnp);
            }
        }
    }
    int cnt[n*n];
    fill(cnt,cnt+n*n,0);
    int ans=0;
    rep(i,0,n*n){
        rep(j,0,v[i].size()){
            cnt[v[i][j]]++;
        }
    }
    queue<int> q;
    int d[n*n];
    fill(d,d+n*n,-1);
    rep(i,0,n*n){
        int x=i/n,y=i%n;
        if(x<=y)continue;
        if(cnt[i]==0){
            q.push(i);
            d[i]=1;
        }
    }
    int sum=0;
    while(q.size()>0){
        int now=q.front();q.pop();
        Max(ans,d[now]);
        sum++;
        rep(i,0,v[now].size()){
            int ne=v[now][i];
            cnt[ne]--;
            if(cnt[ne]==0){
                q.push(ne);
                d[ne]=d[now]+1;
            }
        }
    }
    if(sum<n*(n-1)/2)cout<<-1<<endl;
    else cout<<ans<<endl;
}










Measured memory_bytes: 51072
// Single Shortest Path II
// 問題URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B&lang=jp
// 中央*右
// 
// Vの数が多くFloyd-Warsallでは厳しい...のでBellman-Ford法で解きました。
// ネガティブサイクルの検知がよく分からなかったのですが、あえてV周目のループを回すという方法を下記を参考に実装しました。
// https://www.dyclassroom.com/graph/detecting-negative-cycle-using-bellman-ford-algorithm

#include <iostream>

using namespace std;

int V, E, R, S[2000+5], T[2000+5], D[2000+5];
int C[1000+5]; // 各頂点までの最短距離の上限
const int inf = 1001001001;

void solve(){
    bool update;

    for(int i = 0; i <= V; i++){
        update = false;
        for(int j = 0; j < E; j++){
            int s=S[j], t=T[j], d=D[j];
            if(C[s] < inf && C[s]+d < C[t]){
                // printf("C[%d]: %d to %d\n",t,C[t],C[s]);
                C[t] = C[s]+d;
                update = true;
            }
        }
    }
    if(update){//もしV周目で更新があれば、ネガティブサイクルが存在する
            cout << "NEGATIVE CYCLE" << endl;
    }else{
        for(int i = 0; i < V; i++) {
            if(C[i]==inf) cout << "INF" << endl;
            else cout << C[i] << endl;
        }
    }
}

int main(){
    cin >> V >> E >> R;
    
    fill(C,C+V,inf);
    C[R] = 0;

    for(int i = 0; i < E; i++){
        cin >> S[i] >> T[i] >> D[i];
    }

    solve();
}



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

int main(void){
    int h, w;
    cin >> h >> w;

    for(int i = 0; i < 2*h; i++){
        string s;
        cin >> s;

        cout << s << endl;
        cout << s << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(ll i=j;i<k;i+=in)
#define DF(i,j,k,in) for(ll i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); it++)
#define fitr(it,it1,itr2,in) for(auto it=itr1;it!=itr2;it+=in)
#define Dfeach(it,l) for (auto it = l.end()-1; it != l.begin()-1; it--)
#define Dfitr(it,it1,itr2,in) for(auto it=itr1;it!=itr2-1;it-=in)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ins insert
#define mkp make_pair
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,k;
cin>>n;
vll dp(3);
vll pdp(3);
vll mac(3);
bool flag=false;
bool flag1=false;
F(i,0,n,1){
    F(j,0,3,1){
        cin>>mac[j];
    }
    if(!flag){pdp[0]=mac[0]; pdp[1]=mac[1]; pdp[2]=mac[2]; flag=true;
    dp[0]=mac[0]; dp[1]=mac[1]; dp[2]=mac[2]; flag=true;
    }
    if(flag1){
    F(p,0,3,1){
        F(q,0,3,1){
            if(p!=q) dp[p]=max(dp[p],pdp[q]+mac[p]);
        }
    }
    pdp[0]=dp[0],pdp[1]=dp[1],pdp[2]=dp[2];
    }
    else flag1=true;
}
dp[0]=dp[0]>dp[1]?dp[0]:dp[1];
cout<<max(dp[0],dp[2])<<endl;
return 0;
}


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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

string S;

int main(){
    cin >> S;
    string ans;
    if(S=="Sunny")ans="Cloudy";
    else if(S=="Cloudy")ans="Rainy";
    else if(S=="Rainy")ans="Sunny";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.awt.geom.*;
import java.io.*;
import java.util.*;

public class Main {
	
	private void doit(){
		InStream sc = new InStream();
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			char [] s = sc.next().toCharArray();
			
			long B = 1000000007L;
			long [] bb = new long[n];
			bb[0] = 1L;
			for(int i = 0 ; i < n-1; i++){
				bb[i+1] = bb[i] * B;
			}
			long B1 = 1L;
			long tmp = B;
			// c^(-1)=c^(2^63-1) らしい
			for(int i =0; i < 63; i++){
				B1 *= tmp;
				tmp *= tmp;
			}
			int right = 0, left = 0;
			long now = s[0];
			HashSet<Long> set = new HashSet<Long>();
			for(int i = 0; i < m; i++){
				String op = sc.next();
				if(op.charAt(0) == 'R'){
					if(op.charAt(1) == '+'){
						right++;
						long temp = (long)s[right] * bb[right - left];
						now = now + temp;
					}
					else{
						long temp = (long)s[right] * bb[right - left];
						now = now - temp;
						right--;
					}
				}
				else{
					if(op.charAt(1) == '+'){
						now = now - s[left];
						now = now  * B1;
						left++;
					}
					else{
						now = now * B;
						left--;
						now = now + s[left];
					}
				}
				set.add(now);
			}
			System.out.println(set.size());
		}
	}
	
	class InStream{
		BufferedReader in;StringTokenizer st;
		public InStream() {
			this.in = new BufferedReader(new InputStreamReader(System.in));
			this.st = null;
		}
		String next() {
			while (st==null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (Exception e) {}
			}
			return st.nextToken(); 
		}
		boolean hasNext(){
			try {
				st = new StringTokenizer(in.readLine());
				return true;
			} catch (Exception e) {return false;}
		}
		int nextInt() {	return Integer.parseInt(next()); }
		long nextLong() {return Long.parseLong(next());	}
		double nextDouble() {return Double.parseDouble(next());	}
	}
	
	public static void main(String [] args){
		new Main().doit();
	}
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string cards[3];
    cin >> cards[0] >> cards[1] >> cards[2];

    int cnt[3] = {0}, now = 0;
    while(true){
        if(cnt[now] == cards[now].size()){
            cout << (char)(now + 65) << endl;
            break;
        }

        char card = cards[now][cnt[now]];
        ++ cnt[now];
        if(card == 'a') now = 0;
        else if(card == 'b') now = 1;
        else if(card == 'c') now = 2;
    }
}


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

using namespace std;

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

int main(int argc, char const *argv[]) {
	int ans = 0;
	string str;
	std::cin >> str;
	for (size_t i = 0; i < str.size(); i++) {
		if (str[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}
	std::cout << ans << '\n';
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int gcd(int a, int b)
{
    int r = a % b;
    if (r == 0)
    {
        return b;
    }
    return gcd(b, r);
}

int main()
{
    int a, b;
    cin >> a >> b;

    if (a < b)
        swap(a, b);

    OP(gcd(a, b))
    return 0;
}


Measured memory_bytes: 3092