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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int h,n;
    while (cin >> h >> n) {
        VI dp(h+1,inf);
        dp[0] = 0;
        FOR(i,0,n) {
            int w,v; cin >> w >> v;
            FOR(j,0,h+1) 
                dp[j] = min(dp[j], dp[max(0,j-w)]+v);
        }
        cout << dp[h] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#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>;

//flg を用いたバブルソート
int bubbleSort(int A[], int N) {
    int sw = 0;
    bool flg = 1;
    for (int i = 0; flg; i++) {  // ２番目の式がi< のような形になっていないので、flgによってのみ判断される。
        flg = 0;
        for (int j = N-1; j >= i+1; j--) {
            if (A[j] < A[j-1]) {
                //隣接要素を交換する
                swap(A[j], A[j-1]);
                flg = 1;
                sw++;
            }
        }
    }
    return sw;  
}

int main() {
    int A[100], N, sw;
    cin >> N;
    rep(i,N) cin >> A[i];

    sw = bubbleSort(A, N);

    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  vector<vector<int64_t>> a(3,vector<int64_t>(3));
  rep(i,3){
    rep(j,3){
      cin >> a[i][j];
    }
  }
  int64_t n;
  cin >> n;
  vector<int64_t> b(n);
  rep(i,n){
    cin >> b[i];
  }
  vector<vector<bool>> s(3,vector<bool>(3));
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(b[i] == a[j][k]){
          s[j][k] = true;
        }
      }
    }
  }
  bool ff = false;
  rep(i,3){
    if((s[0][i]&&s[1][i]&&s[2][i]) || (s[i][0]&&s[i][1]&&s[i][2])){
      ff = true;
    }
  }
  if((s[0][0]&&s[1][1]&&s[2][2]) || (s[0][2]&&s[1][1]&&s[2][0])){
    ff = true;
  }
  if(ff){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
      
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i=0; i<h; i++) cin >> s[i];

    vector<vector<int64>> dp(h, vector<int64>(w, INT_MAX));
    dp[0][0] = (s[0][0] == '#');

    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (i+1 < h)
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (s[i][j] == '.' && s[i+1][j] == '#'));

            if (j+1 < w)
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + (s[i][j] == '.' && s[i][j+1] == '#'));
        }
    }

//    for (int i=0; i<h; i++) {
//        for (int j=0; j<w; j++)
//            cout << dp[i][j] << " ";
//        cout << endl;
//    }

    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
#define Joe ios::sync_with_stdio(0); cin.tie(NULL); ios_base::sync_with_stdio(0); cout.tie(NULL);//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define INF 1e9+7
const long long N =1e5+5;
using namespace std;
int dp[3005][3005];
int main(){
	Joe
	string s,t,st="";
	cin>>s>>t;
	int sz=s.length(),tz=t.length();
	for(int i=1;i<=sz;i++){
		for(int j=1;j<=tz;j++){
			if(s[i-1]==t[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}
	}
	int mark=dp[sz][tz];
	int u=sz , d=tz;
	while(mark>0){
		if(mark>dp[u-1][d] && mark>dp[u][d-1]){
			st+=s[u-1];
			mark--;
			u--;
			d--;
		}
		else if(mark==dp[u-1][d])
			u--;
		else
			d--;
	}
	reverse(st.begin(),st.end());
		cout<<st<<endl;
	return 0;
}


Measured memory_bytes: 35456
import sys
sys.setrecursionlimit(20000000)
S = input().split(" ")
n = int(S[0])
m = int(S[1])

py = []

for i in range(m):
    py.append([int(s) for s in input().split(" ")])

def prepare(n, data):
    result = [0 for i in range(n)]
    dict = {}
    data = sorted(data,key=lambda x:x[1])
    for d in data:
        i = d[0] - 1
        result[i] = result[i] + 1
        dict.__setitem__(generateID(d[0], d[1]), str(d[0]).zfill(6) + str(result[i]).zfill(6))

    return dict


def generateID(start, to):
    if start < to:
        start, to = to, start

    return start * 100000 + to

dict = prepare(n, py)

for p in py:
    print(dict[generateID(p[0],p[1])])




Measured memory_bytes: 41092
//sorting.cpp
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c;
    d=min(a,b);
    e=max(a,b);
    f=max(e,c);
    e=min(e,c);
    a=min(d,e);
    b=max(d,e);
    c=f;
    cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=3e5+10;
const int mod=1e9+7;
int a[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]-=i;
    }
    sort(a+1,a+1+n);
    ll sum=0,t=a[n/2+1];
    for(int i=1;i<=n;i++)
    {
        sum+=abs(a[i]-t);
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4364
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
	run();
	string s, t;
	cin >> s >> t;
	t.pop_back();
	cout << (s == t ? "Yes" : "No") << endl;
}


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

    int card[255][14]={{0}};
    
    int main(void){
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            char c;
            int num;
            cin>>c>>num;
            card[(int)c][num]=1;
        }
        for(int i=1;i<=13;i++){
            if(card[(int)'S'][i]==0){
                cout<<"S "<<i<<endl;
            }
        }
        for(int i=1;i<=13;i++){
            if(card[(int)'H'][i]==0){
                cout<<"H "<<i<<endl;
            }
        }
        for(int i=1;i<=13;i++){
            if(card[(int)'C'][i]==0){
                cout<<"C "<<i<<endl;
            }
        }
        for(int i=1;i<=13;i++){
            if(card[(int)'D'][i]==0){
                cout<<"D "<<i<<endl;
            }
        }
    }
    


