akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;
#define n_max 1000

int main()
{
    int N;
    int A_sum = 0, B_sum = 0;
    vector<int> a;

    cin >> N;
    
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    for(int i = 0; i < N; i++){
        //cout << a[i] << endl;
    }
    sort(a.begin(), a.end());

    for(int i = N - 1; i >= 0; i-=2) {
        A_sum += a[i];
        if((i-1) >= 0) {
            B_sum += a[i - 1];
        }
        //cout << A_sum << endl;
        //cout << B_sum << endl;
        //cout << a[i] << endl;
        //cout << a[i+1] << endl;
    }

    cout << A_sum - B_sum << endl;

    return 0;
}


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

vector<pair<int,int>> adj[100001];
int dist[100001];
bool ok[100001];

struct node{
    int l,r,d;
}query[200001];

void dfs(int x,int d){
    
    ok[x] = true;
    dist[x] = d;
    int sz = (int)adj[x].size();
    for(int i=0;i<sz;i++){
       
        int next = adj[x][i].first;
        if(!ok[next]){
            dfs(next,d+adj[x][i].second);
        }
    }
}
int main(int argc, const char * argv[]) {
    
    
    int n,m;
    
    scanf("%d %d",&n,&m);
    
    for(int i=0,x,y,z;i<m;i++){
        scanf("%d %d %d",&x,&y,&z);
        
        adj[x].push_back({y,z});
        adj[y].push_back({x,-z});
        query[i].l = x;
        query[i].r = y;
        query[i].d = z;
    }
    
    for(int i=1;i<=n;i++){
        if(!ok[i]){
            dfs(i,0);
        }
    }
    
    for(int i=0;i<m;i++){
        if(query[i].d != dist[query[i].r]-dist[query[i].l]){
            printf("No\n");
            return 0;
        }
    }
    
    printf("Yes\n");
    
    return 0;
}


Measured memory_bytes: 14464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  1e4 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x ,y, k , d , Q , ans ; string s,t;
ll dp[2][101][MAX];
int K[MAX];

ll solve(int i , int cur , bool tooksmaller){

   
    if(i == n)
        return cur == 0;

    ll &ret = dp[tooksmaller][cur][i];
    if(~ret)
        return ret;

    int sz = (tooksmaller? 9 : K[i]);

    ret = 0 ;

    for(int j = 0 ; j <= sz ; ++j)
        ret = (ret%MOD + solve(i + 1,(cur + j)%d,tooksmaller || (j < K[i]))%MOD)%MOD;

    return ret;

}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//   freopen("test.in","r",stdin);


    cin>>s>>d;

    n = (int)s.length();

    for(int i = 0 ; i < n ; ++i)
        K[i] = s[i] - '0';

    for(int i = 0 ; i < d; ++i)
        for(int j = 0 ; j < n ; ++j)
            for(int k = 0 ; k < 2 ; ++k)
                dp[k][i][j] = -1;

    cout<<(solve(0,0,0) - 1 + MOD)%MOD<<'\n';

  

    return 0;
}


Measured memory_bytes: 16768
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,a,b) for(int i = a;i <= b;i++)

int s_cmp(const void *a,const void *b){
  return strcmp(a,b);
}

int main(void){
  //acquisition of data
  int n; scanf("%d",&n);
  char s[n+1][11]; rep(i,0,n-1){scanf("%s",&s[i]);}
  //sort of data
	qsort(s,n,sizeof s[0],s_cmp);
  //output of result
  int cnt = 1;
  rep(i,1,n-1){
    if(strcmp(s[i-1],s[i]) != 0){
      cnt ++;
    }
  }
  printf("%d",cnt);
  return 0;
}


Measured memory_bytes: 5700
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  bool can = true;
  REP(i, N) {
    if (A[i] % 2 == 0) {
      if (A[i] % 3 != 0 && A[i] % 5 != 0) {
        can = false;
        break;
      }
    }
  }
  if (can == true) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
  return 0;
}


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

int main(){
    long long N, D;
    cin >> N >> D;
    vector<long long>X(N), Y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> X.at(i) >> Y.at(i);
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (X.at(i) * X.at(i) + Y.at(i) * Y.at(i) <= D * D)
        {
            ans++;
        }
    }
    cout << ans;
} 

