akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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 MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

int n, k, MOD;
int dp[85][85][85], cur[85][85];
int pw2[85];

int main()
{
	scanf("%d%d%d", &n, &k, &MOD);
	
	int ans = 0;
	if(k % 2 == 0) {
		cur[0][0] = 1;
		rep1(i, (n + 3) / 2) rep1(j, min(i, k / 2 + 1))
		cur[i][i] = (cur[i][i] + cur[i - j][i - j]) % MOD;
		ans = 1LL * cur[n / 2 + 1][n / 2 + 1] * cur[(n + 3) / 2][(n + 3) / 2] % MOD;
		printf("%d\n", ans);
		return 0;
	}
	
	int n0 = (n + 1) / 2, n1 = n / 2;
	k = (k + 1) / 2;
	
	pw2[0] = 1;
	rep(i, n0) pw2[i + 1] = 2 * pw2[i] % MOD;
	
	n0 += 2;
	n1 += 2;
	
	for(int i = 0; i <= k; i ++) dp[0][1][i] = pw2[max(i - 1, 0)];
	
	rep(i, n0) for(int j = 0; j <= i + 1; j ++)
	rep(lj, n1) {
		if(lj >= j + k || j <= i && lj != j + k - 1 && lj < i - k) {
			dp[i][j][lj] = 0;
			continue;
		}
		dp[i + 1][j][lj] = (dp[i + 1][j][lj] + dp[i][j][lj]) % MOD;
		if(i - j >= 2 * k) {
			for(int nj = i - k; nj < n1; nj ++)
			dp[i + 1][i + 2][nj] = (dp[i + 1][i + 2][nj] + 1LL * pw2[max(nj - i + k - 1, 0)] * dp[i][j][lj]) % MOD;
		} else {
			dp[i + 1][i + 2][lj] = (dp[i + 1][i + 2][lj] + dp[i][j][lj]) % MOD;
			for(int nj = j + k; nj < n1; nj ++)
			dp[i + 1][i + 2][nj] = (dp[i + 1][i + 2][nj] + 1LL * pw2[nj - j - k] * dp[i][j][lj]) % MOD;
		}
	}
	
	printf("%d\n", dp[n0 - 1][n0][n1 - 1]);
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> counter;
    int res = 0;
    rep(i, n) {
        cin >> a[i];
        counter[a[i]]++;
    }
    sort(a.begin(), a.end());
    set<int> s(a.begin(), a.end());
    a.assign(s.begin(), s.end());
    n = a.size();
    for (int i=0; i<n-2; i++) {
        for (int j=i+1; j<n-1; j++) {
            for (int k=j+1; k<n; k++) {
                if (a[i]+a[j] > a[k] && a[k]-a[j] < a[i]) {
                    res += counter[a[i]]*counter[a[j]]*counter[a[k]];
                }
                else break;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

vector<vector<int>> G(101010);
ll dist[101010][3];
int N,M,S,T;

int main(){
  cin>>N>>M;
  rep(i,M){
    int u,v; cin>>u>>v; u--,v--;
    G[u].push_back(v);
  }
  cin>>S>>T; S--,T--;
  
  rep(i,N) rep(j,3) dist[i][j]=-1;
  queue<pair<int,int>> que;
  que.push({S,0});
  dist[S][0]=0;
  while(que.size()){
    auto p=que.front(); que.pop();
    int v=p.first,cur=p.second,nex=(cur+1)%3;
    if(v==T&&cur==0){
      cout<<dist[T][0]/3<<endl;
      return 0;
    }
    for(int u:G[v]){
      if(dist[u][nex]==-1){
        dist[u][nex]=dist[v][cur]+1;
        que.push({u,nex});
      }
    }
  }
  cout<<-1<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<double> x(N);
  vector<double> y(N);
  
  double distsum = 0;
  
  for(int i = 0; i < N; i++) cin >> x.at(i) >> y.at(i);
  
  for(int i = 0; i < N - 1; i++) {
    for(int j = i + 1; j < N; j++) {
      distsum += sqrt(pow(x.at(i) - x.at(j), 2) + pow(y.at(i) - y.at(j), 2));
    }
  }
  
  cout << setprecision(10) << distsum * 2 / N << endl;
    
}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
original = 0
for i in range(N+1):
    original += abs(A[i+1] - A[i])
for i in range(1, N+1):
    if A[i-1] <= A[i] <= A[i+1] or A[i-1] >= A[i] >= A[i+1]:
        print(original)
    else:
        print(original - 2*min(abs(A[i]-A[i+1]), abs(A[i]-A[i-1])))

Measured memory_bytes: 14048
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#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 CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s;
    R(s);
    sort(ALL(s));
    if(s[0]!=s[3]&&s[0]==s[1]&&s[2]==s[3]){
        W("Yes");
    }
    else W("No");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  string s;
  while(cin >> s){
    int jans=0,ians=0;
    for(int i=0;i<s.size()-2;i++){
      if(s[i]=='J' && s[i+1]=='O' && s[i+2]=='I') jans++;
      else if(s[i]=='I' && s[i+1]=='O' && s[i+2]=='I') ians++;
    }
    cout << jans << endl;
    cout << ians << endl;
  }

  return 0;
}



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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  int ans = abs(x[0] - X);
  for (int i = 1; i < N; i++) {
    ans = __gcd(ans, abs(x[i] - X));
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>

using namespace std;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    int numa = a.size() - 1;
    int numb = b.size() - 1;
    int numc = c.size() - 1;
    if (a[numa] == b[0] && b[numb] == c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a,b) memset(a, b, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;


int main(){
        _ios;

        ll a,b,n;
        cin>>a>>b>>n;
        ll x = min(b-1,n);
        cout<<a*x/b<<endl;
return 0;
}


Measured memory_bytes: 3656
import java.util.*;
public class Main{
  public static long[] memo;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] h = new int[N];
    memo = new long[N];
    Arrays.fill(memo, -1L);
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    System.out.println(solve(h));
  }
  
  public static long solve(int[] array){
    long[] ans = new long[array.length];
    ans[0] = 0L;
    ans[1] = Math.abs(array[1] - array[0]);
    for(int i = 2; i < array.length; i++){
      long tmp1 = ans[i-1] + Math.abs(array[i] - array[i-1]);
      long tmp2 = ans[i-2] + Math.abs(array[i] - array[i-2]);
      ans[i] = Math.min(tmp1, tmp2);
    }
    return ans[array.length - 1];
  }
}

Measured memory_bytes: 62000
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            3223372036854775807
#define END(s)          {cout<<s; return 0;}
#define CON(s)          {cout<<s; continue;}
#define BRE(s)          {cout<<s; break;}
#define pb              push_back
#define All(a)          a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)           (int)a.size()
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
//#define usingFiles
using namespace std;

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

inline bool Read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool Write(int x){
	if(x >= 10) Write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int n, m;
string s1, s2;
pair<int, bool> dp[3030][3030];
pii pre[3030][3030];

void Out(int a, int b){
	if(!(pre[a][b].F == -1 || pre[a][b].F == a && pre[a][b].S == b)) Out(pre[a][b].F, pre[a][b].S);
	if(dp[a][b].S) cout << s1[a];
}

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> s1 >> s2;
	n = s1.size(), m = s2.size();
	rep(i, n){
		rep(j, m){
			pre[i][j] = mp(-1, -1);
		}
	}
	int num1 = -1;
	rep(i, n){
		if(s1[i] == s2[0]){
			num1 = i;
			dp[i][0].S = 1;
		}
		if(num1 != -1){
			dp[i][0].F = 1;
			pre[i][0] = mp(num1, 0);
		}
	}
	int num2 = -1;
	rep(i, m){
		if(s1[0] == s2[i]){
			dp[0][i].S = 1;
			num2 = i;
		}
		if(num2 != -1){
			dp[0][i].F = 1;
			pre[0][i] = mp(0, num2);
		}
	}
	for(int i = 1; i < n; i++){
		for(int j = 1; j < m; j++){
			if(s1[i] == s2[j]){
				if(dp[i - 1][j - 1].F + 1 > dp[i][j].F){
					dp[i][j].F = dp[i - 1][j - 1].F + 1;
					dp[i][j].S = 1;
					pre[i][j] = mp(i - 1, j - 1);
				}
			}
			if(dp[i - 1][j].F > dp[i][j].F) dp[i][j] = mp(dp[i - 1][j].F, 0), pre[i][j] = mp(i - 1, j);
			if(dp[i][j - 1].F > dp[i][j].F) dp[i][j] = mp(dp[i][j - 1].F, 0), pre[i][j] = mp(i, j - 1);
		}
	}
//	cout << dp[n - 1][m - 1].F << endl;
	Out(n - 1, m - 1);
	return 0;
}

Measured memory_bytes: 143872
import java.util.Scanner;


public class Main {
    static Scanner s = new Scanner(System.in);
    static char[][] word;

    public static void main(String[] args) {
        while (true) {
            int n = s.nextInt();
            if (n == 0) break;

            word = new char[n][];

            for(int i=0;i<n;i++) {
                String str = s.next();
                word[i] = new char[str.length()];
                for (int j = 0; j < str.length(); j++) {
                    word[i][j] = str.charAt(j);
                }
            }

            int posi=-1;
            for(int i=1;i<n;i++){
                int nowPosi=-1;
                for(int j=0;j<word[i].length;j++) {
                    if (word[i][j]=='.'){
                        nowPosi++;
                    }else {
                        if(posi<=nowPosi){
                            if(posi>=0) {
                                word[i - 1][posi] = '+';
                                chenge(i - 1, posi);
                            }
                            word[i][nowPosi]='+';
                        } else if(posi>nowPosi){
                            word[i-1][posi]='+';
                            chenge(i-2,posi);
                            posi--;
                            while(posi>nowPosi){
                                brank(i-1,posi);
                                posi--;
                            }

                            if(nowPosi>=0) {
                                word[i][nowPosi] = '+';
                                chenge(i - 1, nowPosi);

                            }else{
                                while(posi>nowPosi){
                                    brank(i-1,posi);
                                    posi--;
                                }
                            }
                        }
                        break;
                    }
                }
                posi=nowPosi;
            }
            while(posi>=0){
                brank(n-1,posi);
                posi--;
            }

            for(int i=0;i<n;i++){
                for(int j=0;j<word[i].length;j++) {
                    System.out.print(word[i][j]);
                }
                System.out.println();
            }
        }
    }

    public static void chenge( int n, int m){
        for(int i=n;;i--){
            if(word[i][m]=='.') word[i][m]='|';
            else break;
        }
    }

    public static void brank(int n, int m){
        for(int i=n;;i--){
            if(word[i][m]=='+') break;
            else word[i][m]=' ';
        }
    }
}

Measured memory_bytes: 62564
#include <bits/stdc++.h>
using namespace std;
//const int INF = 0x3f3f3f3f;
//map<int,int> rr;
int main()
{
	char s[4];
	for (int i = 0; i < 3;i++)
	{
		cin >> s[i];
	}
	int flag = 0;
	for (int i = 0; i < 2;i++)
	{
		if(s[i]!=s[i+1])
		{
				flag = 1;
				break;
		}
	}
	if(flag==0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <bitset>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
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; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    long double a;
    long double b;
    cin>>a>>b;
    ll ans = a * b;
    if(ans == 0){
        cout<<0<<endl;
        return 0;
    }
    //cout<<b_<<endl;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define  ff first
#define  ss second
#define sz(a) (ll)a.size()
#define lli long long int
#define pb push_back
#define pf push_front
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define M 1000000007
#define pi 3.1415926535


 int main(){

    fast;
     ll n,k;
   cin>>n>>k;
   
   ll a[n];
   
   for(int i=0;i<n;i++){
   	cin>>a[i];
   }
   ll *dp=new ll[n+1];
   
  dp[0]=0;
   
   
   for(int i=1;i<n;i++){
   	dp[i]=10000000000000;
   
   	for(int j=1;j<=k;j++){
	   ll ab=1000000000000;
	   
   	if(i>=j){
	   ab=abs(a[i]-a[i-j])+dp[i-j];
   }
   		dp[i]=min(ab,dp[i]);
   }
   	
   
   	
   }
   
   cout<<dp[n-1]<<"\n";
     return 0;
 }





Measured memory_bytes: 5208
n = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        if L[i] == L[j]:
            continue
        for k in range(j+1, n):
            if L[j] == L[k]:
                continue
            if L[k] < L[i] + L[j]:
                ans += 1
print(ans)

Measured memory_bytes: 9188
#include <stdio.h>

int main(){
  char input;
  
  scanf("%c",&input);
  
  switch(input){
    case 'a':
    case 'i':
    case 'u':
    case 'e':
    case 'o':
      printf("vowel");
      break;
    default:
      printf("consonant");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> a >> b;
for (int i=0; i<=10000; i++){
	if ((i*8)/100 == a and (i*10)/100==b){
		cout << i;
		return 0;
	}
}
cout << "-1";
return 0;
}

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

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m, k;
  cin >> n >> m >> k;

  map<int, int> row, col;
  map<pair<int, int>, int> points;

  for(int i = 0; i < k; ++i) {
    int x, y;
    cin >> x >> y;
    ++row[x];
    ++col[y];
    ++points[{x, y}];
  }

  vector<pair<int, int>> a, b;

  for(auto [x, c] : row)
      a.emplace_back(c, x);

  for(auto [y, c] : col)
      b.emplace_back(c, y);

  sort(a.begin(), a.end(), greater<decltype(a.back())>());
  sort(b.begin(), b.end(), greater<decltype(b.back())>());

  int ans = 0;
  for(auto [c, x] : a) {
    for(auto [f, y] : b) {
      // cout << '(' << x << ", " << y << ')' << endl;
      int here = points[{x, y}];
      int sub = c + f - here;
      ans = max(ans, sub);
      // cout << c << ' ' << f << ' ' << sub << endl;
      if(not here)
        break;
    }
  }

  cout << ans;
}


Measured memory_bytes: 73508
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

std::vector<std::string> split(const std::string &s, const std::string &delim) {
  using string = std::string;
  std::vector<string> v;
  string::size_type pos = 0;
  while (pos != string::npos) {
    string::size_type p = s.find(delim, pos);
    if (p == string::npos) {
      v.push_back(s.substr(pos));
      break;
    }
    v.push_back(s.substr(pos, p - pos));
    pos = p + delim.size();
  }
  return v;
}

main {
  vvi v(200, vi(200));
  int n = 0;
  {
    int _i = -1, _j = 0;
    string s;
    while (cin >> s) {
      vs xs = split(s, ",");
      (cmax(n, xs.size()) ? _i : _j) += 1;
      rep(i, xs.size()) v[_i - i][_j + i] = stoi(xs[i]);
    }
  }
  vvi dp(n, vi(n));
  dp[0][0] = v[0][0];
  rep(i, n) rep(j, n) {
    if (i > 0) cmax(dp[i][j], dp[i - 1][j] + v[i][j]);
    if (j > 0) cmax(dp[i][j], dp[i][j - 1] + v[i][j]);
  }
  cout << dp.back().back() << endl;
}

Measured memory_bytes: 3308
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include <iomanip>
#include <limits>
#include <thread>
#include <map>
#include <stack>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <list>
#include <functional>
#include <bitset>
#include <tuple>

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

#define elif else if

using namespace std;
typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;


const ll llINF =  numeric_limits<ll>::max();
const int intINF = numeric_limits<int>::max();
const double doubleINF = numeric_limits<double>::infinity();
const ll MOD = 1000000007;


template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }


int scount[100005];

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

  string s;
  cin >> s;
  int n = s.size();

  int rcount = 0;
  int lcount = 0;
  int rpoint = 0;
  int lpoint = 0;

  rep(i,n-1){
    if(s[i] == 'R' && s[i+1] == 'L'){
      lpoint = i;
      rpoint = i+1;
    }
    if(s[i] == 'R') {rcount++;}
    else{lcount++;}

    if(s[i] == 'L' && s[i+1] == 'R'){
      scount[lpoint] += rcount/2 +(rcount%2) + lcount/2;
      scount[rpoint] += rcount/2 + lcount/2 + lcount%2;
      lcount = 0;
      rcount = 0;
    }
    if(i == n-2){
      lcount++;
      scount[lpoint] += rcount/2 +(rcount%2) + lcount/2;
      scount[rpoint] += rcount/2 + lcount/2 + (lcount%2);
    }
  }

  rep(i,n) printf("%d ", scount[i]);
  printf("\n");





  return 0;

}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int r;
    cin >> r;
    cout << 2 * r * M_PI << endl;
    return 0;
}


Measured memory_bytes: 3784
N, T = map(int, input().split())
ct = [list(map(int, input().split())) for _ in range(N)]

ct.sort()
jdg = False

for i in range(N):
    if ct[i][1] <= T:
      jdg = True
      break
    
print(ct[i][0] if jdg else 'TLE')

Measured memory_bytes: 3060
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;

ll tab[nax];

multiset <ll> setel;

int wyn;

map <ll,int> mapa;

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%lld", &tab[i]);
		mapa[tab[i]]++;
	}
	sort(tab+1, tab+1+n);
	reverse(tab+1, tab+1+n);
	for (int i=1; i<=n; i++)
	{
		ll v=tab[i];
		ll w=1;
		if (!mapa[v])
			continue;
		mapa[v]--;
		while(w<=v)
			w<<=1;
		if (mapa[w-tab[i]])
		{
			wyn++;
			mapa[w-tab[i]]--;
		}
	}
	printf("%d\n", wyn);
	return 0;
}


