akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
static const int N=100;
enum COLOR{WHITE,GRAY,BLACK};
static const int INFTY=(1<<21);

int n,M[N][N];
int d[N];

void bfs(int s)
{
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++)d[i]=INFTY;
    d[s]=0;
    int u;
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        for(int v=0;v<n;v++)
        {
            if(M[u][v]==0)continue;
            if(d[v]!=INFTY)continue;
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++)
    {
        cout<<i+1<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
    }
}

int main()
{
    int u,v,k,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)M[i][j]=0;
    }

    for(i=0;i<n;i++)
    {
        scanf("%d %d",&u,&k);
        u--;
        for(j=0;j<k;j++)
        {
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }

    bfs(0);
 	return 0;
}



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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	long N;
	cin >>N;
	vector<long> A(N, 0);
	for (long i=0; i<N; i++)
		cin >>A.at(i);
	long C=0;
	long D=1;
	long i=0;
	while(i<N) {
		if (A.at(i)>D) {
			C +=(A.at(i)-1)/D;
			A.at(i)=1;
			if (1==D)
				D++;
		} else if (A.at(i)==D)
			D++;
		i++;
	}
	cout <<C <<endl;
	return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);
		
		char c=in.next().charAt(0);
		
		if(c>='A' && c<='Z') {
			System.out.println("A");
		}
		else {
			System.out.println("a");
		}
	}

}


Measured memory_bytes: 27000
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
	while (true) {
		int n;
		cin >> n;

		if (n == 0) break;

		vector<int> s;
		inputVector(s, n);

		sort(all(s));

		int sum = 0;
		for (int i = 1; i < s.size() - 1; i++) {
			sum += s[i];
		}
		cout << sum / (int)(s.size() - 2) << endl;
	}

    return 0;
}

Measured memory_bytes: 3136
def f(p):
    bp=bin(p)[2:].zfill(n)
    tmp=[x]+[0 for _ in range(m)]
    cost=0
    for i in range(n):
        if bp[i]=="0": continue
        cost+=skill[i][0]
        for j in range(1,m+1):
            tmp[j]+=skill[i][j]
    return cost if min(tmp)>=x else 10**15

n,m,x=map(int,input().split())
skill=[list(map(int,input().split())) for _ in range(n)]
ans=10**15
for p in range(2**n):
    ans=min(ans,f(p))
print(ans if ans<10**15 else -1)

Measured memory_bytes: 69756
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

ll inverse(ll i) {
  ll x = MOD - 2;
  ll tmp = i;
  ll ret = 1;
  while (x) {
    if (x % 2 == 1) {
      ret = (ret * tmp) % MOD;
    }
    x /= 2;
    tmp = (tmp * tmp) % MOD;
  }
  return ret;
}

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

  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  unordered_map<ll, ll> m1;
  for (ll i = 1; i <= N; i++) {
    m1[i] = inverse(i);
  }

  unordered_map<ll, ll> m2;
  {
    ll sum = 0;
    for (ll i = 1; i <= N; i++) {
      sum += m1[i];
      sum %= MOD;
      m2[i] = sum;
    }
  }

  ll i1 = 1;
  for (ll i = 1; i <= N; i++) {
    i1 = (i1 * i) % MOD;
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ans += (i1 * A[i] % MOD) * (m2[abs(-i) + 1] + m2[abs(N - 1 - i) + 1] - 1);
    ans %= MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 9252
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i) 
constexpr int  INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	/
	/
	/
	*/
	int x, a, b; cin >> x >> a >> b;
	if (b > x + a) cout << "dangerous" << endl;
	else if (b > a) cout << "safe" << endl;
	else cout << "delicious" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, k;
	string s;
	cin >> k >> s;
	rep(i, min(k, (int)s.size()))
		cout << s[i];
	if (s.size() > k)
		printf("...\n");
	else
		printf("\n");
	return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll x, y; cin >> x >> y;
    if(abs(x - y) <= 1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <time.h>
#define fin(i,n) for (int i = 0; i < (int)(n); i++)
#define fin2(i,j,m,n) fin(i,m) fin(j,n)
using namespace std;

template <typename T> bool contains(vector<T> list, T value) {
	for (T tmp : list) if (tmp == value) return true;
	return false;
}


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

	vector<pair<int, int>> list;
	int a, b;
	fin(i, m) {
		cin >> a >> b;
		list.push_back(make_pair(a, b));
	}
	sort(list.begin(), list.end(), [](pair<int, int> a, pair<int, int> b) {
		return a.second < b.second;
	});

	int cnt = 0;
	int bridge = -1;
	fin(i, m) {
		pair<int, int> req = list[i];
		if (bridge != -1 && req.first <= bridge) {
			continue;
		}

		cnt++;
		bridge = req.second - 1;
	}

	cout << cnt << endl;

}

