akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MOD 1000000007LL
#define MAXN 200100

vector<long long> f(MAXN);


long long mul_inv(long long a, long long b)
{
	long long b0 = b, t, q;
	long long x0 = 0, x1 = 1;
	if (b == 1) return 1;
	while (a > 1) {
		q = a / b;
		t = b, b = a % b, a = t;
		t = x0, x0 = x1 - q * x0, x1 = t;
	}
	if (x1 < 0) x1 += b0;
	return x1;
}

long long division(long long a, long long b, long long p) {		// (a / b) mod p = ((a mod p) * (b^(-1) mod p)) mod p
	long long ans, inv;
	inv = mul_inv(b, p);
	ans = ((a % p) * inv) % p;
	return ans;
}

long long calc(long long n, long long k) {
	long long a = f[n], b = (f[k] * f[n - k]) % MOD;
	long long ans = division(a, b, MOD);
	return ans;
}

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

	long long n, m, i, j, k, a, b, ans, x, y;
	cin >> n >> m >> a >> b;
	
	f[0] = 1;
	for (i = 1; i < MAXN; i++) f[i] = (f[i - 1] * i) % MOD;

	ans = 0;
	for (i = 0; i < n - a; i++) {
		x = calc(b - 1 + i, i);
		y = calc(m - b - 1 + n - 1 - i, m - b - 1);

		ans = (ans + x * y) % MOD;
	}
	
	cout << ans << "\n";

	return 0;
}


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

class Node{
private:
  Node* next;
  Node* prev;
  int data;
public:
  Node(){
    next=0;
    prev=0;
    data=0;
  }
  Node(Node* n_next,Node* n_prev,int n_data){
    next=n_next;
    prev=n_prev;
    data=n_data;
  }
  void set_next(Node* next){
    this->next=next;
  }
  void set_prev(Node* prev){
    this->prev=prev;
  }
  void set_data(int data){
    this->data=data;
  }
  Node* get_next(){
    return next;
  }
  Node* get_prev(){
    return prev;
  }
  int get_data(){
    return data;
  }
};

class linkedList{
private:
  Node head;
  Node tail;
public:
  linkedList(){
    head.set_next(&tail);
    tail.set_prev(&head);
  }
  void insert(int x){
    Node* tmp=new Node(head.get_next(),&head,x);
    head.get_next()->set_prev(tmp);
    head.set_next(tmp);
    //print();
  }
  void del(int key){
    Node* search=head.get_next();
    tail.set_data(key);
    while(search->get_data()!=key){
      search=search->get_next();
    }
    if(search!=&tail){
      search->get_prev()->set_next(search->get_next());
      search->get_next()->set_prev(search->get_prev());
      delete search;
    }
    //print();
  }
  void deleteFirst(){
    Node* tmp=head.get_next();
    head.set_next(head.get_next()->get_next());
    head.get_next()->set_prev(&head);
    delete tmp;
    //print();
  }
  void deleteLast(){
    Node* tmp=tail.get_prev();
    tail.set_prev(tail.get_prev()->get_prev());
    tail.get_prev()->set_next(&tail);
    delete tmp;
    //print();
  }
  void print(){
    Node* i=head.get_next();
    while(true){
      if(i==tail.get_prev()){
        cout<<i->get_data()<<endl;
        break;
      }
      cout<<i->get_data()<<' ';
      i=i->get_next();
    }
  }
};

int main(){
  linkedList l;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    char a[15];
    cin>>a;
    if(a[0]=='i'){
      int key;
      cin>>key;
      l.insert(key);
    }else if(a[6]=='F'){
      l.deleteFirst();
    }else if(a[6]=='L'){
      l.deleteLast();
    }else{
      int x;
      cin>>x;
      l.del(x);
    }
  }
  l.print();
  return 0;
}



Measured memory_bytes: 34220
#include "bits/stdc++.h"
using namespace std;

