akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int sum[maxn];
set<int>s;
set<int>::iterator it;
int main()
{
    int n;
    int num=0,mins=1e9;;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],sum[i]=sum[i-1]+a[i];
        for(int i=1;i<n;i++)
        mins=min(mins,abs(sum[n]-sum[i]-sum[i]));



        cout<<mins<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define max 101

int main(void)
{
  int n, h[max], sum, pa;
  int i, j;
  
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++)
  {
    scanf("%d", &h[i]);
  }
  
  for(i = 1 ; i < n ; i++)
  {
    for(j = 0 ; j < i ; j++)
    {
      if(h[j] <= h[i])
      {
        pa += 1;
      }
    }
    if(pa == i)
      sum += 1;
    pa = 0;
  }
  
  printf("%d", sum + 1);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[11110];
long long ii[11111]={};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0;
  string s;
  bool o=true;
  cin >>a;
  for(int n=0;n<a;n++){
    cin >>i[n];
    if(i[n]%2!=0) o=false;
  }
  while(o){
    d++;
    for(int n=0;n<a;n++){
      i[n]=i[n]/2;
      if(i[n]%2!=0) o=false;
    }
  }
  cout <<d<<'\n';
  return (0);
}


Measured memory_bytes: 256
// Anve$hi $hukla
#include <bits/stdc++.h>
using namespace std;
struct ${$(){ios_base::sync_with_stdio(false);cin.tie(NULL);}}$;

typedef long long LL;
const int Maxn = 200005;

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


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

using namespace std;

int main() {

    int n;
    cin >> n;
    
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];
    
    int dp[n][3];
    
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    
    for(int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
        dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
        dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
    }
    
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
    return 0;
}

Measured memory_bytes: 2560
S = list(input())
S.reverse()
N = len(S)
i = 0
ans = "YES"

# maerd remaerd esare resare
while i != N:
    if "".join(map(str,S[i:i+5])) == "maerd":
        i += 5
    elif "".join(map(str,S[i:i+5])) == "esare":
        i += 5
    elif "".join(map(str,S[i:i+6])) == "resare":
        i += 6
    elif "".join(map(str,S[i:i+7])) == "remaerd":
        i += 7
    else:
        ans = "NO"
        break

print(ans)

Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
long long gcd(long long A, long long B) {
  if (A < B) {
	  return gcd(B, A);
	}
  if (B == 0) {
	  return A;
	}
  return gcd(B, A % B);
}

int main() {
  long long A, B;
  cin >> A >> B;
  long long g   = gcd(A, B);
  long long s   = float(sqrt(g));
  long long ans = 1;
  for (long long i = 2; i <= s; i++) {
	  if (g % i == 0) {
		  ans++;
		  while (g % i == 0) {
			  g /= i;
			}
		}
	}
  if (g > 1) {
	  ans++;
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, M, Q; 
	cin >> N >> M >> Q; 
	int A[2019][2019] = {}; 
	int C[2019][2019] = {}; // 黒マスの個数
	int H[2019][2019] = {}; // 黒マスどうしをつなぐ横向きの辺
	int V[2019][2019] = {}; // 黒マスどうしをつなぐ縦向きの辺
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= M; j++){
			char c; 
			cin >> c; 
			A[i][j] = c - '0'; 
		}
	}
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= M; j++){
			C[i][j] = C[i-1][j] + C[i][j-1] - C[i-1][j-1] + A[i][j]; 
		}
	}
	for(int i = 2; i <= N; i++){
		for(int j = 1; j <= M; j++){
			H[i][j] = H[i-1][j] + H[i][j-1] - H[i-1][j-1] + (A[i][j] & A[i-1][j]); 
		}
	}
	for(int i = 1; i <= N; i++){
		for(int j = 2; j <= M; j++){
			V[i][j] = V[i-1][j] + V[i][j-1] - V[i-1][j-1] + (A[i][j] & A[i][j-1]); 
		}
	}
	for(int q = 0; q < Q; q++){
		int x1, y1, x2, y2; 
		cin >> x1 >> y1 >> x2 >> y2; 
		int c = C[x2][y2] - C[x1-1][y2] - C[x2][y1-1] + C[x1-1][y1-1]; 
		int h = H[x2][y2] - H[x1][y2] - H[x2][y1-1] + H[x1][y1-1]; 
		int v = V[x2][y2] - V[x1-1][y2] - V[x2][y1] + V[x1-1][y1]; 
		cout << c - h - v << endl; 
	}
}

Measured memory_bytes: 65536
def main():
    import bisect
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    cnt = {}
    for i in range(n):
        if a[i] not in cnt.keys():
            cnt[a[i]] = 1
        else:
            cnt[a[i]] += 1
    for _ in range(m):
        b,c = map(int,input().split())
        if c not in cnt.keys():
            cnt[c] = b
        else:
            cnt[c] += b
    sumed = 0
    s = 0
    for key in sorted(cnt.keys(),reverse=True):
        if n-sumed-cnt[key]>0:
            sumed += cnt[key]
            s += key*cnt[key]
        else:
            s+=key*(n-sumed)
            break
    print(s)


if __name__ == "__main__":
    main()