Measured memory_bytes: 1528
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	V := make([]float64, N)
	for i := 0; i < N; i++ {
		V[i] = float64(sc.nextInt())
	}
	for len(V) != 1 {
		sort.Float64s(V)
		mid := (V[0] + V[1]) / 2
		V = V[2:]
		V = append(V, mid)
	}
	fmt.Println(V[0])
}


Measured memory_bytes: 640
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(void){
	int x,i,j,k;
	char a[101],b[101];
	x=0;
	char c[12]="END_OF_TEXT";
	scanf("%s",a );
	while (1) {
		scanf("%s",b );
	  if(strstr(b,c)!=NULL)break;
		for(i=0;toupper(b[i])==toupper(a[i]);i++){
			if(toupper(b[i])=='\0'){
				x++;
				break;
			}
		}
	}

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

	return 0;
}

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

int main() {
	int N;
    vector<int> H, dp;
	cin >> N;
    for (int i = 0; i < N; ++i){
        int h = 0;
        cin >> h;
        H.push_back(h);
    }

    dp.push_back(0);
    dp.push_back(std::abs(H[1] - H[0]));
    for (int i = 2; i < N; ++i){
        dp.push_back(min(dp[i-1] + std::abs(H[i] - H[i-1]), dp[i-2] + std::abs(H[i] - H[i-2])));
    }

    cout <<  dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 4300
#include <stdio.h>

int main(void){ 

int a,b,c,i=0,Count=0;  

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

for(i=a;i<=b;i++){ 

if(c%i==0){ 

Count++; 

} 

} 

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

return 0;

}
 

Measured memory_bytes: 596
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {
		vector<pair<double, int>> bmi(n);
		rep(i, n) {
			int p; double h, w; cin >> p >> h >> w;
			bmi[p - 1].second = p;
			bmi[p - 1].first = abs(w / ((h / 100.)*(h / 100.)) - 22);
		}
		Cout(min_element(all(bmi)) - bmi.begin() + 1);
	}
}


Measured memory_bytes: 3140
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#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>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num);

    cins(arr);
    sort(arr.begin(), arr.end());

    int64_t sum = arr[0];
    int exclude = 0;
    for(int i = 1; i < num; i++) {
        int64_t cur = arr[i];
        debug("%d vs %d\n", sum, cur);
        if(sum*2 < cur) exclude = i;
        sum += cur;
    }
    cout << num-exclude << endl;
    return 0;
}