int main() {
    int n, tmp = 0, ans = INT_MAX;
    char s[300000];
    cin >> n >> s;
    if(s[0] == 'E')tmp--;
    for(int i = 0; i < n; i++)
        if(s[i] == 'E')tmp++;
    ans = tmp;
    for(int i = 0; i<n-1;){
        if(s[i] == 'W')tmp++;
        if(s[++i] == 'E')tmp--;
        ans = min(ans, tmp);
    }
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
N,D=input().split() 
N=int(N)
D=int(D)
list = []
for i in range(N):
    x,y=input().split()
    list.append((int(x),int(y)))
counter=0
import math
for u in range(N):
    length=((list[u][0])**2 + list[u][1]**2)
    if math.sqrt(length)<=D:
        counter=counter+1
print(counter)

Measured memory_bytes: 35960
import math
A, B = map(int, input().split())

AA = A * 100 / 8
BB = B * 100 / 10

L = []
for i in range(10000):
    if math.floor(i * 0.08) == A and math.floor(i * 0.1) == B:
        L.append(i)
    
L = sorted(L)
if L == []:
    print(-1)
    exit()

print(L[0])

Measured memory_bytes: 63680
/* 
 * Project: AtCoder Beginners Contest 140 A - Password
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/21
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
#include <cmath>
using namespace std;

uint16_t n;

void solve() {

    uint32_t pattern = pow(n, 3);
    printf("%d\n", pattern);

}

int main() {

    scanf("%hd", &n);

    solve();

}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5e5;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;
  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n = n >> 1;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }
  return ret;
}

int main(){
  int n,Q; cin >> n >> Q;
  vector<tuple<int,int,int>> a;
  rep(i,n) {
    int s,t,x; cin>>s>>t>>x;
    a.pb(make_tuple(x,s-x,t-x));
  }
  sort(all(a));
  set<pii> s;
  rep(q,Q) {
    int d; cin >> d;
    s.insert(pii(d,q));
  }

  vi ans(Q,-1);
  rep(i,n) {
    int x,l,r;
    tie(x,l,r) = a[i];
    auto it = s.lower_bound(pii(l,-1));
    while(it != s.end()){
      if(it->first >= r) break;
      ans[it->second] = x;
      s.erase(it++);
    }
  }

  rep(q,Q) cout << ans[q] << endl;
}


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

using namespace std;

int main()
{
    int a[10], b[10];
    for (int i = 0; i < 10; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < 10; i++) {
        cin >> b[i];
    }

    sort(a, a + 10, greater<int>());
    sort(b, b + 10, greater<int>());
    cout << a[0] + a[1]+ a[2] << " " << b[0] + b[1] + b[2] << endl;
    return 0;
}

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

int main() {
	double x1, y1, x2, y2, x3, y3, x4, y4;
	int n;
	cin >> n;
	for (int i = 0 ; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		double t_AB, t_CD;
		t_AB = (y2 - y1) / (x2 - x1);
		t_CD = (y4 - y3) / (x4 - x3);
		if (abs((y2 - y1)*(x4 - x3) - (y4 - y3)*(x2 - x1))<1e-10) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;

}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define co cout
#define ci cin
#define sf1(n) scanf("%lld",&n);
#define sf2(n,m) scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define en cout<<endl;
#define pb push_back
#define coy cout<< "YES"<<endl;
#define con cout<< "NO"<<endl;
#define For(a,b) for(ll a=0;a<b;a++)
#define br break;
#define i64 long long
i64 M=10000000;
//ll b[805],ans[805];
map< ll,pair<ll,ll> >mp;

int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,res,c1,x,y,c2;
    ci>>n;
    for(ll i=1;i<=n;i++)
    {
        if(i%2) mx++;
    }
    double ans=(double)mx/(double)n;
    printf("%.10lf",ans);
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <iomanip>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

double a,b,c,d,e,f;

int main() {
  while(cin >> a >> b >> c >> d >> e >> f) {
    double x, y;
    x = (c*e - f*b) / (a*e - b*d);
    y = (f*a - c*d) / (e*a - b*d);
    x = x == 0 ? 0 : x;
    y = y == 0 ? 0 : y;
    cout << fixed << setprecision(3) << x << " " << y << endl;
  }
  return 0;
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, m;
	cin >> n >> m;
	vi a(n);
	for (int &x : a) cin >> x;
	int total = accumulate(all(a), 0);
	int select = 0;
	for (auto x : a)
		if (x * 4 * m >= total) ++select;
	puts(select >= m ? "Yes" : "No");
}


Measured memory_bytes: 256
N=int(input())
a=4/N
h_st=max(int(N*(1/4))-1,1)
#h_st=1
for h in range(h_st,3501):
    H=1/h
    for n in range(1,3501):
        a=(4*h*n-N*n-N*h)
        #print(h,n)
        if a:
            w=N*h*n/a
            if w>0 and w.is_integer():
                print(h,n,int(w))
                exit()

print(h,n,w)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line = br.readLine().split(" ");
      int[] arrayS = new int[n];
      int i=0;
      for (String val : line) {
        arrayS[i++] = Integer.parseInt(val);
      }

      MergeSort merge = new MergeSort(arrayS);
      int cnt = merge.mergeSort(0, n);

      merge.dispIntArray();
      System.out.println(cnt);
    }
  }
}

class MergeSort {

  static private final int SENTINEL = Integer.MAX_VALUE;

  private int[] target;
  private int[] bufL;
  private int[] bufR;

  public MergeSort(int[] target) {
    this.target = target;
    bufL = new int[target.length/2+2];
    bufR = new int[target.length/2+2];

  }

  public int mergeSort(int left, int right) {
    int cnt =0;

    if(left+1 < right){
      int mid = (left + right) / 2;
      cnt += mergeSort(left, mid);
      cnt += mergeSort(mid, right);
      cnt += merge(left, mid, right);
    }

    return cnt;
  }

  private int merge(int left, int mid, int right) {
    int cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    
    for(int i=0; i<n1; i++)
      bufL[i] = target[left+i];
    bufL[n1] = MergeSort.SENTINEL;

    for(int i=0; i<n2; i++)
      bufR[i] = target[mid+i];
    bufR[n2] = MergeSort.SENTINEL;

    for(int i=0,j=0,k=left; k<right; k++) {
      if(bufL[i] <= bufR[j])
        target[k] = bufL[i++];
      else
        target[k] = bufR[j++];
      cnt++;
    }

    return cnt;
  }

  public int[] getArray() {
    return target;
  }

  public void dispIntArray() {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 142500
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int even = 0, odd = 0;
  int N; cin >> N;
  for (int i = 0; i < N; ++i) {
    int A; cin >> A;
    if (A % 2 == 0) even++;
    else            odd++;
  }

  if (odd % 2 == 1) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 3592
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	int N, T, A, H;
	int minI;
	double minD, d;

	cin >> N;
	cin >> T >> A;

	cin >> H;
	minI = 1;
	minD = fabs(T - H * 0.006 - A);
	for (int i = 1; i < N; i++)
	{
		cin >> H;
		d = fabs(T - H * 0.006 - A);
		if (d < minD)
		{
			minI = i + 1;
			minD = d;
		}
	}

	cout << minI << endl;

	return 0; 
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll a,b;
  cin>>a>>b;
  if (a>=13)
    cout<<b<<endl;
  else if (a<=5)
    cout<<0<<endl;
  else
    cout<<b/2<<endl;
  return 0;
}


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

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

    bitset<64> mask[n];
    for (int i = 0; i < n; i++)
    {
        int k, b;
        cin >> k;
        while (k--)
        {
            cin >> b;
            mask[i].set(b);
        }
    }

    bitset<64> bit;
    int q, operation, m;

    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> operation >> m;
        if (operation == 0)
            cout << bit[m] << endl;
        // 0 0 1 1 0 0 0 1
        // 0 1 0 1 1 0 1 0
        // 0 0 0 1 0 0 0 0

        // 0 1 0 1 0 1 0 1
        // 0 1 0 1 0 1 0 1
        // 0 1 0 1 0 1 0 1
        if (operation == 1)
            bit |= mask[m];
        if (operation == 2)
            bit &= ~mask[m];
        if (operation == 3)
            bit ^= mask[m];
        if (operation == 4)
            cout << ((bit & mask[m]) == mask[m]) << endl;
        if (operation == 5)
            cout << (bit & mask[m]).any() << endl;
        if (operation == 6)
            cout << (bit & mask[m]).none() << endl;
        if (operation == 7)
            cout << (bit & mask[m]).count() << endl;
        if (operation == 8)
            cout << (bit & mask[m]).to_ullong() << endl;
    }
}



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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
int main( void ){
	// initialize();
	int N;
	cin >> N;
	ll sum = 0;
	rep(i,1,N+1){
		rep(j,1,N+1){
			rep(k,1,N+1){
				sum += __gcd(i,__gcd(j,k));
			}
		}
	}
	cout << sum << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 3664
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    N = int(sysread())
    A = list(map(int, sysread().split()))
    B = list(map(int, sysread().split()))
    C = list(map(int, sysread().split()))
    A.sort()
    B.sort()
    C.sort()
    ansBa = []
    ansBc = []
    for i in range(N):
        b = B[i]
        idx = bisect.bisect_left(A, b)
        ansBa.append(idx)

        idx2 = bisect.bisect_right(C, b)
        ansBc.append(N-idx2)

    #print(ansBc, ansBa)
    ans = 0
    for aa, cc in zip(ansBa, ansBc):
        ans += aa * cc


    print(ans)

if __name__ == "__main__":
    run()


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

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

    int N;

    cin >> N;

    cout << N/2 + N%2;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main (void){
	int a,b;
  	char s[100];
  	char t[100];
  	char u[100];
   	scanf ("%s %s",s,t);
  	scanf ("%d %d",&a,&b);
    scanf ("%s",u);
  if (strcmp(u,s) == 0)
    a = a - 1;
  else 
    b = b - 1;
 	printf("%d %d",a,b);
  return(0);
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll changeW(char c){
  if(c == 'W')
    return 0;
  else
    return 1;
}

ll changeE(char c){
  if(c == 'E')
    return 0;
  else
    return 1;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin >> n;
  
  string s;
  cin >> s;
  
  vector<ll> dp(n, 0);
  REP1(i, n)
    dp[0] += changeW(s[i]);
  
  ll min_count = dp[0];
  REP1(i, n){
    dp[i] = dp[i-1] + changeE(s[i-1])\
    - changeW(s[i]);
    min_count = min(min_count, dp[i]);
  }
  
  cout << min_count << endl;
  
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const intll INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ; 
  
  cout << (n-1)/2 ;
}


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

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

  vector<int> P(N), Q(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> Q.at(i);
  }

  vector<int> V(N);
  iota(V.begin(), V.end(), 1);

  int a, b;
  int i = 0;
  do {
    if (P == V) {
      a = i;
    }
    if (Q == V) {
      b = i;
    }

    i++;
  } while( next_permutation(V.begin(), V.end()) );

  cout << abs(a - b) << endl;
  return 0;
}


Measured memory_bytes: 256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll N;
	cin >> N;
	string s;
	cin >> s;
	
	ll ans = -INF;
	rep(i, N + 1) {
		ll mb[26] = { 0 }, me[26] = { 0 }, tmp = 0;
		rep(j, i) mb[s[j] - 'a'] = 1;
		fori(j, i, N) me[s[j] - 'a'] = 1;
		rep(j, 26) tmp += mb[j] * me[j];
		ans = max(ans, tmp);
	}
	cout << ans << endl;

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 100000000000

ll factorial(ll k) {
	ll sum = 1;
	for (ll i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

vector<ll> e(101, 0);
ll num(ll n) {
	ll cnt = 0;
	rep(i, e.size()) {
		if (e[i] >= n-1) cnt++;
	}
	return cnt;
}

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

	ll N, v;
	ll ans = 0;

	cin >> N;

	ll n;
	rep2(i, 2, N + 1) {
		n = i;
		rep2(j, 2, i + 1) {
			while (n % j == 0) {
				e[j]++;
				n /= j;
			}
		}
	}
	
	ll tmp1, tmp2, tmp3, tmp4;
	tmp1 = num(75);
	tmp2 = num(25) * (num(3) - 1);
	tmp3 = num(15) * (num(5) - 1);
	tmp4 = num(5) * (num(5) - 1) * (num(3) - 2) / 2;

	ans = tmp1 + tmp2 + tmp3 + tmp4;
	cout << ans << "\n";
	return 0;
}


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

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

int main(){
    int k, h, i, j;
    long long int ans = 0;
    scanf("%d",&k);
    for(h=1;h<=k;h++){
        for(i=1;i<=k;i++){
            for(j=1;j<=k;j++){
                ans += gcd(gcd(h,i),j);
            }
        }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 1728
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];
// fac[i] i!
// finv[i] i!の逆元
// inv[i] iの逆元

// テーブルを作る前処理
void COM_init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2; i<MAX; ++i){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//////////////////////////////////////////////////

int main(){
  ll N;
  cin>>N;
  ll A[N+1],CNT[N+1]={},it=0;
  REP(i,N+1){
    cin>>A[i];
    CNT[A[i]]++;
    if(CNT[A[i]]==2) it=A[i];
  }
  
  // P,Q=itが現れる場所
  ll P=-1,Q=-1;
  REP(i,N+1){
    if(A[i]==it){
      if(P>=0) Q=i;
      else P=i;
    }
  }
  
  ll pow2[101010];
  pow2[0]=1;
  for(int i=1; i<=100100; ++i) pow2[i]=pow2[i-1]*2%MOD;
  
  COM_init();
  RREP(i,N+1){
    if(i==1){
      cout<<N<<endl;
      continue;
    }
    
    ll ans=COM(N+1,i);
    if(N-(Q-P)>=i-1) ans-=COM(N-(Q-P),i-1);
    ans=(ans%MOD+MOD)%MOD;
    cout<<ans<<endl;
    
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


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

  map<ll, int> mp;
  vector<ll> v;
  REP(i,N){
    ll a;
    cin >> a;
    mp[a]++;
    if(mp[a]%2==0){
      v.push_back(a);
    }
  }

  sort(ALL(v));
  reverse(ALL(v));

  if(v.size()<2){
    cout << 0 << endl;
  }else{
    cout << v[0] * v[1] << endl;
  }
}




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

template <typename T = int>
struct Edge {
    int from, to;
    T cost;
    int idx;

    Edge() = default;

    Edge(int from, int to, T cost = 1, int idx = -1)
        : from(from), to(to), cost(cost), idx(idx) {
    }

    operator int() const {
        return to;
    }
};

template <typename T = int>
struct Graph {
    vector<vector<Edge<T>>> g;
    int es;

    Graph() = default;

    explicit Graph(int n) : g(n), es(0) {
    }

    size_t size() const {
        return g.size();
    }

    void add_directed_edge(int from, int to, T cost = 1) {
        g[from].emplace_back(from, to, cost, es++);
    }

    void add_edge(int from, int to, T cost = 1) {
        g[from].emplace_back(from, to, cost, es);
        g[to].emplace_back(to, from, cost, es++);
    }

    void read(int M, int padding = -1, bool weighted = false,
              bool directed = false) {
        for (int i = 0; i < M; i++) {
            int a, b;
            cin >> a >> b;
            a += padding;
            b += padding;
            T c = T(1);
            if (weighted) cin >> c;
            if (directed)
                add_directed_edge(a, b, c);
            else
                add_edge(a, b, c);
        }
    }
};

template <typename T = int>
using Edges = vector<Edge<T>>;

template <typename T = int>
struct StronglyConnectedComponents : Graph<T> {
  public:
    using Graph<T>::Graph;
    using Graph<T>::g;
    vector<int> comp;
    Graph<T> dag;
    vector<vector<int>> group;

    void build() {
        rg = Graph<T>(g.size());
        for (int i = 0; i < g.size(); i++) {
            for (auto &e : g[i]) {
                rg.add_directed_edge(e.to, e.from, e.cost);
            }
        }
        comp.assign(g.size(), -1);
        used.assign(g.size(), 0);
        for (int i = 0; i < g.size(); i++) dfs(i);
        reverse(begin(order), end(order));
        int ptr = 0;
        for (int i : order)
            if (comp[i] == -1) rdfs(i, ptr), ptr++;
        dag = Graph<T>(ptr);
        for (int i = 0; i < g.size(); i++) {
            for (auto &e : g[i]) {
                int x = comp[e.from], y = comp[e.to];
                if (x == y) continue;
                dag.add_directed_edge(x, y, e.cost);
            }
        }
        group.resize(ptr);
        for (int i = 0; i < g.size(); i++) {
            group[comp[i]].emplace_back(i);
        }
    }

    int operator[](int k) const {
        return comp[k];
    }

  private:
    vector<int> order, used;
    Graph<T> rg;

    void dfs(int idx) {
        if (exchange(used[idx], true)) return;
        for (auto &to : g[idx]) dfs(to);
        order.push_back(idx);
    }

    void rdfs(int idx, int cnt) {
        if (comp[idx] != -1) return;
        comp[idx] = cnt;
        for (auto &to : rg.g[idx]) rdfs(to, cnt);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    StronglyConnectedComponents<int> gr(n);
    gr.read(m, 0, false, true);
    gr.build();
    cout << gr.group.size() << '\n';
    for (auto &com : gr.group) {
        cout << com.size();
        for (auto v : com) cout << ' ' << v;
        cout << '\n';
    }
}

Measured memory_bytes: 113312
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int n;
vi ans;
void f(vector<vector<pii>> &query, vi &has, vi &v, vi &w, const vi &dp, int i) {
  auto dp1 = dp;
  RREP(j, dp1.size() - w[i]) { chmax(dp1[j + w[i]], dp1[j] + v[i]); }
  for (auto p : query[i]) {
    ans[p.second] = dp1[p.first];
  }
  if (i * 2 + 1 < n && has[i * 2 + 1])
    f(query, has, v, w, dp1, i * 2 + 1);
  if (i * 2 + 2 < n && has[i * 2 + 2])
    f(query, has, v, w, dp1, i * 2 + 2);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vi v(n), w(n);
  constexpr int d = 10;
  REP(i, n) { cin >> v[i] >> w[i]; }
  int q;
  cin >> q;
  vector<pii> p(q);
  REP(i, q) {
    cin >> p[i].first >> p[i].second;
    p[i].first--;
  }

  const int SIZE = 1e5 + 1;
  vvl l(1 << d);
  {
    vl dp(SIZE, 0);
    FOR(i, w[0], dp.size()) dp[i] = v[0];
    l[0] = dp;
  }
  FOR(i, 1, min(n, (int)l.size())) {
    l[i] = l[(i - 1) / 2];
    RREP(j, SIZE - w[i]) { chmax(l[i][j + w[i]], l[i][j] + v[i]); }
  }
  REP(i, q) {
    int x = p[i].first, y = p[i].second;
    if (x < l.size())
      cout << l[x][y] << "\n";
    else {
      vector<pii> k;
      ll ans = -INF;
      while (x >= (1 << d) - 1) {
        k.emplace_back(v[x], w[x]);
        x = (x - 1) / 2;
      }
      REP(i, 1 << (k.size())) {
        ll sumv = 0, sumw = 0;
        REP(j, k.size()) {
          if (i & (1 << j)) {
            sumv += k[j].first;
            sumw += k[j].second;
          }
        }
        if (sumw <= y) {
          chmax(ans, sumv + l[x][y - sumw]);
        }
      }
      cout << ans << "\n";
    }
  }
}


Measured memory_bytes: 806140
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let () =
  let n = scanf " %s" (fun s -> s) in
  print_endline @@ if n.[0] == '9' || n.[1] == '9' then "Yes" else "No"


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var xn = Sarray();
            var x = xn[0];
            var n = xn[1];
            var pn = Slist();
            var ans = 102;
            for(var i=0;i<=101;i++)
            {
                if (Math.Abs(x - i) < Math.Abs(x - ans)
                    && !pn.Contains(i)) ans = i;
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 18896
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//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 SQ(a) ((a)*(a))
#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,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集
int H, W, N;
int sy, sx; 
string s, t; 
int solve(){

    int left = 0, right = W;
    if(s[N-1] == 'L') left++;
    if(s[N-1] == 'R') right--;

    for(int i=N-2; i>=0; i--){
        if(t[i] == 'L') right = min(right+1, W);
        else if(t[i] == 'R') left = max(left-1, 0);
        if(s[i] == 'L') left = left+1;
        else if(s[i] == 'R') right = right-1;
        if(left >= right) return 0;
    }
    if(sx < left || sx >= right) return 0;

    left = 0, right = H;
    if(s[N-1] == 'U') left++;
    if(s[N-1] == 'D') right--;

    for(int i=N-2; i>=0; i--){
        if(t[i] == 'U') right = min(right+1, H);
        else if(t[i] == 'D') left = max(left-1, 0);
        if(s[i] == 'U') left = left+1;
        else if(s[i] == 'D') right = right-1;
        if(left >= right) return 0;
    }
    if(sy < left || sy >= right) return 0;

    return 1;

}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    
    
    cin >> H >> W >> N;
    cin >> sy >> sx;
    sy--; sx--;
    cin >> s >> t;

    if(!solve()) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 3928
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define read(a) scanf("%d", &a)
#define readl(a) scanf("%lld", &a)
#define reads(a) scanf("%s", a)
#define readf(a) scanf("%lf", &a)
#define readc(a) scanf("%c", &a)
#define debug(a, b) printf("%s = %d\n", a, b)
#define debug1(a, i, b) printf("%s[%d] = %d", a, i, b)
#define show(a) putchar(a)
#define pb emplace_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
typedef long long LL;
typedef int Int;
typedef double db;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 5e6 + 7;
char s[N];
ll dp[N];
signed main()
{
    int n, p;
    read(n); read(p);
    reads(s + 1);

    ll ans = 0;
    if(p == 2 || p == 5)
    {
        for(int i = n; i; i--)
            if((s[i]-'0') % p == 0)
                ans += 1ll*i;
    }
    else
    {
        ll d = 1, x = 0;
        for(int i = n; i; i--)
        {
            x += (s[i]-'0') * d;
            x %= p;

            d *= 10;
            d %= p;

            ans += dp[x];
            dp[x]++;
            if(x == 0) ans++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}
/**

**/



Measured memory_bytes: 4020
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,k,m,e;
  vector<int> V;
  while(1){
    cin >> n >> k >> m;
    if(n==0&&k==0&&m==0) break;
    for(int i=1;i<=n;i++) V.push_back(i);
    V.erase(V.begin()+m-1);
    e=(m+k-2+V.size())%V.size();
    while(V.size()!=1){
      V.erase(V.begin()+e);
      e=(e+k-1+V.size())%V.size();
    }
    cout << V[0] << endl;
    V.clear();
  }
  return 0;
}