Measured memory_bytes: 3088
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9
#define N 1100000
#define MAX_V 900010
#define vec vector<int>
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>

ll fact[N],inv[N];
void calc(){
    fact[0]=1;
    rep2(i,1,N){
        fact[i]=i*fact[i-1]%MOD;
    }
    return ;
}
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
ll gcd(ll x,ll y){
    return (x?gcd(y%x,x):y);
}
main(){
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    ll g=gcd(n,m);
    n/=g;
    m/=g;
    rep(i,g){
        if(s[i*n]!=t[i*m]){
            cout<<-1;return 0;
        }
    }
    cout<<n*m*g;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

void call(int n) {
	int i = 1;
	int x;
	bool flg = false;
	while (1) {
		// CHECK_NUM
		x = i;
		if ( x % 3 == 0 ){
			cout << " " << i;
		}
		else {
			while (1) {
				// INCLUDE3
				if ( x % 10 == 3 ){
					cout << " " << i;
					flg = true;
				}
				else {
					x /= 10;
					if ( x ) {
						continue;
					}
					else {
						flg = true;
					}
				}
				if (flg == true) {
					break;
				}
			}
		}
		flg = false;
		// END_CHECK_NUM
		if ( ++i <= n ) {
			continue;
		}
		else {
			cout << endl;
			break;
		}
	}
}

int main(void)
{
	int n;
	cin >> n;
	call(n);
	return 0;
}


Measured memory_bytes: 3044
def popcnt1(n):
    return bin(n).count("1")

def okikae(n):
    kaisu = 0
    if n == 0:
        return 0
    while 1:
        P = popcnt1(n)
        n %= P
        kaisu += 1
        if n == 0:
            return kaisu

OKI = [okikae(i) for i in range(200001)]
X = int(input())
Norig = input()
N = int(Norig,2)
Npop = Norig.count("1")
F = Npop + 1
H = Npop - 1
if H == 0:
    H = -1
FueAmari = N%(Npop + 1)
if Npop != 1:
    HeruAmari = N%(Npop - 1)
else:
    HeruAmari = -1
Fues = []
Herus = []
fue = 1
heru = 1
for i in range(2*(10**5+1)):#2^0の桁から
    fue %= F
    heru %= H
    Fues.append(fue)
    Herus.append(heru)
    fue *= 2
    heru *= 2
RNorig = reversed(Norig)
Results = []
Zougen = []#増えたらTrue
Kaisu = [0] * X
#上の桁から見ていく。ゼロなら減ってイチなら増える
for n,bit in enumerate(Norig):#2**(N-1-n)の桁
    if bit == "0":#増える
        Zougen.append(True)
        print(1+OKI[(FueAmari + Fues[X-1-n] )% F])
    else:
        if H == -1:
            print(0)
            continue
        Zougen.append(False)
        print(1+OKI[(HeruAmari - Herus[X-1-n]) % H])

Measured memory_bytes: 109964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "the " << #x << " -> "; err(x); } while (0)
void err() { cout << "" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
int main()
{
    int r,g,b,n;
    scanf("%d%d%d%d",&r,&g,&b,&n);
    int ans=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            int need=n-i*r-j*g;
            if(need>=0&&need%b==0) ans++;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
int n,m;
int ind[M], dp[M];
vector<int> e[M];
int dfs(int cur) {
    if (dp[cur]) return dp[cur];
    for (int i:e[cur]) dp[cur] = max(dp[cur], dfs(i));
    dp[cur]++;
    return dp[cur];
}
int main()
{
    while (~scanf("%d %d",&n,&m)) {
        MSET(ind, 0);
        MSET(dp, 0);
        REP(i,1,n) e[i].clear();
        REP(i,1,m) {
            int x,y;
            scanf("%d %d",&x,&y);
            e[x].push_back(y);
            ind[y]++;
        }

        int ans = -1;
        REP(i,1,n) if(ind[i]==0) ans = max(ans, dfs(i));
        printf("%d\n", ans-1);
    }
    
    return 0;
}



Measured memory_bytes: 9600
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
const unsigned long long INF = 1LL << 60;
typedef  long long ll;
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;
}

int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}


int main(){ 
int H1,M1,H2,M2,K;
cin >> H1 >> M1 >> H2 >> M2 >> K;
int a = H1 * 60 + M1;
int b = H2 * 60 + M2;
cout << max(0,b-a - K)<< endl;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int mx = max(a, b);
    cout << max(a+b, mx+mx-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    ll x;
    cin>>x;
    cout<<x*x*3<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // AGC027A - Candy Distribution Again

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); // 2 <= n <= 10^5
        Integer[] a = new Integer[n * 3]; // 1 <= a <= 10^9

        for (int i = 0; i < n * 3; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a, Collections.reverseOrder());
        //Arrays.sort(a);

        long sum = 0;
        for (int j = 1; j < n * 2; j += 2) {
            sum += a[j];
        }

        System.out.println(sum);
    }

}

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