Measured memory_bytes: 3688
n=1<<18;N,m;L[1<<18],p;first[1<<18],next[1<<18];i;
long dat[1<<20],lazy[1<<20],A[1<<18],x;
eval(i,l,r){
	dat[i]+=lazy[i];
	lazy[2*i+1]+=lazy[i];
	lazy[2*i+2]+=lazy[i];
	lazy[i]=0;
}
long update(a,b,k,l,r){
	eval(k,l,r);
	return a<=l&r<=b?lazy[k]+=x,eval(k,l,r),dat[k]:l<b&a<r?dat[k]=fmax(
		update(a,b,2*k+1,l,(l+r)/2),
		update(a,b,2*k+2,(l+r)/2,r)
	):dat[k];
}
long query(a,b,k,l,r){
	eval(k,l,r);
	return a<=l&r<=b?dat[k]:l<b&a<r?fmax(
		query(a,b,2*k+1,l,(l+r)/2),
		query(a,b,2*k+2,(l+r)/2,r)
	):0;
}
main(j){
	for(scanf("%d%d",&N,&m);~scanf("%d%d%ld",L+j,&p,A+j);first[p]=j++)next[j]=first[p];
	for(;i++<N;){
		x=0;x=update(0,i,0,0,n);
		//x=query(0,i,0,0,n);
		update(i,i+1,0,0,n);
		for(p=first[i];p!=0;p=next[p])x=A[p],update(L[p],i+1,0,0,n);
	}
	x=0;
	printf("%ld",update(0,N+1,0,0,n));
	//printf("%ld",query(0,N+1,0,0,n));
}

/*
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
*/

Measured memory_bytes: 18944
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int cou = 0;
    for(int i = 0; i < s.length()/2; i++){
      if(s.charAt(i) == (s.charAt(s.length()-i-1))){

      }else{
        cou++;
      }
    }
    System.out.print(cou);
  }
}


Measured memory_bytes: 21844
#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 rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<pair<int,int>> p1(n),p2(n);
    rep(i,n) cin>>p1[i].first>>p1[i].second;
    rep(i,n) cin>>p2[i].first>>p2[i].second;
    sort(p2.begin(),p2.end());
    vector<int> xb(n),yb(n);
    vector<bool> used(n,false);
    int res=0;
    rep(i,n){
        int now=-1,it=-1;
        rep(j,n){
            if(!used[j]&&p2[i].first-p1[j].first>0&&p2[i].second-p1[j].second>0){
                if(chmax(now,p1[j].second))it=j;
            }
        }
        if(it==-1)continue;
        used[it]=true;
        res++;
    }
    //rep(i,n) cout<<used[i]<<endl;
    cout<<res<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.BigDecimal;

public class Main {
  public static void main (String args[]) {
    Scanner sc = new Scanner(System.in);
    
    String A = sc.next();
    String B = sc.next();
    BigDecimal b1 = new BigDecimal(A);
    BigDecimal b2 = new BigDecimal(B);
    BigDecimal b3 = b1.multiply(b2);
    BigDecimal bd1 = b3.setScale(0, BigDecimal.ROUND_DOWN);
    System.out.println(bd1);
  }
}

Measured memory_bytes: 35892
N, M = map(int, input().split())
li = [list(map(int, input().split())) for i in range(M)]
dic = {}
for i in range(N) :
    dic[i] = 0
for l in li :
    dic[l[0] - 1] += 1
    dic[l[1] - 1] += 1
for v in dic.values() :
    print(v)


Measured memory_bytes: 3060
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
using mat = vector<vector<ll>>;
using vec = vector<ll>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){

int N;
cin>>N;
ll x[N+1],A[N+1];
rep3(i,N)cin>>A[i];
rep3(i,N)x[i]=0;
x[N]=A[N];
rep3(i,N-1){
    if(i%2==0){
        x[N]+=A[i];
    }
    else{
        x[N]-=A[i];

    }
}
x[N]/=2;
repr3(i,N-1){
    x[i]=A[i]-x[i+1];
}
rep3(i,N){
    cout<<2*x[i];
    if(i!=N)cout<<" ";
    else cout<<endl;
}
return 0;
}

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

#define ll long long

using namespace std;

const int MAXN = 110;

int res = 0;
ll n, m, k, t, q, u, w, y, r;
int a[MAXN], b[MAXN], c[MAXN], d[MAXN], Val[MAXN];

void dfs(int x, int fa){
    Val[x] = fa;
    if (x == n) {
        int tmp = 0;
        for (int i = 0; i < q; i++) {
        	if (Val[b[i]] - Val[a[i]] == c[i]) tmp += d[i];
		}
        res = max(res, tmp);
        return;
    }
    for (int i = fa; i <= m; i++)
        dfs(x + 1, i);
}

