akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  ll n; cin >> n;
  ll ans = 0;
  vector<ll> memo(n+1, 0);
  for (int i=1; i<=n; i++) {
    for (int j=i; j<=n; j+=i) memo[j]++;
  }
  REP(i,n+1) ans += i*memo[i];
  COUT(ans);
  return 0;
}

Measured memory_bytes: 81328
package main

import "fmt"

func main() {
	var N, T int
	fmt.Scan(&N, &T)

	ts := make([]int, N)
	for i := range ts {
		fmt.Scan(&ts[i])
	}

	var sum int
	for i := 0; i < N-1; i++ {
		sum += f(ts[i], ts[i+1], T)
	}
	fmt.Println(sum + T)
}

func f(t1, t2, T int) int {
	diff := abs(t1, t2)
	if diff >= T {
		return T
	}
	return diff
}

func abs(x, y int) int {
	a := x - y
	if a < 0 {
		return a * -1
	}
	return a
}


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

int main() {
  string X;
  cin >> X;
  for(int i=X.size()/2-1; i>0; i--) {
    if(X.substr(0, i) == X.substr(i, i)) {
      cout << i*2;
      return 0;
    }
  }
}

    

Measured memory_bytes: 256
import math as m

def prime(n):
    if n <= 1:
        return False
    for i in range(2,int(m.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True
    
a = int(input())
x = []
for j in range(a):
    b = int(input())
    if prime(b):
        x.append(b)
print(len(x))


Measured memory_bytes: 5684
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef unsigned long long lu;
typedef pair<int, int> pi;
typedef long long ll;
typedef long double lf;
const ll mod = 1e9 + 7;
vector<ll> d(100);
void dp(int idx, vll &a)
{
    d[idx] = 0;
    for (int i = 0; i < idx; i++)
    {
        d[idx] = max(d[idx], d[i]);
    }
    for (int i = 0; i < idx; i++)
    {
        if (a[idx] > a[i])
        {
            d[idx] = max(d[idx], (d[i] / a[i]) * a[idx] + d[i] % a[i]);
        }
    }
}
int32_t main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vll a(n);
    fr(i, 0, n)
    {
        cin >> a[i];
    }
    d[0] = 1000;
    for (int i = 1; i < n; i++)
    {
        dp(i, a);
    }
    cout << d[n - 1] << "\n";
    return 0;
}

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

int main()
{
	int n,m,a[50],b[50];
	cin>>n>>m;
	for(int i=0;i<m;i++) cin>>a[i]>>b[i];
	
	int v[50]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(a[j]==i+1) v[i]++;
			if(b[j]==i+1) v[i]++;
		}
	}
	
	for(int i=0;i<n;i++) cout<<v[i]<<endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Calculator {
	String testCal(int m, int f, int r) {
		int sum = 0;
		String testGrade = null;
		/**
		 * ???????????????
		 */
		sum = m + f;
		if (m == -1 || f == -1) { // ??????or?????????????????????????????????????????¶??§F
			testGrade = "F";
		} else if (sum >= 80) { // ??????+??????????????????80?????\?????????A
			testGrade = "A";
		} else if (sum >= 65 && m + f < 80) { // ??????+??????????????????65?????\???,80???????????????"B"
			testGrade = "B";
		} else if (sum >= 50 && m + f < 65) { // ??????+??????????????????50?????\???,65???????????????"C"
			testGrade = "C";
		} else if (sum >= 30 && m + f < 50) { // ??????+??????????????????30?????\???,50???????????????"D"
												// ?????????????????????50??\?????????"C"
			if (r >= 50) {
				testGrade = "C";
			}
			else
			testGrade = "D";
		} else if (sum < 30) { // 30?????\??????F
			testGrade = "F";
		}

		return testGrade;
	}

}

public class Main {

	public static void main(String[] args) throws IOException {
		Calculator cal = new Calculator();
		int m = 0, f = 0, r = 0; // ????????????????????????
		String str;
		String tmpBox[] = new String[3]; // split?????¨??????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> result = new ArrayList<String>();
		while (true) {
			str = br.readLine();
			if (str.equals("-1 -1 -1")) {
				break;
			}
			tmpBox = str.split(" ", 0);
			m = Integer.parseInt(tmpBox[0]);
			f = Integer.parseInt(tmpBox[1]);
			r = Integer.parseInt(tmpBox[2]);
			result.add(cal.testCal(m, f, r));
		}
		for (int i = 0; i < result.size(); ++i) {
			System.out.println(result.get(i));
		}
	}

}