Measured memory_bytes: 26752
#include <cstdio>
#include <vector>
using namespace std;
const int NC = 1e5 + 5;
typedef long long ll;
int N, M, Q, fa[NC];
void Init() {
	for (int i = 1; i <= N; ++i) fa[i] = i;
}
int Get(int u) { return (u == fa[u]) ? u : (fa[u] = Get(fa[u])); }
void Merge(int u, int v) {
	u = Get(u);
	v = Get(v);
	if (u != v)
		fa[u] = v;
}
bool same(int u, int v) {
	if (Get(u) == Get(v))
		return 1;
	else return 0;
}
vector<pair<int, int> > ns;
int main() {
	scanf("%d%d%d", &N, &M, &Q);
	Init();
	bool hav1 = 0;
	for (int i = 1; i <= Q; ++i) {
		int A, B, C;
		scanf("%d%d%d", &A, &B, &C);
		++A;
		++B;
		if (!C) Merge(A, B);
		else {
			ns.push_back(make_pair(A, B));
			hav1 = 1;
		}
	}
	for (pair<int, int> p : ns)
		if (same(p.first, p.second)) {
			printf("No\n");
			return 0;
		}
	int block = 0;
	for (int i = 1; i <= N; ++i)
		if (fa[i] == i)
			++block;
	if (M == N - 1) {
		if (!hav1) printf("Yes\n");
		else printf("No\n");
		return 0;
	}
	if (block == 2) {
		if (hav1 == 1) printf("No\n");
		else printf("Yes\n");
		return 0;
	}
	if (block == 1) {
		if (M != N - 1) printf("No\n");
		else printf("Yes\n");
		return 0;
	}
	if (M < N) {
		printf("No\n");
		return 0;
	} else if (M > (N - block) + (ll)block * (block - 1) / 2) {
		printf("No\n");
		return 0;
	} else printf("Yes\n");
	return 0;
}

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

