akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll A,B;
  cin>>A>>B;
  co(A*B);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long x,y,z;
    cin>>x>>y>>z;
     x-=2*z*1ll;
    vector<long long>valid;
    for(int i=1;i<=x;i++)
    {
        long long gap=(i-1)*1ll*z;
        if((x-i*1ll*y)>=gap)
        {
            valid.push_back(i);
        }

    }   
    sort(valid.begin(),valid.end(),greater<int>());
    cout<<valid[0];
}





Measured memory_bytes: 892
from heapq import *

n=int(input())
inputs=lambda:map(int,input().split())
v=inputs()
u=[]
for i in v:
  heappush(u,i)
for j in range(n-1):  
  a1=heappop(u)
  a2=heappop(u)
  ave=(a1+a2)/2
  heappush(u,ave)
print(u[0])
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LOG(...) printf(__VA_ARGS__)
using namespace std;

int sd(int x) {
    int total = 0;
    while (x > 0) {
        total += x % 10;
        x /= 10;
    }
    return total;
}

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

    int min_s = INT_MAX;

    for (int i = 1; i <= n / 2; ++i) {
        int s = sd(i) + sd(n - i);
        if (s < min_s)
            min_s = s;
    }

    cout << min_s << endl;

    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int l=s.size();
  int a=0,b=0,c=0,d=0;
  for(int i=0;i<l;i++){
    if(i%2 == 0){
      if(s[i] == '0') a++;
      else b++;
    }
    else{
      if(s[i] == '0') c++;
      else d++;
    }
  }
  cout << min(a+d,b+c) << endl;
}


Measured memory_bytes: 512
import Data.List.Split

toInt :: String -> Int
toInt = read :: String -> Int

countReachableSquares :: Int -> Int -> Int
countReachableSquares h w
  | h == 1 = 1
  | w == 1 = 1
  | otherwise = ceiling (fromIntegral (h * w) / 2)

main = do
  s <- getLine
  let l = splitOn " " s 
  let h = toInt (l!!0)
  let w = toInt (l!!1)
  putStrLn $ show $ countReachableSquares h w


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

#define NIL -1

struct Node {
  int parent = NIL;
  int left = NIL;
  int right = NIL;
};

Node tree[30];

void preorder(int id) {
  if (id == NIL) return;
  cout << " " << id;
  preorder(tree[id].left);
  preorder(tree[id].right);
}

void inorder(int id) {
  if (id == NIL) return;
  inorder(tree[id].left);
  cout << " " << id;
  inorder(tree[id].right);
}

void postorder(int id) {
  if (id == NIL) return;
  postorder(tree[id].left);
  postorder(tree[id].right);
  cout << " " << id;
}

int main() {
  int N; cin >> N;
  
  for (int i = 0; i < N; i++) {
    int id; cin >> id;
    cin >> tree[id].left >> tree[id].right;
    if (tree[id].left != NIL) {
      tree[tree[id].left].parent = id;
    }
    if (tree[id].right != NIL) {
      tree[tree[id].right].parent = id;
    }
  }

  // get root
  int root = 0;
  while (tree[root].parent != NIL) {
    root = tree[root].parent;
  }

  cout << "Preorder" << endl;
  preorder(root);
  cout << endl;

  cout << "Inorder" << endl;
  inorder(root);
  cout << endl;

  cout << "Postorder" << endl;
  postorder(root);
  cout << endl;
}



Measured memory_bytes: 3116
#include<stdio.h>
#include<vector>

using namespace std;

int main()
{
	int n;
	
	scanf("%d",&n);

	vector<int> a(n);

	for(int b=0;b<n;b++)scanf("%d",&a[b]);

	int cnt=0;
	for(int b=0;b<n-1;b++)
	{
		if(a[b]==a[b+1])
		{
			cnt++;
			b++;
		}
	}

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>

using namespace std;

struct DATA{
  int a;
  int b;
};

void SwapCipher(char&, char&, int);
int Search(string, char);

int main(){
  int i, n, a, b;
  string str;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    cin >> str;

    for(i=0; i<n; ++i){
      cin >> a >> b;
      _data.a = a-1;
      _data.b = b-1;
      data.push_back(_data);
    }

    for(i=data.size()-1; i>=0; --i)
      SwapCipher(str[data[i].a], str[data[i].b], data[i].b-data[i].a);

    cout << str << endl;
    data.clear();
  }
  return 0;
}

void SwapCipher(char& c1, char& c2, int x){
  int a, b;
  string data = "abcdefghijklmnopqrstuvwxyz";
  a = (Search(data, c1) + x)%data.size();
  b = (Search(data, c2) + x)%data.size();
  c1 = data[b];
  c2 = data[a];
}

int Search(string data, char c){
  int i;
  for(i=0; i<data.size(); ++i){
    if(c == data[i]) return i;
  }
  return -1;
}

Measured memory_bytes: 0
using System;
using System.Linq;

namespace AtCoderBeginnerContest151
{
	class Program
	{
		static void Main(string[] args)
		{
			var numbers = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			var results = new Score[numbers[1]];
			var accepts = new bool[numbers[0]];
			var waCounts = new int[numbers[0]];
			for (var i = 0; i < numbers[1]; i++)
			{
				var tmp = Console.ReadLine().Split();
				results[i] = new Score
				{
					Question = int.Parse(tmp[0]),
					Result = tmp[1]
				};
			}

			var accept = 0;
			var reject = 0;
			for(var i = 0; i < numbers[1]; i++)
			{
				if (!accepts[results[i].Question - 1])
				{
					if (results[i].Result == "AC")
					{
						accepts[results[i].Question - 1] = true;
						accept++;
						reject += waCounts[results[i].Question - 1];
					}
					else
					{
						waCounts[results[i].Question - 1]++;
					}
				}
			}

			Console.WriteLine($"{accept} {reject}");
		}