#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
int add(int a,int b){
	return (a + b)%mod;
}
int sub(int a,int b){
	return add(a,mod - 1);
}
int mul(int a,int b){
	return (a*b)%mod;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    bool turn = false;
    while(1){
    	if(!turn){
	    	if(c - b <= 0){
	    		cout << "Yes";
	    		break;
	    	}
	    	c -= b;
    	}else{
    		if(a - d <= 0){
    			cout << "No";
    			break;
    		}
    		a -= d;
    	}
    	turn = !turn;
    }
}

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

using namespace std;

#define fRead(x)  freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)

#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mk make_pair

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))

#define scanI(a) scanf("%d",&a)
#define scanI2(a,b) scanI(a) , scanI(b)
#define scanI3(a,b,c) scanI(a), scanI(b), scanI(c)
#define scanI4(a,b,c,d) scanI(a), scanI(b), scanI(c), scanI(d)

#define scanL(a) scanf("%I64d",&a)
#define scanL2(a,b) scanL(a) , scanL(b)
#define scanL3(a,b,c) scanL(a), scanL(b), scanL(c)
#define scanL4(a,b,c,d) scanL(a), scanL(b), scanL(c), scanL(d)

#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())

#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);

LL BigMod(LL B,LL P,LL M){LL R=1;while(P>0){if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}return R;}

struct point{
    LL name;
    double val;
    bool operator<(const point &a)const{
        return a.val<val;
    }
};
#define mx 1000

priority_queue<point> Q;

vector<LL>tdlist[mx+5];

