akhauriyash/Code-Regression huggingface dataset:
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	d := nextInt()
	p := make([][]int, n)

	for i := 0; i < n; i++ {
		p[i] = nextInts(d)
	}

	result := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			dist := 0
			for k := 0; k < d; k++ {
				diff := p[i][k] - p[j][k]
				dist += diff * diff
			}

			sqrt := int(math.Sqrt(float64(dist)))
			if dist == sqrt*sqrt {
				result++
			}
		}
	}

	fmt.Println(result)
}


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

#define MOD (1000000007LL)

using namespace std;

int main(void){
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    vector<int> T(Q + 1), F(Q + 1), flip(Q + 1, 0);
    vector<char> C(Q + 1);
    for(int i = 1; i <= Q; i++){
        cin >> T[i];
        if(T[i] == 1) flip[i] = flip[i - 1] + 1;
        else{
            flip[i] = flip[i - 1];
            cin >> F[i] >> C[i];
        }
    }
    string ans = "";
    for(int i = Q; i >= 1; i--){
        if(T[i] == 2){
            if((flip[i] % 2 == flip[Q] % 2) ^ F[i] == 2){
                ans.push_back(C[i]);
            }
        }
    }
    if(flip[Q] % 2 == 0) ans.append(S);
    else{
        reverse(S.begin(), S.end());
        ans.append(S);
    }
    for(int i = 1; i <= Q; i++){
        if(T[i] == 2){
            if((flip[i] % 2 != flip[Q] % 2) ^ F[i] == 2){
                ans.push_back(C[i]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3712
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n,l = IN()
	ss=[]
	for _ in range(n):
		s = input()
		ss.append(s)
	ss.sort()
	return ''.join(ss)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
int main(){
	double a,b,c,d,e,f;
	scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
	e=(c-a)*(c-a)+(d-b)*(d-b);
	f=sqrt(e);
	printf("%f\n",f);
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
vector<int> adj[MAXN];
int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, a, b;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    queue<pair<int, int> > Q;
    Q.push({1, 0});
    vector<int> CST(n + 1, inf);
    CST[1] = 0;
    while (!Q.empty()) {
        int v = Q.front().first;
        int c = Q.front().second;
        Q.pop();
        for (int i = 0; i < sz(adj[v]); i++) {
            if (CST[adj[v][i]] == inf) {
                Q.push({adj[v][i], c + 1});
                CST[adj[v][i]] = v;
            }
        }
    }
    bool found = true;
    for (int i = 1; i <= n && found; i++) {
        if (CST[i] == inf) found = false;
    }
    if (found) {
        cout << "Yes\n";
        for (int i = 2; i <= n; i++) {
            cout << CST[i] << '\n';
        }
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 31792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

const double EPS = 1e-8;

using namespace std;
struct Point{
    double x, y, z;
    Point () {}
    Point (double x, double y, double z) :
        x(x), y(y), z(z) {}
};
Point operator - (Point a, Point b){
    return Point(a.x - b.x, a.y - b.y, a.z - b.z);
}
Point operator * (double a, Point b){
    return Point(a * b.x, a * b.y, a * b.z);
}

double dot(Point a, Point b){
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

double abs(Point a){
    return sqrt(dot(a, a));
}


bool is_cross(Point p, Point c, double r){
    bool in_target = (abs(c) < r + EPS);
    bool in_self = (abs(c - p) < r + EPS);
    if(in_self && in_target) return false;
    if(!in_self && in_target) return true;
    if(in_self && !in_target) return true;

    double k = dot(c, p) / dot(p, p);
    if(k < 0 || 1 < k) return false;

    return abs(c - k * p) < r + EPS;
}

int main(){
    int N, M, R;
    while(cin >> N >> M >> R && N){
        vector<Point> sp(N);
        vector<double> sr(N);
        vector<Point> tp(M);
        vector<double> tb(M);
        double ex, ey, ez;
        REP(i, N) cin >> sp[i].x >> sp[i].y >> sp[i].z >> sr[i];
        REP(i, M) cin >> tp[i].x >> tp[i].y >> tp[i].z >> tb[i];
        cin >> ex >> ey >> ez;
        REP(i, N){
            sp[i].x -= ex;
            sp[i].y -= ey;
            sp[i].z -= ez;
        }
        REP(i, M){
            tp[i].x -= ex;
            tp[i].y -= ey;
            tp[i].z -= ez;
        }

        vector<double> score(M);
        for(int i = 0; i < M; i++){
            score[i] = tb[i] / dot(tp[i], tp[i]);
        }

        vector<int> cross(N);
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                if(is_cross(tp[j], sp[i], sr[i])){
                    cross[i] |= 1 << j;
                }
            }
        }

        double ans = 0;
        for(int s = 0; s < (1 << M); s++){
            double score_sum = 0;
            for(int i = 0; i < M; i++)
                if(s >> i & 1)
                    score_sum += score[i];

            if(score_sum < ans) continue;

            int cost = 0;
            for(int i = 0; i < N; i++)
                if(cross[i] & s) cost++;

            if(cost <= R){
                ans = score_sum;
            }
        }
        
        printf("%.15f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1312
import java.util.Scanner;


public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int [] num = new int[n + 1];
        for (int i = 1; i <= n; ++i) {
            num[i] = scanner.nextInt();
        }

        int swap = 0;
        for (int i = 1; i <= n; ++i) {
            if (num[i] != i) {
                if (num[num[i]] != i) {
                    System.out.println("NO");
                    return;
                }
                int pos = num[i];
                num[i] = i;
                num[pos] = pos;
                ++swap;

                if (swap >= 2) {
                    System.out.println("NO");
                    return;
                }
            }
        }
        System.out.println("YES");
    }
}


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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp, tmp);
	if(b % 2 == 1) tmp = mulMod(tmp,a);
	return tmp;
}

/////////////////////////////////////////////////////////

const int N = 5000;

ll dp[3][N + 5];
int n;
string str;

void precompute(){
	int bi = 0;
	dp[0][0] = 1;
	REP(use,1,n){
		REP(len,0,use){
			dp[1^bi][len] = dp[bi][len+1];
			if(len == 0) dp[1^bi][len] = addMod(dp[1^bi][len], dp[bi][0]);
			else dp[1^bi][len] = addMod(dp[1^bi][len], mulMod(2,dp[bi][len-1]));
		}
		bi ^= 1;
	}
}

ll solve(){
	precompute();
	return mulMod(dp[n%2][(int)str.length()], fast(fast(2, (int)str.length()), MOD-2));
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> str;
	cout << solve() << endl;
	return 0;
}

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

int N, W;
int w[110], v[110];

long long dp[110][100010];

int main() {
    cin >> N >> W;
    for(int i = 1; i <= N; i++)
        cin >> w[i] >> v[i];

    for(int j = 0; j <= W; j++)
        dp[0][j] = 0;

    for(int i = 1; i <= N; i++) {
        for(int j = 0; j <= W; j++) {
            if(j >= w[i])
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 80128
#include <iostream>

using namespace std;

int main() {
    long long a, b, k;

    cin >> a >> b >> k;

    long long takahashi, aoki;
    if (a > k) {
        takahashi = a - k;
        aoki = b;
    } else {
        takahashi = 0;
        aoki = a + b - k;
        if (aoki < 0) {
            aoki = 0;
        }
    }

    cout << takahashi << " " << aoki << endl;
}


Measured memory_bytes: 256
/* countABC */

#include <iostream>
using namespace std;

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

  int cnt=0;
  for(int i=0;i<n;i++){
    if(s[i]=='A'){
      if(s[i+1]=='B' && s[i+2]=='C'){
	cnt++;
      }
    }
  }
  cout << cnt << endl; 
}


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

int main() {
  int n, m;

  cin >> n >> m;
  vector<int> v(n, -1);
  bool flag = true;
  rep(i, m) {
    int s, c;
    cin >> s >> c;
    if ((n == 1 || s != 1 || c != 0) && (v[s - 1] == -1 || v[s - 1] == c)) {
      v[s - 1] = c;
    } else {
      flag = false;
    }
  }
  if (flag) {
    int ans = 0;
    rep(i, n) {
      if (v[i] == -1)
        if (n != 1 && i == 0)
          v[i] = 1;
        else
          v[i] = 0;
      ans += v[i] * pow(10, n - i - 1);
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i)
{
    return i % 2;
}

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b)
{
    return __gcd(a, b);
}
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f)
{
    if (f)
        printf("Yes\n");
    else
        printf("No\n");
}
void YES_NO(bool f)
{
    if (f)
        printf("YES\n");
    else
        printf("NO\n");
}

template <typename T>
void deb1(T x)
{
    cout << x << "\n";
}

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
//-------------------ここから回答する-----------------------

void solve(void)
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max(a * c, a * d);
    ans = max(ans, max(b * c, b * d));
    cout << ans << endl;
}
int main(void) { solve(); }

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public int N;
        public int[] A;

        public void Run()
        {
            N = Input.ReadInt();
            A = Input.ReadIntArray();

            Array.Sort(A);

            int a = 0;
            int b = 0;
            for (int i = 0; i < N; i++)
            {
                if (i % 2 == 0) a += A[N - 1 - i];
                if (i % 2 != 0) b += A[N - 1 - i];
            }

            Console.WriteLine(a - b);
        }

    }

    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int mod = 1e9 + 7;
string A, B, C;
int dp[51][2][10][10];

bool f(string s, int i, int x) {
  return s[i] == '?' || (s[i] - '0') == x;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> A >> B >> C, A != "0") {
    fill_n((int*)dp, 51 * 2 * 10 * 10, 0);
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    reverse(C.begin(), C.end());
    int n = A.size();
    dp[0][0][0][0] = 1;
    for (int d = 0; d < n; d++) {
      for (int c = 0; c < 2; c++) {
        for (int a = 0; a < 10; a++) {
          for (int b = 0; b < 10; b++) {
            if (!dp[d][c][a][b]) continue;
            for (int i = 0; i < 10; i++) {
              for (int j = 0; j < 10; j++) {
                if (!(f(A, d, i) && f(B, d, j))) continue;
                int carry = c + a + b > 9;
                if (C[d] != '?' && (i + j + carry) % 10 != (C[d] - '0')) continue;
                (dp[d + 1][carry][i][j] += dp[d][c][a][b]) %= mod;
              }
            }
          }
        }
      }
    }
    int ans = 0;
    for (int c = 0; c < 2; c++) {
      for (int a = 1; a < 10; a++) {
        for (int b = 1; b < 10; b++) {
          if (c + a + b > 9) continue;
          (ans += dp[n][c][a][b]) %= mod;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#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 rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())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;}
constexpr double eps = 1e-6;
constexpr ll LINF = 100200300400500600ll;
constexpr int INF = 2*((1<<30)-1)+1;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {-1,0,1,0};
constexpr int mod = 1000000007;
#define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl;
struct UnionFind {
  vector<int> parent;
  vector<int> size;

  UnionFind(int n) {
    parent = vector<int>(n);
    for(int i = 0; i<n;i++) parent[i] = i;
    size = vector<int>(n,1);
  }

  int root(int ix) {
    if( parent[ix] == ix) return ix;
    return parent[ix] = root( parent[ix] );
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if( x == y ) return false;
    if( size[x] < size[y] ) swap(x,y);
    size[x] += size[y];
    parent[y] = x;
    return true;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int callsize(int x) {
    return size[root(x)];
  }
  
};

void Main(){
  int n;
  cin>>n;
  vi a(n,0);
  rep(i,n-1){
    int b;
    cin>>b;
    b--;
    a[b]++;
  }
  rep(i,n) cout<<a[i]<<endl;
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 3988
# ABC 057 D
import math
N, A, B = map(int,input().split())
v = sorted(list(map(int,input().split())))[::-1]

def nCr(n,r):
    return (math.factorial(n)//(math.factorial(r)*math.factorial(n-r)))

a = sum(v[:A])/A
print(a)

s = 0
for k in range(N):
    if v[A-1] == v[k]:
        s += 1
t = 0
for k in range(A):
    if v[A-1] == v[k]:
        t += 1
u = 0
for k in range(A-1,B):
    if v[A-1] == v[k]:
        u += 1

if a != v[A-1]:
    print(nCr(s,t))
else:
    c = 0
    for k in range(A,A+u):
        c += nCr(s,k)
    print(c)


Measured memory_bytes: 38640
s=input()
s=input().split()
s.sort()
cc=s[0]
cnt=1
l=[]
for c in s[1:]:
 if c==cc:
  cnt+=1
 else:
  l.append(cnt%2)
  cnt=1
  cc=c
l.append(cnt%2)
a=-1 if l.count(0)%2==1 else 0
print(len(l)+a)


Measured memory_bytes: 10936
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int n;

int main()
{
    cin >> n;
    for (int i = 100; i >= 1; i /= 10)
    {
        if (n / i == 1)
        {
            n -= i;
            cout << 9;
        }
        else
        {
            n -= 9 * i;
            cout << 1;
        }
    }
    cout << endl;
}


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


int main() {
  vector<bool> vec(10, true);
  int n, k;
  cin >> n >> k;
  rep(i,k){
    int x; cin >> x;
    vec[x] = false;
  }
  for(int i=n; i<100000; i++){
    int x = i;
    bool flag = true;
    while(x>0){
      int d = x%10;
      if(vec[d] == false){
        flag = false;
        break;
      }
      x /= 10;
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n;
    cout << (n+1)/2 << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;

  for (int i = A; i <= B; i++) {
    int m = i / 10000 % 10;
    int s = i / 1000 % 10;
    int j = i / 10 % 10;
    int z = i % 10;
    if (m == z && s == j) ans++; 
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node{
    int a;
    int num;
}p[105];
bool cmp(node p,node q){
    return p.a<q.a;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&p[i].a);
        p[i].num=i;
    }
    sort(p+1,p+n+1,cmp);
    int cnt=0;
    for(int i=1;i<=n;i++)
        if(p[i].a!=p[i].num) cnt++;
    if(cnt<=2) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{

 public static void main(String[] args){
  
   Scanner sc = new Scanner(System.in);
   
   int[] array = new int[3];
   
   for (int i = 0; i<array.length; i++){
    
     array[i] = sc.nextInt();
     
   }
   
   System.out.println(array[2] + " " + array[0] + " " + array[1]);
   
 }
  
  
  
  
}  

Measured memory_bytes: 21844
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define llong long long
using namespace std;

const int N = 2e5;
const int P = 1e9+7;
int a[N+3],b[N+3];
llong f[N+3],g[N+3];
int n;

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	int m = 0; for(int i=1; i<=n; i++) if(i==0 || a[i]!=a[i-1]) {m++; b[m] = a[i];}
	n = m; for(int i=1; i<=n; i++) a[i] = b[i];
//	for(int i=1; i<=n; i++) printf("%d ",a[i]); puts("");
	f[0] = 1ll; g[a[1]] = 1ll;
	for(int i=1; i<=n; i++)
	{
		f[i] = g[a[i]];
		g[a[i+1]] = (g[a[i+1]]+f[i])%P;
//s		printf("i=%d f=%lld\n",i,f[i]); for(int j=1; j<=n; j++) printf("%lld ",g[j]); puts("");
	}
	printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 4864
import heapq

def Main():
    N, capacity = map(int, input().split())
    w_list = list()

    for _ in range(N):
        v, w = map(int, input().split())
        heapq.heappush(w_list, [-1*float(v/w), v, w] )

    total_value = 0

    while len(w_list) != 0:
        item = heapq.heappop(w_list)
        value_per_weight = -1*item[0]
        value = item[1]
        weight = item[2]
        
        if capacity >= weight:
            capacity -= weight
            total_value += value
        else:
            total_value += capacity * value_per_weight
            break
        
    print(total_value)

Main()



Measured memory_bytes: 23416
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0);

  int N;
  scanf("%d", &N);
  vector<PII> result;
  FOR(i,1,N+1) FOR(j,1,i) {
    if (N % 2 == 0 && (i+j) == N + 1) continue;
    if (N % 2 == 1 && (i + j) == N) continue;
    result.pb({i,j});
  }
  printf("%d\n", result.size());
  for (auto p: result) {
    printf("%d %d\n", p.st, p.nd);
  }
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(){
	int a,abo[4]={0};
	char c[5];
	for(;;){
		if(scanf("%d,%s",&a,&c) == EOF){break;}
		if(strcmp(c,"A") == 0){abo[0]++;}
		if(strcmp(c,"B") == 0){abo[1]++;}
		if(strcmp(c,"AB") == 0){abo[2]++;}
		if(strcmp(c,"O") == 0){abo[3]++;}
	}
	printf("%d\n%d\n%d\n%d\n",abo[0],abo[1],abo[2],abo[3]);
	return 0;
}

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

int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		x -= a[i];
	}
	sort(a.begin(), a.end());
	int ans = 0;
	ans += n;
	cout << ans + x / a[0] << endl;
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

var H int
var W int
var Ch int
var Cw int
var Dh int
var Dw int
var S [][]byte
var m [][]int

func main() {
	H = nextInt()
	W = nextInt()
	Ch = nextInt() - 1
	Cw = nextInt() - 1
	Dh = nextInt() - 1
	Dw = nextInt() - 1

	S = make([][]byte, H)
	m = make([][]int, H)

	max := H*W + 1
	for i := 0; i < H; i++ {
		S[i] = nextBytes()
		m[i] = make([]int, W)

		for j := 0; j < W; j++ {
			m[i][j] = max
		}
	}
	m[Ch][Cw] = 0

	queue := pqNew()
	queue.push(P{Ch, Cw, 0})

	dir := []P{
		P{-1, 0, 0},
		P{+1, 0, 0},
		P{0, -1, 0},
		P{0, +1, 0},
	}

	for !queue.Empty() {
		p := queue.pop()
		if p.h == Dh && p.w == Dw {
			fmt.Println(p.c)
			return
		}
		// A type
		for i := 0; i < len(dir); i++ {
			d := dir[i]
			n := P{p.h + d.h, p.w + d.w, p.c}
			if out(n) {
				continue
			}
			if m[n.h][n.w] <= n.c {
				continue
			}
			m[n.h][n.w] = n.c
			queue.push(n)
		}

		// B type
		for h := -2; h <= +2; h++ {
			for w := -2; w <= +2; w++ {
				if h == 0 && w == 0 {
					continue
				}

				n := P{p.h + h, p.w + w, p.c + 1}
				if out(n) {
					continue
				}
				if m[n.h][n.w] <= n.c {
					continue
				}
				m[n.h][n.w] = n.c
				queue.push(n)
			}
		}
	}

	fmt.Println(-1)
}

func out(p P) bool {
	return p.h < 0 || p.w < 0 || p.h >= H || p.w >= W || S[p.h][p.w] == '#'
}

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

type PQList []P

// PriorityQueue は優先度付きキューを表す
type PriorityQueue struct {
	queue *PQList
	size  int
}

func pqNew() PriorityQueue {
	l := make(PQList, 0, 100)
	pq := PriorityQueue{
		queue: &l,
		size:  0,
	}
	return pq
}

// Push は優先度付きキューに要素を一つ追加します。
func (pq PriorityQueue) push(value P) {
	heap.Push(pq.queue, value)
}

// Pop は優先度付きキューから要素を一つ取り出します。
func (pq PriorityQueue) pop() P {
	return heap.Pop(pq.queue).(P)
}

// Empty は優先度付きキューが空かどうかを判断します。
func (pq PriorityQueue) Empty() bool {
	return len(*pq.queue) == 0
}

func (pq PQList) Len() int {
	return len(pq)
}

func (pq PQList) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq PQList) Less(i, j int) bool {
	return pq.prior(i, j)
}

func (pq *PQList) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[:n-1]
	return item
}

func (pq *PQList) Push(item interface{}) {
	*pq = append(*pq, item.(P))
}

func (pq PQList) prior(i, j int) bool {
	pi := pq[i]
	pj := pq[j]

	if pi.c != pj.c {
		return pi.c < pj.c
	}
	di := abs(pi.h-Dh) + abs(pi.w-Dw)
	dj := abs(pj.h-Dh) + abs(pj.w-Dw)
	return di < dj
}

type P struct {
	h int
	w int
	c int
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 23668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll h, w, n;
	cin >> h >> w >> n;
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];

	ll now = 0;
	vector<vll> ans(h, vll(w));
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			if (i % 2 == 0) {
				ans[i][j] = now + 1;
			}
			else {
				ans[i][w - 1 - j] = now + 1;
			}
			a[now]--;
			if (a[now] == 0) now++;
		}
	}

	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w - 1; j++) cout << ans[i][j] << " ";
		cout << ans[i].back() << endl;
	}
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private static final int SOURCE = 0;
	private static final int TARGET = 1;
	private static final int PLACE_A = 0;
	private static final int PLACE_B = 1;
	private static final int PLACE_C = 2;
	
	private static boolean[] cupHasBall = {true, false, false};
	private static final int NUM_PLACE = cupHasBall.length;
	
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;
		while((buf = br.readLine()) != null){
			String[] input = buf.split(",");
			changeCup(input[SOURCE], input[TARGET]);
		}
		printBallPlace();
	}
	public static void printBallPlace(){
		int ballPlace = 0;
		for(int place = 0; place < NUM_PLACE; place++){
			if(cupHasBall[place]){
				ballPlace = place;
				break;
			}
		}
		String mes = "";
		switch(ballPlace){
		case PLACE_A:
			mes = "A";
			break;
		case PLACE_B:
			mes = "B";
			break;
		case PLACE_C:
			mes = "C";
			break;
		default:
			break;
		}
		System.out.println(mes);
	}
	public static void changeCup(String source, String target){
		changeCup(valueOf(source), valueOf(target));
	}
	private static void changeCup(int source, int target){
		boolean hasBall = cupHasBall[source];
		cupHasBall[source] = cupHasBall[target];
		cupHasBall[target] = hasBall;
	}
	private static int valueOf(String place){
		if(place.compareTo("A") == 0)		return 0;
		else if(place.compareTo("B") == 0)	return 1;
		else if(place.compareTo("C") == 0)	return 2;
		else	return -1;
	}
}

Measured memory_bytes: 16916
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

void countingsort(int [],int);

int main(){
  int A[MAX];
  int n, i, j;

  scanf("%d", &n);


  /* your code */
  for(i=0 ; i<n ; i++)
  {
    scanf("%d",&A[i]);
  }

  countingsort(A,n);

  for(i=0 ; i<n-1 ; i++)
  {
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);

  return 0;
}

void countingsort(int A[],int n)
{
  int i,j,k=0;

  int C[VMAX];
  for(i=0;i<VMAX;i++){
    C[i]=0;
  }
  for(i=0;i<n;i++){
    C[A[i]]++;
  }
  for(i=0;i<VMAX;i++){
    for(j=C[i];j>0;j--){
A[k++]=i;
    }
}
}


Measured memory_bytes: 9588
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;
#define mp make_pair

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	
	int N;
	cin>>N;
	vector<ll> a;
	vector<ll> b;
	for (int i = 0;i < N;++i) {
		ll x, y;
		cin>>x>>y;
		a.pb(x+y);
		b.pb(x-y);
	}

	sort(all(a));
	sort(all(b));

	cout<<max(a[N-1]-a[0], b[N-1]-b[0])<<endl;
	return 0;
}


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

bool read(int &x)
{ return (scanf("%d", &x) != EOF); }

int q;

main(){
	// freopen("4.inp", "r", stdin);
	// freopen("4.out", "w", stdout);
	
	cin >> q;
	while (q--){
		int mark[15] = {};
		memset(mark, 0, sizeof mark);
		for (int i = 1; i <= 6; i++){
			int x; cin >> x; mark[x] = 1;
		}
		for (int i = 1; i <= 13; i++)
			if (i == 7 || mark[i] == 1) continue;
			else mark[i] = 2;
		
		if (mark[1] == mark[13]){
			if (mark[1] == 1) cout << "no\n";
			else cout << "yes\n";
			continue;
		}
		
		int L = 7, R = L;
		int numL = 6, numR = 6, turn = 1;
		while (1){
			if (!numL){ cout << "yes\n"; break; }
			if (!numR){ cout << "no\n"; break; }
			if (turn == 1)
			{
				if (mark[L - 1] == 1 && mark[1] == 1)
					numL--, mark[--L] = -1;
				else 
				if (mark[R + 1] == 1 && mark[13] == 1)
					numL--, mark[++R] = -1;
				else 
				if (mark[L - 1] == 1)
					numL--, mark[--L] = -1;
				else 
				if (mark[R + 1] == 1)
					numL--, mark[++R] = -1;
			}
			else {
				if (mark[L - 1] == 2 && mark[1] == 2)
					numR--, mark[--L] = -1;
				else 
				if (mark[R + 1] == 2 && mark[13] == 2)
					numR--, mark[++R] = -1;
				else 
				if (mark[L - 1] == 2)
					numR--, mark[--L] = -1;
				else 
				if (mark[R + 1] == 2)
					numR--, mark[++R] = -1;
			}
			turn = 3 - turn;
		}
	}
}


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

map <string, int> ct;

int main()
{
	int n, m;
	string s[210];
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> s[i];
		ct[s[i]]++;
	}
	cin >> m;
	for(int i = n+1;i <= m + n;i++){
		cin >> s[i];
		ct[s[i]]--;
	}
	int ans = 0;
	for(int i = 1;i <= m+n;i++){
		ans = max(ans, ct[s[i]]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Point {
    int x;
    int y;
    
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int distanceTo(Point other) {
        return Math.abs(this.x - other.x) + Math.abs(this.y - other.y);
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();


        Point[] s = new Point[N];
        for (int i = 0; i < N; i++) {
            s[i] = new Point(sc.nextInt(), sc.nextInt());
        }

        Point[] c = new Point[M];
        for (int i = 0; i < M; i++) {
            c[i] = new Point(sc.nextInt(), sc.nextInt());
        }

        int[] ans = new int[N];
        for (int i = 0; i < N; i++) {
            Point curs = s[i];
            int min = Integer.MAX_VALUE;
            int idx = 0;
            for (int j = 0; j < M; j++) {
                int d = curs.distanceTo(c[j]);
                if (min > d) {
                    min = d;
                    idx = j;
                }
            }
            ans[i] = idx;
        }

        for (int i = 0; i < N; i++) {
            System.out.println(ans[i] + 1);
        }
        return;
    }

}

Measured memory_bytes: 22868
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int mod = 1000000007;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] s = new int[n];
        for(int i=0;i<n;i++) s[i] = sc.nextInt();
        Arrays.sort(s);
        int index = 0;
        long[] dp = new long[x+1];
        for(int v=0;v<x+1;v++) dp[v] = 0;
        for(int v=1;v<x+1;v++) {
            while(index < n && s[index] <= v) {
                index++;
            }
            // System.out.println(index);
            if(index == 0) {
                dp[v] = v%mod;
                // System.out.println(dp[v]);
            } else {
                for(int i=0;i<index;i++) {
                    int res = v%s[i];
                    dp[v] += dp[res];
                    dp[v] %= mod;
                }
            }
            if(index > 0) {
                int divideBy = modPow(index,mod-2,mod);
                dp[v] *= divideBy;
                dp[v] %= mod;
            }
        }
        int coeff = 1;
        for(int v=1;v<n+1;v++) {
            coeff = modProd(coeff,v,mod);
        }
        // long ans = dp[x] * coeff;
        int ans = modProd((int) dp[x],coeff,mod);
        // ans %= mod;
        System.out.println(ans);
        // System.out.println("dp table");
        // for(int v=0;v<x+1;v++) {
            // System.out.println(dp[v]);
        // }
        // int value = modPow(2, mod-2, mod);
        // int w = modProd(3,value,mod);

        // int y = modProd(w,(int) coeff,mod);
        // System.out.println(coeff);
        // System.out.println(w);
        // System.out.println(y);
    }
    public static int modProd(int x,int y,int mod){
        long xx = (long) x;
        long yy = (long) y;
        long v = xx * yy;
        v %= mod;
        return((int) v);
    }
    public static int modPow(int value,int exponent,int mod) {
        if (exponent == 0) return(1);
        if (exponent == 1) return(value%mod);
        long longValue = (long) value;
        int res = exponent%2;
        int q = exponent/2;
        long answer = 1;
        if(res == 1) answer *= longValue;
        longValue *= longValue;
        longValue %= mod;
        answer = (answer * ((long) modPow((int) longValue, q, mod)))%mod;
        return((int) answer);
    }
}   

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> a(M);
  for(int i = 0; i<M; i++){
    cin >> a.at(i);
  }
  int count_a;
  int count_b;
  for(int i = 0; i<M; i++){
    if(a.at(i)<X){
      count_a++;
    }
    else{
      count_b++;
    }
  }
  cout << min(count_a,count_b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

bool isPrime[1000000];

void setIsPrime(int x) {
    isPrime[1] = true;
	for(int i = 1; i < x; i++) {
		int n = (int)sqrt(i);
		int yakusu = 0;
		for(int j = 1; j<=n; j++) {
			if(i%j==0) yakusu++;
			if(yakusu > 2) break;
		}
		if (yakusu==1) {
			isPrime[i] = true;
		}
	}
}

int numPrimes(int x) {
    int cnt = 0;
    for (int n=1; n <= x; n++) {
        if (isPrime[n]) cnt++;
    }
    return cnt - 1;
}

int main(){
    int x;
    setIsPrime(1000000);
	while(cin >> x) {
		cout << numPrimes(x) << endl;
	}
    return 0;
}

Measured memory_bytes: 2136
/*
	@author: cheerioskun
*/
#pragma GCC target("popcnt")
#include "bits/stdc++.h"
#define f first
#define sc second
#define pb push_back
#define MOD 1000000007L
#define inf 0x3f3f3f3f
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
using namespace std;

int dp[100005], visited[100005];

void dfs(set<int>* adjList, int source, int* visited){
	if(!visited[source]){
		visited[source] = 1;
		for(auto i: adjList[source]){
			if(!visited[i]) dfs(adjList, i, visited);
		}
		for(auto i: adjList[source]){
			dp[source] = max(dp[source], 1 + dp[i]);
		}
	}
}

int main(){
	fast_io
	int N, M;
	cin>>N>>M;
	set<int>* adjList = new set<int>[N];
	int x, y;
	for(int i = 0;i < M; ++i){
		cin>>x>>y;
		adjList[x - 1].insert(y - 1);
	}
	int ans = 0;
	for(int i = 0;i < N; ++i){
		if(!visited[i]){
			dfs(adjList, i, visited);
		}
		ans = max(ans, dp[i]);
	}
	cout<<ans<<endl;
	#ifndef ONLINE_JUDGE
    	cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}



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

#define for_(i,a,b) for(int i=a;i<b;++i)

typedef pair< int, int > pii;

int n, p[1010], d[1010];
vector< vector< pii > > edges;
int deg[1010];

pii diam(int v, int d, int p) {
	pii res(v, d);
	
	for_(i,0,(int)edges[v].size()) {
		pii e = edges[v][i];
		int u = e.first;
		
		if (u != p && deg[u] != 1) {
			pii p = diam(u, d + e.second, v);
			if (p.second > res.second) res = p;
		}
	}
	
	return res;
}

int main() {
	while (cin >> n, n) {
		memset(deg, 0, sizeof(deg));
		for_(i,0,n-1) cin >> p[i];
		for_(i,0,n-1) cin >> d[i];
		
		int ans = 0;
		
		edges.assign(n, vector< pii >());
		
		for_(i,0,n-1) {
			++deg[i+1];
			++deg[p[i]-1];
			edges[i+1].push_back(pii(p[i]-1, d[i]));
			edges[p[i]-1].push_back(pii(i+1, d[i]));
			ans += 3 * d[i];
		}
		
		for_(i,0,n) if (deg[i] == 1) ans -= 2 * edges[i][0].second;
		
		for_(i,0,n) {
			if (deg[i] != 1) {
				pii f = diam(i, 0, -1);
				pii s = diam(f.first, 0, -1);
				ans -= s.second;
				break;
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1388
import sys
from io import StringIO
import unittest
import os

sys.setrecursionlimit(999999999)

def get_arithmetic_progression(a, d, n):
    return n * (2 * a + (n - 1) * d) // 2

# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())

    ans = 0
    for i in range(1, n + 1):
        ans += get_arithmetic_progression(i, i, n // i)

    print(ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4"""
        output = """23"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """100"""
        output = """26879"""
        self.assertIO(test_input, output)

    # def test_input_3(self):
    #     test_input = """10000000"""
    #     output = """838627288460105"""
    #     self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 77484
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int H,W,N;
vi data[214514];
map<pii,int> hoge;
int lefst[214514];
int main(){
	cin>>H>>W>>N;
	rep(i,N){
		int x,y;
		cin>>x>>y;
		x--;y--;
		data[y].pb(x);
		hoge[mp(x,y)]=1;
	}
	int ans=H;
	int nowx=0,nowy=0;
	bool flag=true;
	rep(i,W)lefst[i]=-1;
	lefst[0]=0;
	while(flag){
		if(hoge[mp(nowx,nowy+1)]==1&&hoge[mp(nowx+1,nowy)]==1)flag=false;
		if(hoge[mp(nowx+1,nowy)]==0){
			nowx++;
			if(nowx>=H)flag=false;
		}
		if(hoge[mp(nowx,nowy+1)]==0&&flag){
			nowy++;
			if(nowy>=W)flag=false;
			if(flag)lefst[nowy]=nowx;
		}
		
	}
	/*rep(i,H){
		rep(j,W){
			if(hoge[mp(i,j)]==1)cout<<"#";
			else cout<<".";
		}
		cout<<endl;
	}*/
	for(int i=0;i<W;i++){
		if(lefst[i]>=0){
			int mi=H;
			rep(j,data[i].size()){
				if(data[i][j]>lefst[i]){
					mi=min(mi,data[i][j]);
				}
			}
			ans=min(mi,ans);
			//cout<<i<<" "<<mi<<endl;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 51072
// All Heil Fire Lord Zuko

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

#define sz(x) (int)x.size()
#define F first
#define S second
#define PB push_back

#define debug(x) cerr << #x << " = " << x << "\n"

typedef long long ll ;
typedef pair<ll, ll> pll ;
typedef pair<ll, bool> pllb ;

const ll N = 100 * 1000 + 19 ;
const ll Mod = 998244353 ;
const ll inf = 1e10 + 19 ;

ll n, a, b, h[N];

ll BinarySearch() ;
bool IsValid(ll x) ;

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) ;
    cin >> n >> a >> b ;
    for (int i = 0 ; i < n ; i ++) cin >> h[i] ;
    cout << BinarySearch() ;
    return 0 ;
}

ll BinarySearch() {
    ll low = 0, high = inf ;
    while (high - low > 1) {
        ll mid = (low + high) / 2 ;
        if (IsValid(mid))
            high = mid ;
        else
            low = mid ;
    }
    return high ;
}

bool IsValid(ll x) {
    ll cnt = 0 ;
    for (int i = 0 ; i < n ; i ++) {
        ll tmp = h[i] ;
        tmp -= x * b ;
        if (tmp <= 0) continue ;
        cnt += (tmp / (a - b)) + min(1ll , tmp % (a - b)) ;
    }
    return cnt <= x ;
}

/* THINGS TO CHECK */

// Runtime ->
// Overflow ->
// Time ->
// Memory ->

/* READ PROBLEM STATEMENT CAREFULLY */


Measured memory_bytes: 1024
local k=io.read("n")

local que={1,2,3,4,5,6,7,8,9}

for i=1,k-1 do
    local pop=que[i]
    for j=-1,1 do
        local add=(pop%10)+j
        if 0<=add and add<=9 then
            table.insert(que,pop*10+add)
        end
    end
end
print(que[k])

Measured memory_bytes: 6664