int main()
{
	int n, Tpoint = 0, Hpoint = 0,SmallSize = 0;
	string Tarou, Hanako;

	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> Tarou >> Hanako;
		//文字数の小さいほう
		SmallSize = (Tarou.size() < Hanako.size()) ? Tarou.size() : Hanako.size();

		for (int j = 0; j < SmallSize; j++) {
			if (Tarou == Hanako) {//同じ単語で引き分け
				Tpoint++, Hpoint++;
				break;
			}
			else if (Tarou[j] < Hanako[j]) {//花子勝ち
				Hpoint += 3;
				break;
			}
			else if (Hanako[j] < Tarou[j]) {//太郎勝ち
				Tpoint += 3;
				break;
			}
			else if (j + 1 == SmallSize) {//文字数短いほうに達したら
				(SmallSize == Tarou.size()) ? Hpoint += 3 : Tpoint += 3;
			}
		}
	}

	cout << Tpoint << " " << Hpoint << endl;

	return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> dt(N);
  REP(i, N) {
    cin >> dt[i].second >> dt[i].first;
  }
  sort(dt.begin(), dt.end());
  reverse(dt.begin(), dt.end());

  ll dsum = 0;
  map<ll, ll> m;

  REP(i, K) {
    dsum += dt[i].first;
    m[dt[i].second]++;
  }

  ll ans = dsum + m.size() * m.size();
  int r = K - 1;
  for(int i = K; i < N; i++) {
    if(m[dt[i].second] != 0) continue;
    while(m[dt[r].second] == 1 && r >= 0) r--;
    if(r == -1) break;

    m[dt[i].second]++;
    m[dt[r].second]--;
    dsum = dsum + dt[i].first - dt[r].first;
    ll tmp = dsum + m.size() * m.size();
    ans = max(ans, tmp);
    r--;
  }

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


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