double dis[mx+5],cost[mx+5][mx+5];
LL n;
void DJ(point node){
    LL now = node.name;

    for(LL i = 0;i<=n+1;i++)
    {
        if(i==now)continue;
        LL x = i;

        if(dis[now]+cost[now][x]<dis[x])
        {
            dis[x]=dis[now]+cost[now][x];
            point get;
            get.name=x;
            get.val=dis[x];
            Q.push(get);
//            cout << "here " << now << " " << get.name << " " << get.val << endl;
        }
    }
}
vector<pair<pair<LL,LL>,LL> > v;
int main()
{

        LL x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2  >> y2;
        v.pb(mk(mk(x1,y1),0));
        cin >> n;
        REP(i,n){
            LL xx,yy,rr;
            cin >> xx >> yy >> rr;
            v.pb(mk(mk(xx,yy),rr));
        }
        v.pb(mk(mk(x2,y2),0));

        REP(i,v.size())
        {
            for(int j = i+1;j<v.size();j++)
            {
                double dis = (v[i].ff.ff-v[j].ff.ff)*(v[i].ff.ff-v[j].ff.ff) + (v[i].ff.ss-v[j].ff.ss)*(v[i].ff.ss-v[j].ff.ss);
                dis = sqrt(dis);
                double r = v[i].ss + v[j].ss;
                double c = dis - r;
                if(c<0)c=0;
                cost[i][j]=cost[j][i]=c;
            }
        }

        FOR(i,0,1001)dis[i]=INF;
        dis[0]=0;
        point get;
        get.name=0;
        get.val=0;
        Q.push(get);
        while(not Q.empty())
        {
            point temp=Q.top();
            Q.pop();
            DJ(temp);
        }
        cout<< fixed << setprecision(12) <<  dis[n+1] << "\n";
}


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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    string s;
    cin >> s;
    int64_t ans = 0;
    int leftAs = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            leftAs++;
        } else if (s[i] == 'B' && i + 1 < s.size() && s[i + 1] == 'C') {
            ans += leftAs;
            i++;
        } else {
            leftAs = 0;
        }
    }
    cout << ans << '\n';
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll A, B;
signed main()
{
    cin >> A >> B;
    if(A <= 8 && B <= 8) {
        printf("Yay!\n");
    } else {
        printf(":(\n");
    }
    return 0;
}


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

void getData(vector<int> &x, int N) {
    rep(i, N) {
        int buf;
        cin >> buf;
        x.push_back(buf);
    }
}
void solv() {
    int N;
    vector<int> Ai, Bi, Ci;
    cin >> N;
    getData(Ai, N);
    getData(Bi, N);
    getData(Ci, N);
    int sum = 0;
    rep(i, N) {
        sum += Bi[Ai[i] - 1];
        if (i < N - 1) {
            if (Ai[i] == Ai[i + 1] - 1) {
                sum += Ci[Ai[i] -1];
            }
        }
    }
    cout << sum << endl;
}

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

Measured memory_bytes: 256
package main

import(
	"fmt"
)

func main(){
	var k int
	fmt.Scan(&k)
	s := []int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
	fmt.Print(s[k - 1])
}

Measured memory_bytes: 512
#include <stdio.h>

int main() {
    int d,w,h,n,i;
    int r[1000];
    int hsize;
    
    while(1){
        scanf("%d%d%d",&d,&w,&h);
        if(d==0 && w==0 && h==0) break;
        scanf("%d",&n);
        for(i=0;i<n;i++)
            scanf("%d",&r[i]);
        for(i=0;i<n;i++){
            hsize = r[i]*2;
            hsize = hsize * hsize;
            if(d*d+w*w<hsize || w*w+h*h<hsize || h*h+d*d<hsize)
                printf("OK\n");
            else
                printf("NA\n");
        }
    }
    return 0;
}


