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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    vector<int>vec;
    vec = {i / 100, (i / 10) % 10, i % 10};
    int p = 0;
    for (int j = 0; j < N; j++) {
      if (S.at(j) == vec.at(p) + '0') {
        p++;
      }
      if (p==3){
      ans++;
      break;
      }
    }
  }
  cout << ans << endl;
}


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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define print(x) cout << x << endl
#define debug print("reaching\n")
#define mll map<ll,ll>
#define lsb(i) i&(-i)
#define printv(x) \
	FORALL(i, x.size()) \
	{ \
		cout << x[i] << ' '; \
	} \
	cout << endl \
;
#define printm(m) \
	for(auto i: m){\
		cout<<i.ff<<' '<<i.ss<<endl; \
	}\
;

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	else
	{
		int g = extGcd(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}
}

template <typename T>
T modInv(T a, T m)
{
	T x, y;
	extGcd(a, m, x, y);
	return (x % m + m) % m;
}
// vector<map<ll,ll>> m(2);
long long binpow(long long a, long long b) {
    a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main()
{
	fast;
	// cin.tie(0);
	// cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int t=1;
	// cin>>t;
	ll tot=t;
	while(t--){
		ll n;
		cin>>n;
		vll a(n);
		vll b(n);
		FORALL(i,n){
			cin>>a[i];
		}
		FORALL(i,n){
			cin>>b[i];
		}

		reverse(all(b));
		int j = n-1;
		int l = 0;
		FORALL(i, n){
			if(a[i] == b[i]){
				if(b[i] != b[j] and b[i]!=a[j]){
					swap(b[i], b[j]);
					j--;
				}
				else if(b[i] != b[l] and b[i]!=a[l]){
					swap(b[i], b[l]);
					l++;
				}
				continue;
			}
		}
		int f = 0;
		FORALL(i, n){
			if(a[i] == b[i]){
				f = 1;
				break;
			}
		}
		if(f){
			print("No");
		} else {
			print("Yes");
			FORALL(i, n){
				cout<<b[i]<<' ';
			}
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 6436
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n; cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = n-1; 0 < i; i--){
        if(h[i-1] <= h[i]) continue;
        else if(h[i] + 1 == h[i-1]) h[i-1]--;
        else {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 640
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntListN n = map readInt <$> replicateM (fromIntegral n) BS.getLine

main = do
  n <- getInt
  xs <- getIntListN 5
  let x = minimum xs
  print $ (n + x - 1) `div` x + 4


Measured memory_bytes: 3740
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
          string s = ReadLine();
          for(int i = 0; i < s.Length / 2; i++){
              if(s[i] != s[s.Length - 1 - i]){
                  WriteLine("No");
                  return;
              }
          }

          var s1 = s.Substring(0, (s.Length - 1) / 2);
          for(int i = 0; i < s1.Length / 2; i++){
              if(s1[i] != s1[s1.Length - 1 - i]){
                  WriteLine("No");
                  return;
              }
          }

          var s2 = s.Substring((s.Length + 3) / 2 - 1);
          for(int i = 0; i < s2.Length / 2; i++){
              if(s2[i] != s2[s2.Length - 1 - i]){
                  WriteLine("No");
                  return;
              }
          }

          WriteLine("Yes");
      }
   }
}

Measured memory_bytes: 13140
import functools
import fractions

n, x = map(int, input().split())
a = [int(i) for i in input().split()]

a.append(x)
a.sort()

for i in range(len(a)):
  a[i] = abs(a[i] - x)

gcd = functools.reduce(fractions.gcd, a)
print(gcd)

Measured memory_bytes: 16200
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  cin >> a >> b;

  string aa = "";
  string bb = "";
  for(int i = 0;i < b;i++){
    aa += to_string(a);
  }

  for(int i = 0;i < a;i++){
    bb += to_string(b);
  }

  if(aa < bb)cout << aa << endl;
  else cout << bb << endl;
}

Measured memory_bytes: 256
n, w = map(int, input().split())
items = []

for i in range(n):
    items.append(list(map(int, input().split())))


def knapsack(n, w, items):
    c = [[0 for i in range(w + 1)] for j in range(n + 1)]
    g = [["TOP" for i in range(w + 1)] for j in range(n + 1)]

    for i in range(w + 1):
        c[0][i] = 0
        g[0][i] = "DIAGONAL"

    for i in range(n + 1):
        c[i][0] = 0

    for i in range(1, n + 1):
        for j in range(1, w + 1):
            c[i][j] = c[i - 1][j]
            g[i][j] = "TOP"
            item = items[i - 1]
            if item[1] > j:
                continue
            if item[0] + c[i - 1][j - item[1]] > c[i - 1][j]:
                c[i][j] = item[0] + c[i - 1][j - item[1]]
                g[i][j] = "DIAGONAL"

    max_value = c[n][w]
    routes = []
    for i in range(n, 0, -1):
        if g[i][w] == "DIAGONAL":
            routes.append(i)
            w -= items[i - 1][1]

    return max_value, routes


result, _ = knapsack(n, w, items)
print(result)



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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int H,W;
  cin >> H >> W;
  int sy,sx,gy,gx;
  cin >> sy >> sx >> gy >> gx;
  sy--;
  sx--;
  gy--;
  gx--;
  vector<string> S(H);
  rep(i,H)  cin >> S.at(i);

  vector<vector<int>> dist(H,vector<int>(W,1e9));
  priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> pq;
  dist.at(sy).at(sx)=0;
  pq.push(m_p(0,m_p(sy,sx)));
  while(!pq.empty()){
    int c=pq.top().fi;
    int y=pq.top().se.fi;
    int x=pq.top().se.se;
    pq.pop();
    if(dist.at(y).at(x)<c) continue;
    rep(i,4){
      int ny=y+dy.at(i);
      int nx=x+dx.at(i);
      if(ny<0 || ny>=H || nx<0 || nx>=W)  continue;
      if(S.at(ny).at(nx)=='#')  continue;
      if(dist.at(ny).at(nx)<=c) continue;
      dist.at(ny).at(nx)=c;
      pq.push(m_p(c,m_p(ny,nx)));
    }
    for(int i=-2;i<=2;i++){
      for(int j=-2;j<=2;j++){
        int ny=y+i;
        int nx=x+j;
        int nc=c+1;
        if(ny<0 || ny>=H || nx<0 || nx>=W)  continue;
        if(S.at(ny).at(nx)=='#')  continue;
        if(dist.at(ny).at(nx)<=nc) continue;
        dist.at(ny).at(nx)=nc;
        pq.push(m_p(nc,m_p(ny,nx)));
      }
    }
  }
  int ans=dist.at(gy).at(gx);
  if(ans==1e9)  ans=-1;
  cout << ans << endl;
  debug_mat(dist);

  return 0;
}