int d, n;

int main()
{
    cin >> d >> n;
    if(d==0) cout << (n==100?n+1:n);
    else if (d==1) cout << (n==100?n+1:n)*100;
    else if (d==2) cout << (n==100?n+1:n)*10000;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, a: [i64; n]);
    let a: Vec<i64> = a;
    if a.iter().all(|&x| x < n as i64) {
        println!("{}", 0);
        return;
    }
    let mut ok = i64::MAX / 10;
    let mut ng = 0;
    let d = n as i64 + 1;
    let check = |m| {
        let k = n as i64 - m - 1;
        let mut ret = 0;
        for &ai in &a {
            let ai = ai - k;
            if ai > 0 {
                ret += ai / d + if ai % d == 0 { 0 } else { 1 };
            }
        }
        ret <= m
    };
    while ok - ng > 1 {
        let m = (ok + ng) / 2;
        if check(m) {
            ok = m
        } else {
            ng = m
        }
    }
    for i in max(ok - 1_000_000, 0)..ok {
        if check(i) {
            ok = i;
            break;
        }
    }
    println!("{}", ok);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2148
# https://atcoder.jp/contests/abc049/tasks/arc065_a
s = input()
s = s.replace("eraser", "")
s = s.replace("erase", "")
s = s.replace("dreamer", "")
s = s.replace("dream", "")
if s == "":
    print("YES")