Measured memory_bytes: 32064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 2000000009

int main()
{
    ios::sync_with_stdio(false);
    string a;
	cin>>a;
	if (a.size()<4) cout<<"No";
	else if (a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I') cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int n;
	scanf("%d", &n);
	if (n < 4) {
		printf("No\n");
		return 0;
	}
	else {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (4 * i + 7 * j == n) {
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> xl(n);
    rep(i,n){
        int x, l;
        cin >> x >> l;
        xl[i]={x, l};
    }
    sort(xl.begin(), xl.end());
    int cnt=0;
    int right = xl[0].first + xl[0].second;
    int left2,right2;
    rep(i,n-1){
        left2 = xl[i + 1].first - xl[i + 1].second;
        right2 = xl[i + 1].first + xl[i + 1].second;
        if(right > right2){
            right = right2;
            cnt++;
        }else if(right <= left2){
            right = right2;
        }else{
            cnt++;
        }
    }
    cout << (n-cnt) << endl;
}

Measured memory_bytes: 1024
import os
import sys

import numpy as np


def solve(inp):
    SEGTREE_TABLES = []

    def bit_length(n):
        ret = 0
        while n:
            n >>= 1
            ret += 1
        return ret

    def segtree_init(n):
        n2 = 1 << bit_length(n)
        SEGTREE_TABLES.append([0] * (n2 << 1))
        return len(SEGTREE_TABLES) - 1

    def segtree_build(ins, arr):
        table = SEGTREE_TABLES[ins]
        offset = len(table) >> 1
        table[offset:offset + len(arr)] = list(arr)
        for i in range(offset - 1, 0, -1):
            ch = i << 1
            table[i] = max(table[ch], table[ch + 1])

    def segtree_update(ins, i, x):
        table = SEGTREE_TABLES[ins]
        offset = len(table) >> 1
        i += offset
        table[i] = x
        while i > 1:
            ch = i
            i >>= 1
            table[i] = max(table[ch], table[ch ^ 1])

    def segtree_query(ins, l, r):
        """ max [l, r) """
        table = SEGTREE_TABLES[ins]
        offset = len(table) >> 1
        l += offset
        r += offset
        res = -1
        while l < r:
            if r & 1:
                res = max(res, table[r - 1])
            if l & 1:
                res = max(res, table[l])
                l += 1
            l >>= 1
            r >>= 1
        return res

    def segtree_search(ins, lo, x):
        """
        Get min i where lo <= i, A[i] >= x.
        Assume that a sentinel larger than x is inserted at the right end.
        """
        table = SEGTREE_TABLES[ins]
        offset = len(table) >> 1
        i = lo + offset
        while table[i] < x:
            while i & 1:
                i >>= 1
            i += 1
        while i < offset:
            i <<= 1
            if table[i] < x:
                i += 1
        return i - offset

    def segtree_debug_print(ins):
        table = SEGTREE_TABLES[ins]
        offset = len(table) >> 1
        i = 1
        while i <= offset:
            print(table[i:2 * i])
            i <<= 1

    n = inp[0]
    q = inp[1]
    aaa = inp[2:n + 2]
    ttt = inp[n + 2::3]
    xxx = inp[n + 3::3]
    yyy = inp[n + 4::3]
    INF = 1 << 60

    aaa = np.append(aaa, INF)
    ins = segtree_init(n + 1)
    segtree_build(ins, aaa)

    ans = []

    for i in range(q):
        if ttt[i] == 1:
            segtree_update(ins, xxx[i] - 1, yyy[i])
        elif ttt[i] == 2:
            res = segtree_query(ins, xxx[i] - 1, yyy[i])
            ans.append(res)
        else:
            res = segtree_search(ins, xxx[i] - 1, yyy[i])
            ans.append(res + 1)

    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))


Measured memory_bytes: 54924
#include <iostream>
int main() {
  char c, prev;
  int cnt;
  bool flg = false;
  while(std::cin>>c) {
    (c==prev?++cnt:cnt=0);
    if(cnt==2) {
      flg = true;
    }
    prev = c;
  }
  std::cout << (flg?"Yes":"No");
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int b1, b2, b3;
  scanf("%d%d%d",&b1, &b2, &b3);
 
  if(b1 == 1 && b2 == 0 && b3 == 0){
    printf("Close\n");
  }
  else if(b1 == 0 && b2 == 1 && b3 == 0){
    printf("Close\n");
  }
  else if(b1 == 1 && b2 == 1 && b3 == 0){
    printf("Open\n");
  }
  else if(b1 == 0 && b2 == 0 && b3 == 1){
    printf("Open\n");
  }
  else if(b1 == 0 && b2 == 0 && b3 == 0){
    printf("Close\n");
  } 
  return 0;    
      
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int q;
  cin>>q;
  int m[q];
  for(int i=0;i<q;i++) cin>>m[i];
  set<int> s;
  for(int i=0;i<(1<<n);i++){
    int tmp=0;
    for(int j=0;j<n;j++) tmp+=((i>>j)&1)*a[j];
    if(tmp>2000) continue;
    s.insert(tmp);
  }
  for(int i=0;i<q;i++) cout<<(s.count(m[i])?"yes":"no")<<endl;
  return 0;
}

Measured memory_bytes: 3112
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        
        int[] A = new int[N];
        int[] B = new int[M];
        for(int n=0;n<N;n++) A[n]=sc.nextInt();
        for(int m=0;m<M;m++)B[m]=sc.nextInt();
        
        int maxA = X;
        int minB = Y;
        for(int n=0;n<N;n++) maxA = Math.max(maxA,A[n]);
        for(int m=0;m<M;m++) minB = Math.min(minB,B[m]);
        
        if(maxA<minB) System.out.println("No War");
        else System.out.println("War");
        
    }
}