Measured memory_bytes: 8512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;

int main() {
    int i, j, n, p, q, temp;
    long long int t = 0;
    int flag = 0;
    int minidx;
    long long int minnum=1000000000;
    int count=0;
    string s;
    cin >> n;
    long long int a[n];
    for (i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for(i=0; i<n; ++i){
        if(a[i]<=0){++count;}
        if(abs(a[i])<minnum){minnum=abs(a[i]);minidx=i;}
    }
    if(count%2==0){
        for (i = 0; i < n; ++i) {t+=abs(a[i]);}
    }
    else{
        for (i = 0; i < n; ++i) {
            if(i==minidx){
                t-=abs(a[i]);
            }
            else{t+=abs(a[i]);}
        }
    }

    cout<<t;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;

    return 0;
}

Measured memory_bytes: 3576
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
else
  class Hash
    def bipartite_graph?
      color = Hash.new(0)

      dfs(1, 1, color)
    end

    private

    def dfs(v, c, color)
      color[v] = c

      E[v].each do |u, _|
        return false if color[u] == c
        return false if color[u] == 0 && !dfs(u, -c, color)
      end

      return true
    end
  end

  N, M = gets.split.map(&:to_i)
  E = Hash.new { |h, k| h[k] = {} }
  edges = M.times.map { gets.split.map(&:to_i) }

  edges.each do |a, b|
    E[a][b] = true
    E[b][a] = true
  end

  if E.bipartite_graph?
    color = Hash.new(0)

    dfs = ->(v, c) {
      color[v] = c

      E[v].each do |u, _|
        next if color[u] != 0

        dfs[u, -c]
      end
    }

    dfs[1, 1]

    counter = Hash.new(0)

    color.each do |v, c|
      counter[c] += 1
    end

    puts counter.values.inject(:*) - M
  else
    puts (N * (N - 1)) / 2 - M
  end
end


Measured memory_bytes: 121144
#include <bits/stdc++.h>
//#define DEBUG
#define REP( i , nn ) for(int i = 0 ; i < (int) nn; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve(){
    int n, q;
    ll k;
    cin >> n >> k >> q;
    vi rel_score(n);
    ll abs_score = 0;
    REP(i, q){
        int a;
        cin >> a;
        a--;
        rel_score[a]++;
        if( a != 0){
            abs_score--;
        }
    }
    
    REP(i, n){
        int score =  k + abs_score + (rel_score[i] - rel_score[0]);
        if( score > 0){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }


}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==5&&B==5&&C==7){
    cout << "YES"  << endl;
  }
  else if(A==5&&B==7&&C==5){
    cout << "YES" << endl;
  }
  else if(A==7&&B==5&&C==5){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


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

int main() {
  ll n, m;
  cin>>n>>m;
  ll a[n], b[n];
  for(int i=0; i<n; i++) cin>>a[i]>>b[i];
  pair<ll, ll> p[n];
  for(int i=0; i<n; i++) p[i]={a[i], b[i]};
  sort(p, p+n);
  ll ans=0;
  for(int i=0; i<n; i++){
    ans+=min(p[i].second,m)*p[i].first;
		m-=min(m,p[i].second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main {
    private static Scanner sc= new Scanner(System.in);
    

	public static void main(String[] args) {
		int a=sc.nextInt();
		int b=sc.nextInt();
		int x=a*b;
		int y=(a+b)*2;
		System.out.println(x+" "+y);
	}
	
}
    	

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


int dp[100001];
int main()
{
    int X;
    int price[6] = {100, 101, 102, 103, 104, 105};
    cin >> X;
    
    dp [0] = 1;
    for (int i = 0; i <= 100001; i++){
        for (int j = 0; j < 6; j++){
            if (i >= price[j]){
                dp[i] = max(dp[i], dp[i - price[j]]);
            }
        }
    }
    cout << dp[X] << endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int,input().split()))

while len(A) > 1:
    A.sort()
    for n in range(len(A)-1):
        A[n+1] = A[n+1]%A[0]
    A = [a for a in A if a != 0]
    
print(A[0])

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define BIGINF (int) 4e18 + 7
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF  (int)2e9 + 7
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

int N = 3005;

int main () {
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
   	int dp[N][N];
   	string s1, s2;
    cin >> s1;
    cin >> s2;
    int n1 = s1.length(), n2 = s2.length();
    vector<char> v;

    for (int i = 0; i <= n1; i++) {
    	dp[i][0] = 0;
    }
    for (int i = 0; i <= n2; i++) {
    	dp[i][0] = 0;
    }

    for (int i = 1; i <= n1; i++) {
    	for (int j = 1; j <= n2; j++) {
    		if (s1[i - 1] == s2[j - 1]) {
    			dp[i][j] = dp[i - 1][j - 1] + 1;
    		}
    		else {
    			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    		}
    	}
    }
    if (dp[n1][n2] == 0) cout << "";
    else {
    	int i = n1, j = n2;
    	while (dp[i][j] > 0) {
    		if (dp[i-1][j-1] == dp[i - 1][j] && dp[i-1][j - 1] == dp[i][j - 1] && dp[i][j] > dp[i - 1][j - 1]) {
    			i--;
    			j--;
    			v.push_back(s1[i]);
    		}
    		else {
    			if (dp[i - 1][j] > dp[i][j - 1])
    				i--;
    			else
    				j--;
    		}
    	}
    	int size = v.size();
    	for (int i = size - 1; i >= 0; i--) {
    		cout << v[i];
    	}
	}


    return 0;
}



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

#define SIZE 100
#define WMAX 100010
#define INF 1001000000

long long dp[SIZE + 1][WMAX + 1];
long long w[SIZE + 1] = {0}, v[SIZE + 1] = {0};

int main(){
  int N, W;
  cin >> N >> W;

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

  for (int i = 0; i <= SIZE; i++) {
    for (int j = 0; j <= WMAX; j++) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    for (int val = 0; val <= WMAX; val++) {
      if (v[i] <= val) {
        dp[i][val] = min(dp[i - 1][val], dp[i - 1][val - v[i]] + w[i]);
      } else {
        dp[i][val] = dp[i - 1][val];
      }
    }
  }
  long long ans = 0;
  for (int j = 0; j <= WMAX; j++) {
    if (dp[N][j] <= W) ans = j;
  }
  cout << ans << endl;
}


Measured memory_bytes: 79104
line = STDIN.gets.split(" ")
size = Array.new(2) { |i| i = line[i].to_i }

matrix = []

for i in 0..size[0] - 1 do
  line = STDIN.gets.split(" ")
  for j in 0..size[1] - 1 do
    # puts "i = #{i}, j = #{j}"
    line[j] = line[j].to_i
  end
  matrix << line
  # print matrix
end

for i in 0..size[0] - 1 do
  sum = 0
  matrix[i].each do |x|
    sum += x
  end
  matrix[i][size[1]] = sum
end

# print matrix, "\n"

sum_line = []
for j in 0..size[1] do
  sum = 0
  for i in 0..size[0] - 1 do
    # puts "i = #{i}, j = #{j}"
    sum += matrix[i][j]
    # puts "sum = #{sum}"
  end
  sum_line << sum
end
matrix << sum_line

# print matrix , "\n"

matrix.each do |x|
  output_line = ""
  puts x.join(" ")
end

Measured memory_bytes: 6128
#include<bits/stdc++.h>
#define maxn 105
#define inf 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mm(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const double eps = 1e-6;
const LL mod=1e9+7;
const LL INF=(LL)1e18;
using namespace std;
LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}
LL qpow(LL x,LL y){LL re=1,base=x%mod;while(y){if(y&1)re=(re*base)%mod;base=(base*base)%mod;y>>=1;}return re;}
template<typename T> inline void read(T &x){x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;}
inline void out(int x){if(x>9) out(x/10);putchar(x%10+'0');}
LL a[maxn];
LL lcm(LL a,LL b){
	return a/gcd(a,b)*b;
}
int main(){
//	freopen("input.txt","r",stdin);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	LL ans=1;
	for(int i=1;i<=n;i++) ans=lcm(ans,a[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll N;
  cin >> N;
  ll c=0;
  for(ll i=0;i*i<=N;i++){
    c = i;
  }
  ll key = c;
  ll ans = 0;
  for(ll i=1;i<=key;i++){
    if(N%i==0){
      ll tmp = (N/i)-1;
      if(tmp==0) continue;
      if(N/tmp == N%tmp){
        ans += (N/i);
        ans--;
        //cout << (N/i)-1 << endl;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long num0[222222],num1[222222],fa[222222],pa[222222],x,n,cur,ans;
struct cmp
{
	bool operator ()(const long long i,const long long j)
	{
		if (num0[i]*num1[j]!=num1[i]*num0[j]) return num0[i]*num1[j]>num1[i]*num0[j];
		return i>j;
	}
};
set<long long,cmp> s;
long long root(long long x)
{
	if (pa[x]!=x) pa[x]=root(pa[x]);
	return pa[x];
}
void Union(long long x,long long y)
{
	long long rx=root(x),ry=root(y);
	s.erase(s.find(rx));
	if (s.find(ry)!=s.end()) s.erase(s.find(ry));
	ans+=num1[ry]*num0[rx];
	pa[rx]=ry;num0[ry]+=num0[rx];num1[ry]+=num1[rx];  
	if (ry>1) s.insert(ry); 
}
int main()
{
	scanf("%lld",&n);
	for (long long i=2;i<=n;i++)
	{
		scanf("%lld",&fa[i]);
	}
	for (long long i=1;i<=n;i++)
	{
		pa[i]=i;
	}
	for (long long i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		if (!x) num0[i]++;
		else num1[i]++;
	}
	for (long long i=2;i<=n;i++) s.insert(i); 
	for (long long i=1;i<n;i++)
	{
		cur=*s.begin();
		Union(cur,fa[cur]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 16256
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	int A[13] = {0, 1,3,1,2,1,2,1,1,2,1,2,1};
	cout<< (A[a] == A[b] ?  "Yes": "No");
	return 0;
}

Measured memory_bytes: 256
N = list(map(int, input().split(' ')))

sub = N[1] - N[0]
calc = [N[0]]
for i in range(sub):
	calc.append(N[0] + i + 1)
	
count = 0
for i in range(len(calc)):
	if N[2] % calc[i] == 0:
		count += 1
		
print(count)

Measured memory_bytes: 7920
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int v ,e;
int sta[10001];
vector <int> gin[10001],gout[10001],ans;
queue <int> Q;

void toporogical_sort(){
  for(int i=0;i<v;i++)
    if(!gin[i].size())Q.push(i);
  
  while(!Q.empty()) {
    int t = Q.front(); Q.pop();
    ans.push_back(t);
 
    for(int i=0;i<gout[t].size();i++){
      int nx = gout[t][i];
      int size = gin[nx].size();
      for(int j=0;j<size;j++)
	if(gin[nx][j] == t){
	  gin[nx].erase(gin[nx].begin()+j);
	  break;
	}
      if(!gin[nx].size()) Q.push(nx);
    }
  }
}
 
 
int main() {
  cin >> v >> e;
   for(int i=0;i<e;i++) {
    int s,t;
    cin >> s >> t;
    gin[s].push_back(t);
    gout[t].push_back(s);
   }
  toporogical_sort();
  for(int i=ans.size()-1;i>=0;i--) cout << ans[i] << endl;
  return 0;
}



Measured memory_bytes: 4496
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int D;
vector<int> c(26);
vector<vector<int>> s;

int64_t calc_score(const vector<int>& t) {
  int64_t result = 0;
  vector<int> last(26, -1);
  rep(i, D) {
    const int j = t[i];
    result += s[i][j];
    last[j] = i;
    rep(k, 26) { result -= c[k] * (i - last[k]); }
  }
  return result;
}

int main() {
  cin >> D;

  rep(i, 26) { cin >> c[i]; }

  s.resize(D, vector<int>(26));
  rep(i, D) rep(j, 26) { cin >> s[i][j]; }

  vector<vector<int16_t>> last;
  vector<int> parent;
  vector<int> kind;

  using P = pair<int64_t, int>;
  priority_queue<P, vector<P>, greater<P>> q;

  last.push_back(vector<int16_t>(26, -1));
  parent.push_back(-1);
  kind.push_back(-1);
  q.push(P(0, 0));

  const int width = 800;
  rep(i, D) {
    priority_queue<P, vector<P>, greater<P>> nxt;

    while (!q.empty()) {
      int64_t z;
      int idx;
      tie(z, idx) = q.top();
      q.pop();

      int64_t penalty = 0;
      rep(j, 26) { penalty += c[j] * (i - last[idx][j]); }

      rep(j, 26) {
        int nidx = last.size();
        int64_t w = z + s[i][j] - penalty + c[j] * (i - last[idx][j]);
        nxt.push(P(w, nidx));
        if (nxt.size() > width) {
          nxt.pop();
        }

        last.push_back(last[idx]);
        last[nidx][j] = i;
        parent.push_back(idx);
        kind.push_back(j);
      }
    }

    q = move(nxt);
  }

  while (q.size() > 1) {
    q.pop();
  }

  int64_t score;
  int idx;
  tie(score, idx) = q.top();
  vector<int> sln;
  while (idx != 0) {
    sln.push_back(kind[idx]);
    idx = parent[idx];
  }
  rrep(i, D) { cout << sln[i] + 1 << "\n"; }
  cerr << score << "\n";

  return 0;
}

Measured memory_bytes: 710772
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

const int MAXN = 300000;

vector<int> A;

int ret[MAXN];

int N;

int main() {
	ios_base::sync_with_stdio(false);
	A.clear();
	cin >> N;
	int x;
	FOR (i, N) {
		cin >> x;
		A.pb(x);
	}
	sort(all(A));
	
	int n = A[A.sz - 1];
	int rr = -1, ret = -1;
	FOR (i, N - 1) {
		int val = min(A[i], n - A[i]);
		if (val > rr) {
			rr = val;
			ret = A[i];
		}
	}
	cout << n << " " << ret << endl;
	return 0;
}

Measured memory_bytes: 892
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let s: String = read();
    let c = s.chars().collect::<Vec<char>>();
    let mut exist = vec![0 ; 255];
    for ci in c {
        exist[ci as usize] = 1;
    }

    let a8 = 'a' as u8;
    for d in 0..26 {
        let idx = a8 + d;
        if exist[idx as usize] == 0 {
            println!("{}", (a8 + d) as char);
            return;
        }
    }
    println!("None");
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int N, K;
    cin >> N >> K;

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

    int ans;
    int m = N;
    while(true){
        bool fl = true;

        for(int i=0; i<K; i++){
            int t = m;
            while(t > 0){
                if((t - D[i]) % 10 == 0) fl = false;
                t = t / 10;
            }
        }
        if(fl){
            ans = m;
            break;
        }
        m++;
    }

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
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;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll A, B, M;
	cin >> A >> B >> M;
	Vec a(A), b(B);
	rep(i, A) cin >> a[i];
	rep(i, B) cin >> b[i];
	Vec c(M), d(M), e(M);
	rep(i, M) cin >> c[i] >> d[i] >> e[i];
	rep(i, M){
		c[i]--;
		d[i]--;
	}

	ll minA = LINF, minB = LINF;
	rep(i, A) chmin(minA, a[i]);
	rep(i, B) chmin(minB, b[i]);

	ll ans = minA + minB;
	rep(i, M){
		ll sum = a[c[i]] + b[d[i]];
		sum -= e[i];
		chmin(ans, sum);
	}
	co(ans);
 
	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>

using namespace std;

class Dice {
private:
	int faces[1 + 6] = { };
public:
	void read() {
		for (int i = 1; i <= 6; i++) {
			cin >> faces[i];
		}
	}

	void roll(int f) {
		roll(f, 1, 7 - f, 6);
	}

	void roll(int f1, int f2, int f3, int f4) {
		int tmp = faces[f1];
		faces[f1] = faces[f2];
		faces[f2] = faces[f3];
		faces[f3] = faces[f4];
		faces[f4] = tmp;
	}

	int get(int n) {
		return faces[n];
	}

	vector<int> containsAll(int n) {
		int tmp[6];
		int size = 0;
		for (int i = 1; i <= 6; i++) {
			if (n == faces[i]) {
				tmp[size] = i;
				size++;
			}
		}
		vector<int> vec(size);
		for (int i = 0; i < size; i++) {
			vec[i] = tmp[i];
		}
		return vec;
	}

	bool isEqual(Dice *dice) {
		for (int i = 1; i <= 6; i++) {
			if (this->faces[i] != dice->faces[i])
				return false;
		}
		return true;
	}
};

int main() {
	int n, topNum;
	vector<int> tops, fronts;

	cin >> n;
	Dice dice[n];
	dice[0].read();
	for (int i = 1; i < n; i++) {
		dice[i].read();
		tops = dice[i].containsAll(dice[0].get(2));
		fronts = dice[i].containsAll(dice[0].get(6));

		if (tops.size() == 0 || fronts.size() == 0)
			continue;
		int top = tops[0];
		for (int front : fronts) {
			if (top + front != 7) {
				topNum = dice[i].get(top);
				switch (front) {
				case 6:
					break;
				case 1:
					dice[i].roll(top);
					dice[i].roll(top);
					break;
				default:
					dice[i].roll(front);
					break;
				}

				for (int j = 0; j < 4; j++) {
					dice[i].roll(2, 3, 5, 4);
					if (dice[i].get(2) == topNum) {
						for (int k = 0; k < i; k++) {
							if (dice[k].isEqual(&dice[i])) {
								cout << "No" << endl;
								return 0;
							}
						}
					}
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3084
import java.util.*;
     
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int[][] game = new int[N][3];
    	int[] point = new int[N];
    	int flag = 0;
    	
    	for(int i = 0;i < N;i++){
    		for(int j = 0;j < 3;j++){
    			game[i][j] = sc.nextInt();
    		}
    	}
    	
    	for(int i = 0;i < 3;i++){
    		for(int j = 0;j < N;j++){
    			for(int k = 0;k < N;k++){
    				if(game[j][i] == game[k][i])
    					flag++;
    			}
    			if(flag == 1)
    				point[j] += game[j][i];
    			
    			flag = 0;
    		}
    	}
    	
    	for(int i = 0;i < N;i++){
    		System.out.println(point[i]);
    	}
    }
}

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

int main(void){
  int n,y;
  cin >> n >> y;
  int result10000 = -1,result5000 = -1, result1000 = -1;
  for(int i = 0; i <= n; i++){
    for(int j = 0; j+i <= n; j++){
      int c = n - (j + i);
      int total = 10000 * i + 5000 * j + 1000 * c;
      if(total == y){
        result10000 = i;
        result5000 = j;
        result1000 = c;
      }
    }
  }
cout << result10000 <<" " << result5000 <<" " << result1000 << "\n";
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
graph = Array.new(n)

n.times do |i|
  input = gets.split().map(&:to_i)
  tmp = []
  input[1].times do |j|
    tmp << input[j+2]-1
  end
  graph[i] = tmp
end

dist = Array.new(n, -1)
queue = []

dist[0] = 0
queue << 0

while !queue.empty?
  v = queue.shift
  graph[v].each do |i|
    next if dist[i] != -1
    dist[i] = dist[v] + 1
    queue << i
  end
end

dist.each_with_index do |i, index|
  puts "#{index+1} #{i}"
end


Measured memory_bytes: 6896
#include<stdio.h>
#include<math.h>
int main(){
    int a;
    scanf("%d",&a);
    while(a--){
        double x1,y1,x2,y2,x3,y3;
        scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
        double a1=2*(x2-x1);
        double b1=2*(y2-y1);
        double c1=x1*x1-x2*x2+y1*y1-y2*y2;
        double a2=2*(x3-x1);
        double b2=2*(y3-y1);
        double c2=x1*x1-x3*x3+y1*y1-y3*y3;
        double x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
        double y=(c1*a2-c2*a1)/(a1*b2-a2*b1);
        double r=hypot(x-x1,y-y1);
        printf("%.3lf %.3lf %.3lf\n",x,y,r);
    }
}


Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
ll dp[100100][13];

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w,0));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }
    vector<pair<int,int>> p1,p2;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(a[i][j] %2 == 1){
                if(j == w-1){
                    if(i == h-1) continue;
                    p1.push_back(make_pair(i+1,j+1));
                    p2.push_back(make_pair(i+2,j+1));
                    a[i][j]--;
                    a[i+1][j]++;
                }else{
                    p1.push_back(make_pair(i+1,j+1));
                    p2.push_back(make_pair(i+1,j+2));
                    a[i][j]--;
                    a[i][j+1]++;
                }
            }
        }
    }

    cout << p1.size() << endl;
    for (int i = 0;i < p1.size();++i) {
        cout << p1[i].first << " " << p1[i].second << " " << p2[i].first << " " << p2[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

const LL MOD = 1000000007LL;

LL row(const vector<int> &v){
    LL n = (int)v.size() - 1;
    LL res = 0;
    REP(i, n){
        LL k = i+1;
        LL w = v[i+1] - v[i];
        LL c = (k * (n-k+1)) % MOD;
        c = (c * w) % MOD;
        res = (res + c) % MOD;
    }
    return res;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(n);
    vector<int> y(m);
    REP(i, n)cin >> x[i];
    REP(i, m)cin >> y[i];
    cout << (row(x) * row(y)) % MOD << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
#define R(i,n) for(int i = 1; i<n; i++)
typedef long long ll;
using namespace std;

int main(){
  int w,h,n,x,y,a;
  cin >> w >> h >> n;
  vector<vector<int>> v(h,vector<int>(w,0));
  while(n--){
    cin >> x >> y >> a;
    if(a==1){
      r(i,h){
        r(j,x){
          v.at(i).at(j)=1;
        }
      }
    }
    if(a==2){
      r(i,h){
        for(int j = x;j<w;j++){
          v.at(i).at(j)=1;
        }
      }
    }
    if(a==3){
      r(i,y){
        r(j,w){
          v.at(i).at(j)=1;
        }
      }
    }
    if(a==4){
      r(j,w){
        for(int i = y;i<h;i++){
          v.at(i).at(j)=1;
        }
      }
    }
  }
  int count=0;
  r(i,h){
    r(j,w){
      if(v.at(i).at(j)==0)count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#A155C
import sys
from collections import Counter
n = int(sys.stdin.readline())
S = [sys.stdin.readline().rstrip() for _ in range(n)]
S = Counter(S)
max_cnt = S.most_common()[0][1]

ans = [key for key, value in S.items() if value==max_cnt]

for s in sorted(ans):
    print(s)


Measured memory_bytes: 43476
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll a,b;
  cin >> a >> b;
  if(max(a,b)<=9)cout << a*b << endl;
  else cout << -1 << endl;

}

Measured memory_bytes: 3612
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#include <limits>

using namespace std;
using ll = long long int;
ll inf = numeric_limits<ll>::max();


template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll g(ll A, ll B, ll C, ll x, ll y, ll z) {
  vector<ll> l = {x, y, z};
  ll ret = inf;
  sort(l.begin(), l.end());
  do {
    ret = min(ret, abs(A-l[0])+abs(B-l[1])+abs(C-l[2]));
  } while(next_permutation(l.begin(), l.end()));
  return ret;
}

ll f(ll N, ll A, ll B, ll C, vector<ll> &l, ll depth) {
  ll ans = inf;
  for(ll i=0; i<N; i++) {
    for(ll j=i+1; j<N; j++) {
      for(ll k=j+1; k<N; k++) {
	ans = min(ans, g(A, B, C, l[i], l[j], l[k])+depth*10);
      }
    }
  }
  if(N>3) {
    for(ll i=0; i<N; i++) {
      for(ll j=i+1; j<N; j++) {
	vector<ll> v;
	for(ll k=0; k<N; k++) {
	  if(k!=i and k!=j)
	    v.push_back(l[k]);
	}
	v.push_back(l[i]+l[j]);
	ans = min(ans, f(N-1, A, B, C, v, depth+1));
      }
    }
  }
  return ans;
}


void solve(long long N, long long A, long long B, long long C, std::vector<long long> l){
  std::cout << f(N, A, B, C, l, 0) << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  std::vector<long long> l(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&l[i]);
  }
  solve(N, A, B, C, std::move(l));
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int ati(string a) {
	int ret = 0;
	for (int i = 0; i < a.size(); i++) {
		ret *= 10;
		ret += a.at(i) - '0';
	}
	return ret;
}
int  mprimes(int k) {
	int i;
	for ( i = k; i > 1; i--) {
		int count = 0;
		for (int j = 2; j < i; j++) {
			if (i % j == 0)count++;
		}
		if (count == 0) break;
	}
	return i;
}
bool root(int k, vector<int>* p) {
	int pp = 0;
	int kk = k;
	for (int i = 2; i <= kk; i++) {
		int count = 0;
		while (k % i == 0) {
			count++;
			k /= i;
		}
		if (count)p->at(pp++) = count;
	}
	for (int i = 0; i < p->size(); i++) {
		if (p->at(i) % 2 != 0) return false;
	}
	return true;
}
int main() {
	string a, b;
	int k;
	cin >> a >> b;
	a += b;
	k = ati(a);
	vector<int> p(mprimes(k), 0);
	if (root(k, &p)) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 3648
#include <iostream>
#include <bits/stdc++.h>
#define scan(n)      scanf("%I64d",&n);
#define scan2(a,b)   scanf("%I64d%I64d",&a,&b);
#define scan3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c);
#define sc(n)        scanf("%c",&n);
#define sf(n)        scanf("%lf",&n);
#define ss(n)        scanf("%s",n);
#define forall(i,a,b)for(long long int i=a;i<b;i++)
#define all(a)       a.begin(), a.end()
#define pb           push_back
#define mp           make_pair
#define FAST_IO      ios_base::sync_with_stdio(false); cin.tie(NULL);
#define minimum(a)   *min_element(a.begin(),a.end())
#define maximum(a)   *max_element(a.begin(), a.end())
#define display(a)   for(auto i : a) cout<<i<<" ";
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
using namespace std;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
vector<ll> scanVector(ll n, vector<ll> &v)
{
  ll temp;
  for(ll i = 0; i < n ; i++)
  {
     cin>>temp;
     v.pb(temp);
  }
  return v;
}

void dfs(vector<ll> *adj, bool *visited, ll *dp, ll node)
{
    visited[node] = true;
    for(ll j = 0; j < adj[node].size(); j++)
    {
        if(visited[adj[node][j]] == false)
        {
            dfs(adj,visited,dp,adj[node][j]);
        }
        dp[node] = max(dp[node],1 + dp[adj[node][j]]);
    }
}
int main() {
    FAST_IO
    ll t;
    //cin>>t;
    t = 1;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        vector<ll> adj[100001];
        ll parent,child;
        for(ll i = 0; i < m ; i++)
        {
            cin>>parent>>child;
            adj[parent].push_back(child);
        }
        bool visited[100001] = {false};
        ll dp[100001]={0};
        for(ll i = 1; i <= n; i++)
        {
            if(visited[i] == false)
            {
                dfs(adj,visited,dp,i);
            }
        }
        ll longestPath = 0;
        //finding max value in dp
        for(ll i = 1; i <=n ; i++)
        {
            longestPath = max(longestPath,dp[i]);
        }
        cout<<longestPath<<endl;
    }
    return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> p;
typedef vector<p> vp;
const int INF=1e9;
int main(int argc,char const* argv[])
{
  int t[100005];
  int n;
  cin >> n;
  vi moneys;
  int tmp1=6;
  int tmp2=9;
  moneys.push_back(1);
  while(tmp1<=100000 || tmp2<=100000)
    {
      if(tmp1<=100000) moneys.push_back(tmp1);
      tmp1*=6;
      if(tmp2<=100000) moneys.push_back(tmp2);
      tmp2*=9;
    }
  sort(moneys.begin(),moneys.end(),greater<int>());
  for(int i=0;i<=100000;i++)
    {
      t[i]=INF;
    }
  t[0]=0;
  for(int i=0;i<moneys.size();i++)
    {
      for(int j=0;j+moneys[i]<=n;j++)
	{
	  t[j+moneys[i]]=min(t[j+moneys[i]],t[j]+1);
	}
    }
  cout << t[n] << endl;
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

char X, Y;

int main() {
  cin >> X >> Y;
  if (X < Y) puts("<");
  else if (X == Y) puts("=");
  else puts(">");
}












Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

map<ll,ll> M;

int main(){
  ll N,K,A[200007],S[200007],imos[200007],sum=0,C=0;
  cin >> N >> K;
  A[0]=0;
  S[0]=0;
  rep(i,N+5){
    imos[i]=INF;
  }
  Rep(i,0,N+1){
    if(i!=0){
      cin >> A[i];
      sum += A[i];
    }
    S[i] = sum;
    if(imos[i]!=INF){
      M[imos[i]]--;
    }
    if(i+K<=N+1){
      imos[i+K] = (S[i]-i)%K;
    }
    C+=M[(S[i]-i)%K];
    M[(S[i]-i)%K]++;
  }
  cout << C << endl;
}

Measured memory_bytes: 15872
s=input()
A1=0
A2=0
for i in range(len(s)):
    if s[i]=='A':
        A1=i
        break
    else:
        continue
for t in range(len(s)-1,1,-1):
    if s[t]=='Z':
        A2=t
        break
    else:
        continue
print(A2-A1+1)

Measured memory_bytes: 3512
#include <cstdio>

int main()
{
    char S[11];
    if (scanf("%s", S) == EOF) return -1;
    int answer = 0;
    int length = 0;
    for(int i = 0; i < 11 && S[i] != '\0'; i++) {
        if (S[i] == 'A' ||
            S[i] == 'C' ||
            S[i] == 'G' ||
            S[i] == 'T') {
            length++;
        } else {
            answer = answer < length ? length : answer;
            length = 0;
        }
    }
    answer = answer < length ? length : answer;
    printf("%d\n", answer);
}


Measured memory_bytes: 128
#include<iostream>  
#include<cstring>  
#include<string>  
#include<cstdio>  
#include<cmath>  
#include<vector>  
#include<queue>  
#include<algorithm>  
using namespace std;
#define inf 0x3f3f3f3f  
#define ll long long  
const int maxn = 1e5 + 500;
int main()
{
	int a, b;
	while (~scanf("%d%d", &a, &b)) {
		if (a > b)
			cout << a - 1 << endl;
		else
			cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

long long int a[3][100001];

bool hikaku(int a, int b) {
	int c = a % 10;
	int d = b % 10;
	if (c == 0) c = 10;
	if (d == 0) d = 10;
	return c < d;
}
bool zettai(int a, int b) {
	return a > b;
}

int main() {
	vector<int> a(5);
	for (int i = 0; i < 5; i++) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end(),hikaku);
	int sum = 0;
	for (int i = 1; i < 5; i++) {
		int b = a.at(i);
		if (b % 10 > 0) {
			b += (10 - (b % 10));
		}
		sum += b;
	}
	cout << sum + a.at(0) << endl;
}


Measured memory_bytes: 256