else:
    print("NO")


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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 comb(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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b, d) - max(a, c)) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int a;
  cin >> a;
  cout << a + pow(a, 2) + pow(a, 3) << endl;
}


Measured memory_bytes: 4156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		for (int i = 0; i < N; i++) {
			A[sc.nextInt() - 1] = i + 1;
		}
		sc.close();
		for (int i = 0; i < N; i++) {
			System.out.print(A[i] + " ");
		}
	}
}


Measured memory_bytes: 62204
n, a, b, c = map(int, input().split())
d = {"A": a, "B": b, "C": c}

pl = [input() for _ in range(n)]

res = []
for i, p in enumerate(pl):
    if d[p[0]] == d[p[1]] == 0:
        print("No")
        exit()
    elif d[p[0]] == 0:
        res.append(p[0])
        d[p[0]] += 1
        d[p[1]] -= 1
    elif d[p[1]] == 0:
        res.append(p[1])
        d[p[0]] -= 1
        d[p[1]] += 1
    elif i == n - 1:
        res.append(p[0])
    elif p[0] in pl[i + 1]:
        res.append(p[0])
        d[p[0]] += 1
        d[p[1]] -= 1
    else:
        res.append(p[1])
        d[p[0]] -= 1
        d[p[1]] += 1

print("Yes")
for p in res:
    print(p)