		private class Score
		{
			public int Question { get; set; }

			public string Result { get; set; }
		}
	}
}


Measured memory_bytes: 26448
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>
using namespace std;
long long cnt;
vector<int> G;
int n;
int a[1000000];

/*void algorithm3_6(vector<int> G, int A[], int N) {
    for (int i = G.size() - 1; i >= 0; i--) {
        for (int k = 0; k < N - G[i]; k++) {//对应每个i，一共要进行N-G[i]次选择排序
            int count = (k + G[i]) % G[i];
            if (G[i] == 1) {
                //当G[i]=1时，需要对整个数组进行插入排序
                for (int j = 1; j < N - 1; j++) {
                    int v = A[j];
                    for (int k = j - 1; k >= 0; k--) {
                        if (A[k] > v) {
                            A[k + 1] = A[k];
                            A[k] = v;
                            cnt++;
                        }
                    }
                }
            }
            for (int l = count + G[i]; l <= k + G[i]; l = l + G[i]) {
                int v = A[l];
                for (int m = l - G[i]; m >= 0; m = m - G[i]) {
                    if (A[m] > v) {
                        A[m + G[i]] = A[m];
                        A[m] = v;
                        cnt++;
                    }
                }
            }
        }
    }
}*/
void insertSort(int A[],int n,int g) {
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[],int n) {
    for (int h = 1;;) {
        if (h > n) {
            break;
        }
        G.push_back(h);
        h = 3 * h + 1;
    }
    for (int k = G.size()-1; k >= 0; k--) {
        insertSort(A,n,G[k]);
    }
}

int main() {
    cin >> n;
    cnt = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    shellSort(a,n);
    cout << G.size() << endl;
    for (int i = G.size() - 1; i >= 0; i--) {
        printf("%d",G[i]);
        if (i) {
            printf(" ");
        }
    }
    printf("\n");
    printf("%d\n",cnt);
    for (int j = 0; j < n; j++) {
        printf("%d\n",a[j]);
    }
    return 0;
}


Measured memory_bytes: 7160
#![allow(unused_macros)]

#[allow(unused_imports)]
use std::cmp::{max, min};

#[allow(unused_imports)]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

macro_rules! chmin {
    ($a:ident,$b:expr) => {
        a = {
            let tmp = b;
            if (a > b) {
                b
            } else {
                a
            }
        }
    };
}

macro_rules! chmax {
    ($a:ident,$b:expr) => {
        a = {
            let tmp = b;
            if (a < b) {
                b
            } else {
                a
            }
        }
    };
}

const LG: usize = 30;