Measured memory_bytes: 6420
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0){
    c -= b;
    if(c <= 0){
      cout << "Yes" << endl;
      break;
    }
    a -= d;
    if(a <= 0){
      cout << "No" << endl;
      break;
    }

  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3612
#include <stdio.h>

int main()
{
   int N,x;
    scanf("%d",&N);
    
    if(N%1000==0)
    {
        printf("0");
    }
    
    else
    {
        x=(N/1000)+1;
        printf("%d",((1000*x)-N));
    }
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char x, y;
    cin >> x >> y;
    if (x < y)
    {
        cout << "<" << endl;
    }
    else if (x == y)
    {
        cout << "=" << endl;
    }
    else
    {
        cout << ">" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	cin>>t;
	cout<<t+t*t+t*t*t;
}




	

		

Measured memory_bytes: 3656
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    A = deque(sorted(A, reverse=True))

    q = deque([A.popleft()])
    # print(q)
    ans = 0
    while A:
        ans += q.popleft()
        a = A.popleft()
        q.extend([a, a])
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 32440
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
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; }

#define MAX 100000

vector<int> G[MAX];
int N;
bool seen[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev){
  seen[current] = true;
  prenum[current] = timer;
  lowest[current] = timer;
  timer++;

  for(int next : G[current]){
    if(!seen[next]){
      parent[next] = current;
      dfs(next, current);
      chmin(lowest[current], lowest[next]);
    }
    else if(next != prev){
      chmin(lowest[current], prenum[next]);
    }
  }
}

int main(){
  int e;
  cin >> N >> e;
  rep(i, e){
    int s, t;
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  timer = 1;
  dfs(0, -1);

  set<int> ap;
  int np = 0;
  REP(i, 1, N-1){
    int p = parent[i];
    if(p == 0) np++;
    else if(prenum[p] <= lowest[i]){
      ap.insert(p);
    }
  }
  if(np > 1) ap.insert(0);
  for(auto x : ap) cout << x << endl;

  return 0;
}







Measured memory_bytes: 6908
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = 0;
      if(b<=9) c = a*10+b;
      else if(b <= 99) c = a*100+b;
      else if(b == 100) c = a*1000+100;
      
      int d = (int) Math.sqrt(c);
      
      if(d*d == c) System.out.println("Yes");
      else System.out.println("No");
    }
}

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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int a, b; cin >> a >> b;

  if (a <= 8 && b <= 8) cout << "Yay!" << "\n";
  else cout << ":(" << "\n";
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int a, b;
    cin >> a >> b;
    if(a<=9 && b<=9) cout << a*b << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>

static const int PARM_MIN = 1;
static const int PARM_MAX = 10000;

bool checkInputParameter(const int& val)
{
    if (PARM_MIN <= val && val <= PARM_MAX)
        return true;
    
    return false;
}

void dispValSmaller(const int& min, const int& mid, const int& max)
{
    std::cout << min << " " << mid << " " << max << std::endl;
}

int main(int argc, char* argv[])
{
    int a, b, c;
    std::cin >> a;
    std::cin >> b;
    std::cin >> c;


    if (!checkInputParameter(a)
     || !checkInputParameter(b)
     || !checkInputParameter(c))
        goto END;

    if (a > b) {
        if (b > c) {
            dispValSmaller(c, b, a);
        } else if(a > c) {
            dispValSmaller(b, c, a);
        } else {
            dispValSmaller(b, a, c);
        }
    } else {
        if (a > c) {
            dispValSmaller(c, a, b);
        } else if (b > c) {
            dispValSmaller(a, c, b);
        } else {
            dispValSmaller(a, b, c);
        }
    } 
    
END:
    return 0;
}


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


int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<ll> ryuka(N+1);
    ryuka.at(0) = 2;
    ryuka.at(1) = 1;
    for(int i = 2; i <= N; i++){
        ryuka.at(i) = ryuka.at(i-1) + ryuka.at(i-2);
    }
    cout << ryuka.at(N);
}


Measured memory_bytes: 256
local mod = 1000000007
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local n = io.read("*n")
local t = {io.read("*n")}
for i = 2, n do
  t[i] = io.read("*n")
end

local curlen = 0
local ret = 0
do
  curlen = t[n - 1] - t[1]
  ret = badd(ret, bmul(curlen, modinv(2)))
end
for i_range = 2, n - 1 do
  curlen = curlen + t[n] - t[i_range] - (t[n] - t[n - i_range])
  curlen = curlen % mod
  local a = bmul(i_range, i_range + 1)
  ret = badd(ret, bmul(curlen, modinv(a)))