Measured memory_bytes: 1932
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int p = Integer.parseInt(sc.next());
        int odd = 0;
        int even = 0;
        for (int i = 0; i < n; i++) {
            int m = Integer.parseInt(sc.next());
            if (m % 2 == 1) {
                odd++;
            } else {
                even++;
            }
        }
        long ans = 1;
        if (odd == 0) {
            if (p == 0) {
                for (int i = 0; i < n; i++) {
                    ans *= 2;
                }
            } else {
                ans = 0;
            }
        } else {
            for (int i = 0; i < n - 1; i++) {
                ans *= 2;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



int main() {
    ll n, pred, a=0;
    string s = "Yes";
    cin>>n;
    
    vector<ll> h(n);
    
    rep(i,n) cin>>h[i];
    
    for(ll i = n-1; i>0; i--){
        if(h[i-1]-h[i]>=2) s="No";
        
        if(h[i-1]-h[i]==1){
            h[i-1] = h[i-1] -1;
        }
        
    }
    
    cout<<s<<endl;
    
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pres(x) cout<<fixed; cout<<setprecision(x);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define mod 1000000007
//#define v.all() v.begin(),v.end()

int32_t main(){
	
	fast;
	//open;

	int n,x;
	cin>>n;
	map<pair<string,int>, int> input; map<string, vector<int>> m; string array[n],s; pair<string,int> p; vector<int> v;
	
	rep(i,n){
		cin>>s>>x;
		p = make_pair(s,x);
		input[p] = i;
		array[i] = s;
		m[s].push_back(x);
	}
	sort(array,array+n);
	/*v = m[array[0]];
	sort(v.begin(), v.end(),greater<int>());
	
	rep(i,v.size()){		
		p = make_pair(array[0], v[i]);
		cout<<input[p]+1<<"\n";
	}*/
	
	int i=0; string prev=array[0];
	while(i<n){
		if((array[i]!=array[i-1]) || (i==0)){
			v = m[array[i]];
			sort(v.begin(), v.end(),greater<int>());
			rep(j,v.size()){		
				p = make_pair(array[i], v[j]);
				cout<<input[p]+1<<"\n";
			}
			prev = array[i];
		}
		i++;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    map<int,int> ds;
    rep(i,0,n){
        int d;
        cin>>d;
        ds[d]++;
    }
    
    int m;
    cin>>m;
    map<int,int> ts;
    rep(i,0,m){
        int t;
        cin>>t;
        ts[t]++;
    }
    
    string ans="YES";
    for(auto p:ts){
        int t=p.first;
        int x=p.second;
        
        if(ds[t]<x) ans="NO";
    }
    cout<<ans<<endl;
}



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

int findPath(vector<vector<char>> &g) {
	int h=g.size(),w=g[0].size();
	int len=1;
	
	queue<vector<int>> q;
	q.push({0,0,1});
	g[0][0]='s';
	while (!q.empty()) {
		int i=q.front()[0], j=q.front()[1];
		len = max(len, q.front()[2]);
		q.pop();
		
		//down
		if (i+1 < h) {
			if (g[i+1][j]=='.') {
				q.push({i+1,j,len+1});
				g[i+1][j] = '#';
			}
		}
		//up
		if (i-1 >= 0) {
			if (g[i-1][j]=='.') {
				q.push({i-1,j,len+1});
				g[i-1][j] = '#';
			}
		}
		//right
		if (j+1 < w) {
			if (g[i][j+1]=='.') {
				q.push({i,j+1,len+1});
				g[i][j+1] = '#';
			}
		}
		//left
		if (j-1 >= 0) {
			if (g[i][j-1]=='.') {
				q.push({i,j-1,len+1});
				g[i][j-1] = '#';
			}
		}

		if (i==h-1 and j==w-1) break;
	}

	if (g[h-1][w-1]!='#') len=-1;
	return len;
}

int main() {
	int h,w; cin>>h>>w;
	vector<vector<char>> g(h,vector<char>(w));
	for (int i=0; i<h; i++)
		for (int j=0; j<w; j++)
			cin>>g[i][j];
	int ans=0;
	for (int i=0; i<h; i++)
		for (int j=0; j<w; j++)
			if (g[i][j]!='#') ans++;

	int pathlen = findPath(g);

	if (pathlen==-1) cout << -1 << endl;
	else cout << ans-pathlen << endl;
	return 0;
}


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

int main() {

	int n, m;
	cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
import math
#import pdb

line = input()
elem_list = line.split()
n = int(elem_list[0])
k = int(elem_list[1])

ans = 0
tmp_num = k
if n >= k:
    ans += n - k + 1

pw = 1
while(True):
    pw /= 2
    tmp = math.ceil(tmp_num / 2)
    
    if tmp <= 1:
        ans += (tmp_num - 1) * pw
#        print((tmp_num - 1) * pw)
        break
    
    if n < tmp:
        pass
    elif tmp <= n and n < tmp_num:
        ans += ((n - tmp) + 1) * pw
        #print(((n - tmp) + 1) * pw)
    else:
        ans += (tmp_num - tmp) * pw
#        print((tmp_num - tmp) * pw)
    tmp_num = tmp

ans /= n

print(ans)


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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)

int main() {
    double ans = 0;
    int n;
    double tmp;
    vector<double> v;
    cin >> n;
    REP(i, n){
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.begin()+n);
    REP(i, n){
        if(i == 0)ans = v[0];
        else ans = (ans + v[i])/2;
    }

    cout << setprecision(10) << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<string> a(n);
    vector<string> b(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    
    for(int i = 0;i < n;i++){
        for(int j = n - 1;j > i;j--){
            if(a[j][1] < a[j - 1][1]){
                string x;
                x = a[j];
                a[j] = a[j - 1];
                a[j - 1] = x;
                
            }
        }
    }
    for(int i = 0;i < n;i++){
        cout << a[i];
        if(i != n - 1){
            cout << " ";
        }
    }
    cout << endl << "Stable" << endl;
    
    int minj;
    for(int i = 0;i < n;i++){
        minj = i;
        for(int j = i;j < n;j++){
            if(b[j][1] < b[minj][1]){
                minj = j;
            }
        }
        string x;
        x = b[i];
        b[i] = b[minj];
        b[minj] = x;
    }
    for(int i = 0;i < n;i++){
        cout << b[i];
        if(i != n - 1){
            cout << " ";
        }
    }
    cout << endl;
    bool check = true;
    for(int i = 0;i < n;i++){
        if(a[i] != b[i]){
            cout << "Not stable" << endl;
            check = false;
            break;
        }
    }
    if(check){
        cout << "Stable" << endl;    
    }
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
int n;
string mp;

int main(){
  cin>>n>>mp;
  int a=0,b=0;
  while(mp[a]=='<')a++;
  while(mp[n-1-b]=='>')b++;
  cout <<n-min(a,b)<<endl;
  return 0;
}

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

int main(){
    string station;
    cin >> station;
    if(station.substr(0,1) == station.substr(1,1) &&station.substr(1,1) == station.substr(2,1) && station.substr(0,1) == station.substr(2,1)){
        cout << "No";
    }else{
        cout << "Yes";
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int r, c;

	scanf("%d %d", &r, &c);

	int num[r][c];
	int sum=0;
	int total = 0;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			scanf("%d", &num[i][j]);
		}
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c + 1; j++) {
			if (j == c) {
				printf(" %d\n", sum);
				sum = 0;
			}
			
			else {
				if(j!=0)printf(" ");
				printf("%d", num[i][j]);
				sum += num[i][j];
			}
		}
	}
	sum = 0;
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < r; j++) {
			sum += num[j][i];
		}
		if (i != 0)printf(" ");
		printf("%d", sum);
		total += sum;
		sum = 0;
	}
	printf(" %d\n", total);

	return 0;
}


Measured memory_bytes: 2096
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

static const ll MOD = 1000000000+7;

int ans;
char S[100005];
ll dp[100005][13]; //dp[i][j]: 先頭からi番目までの数字で、13で割った余りがjとなるものの個数 

int main(void) {
    scanf("%s", S);
    dp[0][0] = 1LL;
    rep(i, 1, strlen(S)+1) {
      if (S[i-1] == '?') {
        rep(j, 0, 10) { 
          rep(k, 0, 13) {
            int r = k * 10 + j;
            r %= 13LL;
            dp[i][r] += dp[i-1][k];
          
          }
          
        }
      
      } else {
        int j = S[i-1] - '0';        
        rep(k, 0, 13) {
          int r = k * 10 + j;
          r %= 13;
          dp[i][r] += dp[i-1][k];
        
        }
      
      }
      rep(j, 0, 13) dp[i][j] %= MOD;
    }
   

  
    printf("%lld\n", dp[strlen(S)][5]);

	return 0;
}


Measured memory_bytes: 10496
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int H,W;
vvc field;

int main(){
	cin>>H>>W;
	field=vvc(H,vc(W));
	for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin>>field[i][j];
	for(int k=0;k<2;k++){
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(!k){
					if(i%2==0){
						if(j==W-1) cout<<'.';
						else cout<<'#';
					}
					else{
						if(!j||field[i][j]=='#') cout<<'#';
						else cout<<'.';
					}
				}
				else{
					if(i%2==1){
						if(j) cout<<'#';
						else cout<<'.';
					}
					else{
						if(j==W-1||field[i][j]=='#') cout<<'#';
						else cout<<'.';
					}
				}
			}
			cout<<endl;
		}
		if(!k) cout<<endl;
	}
}