int main() {
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 0; i < q; i++) {
    	scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	}
    for (int i = 1; i <= m; i++) {
    	dfs(1, i);
	}
        
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3752
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{

   
    string p;
    cin >> p;

    int n = p.size() / 2;
    int da = n, db = n;
    if (p.size() % 2) {
        da = n - 1; db = n + 1;
    }
    
    string a = p.substr(0, p.size()/2 );
    string b = p.substr(db, p.size() );
    bool f = 0;
    reverse(b.begin(), b.end());
    for (int i = 0; i < a.size()/2; i++) {
        if (a[i] != a[a.size() - 1 - i])f = 1;
        if (b[i] != b[b.size() - 1 - i])f = 1;
    }
   // cout << a << endl;
   // cout << b;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] != b[i]) {
            f = 1;
        }
    }
    if (f)cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s; cin >> s;
    int same = 0;
    rep(i, 3) {
        for (int j=i+1; j<4; j++) {
            if (s[i] == s[j]) same++;
        }
    }
    if (same == 2) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000
using ppp=pair<ll,pair<int,int>>;

int main(){
  ll N,M,S;
  cin>>N>>M>>S;
  vector<vector<pair<int,int>>> G(N);
  vector<ll> A(M),B(M);
  for(int i=0;i<M;i++){
    int u,v;
    cin>>u>>v>>A.at(i)>>B.at(i);
    u--;
    v--;
    G.at(u).push_back(make_pair(v,i));
    G.at(v).push_back(make_pair(u,i));
  }
  vector<ll> C(N),D(N);
  for(int i=0;i<N;i++){
    cin>>C.at(i)>>D.at(i);
  }

  vector<vector<ll>> time(N,vector<ll>(2501,INF));
  if(S>2500){
    S=2500;
  }
  time.at(0).at(S)=0;
  priority_queue<ppp,vector<ppp>,greater<ppp>> pq;
  pq.push(make_pair(0,make_pair(0,S)));
  while(!pq.empty()){
    int v=pq.top().second.first;
    int money=pq.top().second.second;
    pq.pop();
    int nm=(int)min<ll>(2500,money+C.at(v));
    if(time.at(v).at(nm)>time.at(v).at(money)+D.at(v)){
      time.at(v).at(nm)=time.at(v).at(money)+D.at(v);
      pq.push(make_pair(time.at(v).at(nm),make_pair(v,nm)));
    }
    for(auto p:G.at(v)){
      int nv=p.first;
      int e=p.second;
      if(money<A.at(e)){
        continue;
      }
      if(time.at(nv).at(money-A.at(e))>time.at(v).at(money)+B.at(e)){
        time.at(nv).at(money-A.at(e))=time.at(v).at(money)+B.at(e);
        pq.push(make_pair(time.at(nv).at(money-A.at(e)),make_pair(nv,money-A.at(e))));
      }
    }
  }

  for(int i=1;i<N;i++){
    ll ans=INF;
    for(int j=0;j<=2500;j++){
      ans=min<ll>(ans,time.at(i).at(j));
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 6360
use std::io::{self, Write, BufWriter};

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty), +) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn main() {
    let out = io::stdout();
    let mut out = BufWriter::new(out.lock());
    loop {
        from_line!(h: usize, w: usize);
        if h == 0 && w == 0 {
            break;
        }
        let line = ("#".repeat(w) + "\n").repeat(h);
        out.write(&line.as_bytes()).unwrap();
        out.write(b"\n").unwrap();
    }
}


Measured memory_bytes: 5024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

bool isPrime(int x){
  int i;
  if(x < 2)return 0;
  else if(x == 2) return 1;
  if(x%2 == 0) return 0;
  for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
  return 1;
}

int binary(vector<int> a,lint key) {
  lint left = 0;
  lint right = a.size();
  while(left<right){
    lint mid = (left+right)/2;
    if(a[mid] == key){
      return 1;
    }
    else if(key<a[mid]){
      right = mid;
    }
    else{
      left = mid+1;
    }
  }
  return 0;
}

int main(){
  int w,h;
  char c;
  cin>>w>>h;
  cin>>c;
  string hf="+"+string(w-2,'-')+"+";
  cout<<hf<<endl;
  int count=2;
  for(int i=0;i<h-2;i++){
    if((h+1)/2==count){
      string flag = "|"+string((w-2)/2,'.')+c+string((w-2)/2,'.')+"|";
      cout<<flag<<endl;
    }
    else{
      string flag = "|"+string((w-2),'.')+"|";
      cout<<flag<<endl;
    }
    count++;
  }
  cout<<hf<<endl;
}



Measured memory_bytes: 3168
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

struct LeqCount {
    int cnt;
    LeqCount() : cnt(0) {}
    bool operator()(int lhs, int rhs)
    {
        ++cnt;
        return lhs <= rhs;
    }
};

void read_problem(vector<int>& ary)
{
    int n;
    scanf("%d\n", &n);

    ary.resize(n);
    REP(i, n) {
        scanf("%d", &ary[i]);
    }
}

void merge(vector<int>& ary, int start, int mid, int end, LeqCount& leq)
{
    constexpr int INF = numeric_limits<int>::max();

    vector<int> ary_l(ary.begin() + start, ary.begin() + mid);
    vector<int> ary_r(ary.begin() + mid,   ary.begin() + end);
    ary_l.push_back(INF);
    ary_r.push_back(INF);

    int i = 0;
    int j = 0;
    FOR(k, start, end) {
        if(leq(ary_l[i], ary_r[j])) {
            ary[k] = ary_l[i++];
        }
        else {
            ary[k] = ary_r[j++];
        }
    }
}

void mergesort(vector<int>& ary, int start, int end, LeqCount& leq)
{
    if(end - start >= 2) {
        int mid = (start + end) / 2;
        mergesort(ary, start, mid, leq);
        mergesort(ary, mid, end, leq);
        merge(ary, start, mid, end, leq);
    }
}

int main()
{
    vector<int> ary;
    read_problem(ary);
    int n = ary.size();

    LeqCount leq;
    mergesort(ary, 0, ary.size(), leq);

    REP(i, n) {
        printf("%d%c", ary[i], i == n-1 ? '\n' : ' ');
    }
    printf("%d\n", leq.cnt);

    return 0;
}

Measured memory_bytes: 8232
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    int m, f, b; cin>>m>>f>>b;
    if(b - m <= f) cout << max(0, b - m) << endl;
    else cout << "NA" << endl;
}


