akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	final static String EVENT_HIT = "HIT";
	final static String EVENT_HOMERUN = "HOMERUN";
	// final static String EVENT_OUT = "OUT";

	static Main main = new Main();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String event = "";

		int n = Integer.parseInt(br.readLine());
		for (int i = 0; i < n; i++) {
			Inning inning = main.new Inning(0);
			while ((event = br.readLine()) != null) {
				if (event.equals(EVENT_HIT)) {
					inning.singleHit();
				} else if (event.equals(EVENT_HOMERUN)) {
					inning.homeRun();
				} else {
					inning.out();
					if (inning.outs == 3) {
						System.out.println(inning.run);
						break;
					}
				}
			}
		}
	}

	class Inning {

		int diamond;
		int outs;
		int run;

		Inning(int run) {
			diamond = 0;
			outs = 0;
			this.run = run;
		}

		void singleHit() {
			diamond <<= 1;
			diamond |= 1;
			if ((diamond & 8) > 0) {
				run++;
				diamond &= 7;
			}
		}

		void homeRun() {
			for (int i = 0; i < 3; i++) {
				diamond <<= 1;
				if ((diamond & 8) > 0)
					run++;
			}
			run++;
			diamond = 0;
		}

		void out() {
			outs++;
		}
	}
}

Measured memory_bytes: 15040
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

	VAR(int, n, m);
	VEC(int, x, n);
	VEC(int, y, m);
	sort(ALL(x)); sort(ALL(y));
	
	int sm_x = 0, sm_y = 0;
	REP(i, n - 1) {
		(sm_x += (x[i + 1] - x[i]) * (i + 1) * (n - i - 1)) %= MOD;
		debug(sm_x);
	}
	REP(i, m - 1) {
		(sm_y += (y[i + 1] - y[i]) * (i + 1) * (m - i - 1)) %= MOD;
		debug(sm_y);
	}
	int ans = (sm_x * sm_y) % MOD;
	OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  unordered_map<string, long long> ana;
  for(int i = 0; i < n; ++i){
    cin >> s;
    sort(s.begin(), s.end());
    ana[s]++;
  }
  long long ans = 0;
  for(auto m: ana){
    ans += m.second * (m.second - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 10660
def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = min(a) + min(b)
    for _ in range(M):
        x, y, c = map(int, input().split())
        ans = min(ans, a[x-1] + b[y-1] - c)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65900
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int rec( int i, const vector<int>& h, vector<int>* memo )
{
    if ( i == 1 ) return 0;
    if ( i == 2 ) return abs( h[ i - 1 ] - h[ i - 2 ] );

    if ((*memo)[i] != -1) return (*memo)[i];

    int cost1 = abs( h[ i - 1 ] - h[ i - 2 ] );
    int cost2 = abs( h[ i - 1 ] - h[ i - 3 ] );

    return (*memo)[i] = min( rec( i - 1, h, memo ) + cost1, rec( i - 2, h, memo ) + cost2 );
}

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

    vector<int> h( N );
    for ( int i = 0; i < N; ++i ) cin >> h[ i ];

    vector<int> memo( N + 1, -1 );
    cout << rec( N, h, &memo ) << endl;
}

Measured memory_bytes: 4096
#include "bits/stdc++.h"
using namespace std;

const int N=2e5+20,MAX=1e6+20;

int n,x,f[MAX],dp[MAX];

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&x),f[x]++;

	for(int i=1;i<MAX;i++)
		for(int j=i;j<MAX;j+=i)
			if(f[j]) dp[j]+=f[i];
	int ans=0;
	for(int i=1;i<MAX;i++)
		if(dp[i] and dp[i]==f[i] and f[i]==1) ans+=dp[i];
	printf("%d",ans);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

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

    vector<int> X(N, 1);
    set<int> R;
    R.insert(0);
    REP(i,M){
        int x, y;
        cin >> x >> y;
        x--, y--;
        X[y]++;
        X[x]--;
        if(R.find(x) != R.end()){
            R.insert(y);
            if(X[x] == 0){
                R.erase(x);
            }
        }
    }

    int ans = R.size();
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    for (int x = 0; x <= n; x++)
    {
        if (int(x * 1.08) == n)
        {
            cout << x << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    p[i] = -~p[i] / 2
ans = v = sum(p[:k])
for i in range(n - k):
    v = v - p[i] + p[k + i]
    ans = max(ans, v)
print(ans)


Measured memory_bytes: 24556
#include <iostream>

using namespace std;

int main() {
    long n, amari = 1e9 + 7, power = 1;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        power *= i;
        // cout << power;
        /*if (power > amari) {
            power %= amari;
            cout << ", " << power << endl;
            return 0;
        }*/
        power %= amari;
        // cout << ", " << power << endl;
    }

    cout << power << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<double> arr(n+1,-1);
    for (int i=1; i<=n; i++)
        cin>>arr[i];
    vector<vector<double> > dp(n+1,vector<double>(2*n+3,0));
    dp[0][n+1]=1.0;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=(2*n)+1; j++)
            dp[i][j]=(j<=(2*n))*1.0*dp[i-1][j+1]*(1-arr[i])+(j>1)*1.0*dp[i-1][j-1]*arr[i];
    double ans=0;
    for (int i=n+2; i<=(2*n)+1; i++)
        ans+=dp[n][i];
    cout<<setprecision(50)<<fixed;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 141056
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }
template<typename V> void printVec(V v) {ll i=0;for(auto x : v){std::cout << " [" << i++ << "] " << x;} print();}

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

  ll N = 3;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  std::sort(va.begin(), va.end());
  ll ans = INF;
  do {
    ll cost = 0LL;
    for (ll i = 1; i < N; i++) {
      cost += std::fabs(va[i] - va[i-1]);
    }
    ans = std::min(ans, cost);
  } while (std::next_permutation(va.begin(), va.end()));

  print(ans);
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int w, h, n;
    cin >> w >> h >> n;
    vector<bool> row(w), col(h);
    rep (i, n) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            rep (j, x) row[j] = true;
        } else if (a == 2) {
            FOR (j, x, w) row[j] = true;
        } else if (a == 3) {
            rep (j, y) col[j] = true;
        } else {
            FOR (j, y, h) col[j] = true;
        }
    }
    int vx = 0, vy = 0;
    rep (i, w) {
        if (!row[i]) vx++;
    }
    rep (i, h) {
        if (!col[i]) vy++;
    }
    cout << vx * vy << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int k;
    cin >> k;
    int even = k/2, odd = (k-1)/2+1;
    cout << even*odd << endl;
    return 0;
}