end
for i_range = 1, n - 1 do
  ret = badd(ret, bmul(modinv(i_range), t[n] - t[n - i_range]))
end
for i = 2, n - 1 do
  ret = bmul(ret, i)
end
print(ret)


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int n;long A[size];
long count(int x){
    long a[n];
    rep(i,0,n) a[i]=A[i];
	long count=0;long del=0;
	rep(i,0,n){
		a[i]+=del;
		if(i%2==x){
			if(a[i]>0) continue;
			del+=1-a[i];count+=1-a[i];
			a[i]=1;
		}else{
			if(a[i]<0) continue;
			del-=1+a[i];count+=1+a[i];
			a[i]=-1;
		}
	}return count;
}
int main(){
	cin>>n;
	long sum=0;long a;
	rep(i,0,n){
		cin>>a;sum+=a;
		A[i]=sum;
	}
	cout<<min(count(0),count(1))<<endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

typedef long long ll;

int main() {
    ll cnt = 0;
    ll N, D;
    cin >> N >> D;
    rep(i, N) {
        ll X, Y;
        cin >> X >> Y;
        if (X * X + Y * Y <= D * D) {
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3632
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

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

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

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

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

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

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

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

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

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

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

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

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, K := sc.nextInt(), sc.nextInt()
	R, S, P := sc.nextInt(), sc.nextInt(), sc.nextInt()
	T := sc.nextRuneSlice()
	winMap := make(map[rune]rune)
	winMap['r'] = 'p'
	winMap['s'] = 'r'
	winMap['p'] = 's'
	record := make([]rune, N)
	ans := 0
	for i, r := range T {
		win := winMap[r]
		if K <= i && record[i-K] == win {
			record[i] = 'x'
		} else {
			record[i] = win
			if win == 'r' {
				ans += R
			} else if win == 'p' {
				ans += P
			} else {
				ans += S
			}
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 1792
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

struct Solver {
    // len[v]: 点 v から出る最長のパスの長さ
    len: Vec<usize>,
    // next[v]: 点 v から出る最長のパスの次の点
    next: Vec<usize>,
    N: usize,
    G: Vec<Vec<usize>>,
}

impl Solver {
    fn dfs(&mut self, u: usize) -> usize {
        let mut max_len = 0;

        if self.len[u] != std::usize::MAX {
            return self.len[u];
        }

        for i in 0..self.G[u].len() {
            let v = self.G[u][i];

            let len = self.dfs(v) + 1;
            if max_len < len {
                max_len = len;
                self.next[u] = v;
            }
        }

        self.len[u] = max_len;
        max_len
    }

    fn run(mut self) {
        for v in 0..self.N {
            self.dfs(v);
        }

        let m = (0..self.N).map(|v| self.len[v]).max().unwrap();
        println!("{}", m);
    }
}

fn main() {
    let (N, M) = read!(usize, usize);
    let E = read![usize, usize; M];

    let mut G = vec![vec![]; N];
    for (u, v) in E {
        G[u - 1].push(v - 1);
    }

    Solver {
        N: N,
        G: G,
        len: vec![std::usize::MAX; N],
        next: vec![0; N],
    }
    .run()
}


Measured memory_bytes: 17276
w,x[31],a,b;main(i){for(scanf("%d%*d",&i);w++,i--;)x[w]=w;for(;~scanf("%d,%d",&a,&b);x[b]=i)i=x[a],x[a]=x[b];for(i=1;i<w;)printf("%d\n",x[i++]);exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

struct UF{ //O(loga(n))
    int n;
    int m;
    vi d, r;
    UF(int n) : n(n), m(n), d(n, -1), r(n, 0){};
    int root(int i){
        if(d[i] < 0) return i;
        return d[i] = root(d[i]);
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return false;
 
        if(r[x] < r[y]) swap(x, y);
        else if(r[x] == r[y]) r[x]++;
        d[x] += d[y];
        d[y] = x;
        --m;
        return true;
    }
    int size(int i){
        return -d[root(i)];
    }
    int size() {
        return m;
    }
};


int main(){
    int n, m;
    cin >> n >> m;
    UF uf(n);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        uf.unite(a, b);
    }
    cout << uf.size() << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
using namespace std;
typedef long long ll;


int main(){
	int n;
	cin>>n;
	int c=0;
	REP(i,1,(n/2)+n%2){
		int c2=n-i;
		if(i!=c2)c++;
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int b,c,x[1001],X[1001],i;
	char a[1001][1001];
	for(i=0;i<9;i++){
		scanf("%s",a[i]);
		scanf("%d %d",&b,&c);
		x[i]=0;
		X[i]=0;
		x[i]=b+c;
		X[i]=b*200+c*300;
	}
	for(i=0;i<9;i++){
		printf("%s %d %d\n",a[i],x[i],X[i]);
	}
	return 0;
}

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

#define loop(i, n) for(int i = 0; i < n; i++)
#define sloop(i, s, n) for (int i = s; i < n; i++)
#define rloop(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size(), mx = INT_MIN;
    loop(mid, n/2) {
        int next_start = mid, count = 0;
        for(int i = 0; i < mid; i++) {
            if(s[i] == s[next_start]) {
                count++;
                next_start++;
            } else {
                mx = max(mx, count);
                break;
            }
            // cout << s[i] << " " << s[next_start] << " " << count << endl;
        }
        mx = max(mx, count);
        // cout << mid << " " << mx << endl;
    }
    cout << 2*mx << endl;
    return 0;
}


Measured memory_bytes: 3584
n = int(input())
#n = int(lines.pop())

dictionary = dict()
for i in range(n):
	command,data = input().split()
	#command,data = lines.pop().split()
	if command == 'insert':
		dictionary[data] = 1
	else:
		if data in dictionary:
			print('yes')
		else:
			print('no')

Measured memory_bytes: 37384
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

a.sort()
z = 1
for j in range(n-1):
    if a[j] < a[j+1]:
        z += 1
    elif a[j] == a[j+1]:
        z += 0

print(z)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	long long int n, a[10000];
	long long int min, max, sum=0;
	int i, j;
	
	scanf("%lld", &n);
	
	for(i=0; i<n; i++){
		scanf("%lld", &a[i]);
		sum = sum+a[i];
		min = a[0];
		max = a[0];
		for(j=0; j<n; j++){
			if(min >= a[j]){
				min = a[j];
				}
		}
		for(j=0; j<n; j++){
			if(max <= a[j]){
				max = a[j];
				}
		}
	}
	
	printf("%lld %lld %lld\n", min, max, sum);
	 
	
	return 0;
}

Measured memory_bytes: 676
#include <stdio.h>
#include <math.h>

int main()
{
	int i, N, s[2], t[2], x[1001], y[1001], r[1002];
	scanf("%d %d %d %d", &(s[0]), &(s[1]), &(t[0]), &(t[1]));
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d %d %d", &(x[i]), &(y[i]), &(r[i]));
	
	int j;
	long double tmp, time[1002][1002] = {};
	for (i = 1; i < N; i++) {
		for (j = i + 1; j <= N; j++) {
			tmp = sqrt((long double)(x[i] - x[j]) * (x[i] - x[j]) + (long double)(y[i] - y[j]) * (y[i] - y[j]));
			if (tmp < (long double)(r[i] + r[j])) tmp = 0.0;
			else tmp -= (long double)(r[i] + r[j]);
			time[i][j] = tmp;
			time[j][i] = tmp;
		}
	}
	for (i = 1; i <= N; i++) {
		tmp = sqrt((long double)(x[i] - s[0]) * (x[i] - s[0]) + (long double)(y[i] - s[1]) * (y[i] - s[1]));
		if (tmp < (long double)r[i]) tmp = 0.0;
		else tmp -= (long double)r[i];
		time[i][0] = tmp;
		time[0][i] = tmp;
		tmp = sqrt((long double)(x[i] - t[0]) * (x[i] - t[0]) + (long double)(y[i] - t[1]) * (y[i] - t[1]));
		if (tmp < (long double)r[i]) tmp = 0.0;
		else tmp -= (long double)r[i];
		time[i][N+1] = tmp;
		time[N+1][i] = tmp;
	}
	time[0][N+1] = sqrt((long double)(s[0] - t[0]) * (s[0] - t[0]) + (long double)(s[1] - t[1]) * (s[1] - t[1]));
	time[N+1][0] = time[0][N+1];
	
	int u, w, flag[1002] = {};
	long double min[1002];
	for (i = 1, min[0] = 0.0; i <= N + 1; i++) min[i] = 1e+100;
	while (flag[N+1] == 0) {
		for (u = 0, tmp = 1e+100; u <= N + 1; u++) {
			if (flag[u] == 0 && min[u] < tmp) {
				tmp = min[u];
				w = u;
			}
		}
		flag[w] = 1;
		for (u = w, w = 1; w <= N + 1; w++) {
			if (min[u] + time[u][w] < min[w]) min[w] = min[u] + time[u][w];
		}
	}
	
	printf("%.10Lf\n", min[N+1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 17844
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF=1e18+1;
const int mod = 1000000007;

struct Unionfind{
  vector<int>d;
  Unionfind(int n):d(n,-1){}
  int root(int x){
    if(d[x]<0){return x;}
    return d[x]=root(d[x]);
  }
  bool unite(int x,int y){
    x=root(x);y=root(y);
    if(x==y){return false;}
    if(d[x]>d[y]){swap(x,y);}
    d[x]+=d[y];
    d[y]=x;
    return true;
  }
  bool same(int x,int y){return root(x)==root(y);}
  int size(int x){return -d[root(x)];}
};

int main(){
  int N,M;
  cin>>N>>M;
  Unionfind uf(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    uf.unite(a,b);
  }
  int64_t cnt=0;
  int x=0;
  for(int i=0;i<N;i++){
    if(!uf.same(i,x)){uf.unite(i,x);cnt++;}
  }
  cout<<cnt<<endl;
  return 0;                       
}

Measured memory_bytes: 3784
#include<stdio.h>
int main()
{
    int sec, h, tsag, second, min;
    scanf("%d",&sec);
    h=sec/3600;
    tsag=sec-(h*3600);
    min=tsag/60;
    second=tsag-(60*min);
    printf("%d:%d:%d\n",h ,min, second);
}


Measured memory_bytes: 2084
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pair;
ll inf = 1e10;
int MAX_V;

ll V, E;
vector<Pair> G[100010];
ll d[100010];

void dijkstra(ll s) {
    priority_queue<Pair, vector<Pair>, greater<Pair>> que;
    fill(d, d + V, inf);
    d[s] = 0;
    que.push(Pair(0, s));
    
    while (!que.empty()) {
        Pair p = que.top();
        que.pop();
        
        ll v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            Pair e = G[v][i];
            if (d[e.first] > d[v] + e.second) {
                d[e.first] = d[v] + e.second;
                que.push(Pair(d[e.first], e.first));
            }
        }
    }
}

int main() {
    cin >> V;
    for (int i = 0; i < V; i++) {
        int a, et;
        cin >> a >> et;
        for (int j = 0; j < et; j++) {
            int b;
            ll r;
            cin >> b >> r;
            G[a].emplace_back(b, r);
            //G[b].emplace_back(a, r);
        }
    }

    dijkstra(0);
    for (int i = 0; i < V; i++) {
        cout << i << " " << d[i] << endl;
    }

}


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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define x first
#define y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 ) a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 ) return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 ) return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
   return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
   if ( x == 1 )
	   return 0;
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
		   return 0;
	return 1;
}

const int MAXN = 2e5 + 10;

char c;

int main()
{
   ios_base::sync_with_stdio( false );
   cin.tie( 0 );
   
	cin >> c;
	cout << ( char )( ( int )c + 1 ) << "\n";

   return 0;
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2018/10/05
 *      Author: londo
 */


#include<stdio.h>

char change(char ch){
	if(ch=='1')return '9';
	if(ch=='9')return '1';
	else return ch;
}

int main(){
	char buf[3]; scanf("%s",buf);

	printf("%c%c%c\n",change(buf[0]),change(buf[1]),change(buf[2]));
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll n,a[1<<18];

int main(){
	cin>>n;
	ll s=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		s+=a[i];
	}
	ll minx=s,sum=0;
	for(int i=1;i<=n;i++){
		sum+=a[i];
		minx=min(minx,abs(sum-(s-sum)));
	}
	cout<<minx<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    long long int N;
    cin >> N;
    long long int bars[N];
    
    long long int x;
    long long int total = 0;
    for (int i =0; i < N; i++) {
        cin >> x;
        total += x;
        bars[i] = x;
    }
    
    long long int r_total = 0;
    long long int min;
    for (int i = 0; i < N - 1; i++) {
        r_total += bars[i];

        if ((total - r_total) == r_total) {
            cout << "0" << endl;
            return 0;
        }
        if (i == 0)
            min = abs((total - r_total) - r_total);
        else
            if (min > abs((total - r_total) - r_total))
                min = abs((total - r_total) - r_total);
    }
    
    cout << min << endl;
    
    return 0;
}

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

int main() {
	char b;
	cin >> b;
	if (b == 'A') {
		cout << 'T' << endl;
	}
	else if (b == 'T') {
		cout << 'A' << endl;
	}
	else if (b == 'C') {
		cout << 'G' << endl;
	}
	else if (b == 'G') {
		cout << 'C' << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main(){
		int h,w,a[55][55]={};
		string s[55];
		cin>>h>>w;
		for(int i=0;i<h;i++){
			cin>>s[i];
		}
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(s[i-1][j-1]=='#'){
					a[i-1][j-1]++;
					a[i-1][j]++;
					a[i-1][j+1]++;
					a[i][j+1]++;
					a[i][j-1]++;
					a[i+1][j+1]++;
					a[i+1][j]++;
					a[i+1][j-1]++;
				}
			}
		}
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(s[i-1][j-1]=='#'){
					cout<<"#";
				}
				else{
					cout<<a[i][j];
				}
			}
			cout<<endl;
		}
      return(0);
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  string s;
  cin >> s;
  for (ll i = 0; i < sz(s);i+=2){
    cout << s[i];
  }
  cout << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (auto& e : s) {
    cin >> e;
    reverse(e.begin(), e.end());
    e.insert(e.end() - 1, '`');
  }
  sort(s.begin(), s.end());

  vector<vector<bitset<27>>> v;
  for (const auto& e : s) {
    vector<bitset<27>> ve(e.size() + 1);
    for (int i = e.size() - 1; i >= 0; i--) {
      ve[i][e[i] - '`'] = true;
      ve[i] |= ve[i + 1];
    }
    v.push_back(ve);

    // cerr << e << endl;
  }

  ll r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int ni = s[i].size(), nj = s[j].size();
      if (!(ni <= nj && s[i].substr(0, ni - 2) == s[j].substr(0, ni - 2))) break;
      if (v[j][ni - 2][s[i].back() - '`']) {
        r++;
        // cerr << s[i] << ' ' << s[j] << endl;
      }
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 27316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int a;
    cin>>a;
    if(a<1200){cout<<"ABC"<<endl;}
    else if(a<2800){cout<<"ARC"<<endl;}
    else{cout<<"AGC"<<endl;}
}

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

#define pi pair<int, int>

const int N = 1e3 + 10;
string s[N];
int h, w;
const int INF = 1e9 + 2137;
unordered_map<int, int> dist;

int koszt(pi ruch) {
	if(ruch == make_pair(-1, 0) || ruch == make_pair(1, 0) || ruch == make_pair(0, -1) || ruch == make_pair(0, 1))
		return 0;
	else
		return 1;
}

bool check(pi v) {
	if(v.first < 0 || v.second < 0 || v.first >= h || v.second >= w)
		return false;
	if(s[v.first][v.second] == '#')
		return false;
	return true;
}

int create(pi v) {
	int numer = v.first * w + v.second + 1;
	return numer;
}

void djikstra(pi src) {
	set<pair<int, pi>> setds;
	for(int i=0; i<h; i++) {
		for(int j=0; j<w; j++)
			dist[create({i, j})] = INF;
	}
	setds.insert({0, src});
	dist[create(src)] = 0;
	while(!setds.empty()) {
		pair<int, pi> tmp = *(setds.begin());
		setds.erase(setds.begin());
		pi u = tmp.second;
		
		for(int i=-2; i<=2; i++) {
			for(int j=-2; j<=2; j++) {
				if(i == j && i == 0)
					continue;
				int weight = koszt({i, j});
				pi v = make_pair(u.first+i, u.second+j);
				if(!check(v))
					continue;
				if(dist[create(v)] > dist[create(u)] + weight) {
					if(dist[create(v)] != INF)
						setds.erase(make_pair(dist[create(v)], v));
					dist[create(v)] = dist[create(u)] + weight;
					setds.insert(make_pair(dist[create(v)], v));
				}
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>h>>w;
	int ch, cw, dh, dw;
	cin>>ch>>cw>>dh>>dw;
	for(int i=0; i<h; i++)
		cin>>s[i];
	pi start = make_pair(ch-1, cw-1);
	pi meta = make_pair(dh-1, dw-1);
	djikstra(start);
	int wynik = -1;
	if(dist[create(meta)] != INF)
		wynik = dist[create(meta)];
	cout<<wynik;
}


Measured memory_bytes: 43884
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 998244353;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
bool solve(){
	ll n;cin>>n;
	map<ll,ll>mp;
	ll sum=0;
	rep(i,n){
		ll a;cin>>a;
		mp[a]++;
		sum+=a;
	}
	
	ll q;cin>>q;
	rep(i,q){
		ll b,c;cin>>b>>c;
		sum-=mp[b]*b;
		sum+=mp[b]*c;
		mp[c]+=mp[b];
		mp[b]=0;
		cout<<sum<<endl;
	}
  	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(15);
  solve();
}


Measured memory_bytes: 9428
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
    int N ;
    int sum = 0;
    cin >> N;
    for(int i=1; i <=N; i++){
        sum +=i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main  {
   public static void main(String[] args)  {
      Scanner sc = new Scanner(System.in);
      
      int n = sc.nextInt();
      int k = sc.nextInt();
      
      int a[] = new int[n];
      
      for (int h = 0; h < n; h++) {
         a[h] = 0;
      }
      
      for (int i = 0; i < k; i++) {
         int d = sc.nextInt();
         for (int j = 0; j < d; j++) {
            int aa = sc.nextInt();
            a[aa-1] = 1;
         }
      }
      
      int count = 0;
      
      for (int l = 0; l < n; l++) {
         if (a[l] == 0) {
            count++;
         }
      }
      
      System.out.println(count);
   }
}


Measured memory_bytes: 46396
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b, c, x;
    while(1){
        cin >> n >> a >> b >> c >> x;
        if(n + a + b + c + x == 0) break;
        vector<int> y(n);
        rep(i, 0, n){
            cin >> y[i];
        } 
        int ans = 0;
        int idx = 0;
        for(int i = 0; i <= 10000; i++){
            if(x == y[idx]){
                idx++;
            }
            if(idx == n){
                cout << i << endl;
                break;
            }
            x = (a * x + b) % c;            
            if(i == 10000){
                cout << -1 << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 3104
N = int(input())
S = list(input())

#Wを全部右に寄せる
sW = 0
sR = 0
fW = N
fR = N-1
res = 0

while True:
  for i in range(sW,N):
    if S[i]=="W":
      fW = i
      break
  for i in range(sR,N):
    if S[N-i-1]=="R":
      fR = i
      break
  if fW<N-fR-1:
    S[fW] = "R"
    S[N-fR-1] = "W"
    sW = fW
    sR = fR
    res += 1
  else:
    break
    
print(res)

Measured memory_bytes: 10788
#include <bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
using ll = long long;
const int N = 2e5 + 15;
const int inf = 2e9;
vector<int> g[N];
vector<int> dp(N, inf), ans(N, 1), val(N);

void dfs(int u, int par) {
	int j = lower_bound(dp.begin(), dp.end(), val[u]) - dp.begin();
	int prev = dp[j];
	dp[j] = val[u];
	ans[u] = max(ans[par], j);
	for (int v : g[u]) {
		if (v != par) {
			dfs(v, u);
		}
	}
	dp[j] = prev;
}

int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> val[i];
	int u, v;
	for (int i = 1; i < n; ++i) {
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dp[0] = -inf;
	dfs(1, 0);
	for (int i = 1; i <= n; ++i) {
		cout << ans[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 30828
#include<iostream>

int main()
{
    int N;
    std::cin>>N;
    N--;
    int B[110];
    int A[110];
    int ans = 0;
    for(int i=0;i<N;i++)std::cin>>B[i];

    A[0] = B[0];
    for(int i=0;i<N-1;i++){
        if(B[i]<B[i+1])A[i+1] = B[i];
        else A[i+1] = B[i+1];
    }
    A[N] = B[N-1];
    for(int i=0;i<=N;i++)ans += A[i];
    std::cout<<ans<<std::endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200010;
int n, a[maxn], v[maxn];
ll ans;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if ((i == 1 && a[i]) || (i != 1 && a[i] > a[i - 1] + 1)) {
			printf("-1"); return 0;
		}
	}
	for (int i = 1; i <= n; ++i)
		v[i - a[i]] = a[i];
	for (int i = 1; i <= n; ++i) ans += v[i];
	printf("%lld", ans);
}

Measured memory_bytes: 1792
N,W = list(map(int, input().split()))
w_0 = []
w_1 = []
w_2 = []
w_3 = []
v = []
w = 0
w_count = [0]*4
for _ in range(N):
    a,b = list(map(int, input().split()))
    if w == 0:
        w = a
        w_0.append(b)
    else:
        if a == w:
            w_0.append(b)
        elif a == w+1:
            w_1.append(b)
        elif a == w+2:
            w_2.append(b)
        elif a == w+3:
            w_3.append(b)
    w_count[a-w] += 1

w_0.sort(reverse=True)
w_1.sort(reverse=True)
w_2.sort(reverse=True)
w_3.sort(reverse=True)
ans = 0

for i in range(w_count[0]+1):
    for j in range(w_count[1]+1):
        for k in range(w_count[2]+1):
            for l in range(w_count[3]+1):
                if W >= w * i + (w+1) * j + (w+2) * k + (w+3) * l:
                  
                    S = sum(w_0[:i])+sum(w_1[:j])+sum(w_2[:k])+sum(w_3[:l])
                    ans = max(ans,S)

print(ans)




# dp = [[0]*(W+1) for _ in range(N+1)]

# for i in range(N):
#     for j in range(W+1):
#         if j - w[i] < 0:
#             dp[i+1][j] = dp[i][j]
#         else:
#             dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + v[i])

# k = max(dp)
# print(max(k))

Measured memory_bytes: 3064
N=int(input())
 
i=0
sortedSet={}
while i<N:
  temp=''.join(sorted(input()))
  
  if temp in sortedSet:
    sortedSet[temp]=sortedSet[temp]+1
  else:
    sortedSet[temp]=1
  i=i+1

  
result=0
for v in sortedSet.values():
  result=int(result+v*(v-1)/2)
 
print(result)

Measured memory_bytes: 17852
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;

typedef pair<int,int>P;

struct edge{
	int from;
	int to;
};

const int MAX_N = 100;

vector<edge> G[MAX_N];
bool flag[MAX_N];
P res[MAX_N];
int t = 1;

void dfs(int x)
{
	res[x].first = t++;
	flag[x] = true;
	for(int i=0;i<G[x].size();i++){
		edge e = G[x][i];
		if(!flag[e.to]){
			dfs(e.to);
		}
	}
	res[x].second = t++;
}

int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int id,m;
		cin >> id;
		cin >> m;
		for(int j=0;j<m;j++){
			edge e;
			int end;
			cin >> end;
			e.from = id-1;
			e.to = end-1;
			G[id-1].push_back(e);
		}
	}
	fill(flag,flag+n,false);
	int time=0;
	for(int i=0;i<n;i++){
		if(!flag[i]){
			dfs(i);
		}
	}		
	for(int i=0;i<n;i++){
		cout << i+1 << " " << res[i].first << " " << res[i].second << "\n";
	}
}

Measured memory_bytes: 3068
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[0] == s[1] and s[1] != s[2] and s[2] == s[3])puts("Yes");
    else puts("No");
}

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

struct UnionFind{
  vector<int> Par;

  //N個の独立した根として初期化
  UnionFind(int N) : Par(N) {
    for(int i = 0; i < N; i++) Par[i] = i;
  }

  //どこの根に属するか得る再帰関数
  int root(int X){
    if( Par.at(X) == X ) return X;
    else return Par.at(X) = root(Par.at(X));
  }

  //XとYが同じ根に属するか判定
  bool same(int X, int Y){
    return root(X) == root(Y);
  }

  //XとYの木を合体
  void unite(int X, int Y){
    X = root(X);
    Y = root(Y);
    if( X == Y ) return;
    Par.at(X) = Y;
  }
};

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i);

  UnionFind T(N);

  for( int i = 0; i < M; i++ ){
    int X, Y;
    cin >> X >> Y;
    X--;
    Y--;
    T.unite(X, Y);
  }

  int ans = 0;
  for( int i = 0; i < N; i++ ){
    if( T.same(i, A.at(i)-1) ) ans++;
  }
  cout << ans << endl;


}

Measured memory_bytes: 1792
import math
n,d=map(int,input().split())
arr=[]
for i in range(n):
    x=list(map(int,input().split()))
    arr.append(x)

def solve(arr,n,d):
    count=0
    for i in arr:
        s=math.sqrt(i[0]**2+i[1]**2)
        if s<=d:
            count+=1
    return count
print(solve(arr,n,d))

Measured memory_bytes: 45472
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  int ans = 0;
  rep(d, n){
    vector<string> now(n);
    rep(i, n){
      rep(j, n){
        now.at(i).push_back(s.at(i).at((j+d)%n));
      }
    }
    bool f = false;
    rep(i, n){
      rep2(j, i+1, n){
        if(now.at(i).at(j) != now.at(j).at(i)){
          f = true;
        }
      }
    }
    if(f == false) ans += n;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3880