Measured memory_bytes: 3104
#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 < (int)(n); ++i)

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> d;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    d.push_back({a, b});
  }

  sort(d.begin(), d.end());
  ll ans = 0;
  rep(i, n) {
    int buy = min(m, d[i].second);
    ans += (ll)d[i].first * buy;
    m -= buy;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4300
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val S = readLine()!!.split(' ').map{ it.toInt() }
    val q = readLine()!!.toInt()
    val T = readLine()!!.split(' ').map{ it.toInt() }
    assert (n == S.size)
    assert (q == T.size)
    var ans = 0
    for(t in T){
        for(s in S){
            if (t == s) {
                ans++
                break
            }
        }
    }
    println(ans)
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

// void dp(sp_1, sp_2.....)
// {
// 	if()//exit statement
// 	if()//using the memoization technique
// 	ll ans = //default/dummy answer
// 	//recursions
// 			//max/min
// 	return memo[][].. = ans;

// }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 	cout.tie(NULL);
 	//memset(memo, -1/0, sizeof memo);
 		ll a,p; cin>>a>>p;
 	cout<<(3*a+p)/2<<endl;
	return 0;
}

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

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

	int n, m;
	cin >> n >> m;
	vector<vector<int>> c(m);
	while (n--) {
		int a, b;
		cin >> a >> b;
		if (a <= m)
			c[a - 1].push_back(b);

	}
	int r = 0;
	priority_queue<int> q;
	for (auto const& l : c) {
		for (int x : l) {
			q.push(x);
		}
		if (!q.empty()) {
			r += q.top();
			q.pop();
		}
	}
	cout << r << '\n';
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

