akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
	int N;
	cin>>N;
	vector<int>A(N);
	vector<int>B(N);
	rep(i,N){
		cin>>A[i];
		B[i]=A[i];
	}
	sort(B.begin(),B.end());
	rep(i,N){
		if(A[i]==B[N-1]){
			cout<<B[N-2]<<endl;
		}
		else{
			cout<<B[N-1]<<endl;
		}
	}
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  ll goal = 0;
  for (int i = 2; i < n; i++) goal = (goal ^ a.at(i));
  
  ll sum = a.at(0) + a.at(1);
  if (sum < goal || sum % 2 != goal % 2) {
    cout << -1 << '\n';
    return 0;
  }
  
  ll now = (sum - goal) / 2; // Mt. No.2
  vector<ll> x;
  x.emplace_back(now);
  for (int bit = 60; bit >= 0; bit--) {
    //if (now > a.at(1)) break;
    if ((1LL << bit) & goal) {
      if ((now + (1LL << bit)) >= a.at(1)) x.emplace_back(now + (1LL << bit));
      else now += (1LL << bit);
    }
  }
  
  //for (int i = 0; i < x.size(); i++) cout << x[i] << endl;
  
  sort(x.begin(), x.end());
  if (x.back() < a.at(1)) {
    cout << -1 << endl;
    return 0;
  }
  ll new2 = *lower_bound(x.begin(), x.end(), a.at(1));
  if (new2 == a.at(0) + a.at(1)) {
    cout << -1 << endl;
    return 0;
  }
  
  ll sum2 = (new2 ^ (a.at(0) - (new2 - a.at(1))));
  for (int i = 2; i < n; i++) {
    sum2 = (sum2 ^ a.at(i));
  }
  if (sum2 != 0) {
    cout << -1 << '\n';
    return 0;
  }
  if (new2 - a.at(1) >= 0) cout << new2 - a.at(1) << '\n';
  else cout << -1 << '\n';
}

Measured memory_bytes: 3572
def check_winner(N, M):
    if N == M:
        return "Yes"
    return "No"

if __name__ == "__main__":
    test1 = "3 3"
    test2 = "3 2"
    test3 = "5 0"
    test = test3
    test_input = map(int, input().split())
    print(check_winner(*test_input))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int a[100100];

