akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Objects;

public class Main{
    public static void main(String[] args){
        FastScanner sc = new FastScanner();

        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();

            if(m==-1 && f==-1 && r==-1)break;
            if(m==-1 || f==-1)System.out.println("F");
            else if(m+f>=80)System.out.println("A");
            else if(m+f>=65)System.out.println("B");
            else if(m+f>=50)System.out.println("C");
            else if(m+f>=30){
                if(r>=50)System.out.println("C");
                else System.out.println("D");
            }
            else System.out.println("F");
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}



Measured memory_bytes: 24328
module Main where
import Control.Monad
import Data.List

myPrint :: [String] -> String -> String
myPrint s p = unwords [p, "x", show $ sum [1 | x<-s, x==p]]

count :: Int -> Int -> [String] -> [Int] -> [Int] -> Int
count h w s rs cs = length [() | i<-[0..h-1], j<-[0..w-1], notElem i rs && notElem j cs && s !! i !! j == '#']

main :: IO ()
main = do
    [h, w, k] <- map read . words <$> getLine 
    s <- replicateM h getLine
    print $ length [() | rs<-subsequences [0..h-1], cs<-subsequences [0..w-1], count h w s rs cs == k]

Measured memory_bytes: 4844
import java.util.Scanner;
import java.util.HashSet;
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
      int X = sc.nextInt();
      int N = sc.nextInt();
      HashSet set = new HashSet();
      if(N == 0){
        System.out.println(X);
      } else {
        for(int i = 0; i < N; i++) set.add(sc.nextInt());
        int ans = X;
        for(int i = 1; i < 100; i++){
          if(!set.contains(X)) break;
          if(!set.contains(X - i)) {
            ans = X-  i;
            break;
          }
          if(!set.contains(X + i)) {
            ans = X + i;
            break;
          }
        }
        System.out.println(ans);
      }
      
    } 
}

Measured memory_bytes: 27076
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args) throws IOException
	{
		Scanner c = new Scanner(System.in);
		int N = c.nextInt();
		int[] arr = new int[N];
		String s1 = c.next(), s2 = c.next();
		for(int i=0; i<N; i++)
		{
			if(s1.charAt(i) == s2.charAt(i))
				arr[i] = 1;
			else arr[i] = 0;
		}
//		System.out.println(Arrays.toString(arr));
		long ans = 3; int prev = 1;
		for(int i=0; i<N; i++)
		{ 
//			System.out.println(ans);
			ans%=(1e9+7);
			if(arr[i] == 0) 
			{
				if(prev == 0)
				{
					ans *= 3L;
				}
				else ans *= 2L;
				if(i==0) ans = 6L;
				prev  = 0;
				i++;
			}
			else
			{
				if(prev == 0)
				{
					ans *= 1L;
				}
				else ans *= 2L;
				if(i==0) ans = 3L;
				prev = 1;
			}
		}
		
		System.out.println((ans%(long)(1e9+7)));
	}
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP((i),0,(n))
#define ALL(v) (v).begin(),(v).end()

int main() {
	int n;
	cin >> n;
	int t = n;
	int sum = 0;
	while(t)sum += t % 10, t/= 10;
	if (n % sum == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 12
#define maxm 1000
struct Node{
	int a,b,x;
}a[maxm];
int f[1<<maxn];
int main(){
	int n,m,x,s;scanf("%d%d",&n,&m),s=1<<n;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a[i].a,&a[i].b);
		for(int j=0;j<a[i].b;j++)scanf("%d",&x),a[i].x|=(1<<x);
		a[i].x>>=1;
	}
	for(int i=1;i<s;i++)f[i]=1e9;
	for(int i=0;i<s;i++){
		if(f[i]==1e9)continue;
		for(int j=0;j<m;j++){
			f[i|a[j].x]=min(f[i|a[j].x],f[i]+a[j].a);
		}
	}
	printf("%d",f[s-1]!=1e9?f[s-1]:-1);
	return 0;
}

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

int N, a;
int odd=0, even=0, multiple4=0;