Measured memory_bytes: 25172
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int a[200005], n, i;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("L.INP", "r", stdin);
    //freopen("L.OUT", "w", stdout);
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    a[0] = 2582004;
    for (i = 1; i <= n; i++)
    {
        if (a[i] == a[i - 1])
        {
            return cout << "NO", 0;
        }
    }
    cout << "YES";
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll l, r;

	cin >> l >> r;

	ll ans = INF;

	if (r - l > 2017) {
		ans = 0;
	}
	else {
		vector<ll> v;
		FOR(i, l, r + 1) {
			v.push_back(i % 2019);
		}
		REP(i, v.size()) {
			FOR(j, i + 1, v.size()) {
				ans = min(ans, ((v[i] % 2019) * (v[j] % 2019)) % 2019);
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
def get_gcd(a, b):
    if b > a:
        a, b = b, a
    r = a%b
    if r == 0:
        return b
    else:
        return get_gcd(b, r)


def prime_factorize(n):
    answers = []
    while n % 2 == 0:
        answers.append(2)
        n //= 2
    f = 3
    while f**2 <= n:  # instead of f <= n**0.5
        if n % f == 0:
            answers.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        answers.append(n)
    return answers

A, B = map(int, input().split())
gcd = get_gcd(A, B)
factors = prime_factorize(gcd)
print(len(set(factors+[1])))

Measured memory_bytes: 38640
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

long long n, a, b, c, d;
string s;

int main(){
    cin >> n >> a >> b >> c >> d;
    cin >> s;

    long long j = a-1;
    long long rock_length = 0;
    while(j < max(c-1, d-1)){
        if(s[j] == '#'){
            long long length = 0;
            while(j < max(c-1, d-1) and s[j] == '#'){
                j++;
                length++;
            }
            rock_length = max(rock_length, length);
            j++;
        }
        else{
            j++;
        }
    }

    if(c < d){
        if(rock_length >= 2){
            printf("No\n");
        }
        else{
            printf("Yes\n");
        }
    }
    else{
        if(rock_length >= 2){
            printf("No\n");

        }
        else{
            long long i = b-2;
            long long space_length = 0;

            while(i <= d){
                if(s[i] == '.'){
                    long long length = 0;
                    while(i <= d and s[i] == '.'){
                        i++;
                        length++;
                    }
                    space_length = max(space_length, length);
                    i++;
                }
                else{
                    i++;
                }
            }
            
            if(space_length >= 3){
                printf("Yes\n");
            }
            else{
                printf("No\n");
            }
        }

    }
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

void output(int a[],int n){
    int i;
    for(i=0;i<n;i++){
        if(i==0)printf("%d",a[i]);
        else printf(" %d",a[i]);
    }
    printf("\n");
    return;    
}

int main(void){
    int i;
    
    int n;
    scanf("%d\n",&n);
    
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d \n",&a[i]);
    }
    
    int q;
    scanf("%d\n",&q);
    
    int b,e,t;
    int k,tmp;
    while(q--){
        scanf("%d %d %d\n",&b,&e,&t);
        for(k=0;k<e-b;k++){
            tmp=a[b+k];
            a[b+k]=a[t+k];
            a[t+k]=tmp;
        }
    }
    
    output(a,n);
    
    return 0;
}



Measured memory_bytes: 2100
#再帰回数が多すぎてエラー
import sys

sys.setrecursionlimit(210000)
S = list(input()) + ['D']*100
N = len(S)-10

# print (S)
# print (N)

memo = [-1] * (N+100) 

# print (memo)

def check(k):
    if memo[k] != -1:
        return memo[k]
    if S[k+1] == 'B' and S[k+2] == 'C':
        memo[k] = check(k+2) + 1
        return memo[k]
    if S[k+1] == 'A':
        memo[k] = check(k+1)
        return memo[k]
    memo[k] = 0
    return memo[k]

ans = 0
for i in range(N):
    if S[i] =='A':
        ans += check(i)
print (ans)


Measured memory_bytes: 166844
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		StringBuilder sb = new StringBuilder();
		for(char c : r.string().toCharArray())
		{
			if(c == 'B' && sb.length() == 0) continue;
			if(c == 'B' && sb.length() > 0) sb.setLength(sb.length()-1);
			else sb.append(c);
		}
		print(sb.toString());
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(string());
		}

		long rl() {
			return Long.parseLong(string());
		}

		double rd() {
			return Double.parseDouble(string());
		}

		String string() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return string().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = string();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = string();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(string());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(string());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}

Measured memory_bytes: 21204
N = int(input())

A = list(map(int,input().split()))
s = 0
for i,a in enumerate(A):
    if i%2:
        s -= a
    else:
        s += a

ans = [-1 for i in range(N)]
ans[0] = s

for i in range(1,N):
    ans[i] = (A[i-1]-ans[i-1]//2)*2
print(' '.join(map(str,ans)))


Measured memory_bytes: 19096
N=int(input())

ans=0
for i in range(1,N+1,2):
  tmp=0
  t=i**(1/2)
  for j in range(1,int(t)+1):
    if i%j==0:
      tmp+=1
      
  tmp=tmp*2
  if t-int(t)<=1e-3:
    tmp-=1

  if tmp==8:
    ans+=1
      
print(ans)    



Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
// Boost Multiprecision Library を include
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
namespace mp = boost::multiprecision;

int main(){
    mp::cpp_dec_float_100 a,b,c;
    cin >> a >> b >> c;

  if(sqrt(a)+sqrt(b) < sqrt(c) ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int n, a[111], b[111], dp[111][111];
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for(int i = 2; i <= n; i++) {
		for(int j = 0; j <= n - i; j++) {
			int l = j, r = j + i; // [l, r)
			dp[l][r] = 999999999;
			for(int k = l + 1; k < r; k++) {
				dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + a[l] * a[k] * b[r - 1]);
			}
		}
	}
	cout << dp[0][n] << endl;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	if(s[s.length()-1]=='s'){
		cout<<s;
		cout<<"es";
	}
	else{
		cout<<s;
		cout<<"s";
	}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  vector<int> vec;
  vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << vec.at(k - 1);

}


Measured memory_bytes: 256
/******************gourav_j**************/
#include <bits/stdc++.h>
#define FF first
#define SS second
#define pb push_back
#define mp make_pair
#define INF 1e18
#define MOD 1000000007
#define MAXN 100005
#define mem(a, v) memset(a, v, sizeof a)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define fori(i,a,b) for(int  i=(a);i<=(b);i++)
#define forl(i,a,b) for(ll  i=(a);i<=(b);i++)
#define rfor(i,a,b) for(int i=(b);i>=(a);i--)
#define forit(i, a) for ( __typeof( (a).begin() ) i = (a).begin(); i != (a).end(); i++ )
#define all(v) (v.begin(),v.end())
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef map<string,ll> msi;
typedef set<ll> si;
int dx[] = {-1, 0, 0, 1};
int dy[] = { 0,-1, 1, 0};
                /***********code begins here***********/
int getInvCount(ll arr[],int n) { 
    multiset<ll> set1; 
    set1.insert(arr[0]); 
    int invcount = 0;
    multiset<ll>::iterator itset1;
    for (int i=1; i<n; i++) 
    { 
        set1.insert(arr[i]); 
        itset1 = set1.upper_bound(arr[i]); 
        invcount += distance(itset1, set1.end()); 
    }  
    return invcount; 
}
ll gcdExtended(ll a, ll b, ll *x, ll *y) { 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
ll modInverse(ll b) { 
    ll x, y;
    ll g = gcdExtended(b, MOD, &x, &y); 
    if (g != 1) 
        return -1; 
    return (x%MOD + MOD) % MOD; 
} 
void solve(){
    int n;
    ll k;
    cin>>n>>k;
    ll ar[n];
    fori(i,0,n-1)
    cin>>ar[i];
    int inv = getInvCount(ar,n);
    ll ans = (k%MOD*inv%MOD)%MOD;
    for(int i=0;i<n;i++){
        ll c=0;
        for(int j=0;j<n;j++){
            if(ar[i]>ar[j])
                c++;
        }
        ll y = (k-1)%MOD;
        ll x = (c+((k-1)%MOD*c%MOD)%MOD)%MOD;
        x = (x*y)%MOD;
        ll z = modInverse(2);
        x = (x*z)%MOD;
        ans = (ans+x)%MOD;
    }
    /*for(int i=0;i<n;i++){
        ll y = (k-1);
        ll x = (br[i]+((k-1)*br[i])%MOD)%MOD;
        ans = (ans+((x*y)/2)%MOD)%MOD;
    }*/
    cout<<ans;
}
int main() {
    
    int T=1; 
    //cin>>T;
    while(T--){
        solve();
        cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

multiset<long long> SE;

struct trie{
	struct node{
		vector<int> next;
		int str=-1;
		node(int k){
			next.resize(k,-1);
		}
	};
	vector<node> N;
	vector<string> S;
	int n;
	trie(int k){
		n = k;
		N.push_back(node(n));
	}
	
	void add(string s){
		int now = 0;
		for(int i=0;i<s.size();i++){
			int c = get(s[i]);
			if(N[now].next[c]==-1){
				N[now].next[c] = N.size();
				N.push_back(node(n));
			}
			now = N[now].next[c];
		}
		
		N[now].str = S.size();
		S.push_back(s);
	}
	/*	
	int check(string s){
		int ret = 0;
		trie* now = this;
		for(int i=0;i<s.size();i++){
			int c=get(s[i]);
			if(now->next[c]==0){
				return ret;
			}
			now = now->next[c];
			if(now->flag)ret=i+1;
		}
		return ret;
	}
	*/
	
	int get(char c){
		return c-'0';
	}
	
	void dfs(int d,int now=0){
		if(N[now].next[0]==0&&N[now].next[1]==0)return;
		for(int i=0;i<2;i++){
			if(N[now].next[i]==-1){
				SE.insert(d);
			}
			else{
				dfs(d+1,N[now].next[i]);
			}
		}
	}
		
	
};

long long get(long long t){
	for(long long i=60;i>=0;i--){
		if(t%(1LL<<i)==0)return (1<<i);
	}
	return 0LL;
}

int main(){
	
	int N;
	cin>>N;
	
	long long L;
	cin>>L;
	
	trie T(2);
	
	for(int i=0;i<N;i++){
		string s;
		cin>>s;
		T.add(s);
	}
	
	T.dfs(0);
	
	long long now = 0LL;
	for(auto a:SE){
		now ^= get(L-a);
	}
	
	if(now==0)cout<<"Bob"<<endl;
	else cout<<"Alice"<<endl;
	
	return 0;
}


Measured memory_bytes: 22224
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

ll a[11];
ll n;

ll pow(ll x, ll n){
    ll res = 1;
    for(int i = 0; i < n; i++){
        res *= x;
    }
    return res;
}

ll dfs(int i, ll x){
    if(i == n - 1){
        return x * 10 + a[n - 1];
    }
    return (10 * x + a[i]) * pow(2, n - 2 - i) + dfs(i + 1, 0) + dfs(i + 1, 10 * x + a[i]);
}

int main()
{
    string s;
    cin >> s;
    n = s.size();
    for(int i = 0; i < n; i++){
        a[i] = s[i] - '0';
    }
    cout << dfs(0, 0) << endl;
}

Measured memory_bytes: 256
s = input()

a_no = 0
z_no = 0

for i in range(len(s)):
    if s[i] == "A":
        a_no = i
        break
for i in reversed(range(len(s))):
    if s[i] == "Z":
        z_no = i
        break
print(len(s[a_no:z_no])+1)

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
int n,m,a[100005];
int main(){
	scanf("%d", &n);
	while( n-- ){
		int l,r;
		scanf("%d%d", &l, &r);
		for( int i = l; i <= r; i++ ) a[i] = 1;
	}
	for( int i = 1; i <= 100000; i++ ) m += a[i];
	printf("%d\n", m);
	
} 

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

int main() {
  cout << fixed << setprecision(16);
  int N, K;
  cin >> N >> K;

  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
  }
  
  int maxSum = 0;
  int maxIndex = 0;

  int sum = 0;  
  for (int i = 0; i < K; i++){
    sum += P[i];
  }
  maxSum = sum;
  
  for(int i = 1; i < N - K + 1; i++){
    sum -= P[i-1];
    sum += P[i-1+K];
    
    if (sum > maxSum){
      maxSum = sum;
      maxIndex = i;
    }
  }
  
  double aveSum = 0;
  for (int i = 0; i < K; i++){
    int index = i + maxIndex;
    double sum = (double)(P[index] * (P[index] + 1)) / 2;
    aveSum += sum / P[index];
  }
  
  cout << aveSum << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
using namespace std;

using weight = long long;

constexpr weight INF = 1e18;


// warshall-floyd
void warshall_floyd(std::vector<std::vector<weight>>& g) {
    int V = g.size();
    for(int k=0; k<V; ++k) {
        for(int i=0; i<V; ++i) {
            for(int j=0; j<V; ++j) {
                if(g[i][k] == INF || g[k][j] == INF) {
                    continue;
                }
                g[i][j] = std::min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}


int main() {
    int v, e;
    cin >> v >> e;
    vector<vector<weight>> g(v, vector<weight>(v, INF));
    for(int i=0; i<v; ++i) {
        g[i][i] = 0;
    }
    for(int i=0; i<e; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        g[s][t] = d;
    }
    warshall_floyd(g);
    for(int i=0; i<v; ++i) {
        for(int j=0; j<v; ++j) {
            if(g[i][j] + g[j][i] < 0) {
                cout << "NEGATIVE CYCLE" << endl;
                return 0;
            }
        }
    }
    for(int i=0; i<v; ++i) {
        for(int j=0; j<v; ++j) {
            if(g[i][j] == INF) {
                cout << "INF";
            } else {
                cout << g[i][j];
            }
            if(j != v-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
}


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

double jyun(double a){
    double ta = 0.0;
    ta = (a+1)/2;
    return ta;
}

int main(){
    int n,k;
    cin >> n >> k;
    double A[n];
    rep(i,n) cin >> A[i];
    rep(i,n) A[i] = (A[i] + 1)/2;
    double B[n+1];
    B[0] = 0;
    for(int i = 1;i < n+1;i++) B[i] = A[i-1] + B[i-1];
    
    double maximum = 0.0;
    rep(i,n-k+1) maximum = max(maximum,B[i+k] - B[i]);
    cout << fixed << setprecision(15) << maximum << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define REP(i,n) for (int i=1;i<=n;i++)
#define print(x) cout << x << endl;
typedef long long ll;

int main() {
	int n; cin >> n;
	vector<string> s(n);
	vector<int> x(n, 1);
	rep(i, n) cin >> s[i];
	sort(s.begin(), s.end());
	REP(i, n-1) {
		if (s[i] == s[i - 1]) {
			x[i] = x[i - 1] + 1;
		}
	}
	int maximam = 0;
	rep(i, n) {
		maximam = max(x[i], maximam);
	}
	rep(i, n) {
		if (x[i] == maximam) cout << s[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 15104
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

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

int main() {

    ll N;
    cin >> N;
    pair<pair<string,ll>, ll> A[N];
    rep(i,N){
        string S;
        ll P;
        cin >> S >> P;
        A[i] = make_pair(make_pair(S,-P),i);
    }
    sort(A,A+N);
    rep(i,N) cout << A[i].second+1 << endl;
    return 0;
}


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

using namespace std;

int D = 365, c[26], s[365][26];

struct State {
	int ans[365];
};

class SimulatedAnnealing {
private:
	chrono::system_clock::time_point begin_;
	bool opt_mode_;
	double s_temp_;
	double e_temp_;
	double time_limit_;

	void init(State &state){
		for(int i = 0; i < D; ++i) state.ans[i] = (rand()%26)+1;
	}
	void next(State &state){
		state.ans[rand()%D] = (rand()%26)+1;
	}
	long long score(State &state){
		long long res = 0;
		for(int d = 0; d < D; ++d) res += s[d][state.ans[d]-1];
		for(int d = 0; d < D; ++d){
			long long sum = 0;
			for(int i = 0; i < 26; ++i){
				int lastdi = 0;
				for(int j = 0; j <= d; ++j){
					if(state.ans[j] == (i+1)) lastdi = (j+1);
				}
				sum += c[i] * ((d+1) - lastdi);
			}
			res -= sum;
		}
		return max((long long)1000000+res, (long long)0);
	}
	void start(){
		begin_ = chrono::system_clock::now();
	}
	double now(){
		return static_cast<double>(chrono::duration_cast<chrono::microseconds>(chrono::system_clock::now()-begin_).count()/1.0e6);
	}

public:
	// 初期スコア, 最適化モード("maximize" or "minimize"), 制限時間, 開始時温度, 終了時温度
	SimulatedAnnealing(string opt_mode, double time_limit, double s_temp, double e_temp){
		opt_mode_ = (opt_mode == "maximize");
		time_limit_ = time_limit;
		s_temp_ = s_temp;
		e_temp_ = e_temp;
	}
	void solve(){
		start();

		random_device rnddev;
		mt19937 mt(rnddev());
		uniform_real_distribution<double> rnd(0.0, 1.0);

		State now_state;
		init(now_state);

		long long best_score_ = 0;
		State best_state_;
		init(best_state_);

		long long now_score = score(now_state), next_score;
		while(true){
			if(now() > time_limit_) break;
			State next_state = now_state;
			next(next_state);
			next_score = score(next_state);
			double temp = (e_temp_-s_temp_)*now()/time_limit_+s_temp_;
			double prob = exp((now_score-next_score)/temp);
			if(now_score < next_score || rnd(mt) < prob){
				now_state = next_state;
				now_score = next_score;
			}
			if(best_score_ < now_score){
				best_state_ = now_state;
				best_score_ = now_score;
			}
		}

		for(int i = 0; i < D; ++i){
			printf("%d\n", best_state_.ans[i]);
		}
	}
};

int main(){
	// Input
	cin >> D;
	for(int i = 0; i < 26; ++i) cin >> c[i];
	for(int i = 0; i < D; ++i) for(int j = 0; j < 26; ++j) cin >> s[i][j];

	SimulatedAnnealing sa("maximize", 1.98, 50, 20);
	sa.solve();
}


Measured memory_bytes: 3872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    string n;
    cin >> n;
    for (int i = 0; i < n.size() - 1; i++) {
        if (n.at(i) == 'B' && n.at(i + 1) == 'C') {
            n.at(i) = 'X';
            n.at(i + 1) = 'X';
        }
    }
    n += "QQ";
    ll ans = 0;
    ll a = 0;
    for (int i = 0; i < n.size(); i++) {
        if (n.at(i) == 'A') {
            a++; 
        }

        else if (n.at(i) == 'X') {
            ans += a;
        }
        else {
            a = 0;
        }
    }
    ans /= 2;
    cout << ans << endl;
}

Measured memory_bytes: 640
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  solve <$> replicateM n (getl $ wrds toInt) >>= mapM_ print

solve :: [[Int]] -> [Int]
solve = map sum . transpose . map f . transpose
  where
    f xs = [if i `elem` (xs \\ [i]) then 0 else i | i <- xs]

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4236
a, b, c, x, y = map(int, input().split())

ans1 = x * a + y * b

min_xy = min(x, y)
ans2 = min_xy * 2 * c + (x - min_xy) * a + (y - min_xy) * b

max_xy = max(x, y)
ans3 = max_xy * 2 * c

print(min(ans1, ans2, ans3))

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


int main()
{
    int a, b;
    cin >> a >> b;
    bool ok = false;
    for (int x = 1; x <= 1500; x++) {
        if (x * 8 / 100 == a && x * 10 / 100 == b) {
            ok = true;
            cout << x << endl;
            break;
        }
    }
    if (!ok) cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
a11, a12, a13 = map(int,input().split())
a21, a22, a23 = map(int,input().split())
a31, a32, a33 = map(int,input().split())
n=int(input())
b=[0]*n
for i in range(n):
  b[i]=int(input())
  
for i in range(n):
  if b[i] == a11:
    a11=0
  elif b[i] == a12:
    a12 = 0
  elif b[i] == a13:
    a13 = 0
  elif b[i] == a21:
    a21 = 0
  elif b[i] == a22:
    a22 = 0
  elif b[i] == a23:
    a23 = 0
  elif b[i] == a31:
    a31 = 0
  elif b[i] == a32:
    a32 = 0
  elif b[i] == a33:
    a33 = 0
  else:
    pass
  
if a11+a12+a13==0 or a21+a22+a23==0 or a31+a32+a33==0 or a11+a21+a31==0 or a12+a22+a32==0 or a13+a23+a33==0 or a11+a22+a33==0 or a31+a22+a13==0:
  print('Yes')
else:
  print('No')




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

int n;
void solve() {
    if(n < 1000) cout << "ABC" << endl;
    else cout << "ABD" << endl;
}

int main() {
    while(~scanf("%d", &n)) {
        solve();
    }
	return 0;
}


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

int gcd(int x, int y){
    if(y == 0) return x;
    if(y == 1) return 1;
    else return gcd(y, x%y);
}

int main(){
    int x, y;
    cin >> x >> y;
    if(x < y) swap(x, y);
    cout << gcd(x, y) << endl;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
const int maxn = 333;
long long dist[maxn][maxn];
int cs[maxn][maxn];
int main(){
	int n, m, l; cin >> n >> m >> l;
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dist[i][j] = l + 1;
	for(int i = 0; i < n; i++) dist[i][i] = 0;
	for(int i = 0; i < m; i++){
		int a, b; long long c; cin >> a >> b >> c; a--; b--;
		dist[a][b] = min(dist[a][b], c);
		dist[b][a] = min(dist[b][a], c);
	}
	for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	for(int i = 0; i < n; i++){
		queue<int> q;
		for(int j = 0; j < n; j++) cs[i][j] = -1;
		cs[i][i] = 0;
		q.push(i);
		while(!q.empty()){
			int u = q.front(); q.pop();
			for(int j = 0; j < n; j++){
				if(dist[u][j] <= l && cs[i][j] == -1){
					cs[i][j] = cs[i][u] + 1;
					q.push(j);
				}
			}
		}
	}
	int q; cin >> q;
	while(q--){
		int s, t; cin >> s >> t; s--; t--;
		if(cs[s][t] == -1)
			cout << -1 << "\n";
		else
			cout << -1 + cs[s][t] << "\n";
	}
	return 0;
}


Measured memory_bytes: 1664
s = input()
a, b, c, d = int(s[0]), int(s[1]), int(s[2]), int(s[3])

B = [b, -b]
C = [c, -c]
D = [d, -d]

is_7 = False

for i_b in B:
    for i_c in C:
        for i_d in D:
            if a+i_b+i_c+i_d == 7:
                is_7 = True
                break
        if is_7:
            break
    if is_7:
        break
        
signs = []
for i in [i_b,i_c,i_d]:
    if i>=0:
        signs.append('+')
    else:
        signs.append('-')
        
print(str(a)
      +signs[0]
      +str(abs(i_b))
      +signs[1]
      +str(abs(i_c))
      +signs[2]
      +str(abs(i_d))
      +'=7')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <stack>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i ++)
using ll = long long;
const int INF = 1<<25;
typedef pair<int, int> P;
int N, M;
int xs[100000], ys[100000];
vector<int> G[100000];
vector<int> Ginv[100000];
vector<int> sorted;
int degree[100000];
int dp[100000];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> M;
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
        Ginv[y].push_back(x);
        degree[y] ++;
    }
    stack<int> st;
    rep(i, N) if (degree[i] == 0) st.push(i);
    while (st.size() > 0) {
        int i = st.top(); st.pop();
        sorted.push_back(i);
        for (int j : G[i]) {
            degree[j] --;
            if (degree[j] == 0) st.push(j);
        }
    }
    rep(i, N) {
        int x = sorted[i];
        int d = 0;
        for (int y : Ginv[x]) {
            d = max(d, dp[y] + 1);
        }
        dp[x] = d;
    }
    int ans = 0;
    rep(i, N) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15372
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define vec(j,n) vector<int>(j(n))
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    vector<int>ans(5);
    for(int i=0;i<5;i++){
        cin >> ans.at(i);
    }
    for(int i=0;i<5;i++){
        if(ans.at(i) == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
	SpeedForce;
	char c;
	cin >> c;
	c++;
	cout << c;
   	return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>

typedef long long ll;

using namespace std;

int main(void)
{
    int a, b, cnt = 0;
    cin >> a >> b;

    while(1) {
        a -= b;
        cnt++;
        if(a <= 0) {
            break;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

int main(){ 
  double n,range;
  int d,cnt=0,result;
  cin >> n >> d;
  range=d*2+1;
  result=ceil(n/range);
  cout << result << endl;
  return 0;
}

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


int main() {
	int a, b;
	cin >> a >> b;
	if (a * b * 3 % 2 != 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator

#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define BG begin
#define ED end

#define For(i,j,k) for (int i=(j);i<=(int)k;i++)
#define Rep(i,j,k) for (int i=(j);i>=(int)k;i++)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));

#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
using namespace std;

int S(ll i){
	int s=0;
	for (;i;s+=i%10,i/=10);
	return s;
}
const int N=100005;
ll q[N];
double v[N];
int main(){
	ll val1=1;
	int top=0;
	for (int i=1;i<=15;i++,val1*=10)
		for (int j=1;j<=999;j++)
			q[++top]=j*val1+val1-1;
	sort(q+1,q+top+1);
	top=unique(q+1,q+top+1)-q-1;
	v[top+1]=1e18;
	for (int i=top;i;i--){
		v[i]=1.0*q[i]/S(q[i]);
		if (v[i]>v[i+1]) q[i]=0;
		v[i]=min(v[i],v[i+1]);
	}
	int k;
	scanf("%d",&k);
	for (int i=1;k;i++)
		if (q[i]) printf("%lld\n",q[i]),k--; 
}


Measured memory_bytes: 512
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();

    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    line.trim()
        .split_whitespace()
        .map(|x| x.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .map_err(|_| format!("{}", "parse error"))
}

fn grade(m: i8, f: i8, r: i8) -> char {
    match (m, f, r) {
        (-1, _, _) => 'F',
        (_, -1, _) => 'F',
        (x, y, _) if x + y >= 80 => 'A',
        (x, y, _) if x + y >= 65 => 'B',
        (x, y, _) if x + y >= 50 => 'C',
        (x, y, r) if x + y >= 30 => {
            if r >= 50 {
                'C'
            } else {
                'D'
            }
        }
        (x, y, _) if x + y < 30 => 'F',
        (_, _, _) => 'X',
    }
}

fn main() {
    let mut n = read_parameters::<i8>().unwrap();
    let (mut m, mut f, mut r) = (n[0], n[1], n[2]);

    while !(m == -1 && f == -1 && r == -1) {
        println!("{}", grade(m, f, r));
        n = read_parameters::<i8>().unwrap();
        m = n[0];
        f = n[1];
        r = n[2];
    }
}



Measured memory_bytes: 5036
/*
 * x 軸上に N 人の人が立っています。 人 i の位置を xi とします。 任意の i に対して、xi は 0 以上 10^9 以下の整数です。 同じ位置に複数の人が立っていることもありえます。
 * 
 * これらの人の位置に関する情報が M 個与えられます。 このうち i 個めの情報は (Li,Ri,Di) という形をしています。 
 * この情報は、人 Ri は人 Li よりも距離 Di だけ右にいること、 すなわち、xRi−xLi=Di が成り立つことを表します。
 * 
 * これら M 個の情報のうちのいくつかに誤りがある可能性があることがわかりました。 与えられる M 個すべての情報と矛盾しないような値の組 (x1,x2,…,xN) が存在するかどうか判定してください。
 */

import java.util.*;
	public class Main{
		
		static int[] belongs = null;
		static int[] states = null;
        
		public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next());
            int m = Integer.parseInt(sc.next());
            states = new int[n];
            belongs = new int[n];
            
            for(int i=0; i<n; i++){
            	belongs[i] = i;
            	states[i] = 0;
            }
            
            for(int i=0; i<m; i++){
            	int l = Integer.parseInt(sc.next())-1;
            	int r = Integer.parseInt(sc.next())-1;
            	int d = Integer.parseInt(sc.next());
            	if(!merge(l, r, d)){
            		System.out.println("No");
            		sc.close();
            		return;
            	}
            }
            System.out.println("Yes");
            sc.close();
		}
            
		public static int updateBelongs(int a){
			if(a == belongs[a]){
				return a;
			}else{
				int temp = belongs[a];
				belongs[a] = updateBelongs(belongs[a]);
				states[a] += states[temp];
				return belongs[a];
			}
		}
		
		public static boolean merge(int l, int r, int d){
			int lb = updateBelongs(l);
			int rb = updateBelongs(r);
			
            if(lb == rb){
            	return states[r] == states[l] + d;
            }else{
            	belongs[rb] = lb;
            	states[rb] = states[l] + d - states[r];
            	return true;
            }
        }
    }
	

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

int k[100000];
signed main() {
	int a;
	while (cin >> a, a) {
		int b = 0;
		for (int c = 0; c < a; c++) {
			int d;
			scanf("%lld", &d);
			b += d;
		}
		for (int g = 0; g < a-1; g++) {
			int h;
			scanf("%lld", &h);
			k[g] = h;
		}
		sort(k, k + a - 1);
		reverse(k, k + a - 1);
		int MAX = b*a;
		for (int l = 0; l < a - 1;l++) {
			a--;
			b += k[l];
			MAX = max(MAX, b*a);
		}
		cout << MAX << endl;
	}
}

Measured memory_bytes: 3396