#[allow(non_snake_case)]
#[allow(unused)]
fn main() {
    input! {
        N:usize,
        K:Isize1,
        P:[Usize1;N],
        C:[i32;N],
    }
    let mut dst = vec![vec![0usize; N]; LG];
    let mut sum = vec![vec![0i64; N]; LG];
    let mut opt = vec![vec![0i64; N]; LG];

    for i in 0..N {
        dst[0][i] = P[i];
        sum[0][i] = C[P[i]] as i64;
        opt[0][i] = max(C[P[i]], 0) as i64;
    }

    for k in 1..LG {
        for i in 0..N {
            dst[k][i] = dst[k - 1][dst[k - 1][i]];
            sum[k][i] = sum[k - 1][i] + sum[k - 1][dst[k - 1][i]];
            opt[k][i] = max(opt[k - 1][i], sum[k - 1][i] + opt[k - 1][dst[k - 1][i]]);
        }
    }

    let mut ans = i64::min_value();
    for i in 0..N {
        let mut v = P[i];
        let mut sm = C[v] as i64;
        ans = max(ans, sm);
        for k in 0..LG {
            if (K >> k & 1) == 0 {
                continue;
            }
            ans = max(ans, sm + opt[k][v]);
            sm += sum[k][v];
            v = dst[k][v];
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 5776
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <complex>
#include <assert.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <double,double> P;
 
static const int tx[] = {+0,+1,+0,-1};
static const int ty[] = {-1,+0,+1,+0};
 
static const double EPS = 1e-8;

int table[3][3];

bool check(int mod){
  set<int> result;
  for(int y = 0; y < 3; y++){
    int sum = 0;
    for(int x = 0; x < 3; x++){
      sum += table[y][x];
    }
    result.insert(sum % mod);
  }
  for(int x = 0; x < 3; x++){
    int sum = 0;
    for(int y = 0; y < 3; y++){
      sum += table[y][x];
    }
    result.insert(sum % mod);
  }
  result.insert((table[0][0] + table[1][1] + table[2][2]) % mod);
  result.insert((table[0][2] + table[1][1] + table[2][0]) % mod);
  return (result.size() == 1);
}

int dfs(int pos,int used,int mod){
  if(pos >= 9 && check(mod)){
    return 1;
  }
  else if(pos >= 9){
    return 0;
  }
  int res = 0;
  int x = pos % 3;
  int y = pos / 3;

  if(table[y][x] == 0){
    for(int i = 1; i <= 10; i++){
      if(used & (1<<i)) continue;
      table[y][x] = i;
      res += dfs(pos + 1, used | (1<<i),mod);
      table[y][x] = 0;
    }
  }
  else{
    res += dfs(pos + 1, used,mod);
  }
  return res;
}

int main(){
  while(~scanf("%d",&table[0][0])){
    int used = 0;
    if(table[0][0] != 0){
      used |= (1<<table[0][0]);
    }

    for(int y = 0; y < 3; y++){
      for(int x = 0; x < 3; x++){
        if(y == 0 && x == 0) continue;
        scanf("%d",&table[y][x]);
        if(table[y][x] != 0){
          used |= (1<<table[y][x]);
        }
      }
    }
    int mod;
    scanf("%d",&mod);
    if(mod == -1) break;

    used |= (1<<mod);
    int res = 0;
    if(mod == 0){
      int prev = used;
      for(int i = 1; i <= 10; i++){
        if(used & (1<<i)) continue;
        used |= (1<<i);
        mod = i;
        res += dfs(0,used,mod);
        used = prev;
      }
    }
    else{
      res += dfs(0,used,mod);
    }
    printf("%d\n",res);
  }
}

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

#define int long long

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

int N, K;
int x[50], y[50];

signed main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    int ans = LLONG_MAX;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                for (int l = 0; l < N; l++) {
                    int contain = 0;
                    for (int m = 0; m < N; m++) {
                        if (x[i] <= x[m] && x[j] >= x[m] && y[k] <= y[m] && y[l] >= y[m]) {
                            contain++;
                        }
                        if (contain >= K) {
                            ans = min(ans, (x[j] - x[i]) * (y[l] - y[k]));
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,maxx,sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int v;
		scanf("%d",&v);
		sum+=v;
		maxx=max(maxx,v);
	}
	sum-=maxx;
	if(sum>maxx)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

typedef long long int ll;

map<ll,ll> freq;

ll f(ll x, ll y, ll z) {
	return x * x + y * y + z * z + x * y + x * z + y * z;
}

void triplets(int n) {
	for (int i = 1; i * i <= n; i++) {
		for (int j = 1; j * j <= n and i * j <= n; j++) {
			for (int k = 1; k * k <= n and j * k <= n and i * k <= n; k++) {
				ll _f = f(i, j, k);
				if (_f > n)
					break;
				freq[_f]++;
			}
		}
	}
}

int main() {
	optimizar_io
	int n;

	cin >> n;
	triplets(n);
	for (int i = 1; i <= n; i++) {
		if (freq.count(i))
			cout << freq[i] << "\n";
		else
			cout << "0\n";
	}
	return 0;
}

Measured memory_bytes: 4164
#include <climits>
#include <cstdio>
#include <cstdint>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using i32 = int32_t;
using u32 = uint32_t;
using f32 = float;
using f64 = double;
using i64 = int64_t; 
using u64 = uint64_t; 

#define SELECTER(_1, _2, _3, _4, _5, _6, _7, _8, SELECT, ...) SELECT

#define _FC1(func, type, _1)      func(type, _1);
#define _FC2(func, type, _1, ...) func(type, _1); _FC1(func, type, __VA_ARGS__);
#define _FC3(func, type, _1, ...) func(type, _1); _FC2(func, type, __VA_ARGS__);
#define _FC4(func, type, _1, ...) func(type, _1); _FC3(func, type, __VA_ARGS__);
#define _FC5(func, type, _1, ...) func(type, _1); _FC4(func, type, __VA_ARGS__);
#define _FC6(func, type, _1, ...) func(type, _1); _FC5(func, type, __VA_ARGS__);
#define _FC7(func, type, _1, ...) func(type, _1); _FC6(func, type, __VA_ARGS__);
#define _FC8(func, type, _1, ...) func(type, _1); _FC7(func, type, __VA_ARGS__);

#define _FCN(func, type, ...) SELECTER(__VA_ARGS__, _FC8, _FC7, _FC6, _FC5, _FC4, _FC3, _FC2, _FC1)(func, type, __VA_ARGS__);

constexpr const char *type2fmt(const char *fmt) {
  if(strcmp(fmt, "i32")) return "%d";
  if(strcmp(fmt, "u32")) return "%u";
  if(strcmp(fmt, "f32")) return "%f";
  if(strcmp(fmt, "f64")) return "%lf";
  if(strcmp(fmt, "i64")) return "%lld";
  if(strcmp(fmt, "u64")) return "%llu";
  if(strcmp(fmt, "char*")) return "%s";
  return "";
}

#define _R(type, _1) type _1; { type _t; scanf(type2fmt(#type), &_t); _1 = _t; }
#define _P(type, _1) { const type _t = (_1); printf(type2fmt(#type), _t); putchar('\n'); }

#define RI(...)   _FCN(_R, i32, __VA_ARGS__);
#define RUI(...)  _FCN(_R, u32, __VA_ARGS__);
#define RF(...)   _FCN(_R, f32, __VA_ARGS__);
#define RD(...)   _FCN(_R, f64, __VA_ARGS__);
#define RLL(...)  _FCN(_R, i64, __VA_ARGS__);
#define RULL(...) _FCN(_R, u64, __VA_ARGS__);

#define PI(...)   _FCN(_P, i32, __VA_ARGS__);
#define PUI(...)  _FCN(_P, u32, __VA_ARGS__);
#define PF(...)   _FCN(_P, f32, __VA_ARGS__);
#define PD(...)   _FCN(_P, f64, __VA_ARGS__);
#define PLL(...)  _FCN(_P, i64, __VA_ARGS__);
#define PULL(...) _FCN(_P, u64, __VA_ARGS__);
#define PS(...)   _FCN(_P, char*, __VA_ARGS__);

#define REP(n) for (int _i = 0; _i < n; _i++)

const u64 mod = 1000000007;

int main() {
  vector<u32> v;
  RI(N); REP(N) { RI(t); v.push_back(t); }
  sort(v.begin(), v.end());
  PI(v[v.size() - 1] - v[0]);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int A, B, C, g, d;
	d = 0;
	g = 0;

	scanf("%d %d %d", &A, &B, &C);

	while (g < C) {
		++d;
		g = g + A;
		if (d % 7 == 0) {
			g = g + B;
		}
	}
	printf("%d\n", d);

	return 0;
}



Measured memory_bytes: 2096
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N;
int A[2010];
int B[2010][2010];
int X;

signed main(){
	cin>>N>>X;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N){
		B[i][0]=A[i];
		for(int k=1;k<N;k++){
			B[i][k]=min(B[i][(k-1+N)%N],A[(i-k+N)%N]);
		}
	}
	int ans=INF;
	REP(k,N){
		int sum=0;
		REP(i,N){
			sum+=B[i][k];
		}
		ans=min(ans,k*X+sum);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
	int n;
	int cnt = 0;
	int a[128];

	cin >> n;

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

	for (int i = 0; i < n - 1; i++){
		int mini = i;
		for (int j = i; j < n; j++){
			if (a[mini] > a[j]) mini = j;
		}
		if (mini != i){
			swap(a[mini], a[i]);
			cnt++;
		}
	}

	
	for (int i = 0; i < n; i++){
		cout << a[i] << (i + 1 == n ? '\n' : ' ');
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3068
open Scanf
open Printf

exception Error

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec rep n f = if n <= 0 then [] else let x = f () in x :: rep (n-1) f

let rec itv f xs =
  match xs with
  | [] -> raise Error
  | (_::[]) -> []
  | (x::y::ys) -> f x y :: itv f (y::ys)

let () =
  let n = read_int () in
  let result = (0, 0, 0) :: rep n (fun () -> let [t; x; y] = read_ints 3 in (t, x, y))
  |> itv (fun (t0, x0, y0) (t1, x1, y1) -> (t1-t0, x1-x0, y1-y0))
  |> List.for_all (fun (dt, dx, dy) ->
      let rest = dt - abs dx - abs dy in rest >= 0 && rest mod 2 = 0) in
  printf "%s\n" (if result then "Yes" else "No")


Measured memory_bytes: 20736
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  cin>>s;
  reverse(s.begin(), s.end());
  string e[4] = {"maerd", "remaerd", "esare", "resare"};
  int l[4] = {5,7,5,6};
  int point = 0;
  string ans = "YES";
  while(point != s.size()) {
    bool flag = false;
    rep(i,4) {
      if(s.substr(point, l[i]) == e[i]) {
        point += l[i];
        flag = true;
        break;
      }
    }
    if(!flag) {
      ans = "NO";
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int LIS(VL a){
    int n = a.size();
    VL dp(n+1,1e18);
    REP(i,n){
        *lower_bound(ALL(dp), a[i]) = a[i];
    }
    int ret =  lower_bound(ALL(dp), 1e18) - dp.begin();
    return ret;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    if (a + b > n + 1 || a * b < n){
        cout << -1 << endl;
        return 0;
    }

    VI cnt(b, 1);
    cnt[0] = a;
    int c = 1;
    REP(_,n-a-b+1){
        cnt[c]++;
        c++;
        if (c >= b) c = 1;
    }


    VL ans(n);
    int p = 0;
    ll s = n;
    REP(i,b){
        s -= cnt[i];
        REP(j,cnt[i]){
            ans[p++] = s + j;
        }
    }

    REP(i,n) printf("%lld ", ans[i] + 1);
    cout << endl;

    // VL x(ans), y(ans);
    // REP(i,n) y[i] *= -1;

    // cout << LIS(x) << " " << LIS(y) << endl;

    return 0;
}


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

int main(){
    char c[8][9];
    int i,j;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            cin>>c[i][j];
        }
    }
    cout<<90<<endl;
    for(i=0;i<8;i++){
        for(j=7;j>=0;j--){
            cout<<c[j][i];
        }
        cout<<endl;
    }
    cout<<180<<endl;
    for(i=7;i>=0;i--){
        for(j=7;j>=0;j--){
            cout<<c[i][j];
        }
        cout<<endl;
    }
    cout<<270<<endl;
    for(i=7;i>=0;i--){
        for(j=0;j<=7;j++){
            cout<<c[j][i];
        }
        cout<<endl;
    }
    return 0;
}

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

int main() {
	char a, b;
	cin >> a >> b;
	if (a == 'H') {
		if (b == 'H') {
			cout << 'H' << endl;
		}
		else {
			cout << 'D' << endl;
		}
	}
	else{
		if (b == 'H') {
			cout << 'D' << endl;
		}
		else {
			cout << 'H' << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom
  
m, n = map(int, input().strip().split())
print((ncr(m, 2) if m >=2 else 0) + (ncr(n, 2) if n >= 2 else 0))

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    ll n,k;
    cin>>n>>k;
    n=k+n%k;
    ll ans=linf;
    rep(i,5){
        n=abs(k-n);
        ans=min(ans,n);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = len([i for i in A if i % 2==0])
count = 0
for i in A:
    if i % 2 !=0:
        continue
    elif i % 3 ==0 or i % 5==0:
        count  +=1
if count == B:
    print('APPROVED')
else:
    print('DENIED')


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

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

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

    vector<vector<int>> b(n, vector<int> (m, 0));

    int cnt = 0;

    for (int i = 0; i < n; i += 1) {
        int last = 0;
        for (int j = 0; j < m; j += 1) {
            if (a[i][j] == '#') {
                ++cnt;
                last = cnt;
            }
            b[i][j] = last;
        }

        for (int j = m - 1; j >= 0; j -= 1) {
            if (b[i][j] > 0) {
                last = b[i][j];
            } else {
                b[i][j] = last;
            }
        }
    }
    
    auto zero = vector<int> (m, 0);
    auto last = zero;

    for (int i = 0; i < n; i += 1) {
        if (b[i] != zero) {
            last = b[i];
        } else {
            b[i] = last;
        }
    }
    
    last = zero;

    for (int i = n - 1; i >= 0; i -= 1) {
        if (b[i] != zero) {
            last = b[i];
        } else {
            b[i] = last;
        }
    }

    for (int i = 0; i < n; i += 1) {
        for (int j = 0; j < m; j += 1)
            cout << b[i][j] << " ";
        cout << "\n";
    }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int64 expr(string &s, int64 &p);
int64 term(string &s, int64 &p);
int64 value(string &s, int64 &p);

int64 expr(string &s, int64 &p) {
  int64 res = term(s, p);
  while (p < s.size()) {
    if (s[p] == '+') {
      p++;
      res += term(s, p);
      continue;
    }
    break;
  }
  return res;
}

int64 term(string &s, int64 &p) {
  int64 res = value(s, p);
  while (p < s.size()) {
    if (s[p] == '*') {
      p++;
      res *= value(s, p);
      continue;
    }
    break;
  }
  return res;
}

int64 value(string &s, int64 &p) {
  return s[p++]-'0';
}

int64 expr2(string &s) {
  int64 res = s[0]-'0';
  FOR(i, 1, s.size()) {
    if (s[i] == '+') {
      res = res + s[i+1] -'0';
      i++;
    } else {
      res = res * (s[i+1] - '0');
      i++;
    }
  }
  return res;
}

int main(void) {
  string s;
  int64 ret;
  cin >> s >> ret;
  string ans = "ILMU";
  int64 p = 0;
  int64 res = (ret == expr(s, p)) << 1 | (ret == expr2(s));
  cout << ans[res] << endl;
}



Measured memory_bytes: 3224
S = input()

half_length = int(len(S) / 2)
cnt = 0
front = []
back = []

if len(S) % 2 == 0:
    front = list(S[ 0 : half_length ])
    back = list((S[ half_length : len(S)]))
else:
    front = list((S[ 0 : int(len(S) / 2) ]))
    back = list((S[ int(len(S) / 2) + 1 : len(S)]))


back.reverse()

for i in range(len(front)):
    if front[i] != back[i]:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector> 
using namespace std;
int n;
long long ans;
struct node{
	int x,y;
	node(int u,int v)
	{
		x=u,y=v;
	}
};
vector <node> c[4];
inline bool cmp1(node x,node y)
{
	return x.x+x.y > y.x+y.y;
}
inline bool cmp2(node x,node y)
{
	return -x.x+x.y > -y.x+y.y;
}
inline bool cmp3(node x,node y)
{
	return -x.x-x.y > -y.x-y.y;
}
inline bool cmp4(node x,node y)
{
	return x.x-x.y > y.x-y.y;
}
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	n=read();
	int u,v;
	for(int i=1;i<=n;++i)
	{
		int x=read(),y=read();
		c[0].push_back(node(x,y));
		c[1].push_back(node(x,y));
		c[2].push_back(node(x,y));
		c[3].push_back(node(x,y));
	}
	sort(c[0].begin(),c[0].end(),cmp1);
	sort(c[1].begin(),c[1].end(),cmp2);
	sort(c[2].begin(),c[2].end(),cmp3);
	sort(c[3].begin(),c[3].end(),cmp4);
	for(int i=0;i<n;++i)
	{
		int x=c[0][i].x,y=c[0][i].y;
		for(int j=0;j<4;++j)
		{
			u=c[j][0].x,v=c[j][0].y;
			ans=max(ans,(long long)abs(x-u)+abs(y-v));
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    int N, M;
    cin>>N>>M;
    vector<int> A;
    int tmp;
    int sum = 0;
    for(int i=0;i<N;++i){
        cin>>tmp;
        A.push_back(tmp);
        sum += tmp;
    }
    sort(A.begin(), A.end(), greater<int>());
    int ans = 0;
    for(int i=0;i<N;++i){
        if(A[i]*4*M>=sum)ans++;
    }
    if(ans>=M)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll n;cin >>n;
  vector<ll> a(n);
  vector<ll> b(n);
  for(ll i=0;i<n;++i)cin >> a[i] >> b[i];
  ll cnt = 0LL;
  for(ll j=0;j<n;++j){
    if( (a[n-1-j]+cnt)%(b[n-1-j]) != 0){
      cnt += (b[n-1-j]) - (a[n-1-j]+cnt)%(b[n-1-j]);
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>

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

using namespace std;

int main() {
    long l,r;
    cin >>l>>r;
    long res = 1000000;
    if (r-l > 2018) {
        res = 0;
    } else {
        for(long i=l;i<r;i++) {
            for (long j=i+1;j<r+1;j++) {
                res = min(res, (i%2019)*(j%2019)%2019);
            }
        }
    }
    cout <<res<<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()
{
    long long N;
    cin >> N;
    vector<long long> count(N + 1);
    vector<long long> count2(N + 1);
    vector<long long> value(N);
    rep(i, N){
        long long tmp = 0LL;
        cin >> tmp;
        value.at(i) = tmp;
        count.at(tmp)++;
    }

    long long sum = 0LL;
    rep(i, N+1){
        long long tmp = count.at(i);
        if(tmp == 0){
            continue;
        }
        count2.at(i) = tmp * (tmp - 1LL) / 2LL;
        sum += count2.at(i);
    }

    rep(i, N){
        long long tmp = value.at(i);
        long long tmp2 = count.at(tmp);
        long long tmp3 = (tmp2 - 1LL) * (tmp2 - 2LL) / 2LL;
        long long ans = sum - count2.at(tmp) + tmp3;
        cout << ans << endl;
    }

}

Measured memory_bytes: 7296
#include <stdio.h>

int main(void){
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a<b){
		printf("a < b\n");
	}
	if(a>b){
		printf("a > b\n");
	}
	if(a==b){
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 1008
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {

    ll N;
    string S;
    cin >> N >> S;
    ll A[N];
    rep(i,N) A[i] = 0;
    ll s = S.length();
    rep(i,s){
        if(i>0){
            if(S[i]=='E') A[0]++;
        }
    }
    rep(i,s){
        if(i>0){
            A[i] = A[i-1];
            if(S[i-1]=='W') A[i]++;
            if(S[i]=='E') A[i]--;
        }
    }
    ll out = N;
    rep(i,N){
        if(A[i]<out) out = A[i];
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  string s,t;
  int c=0;
  cin>>s;
  cin>>t;
  for(int i=0;i<s.length();i++)
    {
    if(s[i]!=t[i])
      {
      c++;
      }
    }
  cout<<c<<endl;
  }


Measured memory_bytes: 3900
#include <stdio.h>

void buildMaxHeap(int); // n??即i                                                                                 
void maxHeapify(int, int);
int heap[500000];

int main(void){
  int n,i;

  scanf("%d",&n); // heap_size                                                                                  
  for( i = 0 ; i < n ; i++ ){
    scanf("%d",&heap[i]);
  }

  buildMaxHeap(n);

  for( i = 0 ; i < n ; i++ ){
    printf(" %d",heap[i]);
  }

  printf("\n");
  return 0;
}

void buildMaxHeap(int size){
  int i;
  for( i = size/2 ; i >= 0 ; i-- ){
    maxHeapify(i, size);
  }
}

void maxHeapify(int x, int size){
  int l,r,largest,tmp;
  l = x*2+1;
  r = x*2+2;

  if( l <= size && heap[l] > heap[x] ) largest = l;
  else largest = x;
  if( r <= size && heap[r] > heap[largest] ) largest = r;
  if( largest != x ){
    tmp = heap[x];
    heap[x] = heap[largest];
    heap[largest] = tmp;
    maxHeapify(largest, size);
  }
}

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

int main(){
	int n,  ma, mi, a;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>a;
		if(!i){
			ma = a;
			mi = a;
		}else{
			ma = max(a, ma);
			mi = min(a, mi);
		}
		
	}
	
	cout<<ma - mi<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
  map<int, int> check;
  int N, a;
  cin >> N;
  rep(i, N){
    cin >> a;
    check[a]++;
  }
  bool ans = true;
  for(auto itr : check){
    if(check[itr.first] > 1){
      ans = false;
      break;
    }
  }
    if(ans)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
}


Measured memory_bytes: 9600
#include<stdio.h>

int main(){
    long long n,a,b,sum = 0;
    scanf("%lld %lld %lld",&n,&a,&b);

    sum += a * (n / (a + b));
    if((n % (a + b)) < a)sum += (n % (a + b));
    else sum += a;

    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

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

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>b(n);
	rep(i, n) {
		cin >> a[i];
		b[a[i]]++;
	}
	ll ans = 1;
	if (n % 2 != 0) {
		rep(i, n) {
			if (i == 0 && b[i]!=1) {
				cout << 0 << endl;
				return 0;
			}
			if (i % 2 != 0&&b[i]!=0) {
				cout << 0 << endl;
				return 0;
			}
			if (i % 2 != 0 && b[i] == 0) {
				continue;
			}
			if (i != 0 && i % 2 == 0 && b[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
			ans *= b[i];
			ans = ans % 1000000007;
		}
	}
	else {
		rep(i, n) {
			if (i % 2 != 0 && b[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
			if (i % 2 == 0 && b[i] == 0) {
				continue;
			}
			if (i % 2 == 0 && b[i] != 0) {
				cout << 0 << endl;
				return 0;
			}
			ans *= b[i];
			ans = ans % 1000000007;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n, k int
	var bs []byte
	fmt.Scan(&n, &bs, &k)
	key := bs[k-1]
	sub := []byte("*")[0]
	for i, v := range bs {
		if key != v {

			bs[i] = sub
		}
	}
	fmt.Println(string(bs))
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

int compare(const void *a,const void *b){
	return *(int *)b-*(int *)a;
}

int main(){
	int N;
	int sum=0;
	int i;
	
	scanf("%d",&N);
	
	int L[N];
	
	for(i=0;i<N;i++){
		scanf("%d",&L[i]);
	}
	
	qsort(L,N,sizeof(int),compare);
	
	for(i=1;i<N;i++){
		sum+=L[i];
	}
	
	if(L[0]<sum)	printf("Yes");
	else	printf("No");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a[100000],b,c[50000],i,k=0,j;
  for(cin>>n,i=0;i<n;i++)cin>>a[i];
  for(cin>>b,i=0;i<b;i++)cin>>c[i];
  for(i=0;i<b;i++)if(binary_search(a,a+n,c[i]))k++;
  cout<<k<<endl;
}

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

int main()
{
	int r, D,x;
	cin >> r;
	cin >> D;
	cin >> x;
	for (int i = 0; i < 10; i++)
	{
		x = (r * x - D);
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std;
typedef long long int ll;

vector<int> adj[100000], dp;

int dfs(int curr, vector<bool>& visited) {
	if (visited[curr])
		return dp[curr];
	visited[curr] = true;
	int max_val = 0;
	for (int node : adj[curr]) {
		max_val = max(max_val, 1 + dfs(node, visited));
	}
	return dp[curr] = max_val;
}


int main() {
	fastio;
	int n, m, x, y;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		adj[x].push_back(y);
	}
	dp.resize(n + 1);
	vector<bool> visited(n + 1);
	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (!visited[i]) {
			res = max(res, dfs(i, visited));
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 11332
#include <iostream>
using namespace std;
#define len 100001
#define INFTY 10000000

struct Card{
  char picture;
  int num;
};

int partition(Card A[],int p,int r){
  
  int x = A[r].num;
  int i = p-1;
  for(int j = p; j < r; ++j){
    if(A[j].num <= x){
      ++i;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

void quicksort(Card A[],int p,int r){
  if(p < r){
    int q = partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}

void merge(Card A[],int left,int mid,int right){
  int n1 = mid - left;
  int n2 = right - mid;
  Card L[n1],R[n2];
  for(int i=0; i < n1; ++i)   L[i] = A[left + i];
  for(int i=0; i < n2; ++i)   R[i] = A[mid + i];
  L[n1].num = INFTY;
  R[n2].num = INFTY;
  int i = 0, j = 0;
  for(int k = left; k < right; ++k){
    if( L[i].num <= R[j].num ){
      A[k] = L[i++];
    }
    else{ 
      A[k] = R[j++];
    }
  }

}

void mergesort(Card A[],int left,int right){
  if(left+1 < right){
    int mid = (left + right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}

bool isStable(Card A[],Card B[],int n){
  for(int i=0; i<n; ++i)
    if(A[i].picture != B[i].picture)
      return false;
  return true;
}

int main(){
  int n;
  Card A[len],B[len];
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> A[i].picture >> A[i].num;
    B[i].picture = A[i].picture;
    B[i].num = A[i].num;
  }
  quicksort(A,0,n-1);
  mergesort(B,0,n);

  if(isStable(A,B,n))
    cout << "Stable";
  else
    cout << "Not stable";
  cout << endl;

  for(int i=0; i<n; ++i) cout << A[i].picture << " " << A[i].num << endl;
  

  return 0;
}



Measured memory_bytes: 5432
/*	
	:)
*/
#include <bits/stdc++.h> 
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define pb push_back
#define ff first
#define ff first
#define ss second
#define inf 2e18
#define mod 998244353
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define mx 205
#define ll long long
#define pi 3.1415926535897932384626433
void solve()
{
	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.size() <= k)
	{
		cout << s << endl;
	}
	else
	{
		fl(i,0,s.size())
		{
			if(i < k)
				cout << s[i];
		}
		cout << "...";
	}
}
main()
{
	fast;
	int t =  1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3652
var
	s,t,ans:ansistring;
	i,j,n,m:longint;
	a:array[0..3001,0..3001] of longint;
begin
	readln(s); n:=length(s);
	readln(t); m:=length(t);
	fillchar(a,sizeof(a),0);
	for i:=1 to n do
		for j:=1 to m do
			if s[i]=t[j] then a[i,j]:=a[i-1,j-1]+1
			else if a[i-1,j]>a[i,j-1] then a[i,j]:=a[i-1,j]
					else a[i,j]:=a[i,j-1];
	ans:='';
	i:=n; j:=m;
	while (i>0) and (j>0) do
		if s[i]=t[j] then
		begin
			ans:=s[i]+ans;
			dec(i); dec(j);
		end
		else if a[i-1,j]>a[i,j-1] then dec(i)
				else dec(j);
	writeln(ans);
end.

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

constexpr double EPS = 1e-10;
using point = complex<double>;
using vect = point;
using segment = pair<point, point>;
using line = segment;
using circle = pair<point, double>;
using polygon = vector<point>;
double dot(vect a, vect b){
	return real(a) * real(b) + imag(a) * imag(b);
}
double cross(vect a, vect b){
	return real(a) * imag(b) - imag(a) * real(b);
}
point project(line l, point p){
	vect base = l.second - l.first;
	base /= abs(base);
	double r = dot(p - l.first, base);
	return l.first + r * base;
}
point reflect(line l, point p){
	return p + (project(l, p) - p) * 2.0;
}
int ccw(point p0, point p1, point p2){
	vect v = p1 - p0, w = p2 - p0;
	if(cross(v, w) > EPS) return 1; // COUNTER_CLOCKWISE
	if(cross(v, w) < -EPS) return -1; // CLOCKWISE
	if(dot(v, w) < -EPS) return 2; // ONLINE p2 - p0 - p1
	if(norm(v) + EPS < norm(w)) return -2; // ONLINE p0 - p1 - p2
	return 0; // ONLINE p0 - p1 - p2
}
bool orthogonal(vect v1, vect v2){
	double t = abs(dot(v1, v2));
	return t <= EPS;
}
bool parallel(vect v1, vect v2){
	double t = abs(cross(v1, v2));
	return t <= EPS;
}
bool intersect(segment s1, segment s2){
	int t = ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second);
	int u = ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second);
	return (t == 0 || t == -1 || t == -4) && (u == 0 || u == -1 || u == -4);
}
point getcrosspoint(segment s1, segment s2){
	assert(intersect(s1, s2));
	assert(!parallel(s1.second - s1.first, s2.second - s2.first));
	vect base = s2.second - s2.first;
	double d1 = abs(cross(base, s2.first - s1.first));
	double d2 = abs(cross(base, s2.first - s1.second));
	return s1.first + (s1.second - s1.first) * d1 / (d1 + d2);
}
double getdistancePL(point p, line l){
	return abs(cross(p - l.first, l.second - l.first)) / abs(l.second - l.first);
}
double getdistancePS(point p, segment s){
	if(dot(s.second - s.first, p - s.first) < 0.0) return abs(p - s.first);
	if(dot(s.first - s.second, p - s.second) < 0.0) return abs(p - s.second);
	return getdistancePL(p, line(s));
}
double getdistanceSS(segment s1, segment s2){
	if(intersect(s1, s2)) return 0.0;
	return min({getdistancePS(s2.first, s1), getdistancePS(s2.second, s1), getdistancePS(s1.first, s2), getdistancePS(s1.second, s2)});
}
double area(polygon p){
	assert(p.size() >= 2);
	point t = p[1];
	double res = 0.;
	for(size_t i=2; i<p.size(); ++i){
		res += cross(t-p[0], p[i]-p[0]) / 2.;
		t = p[i];
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	polygon p(n);
	for(auto &i:p){
		int x, y; cin >> x >> y;
		i = point(x, y);
	}
	cout << fixed << setprecision(1) << area(p) << "\n";
}


Measured memory_bytes: 3284
/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A
 */

#include <vector>
#include <iostream>
using namespace std;

class UnionFind {
public:
    /**
     * コンストラクタ．
     * @param n
     */
    UnionFind(int n);

    /**
     * 木の根を求める
     * @param x
     * @return
     */
    int find(int x);

    /**
     * xとyの属する集合を併合する
     * @param x
     * @param y
     */
    void unite(int x, int y);

    /**
     * xとyが同じ集合に属するか否か
     * @param x
     * @param y
     * @return
     */
    bool same(int x, int y);

    int size(int x);

private:
    std::vector<int> sz;
};

UnionFind::UnionFind(int n) {
    sz.assign(n, -1);
}

// 木の根を求める
int UnionFind::find(int x) {
    if (sz[x] < 0) return x;
    return sz[x] = find(sz[x]);
}

// xとyの属する集合を併合する
void UnionFind::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (sz[x] > sz[y]) swap(x, y);
    sz[x] += sz[y];
    sz[y] = x;
}

// xとyが同じ集合に属するか否か
bool UnionFind::same(int x, int y) {
    return find(x) == find(y);
}

int UnionFind::size(int x) {
    return -sz[find(x)];
}

int N, Q;

int main() {

    cin >> N >> Q;

    UnionFind uf(N);

    while (Q--) {

        int com, x, y;
        cin >> com >> x >> y;

        if (com == 0) {
            uf.unite(x, y);
        } else {
            printf("%d\n", uf.same(x, y) ? 1 : 0);
        }
    }

    return 0;
}


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

using namespace std;

int main()
{
    #ifdef __beyond_TLE__
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #define cerr if(true)cerr
        freopen("Eroor.txt", "w", stderr);
    #endif

    #ifndef __beyond_TLE__
        #define cerr if(false)cerr
    #endif
    string s;
    cin>>s;
    long long int cnt=0, len = s.length();
    for(long long int i=0;i<len;i++)
    {
        if(s[i]=='0'&&s[i+1]=='0')
        {
            s[i+1]='1';
            cnt++;
        }
        else if(s[i]=='1'&&s[i+1]=='1')
        {
            s[i+1]='0';
            cnt++;
        }
    }
    cout<<min(len-cnt,cnt);
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int retlen = 0;
    for(int i=0; i <  n - 1; i++){
        for(int len = retlen + 1; len <= (n - i) / 2 ; len++){
            string pat = s.substr(i, len);
            auto l1 = s.find(pat);
            auto l2 = s.rfind(pat);
            if(l1 + len <= l2){
                retlen = len;
            }else{
                break;
            }
        }
    }
    cout << retlen << endl;
    return 0;
}

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

int main(){
  string str, str1, str2;
  int m, h;
  
  while(1){  
    cin >> str;
    if( str[0] == '-') break;
    cin >> m;
    for( int j = 0; j < m; j++){
      cin >> h;
      str1 = str.substr(0, h);
      str2 = str.substr(h, str.size() - h);
      str = str2 + str1;
    }
    cout << str << endl;
  }

  return 0;
}

Measured memory_bytes: 3180