int main(void){
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> a;
        if(a%2) odd++;
        else if(a%4) even++;
        else multiple4++;
    }

    bool ans = true;

    if(!even){
        if(odd > multiple4+1) ans = false;
    }else{
        if(odd > multiple4) ans = false;
    }

    if(ans) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	

  	long long int m,ans,i,n;
  
  	scanf("%lld %lld",&n,&m);
  
  	if(n == 1){
    	printf("%lld\n",m);
      	return 0;
    }
  	if(m < 2*n){
  		printf("1\n");
      	return 0;
    }
  
  	for(i=m/n+1;i >=1;i--){
      if(m % i ==0){
      	ans = i;
        break;
      }
    }
	 
  	printf("%lld\n",ans);
  
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	map<ll, ll> m;
	auto prev = 0ll;
	for (auto i = 0; i < N; ++i)
	{
		auto next = (prev + A[i]) % M;
		++m[next];
		prev = next;
	}
	++m[0];

	auto ans = 0ll;
	for (auto p : m)
	{
		ans += p.second * (p.second - 1) / 2;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4608
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N, X;
  cin >> N >> X;
  int tot = 0;
  int min_v = INF;
  for(int i=0; i<N; ++i){
    int v;
    cin >> v;
    tot += v;
    min_v = min(min_v, v);
  }
  int ans = N;
  ans += (X-tot)/min_v;

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define N 100010
vector<ll> g[N];
ll n,m,cnt[N];
bool dfs(ll x,ll from,ll a,ll b){
  if(x==a)return 0; if(x==b)return 1;
  for(auto y:g[x])if(y!=from)return dfs(y,x,a,b);
}
int main(){
    cin>>n>>m;for(int i=1;i<=n;i++)cnt[i]=0;
    for(int i=0;i<m;i++){
      ll a,b;cin>>a>>b;
      cnt[a]++,cnt[b]++;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    int cnt4=0; vector<ll> lis;
    int sum=0;
    for(int i=1;i<=n;i++){
      if(cnt[i]%2==1)sum=-1e9;
      else sum+=cnt[i]/2-1;
      if(cnt[i]==4){cnt4++;lis.push_back(i);}
      if(cnt[i]>=6)cnt4=-1e9;
    }
    if(cnt4==2){
      bool ok=0;
      for(auto y:g[lis[0]]){
	if(dfs(y,lis[0],lis[0],lis[1])==0)ok=1;
      }
      if(ok==0)sum=-1e9;
    }
    if(sum>=2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 6528
using System;
using System.Diagnostics;
using System.Linq;


namespace ConsoleApp1
{
    class Program
    {
        static void print(string s)
        {
            Console.WriteLine(s);
        }

        static string scan()
        {
            return Console.ReadLine();
        }

        static void Main(string[] args)
        {
            int x, y;
            string[] lineArray = scan().Split(" ");
            x = int.Parse(lineArray[0]);
            y = int.Parse(lineArray[1]);
            int i = 0;
            for (i = 0; i <= x; i++) 
            {
                if (i * 2 + (x - i) * 4 == y) 
                {
                    i = 999;
                }
            }
            if (i >= 999) 
                print("Yes");
            else
                print("No");
        }
    }
}


Measured memory_bytes: 27464
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 105;
string s;
ll dp[N][4][2]; //dp [i][k][b] = # ways to assign numbers i..n such that k non-zero numbers are left, and b=true if we are equal to n so far

ll solve(int i, int k, bool b) {
  if (k < 0) return 0;
  if (i == s.size()) return k==0;
  if (dp[i][k][b] == -1) {
    dp[i][k][b] = 0;
    int dig = s[i] - '0';
    if (b) {
      //maintain equality
      dp[i][k][b] += solve(i+1, k - (dig > 0), 1);
      //go less than dig
      for (int d = 0; d < dig; ++d) {
        dp[i][k][b] += solve(i+1, k - (d > 0), 0);
      }
    } else {
      dp[i][k][b] += solve(i+1, k, 0);
      for (int d = 1; d <= 9; ++d) {
        dp[i][k][b] += solve(i+1, k-1, 0);
      }
    }
  }
  return dp[i][k][b];
}

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  memset(dp, -1, sizeof dp);
  cin >> s;
  int k; cin >> k;
  cout << (solve(0, k, 1)) << nl;

  return 0;
}



Measured memory_bytes: 256
from operator import mul

# 自分の解答
def myAnswer(B:list,A:list,C:int) -> int:
   counter=0
   for a in A:
      if( sum(map(mul,B,a)) + C > 0): counter += 1
   return counter


def modelAnswer(B:list,A:list,C:int,N:int,M:int) -> int:
   ans = 0
   for i in range(N):
      total = 0
      for j in range(M):
         total += A[i][j] * B[j]
      if(total + C > 0): ans += 1
   return ans


def main():
   N,M,C = map(int,input().split())
   B = list(map(int,input().split()))
   A=[]
   for _ in range(N):
      A.append(list(map(int,input().split())))

   ans = myAnswer(B[:],A[:],C)
   ans2 = modelAnswer(B[:],A[:],C,N,M)
   print(ans2)


if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
bool vis[110];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int d;
		cin>>d;
		for(int j=0;j<d;j++){
			int x;
			cin>>x;
			vis[x]=1;
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3624
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    int ans = 0;
    int temp = 0;
    rep(i,N-1){
        if(h[i+1]<=h[i]) temp++;
        else temp = 0;
        ans = max(ans,temp);
    }
    cout << ans << nn;
    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF INT_MAX

vector< vector<int> > adj;
vector<int> serial;

void dfs(int v, int sn)
{
    serial[v] = sn;
    for (auto e : adj[v]) {
        if (serial[e]) continue;
        dfs(e, sn);
    }
}

int main(int, char**)
{
    int n, m;
    cin >> n >> m;

    adj.assign(n, vector<int>());
    int s, t;
    rep(i,m) {
        cin >> s >> t;
        adj[s].push_back(t);
        adj[t].push_back(s);
    }


    serial.assign(n, 0);
    int sn = 1;
    rep(i,n) {
        if (serial[i]) continue;
        dfs(i, sn++);
    }
    int q;
    cin >> q;
    rep(i,q) {
        cin >> s >> t;
        if (serial[s] == serial[t]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}



Measured memory_bytes: 11852
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 100000
#define WEIGHT 10000

int check(long long mid, int n, int k, int weight[]){
	int i=0;
	long long tmp;
	
	for(int j=0;j<k;j++){ //トラックがある限り
		tmp=0;
		while(tmp+weight[i]<=mid){
			tmp+=weight[i];
			i++;
			if(i==n)return n;
		}
	}
	
	return i;
}

int main(){
    int k; //荷物数
	int track; //トラック
	int weight[M]; //荷物の重さ
	long long left=0,right=M*WEIGHT,mid; //探査用変数
	int tmp;
	
	scanf("%d %d",&k,&track);
	
	for(int i=0;i<k;i++){
		scanf("%d",&weight[i]);
	}
	
	while(right-left>1){
		mid=(left+right)/2;
		tmp=check(mid,k,track,weight);
		if(tmp>=k){
			right=mid;
		}else{
			left=mid;
		}
	}
	
	tmp=right;
	
	printf("%d\n",tmp);
	
    return 0;
}


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

string kind = "ABCDEFG";

vector<vector<pair<int,int>>> fig = {
    {{ 1, 0}, { 0, 1}, { 1, 1}}, //A
    {{ 0, 1}, { 0, 2}, { 0, 3}}, //B
    {{ 1, 0}, { 2, 0}, { 3, 0}}, //C
    {{-1, 1}, { 0, 1}, {-1, 2}}, //D
    {{ 1, 0}, { 1, 1}, { 2, 1}}, //E
    {{ 0, 1}, { 1, 1}, { 1, 2}}, //F
    {{ 1, 0}, {-1, 1}, { 0, 1}}  //G
};

int main() {
    int v[8][8];
    while (1) {
        char c;
        rep(i,8) rep(j,8) {
            if ( ! (cin >> c)) return 0;
            v[i][j] = c - '0';
        }
        rep(i,8) rep(j,8) {
            if ( ! v[i][j]) continue;
            rep(k,(int)fig.size()) {
                bool ok = true;
                for (auto p : fig[k]) {
                    int x = j + p.first;
                    int y = i + p.second;
                    if (x < 0 || 8 <= x || y < 0 || 8 <= y || ! v[y][x]) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    cout << kind[k] << endl;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1180
def main():
    """
    1 <= N  <= 10^5
    2 <= M  <= 10^9
    1 <= Ai <= 10^9
    1 <= i  <= N

    1 <= l <= r  <= N
    A_l + A_l+1 + ... + Ar = x * M
    """
    N, M = map(int, input().split())
    *A, = map(int, input().split())

    # ans = f(N, M, A)
    ans = editorial(N, M, A)
    print(ans)


def f(N, M, A):
    """
    直感: 累積和, 10^5^2: TLE
        二分探索?
    """
    b = [0] * N
    b[0] = A[0]
    for i in range(1, N):
        b[i] = b[i-1] + A[i]

    ans = TLE(N, M, A, b)
    return ans


def editorial(N, M, A):
    """
    """
    b = [0] * (N + 1)
    for i in range(N):
        b[i+1] = b[i] + A[i]
    c = [x % M for x in b]

    ans = 0
    m = {}
    c = [x % M for x in b]
    for x in c:
        if not x in m:
            m[x] = 0
        else:
            ans += m[x]
        m[x] += 1

    return ans


def TLE(N, M, A, b):
    ans = 0
    for l in range(N):
        for r in range(l, N):
            if l - 1 < 0:
                s = b[r]
            else:
                s = b[r] - b[l-1]
            if s % M == 0:
                ans += 1

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 20036
N = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(0, N):
    min_A = A[i]
    for j in range(i, N):
        if A[j] < min_A:
            min_A = A[j]
            num = j
    if min_A < A[i]:
        v = A[i]
        A[i] = min_A
        A[num] = v
        count += 1

s = [str(a) for a in A]
s = " ".join(s)
print(s)
print(count)



Measured memory_bytes: 5604
#include<stdio.h>
int main(){
  int a,b,sum,n,m;

  while(scanf("%d %d",&a,&b)!=EOF){
    sum=a+b;
    m = 1;
    for ( n = 1; n <= 1000000; n = n*10){
      if(n<=sum && sum<n*10){printf("%d\n", m);}
      m = m+1;
    }
    
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int D = scan.nextInt();
		int G = scan.nextInt();

		int[] p = new int[D];
		int[] c = new int[D];

		for (int input = 0; input < D; input++) {
			p[input] = scan.nextInt();
			c[input] = scan.nextInt();
		}

		int total;
		int positionCount;
		int numberOfProblems;
		int zeroposition;
		int min = (int)Math.pow(2, 30);

		for (int bit = 0; bit < Math.pow(2, D); bit++) {

			total = 0;
			positionCount = 0;
			numberOfProblems = 0;
			zeroposition = -1;

			for (int shift = 0; shift < D; shift++) {		//全ビット探索：1が+を入れることに対応

				if ((1&bit>>shift) == 1) {
					total += 100*(positionCount+1) * p[positionCount] + c[positionCount];
					numberOfProblems += p[positionCount];
				} else {
					zeroposition = positionCount;
				}

				positionCount++;

			}
				
			if (total < G) {
				if (100*(zeroposition+1)*(p[zeroposition]-1) >= G - total) {
					numberOfProblems += Math.ceil((double) (G - total) / (100*(zeroposition+1)));
				} else {
					continue;
				}
			}
			
			if (min > numberOfProblems) {
				min = numberOfProblems;
			}

		}

		System.out.println(min);

	}
}

Measured memory_bytes: 23764
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8").split(' ');

const five = input.filter(x => {
    return parseInt(x) === 5;
});

const seven = input.filter(x => {
    return parseInt(x) === 7;
});

if (five.length === 2 && seven.length === 1) {
    console.log('YES');
} else {
    console.log('NO');
}


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
vector<int> arr(MAXX);
void trozen()
{
    int n;
    cin>>n;
    int ans=n/10;
    if(n%2)
    {
        cout<<0<<endl;
        return;
    }
    for(int i=50;(n/i)>=1;i*=5)
    {
            ans+=(n/i);
    }
        cout<<ans<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


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

int main() {
	ll N;
	cin >> N;
  
    const ll MOD = 1000000007;
    ll ans1=1;
  	for(ll i=1; i<=N; ++i) {
        ans1 *= 10;
        ans1 %= MOD;
    }
    ll ans2=1;
    for(ll i=1; i<=N; ++i) {
        ans2 *= 9;
        ans2 %= MOD;
    }
    ll ans3=1;
    for(ll i=1; i<=N; ++i) {
        ans3 *= 8;
        ans3 %= MOD;
    }

    ll ans = ans1-ans2-ans2+ans3;
    ans %= MOD;
    ans = (ans+MOD)%MOD;

    cout << ans << endl;
  
    return 0;
}


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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int N = input(), M = input();

    vector< i64 > div;
    for (i64 i = 1; i * i <= M; i += 1) {
        if (M % i == 0) {
            div.push_back(i);
            div.push_back(M / i);
        }
    }

    rwhole(sort, div);
    for (auto d: div) {
        if (d * N <= M) {
            cout << d << endl;
            return;
        }
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
vector<int> A(1);

bool found(int x){
	for(int i = 0; i < x; i++)
		if(A[i] == A[x]) return true;
	return false;
}

int main(void){
	//IO("test.in", "test.out");
	scanf("%d", &A[0]);
	while(!found(A.size() - 1))
		if(A[A.size() - 1] % 2 == 0) A.push_back(A[A.size() - 1] / 2);
		else A.push_back(A[A.size() - 1] * 3 + 1);
	printf("%d\n", A.size());
}

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

using namespace std;

int main(){
	int n, cnt = 1;
	scanf("%d", &n);
	char s [n];
	scanf("%s", s);
	char prev = s[0];
	for (int i = 1; i < n; ++i){
		if(prev != s[i]){
			cnt++;
			prev=s[i];
		}
	}
	printf("%d", cnt);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    ll K;
    cin >> N >> K;
    ll A[N];
    vector<ll> B;
    vector<ll> C;
    ll z = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 0) z++;
        else if (A[i] < 0) B.push_back(A[i]);
        else C.push_back(A[i]);
    }
    ll nb = B.size();
    ll nc = C.size();
    ll f0 = B.size() * C.size();
    ll f1 = f0 + z * (B.size() + C.size()) + (z * (z - 1)) / 2;
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    if (K <= f0) {
         ll l = -1e18 - 1ll;
         ll r = 0;
         while (r - l > 1) {
             ll m = (l + r) / 2;
             ll sum = 0;
             int j = nc - 1;
             for (int i = B.size() - 1; i >= 0; i--) {
                 while (j >= 0 && B[i] * C[j] <= m) j--;
                 sum += nc - 1 - j;
             }
              //cout << sum << " " << m << "\n";
             if (sum < K) l = m;
             else r = m;
         }
         
         cout << r << "\n";
    } else if (K <= f1) {
        cout << "0\n";
    } else {
        ll l = 0;
        ll r = 1e18 + 1ll;
        while (r - l > 1) {
            ll m = (l + r) / 2;
            ll sum = f1;
            int j = nb - 1;
            for (int i = 0; i < nb - 1; i++) {
                while (j >= 0 && B[i] * B[j] <= m) j--;
                sum += min((int)nb - j - 1, (int)nb - i - 1);
            }
            
            j = 0;
            for (int i = nc - 1; i >= 1; i--) {
                while (j < nc && C[i] * C[j] <= m) j++;
                sum += min(i, j);
            }
            // cout << sum << " " << m << "\n";
            if (sum < K) l = m;
            else r = m;
        }
        cout << r << "\n";
    }
    return 0;
}

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

ll n;

int main(){
  cin >> n;
  cout << (n * (n - 1)) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}

int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a,b;
    cin>>a>>b;
    for(int i=1;i<1251;i++){
        int a1=(i*8)/100,b1=i/10;
        if(a1==a&&b1==b){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;

	return 0;
}


Measured memory_bytes: 256
h,w = gets.chomp.split(" ").map{|i| i.to_i}

ans = []

h.times do |i|
	line = gets.chomp
	if line =~ /snuke/ then
		ans[0] = (line.index("snuke")/6.0).ceil
		ans[1] = i+1
		break
	end
end

puts "#{("A".."Z").to_a[ans[0]]}#{ans[1]}"

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int MOD = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y, int md = MOD){x += y; if(x >= md) x -= md;}
void sub_self(int &x, int y, int md = MOD){x -= y; if(x < 0) x += md;}
void mul_self(int &x, int y, int md = MOD){x = x * 1LL * y % md;}
inline int mul(int x, int y, int md = MOD){return x * 1LL * y % md;}
inline int add(int x, int y, int md = MOD){x += y; if(x >= md) x -= md; return x;}
inline int sub(int x, int y, int md = MOD){x -= y; if(x < 0) x += md; return x;}

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

vector<int> read(int n, int k){
	vector<int> vec(n);
	for(int i = 0; i < k; ++i) cin >> vec[i];
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for(int i = k; i < n; ++i)
		vec[i] = (a * 1ll * vec[i - 2] + b * 1ll * vec[i - 1] + c) % d;
	return vec;
}

int dp[2002];

int check(int sum){
	if(sum == 0) return 1;
	int& res = dp[sum];
	if(res != -1) return res;
	res = 0;
	for(int i = 3; i <= sum; ++i){
		add_self(res, check(sum - i));
	}
	return res;
}

void solve(){

	int s;
	cin >> s;
	memset(dp, 0xff, sizeof dp);
	cout << check(s) << '\n';

	return;
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("input.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": ";
		solve();
		// cout << '\n';
		// cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3640
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	vector<int> res = { 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 };
	int k; cin >> k;
	cout << res[k - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,M;
cin>>N>>M;
vector<int>s(M);
vector<int>c(M);
vector<int>answer(N);
vector<bool>h(N);
bool a=false;
if(M==0){
    if(N==1){
        cout<<0<<endl;
    }
    else{
    cout<<1;
    for(int i=0; i<N-1; i++){
        cout<<0;
    }
    cout<<""<<endl;
}
}
else{
    bool z=false;
for(int i=0; i<M; i++)
{
    cin>>s.at(i);
    cin>>c.at(i);
    if(c.at(i)!=0){
        z=true;
    }
    if(h.at(s.at(i)-1)==true&&answer.at(s.at(i)-1)!=c.at(i)&&c.at(i)!=0){
        a=true;
    }
  else if(c.at(i)==0&&s.at(i)==1){
    a=true;
  }
    answer.at(s.at(i)-1)=c.at(i);
    h.at(s.at(i)-1)=true;
}
if(z==true){
if(a==false){
if(answer.at(0)==0){
    answer.at(0)=1;
}
for(int i=0; i<N; i++){
cout<<answer.at(i);
}
cout<<""<<endl;
}
else
{
    cout<<-1<<endl;
}
}
else
{
    bool g=false;
    for(int i=0; i<M; i++){
        if(s.at(i)==1){
        }
        else
        g=true;
    }
    if(g==true||N==1){
   if(N==1){
        cout<<0<<endl;
    }
    else{
    cout<<1;
    for(int i=0; i<N-1; i++){
        cout<<0;
    }
    cout<<""<<endl;
    }
}
else
cout<<-1<<endl; 
}

}
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
    using namespace std;
    #define MX 1000006
    vector<int>vec;
    int main()
    {
        double a,b,f=0,j,k,sum,ans,n,odd,even;
        int t;
        string s,s1;
        cin>>t;
        for(int i=1;i<=t;i++)
        {
            if(i%2==0)
                even++;
            else
                odd++;
        }
       // cout<<odd<<"\n";
        if(t%2==0)
        printf("%.10lf\n",even/t);
        else
        printf("%.10lf\n",odd/t);
 
 
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const ll LINF = 1LL << 60;
    const ll SMAX = 2500;
    using plpll = pair<ll,pll>;
    auto makep = [](const ll time,const int to,const int sil) {
        return make_pair(time,make_pair(to,sil));
    };

    ll N, M;
    cin >> N >> M;
    ll S; cin >> S;
    vector<vector<plpll>> g(N);
    REP(i,M) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        ll toll, t;
        cin >> toll >> t;
        g[u].push_back(makep(t,v,toll));
        g[v].push_back(makep(t,u,toll));
    }
    vector<ll> C(N),D(N);
    REP(i,N) cin >> C[i] >> D[i];

    S = min(S,SMAX);
    vector<vector<ll>> dp(N,vector<ll>(SMAX+5,LINF));
    dp[0][0] = 0;

    priority_queue<plpll,vector<plpll>,greater<plpll>> dj;

    dj.push(makep(0,0,S));

    while(!dj.empty()) {
        plpll p = dj.top(); dj.pop();
        ll time = p.first;
        ll cnt = p.second.first;
        ll sil = p.second.second;
        if (dp[cnt][sil] < time) continue;
        
        // 1回分交換を追加
        if (sil + C[cnt] <= SMAX) {
            ll sc = sil+C[cnt];
            ll tc = time + D[cnt];
            if (dp[cnt][sc] > tc) {
                dp[cnt][sc] = tc;
                dj.push(makep(tc,cnt,sc));
            }
        }

        // 辺を通る
        for(auto p2:g[cnt]) {
            ll time2 = time + p2.first;
            ll to = p2.second.first;
            ll sil2 = sil - p2.second.second;
            if (sil2 < 0) continue;
            if (dp[to][sil2] > time2) {
                dp[to][sil2] = time2;
                dj.push(makep(time2,to,sil2));
            }
        }
    }

    FOR(i,1,N) {
        ll ans = LINF;
        REP(j,SMAX) ans = min(ans,dp[i][j]);
        OUT(ans)
    }

    return 0;
}

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

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

    int odd, even;

    if( K % 2 ){
        odd = K / 2 + 1;
        even = K / 2;
    } else {
        odd = K / 2;
        even = K / 2;
    }

    cout << odd * even << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;
#define pi 3.141592653589

signed main(){
    quickie
    int n, k ;
    cin >> n >> k ;
    int y = k ;
    int a[n+1] ;
    mi m ;
    rep(i, 1, n+1) {
        cin >> a[i] ;
    }    
    vi v ;
    int curr = 1, x = 0;
    while(1) {
        v.pb(curr) ;
        m[curr]++ ;
        curr = a[curr] ;
        x++ ;
        if(m[curr] != 0) {
            break ;
        }
    }
    int xx ;
    rep(i, 0, v.size()) {
        if(v[i] == curr) {
            xx = i ;
            break ;
        }
    }
    int l = x-xx ;
    k -= (x) ;
    k %= l ;
    rep(i, 0, k) {
        curr = a[curr] ;
    }
    int p = 1 ;
    if(y < x) {
        rep(i, 0, y) {
            p = a[p] ;
        }
        cout << p << "\n" ;
        return 0;
    }
    cout << curr << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

Measured memory_bytes: 18536
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n; cin>>n;
	int c = 0;
	rep(i, n){
		string s;
		cin>>s;
		if(s[0]=='Y') c++;
	}
	if(c) cout<<"Four"<<endl;
	else cout<<"Three"<<endl;
	return 0;
}


Measured memory_bytes: 764
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        string[] S = new string[N];
        for(int i = 0; i < N; i++)
        {
            S[i] = Console.ReadLine();
        }
        Array.Sort(S);
        string ans = "";
        for (int i = 0; i < N; i++)
            ans += S[i];
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11360
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MX=3*1e5+100;
const long long INF = 1e18;
int N, M, k;
int arr[MX];
int p[MX];
int is[MX];
int main()
{
    for(int i=2;i<=1e5;i++)
    {
        if(p[i]) continue;
        for(int j=2*i;j<=1e5;j+=i)
            p[j]=1;
    }
    p[0]=p[1]=1;
    for(int i=1;i<1e5+1;i++)
        if(p[i] == 0 && p[(i+1)/2] == 0) is[i]=1;
    for(int i=1;i<1e5+1;i++) is[i]+=is[i-1];
    int q;
    scanf("%d", &q);
    while(q--)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        cout<<is[r]-is[l-1]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}



bool isOK(ll mid,ll key,ll a,ll b){
  string strmid = to_string(mid);
  
  if(a*mid + b*strmid.size() > key) return true;
  else return false;
}
 
int binary_search(ll key,ll a,ll b){
    int left = 0; 
    int right = 1e9+1; 
    
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key,a,b)) right = mid;
        else left = mid;
    }

    return left;
}




int main(){
  ll a,b,c,d; cin >> a >> b >> c >> d;
  
  cout << min(a,b) + min(c,d) << endl;
  
  
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>


using namespace std;

#define  INF (1<<29)

void warshall_floyd(int n, int matrix[201][201]){ 
    // nは頂点数,matrixにはグラフの距離を格納した2次元配列（隣接行列）
    // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）
    for (int i = 0; i < n; i++)      // 経由する頂点
      for (int j = 0; j < n; j++)    // 開始頂点
        for (int k = 0; k < n; k++)  // 終端
          matrix[j][k] = min(matrix[j][k], matrix[j][i] + matrix[i][k]);
}

int main(){
    int N,M,R;
    int r[9];
    int matrix[201][201];
    scanf("%d %d %d", &N, &M, &R);
    for(int i=0;i<R;i++) scanf("%d",&r[i]);
    for(int i=0;i<R;i++) r[i] = r[i]-1;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
        if(i!=j) matrix[i][j] = INF; 
        else matrix[i][j] = 0;
        }
    }
    for(int i=0; i<M; i++){
        int A,B,C;
        scanf("%d %d %d",&A,&B,&C);
        if(matrix[A-1][B-1]>C) matrix[A-1][B-1] = matrix[B-1][A-1] = C;
    }

    warshall_floyd(N, matrix);
    
    int result = INF;
    sort(r,r+R);
    do{ 
        int buf = 0;
        for(int i=0;i<R-1; i++) buf += matrix[r[i]][r[i+1]]; 
        if(result > buf) result = buf;
    } while(next_permutation(r, r+R));   // 次の順列を生成
    printf("%d",result);
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100010;

int n, m;
vector<int> g[N];
bool vis[N];
int dp1[N], dp2[N];

void dfs1(int u) {
  vis[u] = true;
  dp1[u] = 1;
  for (int v : g[u])
    if (!vis[v]) {
      dfs1(v);
      dp1[u] = dp1[u] * (ll)(dp1[v] + 1) % m;
    }
}

void dfs2(int u) {
  int sz = g[u].size() + 2;
  vis[u] = true;
  vector<int> pre(sz), suf(sz);
  pre[0] = 1;
  suf[sz - 1] = 1;
  for (int i = 1; i < sz - 1; ++i)
    pre[i] = pre[i - 1] * (ll)(1 + (vis[g[u][i - 1]] ? 0 : dp1[g[u][i - 1]])) % m;
  for (int i = sz - 2; i; --i)
    suf[i] = suf[i + 1] * (ll)(1 + (vis[g[u][i - 1]] ? 0 : dp1[g[u][i - 1]])) % m;
  for (int i = 0; i < sz - 2; ++i) {
    int v = g[u][i];
    if (!vis[v]) {
      dp2[v] = (pre[i] * (ll)suf[i + 2] % m * dp2[u] % m + 1) % m;
      dfs2(v);
    }
  }
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &n, &m);
  for (int rep = 1; rep < n; ++rep) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs1(1);
  dp2[1] = 1;
  memset(vis, 0, sizeof(vis));
  dfs2(1);
  for (int i = 1; i <= n; ++i)
    printf("%d\n", int(dp1[i] * (ll)dp2[i] % m));

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 16512
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <iostream>
#include <sstream>
using namespace std;
#define INF INT_MAX>>1


int main()
{   
    // freopen("in","r",stdin);
    int n;
    while(scanf("%d",&n)&&n){
        int u,v,w,max_v=0;
        int g[15][15];
        memset(g,0x3f3f,sizeof(g));
        for(int i=0;i<n;i++){
            scanf("%d %d %d",&u,&v,&w);
            g[u][v]=g[v][u]=w;
            max_v = max(max_v,u);
            max_v = max(max_v,v);
        }  

        for(int k=0;k<=max_v;k++){
            for(int i=0;i<=max_v;i++){
                for(int j=0;j<=max_v;j++){
                    if(g[i][k]+g[k][j]<g[i][j])
                        g[i][j] = g[i][k]+g[k][j];
                }
            }
        }
        int ans_sum = INF,ans_i;
        for(int i=0;i<=max_v;i++){
            int sum = 0;
            for(int j=0;j<=max_v;j++){
                if(i!=j){
                    sum += g[i][j];
                }
            }
            if(sum < ans_sum){
                ans_sum = sum;
                ans_i = i;
            }
        }
        printf("%d %d\n",ans_i,ans_sum);
    }
    return 0;
}

Measured memory_bytes: 1184
N , K = gets.split.map!{|n| n.to_i}
t = Array.new(N)

for i in 1..N
    t[i-1] = gets.split.map!{|n| n.to_i}
end

t = t.sort{|a , b| -a[1] <=> -b[1]}

max = 0
variety = Hash.new(0)
t.each_with_index do |value , index|
    if index < K
        value[2] = variety[value[0]]
        variety[value[0]] += 1
        max += value[1]
    end
end

max += variety.size ** 2
a = max

for i in 1..K
    if t[K-i][2] == 0
        next
    end

    while K < t.size && variety[t[K][0]] != 0
        t.delete_at(K)
    end

    if K >= t.size
        break
    end

    a += t[K][1] - t[K-i][1] + 2 * variety.size + 1
    if max < a
        max = a 
    end
    variety[t[K][0]] += 1

end

puts max

Measured memory_bytes: 14312