Measured memory_bytes: 1024
// line io: https://gist.github.com/hebiyan/cb56a7c7eb7c210ce562
use std::cmp::Ordering;

fn compute_temprature(A:f64, T:f64, H: Vec<&str>) -> Vec<f64> {
    // let mut idx_rasidual: Vec<(usize,u32)> = vec![];
    let mut rasidual: Vec<f64> = vec![];
    for (i, item) in H.iter().enumerate() {
        let h: f32 = item.parse().unwrap_or(0.0);
        // idx_rasidual.push((i, T - (h*0.006) as f64));
        rasidual.push((A - T + (h*0.006) as f64).abs())
    }
    // idx_rasidual
    rasidual
}

fn main() {
    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let N:f64 = vec[0].parse().unwrap_or(0.0);

    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let T:f64 = vec[0].parse().unwrap_or(0.0);
    let A:f64 = vec[1].parse().unwrap_or(0.0);


    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let H: Vec<&str> = line.split_whitespace().collect();
    
    let rasidual = compute_temprature(A, T, H);

    // println!("{}", rasidual.iter().map(|(x, y)| (y, x)).min());
    let index_of_min: Option<usize> = rasidual
        .iter()
        .enumerate()
        .min_by(|&(_, a), &(_, b)| a.partial_cmp(b).unwrap_or(Ordering::Equal))
        .map(|(index, _)| index);

    println!("{}", index_of_min.unwrap()+1);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vvi G(n),rG(n);
    rep(_,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        rG[b].pb(a);
    }
    int ans = inf;
    vi sv;
    rep(i,n) {
        vi dist(n,inf),pre(n);
        queue<int> q;
        q.push(i);
        dist[i] = 0;
        pre[i] = -1;
        while(q.size()) {
            int v = q.front();
            q.pop();
            for(int u : rG[v]) {
                if(chmin(dist[u],dist[v]+1)) {
                    q.push(u);
                    pre[u] = v;
                }
            }
        }
        int ind = n;
        dist.pb(inf);
        for(int u : G[i]) {
            if(dist[ind] > dist[u]) ind = u;
        }
        if(ind == n) continue;
        if(chmin(ans,dist[ind]+1)) {
            sv.clear();
            while(ind >= 0) {
                sv.pb(ind+1);
                ind = pre[ind];
            }
        }
    }
    if(ans == inf) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    for(int i : sv) cout << i << "\n";
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> L(N);
	Int lmax = -INF;
	Int temp;
	Int sum=0;
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		if (temp>=lmax) {
			lmax = temp;
		}
		sum += temp;
	}

	if (lmax<sum-lmax) cout << "Yes" << "\n";
	else cout << "No" << "\n";

}


Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  ns <- map (subtract 48 . fromEnum) <$> getLine :: IO [Int]
  let candidate = solve ns
      c' = filter ((==7) . fst) candidate
  putStrLn $ snd (head c') ++ "=7" 

solve (n:ns) =
  map (foldl
        (\(acc, str) (op, tr) ->
            (toFunc op acc tr, str ++ op : show tr)) (n, show n)) fs
  where
    toFunc c
      | c == '+' = (+)
      | otherwise = flip subtract
    ops = replicateM 3 ['+', '-']
    fs = map (`zip` ns) ops


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
#define MOD (ll)(1e9+7)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	vector<int> v(n);
	int s=0;
	for(auto &i:v)
	{
		cin>>i;
		s+=i;
	}
	int tmp=s;
	for(int j=1;j!=0;j=(j+2)%n)
	{
		tmp-=2*v[j];
	}
	cout<<tmp;
	For(i,0,n-2)
	{
		cout<<" "<<(v[i]-tmp/2)*2;
		tmp=(v[i]-tmp/2)*2;
	}
	return 0;
}









Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int Sosu(int *,int);
int Calc(int);