Measured memory_bytes: 17028
#include <stdio.h>

#define N 100

int main(void){
  int n, m, l, a[N][N], b[N][N];
  long int c[N][N];
  int i, j, k;

  scanf("%d%d%d", &n, &m, &l);
  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      scanf("%d", &a[i][j]);
    }
  }
  for(i = 0; i < m; i++){
    for(j = 0; j < l; j++){
      scanf("%d", &b[i][j]);
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < l; j++){
      c[i][j] = 0;
      for(k = 0; k < m; k++){
	c[i][j] += a[i][k] * b[k][j];
      }
      printf("%ld", c[i][j]);
      if(j != l-1){
	printf(" ");
      }else{
	printf("\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 680
#include<bits/stdc++.h>
using namespace std;
#define piii pair<int, pair<int, int> >
const int inf=1e9+99;
char a[1009][1009];
int r, c;
vector<pair<int, int> >black;
int dist[1009][1009];
int xx[]={0, -1, 0, 1};
int yy[]={1, 0, -1, 0};
int main(){
	cin>>r>>c;
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin>>a[i][j];
			dist[i][j]=inf;
			if(a[i][j]=='#'){ 
				black.push_back({i, j});
				dist[i][j]=0;
			}
		}
	}
	priority_queue<piii, vector<piii>, greater<piii> >pq;
	for(int i=0; i<black.size(); i++){
		pq.push({0, {black[i].first, black[i].second}});
	}
	while(!pq.empty()){
		int di=pq.top().first;
		int cx=pq.top().second.first, cy=pq.top().second.second;
		pq.pop();
		if(di>dist[cx][cy]) continue;
		for(int i=0; i<4; i++){
			int nx=cx+xx[i], ny=cy+yy[i];
			if(nx<0 || nx>=r || ny<0 || ny>=c) continue;
			if(dist[nx][ny]>dist[cx][cy]+1){
				dist[nx][ny]=dist[cx][cy]+1;
				pq.push({dist[nx][ny], {nx, ny}});
			}else continue;
		}
	}
	int maks=-1;
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			maks=max(maks, dist[i][j]);
		}
	}
	cout<<maks<<endl;
	return 0;
}