Measured memory_bytes: 24372
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s;
    cin >> s;
    bool ok = false;
    rep (i, s.size()) {
        if (s[i] - '0' == 7)
            ok = true;
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
b = input().split(" ")
min = int(b[0])
max = int(b[0])
total = 0
for i in range(n):
    if int(b[i]) <= min:
        min = int(b[i])
    if int(b[i]) >= max:
        max = int(b[i])
    total += int(b[i])
print("%d %d %d"%(min, max, total))



Measured memory_bytes: 6340
n = int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
p = 9999
m = 9999
for i in range(n):
  tem = t - (H[i]*0.006)
  dist = abs(a-tem)
  if dist < m:
    p = H[i]
    m = dist
print(H.index(p)+1)

Measured memory_bytes: 9256
#include<stdio.h>
int main(){
  int n, x, nokori;
  scanf("%d%d", &n, &x);
  int i, m;
  int sum=0;
  int min=1000;
  for( i=0; i<n; i++){
    scanf("%d", &m);
    sum=sum+m;
    if(min>m) min=m;
  }
  nokori=x-sum;
  printf("%d\n", nokori/min+n);
  //printf("%d\n", sum);
  return 0;
}
    

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const int MAX_V = 110;

struct Flow{
    struct edge{
        int to, cap, rev;
    };
    vector<edge> G[MAX_V];//隣接リスト
    bool used[MAX_V];

    void add_edge(int from, int to, int cap){
        G[from].push_back((edge){to, cap,(int) G[to].size()});
        G[to].push_back((edge){from, 0, (int) G[from].size() - 1});
    }

    //増加パスを探す
    int dfs(int v, int t, int f){
        if(v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); ++i){
            edge &e = G[v][i];
            if(!used[e.to] && e.cap > 0){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    //sからtへの最大流
    int max_flow(int s, int t){
        int flow = 0;
        while(1){
            memset(used, 0, sizeof(used));
            int f = dfs(s, t, INF);
            if(f == 0) return flow;
            flow += f;
        }
    }
};

int main(){
 int V,E; cin >> V >> E;
  Flow mf;
  for(int i = 0; i < E; i++){
   int u,v,c; cin >> u >> v >> c; 
    // u and v have already been 0-indexed
    mf.add_edge(u,v,c);}
  
  cout << mf.max_flow(0, V - 1) << endl; 
  return 0;}


Measured memory_bytes: 3220
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())

flag = False
for cx in range(101):
    for cy in range(101):
        needH = -1
        for i in range(N):
            if h[i] > 0:
                H = abs(x[i] - cx) + abs(y[i] - cy) + h[i]
                if needH == -1:
                    needH = H
                else:
                    if needH != H:
                        needH = -2
                        break
        if needH == -2:
            continue
            
        for i in range(N):
            if h[i] == 0:
                dist = abs(x[i] - cx) + abs(y[i] - cy)
                # distの方が大きくなければいけない
                if needH > dist:
                    needH = -2
                    break
        if needH == -2:
            continue
        else:
            flag = True
        if flag:
            break
    if flag:
        break
                    
print(cx, cy, H)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    map<int, int> A;
    rep(i, n) {
        int a;
        cin >> a;
        A[a]++;
    }
    if(A.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}


//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i = 0; i < n; i++){
    int s;
    cin>>s;
    a[i] = s-1;
  }
  int counter = 0;
  int j = 0;
  for(int i = 0; i < n; i++){
    j = a[j];
    counter++;
    if(j == 1){
      cout<<counter<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}
  



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin >> A.at(i);
	}

	for(int i=0;i<N-1;i++){
		for(int j=N-1;0<j;j--){
			if(A.at(j) > A.at(j-1)){
				int temp = A.at(j-1);
				A.at(j-1) = A.at(j);
				A.at(j) = temp;
			}
		}
	}

	int math=0;
	for(int i=0;i<N;i++){
		if(i == 0 || i %2 == 0){
			math += A.at(i);
		}else{
			math -= A.at(i);
		}
	}
	cout << math<< endl;
}

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