Measured memory_bytes: 256
s=input()
s=list(s)
t=input()
n=len(s)
m=len(t)
ind=-1 
def ok(a,b):
    for i in range(len(a)):
        if a[i]=='?':
            pass 
        else:
            if a[i]!=b[i]:
                return 0 
    return  1 
for i in range(n-m+1): 
    if ok(s[i:i+m],t):
        ind=i 
if ind==-1:
    print('UNRESTORABLE')
else: 
    s[ind:ind+m]=t  
    for i in range(len(s)):
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))

Measured memory_bytes: 38384
r,g,b,n = map(int,input().split())

ans = 0

num = [r,g,b]
#print(num)
num.sort()
#print(num[0],num[1])
#exit()

for i in range(n+1):
    if i * num[2] > n:
        break
    for j in range(n+1):
        #if i + j >= n:
            #ans = ans + 1
        #    break
        if (n - i*num[2] - j*num[1]) < 0:
            break
        if (n - i*num[2] - j*num[1]) % num[0] == 0:
            ans = ans + 1

print(ans)

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    if(n * a < b){
        cout << n * a << endl;
    }else{
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(int a, int b){
   return b ? GCD(b, a%b) : a;
}

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

int main(){
   int n, q;
   string s;
   cin >> n >> q >> s;
   vector<int> l(q), r(q);
   for(int i = 0; i < q; i++){
      cin >> l[i] >> r[i];
   }

   // TODO
   // 愚直に線形探索しては間に合わない。
   // 文字列の部分集合の個数を求めるような問題では
   // 累積和を用いることを考える

   // 愚直解(TLE)
//   for(int i = 0; i < q; i++){
//      int cnt = 0;
//      string subst = s.substr(l[i]-1, r[i] - l[i]+1);
//      for(int j = 0; j < subst.size(); j++){
//         if(subst[j] == 'A' and subst[j+1] == 'C'){
//            cnt++;
//         }
//      }
//      cout << cnt << endl;
//   }

   // 累積和
   vector<int> sum(n+1, 0);   // sum[0] = 0
   for(int i = 0; i < n; i++){
      if(i+1 < n and s[i] == 'A' and s[i+1] == 'C'){
         sum[i+1] = sum[i] + 1;
      }
      else{ // last index
         sum[i+1] = sum[i];
      }
   }

   for(int i = 0; i < q; i++){
      r[i]--, l[i]--;
      cout << sum[r[i]] - sum[l[i]] << endl;
   }

   return 0;
}

Measured memory_bytes: 2176
import sys
input = sys.stdin.readline
A, B = [int(x) for x in input().split()]
S = input().rstrip()
if S[A] != "-":
    print("No")
    sys.exit()
if "-" in S[:A] or "-" in S[A+1:]:
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 3060
import java.util.*;

class Main {
    public static void main(String args[]){

        Scanner s=new Scanner(System.in);
        Integer n= s.nextInt();
        int count=0;
        Map<Integer,Integer> a=new HashMap<>();
        for (int i = 0; i <100 ; i++) {
            a.put(i,0);
        }
        for (int i = 1; i <=n ; i++) {
            //さいしょのもじ
            int ns=String.valueOf(i).charAt(0)-'0';
            int nf=i%10;
            int and=nf+ns*10;

            // jibun
            if(ns==nf){count++;}
            // gyaku
            int bnd=nf*10+ns;
            count+=a.get(bnd)*2;
            a.put(and,a.get(and)+1);

        }
        System.out.println(count);
    }

}

Measured memory_bytes: 38692
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

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

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

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	nongetpop(array,&(*size));
	return temp;
}

int nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
	int cnt[259] = { 0 };
	char str[30];
	scanf("%s",str);
	for (int i = 0; i < strlen(str); ++i)	++cnt[(int)str[i]];
	for (int i = 'a'; i <= 'z'; ++i){
		if(cnt[i] > 1){
			puts("no");
			return 0;
		}
	}
	puts("yes");
	return 0;
}

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

int main(){
	int n,k; cin>>n>>k;
	int ans=1;
	rep(i,n){
		if(ans*2<ans+k) ans*=2;
		else ans+=k;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;

namespace Sort
{
    class Program
    {

        static void Main(string[] args)
        {
            List<int> i = Console.ReadLine().Split(' ')
                    .Select(e => int.Parse(e)).ToList();
            
            i.Sort();

            Console.WriteLine("{0} {1} {2}", i[0], i[1], i[2]);
        }
    }
}

Measured memory_bytes: 9664
import java.util.*;
public class Main
{
  public static void main(String[] args)
  {
    Scanner s=new Scanner(System.in);
    String st1=s.next();
    String st2=s.next();
    int a=s.nextInt();
    int b=s.nextInt();
    String st3=s.next();
    if(st3.equals(st1))
      a--;
    else
      b--;
    System.out.println(a+" "+b);
  }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define int 		  long long
#define	pb 			  push_back
#define all(a)		  (a).begin(),(a).end()
#define sz(x)		  (int)x.size()
#define endl	 	  "\n"
#define inf 		  1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)

mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers.

//int dp[1000001] = {0};


void solve(){
	int n, cnt=0;
	cin>>n;
	if(n<3){
		cout<<'0'<<endl;
		return;
	}
	string s;
	cin>>s;

	FOR(i, 0, n-2){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') cnt++;
	}
	cout<<cnt<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
	//	cout<<"Case #"<<i<<":"<<endl;
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}

Measured memory_bytes: 256
import math
n = int(input())

a = []
b = []

for i in range(n):
  c, d= map(int, input().split())
  a.append(c)
  b.append(d)

a.reverse()
b.reverse()

tot = 0
for i in range(n):
  if (a[i]+tot)%b[i] == 0:
    continue
  x = b[i] - (a[i]+tot)%b[i]
  tot += x
print (tot)

Measured memory_bytes: 16908
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;


signed main() {
  int N;
  cin >> N;
  vector<double> A(N);
  REP(i, N) cin >> A[i];

  double ans = 0;
  REP(i, N) ans += 1.0/A[i];

  printf("%.9lf\n", 1.0/ans);

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

struct UF{
	vector<int>par,sz;
	void init(int n){
		par.resize(n);
		sz.resize(n);
		for(int i=0;i<n;i++){
			par[i]=i;
			sz[i]=1;
		}
	}
	int find(int x){
		return x==par[x]?x:par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		sz[x]+=sz[y];
		par[y]=x;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};

signed main(){
	int N;
	cin >> N;
	vector<int>a(N);
	REP(i,N){
		cin >> a[i];
	}
	vector<int>cnt(100010);
	REP(i,N){
		cnt[a[i]]++;
	}
	int ans = accumulate(ALL(a),0ll);
	int Q;
	cin >> Q;
	REP(_,Q){
		int B,C;
		cin>>B>>C;
		int diff = (C - B) * cnt[B];
		ans += diff;
		cnt[C] += cnt[B];
		cnt[B] = 0;
		out(ans);
	}
}

Measured memory_bytes: 4840
//105 B - Cakes and Donuts 2018/08/11
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n;cin >> n;
    for(int i=0;i<=25;++i){
        for(int j=0;j<=14;++j){
            if(4*i+7*j==n) { cout << "Yes" << endl; return 0;}
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\,
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int l,r,d;
    cin >> l >> r >> d;
    int num = 0;
    for(int i = 1;i<111;i++){
        int ans = d*i;
        if(ans >= l && ans <=r) num++;
    }
    cout << num << endl;

}

Measured memory_bytes: 3632
import collections
n = int(input())
S = list(input())
counterA = collections.Counter(S)
for i in range(1,n):
    counterB = collections.Counter()
    S = list(input())
    counterS = collections.Counter(S)
    for j in counterA.keys():
        if j in counterS:
            counterB[j] = min(counterA[j],counterS[j])
        else:
            counterB[j] = 0
    counterA = counterB
ls = []
for i in counterA.keys():
    for j in range(counterA[i]):
        ls.append(i)
ls.sort()
ans = ''.join(ls)
print(ans)

Measured memory_bytes: 9468
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 int p[] = new int[N];
		 
		 for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 }
		 
		 
		 int p_1;
		 int p_2;
		 int p_3;
		 int cnt = 0;
		 
		 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 }
		 
		 System.out.println(cnt);
		 
		 scan.close();

	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  string s;
  cin >> s;

  cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}


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

const int N = 55;

int n, a[N];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    int x = int(max_element(a + 1, a + n + 1) - a);
    int y = int(min_element(a + 1, a + n + 1) - a);
    if(abs(a[x]) < abs(a[y])) x = y;
    printf("%d\n", 2 * n - 2);
    if(a[x] > 0){
        printf("%d 2\n%d 2\n", x, x);
        for(int i = 2; i < n; i++)
            printf("%d %d\n%d %d\n", i, i + 1, i, i + 1);
    }
    else{
        printf("%d %d\n%d %d\n", x, n - 1, x, n - 1);
        for(int i = n - 1; i > 1; i--)
            printf("%d %d\n%d %d\n", i, i - 1, i, i - 1);
    }
}

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = ii(), ii(), ii(), ii()
    print(min(A, B) + min(C, D))


if __name__ == '__main__':
    main()


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vi a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    int ans = 0, ai = 0, bi = 0;
    ll sum = 0;
    while (sum+a[ai]<=k) {
        sum += a[ai];
        ++ans; ++ai;
        if (ai == n) break;
    }
    while (sum+b[bi]<=k) {
        sum += b[bi];
        ++ans; ++bi;
        if (bi == m) break;
    }
    if (ans == n+m) {
        cout << ans << endl;
        return 0;
    }
    int mx = ans;
    while (ai>0 && bi<m) {
        --ai; --ans;
        sum -= a[ai];
        while (sum+b[bi]<=k) {
            sum += b[bi];
            ++ans; ++bi;
            if (bi == m) break;
        }
        mx = max(mx, ans);
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
	int i, j, k;
	scanf("%d%d", &j, &k);
	if(k == 1) cout << 0;
	else cout << j - k; 
	
	return 0;
}


Measured memory_bytes: 256
require 'prime'

$n = gets.to_i
arr = gets[0..-2].split.map &:to_i

def calc(arr)
  result = []
  $n.times do |i|
    if i == 0
      result << arr[i]
      next
    end

    result << result[i-1].gcd(arr[i])
  end
  result
end
larr = calc(arr)
rarr = calc(arr.reverse).reverse

max = 0
$n.times do |i|
  if i == 0
    max = rarr[1]
    next
  end

  if i == $n-1
    max = [max, larr[-2]].max
    next
  end

  v = larr[i-1].gcd rarr[i+1]
  max = [max, v].max
end
puts max


Measured memory_bytes: 15912
#include <stdio.h>

int cnt[8];

int max(int a, int b){ return a > b ? a : b; }
int min(int a, int b){ return a < b ? a : b; }

int main(){
    int N;
    scanf("%d", &N);
    int free = 0;
    for(int i=0; i<N; i++){
        int x;
        scanf("%d", &x);
        if(x > 3199) free++;
        else cnt[x/400]++;
    }
    int res = 0;
    for(int i=0; i<8; i++) if(cnt[i]) res++;
    printf("%d %d", max(1, res), res+free);
    return 0;
}

Measured memory_bytes: 128
function main()
  
  (H,N) = map(x -> parse(Int,x), split(readline()))
  
  A = map(x -> parse(Int,x), split(readline()))
  
  sum = 0
  
  for i in 1:N
    sum += A[i]
  end
  
  if sum >= H
    println("Yes")
  else
    println("No")
  end
  
end
  
main()

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

int main() {

	int a, b, c, d;

	cin >> a >> b >> c >> d;

	if (a + b > c + d) {
		cout << "Left" << endl;
	}
	else if (a + b == c + d) {
		cout << "Balanced" << endl;
	}
	else {
		cout << "Right" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  char s;                                                                      cin >> s;
  if(s=='A') cout << 'T' << "\n";                                              else if(s=='T') cout << 'A' << "\n";                                         else if(s=='C') cout << 'G' << "\n";                                         else if(s=='G') cout << 'C' << "\n";                                         return 0;                                                                  }

Measured memory_bytes: 3608
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


n = int(input())
count = 0

for i in range(1, n + 1):
    if i % 2 == 1 and len(make_divisors(i)) == 8:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int h, w;
char s, t;
string c[51];
P idx[30];

int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

vector<int> G[100];
int d[110];

void dijkstra(int s){
    fill(d, d + 100, INF);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(d[s], s));
    while(!q.empty()){
        P p = q.top(); q.pop();
        int from = p.second;
        int cost = p.first;
        if(d[from] < cost) continue;
        rep(i, 0, G[from].size()){
            int next = G[from][i];
            // int next = e.to;
            int newCost = cost + 1;
            if(d[next] > newCost){
                d[next] = newCost;
                q.push(P(newCost, next));
            }
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> s >> t;
    rep(i, 0, h) cin >> c[i];
    rep(i, 0, 30) idx[i] = {-1, -1};
    rep(i, 0, h){
        rep(j, 0, w){
            if('A' <= c[i][j] && c[i][j] <= 'Z'){
                idx[c[i][j] - 'A'] = {i, j};
            }
        }
    }
    rep(i, 0, 26){
        if(idx[i].first == -1) continue;
        rep(j, 0, 4){
            int y = idx[i].first + 2 * dy[j];
            int x = idx[i].second + 2 * dx[j];
            if(!contain(y, x)) continue;
            if(c[y][x] == '|'){
                if(j == 2 || j == 3) continue;
            }
            if(c[y][x] == '-'){
                if(j == 1 || j == 0) continue;
            }
            while(1){
                if(!contain(y, x)) break;
                if('A' <= c[y][x] && c[y][x] <= 'Z'){
                    G[i].push_back(c[y][x] - 'A');
                    break;
                }
                if(c[y][x] == '.') break;
                y += dy[j];
                x += dx[j];
            }
        }
    }
    dijkstra(s - 'A');
    cout << d[t - 'A'] << endl;
}



Measured memory_bytes: 3248
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[51];

int main()
{
  scanf("%s", str);
  int n = strlen(str);
  for (int i=0; i<n-8; i++) {
    printf("%c", str[i]);
  }
  return 0;
}

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

int main() {
    int n;cin>>n;
    int ans=1;
    int cc1=0;
    for(int i=1;i<=n;++i){
        int tmp = i;
        int cc = 0;
        while(tmp>0){
            if(tmp%2==0){
                ++cc;
                tmp/=2;
            }
            else break;
        }
        if(cc>cc1){
            cc1=cc;
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pii pair<int,int>
#define pll pair<long,long>
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)
#define adj(N) vector<vector<int>> ADJ(N+1)


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

	READV(P);
	READV(Q);
	READV(R);
	cout<<min({P+Q,R+Q,P+R});

	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  
  int l[n];
  rep(i,n){
    cin >> l[i];
  }
  
  sort(l,l+n);
  int sum = 0;
  for(int i = 0; i < n-1; i++){
    sum += l[i];
  }
  
  if(sum > l[n-1]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
	static class Comp implements Comparator<Integer> {
		@Override
		public int compare(Integer o1, Integer o2) {
			return Integer.compare(o2, o1);
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<Queue<Integer>> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(new PriorityQueue<>(new Comp()));
		}
		for (int i = 0; i < q; i++) {
			switch (sc.nextInt()) {
				case 0:
					list.get(sc.nextInt()).add(sc.nextInt());
					break;
				case 1:
					int t = sc.nextInt();
					if (!list.get(t).isEmpty()) {
						System.out.println(list.get(t).peek());
					}
					break;
				case 2:
					t = sc.nextInt();
					if (!list.get(t).isEmpty()) {
						list.get(t).poll();
					}
					break;
			}
		}
	}
}


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

int minCost(int *arr,int n){

    int first,second,third;
    second = 0;

    for(int i=1;i<n;i++){

        int option1 = abs(arr[i]-arr[i-1]) + second;
        int option2 = (i==1) ? INT_MAX : abs(arr[i]-arr[i-2]) + first;
        third = min(option1,option2);
        first = second;
        second = third;
    }
    return third;
}

int main() {
    
    int n;
    cin>>n;
    int arr[n];

    for(int i=0;i<n;i++) cin>>arr[i];

    cout<<minCost(arr,n);
}


Measured memory_bytes: 4016
H ,W = map(int,input().split())

from collections import deque

S = [input() for i in range(H)]
directions = [[0,1],[1,0],[-1,0],[0,-1]]


counter = 0

#インデックス番号　xが行番号　yが列番号
for x in range(H):
    for y in range(W):
        if S[x][y]=="#":
            continue
         
        que =  deque([[x,y]])
        memory = [[-1]*W for _ in range(H)]
        memory[x][y]=0
       
        while True:
            if len(que)==0:
               break
            h,w = que.popleft()

            for i,k in directions:
                x_new,y_new = h+i,w+k

                if not(0<=x_new<=H-1) or not(0<=y_new<=W-1) :
                    continue
                
                elif not memory[x_new][y_new]==-1 or S[x_new][y_new]=="#":
                    continue

                memory[x_new][y_new] = memory[h][w]+1
                que.append([x_new,y_new]) 
        counter = max(counter,max(max(i) for i in memory))

print(counter)


Measured memory_bytes: 69744
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

vector<vector<int>> dis;
vector<vector<char>> field; 
int INF=1e9;
int H,W;

void bfs(int x, int y){
    //cout<<"bfs"<<endl;
    vector<int> dir_x={1,0,-1,0},dir_y={0,-1,0,1};
    queue<pair<int,int>> Q;
    Q.push(make_pair(x,y));
    dis[y][x]=0;

    while(!Q.empty()){
        //cout<<"while"<<endl;
        pair<int,int> p=Q.front();
        Q.pop();

        x=p.first;
        y=p.second;

        for(int i=0; i<4; i++){
            int nx=x+dir_x[i],ny=y+dir_y[i];
            if(0<=nx && nx<W && 0<=ny && ny<H && field[ny][nx]=='.' && dis[ny][nx]>dis[y][x]+1){
                Q.push(make_pair(nx,ny));
                dis[ny][nx]=dis[y][x]+1;
            }
        }
    }
}

int main(){
    int white_cnt=0,black_cnt=0;

    cin>>H>>W;

    dis.resize(H);
    field.resize(H);

    for(int h=0; h<H; h++){
        dis[h].resize(W);
        for(int w=0; w<W; w++){
            dis[h][w]=INF;
        }

        field[h].resize(W);
    }

    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            cin>>field[h][w];
        }
    }

    bfs(0,0);
    
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            if(field[h][w]=='#'){
            //if(dis[h][w]==INF){
                black_cnt++;
            }else{
                white_cnt++;
            }
        }
    }    
    /*
    cout<<black_cnt<<endl;
    cout<<white_cnt<<endl;
    cout<<dis[H-1][W-1]<<endl;
    */
    if(dis[H-1][W-1]==INF){
        cout<<-1<<endl;
    }else{
        cout<<white_cnt-1-dis[H-1][W-1];
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib> 
using namespace std;
 
int main(){

    stack<int> st;
    string s;
    int a,b;

    while(cin >> s){
        if(s=="+"){
            a=st.top();
            st.pop();
            b=st.top();
            st.pop();
            st.push(a+b);
        }
        else if(s=="-"){
            a=st.top();
            st.pop();
            b=st.top();
            st.pop();
            st.push(b-a);
        }
        else if(s=="*"){
            a=st.top();
            st.pop();
            b=st.top();
            st.pop();
            st.push(a*b);
        }
        else st.push(atoi(s.c_str()));
    }

    cout << st.top() << endl;

    return 0;

} 

Measured memory_bytes: 1200
N=int(input())
xy=[list(map(int,input().split())) for i in range(N-1)]
mod=10**9+7

data=[[] for i in range(N+1)]
for x,y in xy:
    data[x].append(y)
    data[y].append(x)

parent=[-1]*(N+1)
child=[0]*(N+1)

parent[1]=1
que=[1]
while que:
    u=que.pop()
    for v in data[u]:
        if parent[v]==-1:
            parent[v]=u
            que.append(v)
            child[u]+=1

dp=[[1,1] for i in range(N+1)]
que=[]
for i in range(1,N+1):
    if child[i]==0:
        que.append(i)

while que:
    u=que.pop()
    for v in data[u]:
        if parent[u]==v:
            child[v]-=1
            if child[v]==0:
                que.append(v)
            continue
        dp[u][1]=dp[u][1]*dp[v][0]%mod
        dp[u][0]=dp[u][0]*(dp[v][0]+dp[v][1])%mod

print((dp[1][0]+dp[1][1])%mod)

Measured memory_bytes: 92632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int N,M,X;
    scanf("%d%d%d",&N,&M,&X);
    int pos[M];
    rep(i,M){
        scanf("%d",&pos[i]);
    }
    int min1=0,min2=0;
    for(int i=X;i>=0;i--){
        for(int j=0;j<M;j++){
            if(i==pos[j]){
                min1++;
            }else{
                ;
            }
        }
    }
    for(int i=X;i<=N;i++){
        for(int j=0;j<M;j++){
            if(i==pos[j]){
                min2++;
            }else{
                ;
            }
        }
    }
    (min1<min2)?printf("%d",min1):printf("%d",min2);
}


Measured memory_bytes: 1728
#include<stdio.h>
int main(void)
{
    int n, m, i, max, min;
    scanf("%d %d", &n, &m);

    int L[m], R[m];

    for(i = 0; i < m; i++)
        scanf("%d %d", &L[i], &R[i]);

    max = L[0];
    for(i = 0; i < m; i++)
    {
        if(max < L[i])
            max = L[i];
    }

    min = R[0];
    for(i = 0; i < m; i++)
    {
        if(min > R[i])
            min = R[i];
    }
   // printf("%d and %d\n", max, min);
    if(min -max + 1 > 0)
        printf("%d\n", min - max + 1);
    else
        printf("0\n");

    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

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

    LL n,w;

    cin >> n >> w;

    vector<LL> a(n),b(n);

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

    vector<vector<vector<LL>>> dp(n+1,vector<vector<LL>>(n+1,vector<LL>(n*4,0)));
    for(int i = 1; i < n+1; i++){
        for(int j = 1; j < n+1; j++){
            for(int k = 0; k < n*4; k++){
                LL tmp = a[i-1] - a[0];
                if(k - tmp >= 0){
                    if(dp[i-1][j][k] < dp[i-1][j-1][k-tmp] + b[i-1]){
                        dp[i][j][k] = dp[i-1][j-1][k-tmp] + b[i-1];
                    }else{
                        dp[i][j][k] = dp[i-1][j][k];
                    }
                }else{
                    dp[i][j][k] = dp[i-1][j][k];
                }
            }
        }
    }

    LL max = 0;

    for(int i = 0; i < n+1; i++){
        for(int j = 0; j < 4*n; j++){
            if(dp[n][i][j] > max && i*a[0] + j <= w){
                max = dp[n][i][j];
            }
        }
    }
    

    cout << max << endl;
    
    return 0;
}

Measured memory_bytes: 32896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int n = Integer.parseInt(str);

		System.out.println(fac(n));
	}

	static long fac(int n){
		if(n==0){
			return 1;
		}else{
			return n*fac(n-1);
		}
	}

}

Measured memory_bytes: 16856
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K,s=0;
  cin >> K;
  for(int a=1;a<=K;a++){
    for(int b=1;b<=K;b++){
      for(int c=1;c<=K;c++){
        int i=std::gcd(b,c);
        int j=std::gcd(a,i);
        s+=j;
      }
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
typedef vector<int> vec;
int N,K;
vec p,q;
vec mul(const vec &a,const vec &b){
	vec ret(N);
	REP(i,N){
		ret[i]=a[b[i]];
	}
	return ret;
}
vec inv(const vec &v){
	vec ret(N);
	REP(i,N){
		ret[v[i]]=i;
	}
	return ret;
}
vec pwr(vec n,int m){
	vec ret(N);
	REP(i,N)ret[i]=i;
	while(m){
		if(m&1){
			ret=mul(ret,n);
		}
		n=mul(n,n);
		m>>=1;
	}
	return ret;
}
int main(){
	scanf("%d %d",&N,&K);
	K--;
	REP(i,N){
		int pi;
		scanf("%d",&pi);
		pi--;
		p.push_back(pi);
	}
	REP(i,N){
		int qi;
		scanf("%d",&qi);
		qi--;
		q.push_back(qi);
	}
	vec a,b;
	a=pwr(mul(mul(mul(q,inv(p)),inv(q)),p),K/6);
	K%=6;
	if(K==0){
		b=p;
	}else if(K==1){
		b=q;
	}else{
		vec b0=p,b1=q;
		REP(i,K-1){
			b=mul(b1,inv(b0));
			b0=b1;
			b1=b;
		}
	}
	vec ans=mul(mul(a,b),inv(a));
	REP(i,N){
		if(i)putchar(' ');
		printf("%d",ans[i]+1);
	}
	putchar('\n');
}

Measured memory_bytes: 3904
def s():
 import sys
 r=sys.stdin.readline
 for e in iter(r,'0\n'):
  R=[[]for _ in[0]*-~int(e)]
  for _ in[0]*int(r()):
   a,b=map(int,r().split())
   R[a]+=[b];R[b]+=[a]
  for m in R[1][:]:R[1]+=R[m]
  print(len({*R[1]}-{1}))
s()


Measured memory_bytes: 6300
from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')): 
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))

def dict(a):
    d={}
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d

def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bi.bisect_right(a, x)
    if i != len(a):
        return i
    else:            
        return -1

def main():
    try:
        n=I()
        if n<=599:print(8)
        elif n<=799:print(7)
        elif n<=999:print(6)
        elif n<=1199:print(5)
        elif n<=1399:print(4)
        elif n<=1599:print(3)
        elif n<=1799:print(2)
        elif n<=1999:print(1)



    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    #for _ in range(I()):main()
    for _ in range(1):main()




Measured memory_bytes: 9384
#include<stdio.h>

#define N 100

int main(){

  int i,j,k,n,u,v,Adj[N][N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      Adj[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
   
      Adj[u-1][v-1]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d",Adj[i][j]);
      printf(" ");
    }
    printf("%d",Adj[i][j]);
    printf("\n");
  }

  return 0;
  
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,W;
    cin>>n>>W;
    vint w(n+1);
    vint v(n+1);
    REP(i,1,n+1){
	cin>>w[i]>>v[i];
    }
    vector<vector<ll> > dp(n+1,vector<ll>(100001));
    rep(i,n+1){
	rep(j,100001){
	    dp[i][j]=999999999999ll;
	}
    }
    dp[0][0]=0;
    REP(i,1,n+1){
	rep(j,100001){
	    if(j-v[i]>=0){
		dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
	    }
	    else{
		dp[i][j]=dp[i-1][j];
	    }
	}
    }
    int ans=100000;
    while(dp[n][ans]>W){
	ans--;
    }
    cout<<ans<<'\n';    return(0);
}


Measured memory_bytes: 80256