Measured memory_bytes: 31848
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printShortestDist() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		Iterator<LinkedList<Integer>> it = adjList.iterator();
		int num = 0;
		while(it.hasNext()) {
			LinkedList<Integer> c = it.next();
			Iterator<Integer> it2 = c.iterator();
			
			while(it2.hasNext()){
				adjMatrix[num][it2.next()] = 1; 
			}
			num++;
		}
		
		Queue<Integer> q = new LinkedList<Integer>();
		int[] neighbor = new int[totalVertex];
		for(int h = 0; h<neighbor.length;h++) {
			if(h==0) {neighbor[0] = 0;}
			else{neighbor[h]= -1;}
			}
		q.add(0);
			while(!q.isEmpty()) 
			{
				int tmpidx = q.poll();
				LinkedList<Integer> tmp = adjList.get(tmpidx);
				for (int l=0; l<tmp.size(); l++)
					{
					int f = tmp.get(l);
					if(neighbor[f] ==-1) {q.add(f);neighbor[f] = neighbor[tmpidx]+1;}
					} 
				
				
			}
			
			for (int k=0; k<totalVertex; k++) {
				System.out.println((k+1) + " " + neighbor[k]);
			}
		}
			
		
	}


//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printShortestDist();
	}
}




Measured memory_bytes: 28444
N=int(input())
def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = sorted(list(set(table)))
  l=len(table)
  if l==2:
      return n-1
  elif l%2==1:
      a=0
      x=l//2
  else:
      a=1
      x=l//2-1
      y=l//2
  if a==0:
    return table[x]*2-2
  if a==1:
    return table[x]+table[y]-2
print(divisor(N))

Measured memory_bytes: 3924
s = input()
if s.count('N') >= 1 and s.count('S') >= 1:
  if s.count('W') >= 1 and s.count('E') >= 1:
    print('Yes')
    exit()
  elif s.count('W') ==0 and s.count('E') == 0:
    print('Yes')
    exit()
elif s.count('N') == 0 and s.count('S') == 0:
  if s.count('W') >= 1 and s.count('E') >= 1:
    print('Yes')
    exit()
  elif s.count('W') ==0 and s.count('E') == 0:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void call(int *n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= *n ) goto CHECK_NUM;

  cout << endl;
}
int main(){
	int a;
	scanf("%d",&a);
	call(&a);
	return 0;
}


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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

# define int long long

int n,q;
int a[N];
int cnt[N];
int ans;