int main(){
	int n;
	cin>>n;
	int a;
	vector<pii> p;
	for (int i = 0; i < n; ++i){
		cin>>a;
		p.pb(make_pair(a,i));
	}

	sort(all(p));

	for (int i = 0; i < n-1; ++i){
		cout<<p[i].second+1<<' ';
	}

	cout<<p[n-1].second+1<<endl;



	return 0;
}


Measured memory_bytes: 1780
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a, e;
	cin >> a;
	if (a == 1 || a == 2 || a == 3 || a == 5 || a == 6 || a == 9 || a == 10 || a == 13 || a == 17) {
		cout << "No" << "\n";
	}
	else {
		cout << "Yes" << "\n";
	}
	cin >> e;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=1000005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
char str[max_n];
void reads(string& s){scanf(" %s",str);s=str;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,a[max_n];
int p[max_n];
int cnt[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",a+i);
        cnt[a[i]]++;
    }
    for(int i=1;i<max_n;i++){
        if(cnt[i])for(int j=i*2;j<max_n;j+=i)p[j]=true;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(cnt[a[i]]==1&&!p[a[i]])ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 12320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_6_B_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            List<string> vs0= new List<string>() {"S 1" , "S 2" , "S 3" , "S 4" , "S 5" , "S 6" , "S 7"  , "S 8" , "S 9", "S 10" , "S 11" , "S 12" , "S 13"
                , "H 1" , "H 2" , "H 3" , "H 4" , "H 5" , "H 6" , "H 7" , "H 8" , "H 9" , "H 10" , "H 11" , "H 12" , "H 13"
                , "C 1" , "C 2" , "C 3" , "C 4" , "C 5" , "C 6" , "C 7" , "C 8" , "C 9" , "C 10" , "C 11" , "C 12" , "C 13"
                , "D 1" , "D 2" , "D 3" , "D 4" , "D 5" , "D 6" , "D 7" , "D 8" , "D 9" , "D 10" , "D 11" , "D 12" , "D 13" };
            string[] str1 = null;
            for (int i = 0; i < n; i++)
            {
                string vs = Console.ReadLine();
                vs0.Remove(vs);
            }
            foreach (string str in vs0)
            {
                Console.WriteLine(str);
            }
        }
    }
}



Measured memory_bytes: 17808
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 3e3 + 100;

int n;
ll pre[MAXN];
ll DP[MAXN][MAXN];
string s;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	cin >> s;
	DP[1][1] = 1;
	pre[1] = DP[1][1];
	FOR(i, 2, n) {
		if (s[i - 2] == '<') {
			DP[i][1] = 0;
			FOR(j, 2, i) DP[i][j] = (pre[j - 1]) % MOD; 
		}
		else {
			DP[i][i] = 0;
			FOR(j, 1, i - 1) DP[i][j] = ((pre[i - 1] - pre[j - 1]) % MOD + MOD) % MOD;
		}
		FOR(j, 1, n) {
			pre[j] = (pre[j - 1] + DP[i][j]) % MOD;
			//cout << i << ' ' << ' ' << j << ' ' << pre[j] << '\n';
		}
	}
	ll res = 0;
	cout << pre[n] << '\n';
}

Measured memory_bytes: 72320
a, b = gets.split.map(&:to_i)
b += 1

y = 1
loop do
    break if b < (y << 1)
    y <<= 1
end
ans = 0
loop do
    break if y <= 1
    mod_a = a % (y << 1) - y
    mod_b = b % (y << 1) - y
    if ([0, mod_b].max + [0, mod_a].max).odd?
        ans += y 
    end
    y >>= 1
end
puts ans + ((b / 2 - a / 2).odd? ? 1 : 0 )

Measured memory_bytes: 1788
#include <cstdio>
using namespace std;

bool v[10];
int d[10];