Measured memory_bytes: 1324
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,k,a,b,c,ct,mx,p;
    map<ll,ll>mp;
    cin>>n>>k;
    ct=0;
    p=n;
    while(n--)
    {
        cin>>m;
        while(m--)
        {
            cin>>a;
            mp[a]++;
        }
        for(int i=1;i<=mp.size();i++)
        {
            mx=mp[i];
            //cout<<"mx: "<<mx;
            //cout<<"  n: "<<p<<endl;
            if(mx==p) ct++;
        }
    }
    cout<<ct<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define ld          long double
const ll N=1e3+3;
vector<ll>g[N];
ll n;

void solve()  
{
	cin>>n;
	for(ll i=1; i<=n; i++)
	{
		ll x;
		for(ll j=0; j<n-1; j++)
		{
			cin>>x;
			g[i].push_back(x);
		}
	}
	/*ll mx;
	  ll l=2, r=n-1;
	while(r-l>1)
	{
		ll mid=(r+l)/2;
		bool fl=1;
		for(ll i=1; i<=n; i++)
		{
			fl=fl&(is_sorted(g[i].begin()+n-mid-1, g[i].end()));
		}
		if(fl==1)
		{
			l=mid;
		}
		else
		{
			r=mid;
		}
	}
		bool fl=1;
		for(ll i=1; i<=n; i++)
		{
			fl=fl&(is_sorted(g[i].begin()+n-1-r, g[i].end()));
		}
		if(fl==1)
		{
			 mx=r;
			for(ll i=1; i<=n; i++)
			{
				vector<ll>t(g[i].begin(), g[i].begin()+n-1-r);
				g[i]=t;
			}
		}
		fl=1;
		for(ll i=1; i<=n; i++)
		{
			fl=fl&(is_sorted(g[i].begin()+n-l-1, g[i].end()));
		}
		if(fl==1)
		{	
			mx=l;
			for(ll i=1; i<=n; i++)
			{
				vector<ll>t(g[i].begin(), g[i].begin()+n-1-l);
				g[i]=t;
			}
		}*/
	ll tot=0, cnt=0, days=0;
	/*if(mx==n-1)
	{
		cout<<n*(n-1)/2<<endl;
		return;
	}
	if(mx>1)
	{
		cnt=mx*(mx-1)/2;
		days=cnt;
	}
	 */
	tot=n*(n-1)/2;
	for(ll i=1; i<=n; i++) reverse(g[i].begin(), g[i].end());
	while(cnt < tot)
	{	
		if(days>=4000)
		{
			cout<<n*(n-1)/2<<endl;
			return;
		}
		set<pair<ll,ll>>s;
		vector<bool>mark(n+1,0);
		for(ll i=1; i<=n; i++)
		{	
			if(mark[i] or g[i].size()==0) continue;
			ll x=g[i][g[i].size()-1];
			ll y=g[x][g[x].size()-1];
			if(y==i)
			{
				s.insert({x, y});
				mark[x]=1;
				mark[y]=1;
			}
		}
		if(s.size()==0) { cout<<-1<<endl; return; }
		cnt += s.size();
		days++;
		for(auto p : s)
		{
			ll f=p.first, se=p.second;
			g[f].pop_back();
			g[se].pop_back();
		}
	}
	cout<<days<<endl;
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
	ll T = 1;
	//cin>>T; 
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 8320
fun main(args: Array<String>) {
    val (H, W, K) = readLine()!!.split(' ').map { it.toInt() }
    val c = (1..H).map { readLine()!! }
    var ans = 0
    for (bitH in 0 until (1 shl H)) {
        for (bitW in 0 until (1 shl W)) {
            val count = c.mapIndexed { i, row ->
                row.mapIndexed { j, ch ->
                    if (ch == '#' && (bitH and (1 shl i) == 0) && (bitW and (1 shl j) == 0)) {
                        1
                    } else {
                        0
                    }
                }.sum()
            }.sum()
            if (count == K) {
                ans++
            }
        }
    }
    println(ans)
}

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

#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 510000;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  long long n, k;
  cin >> n >> k;
  COMinit();
  if(n <= k) {
    cout << COM(n+n-1, n-1) << endl;
  }
  else {
    long long ans = 1;
    for(int i=1;i<=k;i++) {
      ans += COM(n, i) * COM(n-1-i+i, i);
      ans %= MOD;
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
long long a[100001], t;
int main(){
	long long n, q, x, y;
	cin >> n;
	for (long long i=1; i<=n; i++){
		cin >> x;
		t+=x;
		a[x]++;
	}
	cin >> q;
	for (long long i=1; i<=q; i++){
		cin >> x >> y;
		t-=(a[x]*x), t+=(a[x]*y);
		a[y]+=a[x], a[x]=0;
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 4300
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x+r<=w&&x-r>=0&&y+r<=h&&y-r>=0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

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

int main(){

  int n,a,b,c;
  
  while(1){
  
    cin>>n;
    
    if(n==0) break;
    
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      if(a==100 || b==100 || c==100){
	cout<<"A"<<endl;
      }else if((a+b)/2 >= 90){
	cout<<"A"<<endl;
      }else if((a+b+c)/3 >= 80){
	cout<<"A"<<endl;
      }else if((a+b+c)/3 >= 70){
	cout<<"B"<<endl;
      }else if((a+b+c)/3 >= 50 && a >= 80 || (a+b+c)/3 >= 50 && b >= 80){
	cout<<"B"<<endl;
      }else{
	cout<<"C"<<endl;
      }
    }
  }
  
    return 0;
}



Measured memory_bytes: 3096
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
	
		long []sum = new long [n+1];
		
		for(int i = 0 ; i < n ;i++) {
			long a = Long.parseLong(sc.next());
			sum[i+1] = a + sum[i];
		}
		
		Arrays.sort(sum);
		long temp = sum[0];
		long ans = 0;
		int len = 1;
		
		for(int i = 1 ; i <= n+1 ;i++) {
			if(i == n+1) {
				ans += (long)len*(len-1)/2;
				break;
			}
			if(temp == sum[i]) {
				len++;
			}
			else {
				
				ans += (long)len*(len-1)/2;
				len = 1;
			}
			temp = sum[i];
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 63724
// Igorjan94, template version from 13 October 2017. C++17 version, modified 18 march 2020 (writeln<tuple>, whole->all) {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)
#define     SZ(a)    int(size(a))

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

#define pb push_back
#define all(a) begin(a), end(a)
#define ints(a...) int a; readln(a)

[[maybe_unused]] const int MOD = 1000000007;
[[maybe_unused]] const int INTMAX = numeric_limits<int>::max();

#define ttt12i template<class T1, class T2> inline
#define  ttti  template<class T> inline

void writeln(){cout<<"\n";}ttti void print(T&& a);ttti void priws(T&& a);ttti void read(T& a);
template<class... Args> inline void readln(Args&... args){(read(args),...);}
template<class H, class...T> inline void writeln(H&& h,T&&...t){priws(h);(print(t),...);writeln();}

//Igorjan
//}}}

void run()
{
    int n;
    cin >> n;
    ll ans = 0;
    fori1(n + 1)
        forj1(n + 1)
            forn(k, n + 1)
                if (k)
                    ans += gcd(gcd(i, j), k);
    cout << ans << "\n";
                
}

//{{{
int main()
{
    ios_base::sync_with_stdio(false);
    run();
    cerr << fixed << setprecision(0) << "Execution time = " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

#define a _a
#define n _n
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>const&a);
template<typename T,typename D=decltype(*begin(declval<T>())),typename enable_if<!is_same<T,basic_string<char>>::value>::type* =nullptr>
ostream&operator<<(ostream&os,T const&a){auto it=begin(a);if(it!=end(a))os<<*it++;while(it!=end(a))os<<"\n "[is_fundamental<typename T::value_type>::value]<<*it++;return os;}
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>const&a){return os<<a.first<<" "<<a.second;}
ttt12i istream&operator>>(istream&is,pair<T1,T2>&a){return is>>a.first>>a.second;}
ttti   istream&operator>>(istream&is,vector<T>&a){fori(a.size())is>>a[i];return is;}
ttti void print(T&&a){cout<<" "<<a;}
ttti void priws(T&&a){cout<<a;}
ttti void read(T&a){cin>>a;} //}}}

Measured memory_bytes: 3260
#include<iostream>
#include<string>
using namespace std;
int main(){
	string taro;
	string hanako;
	int p_taro=0;
	int p_hana=0;
	int n;
	
	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>taro>>hanako;
		if(taro>hanako)
			p_taro+=3;
		else if(taro<hanako)
			p_hana+=3;
		else if(taro==hanako){
			p_taro+=1;
			p_hana+=1;
		}
	}
	cout<<p_taro<<" "<<p_hana<<endl;
}

Measured memory_bytes: 1208