akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include <deque>
using namespace std;

#define P 1000000007
int n;
char S[510][510];

bool have[510];
int ss[510];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%s", S[i] + 1);
	int s = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (S[i][j] == '#')
				s += 1, have[j] = true, ss[j] += 1;
	if (s == 0) {
		printf("-1\n");
		return 0;
	}
	int ans = 2 * n;
	for (int i = 1; i <= n; i++) {
		int sum = 0;
		for (int j = 1; j <= n; j++) {
			if (S[i][j] == '.')
				sum += 1;
		}
		if (!have[i] && sum != 0)
			sum += 1;
		
		for (int p = 1; p <= n; p++)
			if (S[i][p] == '#' && ss[p] == n)
				sum -= 1;
		sum += n;
		ans = min(ans, sum);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 512
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
typedef long long LL;
const int N=1e5+5,P=1e9+7;

int n;
char S[N];
LL s[N];
int app_a[N],app_b[N];//在当前状态下加一个a后转移到的状态
int nex[N][3];//下一个，前缀和%3=i的位置（不算当前的位置）
int nex_xx[N];//下一个连续相同字符的位置， nex_xx[i] 和nex_xx[i]+1相同
LL f[N];

int main(){
    scanf("%s",S+1);
    n=strlen(S+1);
    FOR(i,1,n)s[i]=S[i]=='a'?1:2;
    FOR(i,2,n)s[i]+=s[i-1];
    nex[n][0]=nex[n][1]=nex[n][2]=n+1;
    nex[n+1][0]=nex[n+1][1]=nex[n+1][2]=n+1;
    ROF(i,n-1,0){
        FOR(j,0,2)nex[i][j]=s[i+1]%3==j?i+1:nex[i+1][j];
    }
    //FOR(i,0,n)printf("%d%c",nex[i][0]," \n"[i==n]);
    //FOR(i,0,n)printf("%d%c",nex[i][1]," \n"[i==n]);
    //FOR(i,0,n)printf("%d%c",nex[i][2]," \n"[i==n]);
    nex_xx[n]=nex_xx[n+1]=n+1;
    ROF(i,n-1,0){
        nex_xx[i]=s[i+1]-s[i]==s[i+2]-s[i+1]?i+1:nex_xx[i+1];
    }
    //FOR(i,0,n)printf("%d%c",nex_xx[i]," \n"[i==n]);
    FOR(i,0,n){
        app_a[i]=s[i+1]-s[i]==1?i+1:nex[nex_xx[i]][(s[i]+1)%3];
        app_b[i]=s[i+1]-s[i]==2?i+1:nex[nex_xx[i]][(s[i]+2)%3];
    }
    //FOR(i,0,n)printf("%d%c",app_a[i]," \n"[i==n]);
    //FOR(i,0,n)printf("%d%c",app_b[i]," \n"[i==n]);
    f[0]=1;
    FOR(i,0,n){
        f[app_a[i]]=(f[app_a[i]]+f[i])%P;
        f[app_b[i]]=(f[app_b[i]]+f[i])%P;
    }
    LL ans=0;
    FOR(i,1,n)if(s[i]%3==s[n]%3)ans=(ans+f[i])%P;
    if(nex_xx[0]==n+1)puts("1");
    else printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
string s;
int k;
int main(){
cin>>s>>k;
for(auto &ch:s) if (ch!='a'&&'z'-ch+1<=k){
k-=('z'-ch+1);
ch='a';

}
k%=26;
s[s.length()-1]+=k;
cout<<s<<'\n';
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//??????????????§????????§??????????????§?????????

int main(void){
	int N;
	cin>>N;
	int num[100001]={};
	int a,b,min=999999,max=-1,ans=0;
	rep(i,N){
		cin>>a>>b;
		reg(i,a,b)num[i]++;
		if(a<min)min=a;
		if(b>max)max=b;
	}
	reg(i,min,max){
		if(num[i]+1>=i)ans=i-1;
	}

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

Measured memory_bytes: 3492
N = int(input())
def cnt_div(n):
    cnt = 0
    for i in range(1,n+1):
        if i*i>n:break
        if n%i==0:
            cnt+=1
            if n//i!=i:
                cnt+=1
    return cnt
cnt = 0
for i in range(1,N+1):
    if i%2==1 and cnt_div(i)==8:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 199999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int h, w;
	cin >> h >> w;
	string mz = "";
	string wall = "#";
	REP(i, w+1) wall += "#";
	mz += wall;
	string s;
	REP1(i, h){
		cin >> s;
		mz += "#" + s + "#";
	}
	mz += wall;
	//cout << mz << endl;
	//隣接テーブルをつくる
	int n = h*w;
	int tab[h*w][h*w] = {};
	REP(i, n) REP(j, n) tab[i][j] = INF;
	REP1(i, h){
		REP1(j, w){
			if(mz[(w+2) * i + j] == '#') continue;
			REP(k, 4){
				int sta = w * (i-1) + j - 1;
				int sza = (w+2) * i + j;
				int goa, gza;
				if(k == 0){
					goa = sta - w;
					gza = sza - w - 2;
				}
				if(k == 1){
					goa = sta - 1;
					gza = sza - 1;
				}
				if(k == 2){
					goa = sta + 1;
					gza = sza + 1;
				}
				if(k == 3){
					goa = sta + w;
					gza = sza + w + 2; 
				}
				tab[sta][sta] = 0;
				if(mz[gza] == '.'){
					tab[sta][goa] = 1;
					tab[goa][sta] = 1;
				}
			}
		}
	}
	/*
	REP(i, n){
		REP(j, n){
			cout << tab[i][j] << " " ; 
		}
		cout << endl;
	}
	*/
	//
	REP(k, n){
		REP(i, n){
			REP(j, n){
				tab[i][j] = min(tab[i][j], tab[i][k] + tab[k][j]);
			}
		}
	}
	ans = 0;
	REP(i, n){
		REP(j, n){
			if(tab[i][j] < INF) ans = max(ans, tab[i][j]);
		}
	}
	cout << ans << endl;
}

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

int x;

bool check(int n)
{
    for(int i = 2; i <= sqrt(n); ++i) {
        if(n%i == 0) {
            int temp = n;
            while(temp%i == 0) temp /= i;
            if(temp == 1) return true;
        }
    }
    return false;
}

int main()
{
    scanf("%d", &x);
    if(x == 1) {
        printf("1\n");
        return 0;
    }
    for(int i = x; i >= 1; --i) {
        if(check(i) || i == 1) {
            printf("%d\n", i);
            return 0;
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  string s;
  cin >> s;
  cout << s[0] << s.size()-2 << s[s.size()-1] << endl;

  return 0;
}


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

int main() {
    int x = 0;
    int y = 0;
    int bonus = 200;
    int c = 0;

    int n;

    cin >> n;

    for(int i = 0;i < n; i++){
        x += 800;
        c ++;
        if(c%15==0){
            y += bonus;
        }
    }

    cout << x-y << endl;
}

Measured memory_bytes: 256
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    A = kwargs["A"]
    B = [0 for i in range(n)]
    for i in range(n - 1):
        B[i+1] = max(0, A[i] + B[i] - A[i+1])
    if n > 1:
        B[-1] = max(0, A[-2] + B[-2] - A[-1])
    res = sum(B)
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    cin = input().split()
    kwargs["A"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 62892
n = int(input())
a = [int(x) for x in input().split()]
a.append(0)
a.insert(0,0)
sm = 0

for i in range(1,len(a)):
    sm += abs(a[i] - a[i-1])

for i in range(1,len(a)-1):
    dis1 = abs(a[i-1] - a[i]) + abs(a[i+1] - a[i])
    dis2 = abs(a[i-1] - a[i+1])
    print(sm - dis1 + dis2)


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

int main() {
    long long N; cin >> N;
    vector<long long>A(3 * N);
    long long ans = 0;
    for (long long i = 0; i < 3 * N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end(), greater<long long>());
    for (long long i = 1; i < 2 * N; i += 2) {
        ans += A.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main(){


  string s,t;
  cin >> s >> t;

  if(t.size() != s.size() + 1) cout << "No" << endl;

  bool ok=true;
  for(int i = 0; i < s.size(); i++){
    if(s[i] != t[i]){ ok = false; break;}
  }

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

  return 0;
}


Measured memory_bytes: 3628
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    s = [input().strip() for i in range(N)]
    
    ans = 0
    ba = 0
    b_ = 0
    _a = 0
    for c in s:
        ans += c.count("AB")
        if c[0] == "B":
            if c[-1] == "A":
                ba += 1
            else:
                b_ += 1
        elif c[-1] == "A":
            _a += 1
    if ba == 0:
        ans += min(b_, _a)
    elif b_ + _a > 0:
        ans += ba + min(b_, _a)
    elif b_ + _a == 0:
        ans += ba - 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3700
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N,greater<lint>());
    lint ans=0;
    rep(i,N-1) ans+=A[(i+1)/2];
    cout << ans << endl;
}

Measured memory_bytes: 5208
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>

using namespace std;
typedef long long lint;

const int MAXK = 4020;
int whiteBoard[MAXK][MAXK];
int blackBoard[MAXK][MAXK];
int whiteSumBoard[MAXK][MAXK];
int blackSumBoard[MAXK][MAXK];

void calcSumBoard(int board[MAXK][MAXK], int sumBoard[MAXK][MAXK], const int K) {
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < K; j++) {
            sumBoard[i+1][j+1] = sumBoard[i+1][j] + sumBoard[i][j+1] - sumBoard[i][j] + board[i][j];
        }
    }
}

// [left, right), [bottom, upper)
int calcSum(int left, int right, int bottom, int upper, int sumBoard[MAXK][MAXK]) {
    return sumBoard[upper][right] - sumBoard[upper][left] - sumBoard[bottom][right] + sumBoard[bottom][left];
}

int main() {
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        x %= 2*K;
        y %= 2*K;
        for (int dx = 0; dx < 2; dx++) {
            for (int dy = 0; dy < 2; dy++) {
                if (c == 'B') {
                    blackBoard[y+dy*2*K][x+dx*2*K]++;
                } else {
                    whiteBoard[y+dy*2*K][x+dx*2*K]++;
                }
            }
        }
    }
    calcSumBoard(whiteBoard, whiteSumBoard, 4*K);
    calcSumBoard(blackBoard, blackSumBoard, 4*K);
    int ans = 0;
    for (int y = 0; y <= 2*K; y++) {
        for (int x = 0; x <= 2*K; x++) {
            int tmp = 0;
            tmp += calcSum(0, x, 0, y, whiteSumBoard);
            tmp += calcSum(0, x, y, y+K, blackSumBoard);
            tmp += calcSum(0, x, y+K, 2*K, whiteSumBoard);
            tmp += calcSum(x, x+K, 0, y, blackSumBoard);
            tmp += calcSum(x, x+K, y, y+K, whiteSumBoard);
            tmp += calcSum(x, x+K, y+K, 2*K, blackSumBoard);
            tmp += calcSum(x+K, 2*K, 0, y, whiteSumBoard);
            tmp += calcSum(x+K, 2*K, y, y+K, blackSumBoard);
            tmp += calcSum(x+K, 2*K, y+K, 2*K, whiteSumBoard);
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 252416
#include <stdio.h>

int main()
{
    int a, b;

    scanf("%d %d", &a, &b);

    if(a < b){
        printf("a < b\n");
    }
    else if(a > b){
        printf("a > b\n");
    }
    else {
        printf("a == b\n");
    }

    return 0;
}



Measured memory_bytes: 2000
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] input = sc.nextLine().split("[\\s]+");
    int N = Integer.parseInt(input[0]);
    int K = Integer.parseInt(input[1]);
    String[] inputX = sc.nextLine().split("[\\s]+");
    int[] x = new int[N];
    for(int i = 0; i < N; i++) {
      x[i] = Integer.parseInt(inputX[i]);
    }
    int min = 0;
    for(int i = 0; i < N - K + 1; i++) {
      int sum1 = Math.abs(x[i]) + Math.abs(x[i+K-1] - x[i]);
      int sum2 = Math.abs(x[i+K-1]) + Math.abs(x[i+K-1] - x[i]);
      int sum = Math.min(sum1,sum2);
      if(i == 0 || sum < min) {
        min = sum;
      }
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 48384
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    a = bisect.bisect_left(A,b)
    c = n - bisect.bisect_left(C,b+1)
    ans += a*c
print(ans)

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; 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(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll powmod(ll x, ll n){
    ll res=1;
    while(n>0){
        if(n&1) res = res*x%MOD;
        x = x*x%MOD;
        n>>=1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    lvec c(n);
    VIN(c);
    sort(c.begin(), c.end());
    ll MAX =5*1e5+1;
    lvec fac(MAX), finv(MAX);
    COMinit(MAX, fac, finv);
    ll ans=0;
    REP(i, n){
        ll j =  i+1;
        ans += (powmod(2, j-1)*c[i]%MOD)*(powmod(2, n-j)+(n-j)*powmod(2, n-j-1)%MOD);
        ans %= MOD;
    }
    cout << ans*powmod(2, n)%MOD << endl;
}

Measured memory_bytes: 13568
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    cout << H*W-h*W-(H-h)*w << "\n";
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
vector <long long> A;
vector <long long> B;
int N;
int M = 30;
int main(void) {
	long long ans = 0;
	long long T = 1;
	cin >> N;
	rep(i, N) { 
		long long p;
		cin >> p;
		A.push_back(p);
	}
	rep(i, N) { 
		long long p;
		cin >> p;
		B.push_back(p);
	}
	rep(k, M) {
		vector <long long> C;
		vector <long long> D;
		rep(i, N) { 
			C.push_back(B[i] % (2 * T));
			D.push_back(A[i] % (2 * T));
		}
		sort(C.begin(),C.end());
		long long tmp = 0;
		rep(i, N) {
			tmp += lower_bound(C.begin(), C.end(), 2 * T - D[i]) - C.begin();
			tmp -= lower_bound(C.begin(), C.end(), 1 * T - D[i]) - C.begin();
			tmp += lower_bound(C.begin(), C.end(), 4 * T - D[i]) - C.begin();
			tmp -= lower_bound(C.begin(), C.end(), 3 * T - D[i]) - C.begin();
		}
		ans += T * (tmp % 2);
		T = T * 2;
	}
	cout << ans << endl;
	return 0;
}


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

int block[61][61];
int dist[61][61];

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

int main() {
  while (1) {
    memset(dist, -1, sizeof(dist));
    int h, w;
    cin >> w >> h;
    if(w + h == 0) break;
    w = w * 2 - 1;
    h = h * 2 - 1;
    rep(i, h) {
      if (i % 2 == 0) {
        rep(j, w) if (j % 2 == 1) cin >> block[i][j];
      } else {
        rep(j, w) if (j % 2 == 0) cin >> block[i][j];
      }
    }

    queue<P> q;
    q.push(P(0, 0));
    dist[0][0] = 1;
    while (!q.empty()) {
      int i = q.front().first;
      int j = q.front().second;
      P now = P(i, j);
      q.pop();
      rep(d, 4) {
        int ni = i + di[d], nj = j + dj[d];
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (block[ni][nj] == 1) continue;

        ni = i + di[d] * 2;
        nj = j + dj[d] * 2;
        if (dist[ni][nj] > 0) continue;
        dist[ni][nj] = dist[i][j] + 1;
        q.push(P(ni, nj));
      }
    }
    // rep(i, h) {
    //   rep(j, w) printf("%3d", dist[i][j]);
    //   cout << endl;
    // }
    int ans = max(0, dist[h - 1][w - 1]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3100
import bisect


def count(text, s, rgb_bag):
    ans = 0
    for i in rgb_bag[text[0]]:
        for j in rgb_bag[text[1]]:
            if i > j:
                continue
            k = bisect.bisect_left(rgb_bag[text[2]], j)
            ans += len(rgb_bag[text[2]]) - k
            ng_idx = j + (j - i)
            if ng_idx >= len(s):
                continue
            if s[ng_idx] == text[2]:
                ans -= 1
    return ans


def main():
    n = int(input())
    s = input()
    rgb_bag = {'R': [], 'G': [], 'B': []}
    for i, v in enumerate(s):
        rgb_bag[v].append(i)
    ans = 0

    for r in 'RGB':
        for g in 'RGB':
            for b in 'RGB':
                if r == g or g == b or b == r:
                    continue
                ans += count(r+g+b, s, rgb_bag)
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    int n;
    string a, b, c;
    int cnt = 0;

    cin >> n >> a >> b >> c;

    for (int i = 0; i < n; i++) {
        int same = 0;
        if (a[i] == b[i]) {
            same++;
        }
        if (b[i] == c[i]) {
            same++;
        }
        if (c[i] == a[i]) {
            same++;
        }
        if (same == 0) {
            cnt += 2;
        } else if(same == 1) {
            cnt += 1;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=0,n,r;
    cin>>n>>r;
    ans=(n<10)?(r+(100*(10-n))):(r);
    cout<<ans<<endl;



    return 0;

}

Measured memory_bytes: 256
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=sc.nextInt();
		int su;
		int num=0;
		String mark;
		Boolean s[]=new Boolean[52];
		Arrays.fill(s, false);//s[]の配列に初期値falseを設定
		
		for(int i=0;i<n;i++){
			mark=sc.next();
			su=sc.nextInt();
			
			if(mark.equals("S")) num=0;
			else if(mark.equals("H"))	num=13;
			else if(mark.equals("C"))	num=26;
			else if(mark.equals("D"))	num=39;
			
			s[num+su-1]=true;
		}//for
		
		
		for(int i=0;i<52;i++){
			if(i<13 && s[i]==false){
				System.out.println("S "+(i+1)); 
			}else if(i<26 && s[i]==false){
				System.out.println("H "+(i-12)); 
			}else if(i<39 && s[i]==false){
				System.out.println("C "+(i-25)); 
			}else if(i<52 && s[i]==false){
				System.out.println("D "+(i-38)); 
			}else continue;
		}//for
	}
}

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

using ull = unsigned long long;

template <typename F>
struct y_comb {
  F func;

  template <typename... Args>
  decltype(auto) operator()(Args&&... args) {
    return func(*this, std::forward<Args>(args)...);
  }

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

template <typename F>
y_comb(F) -> y_comb<F>;

constexpr ull maxAns = 1ull << 40;

int main() {
  int ntc;
  cin >> ntc;
  for (int itc = 0; itc < ntc; itc++) {
    ull n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    unordered_map<ull, ull> memo;
    auto f = y_comb{[&](auto& self, ull x) -> ull {
      ull& ret = memo[x];
      if (ret) return ret;
      if (x == 0) return 0;
      ret = (x < maxAns / d) ? x * d : maxAns;
      int r2 = x % 2;
      ret = min(ret, a + (r2 == 0 ? self(x / 2)
                                  : d + min(self(x / 2), self(x / 2 + 1))));
      int r3 = x % 3;
      ret = min(ret, b + (r3 <= 1 ? r3 * d + self(x / 3)
                                  : (3 - r3) * d + self(x / 3 + 1)));
      int r5 = x % 5;
      ret = min(ret, c + (r5 <= 2 ? r5 * d + self(x / 5)
                                  : (5 - r5) * d + self(x / 5 + 1)));
      return ret;
    }};
    cout << f(n) << '\n';
  }
  return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> ans(N+1,0);
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    ans.at(a)++;
    ans.at(b)++;
  }
  for(int i=1;i<=N;i++){
    cout << ans.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int n;
const int MAX = 110;
const int INF = 1e9;
int D[MAX];
struct edge{
    int cost, to;
};
vector<edge> G[MAX];

void dijkstra(int s){
    for(int i = 0; i < n; i++){
        D[i] = INF;
    }
    D[s] = 0;
    priority_queue<P, vector<P>, greater<P>> q;
    q.push({0, s});
    while(!q.empty()){
        P p = q.top();
        q.pop();
        int now = p.second;
        for(int i = 0; i < G[now].size(); i++){
            edge e = G[now][i];
            if(D[e.to] > D[now] + e.cost){
                D[e.to] = D[now] + e.cost;
                q.push({D[e.to], e.to});
            }
        }
    }
}

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

    cin >> n;
    for(int i = 0; i < n; i++){
        int u, k;
        cin >> u >> k;
        for(int i = 0; i < k; i++){
            int v, c;
            cin >> v >> c;
            G[u].push_back({c, v});
        }
    }

    dijkstra(0);

    for(int i = 0; i < n; i++){
        cout << i << ' ' << D[i] << endl;
    }

    return 0;
}


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

int N, M, Q;
int res = 0;
vector<int> a, b, c, d;
vector<int> A(15, 0);

int dsf(int lower, int num){
  if(lower == M || num == N){
    int sum = 0;
    for(int i = num; i <= N; i++) A[i] = lower;
    for(int i = 0; i < Q; i++){
      if(A[b[i]] - A[a[i]] == c[i]) sum += d[i];
    }
    return sum;
  }
  int MAX = 0;
  A[num] = lower;
  for(int k = lower; k <= M; k++) MAX = max(MAX, dsf(k, num+1));
  return MAX;
}

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

  int ta, tb, tc, td;
  for(int i = 0; i < Q; i++){
    cin >> ta >> tb >> tc >> td;
    a.push_back(ta); b.push_back(tb);
    c.push_back(tc); d.push_back(td);
  }

  for(int k = 1; k <= M; k++){
    res = max(res, dsf(k, 1));
  }

  cout << res << endl;
  return 0;
  
}

Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	ll l, K; scanf("%lld %lld", &l, &K);
	vector<vector<vector<ll>>> dp(150, vector<vector<ll>>(l + 1, vector<ll>(2)));
	dp[0][1][0] = 1;
	if(K <= l) dp[0][K][0] = 1;
	ll res = 0;
	for (int i = 0; i < 149; i++) {
		for (int j = 0; j <= l; j++) {
			for (int k = 0; k < 2; k++) {
				//dp[i + 1][j][k] += dp[i][j][k];
				if (j + 1 <= l) dp[i + 1][j + 1][k ^ 1] += dp[i][j][k];
				if(k == 1) if (j + K <= l) dp[i + 1][j + K][k ^ 1] += dp[i][j][k];
			}
		}
	}
	for (int j = 0; j < 150; j++) {
		//cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << j << "^^^^^^^^^^^^^^^^^^^^^^" << endl;
		for (int i = 0; i <= l; i++) {
			res += dp[j][i][0];
			//cout << dp[j][i][0] << endl;
		}
	}
	cout << res << endl;
	return 0;

}



Measured memory_bytes: 4096
fun main(args: Array<String>) {
    val n_k = readLine()!!.split(" ").map(String::toInt)
    val h = readLine()!!.split(" ").map(String::toInt)
    var count = 0
    for (i in 0 until n_k[0]){
        if(h[i] >= n_k[1]){
            count += 1
        }
    }
    println(count)
}

Measured memory_bytes: 46200
#include<stdio.h>
int main(void)
{
int i,imax,n, nmin, nmax, a[10000], max, s;
while(scanf("%d %d %d",&n,&nmin,&nmax))
{
if(n==0&&nmin==0&&nmax==0)
break ;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
max = 0;
for(i=nmin;i<=nmax;i++)
{
s = a[i-1]-a[i];
if(s>=max)
  {
imax=i;
max=s;
  }
}
printf("%d\n",imax);
}
return 0;
}



Measured memory_bytes: 2044
getBonusScore :: [Int] -> [Int] -> Int -> Int
getBonusScore inList cList ans
 | null inList = ans
 | otherwise   = getBonusScore (tail inList) cList $ ans + ( cList !! (head inList - 2) )

main = do
 getLine
 aList <- map read . words <$> getLine :: IO [Int]
 bList <- map read . words <$> getLine :: IO [Int]
 cList <- map read . words <$> getLine :: IO [Int]
 let normalScore = sum bList
 let bonuxIndex = filter (\x -> x /= 0) . zipWith (*) aList $ 0:(map (\x -> if x == 1 then 1 else 0) $ zipWith (-) (tail aList) aList)
 print $ (getBonusScore bonuxIndex cList 0) + normalScore

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

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int N = sc.nextInt();

    double ans = 0.0;
    int a = N / 2 + (N % 2);
    ans = (double) a / N;

    System.out.println(ans);

  }
}

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

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    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 int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int 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 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();
    }
  }
}

Measured memory_bytes: 22356
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000;
const double PI = acos(-1);
const int mod = 1000000007;

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

    for (int n = 1; n <= 1000; n++) {
        for (int i = 100 * n; i <= 105 * n; i++) {
            if (i == x) {
                cout << 1 << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    return 0;
}


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

int main(void) {
	
	vector<int> A;
	for(int i=0; i<3; i++) {
		int a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());
	
	cout << abs(A[0]-A[1])+abs(A[2]-A[1]);

	return 0;
}

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

int main() {
    ll X;
    cin >> X;

    ll n500 = X / 500;
    ll t = X % 500;

    ll n5 = t / 5;

    cout << n500 * 1000 + n5 * 5 << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
k=0
h[0]-=1
for i in range(n-1):
    if h[i]>h[i+1]:
        print("No")
        break
    elif h[i]<h[i+1]:
        h[i+1]-=1
        k+=1
    else:
        k+=1
if k==n-1:
    print("Yes")

Measured memory_bytes: 14396
n = 0
ans = 0
mods = [0]*2019
mods[0] = 1
for i, j in enumerate(reversed(input())):
  n = (n+int(j)*pow(10, i, 2019))%2019
  mods[n] += 1
for i in mods: ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=5e5+5,M=5e3+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,m;
ll f[N][3],bad[N];
struct mat{
	ll x[3][3];
	mat friend operator*(mat a,mat b){
		mat c;clr(c.x);
		re(i,0,3)re(j,0,3)re(k,0,3)(c.x[i][j]+=a.x[i][k]*b.x[k][j]%mod)%=mod;
		return c;
	}
};
mat qpow(mat a,int b){
	mat c;clr(c.x);re(i,0,3)c.x[i][i]=1;
	for(;b;b>>=1,a=a*a)if(b&1)c=c*a;
	return c;
}
int main(){
	read(n,m);
	mat f=(mat){1,0,1,2,1,2,1,1,2};
	mat g=(mat){1,0,0,2,1,0,1,1,1};
	mat f0;clr(f0.x);
	//f0.x[0][0]=1;f0.x[1][0]=2;f0.x[2][0]=1;
	re(i,0,3)f0.x[i][i]=1;
	rep(i,1,m){bad[i]=read();}
	bad[++m]=n;
	re(i,1,m)f0=f0*qpow(f,bad[i]-bad[i-1]-1)*g;
	f0=f0*qpow(f,bad[m]-bad[m-1]-1);
	cout<<(f0.x[2][0]+f0.x[2][1]*2+f0.x[2][2])%mod;
	//cout<<f0.x[2][0];
	/*
	rep(i,1,m)bad[read()-1]=1;
	f[0][0]=1;f[0][1]=2;f[0][2]=1;
	rep(i,0,n-1){
		if(bad[i]){
			f[i+1][0]=(f[i][0])%mod;
			f[i+1][1]=(f[i][0]*2+f[i][1])%mod;
			f[i+1][2]=(f[i][0]+f[i][1]+f[i][2])%mod;
			continue;
		}
		f[i+1][0]=(f[i][0]+f[i][2])%mod;
		f[i+1][1]=(f[i][0]*2+f[i][1]+f[i][2]*2)%mod;
		f[i+1][2]=(f[i][0]+f[i][1]+f[i][2]*2)%mod;
	}
	cout<<f[n][2];*/
}

Measured memory_bytes: 1024
import java.util.*;


import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		ArrayDeque<Integer>[] qa = new ArrayDeque[n];
		for(int i = 0; i < n; i++) {
			qa[i] = new ArrayDeque<Integer>(n);
			for(int j = 0; j < n - 1; j++) {
				qa[i].add(ni());
			}
		}

		int result = 0;
		boolean[] checked = new boolean[n];
		boolean[] matchedBefore = new boolean[n];
		Arrays.fill(matchedBefore, true);
		
		while(true) {
			//Completion check
			boolean isComp = true;
			for(int i = 0; i < n; i++) {
				isComp = isComp && qa[i].isEmpty();
			}
			if(isComp)break;
			
			//Find match
			boolean matchable = false;			
			for(int i = 0; i < n; i++) {
				if(!matchedBefore[i])continue;
				if(qa[i].isEmpty() || checked[i])continue;
				int target = qa[i].peek();
				if(!checked[target - 1] && qa[target - 1].peek() == i + 1) {
					qa[i].poll();
					qa[target - 1].poll();
					checked[i] = true;
					checked[target - 1] = true;
					matchable = true;
					matchedBefore[i] = true;
					matchedBefore[target - 1] = true;
				} else {
					matchedBefore[i] = false;
				}
			}
			
			//Continue check
			if(!matchable) {
				result = -1;
				break;
			} else {
				result++;
				Arrays.fill(checked, false);
			}			
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		} 
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 71928
from collections import Counter
n=int(input())
a=[]
for _ in range(n):
    a.append(input())
m=int(input())
b=[]
for _ in range(m):
    b.append(input())
a=Counter(a)
b=Counter(b)

ans=0
for k,v in a.items():
    tmp=v
    if k in b:
        tmp-=b[k]
    ans=max(ans, tmp)
print(ans)




Measured memory_bytes: 3316
a, b, c, d = map(int, input().split())

x_dis = c - a
y_dis = d - b

for i in range(y_dis):
    print('U', end='')

for i in range(x_dis):
    print('R', end='')

for i in range(y_dis):
    print('D', end='')

for i in range(x_dis+1):
    print('L', end='')

for i in range(y_dis+1):
    print('U', end='')

for i in range(x_dis+1):
    print('R', end='')

print('D', end='')
print('R', end='')

for i in range(y_dis+1):
    print('D', end='')

for i in range(x_dis+1):
    print('L', end='')

print('U')

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

public class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    int[][] arr = new int[n][3];
    for(int i=0;i<n;i++){
      String[] s = br.readLine().split(" ");
      arr[i][0] = Integer.parseInt(s[0]);
      arr[i][1] = Integer.parseInt(s[1]);
      arr[i][2] = Integer.parseInt(s[2]);
      //System.out.println(arr[i][0]+" "+arr[i][1]+" "+arr[i][2]);
    }
    int[][] dp = new int[n][3];
    int max = 0;
    for(int i=0;i<3;i++){
      dp[0][i] = arr[0][i];
      max = Math.max(max,dp[0][i]);
    }
    
    if(n==1)
      System.out.println(max);
    else{
      for(int i=1;i<n;i++){
        dp[i][0] = arr[i][0] + Math.max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = arr[i][1] + Math.max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = arr[i][2] + Math.max(dp[i-1][0],dp[i-1][1]);
      }
    
    
    for(int i=0;i<3;i++){
      max = Math.max(max,dp[n-1][i]);
    }
    System.out.println(max);
    }
  }
}

Measured memory_bytes: 59888
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        String S;
        try (Scanner sc = new Scanner(System.in)) {
            S = sc.next();
        }
        char[] c = S.toCharArray();
        if(c[0]==c[1] && c[1]==c[2]){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 22100
N=int(input())
L=list(map(int,input().split()))
L = sorted(L)

def binary_search(func, array, left=0):
    right=len(array)-1
    y_left, y_right = func(array[left]), func(array[right])
    if y_left==False:return 0
    while True:
        middle = (left+right)//2
        y_middle = func(array[middle])
        if y_left==y_middle: left=middle
        else: right=middle
        if right-left==1:break

    return left

SUM = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    l = L[i]+L[j]
    if L[-1]<l:
      k = N-1
    else:
      k = binary_search(lambda x: x<l, L, j+1)
    SUM += max(0,k-j)

print(SUM)

Measured memory_bytes: 69028
def solve():
    ans = 1000000
    for i in range(2):
        if H[i] % 3 == 0:
            return 0
        ans = min(ans, H[1 - i])
        H1 = H[i] // 3
        S_max = (H1 + 1) * H[1 - i]
        S_min = (H[i] - H1 - 1) * (H[1 - i] // 2)
        ans = min(ans, S_max - S_min)
        S_min = H1 * H[1 - i]
        S_max = (H[i] - H1) * ((H[1 - i] + 1) // 2)
        ans = min(ans, S_max - S_min)
    return ans

H = list(map(int, input().split()))
print(solve())

Measured memory_bytes: 38512
import sys; sys.setrecursionlimit(50000)
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

import heapq
q = []
S = set()
heapq.heappush(q, (-(A[0]+B[0]+C[0]), 0, 0, 0))
S.add((0, 0, 0))
for _ in range(K):
    p, i, j, k = heapq.heappop(q)
    print(-p)
    if i + 1 < X and not (i+1, j, k) in S:
        heapq.heappush(q, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
        S.add((i+1,j,k))
    if j + 1 < Y and not (i, j+1, k) in S:
        heapq.heappush(q, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
        S.add((i,j+1,k))
    if k + 1 < Z and not (i, j, k+1) in S:
        heapq.heappush(q, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
        S.add((i,j,k+1))


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

vector<int> ans(31);

void swap(int a, int b){
  int tmp = ans[a];
  ans[a] = ans[b];
  ans[b] = tmp;
}

int main(){
  int w, n;

  cin >> w >> n;
  for(int i=1; i<=w; i++) ans[i] = i;

  for(int i=0; i<n; i++){
    int a, b;
    scanf("%d,%d", &a, &b);
    swap(a,b);
  }

  for(int i=1; i<=w; i++) cout << ans[i] << endl;
}
  


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


	int main() {
		int x, y;
		cin >> x >> y;
		int ans = 1;
		if (x == y) {
			ans = x;
		}
		else {
			if (y > x) {
				int tmp = x;
				x = y;
				y = tmp;
			}
			int q = x % y;

			for (int i = 1; i <= q; i++) {
				int A = y % i;
				int B = q % i;
				if (A == 0 && B == 0) {
					ans = i;
				}
			}
		}
		
		cout << ans << endl;
		return 0;
	}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n;
int main(){
	cin>>n;
	FOR(i,1,n-1){
		FOR(j,i+1,n){
			FOR(k,0,10) if (((i>>k)&1)!=((j>>k)&1)){printf("%d ",k+1);break;}
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 512