bool end() {
	bool a = true;
	for (int i = 0; i <= 9; i++) {
		a = a&&v[i];
	}
	return a;
}

int minv() {
	int i,j, dmin=200000;
	for (i = 0; i <= 9; i++) {
		if (v[i] == false && d[i] < dmin) {
			dmin = d[i];
			j = i;
		}
	}
	v[j] = true;
	return j;
}

int main() {
	int h, w, c[10][10], a[201][201], i, j, k, u;
	long long sum=0;
	scanf("%d %d", &h,&w);
	for (i = 0; i <= 9; i++) {
		for (j = 0; j <= 9; j++) {
			scanf("%d", &c[i][j]);
		}
		d[i] = c[i][1];
		v[i] = (i == 1);
	}
	while (!end()) {
		u = minv();
		for (j = 0; j <= 9; j++) {
			if (d[j] > d[u] + c[j][u]) {
				d[j] = d[u] + c[j][u];
			}
		}
	}
	for (i = 1; i <= h; i++) {
		for (j = 1; j <= w; j++) {
			scanf("%d", &a[i][j]);
			if (a[i][j] != -1) {
				sum += d[a[i][j]];
			}
		}
	}
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 384
import sys
from fractions import gcd
n = int(input())
a = [int(input()) for _ in range(n+1)]
x = 0
while True:
	m = abs(sum([a[i]*pow(x, n-i) for i in range(n+1)]))
	if m != 0:
		break
	x += 1
ps = []

i = 2
while i**2 <= m and i <= n+1:
#for i in range(2, int(sqrt(m))+1):
	if m%i == 0:
		ps.append(i)
		while m%i == 0:
			m //= i
	i += 1
if m != 1 and n != 0:
	ps.append(m)
#print(ps)
g = a[0]
for i in range(1, n+1):
	g = gcd(g, abs(a[i]))

#print(g)
ans = []

i = 2
while i**2 <= g:
#for i in range(2, int(sqrt(m))+1):
	if g%i == 0:
		if i >= n+1:
			ans.append(i)
		while g%i == 0:
			g //= i
	i += 1
if g != 1 and g >= n+1:
	ans.append(g)

a = a[::-1]
for p in ps:
	if p-1 > n:
		ng = False
		for i in range(1, n+1):
			if a[i]%p != 0:
				ng = True
				break
		if not ng:
			ans.append(p)
	else:
		mods = [0 for _ in range(p-1)]
		for i in range(1, n+1):
			mods[i%(p-1)] += a[i]
			mods[i%(p-1)] %= p
		if mods[0] == 0:
			ng = False
			for i in range(1, p-1):
				if mods[i] != 0:
					ng = True
					break
			if not ng:
				ans.append(p)
ans = sorted(list(set(ans)))
if ans:
	print(*ans, sep="\n")

Measured memory_bytes: 12484
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n = I()
p = LI()
q = LI()

if p==q:
    print(0)
    exit()

l = [i for i in range(1,n+1)]
a=0
b=0
for i,x in enumerate(itertools.permutations(l)):
    if p==list(x):
        a = i
    if q==list(x):
        b = i
print(abs(a-b))


Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
typedef long long ll;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
int a[N], b[N], c[N];
int f[N][3];
int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	for(int i=1; i<=n; i++){
		f[i][0] = max(f[i-1][1], f[i-1][2]) + a[i];
		f[i][1] = max(f[i-1][0], f[i-1][2]) + b[i];
		f[i][2] = max(f[i-1][0], f[i-1][1]) + c[i];
	}
	int ans = max(f[n][0], max(f[n][1], f[n][2]));
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#define N 100000

int linerSearch(int);

int A[N],n;

int main(){

  int m,j,key,count=0;

  scanf("%d",&n);
  for(j = 0 ; j < n ; j++){
    scanf("%d",&A[j]);
  }

  scanf("%d",&m);
  for(j = 0 ; j < m ; j++){
    scanf("%d",&key);
    
    if(linerSearch(key) == 1) count++;
  }

  printf("%d\n",count);
  return 0;
}

int linerSearch(int key)
{
  int i;

  for(i = 0 ; i < n ; i++){
    if(A[i] == key) return 1;
  }
  return 0;
}

Measured memory_bytes: 632
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*16
#define REP(i,n) for(long long i = 0;i < n;++i)
vector<long long> vertexs[200000];
vector<long long> gyaku[200000];
long long cnt[200000] = {};
long long tere[200000] = {};
long long ans[200000] = {};
int main() {
	int n, m;
	cin >> n >> m;
	REP(i, n+m-1) {
		long long a, b;
		cin >> a >> b;
		vertexs[a].push_back(b);
		gyaku[b].push_back(a);
		tere[b]++;
	}
	for (int start = 1; start <= n; ++start) {
		if (tere[start] == 0) {
			//startは根
			queue<int> next;
			next.push(start);
			vector<int> saisyuu;
			while (next.empty() == false) {
				int now = next.front();
				next.pop();
				if (vertexs[now].size() != 0) {
					for (int i = 0; i < vertexs[now].size(); ++i) {
						tere[vertexs[now][i]]--;
						cnt[vertexs[now][i]] = max(cnt[vertexs[now][i]], cnt[now] + 1);
						if (tere[vertexs[now][i]] == 0) {
							next.push(vertexs[now][i]);
						}
					}
				}
				else {
					saisyuu.push_back(now);
				}
			}
			for (int i = 0; i < saisyuu.size(); ++i) {
				int now = saisyuu[i];
				while (now != start) {
					for (int q = 0; q < gyaku[now].size(); ++q) {
						if (cnt[gyaku[now][q]] == cnt[now] - 1) {
							ans[now] = gyaku[now][q];
							now = gyaku[now][q];
							break;
						}
					}
				}
			}
			for (int i = 1; i <= n; ++i) {
				cout << ans[i] << endl;
			}
			return 0;
		}
	}
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  map<int,int> m;

  rep(i,n){
    cin >> a[i];
    m[a[i]]++;
  }

  sort(all(a));
  a.erase(unique(all(a)), a.end());

  int ans=0;
  rep(i,a.size()){
    if(m[a[i]]%2==1)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5376
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}

fn main(){
    let mut scan = Scanner::new();
    let n:usize = scan.next();
    let mut se: HashSet<String> = HashSet::with_capacity(n);

    for _ in 0..n {
        let s: String = scan.next();
        se.insert(s);
    }
    println!("{}", se.len());
}


Measured memory_bytes: 14672
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n-1; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;


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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

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 main()
{
    // input
    ll N, M;
    ll node1, node2;
    cin >> N >> M;
    vector<pair<ll,ll>> A(M);
    for (ll i = 0; i < M; i++)
    {
        cin >> node1 >> node2;
        --node1, --node2;
        A[i].first = node1;
        A[i].second = node2;
    }

    // calculation
    vector<ll> ans(M);
    ans[M - 1] = (N * (N - 1)) / 2; // 全ての頂点が孤立している状態

    UnionFind uf(N);
    for (ll i = M - 1; i >= 1; --i)
    {
        node1 = A[i].first, node2 = A[i].second;
        if (uf.issame(node1, node2))
        {
            ans[i - 1] = ans[i];
        }
        else
        {
            // 根が異なるとき，それぞれのサイズの積（頂点の組み合わせ）を引く．
            ans[i - 1] = ans[i] - (uf.size(node1) * uf.size(node2));
            uf.merge(node1, node2);
        }
    }

    REP(i, M)
    {
        cout << ans[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    PRINT((b-a+1)-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/(c*d/gcd(c,d))-(a-1)/(c*d/gcd(c,d))));
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

ll n,m,a,b,c,x,y,aa[100010],ba[100010];
bool r,br,ar;
string s;
char ca,cb;


int main(){
    cin>>a>>b;
    cout<<(a-1)*(b-1)<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  bool result = true;
  if(c < a) result = false;
  if(c > b) result = false;
  if(result){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256