signed main()
{
    read(n);
    Rep(i,1,n)read(a[i]),cnt[a[i]]++,ans+=a[i];
    read(q);
    while(q--){
        int x,y;
        read(x),read(y);
        ans+=cnt[x]*(y-x);
        cnt[y]+=cnt[x];
        cnt[x]=0;
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 5312
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
     int N=int.Parse(str[0]);
      int K=int.Parse(str[1]);
      string[] len=Console.ReadLine().Split(' ');
      int ans=0;
      int[] sortlen=new int[N];
      for(int i=0;i<N;i++){
        sortlen[i]=int.Parse(len[i]);
      }
       Array.Sort(sortlen);
      for(int i=1;i<=K;i++){
        ans+=sortlen[N-i];
       
      }
       Console.WriteLine(ans);
    }
    
  }

}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int dat[125252];
void init(){
  REP(i,125252)dat[i]=-1;
}
int root(int x){
  return dat[x]<0 ? x : (dat[x]=root(dat[x]));
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x!=y){
    if(dat[x]>dat[y])swap(x,y);
    dat[x] += dat[y];
    dat[y] = x;
  }
}
bool same(int x,int y){
  return root(x)==root(y);
}
int size(int x){
  return -dat[x];
}

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

  init();
  while(m--){
    int a,b;
    cin>>a>>b;
    --a; --b;
    unite(a,b);
  }
  int res = 0;
  REP(i,n){
    if(i!=root(i))continue;
    if(size(i)==1)--res;
    else ++res;
  }
  cout<<abs(res)<<endl;
  return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<int,int>
#define mp make_pair
using namespace std;
int n,k;
int memo[100005];
int a[100005];
int solve(int i)
{
    if(i == n-1)
    {
        return 0;
    }
    int &ret = memo[i];
    if(ret != -1)
        return ret;
    ret = 1e9;
    for(int j=1;j<=k;j++)
    {
        if(i+j < n)
        {
            int s1 = abs(a[i]-a[i+j]);
            ret = min(ret , s1+solve(i+j));
        }
    }
    return ret;
}
int main()
{
    memset(memo,-1,sizeof(memo));
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<solve(0);
}


Measured memory_bytes: 5760
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
      if(N%1000!=0){
      Console.WriteLine(1000-(N%1000));
      }else{
        Console.WriteLine(0);
      }
    }
    
  }

}


Measured memory_bytes: 27524
# -*- coding: utf-8 -*-
import math
import sys
import bisect

## input
a,b,q = map(int, sys.stdin.readline().rstrip().split())
s_s, t_s, x_s = [[-10**11], [-10**11], []]
for _ in range(a):
  s_s.append(int(sys.stdin.readline().rstrip()))
for _ in range(b):
  t_s.append(int(sys.stdin.readline().rstrip()))
for _ in range(q):
  x_s.append(int(sys.stdin.readline().rstrip()))
s_s.append(10**11)
t_s.append(10**11)


def solve(k):
  s_pos = bisect.bisect_left(s_s, k)
  t_pos = bisect.bisect_left(t_s, k)
  mn = 10**11
  for i in [s_s[s_pos-1], s_s[s_pos]]:
    for j in [t_s[t_pos-1], t_s[t_pos]]:
      mn = min(mn,abs(i-k)+abs(i-j), abs(j-k)+abs(i-j))
  return(mn)

if __name__ == "__main__":
  for x in x_s:
    print(solve(x))

Measured memory_bytes: 16168
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto a = RDR.ARR;
	a.sort!"a > b"();
	long ans;
	foreach (i; 0..N)
	{
		auto j = i*2+1;
		ans   += a[j];
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}


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

using namespace std;

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

  int a, b, k;
  cin >> a >> b >> k;

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

  return 0;
}



Measured memory_bytes: 256
import heapq

from typing import List


def main():
    n, k = map(int, input().split())
    v = []
    for _ in range(n):
        t, d = map(int, input().split())
        v.append((t, d))

    print(vs(v, k))


def vs(v: List[List[int]], k: int) -> int:
    v.sort(key=lambda x: x[1], reverse=True)

    # Dup type
    h0 = []
    # New type
    h1 = []
    # types
    s = set()
    types = 0
    op = 0

    for i in range(k):
        t, d = v[i]
        op += d

        if t in s:
            heapq.heappush(h0, d)
            continue

        types += 1
        s.add(t)

    for i in range(k, len(v)):
        t, d = v[i]

        if not t in s:
            s.add(t)
            heapq.heappush(h1, -d)

    result = op + types ** 2

    while len(h0) > 0 and len(h1) > 0:
        d0 = heapq.heappop(h0)
        d1 = -heapq.heappop(h1)
        op = op - d0 + d1
        types += 1
        tmp = op + types ** 2

        if tmp > result:
            result = tmp

    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 31048