int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i];
	
	int ans=1;
	int flag=0;
	for(int i=0;i<n-1;i++){
		if(flag==0){
			if(a[i]<a[i+1]){
				flag=1;
			}else if(a[i]>a[i+1]){
				flag=-1;
			}else{
				flag=0;
			}
		}else if(flag==1){
			if(a[i]>a[i+1]){
				ans++;
				flag=0;
				//cout<<i<<endl;
			}
		}else if(flag==-1){
			if(a[i]<a[i+1]){
				ans++;
				flag=0;
				//cout<<i<<endl;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long X, long long Y){
    for (long long i = 0; i <= X; i++) {
        long long sum = i * 2 + (X -i) * 4;
        if (sum == Y) {
            cout << "Yes" << endl;
            return;
        }

    }
    cout << "No" << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 3680
import java.io.*;
import java.util.*;

public class Main{

	static int MOD=(int)1e9+7;
	static PrintWriter out=new PrintWriter(System.out);;
	static int [][]memo;
	static int n,m;
	static char [][]grid;
	static boolean valid(int i,int j) {
		return i>=0 && i<n && j>=0 && j<m && grid[i][j]=='.';
	}
	static int dp(int i,int j) {
		if(!valid(i,j))
			return 0;
		if(i==n-1 && j==m-1)
			return 1;
		if(memo[i][j]!=-1)
			return memo[i][j];
		int ans=dp(i+1,j)+dp(i,j+1);
		if(ans>=MOD)
			ans-=MOD;
		return memo[i][j]=ans;
		
	}
	
		
		
	
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		
		n=sc.nextInt();
		m=sc.nextInt();
		grid=new char[n][m];
		memo=new int [n][m];
		for(int i=0;i<n;i++)
			grid[i]=sc.next().toCharArray();
		for(int []a:memo)
			Arrays.fill(a, -1);
		out.println(dp(0,0));
		
		out.close();

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


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

#define int long long
int start[100005], end[100005];
//int times[100005];
int n,m;

signed main(void){
	ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.inp","r",stdin);
	cin>>n>>m;
	int from,to;
	cin>>to;
	for (int i=0; i<m-1; i++){
		from=to;
		cin>>to;
		start[i]=min(from-1,to-1);
		end[i]=max(from-1,to-1);
	}
	sort(start,start+m-1);
	sort(end,end+m-1);
	int pts=0,pte=0;
	int cur=0;
	int real_cost=0;
	for (int i=0; i<n-1; i++){
		int cost1,cost2,cost3;
		while (i==start[pts]&&pts<m-1){
			cur++;
			pts++;
		}
		while (i==end[pte]&&pte<m-1){
			cur--;
			pte++;
		}
		cin>>cost1>>cost2>>cost3;
		real_cost+=min(cur*cost1,cost3+cur*cost2);
	}
	cout<<real_cost<<endl;
	return 0;
}

Measured memory_bytes: 4664
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

LL H,W;

LL solve();

int main(){

    cin>>H>>W;

    cout<<solve()<<endl;
}

LL solve(){

    LL h;//縦の幅
    LL w;//横の幅
    LL Sa=0,Sb=0,Sc=0,Smin=0,Smax=0,Sdelta=__LONG_LONG_MAX__;
    
    //最初に横に割る
    for(h=1;h<H;h++){
        Sa=W*h;//ひとつ目の面積

        //次に縦に割る
        {
             w=W/2;
             Sb=(H-h)*w;
             Sc=(H-h)*(W-w);
             Smin=min(Sa,min(Sb,Sc));
             Smax=max(Sa,max(Sb,Sc));
             Sdelta=min(Sdelta,Smax-Smin);
        }
        //横に割る
        {
            LL h2=(H-h)/2;
            Sb=W*(h2);
            Sc=W*(H-h-h2);
             Smin=min(Sa,min(Sb,Sc));
             Smax=max(Sa,max(Sb,Sc));
             Sdelta=min(Sdelta,Smax-Smin);
        }
    }

    //最初に縦に割る
    for(w=1;w<W;w++){
        Sa=H*w;
        //次に縦に割る
        {
            h=H/2;
            Sb=(W-w)*h;
            Sc=(W-w)*(H-h);
             Smin=min(Sa,min(Sb,Sc));
             Smax=max(Sa,max(Sb,Sc));
             Sdelta=min(Sdelta,Smax-Smin);
        }

        //次に横に割る
        {
            LL w2=(W-w)/2;
            Sb=H*w2;
            Sc=H*(W-w-w2);
             Smin=min(Sa,min(Sb,Sc));
             Smax=max(Sa,max(Sb,Sc));
             Sdelta=min(Sdelta,Smax-Smin);

        }
    }


    return Sdelta;
}

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

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

ll dist[100001];
ll INF = 1001001001001;

struct Info {
  int to = -1; 
  ll d = -1;
  Info() {} 
  Info(int to, ll d): to(to), d(d) {}
};

bool bfs(vector<vector<Info>>& infos) {
  queue<int> q;
  int n = infos.size();
  for (int i = 0; i < n; ++i) {
    if (dist[i] != INF) continue;
    dist[i] = 0;
    q.push(i);
    while (!q.empty()) {
      int from = q.front(); q.pop();
      for (Info &info: infos[from]) {
        int to = info.to;
        // cerr << from << " " << to << " " << info.d << endl;
        if (dist[to] == INF) {
          dist[to] = dist[from] + info.d;
          q.push(to);
        }
        else {
          if (dist[to] != dist[from] + info.d) return false;
        }
      }
    }
  }
  return true;
}

int main() {
  ll n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    dist[i] = INF;
  }
  vector<vector<Info>> infos(n);
  for (int i = 0; i < m; ++i) {
    int l, r;
    ll d;
    cin >> l >> r >> d;
    --l; --r;
    infos[r].emplace_back(l, d);
    infos[l].emplace_back(r, -d);
  }
  bool ans =bfs(infos);
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int p[200005];
int r[200005];
int dp[200005];
int n;

int dfs(int i) {
    if(dp[i] != 0) return dp[i];
    if(p[i] == n-1) return dp[i] = 1;
    if(i == n-1) return dp[i] = 1;
    if(r[p[i]+1] < i){
        return dp[i] = 1;
    }else{
        return dp[i] = dfs(r[p[i]+1])+1;
    }
}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    cin >> n;
    inc(i, 0, n){
        cin >> p[i];
        p[i]--;
        r[p[i]] = i;
    }
    //inc(i, 0, n){
        //cout << p[i];
    //}
    //cout << endl;

    int mx = 0;
    inc(i, 0, n){
        mx = max(mx, dfs(i));
    }
    cout << n-mx << endl;
    return 0;
}


Measured memory_bytes: 5760
import sys
n = [int(i) for i in input().split()]
a = []
for i in range(n[1]):
    a.append(int(input()))

a.append(n[0]+1)
a = sorted(list(set(a)))


def k(i):
    ans = 1
    pri = 0
    for idx in range(i):
        tmp = ans
        ans += pri
        pri = tmp
    return ans


for i in range(1, len(a)):
    if a[i]-a[i-1] == 1:
        print(0)
        sys.exit()
j = -1
ans = 1
for i in a:
    ii = i-j-2
    ans = ans*k(ii)
    j = i
if len(a) == 1:
    ans = k(n[0])
print(ans % 1000000007)


Measured memory_bytes: 58072
sub f{my$x=$_;$p=0;$p=$M[$x]+=$-=($M[$_]||&f)+1-$M[$x]for@$x;$p}
<>;
/ /,push@{$`},$'+0for<>;
map{$M[$_]or$\+=$-=&f-$\}1..1e5;print

Measured memory_bytes: 107008
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b,c,d,e,ans=5;
	cin>>n>>a>>b>>c>>d>>e;
	long long mn=min(a,min(b,min(c,min(d,e))));
	n-=mn;
	if(n<=0)
	{
		cout<<ans;
		return 0;
	}
	if(n%mn==0)
	ans+=n/mn;
	else
	ans+=(n/mn+1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

const INF = 1<<30

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n,m := input.NextInts()
  g := make([][]int,n)
  for i:=0;i<m;i++ {
    a,b := input.NextInts()
    g[a-1] = append(g[a-1],b-1)
  }
  state := make([]int,n)
  stack := []int{}
  var dfs func(int) bool
  dfs = func(v int) bool {
    if state[v] != 0 {
      if state[v] == -1 { return false }
      for i:=0;i<len(stack);i++ {
        if stack[i] == v {
          stack = stack[i:]
          return true
        }
      }
      stack = []int{}
      return true
    }
    stack = append(stack,v)
    state[v] = 1
    for _,u := range g[v] {
      if dfs(u) { return true }
    }
    state[v] = -1
    stack = stack[:len(stack)-1]
    return false
  }
  solve := func() {
    nxt := make([]int,n)
    vis := make([]bool,n)
    del := make([]bool,n)
    for i:=0;i<n;i++ { del[i] = true }
    for i:=0;i<len(stack);i++ {
      v := stack[i]
      u := stack[(i+1)%len(stack)]
      nxt[v] = u
      del[v] = false
    }
    v := stack[0]
    for !vis[v] {
      for _,u := range g[v] {
        if del[u] { continue }
        for w:=v;nxt[w]!=u; {
          w = nxt[w]
          del[w] = true
        }
        nxt[v] = u
      }
      vis[v] = true
      v = nxt[v]
    }
    a := []int{}
    x := v
    for {
      a = append(a,v)
      v = nxt[v]
      if v == x { break }
    }
    fmt.Println(len(a))
    for _,v := range a { fmt.Println(v+1) }
  }
  for i:=0;i<n;i++ {
    if state[i] == 0 {
      if dfs(i) { solve();return }
    }
  }
  fmt.Println(-1)
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInts() (int,int) {
  s := strings.Fields(i.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int a, b, c;
	scanf("%lld/%lld/%lld", &a, &b, &c);
	if (b <= 4) cout << "Heisei\n";
	else cout << "TBD\n";
}

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

int main() {

	while (1) {
		int i, j, k, n, m, x[3], y[3];
		vector<int> hash[51], hashrev[51];

		cin >> n;
		if (n == 0)break;
		for (i = 0; i <= n; i++) {
			cin >> m;
			cin >> x[0] >> y[0] >> x[1] >> y[1];
			hash[i].push_back((x[0] - x[1]) * (x[0] - x[1]) + (y[0] - y[1]) * (y[0] - y[1]));
			hashrev[i].push_back((x[0] - x[1]) * (x[0] - x[1]) + (y[0] - y[1]) * (y[0] - y[1]));
			for (j = 2; j < m; j++) {
				cin >> x[j % 3] >> y[j % 3];
				if ((x[j % 3] - x[(j - 1) % 3]) * (y[(j - 1) % 3] - y[(j - 2) % 3])
					- (x[(j - 1) % 3] - x[(j - 2) % 3]) * (y[j % 3] - y[(j - 1) % 3]) > 0) {
					hash[i].push_back(-1);
					hashrev[i].push_back(-2);
				} else {
					hash[i].push_back(-2);
					hashrev[i].push_back(-1);
				}
				hash[i].push_back((x[j % 3] - x[(j - 1) % 3]) * (x[j % 3] - x[(j - 1) % 3])
					+ (y[j % 3] - y[(j - 1) % 3]) * (y[j % 3] - y[(j - 1) % 3]));
				hashrev[i].push_back((x[j % 3] - x[(j - 1) % 3]) * (x[j % 3] - x[(j - 1) % 3])
					+ (y[j % 3] - y[(j - 1) % 3]) * (y[j % 3] - y[(j - 1) % 3]));
			}
		}

		for (i = 1; i <= n; i++) {
			reverse(hashrev[i].begin(), hashrev[i].end());
			if (hash[i] == hash[0] || hashrev[i] == hash[0])cout << i << endl;
		}

		cout << "+++++" << endl;


	}

	


	return 0;
}

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


int main(){
  ll n;cin>>n;
  vll a(n);rep(i,n)cin>>a[i];
  sort(all(a),greater<ll>());
  ll N = a[0];
  sort(all(a));
  int i = lower_bound(all(a),N/2)-a.begin();
  ll R;
  if(N/2-a[i-1]<a[i]-N/2 || a[i]==N) R=a[i-1];
  else R=a[i];
  cout << N << " " << R << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if ( T[u].p == NIL ) cout << "root, ";
  else if ( T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for (  i = 0, c = T[u].l; c != NIL; i++, c = T[c].r ) {
    if ( i ) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u, int p) {
  D[u] = p;
  if ( T[u].r != NIL ) rec(T[u].r, p);
  if ( T[u].l != NIL ) rec(T[u].l, p + 1);
}

int main() {
  int i, j, d, v, c, l, r;
  cin >> n;
  for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;

  for ( i = 0; i < n; i++ ) {
    cin >> v >> d;
    for ( j = 0; j < d; j++ ) {
      cin >> c;
      if ( j == 0 ) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for ( i = 0; i < n; i++ )
    if ( T[i].p == NIL ) r = i;

  rec(r, 0);

  for ( i = 0; i < n; i++ ) print(i);

  return 0;
}


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

int main(){
	string s;
	cin >> s;
	int ans=10000;
	rep(i,s.size()-2){
		string sub=s.substr(i,3);
		int n = stoi(sub);
		ans=min(ans,abs(n-753));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n, w;
    cin >> n >> w;
    vector<int> vv(n) , vw(n);
    REP(i,n) cin >> vw[i] >> vv[i];
    ll w1 = vw[0];
    int ans = 0;

    vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(n+1,vector<int>(n*3)));

    REP(i,n) for(int j = i; j>=0;j--) for(int k = j*3;k >= 0;k--) {
        //cerr << "dp" << i << j << k << endl;
        if (w1 * j + k + vw[i] <= w) {
            //cerr << i << " " << j << " " << k + vw[i] - w1 << " " << w1 * j + k + vw[i] << " " << dp[i][j][k] + vv[i]<< endl;
            dp[i+1][j+1][k + vw[i] - w1] = max(dp[i+1][j+1][k + vw[i] - w1], dp[i][j][k] + vv[i]);
            ans = max(ans,dp[i+1][j+1][k + vw[i] - w1]);
        }
        //cerr << i << " "<< j << " " << k << " "<< dp[i][j][k] << endl;
        dp[i+1][j][k] = dp[i][j][k];
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, sum;
  cin >> N >> K;
  sum = 0;
  int x[N];
  for ( int i = 0; i < N; i++ ) {
    cin >> x[i];
  }
  for ( int i = 0; i < N; i++ ) {
    if ( x[i] < ( K - x[i] ) ) {
      sum += x[i]*2;
    }
    else {
      sum += ( K - x[i] ) * 2;
    }
  }
  cout << sum;
}

Measured memory_bytes: 256
GC.disable

class BinaryIndexTree
  attr_reader :bit, :size

  def initialize(size, init: 0)
    @bit = Array.new(size, init)
    @size = size
  end

  def sum(i)
    s = 0

    while i > 0
      s += bit[i]
      i -= i & -i
    end

    s
  end

  def add(i, x)
    while i < size
      bit[i] += x
      i += i & -i
    end
  end
end

N, Q = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)
queries = Q.times.map.with_index { |i|
  l, r = gets.split.map(&:to_i)

  [i, l, r]
}

ans = Array.new(Q, -1)
last = Array.new(N + 1)
idx = 0
bit = BinaryIndexTree.new(N + 1)

queries.sort_by { |i, l, r| r }.each do |i, l, r|
  while idx < r
    c = C[idx]

    if last[c]
      bit.add(last[c], 1)
    end

    last[c] = idx + 1
    idx += 1
  end

  ans[i] = (r - l + 1) - (bit.sum(r) - bit.sum(l - 1))
end

puts ans


Measured memory_bytes: 267288
import math

N, M = map(int, input().split())
if abs(N - M) == 0:
    print(math.factorial(N) * math.factorial(M) * 2 % (10 ** 9 + 7))
elif abs(N - M) == 1:
    print(math.factorial(N) * math.factorial(M) % (10 ** 9 + 7))
else:
    print(0)


Measured memory_bytes: 86516
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int sum = 0;
        int[] T = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            T[i] = sc.nextInt();
            sum += T[i];
        }

        int M = sc.nextInt();
        int[] P = new int[M];
        int[] X = new int[M];
        for (int i = 0; i < M; i++) {
            P[i] = sc.nextInt();
            X[i] = sc.nextInt();

            System.out.println(sum - T[P[i]] + X[i]);
        }
        

        return;
    }

}

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

struct	UnionFind {
	int		size;
	int		*par;
	int		*rank;
	UnionFind(int size): size(size), par(NULL), rank(NULL) {
		assert(size > 0);
		par = new int[size];
		rank = new int[size];
		assert(par != NULL && rank != NULL);
		for (int i = 0; i < size; ++i) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	~UnionFind() {
		delete [] par;
		delete [] rank;
		par = NULL;
		rank = NULL;
	}
	int		find(int idx) {
		if (par[idx] == idx)
			return idx;
		return (par[idx] = find(par[idx]));
	}
	bool	same(int lhs, int rhs) {
		if (find(lhs) == find(rhs))
			return true;
		return false;
	}
	void	unite(int lhs, int rhs) {
		int	par_l = find(lhs), par_r = find(rhs);
		if (par_l == par_r)
			return;
		if (rank[par_l] < rank[par_r]) {
			par[par_l] = par_r;
		} else {
			par[par_r] = par_l;
			if (rank[par_l] == rank[par_r])
				++rank[par_l];
		}
	}
};

int	main()
{
	int	N, K, L;
	cin >> N >> K >> L;
	UnionFind	road(N), train(N);
	int	p, q, s, r;
	for (int i = 0; i < K; ++i) {
		cin >> p >> q;
		--p; --q;
		road.unite(p, q);
	}
	for (int i = 0; i < L; ++i) {
		cin >> s >> r;
		--s; --r;
		train.unite(s, r);
	}
	map<pair<int, int>, int>	cnt_map;
	for (int i = 0; i < N; ++i) {
		int	r_par = road.find(i), t_par = train.find(i);
		auto pr = make_pair(r_par, t_par);
		if (!cnt_map.count(pr))
			cnt_map[pr] = 0;
		++cnt_map[pr];
	}
	for (int i = 0; i < N; ++i) {
		int	r_par = road.find(i), t_par = train.find(i);
		auto pr = make_pair(r_par, t_par);
		cout << cnt_map.at(pr);
		if (i < N - 1)
			cout << " ";
		else
			cout << endl;
	}
}


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

int main()
{
  ll n,k;
  cin>>n>>k;
  
  
  ll a[n];
  for(ll i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  ll ans=0;
  for(ll i=0;i<n-k;i++)
  {
    ans+=a[i];
  }

  cout<<ans;
  
 
  
  
  
  
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

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

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

  int N; scanf("%d",&N);
  vi A(N); REP(i,N) scanf("%d",&A[i]);

  map<int,int> written;
  REP(i,N) {
    if (!written.count(A[i])) {
      written[A[i]]++;
    }
    else {
      written[A[i]]--;
    }
  }

  int ans = 0;
  for (auto p : written) {
    auto k = p.first;
    auto v = p.second;
    if (v%2 != 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  string str;
  for(int i=0; i<3; i++){
    cin >> str;
    cout << str[0];
  }

  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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() {
    int n,m;
    cin >> n>> m;
    vector<int>a(m);
    rep(i,m) cin >> a[i];
    int sum = 0;
    rep(i,m) sum += a[i];

    if(n-sum>=0) cout << n-sum << endl;
    else cout << "-1" <<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        int l = n / i;
        ans += l * (i + l * i) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

vector<string> results[11];

int main()
{
    int n;
    cin >> n;
    results[1].push_back("a");
    for (int i = 2; i <= n; i++)
    {
        for (string s : results[i - 1])
        {
            char maxC = 'a';
            for (int j = 0; j < s.length(); j++)
            {
                if (s.at(j) > maxC) {maxC = s.at(j);}
            }
            for (char c = 'a'; c <= maxC + 1; c++)
            {
                results[i].push_back(s + c);
            }
        }
    }
    for (string s : results[n])
    {
        cout << s << endl;
    }
}

Measured memory_bytes: 11380
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int K = sc.nextInt();
		if(K%2==1){
			out.println((long)Math.pow(Math.floor(N/K), 3));
		}else{
			int count0 =0;
			int countHalf =0;
			int half = K/2;
			for(int i=1;i<=N;i++){
				if(i%K==0)count0++;
				else if(i%K==half) countHalf++;
			}
			out.println((long)(Math.pow(count0, 3)+Math.pow(countHalf, 3)));
		}
		out.flush();
	}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23380
N=int(input())
fir=0
sec=0
adr=[]
for i in range(N):
  a=int(input())
  if a==fir:
    adr.append(i)
  elif a>fir:
    sec=fir
    fir=a
    adr=[i]
  elif a<fir:
    if a>sec:
      sec=a
if len(adr)==1:
  for i in range(N):
    if i!=adr[0]:
      print(fir)
    else:
      print(sec)
else:
  for i in range(N):
    print(fir)

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

using namespace std;

int main(void)
{
	int a, b, c;
	cin >> a;
	vector<int> vec;


	if (a % 10 == 3)
	{
		cout << "bon" << endl;
	}
	else if (a % 10 == 0 || a % 10 == 1 || a % 10 == 6 || a % 10 == 8)
	{
		cout << "pon" << endl;
	}
	else
		cout << "hon" << endl;

}

Measured memory_bytes: 3620
import java.util.*;
import java.io.*;

class Main {
  public static void main(String[] args){
    Scanner  sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int a = 0;
    int i = 0;
    while(a < n){
      a += 2 * d + 1;
      i ++;
          }
          System.out.println(i);
  }
}


Measured memory_bytes: 25172
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
a,b,c,d,e,f = LI()
a *= 100
b *= 100
ans = [a,0]
for i in range(f//a+1):
    for j in range((f-a*i)//b+1):
        for k in range((f-a*i-b*j)//c+1):
            for l in range((f-a*i-b*j-c*k)//d+1):
                if i or j or k or l:
                    s = c*k+d*l
                    w = a*i+b*j
                    q = w*e//100
                    if s <= q:
                        if w+s <= f:
                            if ans[1]/ans[0] < s/(s+w):
                                ans = [w+s,s]
print(*ans)
"""

#D
n = I()
a = LIR(n)
d = [[a[i][j] for i in range(n)] for j in range(n)]
l = [[1 for j in range(n)] for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] >= d[i][k]+d[k][j]:
                d[i][j] = d[i][k]+d[k][j]
                l[i][j] = l[i][k]+l[k][j]

if a != d:
    print(-1)
    quit()
ans = 0
for i in range(n):
    for j in range(n):
        if l[i][j] == 4:
            ans += d[i][j]
ans //= 2
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 46300
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pb push_back

int main()
{
    ull n,k;
    cin>>n>>k;
    ull ans=n%k;
    ans=min(ans,k-ans);
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
l_set = list(set(l))

def func(l,k):
    ans = min(l)-k
    l_i = [i for i, x in enumerate(l) if x == min(l)]
    l_split = []
    for i in range(len(l_i)+1):
        if i==0:
            l_ = l[:l_i[i]]
            if(l_):
                l_split.append(l_)
        elif i==len(l_i):
            l_ = l[l_i[i-1]+1:]
            if(l_):
                l_split.append(l_)
        else:
            l_ = l[l_i[i-1]+1:l_i[i]]
            if(l_):
                l_split.append(l_)
    k = min(l)
    for l_ in l_split:
        ans += func(l_,k)
    return ans

ans = func(l,0)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios::sync_with_stdio(0);  //fast input and output
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    ll a[200001],h[200001]={0},i,p,c=0,w=0;
     string s[m+1];
     for(i=0;i<m;i++)
     {
         cin>>a[i]>>s[i];
     }
    for(i=0;i<m;i++)
    {
        if(h[a[i]]!=-1)
        {
            if(s[i]=="WA")
            {
                h[a[i]]++;
            }
            else if(s[i]=="AC")
            {
                c++;
                w+=h[a[i]];
                h[a[i]]=-1;
            }
        }
    }
     cout<<c<<endl<<w<<endl;
    return 0;
}



Measured memory_bytes: 8704
h,w,a,b=map(int,input().split())

if(a>(w//2) and b>(h//2)):
    print('No')
else:
    for i in range(h):
        if(i<b):
            print(''.join(['0' for _ in range(a)]) + ''.join(['1' for _ in range(w-a)]))
        else:
            print(''.join(['1' for _ in range(a)]) + ''.join(['0' for _ in range(w-a)]))



Measured memory_bytes: 9188
def max(a,b); a > b ? a : b end
def min(a,b); a < b ? a : b end
def swap(a,b); a, b = b, a  end
def yn(f); puts f ? "Yes" : "No" end

def yes(f=nil); f.nil? ? (puts "Yes"; exit) : (puts f ? "Yes" : "No") end
def no(f=nil);  f.nil? ? (puts "No";  exit) : (puts f ? "No" : "Yes") end

inf = Float::INFINITY
mod = 10 ** 9 + 7

k = gets.to_s.to_i
#a = gets.to_s.split.map{|e|e.to_i}
#m = Array.new(n){ gets.to_s.split.map{|e|e.to_i} }
s = gets.to_s.chomp

if s.size <= k
  puts s
else
  puts s[0, k] + "..."
end

Measured memory_bytes: 14392
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

// Union find
struct uf {
  vi d;
  uf(){}
  uf(int mx):d(mx,-1){}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y]; d[y] = x;
    return true;
  }
  int size(int x) { return -d[root(x)];}
};
//


int main() {
  df(n); df(m);
  uf t(n+m);
  rep(i,n) {
    df(k);
    rep(j,k) {
      df(l);
      --l;
      t.unite(i,n+l);
    }
  }
  string ans = "YES";
  rep(i,n-1) if (t.root(i) != t.root(i+1)) ans = "NO";
  cout << ans << endl;
  return 0;
}







Measured memory_bytes: 1024
main = do
    getLine >>= return.solve.l >>= putStrLn

p = [[1,a,b,c] | a <- [1,-1], b <- [1,-1], c <- [1,-1]]

l [] = []
l (x:xs) = (read [x]) : (l xs)

solve :: [Int] -> String
solve x = f x p where
    f x (y:ys)
        | sum (zipWith (*) x y) == 7 = tail (showAns x y)
        | otherwise = f x ys

showAns [] [] = "=7"
showAns (x:xs) (y:ys)
    | y == 1 = "+" ++ (show x) ++ showAns xs ys
    | y == -1 = "-" ++ (show x) ++ showAns xs ys

Measured memory_bytes: 508
z=60;main(h,m,s,t){for(;scanf("%d%d%d",&h,&m,&s),~h;printf("%02d:%02d:%02d\n%02d:%02d:%02d\n",t/z/z,t/z%z,t%z,t*3/z/z,t*3/z%z,t*3%z))t=7200-h*z*z-m*z-s;exit(0);}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#include <math.h>//pow(x,y)=x^y
#include <algorithm>//sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(i,n) for (int i=0; i <(n);i++)
#define ll long long
using namespace std;


int main() {
int N,zero;
ll P;
P = pow(10,18);
cin >> N;
vector<ll> A(N);
rep(i,N){
cin >> A.at(i);
}

zero = 0;
rep(i,N){
	if(A.at(i)==0) zero=1;
}

ll prod = 1;

if(zero==0){
rep(i,N){
	if(A.at(i)<=P/prod){
		prod *= A.at(i);
	}else{
		cout << -1 <<endl;return 0;
	}
}
cout << prod <<endl;return 0;
}else{
	int B=0;
	cout << B <<endl;
}
}


Measured memory_bytes: 4004
S = input()
K = int(input())
N = len(S)

l = []
for i in range(N):
    for j in range(i+1,min(i+K+1,N+1)):
        s = S[i:j]
        l.append(s)
l = list(set(l))
l.sort()
print(l[K-1])

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

#define N_MAX 102
#define K_MAX 100002

using namespace std;

int n, k;

int a[N_MAX];

bool dp[K_MAX];

int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    dp[0] = false;
    for(int i = 1; i <= k; i++)
    {
        bool ok = false;
        for(int j = 1; j <= n; j++)
            if(a[j] <= i && dp[i - a[j]] == false)
            {
                ok = true;
                break;
            }
        dp[i] = ok;
    }
    if(dp[k] == true)
        cout << "First\n";
    else
        cout << "Second\n";
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#define input std::cin

using vector = std::vector<int>;
using lint = long long int;
using string = std::string;

int modulo = 1000000000 + 7;

int main() {
  int n; input >> n;
  vector nums (n);
  for (int &num : nums) {
	input >> num;
  }
  int ans = 0;
  int sum = 0;
  for (int i=nums.size()-1; i>=0; i--) {
	int prod = (nums[i] * (lint) sum) % modulo;
	ans = (ans + (lint)prod) % modulo;
	sum = (sum + (lint)nums[i])%modulo;
  }
  std::cout << ans << std::endl;
}



Measured memory_bytes: 3992
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const ll MOD=1e9+7;

const int SIZE=2*1e5;
ll powm(ll x,ll k){
    ll res=1;
    while(k){
        if(k&1) res=res*x%MOD;
        k>>=1;
        x=x*x%MOD;
    }
    return res;
}
ll inv(ll x){
    return powm(x,MOD-2);
}
struct Comb{
    ll fact[SIZE];
    ll invFact[SIZE];
    Comb(){
        fact[0]=1;
        for(int i=1;i<SIZE;i++) fact[i]=fact[i-1]*i%MOD;
        invFact[SIZE-1]=inv(fact[SIZE-1]);
        for(int i=SIZE-2;i>=0;i--) invFact[i]=invFact[i+1]*(i+1)%MOD;
    }
    ll operator()(int n,int k){return fact[n]*invFact[k]%MOD*invFact[n-k]%MOD;}
} comb;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

    vector<vector<ll>> dp(n+1,vector<ll>(k+1));    
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=k;j++){
            int to=j+a[i]+1;
            if(to<=k) (dp[i+1][to]-=dp[i][j])%=MOD;
            (dp[i+1][j]+=dp[i][j])%=MOD;
        }
    }
    vector<ll> A=dp[n];

    vector<ll> B(k+1);
    for(int i=0;i<=k;i++){
        B[i]=comb(i+n-1,n-1);
    }
    
    ll res=0;
    for(int i=0;i<=k;i++){
        res+=A[i]*B[k-i]%MOD;
        res%=MOD;
    }

    cout<<(res%MOD+MOD)%MOD<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 84080
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
long long i,j,k,l,n,x[1000],y[1000],h[1000],mn=10000000000;
int main(){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i] >> y[i] >> h[i];
		mn = min(mn,h[i]);
	}
	for(j=0;j<=100;j++){
		for(k=0;k<=100;k++){
			for(l=mn;l<=mn+400;l++){
				for(i=0;i<n;i++){
					if(h[i]!=max(0LL,l-abs(j-x[i])-abs(k-y[i]))){
						break;
					}
					if(i==n-1){
						cout << j << " " << k << " " << l << endl;
						return 0;
					}
				}
			}
		}
	}
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)  //  rep
#define repr(i,a,n) for(int i=a;i>n;i--)  //  repリバース
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9000000000000000000 //  巨大数INF
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b;
  cin >> a >> b;
  if (a<=8&&b<=8) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type stringSorter []byte

func (a stringSorter) Len() int           { return len(a) }
func (a stringSorter) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a stringSorter) Less(i, j int) bool { return a[i] < a[j] }

func solve(stdin io.Reader, stdout io.Writer) {
	var n int

	var sc = make(map[string]int)

	reader := bufio.NewScanner(stdin)

	reader.Scan()
	n, _ = strconv.Atoi(reader.Text())

	for i := 0; i < n; i++ {
		reader.Scan()
		b := []byte(reader.Text())
		sort.Sort(stringSorter(b))
		sc[string(b)]++
	}

	w := 0
	for _, v := range sc {
		w += v * (v - 1) / 2
	}
	fmt.Fprintln(stdout, w)
}



Measured memory_bytes: 9856
#include<iostream>
using namespace std;
int main()
{
	long long N;
	long long S;
    cin >> N;
    long long a[N+1]; a[0] = 0;
    int i;
    long long number[N+1];
    for(i=1;i<N+1;i++)
    {
    	cin >> a[i];
    }
    for(i=0;i<N+1;i++)
    {
    	number[i] = 0;
    }
    for(i=1;i<N+1;i++)
    {
    	number[a[i]] = number[a[i]] + 1;
    }
    S = 0;
    for(i=1;i<N+1;i++)
    {
    	S = S + number[i]*(number[i]-1)/2;
    }
    for(i=1;i<N+1;i++)
    {
    	cout << S - (number[a[i]] - 1) << endl;
    }
    return 0;
}
    
    
    


Measured memory_bytes: 5760