int main()
{
  int n,i,b,*a;

  scanf("%d",&n);

  a = (int *)malloc(n * sizeof(int));
  
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  b = Sosu(a,n);

  printf("%d\n",b);

  free(a);

  return 0;
}

int Sosu(int *a,int n)
{
  int i,d,c=0;
  for(i=0;i<n;i++){
    d = Calc(a[i]);
    if(d==1) c++;
  }

  return c;
}

int Calc(int a)
{
  int i=3;

  if(a==2) return 1;

  if(a<2 || a%2==0) return 0;

  while((double)i<=sqrt(a)){
    if(a%i==0) return 0;
    i += 2;
  }
  
  return 1;
}


  
  
    
    
    
  



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

int main()
{
	int h,w;
	cin >> h >> w;
	vector<vector<int>> c(10,vector<int>(10));
	for(int i = 0;i<10;i++)
	{
		for(int j = 0;j<10;j++)
		{
			cin >> c[i][j];
		}
	}
	for(int k = 0;k<10;k++)
	{
		for(int i = 0;i<10;i++)
		{
			for(int j = 0;j<10;j++)
			{
				c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
			}
		}
	}
	vector<vector<int>> A(h,vector<int>(w));

	ll ans = 0;
	for(int i = 0;i<h;i++)
	{
		for(int j = 0;j<w;j++)
		{
			cin >> A[i][j];
			if(A[i][j]==-1)continue;
			ans += c[A[i][j]][1];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
ll n,m,li[12],sw[12],ans;
vector<ll>ch[12];
void cal(){
	for(ll i=0;i<m;i++){
		ll cnt=0;
		for(ll j=0;j<ch[i].size();j++){
			if(sw[ch[i][j]]==1){
				cnt++;
			}
		}
		if(cnt%2!=li[i]){
			return ;
		}
	}
	ans++;
	return ;
}
void dep(ll now){
	if(now==n){
		cal();
		return ;
	}
	sw[now]=0;dep(now+1);
	sw[now]=1;dep(now+1);
}
int main() {
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll k;
		cin>>k;
		for(ll j=0;j<k;j++){
			ll x;
			cin>>x;
			x--;
			ch[i].push_back(x);
		}
	}
	for(ll i=0;i<m;i++){
		cin>>li[i];
	}
	dep(0);
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void mod(long long &a) { if (a > MOD) a %= MOD; }

int main(){
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<long long> cnt_A(N, 0);
    vector<long long> cnt_B(N, 0);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            if (A[i] > A[j]) {
                cnt_A[i]++;
            }
        }

        for (int j = i + 1; j < N; j++) {
            if (A[i] > A[j]) {
                cnt_B[i]++;
            }
        }
    }

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        long long a = (K * (K - 1)) / 2; mod(a);
        a *= cnt_A[i]; mod(a);
        long long b = (K * (K + 1)) / 2; mod(b);
        b *= cnt_B[i]; mod(b);
        ans += a + b; mod(ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
using ll = long long;

int N;
int L[2001];
int ans;


int main(){
	cin >> N;
	rep(i, N){ cin >> L[i]; }


	sort(L, L + N);
	REP(a, 0, N - 2){
		REP(b, a + 1, N - 1){
			REP(c, b + 1, N){
				if ((L[a] < L[b] + L[c]) && (L[c] < L[b] + L[a]) && (L[b] < L[c] + L[a])){
					ans++;
				}
			}
		}
	}


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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>

using namespace std;


int main(){
	long long int res=0,n;
	string str[605];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>str[i];
		str[i+n]=str[i];
	}
	
	for(int i=0;i<n;i++)
	{
		bool key=true;
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				if(str[j+i][k]!=str[k+i][j])
				{
					key=false;
					//cout<<i<<" "<<j<<" "<<k;
				}
			}
			
		}
		if(key)
		{
			res+=n;
		}
	}
	cout<<res;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> xs(n, -1);
    for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        if (xs[s] != -1 && xs[s] != c) {
            cout << "-1" << endl;
            return 0;
        }
        xs[s] = c;
    }
    if (xs[0] == -1 && n != 1) {
        xs[0] = 1;
    }
    for (int& x : xs) {
        if (x == -1) {
            x = 0;
        }
    }
    if (xs[0] == 0 && n != 1) {
        cout << "-1" << endl;
        return 0;
    }
    for (int x : xs) {
        cout << x;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256