namespace Atc_0039
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            int N = int.Parse(S);

            int result = 0;

            for (int i = 1; i <= N; i++)
            {
                int cnt = 0;
                if (i % 2 == 1)
                {
                    for (int j = 1; j <= i; j++)
                    {
                        if (i % j == 0)
                        {
                            cnt++;
                        }
                    }

                    if (cnt == 8)
                    {
                        result++;
                    }
                }
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 27460
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vl a(n);
	cin>>a;
	ll t=sum(a);
	vl p;
	range(i,1,1+(ll)ceil(sqrt(t))){
		if(t%i==0){
			p.push_back(i);
			if(t%i!=i)p.push_back(t/i);
		}
	}
	sort(rall(p));
	for(auto&e:p){
		vl x(n+1,0);
		rep(i,n){
			x[i+1]=a[i]%e;
		}
		sort(all(x));
		partial_sum(all(x),x.begin());
		rep(i,n+1){
			if(x[i] == (n-i)*e-(x[n]-x[i]) and x[i]<=k){
				puta(e);
				return 0;
			}
		}
	}
	return 0;
}

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

int main() {
    ll n;
    cin>>n;
    bool ans=0;
    for(int i=0;i<n;i++){
        char a;
        cin>>a;
        if(a=='Y'){
            ans=1;
        }
    }
    if(ans==1){
        cout<<"Four";
    }
    else
        cout<<"Three";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i,j;
  int p[1001];
  int sum;
  while(1){
    cin>>n>>m;
    if(n==0&&m==0) break;
    for(i=0;i<n;++i) cin>>p[i];
    sort(p,p+n);
    sum=0;
    if(n%m==0){
      for(i=0;i<n;i+=m)
	for(j=1;j<m;++j)
	  sum+=p[i+j];
    }else{
      for(i=0;i<n%m;++i)
	sum+=p[i];
      for(;i<n;i+=m)
	for(j=1;j<m;++j)
	  sum+=p[i+j];
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 3032
#include<bits/stdc++.h> 
using namespace std; 
int gcdEx(int a, int b, int *x, int *y){if(!a){*x=0;*y=1;return b;} 
int x1,y1,gcd=gcdEx(b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
int modI(int b, int m)      {int x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
typedef long long           ll;
typedef pair<int, int>      pii;
typedef vector<int>         vi;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define loop(i,b,n)           for(int i=b;i<n;i++)
#define loopv(i,b,n,a)         for(int i=b;i<n;i+=a)
#define loopr(i,b,n)           for(int i=n;i>=0;i--)

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define MOD                 1000000007 
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(int)(MOD+((a%MOD)-(b%MOD))%MOD):(int)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (int)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;}
y=y>>1; x=(x*x)%MOD;} return r;}

int main()
{ 
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
  //  start_routine();
    
   ll t,sum=0,ans=0,n;
  // cin>>t;

   //while(t--) {  cin>>n ; }
   cin>>n;
   vector<ll> a(n),u(n); 
   loop(i,0,n)
   cin>>a[i];
   u=a;
   sort(all(u));
   
   ll c=0;
   loop(i,0,n)
   if(a[i]==u[i])
   c++; 
   
   if(c==n-2||c==n) 
   cout<<"YES" ;
   else
   cout<<"NO";
    
    return 0;
}


Measured memory_bytes: 256
nums = list(map(int, input().split()))
nums2 = list(map(int, input().split()))

import random

class dice:
    def __init__(self):
        self.top = 0
        self.right = 0
        self.front = 0
        self.left = 0
        self.back = 0
        self.bottom = 0
    
    def set_num(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums
        return self
    
    def get_right(self, f_top, f_front):
        while f_top!=self.top or f_front!=self.front:
            self.roll(random.randint(0,3))
        return self.right
    
    def check(self, dice2):
        cnt=0
        while cnt<10000:
            if self.is_same(dice2):
                return True
            cnt+=1
            self.roll(random.randint(0,3))
        
        return False
        
        
    def is_same(self, dice2):
        if (self.top, self.right, self.left, self.front, self.back, self.bottom)==(d2.top, d2.right, d2.left, d2.front, d2.back, d2.bottom):
            return True
        else:
            return
        
    def roll(self, command):
        if command==0:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.left, self.front, self.top, self.bottom, self.back, self.right
        elif command==1:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.right, self.front, self.bottom, self.top, self.back, self.left
        elif command==2:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.front, self.bottom, self.right, self.left, self.top, self.back
        elif command==3:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.back, self.top, self.right, self.left, self.bottom, self.front
            

d = dice()
d.set_num(nums)
d2 = dice()
d2.set_num(nums2)

if d.check(d2):
    print('Yes')
else:
    print('No')


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

int gcd(int x,int y){
	int b = x%y;
	if(b != 0)
		return gcd(y,b);
	return y;
}

int main(){
	int x,y;
	cin >> x >> y;
	if(x<y){
		int temp = x;
		x = y;
		y = temp;
	}
	cout << gcd(x,y) << endl;
	return 0;
}

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

struct Node{
    int parent = -1;
    int depth;
    vector<int> child;
};

class Tree{
    int root = -1;
    vector<Node> node;
    void calc_root(){
        int i = 0;
        for (int i = 0; ; i++) {
            if (node[i].parent == -1) {
                root = i;
                return;
            }
        }
    }
    void calc_all_depth(int id, int depth){
        node[id].depth = depth;
        for (int i = 0; i < node[id].child.size(); i++) {
            calc_all_depth(node[id].child[i], depth + 1);
        }
    }
public:
    Tree(int n){
        node.resize(n);
    }
    void input_child(int id, int c){
        node[id].child.push_back(c);
        node[c].parent = id;
    }
    void calc_depth(){
        calc_root();
        calc_all_depth(root, 0);
    }
    void print_node(){
        for (int i = 0; i < node.size(); i++) {
            cout << "node " << i << ": parent = " << node[i].parent;
            cout << ", depth = " << node[i].depth << ", ";
            if (node[i].parent == -1) {
                cout << "root";
            } else if (!node[i].child.empty()) {
                cout << "internal node";
            } else {
                cout << "leaf";
            }
            cout << ", [";
            for (int j = 0; j < node[i].child.size(); j++) {
                cout << node[i].child[j];
                cout << (j < node[i].child.size() - 1 ? ", " : "");
            }
            cout << "]" << endl;
        }
    }
};

int main(){
    int n;
    cin >> n;
    Tree T(n);
    for (int i = 0; i < n; i++) {
        int id;
        cin >> id;
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int c;
            cin >> c;
            T.input_child(id, c);
        }
    }
    T.calc_depth();
    T.print_node();
    return 0;
}

Measured memory_bytes: 6848
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ.Volume2
{
    public class PrimeQuadruplet
    {
        public static int Main()
        {
            // 10000000??\???????´???°????±???????
            var prime = new bool[10000001];
            for(int i = 2; i <= 10000000; i++) { prime[i] = true; }
            prime[0] = false;
            prime[1] = false;
            prime[2] = true;
            int stop = (int)Math.Sqrt(10000000);
            for (int i = 2; i <= stop; i++)
            {
                if (!prime[i]) { continue; }
                for(int j = 2; i * j <= 10000000; j++) { prime[i * j] = false; }
            }

            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if(n == 0) { break; }

                int ans = 0;
                for(int i = n; i >= 13; i--)
                {
                    if (prime[i - 8] && prime[i - 6] && prime[i - 2] && prime[i])
                    {
                        ans = i;
                        break;
                    }
                }

                Console.WriteLine(ans);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 18972
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<iomanip>

using namespace std;

void D() {
	int N;
	cin >> N;
	int K;
	cin >> K;
	vector<int> ps(N);

	for (int i = 0; i < N; i++) {
		cin >> ps[i];
	}

	vector<int> max(N-K +1);

	int subsum = 0;
	for (int i = 0; i < K; i++) {
		subsum += ps[i];
	}
	max[0] = subsum;
	for (int j = 1; j + K < N + 1; j++) {
		int head = ps[j - 1];
		int tail = ps[j + K - 1];
		max[j] = max[j - 1] + tail - head;
		
	}

	auto iter = max_element(max.begin(), max.end());
	size_t index = distance(max.begin(), iter);

	double ans = (K + max[index]);
	ans /= 2;
	cout << ans << endl;
}

void A() {
	string S, T;
	cin >> S >> T;

	int A, B;
	cin >> A >> B;

	string U;
	cin >> U;
	if (U == S) {
		cout << (A - 1) << " " <<  B << endl;
	}
	else {
		cout << A << " " <<  (B - 1) << endl;
	}
}

void B() {
	string S;
	cin >> S;
	string X;
	for (int i = 0; i < S.length(); i++) {
		X += "x";
	}

	cout << X << endl;
}

void E() {
	int N, K;
	cin >> N >> K;
	vector<vector<int>> lists(3, vector<int>(100));
	lists[0][0] = 1;
	lists[1][0] = 0;
	lists[2][0] = 0;

	int D = log10(N) + 1;
	for (int i = 1; i < D; i++) {
		lists[0][i] = 9 + lists[0][i - 1];
		lists[1][i] = 9 * lists[0][i - 1];
		lists[2][i] = 9 * lists[1][i - 1];
	}
	int ans = 0;
	for (int j = D - 1; j >= 0; j--) {
	}
}
int main() {
	A();
}

Measured memory_bytes: 256
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

s, t = nas()
a, b = na()
u = ns()

if u == t:
    print(a, b - 1)
elif u == s:
    print(a - 1, b)

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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 (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


int main() {

    int X, Y; cin >> X >> Y;

    bool ans = false;
    REP(i, 100) {
        REP(j, 100) {
            if (i + j == X and 2*i + 4*j == Y) {
                ans = true;
            }
        }
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++);

ll C[51][51];//nCk=C[n][k]

void comb_table(ll N){
	for(int i=0;i<=N;++i){
		for(int j=0;j<=i;++j){
			if(j==0 or j==i){
				C[i][j]=1LL;
			}else{
				C[i][j]=(C[i-1][j-1]+C[i-1][j]);
			}
		}
	}
}

//a,b x
int main(){
	comb_table(50);
	ll N,A,B; cin>>N>>A>>B;
	vector<ll> V(N);
    rep(i,N) cin>>V[i];
	sort(V.bg,V.ed,greater<ll>());

	ll sum=0,mem;
	rep(i,A){
		sum+=V[i];
		mem=V[i];
	}
	double ave=(double)sum/A;
	if(mem==V[0]){
		ll cnt=0,ans=0;
		rep(i,N){
			if(V[i]==mem) cnt++;
		}
		for(int i=A;i<=min(B,cnt);i++){
			ans+=C[cnt][i];
		}
		printf("%.8f\n",ave);
		cout<<ans;
	}	
	else{
		ll cnt=0,memcnt=0;
		rep(i,N){
			if(V[i]>mem) cnt++;
			else if(V[i]==mem) memcnt++;
		}
		printf("%.8f\n",ave);
		cout<<C[memcnt][A-cnt];
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int a;
	string s;
	cin >> a >> s;

	if (a < 3200) cout << "red" << endl;
	else cout << s << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<int, int> pint;
ll inf = 1000000000 + 7;



int A[100][100];
int B[100];
int main() {
	int N, M, C;


	cin >> N >> M >> C;
	
	rep(i, M) {
		cin >> B[i];
	}

	rep(i, N) {
		rep(j, M) {
			cin >> A[i][j];
		}
	}

	int num = 0;
	int check = 0;
	rep(i, N) {
		rep(j, M) {
			check += A[i][j] * B[j];
			
		}
		check += C;
		if (check > 0) {
			num += 1;
		}
		check = 0;
	}

	cout << num << endl;


	
	return 0;
}

Measured memory_bytes: 256
// 2011/09/27 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n, k;
		cin >> n >> k;
		if(n==0&&k==0)
			break;

		int a[100000];
		for(int i=0; i<n; i++)
			cin >> a[i];

		int sum = 0;
		for(int i=0; i<k; i++)
			sum += a[i];

		int max = sum;
		for(int i=k; i<n; i++){
			sum += a[i];
			sum -= a[i-k];
			if(max<sum)
				max = sum;
		}

		cout << max << endl;
	}

	return 0;
}

Measured memory_bytes: 0
n = int(input())
As = map(int, input().split())
from collections import defaultdict
dic = defaultdict(int)
for a in As:
  dic[a] += 1


table = [0] * (10**6+5)
for a, v in dic.items():
  for i in range(a, 10**6+5, a):
    table[i] += 1
ans = 0
for k, v in dic.items():
  if table[k] >= 2 and v == 1:
    ans += 1
  elif v >= 2:
    ans += v
print(n-ans)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

long long gcd(long long a,long long b){
    while(b){
        swap(a%=b,b);
    }
    return a;
}
long long lcm(long long a,long long b){
    return a/gcd(a,b)*b;
}

int N,M;
int A[111111];
signed main(){
    cin>>N>>M;
    rep(i,N){
        cin>>A[i];
        A[i]/=2;
    }

    int l=1;
    rep(i,N){
        l=lcm(l,A[i]);
        if(l>M){
            cout<<0<<endl;
            return 0;
        }
    }

    rep(i,N){
        if((l/A[i])%2==0){
            cout<<0<<endl;
            return 0;
        }
    }

    int tmp=M/l;
    tmp=(tmp+1)/2;
    cout<<tmp<<endl;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int A = S.size();
  int count = 0;
  for(int i =0;i < A;i++){
    if(i % 2 == 0){
    if(S[i] != 'R' && S[i] != 'U' && S[i] != 'D'){
      count++;
      }
    }
    if(i % 2 == 1){
      if(S[i] != 'L' && S[i] != 'U' && S[i] != 'D'){
        count++;
      }
    }
  }
  if(count > 0){
    cout << "No" << endl;
  }
else{
cout << "Yes" << endl;
}
}


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

using namespace std;

using ll = long long;

void dfs(int cur, int par, ll val, vector< vector<int> >& g, vector<ll>& v, vector<ll>& ans) {
    val += v[cur];
    ans[cur] = val;
    for (int nex : g[cur]) {
        if (nex == par) continue;
        dfs(nex, cur, val, g, v, ans);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector< vector<int> > g(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<ll> v(n, 0);
    for (int i = 0; i < q; i++) {
        int p, x;
        cin >> p >> x;
        p--;
        v[p] += x;
    }

    vector<ll> ans(n, 0);
    dfs(0, -1, 0, g, v, ans);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " \n"[i + 1 == n];
    }
    return 0;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string a,b;
    int i,j,la,lb,ans=INT_MAX,cnt;
    cin >> a >> b;
    la=a.size(),lb=b.size();
    for(i=0;i<=la-lb;i++)
    {
        cnt=0;
        for(j=0;j<lb;j++)cnt+=a[j+i] != b[j];
        ans=min(ans,cnt);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
N=input()

lists = []
temp=[i for i in range(10)]

MOD=10**9+7

dic={0:1}

for i in N:
    new_dic={}
    hoge=list(dic.items())
    if i == "?":
        for amari,count in hoge:
            amari*=10
            for num in temp:
                a = (amari + num) % 13
                if a in new_dic:
                    new_dic[a]+=count
                else:
                    new_dic[a]=count
    else:
        num=int(i)
        for amari,count in hoge:
            a = (amari*10 + num)%13
            if a in new_dic:
                new_dic[a]+=count
            else:
                new_dic[a]=count
    for key in new_dic:
        new_dic[key] %= MOD
    dic = new_dic

try:
    print(dic[5])
except:
    print(0)

Measured memory_bytes: 43500
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535
vector<int> prime;
vector<int> primetilln(int n)
{
	int arr[n + 1] = {0};
	vector<int> ans;
	for (int i = 2; i <= n; i++)
	{
		if (arr[i] == 0)
		{
			ans.pb(i);
			for (int j = 2; i * j <= n; j++)
			{
				arr[i * j] = 1;
			}
		}
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int u = 1e6;
	prime = primetilln(u); int cnt[u + 1] = {0};
	int arr[n + 1] = {0}; int gd;
	for (int i = 1; i <= n; i++)
	{
		cin >> arr[i];
		cnt[arr[i]]++;
		if (i == 1)
			gd = arr[i];
		else
			gd = __gcd(gd, arr[i]);
	} int f = 0;
	for (int i = 0; i < prime.size(); i++)
	{
		int cn = 0;
		for (int j = 1; prime[i] * j <= u; j++)
		{
			cn += cnt[prime[i] * j];
		}
		if (cn >= 2)
		{f = 1; break;}
	}
// 	cout<<f<<endl;
	if (f == 0)
		cout << "pairwise coprime";
	else if (gd == 1)
		cout << "setwise coprime";
	else
		cout << "not coprime";

	return 0;
}



Measured memory_bytes: 11612
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main() {
  int N;
  string S;
  bool f=true;
  cin>>N>>S;
  if(N%2==1) f=false;
  else{
    for(int i=0;i<N/2;i++){
    if(S[i]!=S[i+N/2]){
      f=false;
      break;
    }
  }
  }
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}	


Measured memory_bytes: 256
#import numpy as np
import collections
#import math




#f = open('./input_E.txt')
#
#H,W,M=map(int, f.readline().split())
#bakuha = []
#bakuha_H=[]
#bakuha_W=[]
#for i in range(M):
#    hh,ww=map(int, f.readline().split())
#    bakuha_H.append(hh)
#    bakuha_W.append(ww)
#    bakuha.append([hh,ww])




H,W,M=map(int, input().split())
bakuha = []
bakuha_H=[]
bakuha_W=[]
for i in range(M):
    hh,ww=map(int, input().split())
    bakuha_H.append(hh)
    bakuha_W.append(ww)
    bakuha.append([hh,ww])





count_H = collections.Counter(bakuha_H)
H_most = count_H.most_common()
H_most_num = H_most[0][1]

#H_only_most = [x for x in H_most if x[1]==H_most_num]
#H_kouho = [x[0] for x in H_only_most]

H_kouho = [x[0] for x in H_most if x[1]==H_most_num]


count_W = collections.Counter(bakuha_W)
W_most = count_W.most_common()
W_most_num = W_most[0][1]

#W_only_most = [x for x in W_most if x[1]==W_most_num]
#W_kouho = [x[0] for x in W_only_most]
W_kouho = [x[0] for x in W_most if x[1]==W_most_num]

ans = H_most_num + W_most_num

#マイナス1するかどうか
ans_minus = True

len_H_kouho=len(H_kouho)
len_W_kouho=len(W_kouho)
num_kouho = len_H_kouho*len_W_kouho

bakuha_1d = [W * (x[0]-1) + x[1] for x in bakuha]
bakuha_1d.sort(reverse=True)
bakuha_1d_max = bakuha_1d[0]
bakuha_1d_min = bakuha_1d[-1]

#print(bakuha_1d)

if num_kouho <= M:
    kouho_1d = []
    for h_k in H_kouho:
        for w_k in W_kouho:
            kouho_1d.append(W*(h_k-1)+w_k)
    kouho_1d.sort()
    kouho_1d_min = kouho_1d[0]
    kouho_1d_max = kouho_1d[-1]
    
#    print(kouho_1d)    
    
    if kouho_1d_max <= bakuha_1d_max and kouho_1d_min >= bakuha_1d_min:
        b1_0 = bakuha_1d_min
        for_break=False
        for k1 in kouho_1d:
#            if k1 >= b1_0:
            tuzuku = True
            while tuzuku:
                b1_0 = bakuha_1d.pop()
#                print(k1,b1_0)
                if b1_0 >= k1:
                    tuzuku = False
                    if b1_0 != k1:
                        ans_minus = False
                        for_break=True
            if for_break:
                break
    else:
        ans_minus = False
#    for i in range(M):
#        b1_0 = bakuha_1d.pop(0)
        
        
        
else:
    ans_minus = False
#
#print(ans_minus)
if ans_minus:
    ans-=1
    

print(ans)

Measured memory_bytes: 238656
last = None
used = []
for _ in range(int(input())):
	w = input().rstrip()

	if last is not None:
		if last == w[0] and not(w in used):
			last = w[-1]
			used.append(w)
			continue
		else:
			print('No')
			break
	else:
		last = w[-1]
		used.append(w)

else: print('Yes')

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long input = long.Parse(Console.ReadLine());

            long res = (input / 500) * 1000;
            res += ((input % 500) / 5) * 5;

            Console.WriteLine(res);
        }

    }
}


Measured memory_bytes: 13140
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	vector<int> h(n, 0);
	rep(i, m) {
		int p1, p2;
		cin >> p1 >> p2;
		p1--; p2--;
		g[p1].push_back(p2);
		h[p2]++;
	}
	queue<int> none;
	rep(i, n) {
		if (h[i] == 0) {
			none.push(i);
		}
	}
	vector<int> tsort;
	while (none.size()) {
		int i = none.front(); none.pop();
		tsort.push_back(i);
		for (auto& j : g[i]) {
			h[j]--;
			if (h[j] == 0) none.push(j);
		}
	}
	reverse(tsort.begin(), tsort.end());
	vector<int> dp(n, 0);
	int ans = 0;
	for (int i : tsort) {
		for(int u:g[i]){
			dp[i] = max(dp[i], dp[u] + 1);
		}
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7032
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int f(int x1, int x2) {
  return (x1-x2)*(x1-x2);
}
int main() {
  int n; cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  vector<int> v(n);
  double ans = 0.;
  rep(i, n) v[i] = i;
  do {
    for(int i = 1; i < n; i++) {
      ans += sqrt(f(x[v[i]], x[v[i-1]])+f(y[v[i]], y[v[i-1]]));
    }
  } while(next_permutation(v.begin(), v.end()));
  for(int i = 1; i <= n; i++) ans /= i;
  cout << setprecision(10);
  cout << fixed << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

void calc( int n, int k, const vector<int>& a, vector<int>& flag0 )
{
    set<pair<int,int> > z;
    int i;
    for(i=0; i<n; i++) {
        if(i-k>=0) {
            z.erase(make_pair(a[i-k],i-k));
        }
        if(!z.empty()) {
            auto it=z.rbegin();        
            int max= it->first;
            if(a[i]<max) {
                flag0[i]=i;
            }
            else {
                flag0[i]=flag0[i-1];
            }
        }
        z.insert(make_pair(a[i],i));
    }

    return;
}

int main(int argc, char* argv[])
{
    int n,k;
    scanf("%d%d", &n, &k);

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

    vector<int> flag0(n);
    calc( n, k, a, flag0 );

    vector<int> a1=a;
    reverse(a1.begin(), a1.end());
    for(i=0; i<n; i++) {
        a1[i]=n-1-a1[i];
    }
    vector<int> flag1(n);
    calc( n, k, a1, flag1 );
    reverse( flag1.begin(), flag1.end());
    for(i=0; i<n; i++) {
        flag1[i]=n-1-flag1[i];
    }

    int add=0;
    set<pair<int,int> > zz;
    for(i=k-1; i<n; i++) {
        int tmp0=flag1[i-(k-1)];
        int tmp1=flag0[i];
        if(tmp0<=tmp1) {
            zz.insert(make_pair(tmp0,tmp1));
        }
        else {
            add=1;
        }
    }
    printf("%d\n", (int)zz.size()+add);

    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define PQ priority_queue
#define pb push_back
#define fu(i,a,j) for(int i=a;i<j;i++)
#define fd(i,a,j) for(int i=a;i>=j;i--)
#define SYNC ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define MOD 1000000007 
#define MOD2 1000000021
#define MAXN 2000000
#define INF 1e9
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;

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

ll m_pow(ll a, ll b, ll M = MOD) { ll res = 1; for (; b; b >>= 1, a = (a * a) % M)if (b & 1)res = (res * a) % M; return res; }
ll gcd(ll a, ll b) { if (a < b) swap(a, b); for (; b; a %= b, swap(a, b)); return a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };
db dis(pii a, pii b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }
int dr[] = { 0, 1, 0, -1, 1,1,-1,-1 };
int dc[] = { 1, 0, -1, 0, 1,-1,1,-1 };

int n, m, k, t;

string ansok[2] = { "NO","YES" };

pii a[200005];
int par[200005];
int sz[200005];
int Find(int u) {
	if (par[u] < 0) { return u; }
	return par[u] = Find(par[u]);
}
bool Union(int u, int v) {
	u = Find(u);
	v = Find(v);
	if (u == v)
		return 0;
	par[v] = u;
	sz[u] += sz[v];
	return 1;
}
int main()
{
	SYNC;
	memset(par, -1, sizeof par);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		sz[i] = 1;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		Union(u,v);
	}
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		mx = max(mx, sz[Find(i)]);
	}
	cout << mx << '\n';
	return 0;
}

Measured memory_bytes: 5732
def common_divisor(a, b):
    cd_list = []
    for i in range(1, 101):
        if a % i == 0 and b % i == 0:
            cd_list.append(i)
    return cd_list

A, B, K = map(int, input().split())
print(common_divisor(A, B)[-K])


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<cmath>
using namespace std;

int main(void)
{
	vector<int> S, T;
	int n, q, m, p, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> m;
		S.push_back(m);
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> p;
		T.push_back(p);
	}
	S.push_back(T[0]);
	for (int i = 0; i < q; i++) {
		if (i)
			S[n] = T[i];
		int j;
		for (j = 0; S[j] != T[i]; j++);
		if (j != n)
			sum++;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3240