akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int dp[512][512][10][3][2];
char look[512];
int mod;
int len;

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

int memo(int digits, int div, int now, int upd, int same)
{
    int i, j;
    int ans;
    
    if (digits == len){
        return (!div);
    }
    
    if (dp[digits][div][now][upd][same] >= 0){
        return (dp[digits][div][now][upd][same]);
    }
    
    ans = 0;
    if (upd == 2){
        if (digits != len - 1){      // if all digits of number equals to zero, that isn't a zig-zag number
            ans += memo(digits + 1, div * 10 % mod, now, 2, same && (look[digits] - '0') == 0);
            ans %= 10000;
        }
        for (i = now + 1; i <= (same ? look[digits] - '0' : 9); i++){
            ans += memo(digits + 1, (div * 10 + i) % mod, i, 1, same && (look[digits] - '0') == i);
            if (digits != len - 1){ // 1-digit number will be same at two status, up and down
                ans += memo(digits + 1, (div * 10 + i) % mod, i, 0, same && (look[digits] - '0') == i);
            }
            ans %= 10000;
        }
    }
    else if (upd == 0){ //increase
        for (i = now + 1; i <= (same ? look[digits] - '0' : 9); i++){
            ans += memo(digits + 1, (div * 10 + i) % mod, i, upd ^ 1, same && (look[digits] - '0') == i);
            ans %= 10000;
        }
    }
    else {              //decrease
        for (i = min(now - 1, same ? look[digits] - '0' : now - 1); i >= 0; i--){
            ans += memo(digits + 1, (div * 10 + i) % mod, i, upd ^ 1, same && (look[digits] - '0') == i);
            ans %= 10000;
        }
    }
    
    return (dp[digits][div][now][upd][same] = ans % 10000);
}

int ZigZag(char *str)
{
    int len = strlen(str);
    int up;
    int i;
    
    if (len == 1){
        return (1);
    }
    if (len == 2){
        return (str[0] != str[1]);
    }
    up = str[0] < str[1];
    for (i = 1; i < len; i++){
        if (up && str[i] > str[i - 1]){
            up ^= 1;
        }
        else if (!up && str[i] < str[i - 1]){
            up ^= 1;
        }
        else {
            return (0);
        }
    }
    return (1);
}

int main(void)
{
    int first, next;
    char start[512], end[512];
    
    scanf("%s", start);
    scanf("%s", end);
    scanf("%d", &mod);
    
    memset(dp, -1, sizeof(dp));
    
    sprintf(look, "0%s", start);
    len = strlen(look);
    first = memo(0, 0, 0, 2, 1);
    
    memset(dp, -1, sizeof(dp));
    
    sprintf(look, "0%s", end);
    len = strlen(look);
    next = memo(0, 0, 0, 2, 1);
    
    printf("%d\n", (next - first + ZigZag(start) + 10000) % 10000);
    
    return (0);
}

Measured memory_bytes: 60000
import sys
import queue

#+++++
		
def main():
	n = int(input())
	l = list(map(int, input().split()))
	ll=queue.PriorityQueue()
	for v in l:
		ll.put(v)

	while not ll.empty():
		ii=ll.get()
		nn=ll.get()
		nc=(ii+nn)/2
		if ll.empty():
			return nc
		ll.put(nc)
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 4208
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<double> p(n); rep (i, n) cin >> p[i];
    vector<vector<double> > dp(n + 1, vector<double>(n + 1, 0.0));
    dp[0][0] = 1.0;
    rep (i, n) {
        rep (j, n) {
            dp[i + 1][j + 1] += p[i] * dp[i][j];
            dp[i + 1][j] += (1 - p[i]) * dp[i][j];
        }
    }
    double ans = 0;
    rep (i, n / 2 + 1, n + 1) ans += dp[n][i];
    printf("%.16lf\n", ans);
    return 0;
}

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

int cmp(const int *a,const int *b){
  if(*a>*b){
    return 1;
  }
  else if(*a<*b)
  return -1;
  else return 0;
}

int main(void){
  int n;

  scanf("%d",&n);

  int d[n];
  long long kosu[n];
  long long ans=1;
  int cnt;
  int i,j,k;

  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
    if(d[i]==0&&i!=0){
      printf("0\n");
      return 0;
    }
  }
  if(d[0]!=0){
    printf("0");
    return 0;
  }




  qsort(d,n,sizeof(int),(int (*)(const void *,const void *))cmp);
/*for(i=0;i<n;i++){
  printf("%d",d[i]);
}*/
for(i=0;i<n-1;i++){
if(d[i+1]-d[i]>1){
  printf("%d",0);
  return 0;
}
}
k=1;
kosu[0]=1;
  for(i=1;i<n;i=i+cnt){
    cnt=0;
    for(j=i;j<n;j++){
      if(d[j]==d[j+1]){
        cnt++;
        ans=ans*kosu[k-1]%998244353;
      }
      else{
        ans=ans*kosu[k-1]%998244353;
        kosu[k]=cnt+1;
        k++;
        cnt++;
        break;
      }
    }
  }
/*for(i=0;i<k;i++){
  printf("kosu[%d]=%d\n",i,kosu[i]);
}*/

/* for(i=1;i<k;i++){

    ans=ans*pow(kosu[i-1],kosu[i]);

    ans=ans%998244353;

  }*/
  ans=ans%998244353;
  printf("%lld",ans);



return 0;
}


Measured memory_bytes: 1396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;

int main(){
    int n,mm;cin>>n>>mm;
    map<int,vector<ll> >m;
    vector<pair<int,ll> >v(mm);
    for(int i=0;i<mm;i++){
        cin>>v[i].first>>v[i].second;
        m[v[i].first].push_back(v[i].second);
        
    }
    for(auto it=m.begin();it!=m.end();it++){
        sort(it->second.begin(),it->second.end());
    }
    for(int i=0;i<mm;i++){
        int a=v[i].first; ll b=v[i].second;
        int aa=to_string(a).size();
        for(int j=0;j<6-aa;j++)cout<<0;
        cout<<a;
        int x=lower_bound(m[a].begin(),m[a].end(),b)-m[a].begin()+1;
        int bb=to_string(x).size();
        for(int j=0;j<6-bb;j++)cout<<0;
        cout<<x;
        cout<<endl;
    }
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  string S;
  cin >> S;
  vector <int> nums;
  numa(c,S){
    nums.pb(c-'0');
  }
  ll ans = 0;
  const int x = sz(nums) - 1;
  rep(bit, (1<<x)) {
    vector <int> f;
    f.pb(nums[0]);
    for (int i = 0; i < x; i++) {
      if (bit & (1<<i)) {
        f.pb(-1);
      }
      f.pb(nums[i+1]);
    }
    ll q = 0;
    ll t = 0;
    numa(x,f){
      if (x == -1) {
        q += t;
        t = 0;
      }else{
        t *= 10;
        t += x;
      }
    }
    q += t;
    ans += q;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define INF (1<<21)
#define MAX 100

int main(){
  int i,j,k,l,n;
  int p[MAX+1],m[MAX+1][MAX+1];

  // input
  scanf("%d",&n);
  for(i=1; i<=n; i++) scanf("%d %d",&p[i-1],&p[i]);

  // calculate
  for(i=1; i<=n; i++) m[i][i] = 0;

  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i; k<j; k++)
	if(m[i][j] > m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]){
	  m[i][j] = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	}
      }
    }

  // output
  printf("%d\n", m[1][n]);

  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
vector<int> G[100010];
int A[100010],B[100010];
int D[100010];

int h[100010];//頂点の入次数を管理
stack<int> st;
vector<int> T;

void Topologic(){
	REP(i,N){
		if(h[i]==0){
			st.push(i);
		}
	}
	while(st.size()){
		int i=st.top();st.pop();
		T.push_back(i);
		for(auto j:G[i]){
			h[j]--;
			if(h[j]==0){
				st.push(j);
			}
		}
	}
}

signed main(){
	cin>>N>>M;
	REP(i,M){
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
		G[A[i]].push_back(B[i]);
		h[B[i]]++;
	}
	int ans=0;
	Topologic();
	REP(i,T.size()){
		int s=T[i];
		REP(j,G[s].size()){
			int e=G[s][j];
			D[e]=max(D[e],D[s]+1);
			ans=max(ans,D[e]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9716
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#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 {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 (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ld = long double;
using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

int n;
vector<int> A;

ll Oblicz(int b) {
  ll wyn = 0;
  for (int i = 0; i < n; i++) {
    wyn += abs(A[i] - (b + i + 1));
  }
  return wyn;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  A.resize(n);
  for (int& x : A) cin >> x;
  ll a = -2000 * 1000 * 1000, b = 2000 * 1000 * 1000;
  while (a + 10 < b) {
    const int l = (a * 2 + b) / 3;
    const int r = (a + b * 2) / 3;
    if (Oblicz(l) < Oblicz(r)) {
      b = r;
    } else {
      a = l;
    }
  }
  ll wyn = Oblicz(0);
  for (int i = a; i <= b; i++) {
    Mini(wyn, Oblicz(i));
  }
  cout << wyn << endl;
  return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int, readline().split())
a = [tuple(map(int, readline().split())) for _ in range(n)]

def check(n,a):
    ans = 0
    ok = 1
    for i in range(n):
        for j in range(i+1,n):
            for k in range(n):
                if k==i or k==j: continue
                if a[i][k] + a[j][k] < a[i][j]:
                    return -1
                elif a[i][k] + a[j][k] == a[i][j]:
                    break
            else:
                ans += a[i][j]
    return ans
            
print(check(n,a))


Measured memory_bytes: 70748
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

SP = [input().strip().split() for _ in range(N)]
# print(SP)
dic = defaultdict(str)
for i, (S, P) in enumerate(SP):
	# print(i, S, P)
	dic["{},{}".format(S, P)] = i+1
SP.sort(key=lambda x: (x[0], -int(x[1])))
for S, P in SP:
	print(dic["{},{}".format(S, P)])


Measured memory_bytes: 4212
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        q_2();
    }

    private static void q_1() {
        try(Scanner scan = new Scanner(System.in)) {
            int H = scan.nextInt();
            int W = scan.nextInt();
            int h = scan.nextInt();
            int w = scan.nextInt();

            int result = (H * W) - ((W * h) - (h * w) + (H * w));

            System.out.println(result);
        }
    }

    private static void q_2() {
        try(Scanner scan = new Scanner(System.in)) {
            int N = scan.nextInt();
            int M = scan.nextInt();
            int C = scan.nextInt();

            int[] B = IntStream.range(0, M).map(i -> scan.nextInt()).toArray();
            int[][] A = new int[N][M];

            for(int i=0; i<N; i++) {
                for(int j=0; j<M; j++) {
                    A[i][j] = scan.nextInt();
                }
            }

            int cnt = 0;
            int result;
            for(int i=0; i<N; i++) {
                result = 0;
                for(int j=0; j<M; j++) {
                    result += B[j] * A[i][j];
                }
                result += C;

                if(result > 0) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        }
    }
}

Measured memory_bytes: 28500
N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort()
yen = 0
for a, b in AB:
    if M - b <= 0:
        yen += a * M
        break
    yen += a*b
    M -= b
print(yen)


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

using namespace std;

int64_t solve(int64_t x, int64_t y) {
  if (x == 0) {
    if (y > 0) {
      return y;
    } else {
      return 1 + (-y);
    }
  } else if (x > 0) {
    if (y >= x) {
      return y - x;
    } else if (y > 0) {
      return 1 + (x - y) + 1;
    } else if (y == 0) {
      return 1 + x;
    } else if (-y < x) {
      return 1 + (x - (-y));
    } else {
      return ((-y) - x) + 1;
    }
  } else {
    if (y >= -x) {
      return 1 + (y - (-x));
    } else if (y > 0) {
      return (-x) - y + 1;
    } else if (y == 0) {
      return -x;
    } else if (-x >= -y) {
      return (-x) - (-y);
    } else {
      return 1 + ((-y) - (-x)) + 1;
    }
  }
}

int main() {
  int64_t x, y;
  cin >> x >> y;

  cout << solve(x, y) << endl;

  return 0;
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto V = aryread();
    long ans;
    foreach (i; 0 .. N + 1)
        foreach (j; 0 .. N - i + 1)
        {
            long[] v = V[0 .. i] ~ V[$ - j .. $];
            long cnt = K - i - j;
            if (cnt < 0)
                continue;
            v.sort();
            long s;
            while (s < cnt && s < v.length && v[s] < 0)
                s++;
            dprint(i, j, v, cnt, s, v[s .. $].sum());
            ans = ans.max(v[s .. $].sum());
        }
    writeln(ans);
}


Measured memory_bytes: 3884
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
using P = pair<ll, ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((ll)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((ll)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll X, N;
ll Main() {
    cin >> X >> N;
    vl p(102, 0);
    
    rep(i,N) {
        ll tmp;
        cin >> tmp;
        p[tmp] = 1;
    }

    P ans(99999, -1);
    
    // 0 から 101 までを調べる
    rep(i, 102) {
        if(p[i] == 1) continue;
        // 最もXに近いものを求める
        ll diff = abs(X-i);
        // そして近い数が複数存在する場合は、そのうち最も小さいものを取る
        ans = min(ans, P(diff, i));
    }
    
    cout << ans.second << endl;
    return 0;
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;



int main() {

	int n;
	cin >> n;
	vi l(n);
	rep(i, n)cin >> l[i];

	sort(all(l));
	int ans = 0;

	rep1(i, n)rep(j, i) {
		int ma = l[i] + l[j];
		ans += lower_bound(all(l), ma) - l.begin() -i - 1;
	}

	cout << ans << endl;
}

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

long long MOD = 998244353;

vector<long long> F, RF, R;

void init(long long N) {
	F.resize(N + 1), RF.resize(N + 1), R.resize(N + 1);
	F[0] = F[1] = RF[0] = RF[1] = R[0] = R[1] = 1;
	for (int i = 2; i <= N; i++) {
		F[i] = (F[i - 1] * i) % MOD;
		R[i] = MOD - (R[MOD % i] * (MOD / i)) % MOD;
		RF[i] = (RF[i - 1] * R[i]) % MOD;
	}
	return;
}

long long Comb(long long A, long long B) {
	if (B < 0 || A < B) return 0;
	return (F[A] * ((RF[A - B] * RF[B]) % MOD)) % MOD;
}

int main() {
	string S;
	vector<long long> R, B;
	cin >> S;
	long long N = S.size();
	init(N);
	R.resize(N + 1), B.resize(N + 1);
	vector<vector<long long> > DP(N + 1, vector<long long>(N + 1, 0));
	DP[0][0] = 1;
	R[0] = B[0] = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '0') R[i + 1] = R[i] + 2, B[i + 1] = B[i] + 0;
		if (S[i] == '1') R[i + 1] = R[i] + 1, B[i + 1] = B[i] + 1;
		if (S[i] == '2') R[i + 1] = R[i] + 0, B[i + 1] = B[i] + 2;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			if (j != 0) DP[i][j] = (DP[i][j] + DP[i - 1][j - 1]) % MOD;
			DP[i][j] = (DP[i][j] + DP[i - 1][j]) % MOD;
		}
		for (int j = 0; j < i - B[i]; j++) DP[i][j] = 0;
		for (int j = R[i] + 1; j <= N; j++) DP[i][j] = 0;
	}
	long long ANS = 0;
	for (int i = 0; i <= N; i++) {
		ANS += DP[N][i] * Comb(N, R[N] - i);
		ANS %= MOD;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 31744
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {
    ll count = 0;

    ll N;
    cin >> N;
    vector<ll>D(N);

    rep(i, N) {
        cin >> D[i];
    }

    sort(D.begin(), D.end());

    ll M;
    cin >> M;
    vector<ll>T(M);

    rep(i, M) {
        cin >> T[i];
    }

    sort(T.begin(), T.end());

    int i = 0, j = 0;
    
    while (i != N && count != M) {
        if (T[j] == D[i]) {
            count++;
            i++;
            j++;
        }
        else {
            i++;
        }
    }

    if (count == M) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }

    return 0;
}


Measured memory_bytes: 5952
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    int r;
    cin >> n >> r;
    ans = 0;
    if(n >= 10)
    {
        ans = r;
    }
    else
    {
        ans = r + (100*(10-n));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

#define MAX 1000

int main()
{
	int N, ans=0, A[MAX];
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%d", &A[i]);
	}
	for(int i=0; i<N; i++){
		for(int j=i+1; j<N; j++)
			ans += A[i]*A[j];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
c0 = c1 = c2 = c3 = 0

N = int(input())
for i in range(N):
    s = input()
    if s == 'AC':
        c0 += 1
    elif s == 'WA':
        c1 += 1
    elif s == 'TLE':
        c2 += 1
    else:
        c3 += 1
tmp = ['AC', 'WA', 'TLE', 'RE']
tmp2 = [c0, c1, c2, c3]        

for i in range(4):
    print(tmp[i] + ' ' + 'x' + ' ' + str(tmp2[i]))

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

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<string> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    vector<string> B(M);
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }
    
    bool found = 0;
    for (int i = 0; i <= N - M; i++) {
        for (int j = 0; j <= N - M; j++) {
            bool ok = 1;
            for (int k = 0; k < M; k++) {
                for (int l = 0; l < M; l++) {
                    if (A[i + k][j + l] != B[k][l]) {
                        ok = 0;
                    }
                }
            }
            found |= ok;
        }
    }
    cout << (found ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
n,m,b,q[1024];char s[9],c[9];
main(i,t,p)
{
    for(;scanf("%d%d",&m,&n)*m;){
       	p=m;
        for(t=i=1;i<=n;i++){
            scanf("%s",s,*c=0);
            i%3||strcat(c,"Fizz");
            i%5||strcat(c,"Buzz");
            *c||sprintf(c,"%d",i);
            for(strcmp(s,c)&&p>1&&(q[t]=p--);q[t=t%m+1];);
        }
        for(t=i=1;i<=m;i++)q[i]?q[i]=0:(t=!printf(" %d"+t,i));
        puts("");
    }
}

Measured memory_bytes: 640
# encoding:utf-8

import numpy as np
import random
import copy

def select_ok(r_list,b_position):
    pass_list = []
    for i in range(len(r_list)):
        if r_list[i][0] < b_position[0] and r_list[i][1] < b_position[1]:
            pass_list.append(r_list[i])

    return pass_list



n = int(input())
r = []
b = []

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

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

b_sorted = sorted(b,key=lambda x:x[0])
count = 0
for i in range(n):
    pairs = select_ok(r,b_sorted[i])
    if len(pairs) > 0:
        sorted_pairs = sorted(pairs,key=lambda x:x[1],reverse=True)
        # print(sorted_pairs)
        count += 1
        r.remove(sorted_pairs[0])

print(count)

# print(answer)


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

set<string> ap;

void permute(string a, int l, int r)  
{  
    // Base case  
    if (l == r)  
        ap.insert(a);  
    else
    {  
        // Permutations made  
        for (int i = l; i <= r; i++)  
        {  
  
            // Swapping done  
            swap(a[l], a[i]);  
  
            // Recursion called  
            permute(a, l+1, r);  
  
            //backtrack  
            swap(a[l], a[i]);  
        }  
    }  
}

int main(){
	// your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ap.clear();
    int n;
    cin>>n;
    string s1,s2;
    s1="";
    s2="";
    int i;
    int t1;
    for(i=1;i<=n;i++){
        cin>>t1;
        s1=s1+to_string(t1);
    }
    for(i=1;i<=n;i++){
        cin>>t1;
        s2=s2+to_string(t1);
    }
    
    string s="";
    for(i=1;i<=n;i++){
        s=s+to_string(i);
    }
    permute(s,0,n-1);
    int a=0;
    int b=-1;
    int k=1;
    for(auto itr=ap.begin();itr!=ap.end();itr++){
        if(*itr==s1 || *itr==s2){
            if(a==0){
                a=k;
            }
            else{
                b=k;
            }
        }
        k++;
    }
    if(b==-1){
        b=a;
    }
    cout<<abs(a-b);
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int i,s;
  vector<int> d(n);
  for(i=0;i<n;i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  s=1;
  for(i=1;i<n;i++){
    if(d.at(i)!=d.at(i-1)){
      s++;
    }
  }
  
  cout << s << endl;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> data(H, vector<char>(W));

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> data.at(i).at(j);
        }
    }
    int countW, countH;

    for(int i = 0; i < H; i++) {
        countW = 0;
        for(int j = 0; j < W; j++) {
            if(data.at(i).at(j) == '.'){
                countW++;
            }
            if(countW == W){
                for(int k = 0; k < W; k++) {
                    data.at(i).at(k) = 'D';
                }
            }
        }
    }

    for(int j = 0; j < W; j++) {
        countH = 0;
        for(int i = 0; i < H; i++) {
            if(data.at(i).at(j) == '.' || data.at(i).at(j) == 'D'){
                countH++;
            }
            if(countH == H){
                for(int k = 0; k < H; k++) {
                    data.at(k).at(j) = 'D';
                }
            }
        }
    }
    
    int X = 0;

    for (int i = 0; i < H; i++) {
        if (X > 0) {
            cout << endl;
        }
        X = 0;
        for (int j = 0; j < W; j++) {
            if (data.at(i).at(j) == 'D') {
                continue;
            }
            else {
                cout << data.at(i).at(j);
                X++;
            }
        }
    }

}


Measured memory_bytes: 256
/*　２分木のすべての節点を巡回するプログラム　*/
#include <stdio.h>

#define NIL -1
#define MAX 25     /*　最大の節点数　*/

struct node{

  int id;
  int left;
  int right;
  int parent;
};

struct node T[MAX];       /*　二分木　*/

void preorder(int);
void inorder(int);
void postorder(int);

int main()
{
  int i, j, n, num, root, l, r;

  /*　二分木をNILで初期化　*/
  for( i = 0; i<MAX; i++ )
    T[i].left = T[i].right = T[i].parent = NIL;

  /*　n個の節点を読み込む　*/
  scanf("%d", &n);
  for( i = 0; i<n; i++ )
    {
      scanf("%d%d%d", &num, &l, &r);

      T[num].id    = num;
      T[num].left  = l;
      T[num].right = r;

      /* 左の子の親を設定　*/
      if( l != NIL )
	T[ l ].parent  = num;
      /*　右の子の親を設定　*/
      if( r != NIL )
	T[ r ].parent = num;
    }

  /* rootノードを求める　*/
  for( i = 0; i<n; i++ )
    {
      if( T[i].parent == NIL )
	{
	  root = i;
	  break;
	}
    }
  
  /*　二分木を先行順巡回によって出力　*/
  printf("Preorder\n");
  preorder(root);
  /*　二分木を中間順巡回によって出力　*/
  printf("\nInorder\n");
  inorder(root);
  /*　二分木を後行順巡回によって出力　*/
  printf("\nPostorder\n");
  postorder(root);
  printf("\n");
  
  return 0;
}

/* 二分木Tに先行順巡回を行った節点番号を順番に出力する関数　*/
void preorder(int n)
{
  if( n == NIL )
    return;
  
  printf(" %d", T[n].id);
  preorder( T[n].left );
  preorder( T[n].right );
}

/*　二分木Tに中間順巡回を行った節点番号を順番に出力する関数　*/
void inorder(int n)
{
  if( n == NIL )
    return;

  inorder( T[n].left);
  printf(" %d", T[n].id);
  inorder( T[n].right);
}

/*　二分木Tに後行順巡回を行った節点番号を順番に出力する関数　*/
void postorder(int n)
{
  if( n == NIL )
    return;

  postorder( T[n].left );
  postorder( T[n].right );
  printf(" %d", T[n].id);
}



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

int main()
{
  int n,k,q,qv,hold;
  cin >> n >> k >> q;
  hold = q;
  int score[n+1], correct[n+1];
  for (int i = 1 ; i <= n; i++)
  {
    //score[i]=k;
    correct[i]=0;
  }
  while(hold--)
  {
    cin >> qv;
    correct[qv]++;
  }
  for(int i = 1 ; i <= n; i++)
  {
    score[i] = k - (q - correct[i]);
    if(score[i] > 0)
      cout << "Yes" << endl;
    else
      cout <<"No"<<endl;
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    p[i] = make_pair(x, y);
  }
  map<pair<int, int>, int> mp;
  rep(i, n) rep(j, n) {
    if (i == j) continue;
    int xdist, ydist;
    xdist = p[j].first - p[i].first;
    ydist = p[j].second - p[i].second;
    pair<int, int> a = make_pair(xdist, ydist);
    mp[a]++;
  }
  int cnt = 0;
  for (auto x : mp) {
    cnt = max(cnt, x.second);
  }
  cout << n - cnt << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <inttypes.h>

int K;
uint64_t A[114514];

int main(void) {
	int i;
	uint64_t saisyou, saidai;
	if (scanf("%d", &K) != 1) return 1;
	for (i = 0; i < K; i++) {
		if (scanf("%" SCNu64, &A[i]) != 1) return 1;
	}
	saisyou = saidai = 2;
	for (i = K - 1; i >= 0; i--) {
		saisyou = ((saisyou + A[i] - 1) / A[i]) * A[i];
		saidai = (saidai / A[i]) * A[i] + (A[i] - 1);
		if (saisyou > saidai) {
			puts("-1");
			return 0;
		}
	}
	printf("%" PRIu64 " %" PRIu64 "\n", saisyou, saidai);
	return 0;
}


Measured memory_bytes: 2464
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
BC = [list(map(int,input().split())) for i in range(M)]
BC.sort(key = lambda x:-x[1])

index = 0
for i in range(len(BC)):
    for j in range(BC[i][0]):
        if index == len(A) or A[index] >= BC[i][1]:
            break

        else:
            A[index] = BC[i][1]
            index += 1

print(sum(A))
    

Measured memory_bytes: 36072
n = int(input())
T = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
    b, f, r, v = map(int, input().split())
    T[b-1][f-1][r-1] += v
    
for i in range(4):
    for j in range(3):
        for k in range(10):
            print('',T[i][j][k],end='')
        print()
    if i<3:
        print('#'*20)


Measured memory_bytes: 5636
h, w = map(int, input().split())

lst = ["." + input() + "." for _ in range(h)]
matrix = ["." * (w + 2)] + lst + ["." * (w + 2)]


ans = "Yes"
for i in range(1, h + 1):
    for j in range(1, w + 1):
        center = matrix[i][j]
        up = matrix[i - 1][j]
        down = matrix[i + 1][j]
        left = matrix[i][j - 1]
        right = matrix[i][j + 1]
        if center == "#" and up == "." and down == "." and left == "." and right == ".":
            ans = "No"
print(ans)

Measured memory_bytes: 3064
#coding : utf-8

import os
import sys

N = int(input())

A = list(map(lambda x: int(x), input().split(" ")))

B = list(map(lambda x: int(x), input().split(" ")))

#print(N)
#print(A)
#print(B)

total = 0

for i in range(N):
	if B[i] < A[i]:
		mons = B[i]
		total += mons
#		print("勇者%d bustered %d monsters => total=%d" % (i+1, mons, total))
	else:
		mons = A[i]
		total += mons
#		print("勇者%d bustered %d monsters => total=%d" % (i+1, mons, total))
		B[i] -= mons
		
		if B[i] > 0:
			mons = min(A[i+1], B[i])
			total += mons
#			print("勇者%d bustered %d monsters => total=%d" % (i+1, mons, total))
			B[i] -= mons
			A[i+1] -= mons

print(total)





Measured memory_bytes: 18476
let () = Scanf.scanf "%d\n" @@ fun n ->
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@
  Array.init n @@ fun i -> Scanf.scanf "%d " @@ fun a ->
    if i mod 2 = 0 && a mod 2 = 1 then 1 else 0

Measured memory_bytes: 3832
def main():
    # A, B, C, D = 10, 9, 10, 10
    A, B, C, D = map(int, input().split())

    while A > 0 and C > 0:
        C -= B
        if C <= 0:
            flag = True
            break
        A -= D
        if A <= 0:
            flag = False
            break

    if flag:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 61684
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>
using namespace std;

//fixed << setprecision(10)
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

int gcd(int a,int b) {
	if (a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

map<int, int> prime;
void Prime(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}

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

	int n = str.size();
	vector<int> num(n + 1,0);
	long long int sum = 0;

	for (int i = 0; i < n; i++) {
		if (str[i] == '<') {
			num.at(i + 1) = num.at(i) + 1;
		}
	}
	for (int i = n-1; i >=0; i--) {
		if (str[i] == '>') {
			num.at(i) = max(num.at(i), num.at(i+1) + 1);
		}
	}

	for (int i = 0; i <= n; i++) {
		sum += num.at(i);
	}
	/*
	for (int i = 0; i <= n; i++) {
		cout << num.at(i) << " ";
	}cout << endl;
	*/
	cout << sum << endl;
}


Measured memory_bytes: 2820
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k;
	cin>>k;
	int a,b;
	cin>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int read() { 
    bool flag = true; int num = 0;char c = getchar(); 
    for(;c < '0' || c > '9';c = getchar())if(c == '-') flag = false; 
    for(;c >= '0' && c <= '9';c = getchar()) num = ( num << 3 ) + ( num << 1 ) + c - 48; 
    if(flag) return num;  else return -num; 
}

int main(){
	string s;
	cin>>s;
	cout<<s[0];
	cin>>s;
	cout<<s[1];
	cin>>s;
	cout<<s[2];
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
nlist = [[] for i in range(N+1)]
# print(nlist)
for m in range(M):
    a, b = map(int,input().split())
    nlist[a].append(b)
    nlist[b].append(a)
    # min_, max_ = min(a,b), max(a,b)
    # nlist[min_].append(max_)
# print(nlist)

# 各部屋への最短経路

def bfs():
    nstep = 1
    queue = [1]
    min_dist = [0]*N
    # print(min_dist)
    while True:
        if len(queue)==0:
            break
        ncurrent = queue[0]
        queue.pop(0)
        # print(ncurrent, min_dist)
        for i in nlist[ncurrent]:
            if min_dist[i-1]!=0:
                continue
            queue.append(i)
            min_dist[i-1] = min_dist[ncurrent-1] + 1
    return min_dist
ret=bfs()

if 0 in ret:
    print("No")
else:
    print("Yes")
    dist2n = {r:i+1 for i, r in enumerate(ret)}
    for i in range(1,len(ret)):
        if ret[i]==1:
            print(1)
        else:
            print(dist2n[ret[i]-1])

Measured memory_bytes: 39748
n = int(input())
dp = [float("Inf")]*(n+1)
for i in range(n+1):
    if i < 6:dp[i] = i
    power = 1
    while i >= 6 ** power:
        if dp[i] > dp[i-6**power]+1:dp[i] = dp[i-6**power] + 1
        power += 1
    power = 1
    while i >= 9 ** power:
        if dp[i] > dp[i-9**power]+1:dp[i] = dp[i-9**power] + 1
        power += 1
print(int(dp[n]))

Measured memory_bytes: 3828
from itertools import permutations

n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]

def d(xy1, xy2):
    return ((xy1[0] - xy2[0])**2 + (xy1[1] - xy2[1])**2)**0.5

p = [i for i in permutations(xy, n)]

s, e = 0, 1
ds = []
for i in p:
    while e <= n-1:
        xy1 = i[s]
        xy2 = i[e]
        ds.append(d(xy1, xy2))
        s += 1
        e += 1
    s, e = 0, 1

print(sum(ds)/len(p))

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

int main() {
  int N;
  string S;

  cin >> N;
  cin >> S;

  vector<bool> s(N);

  int bc = 0;

  for(int i = 0; i < N; i++) {
    s[i] = S.at(i) == '.' ? false : true;
  }

  vector<int> bs(N);
  vector<int> ws(N);

  bs[0] = (s[0] ? 1 : 0);
  for(int i = 1; i < N; i++) {
    bs[i] = bs[i-1] + (s[i] ? 1 : 0);
  }

  ws[N-1] = (s[N-1] ? 0 : 1);
  for(int i = N-2; i >= 0; i--) {
    ws[i] = ws[i+1] + (s[i] ? 0 : 1);
  }

  int ans = bs[0] + ws[0];

  for(int i = 1; i < N; i++) {
    if(ans > bs[i]+ws[i]) ans = bs[i]+ws[i];
  }

  cout << ans-1 << endl;
}


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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple

#define N 311111
#define A 1111111
#define BLOCK 555 // ~sqrt(N)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int INF = 1e9 +5;
const int nax = 1e5 +5;
const long M = 1000000007;
double p[305][305][305];
double ev[305][305][305];
int dp[nax];
// int visited[nax];
// int in_degree[nax];
// vector<int> edges[nax];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout<<fixed;
	cout<<setprecision(10);
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		int n,k;
		cin>>n>>k;
		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		for(int i=0;i<=k;i++){
			for(int x : arr){
				if(i>=x && dp[i-x]==0){
					dp[i] = true;
				}
			}
		}
		string ans = dp[k] ? "First" : "Second";
		cout<< ans << '\n';
	}
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
const int N=4,Mod=1e9+7;
struct Mat{
	int a[N][N];
	inline void clear(){memset (a,0,sizeof(a));}
	inline Mat operator *(Mat t){
		Mat c;c.clear();
		for (int i=1;i<=2;i++)
			for (int j=1;j<=2;j++)
				for (int k=1;k<=2;k++){
					c.a[i][j]+=1ll*a[i][k]*t.a[k][j]%Mod;
					c.a[i][j]%=Mod;
				}
		return c;
	}
};
inline int qpow(int a,ll b){
	int ans=1;
	while (b){
		if (b&1) ans=1ll*ans*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return ans;
}
const int M=1005;
char s[M][M],ss[M][M];
int n,m;ll k;
inline void rev(){
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			ss[m-j+1][i]=s[i][j];
	swap(n,m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			s[i][j]=ss[i][j];
}
inline int query(){
	int cnt=0;
	for (int i=1;i<=n;i++)
		if (s[i][1]=='#'&&s[i][m]=='#') ++cnt;
	return cnt;
}
int main (){
	scanf ("%d%d%lld",&n,&m,&k);
	for (int i=1;i<=n;i++)
		scanf ("%s",s[i]+1);
	int x=0,y=0,z=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			x+=(s[i][j]=='#');
	int f1=query(),cnt=0;
	rev();int f2=query();rev();
	if (f1&&f2) return puts("1"),0;
	else if (!f1&&!f2) return printf ("%d",qpow(x,k-1)),0;
	else if (f2) rev();
	for (int i=1;i<=n;i++)
		for (int j=1;j<m;j++)
			y+=(s[i][j]=='#'&&s[i][j+1]=='#');
	for (int i=1;i<=n;i++)
		z+=(s[i][1]=='#'&&s[i][m]=='#');
	Mat t;t.clear();
	t.a[1][1]=x,t.a[1][2]=y,t.a[2][2]=z;
	Mat ans;ans.clear();--k;ans.a[1][1]=ans.a[2][2]=1;
	while (k){
		if (k&1) ans=ans*t;
		t=t*t,k>>=1;
	}
	printf ("%d",(ans.a[1][1]-ans.a[1][2]+Mod)%Mod);
	return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include<string.h>

int main(void){
    int n;
    int s[4];
    int i;

    for(i  = 0; i < 4; i++)
        s[i] = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        char result[4];
        scanf("%s", result);
        if(strcmp(result, "AC") == 0)
            s[0]++;
        else if (strcmp(result, "WA") == 0)
            s[1]++;
        else if (strcmp(result, "TLE") == 0)
            s[2]++;
        else if (strcmp(result, "RE") == 0)
            s[3]++;
    }

    printf("AC x %d\n", s[0]);
    printf("WA x %d\n", s[1]);
    printf("TLE x %d\n", s[2]);
    printf("RE x %d\n", s[3]);

    return 0;
}

Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int total = Integer.parseInt(scan.next());
		scan.close();
		int hour = total / 3600;
		int min = (total - hour * 3600) / 60;
		int sec = (total - hour * 3600 - min * 60);
		System.out.println(hour + ":" + min + ":" + sec);
	}
}



Measured memory_bytes: 26116
#include<bits/stdc++.h>
using namespace std;
const long long Max = 10e7;
typedef long long ll;
int mod = 1000000007;
const int Size = 1000-10;
int main()
{
    int n;
    cin >> n;
    int dp[n+5] = {};
    int A[n+5] = {};
    for(int i = 1; i <= n; i++)
    {
        cin >> A[i];
    }
    dp[1] = 0;
    dp[2] = abs(A[1]-A[2]);
    for(int i = 3; i <= n; i++)
    {
        dp[i] = min(abs(A[i] - A[i-1]) + dp[i-1], abs(A[i]- A[i-2]) + dp[i-2]);
    }
    cout << dp[n] << endl;
    return 0;
}


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

int main()
{
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> divisor_A(100), divisor_B(100);
    vector<int> ans(100);
    int cnt = 0;

    rep(i, A) {
        if (A % i == 0) {
            divisor_A.at(cnt) = i;
            cnt++;
        }
    }
    cnt = 0;

    rep(i, B) {
        if (B % i == 0) {
            divisor_B.at(cnt) = i;
            cnt++;
        }
    }

    cnt = 0;
    for (int i = 0; i < divisor_A.size(); i++) {
        for (int j = 0; j < divisor_B.size(); j++) {
            if (divisor_A.at(i) == divisor_B.at(j) && divisor_A.at(i) != 0) {
                ans.at(cnt) = divisor_A.at(i);
                cnt++;
            }  
        }
    }
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());

    cout << ans.at(K-1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;

int n, m;
int a[100005],b[100005];
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)
	{
		a[i] = 1;
		b[i] = 0;
	}
	int x, y;
	b[1] = 1;
	for(int i = 0; i < m; i++)
	{
		scanf("%d%d", &x, &y);
		a[x]--;
		a[y]++;
		if(b[x]) b[y] = 1;
		if(a[x] == 0 && b[x] == 1) b[x] = 0;
	}
	int sum = 0;
	for(int i = 1; i <= n; i++)
	{
		if(b[i]) sum++;
	}
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static const LLONG LL_HUGE_NUM = 1000000007LL;

static void C_task();

int main()
{
	C_task();
	
	fflush(stdout);
	return 0;
}


static void C_task()
{
	int N, M;
	scanf(" %d %d", &N, &M);

	auto dp = new LLONG[N + 1];
	memset(dp, 0, sizeof(LLONG) * (N + 1));

	int brkStep;
	for (int i = 0; i < M; i++) {
		scanf(" %d", &brkStep);
		//	壊れた段に目印
		dp[brkStep - 1] = 0xFFFF;
	}

	if (!dp[0] && !dp[1]) {
		dp[0] = 1;
		dp[1] = 2;
	}
	else if (dp[0] && dp[1]) {
		dp[0] = dp[1] = 0;
	}
	else if (dp[0]) {
		dp[0] = 0;
		dp[1] = 1;
	}
	else if (dp[1]) {
		dp[0] = 1;
		dp[1] = 0;
	}
	for (int i = 2; i < N; i++) {
		if (!dp[i]) {
			dp[i] = (dp[i - 1] + dp[i - 2]) % LL_HUGE_NUM;
		}
		else {
			dp[i] = 0;
		}
	}

	printf("%lld\n", dp[N - 1]);
	
	delete[] dp;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    vector<int> y = x;
    sort(y.begin(), y.end());
    for (int i = 0; i < n; i++){
        if (x[i] < y[n / 2]) cout << y[n / 2] << "\n";
        else cout << y[n / 2 - 1] << "\n";
    }

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

int main() {

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

    ll A; ld b; cin >> A >> b;

    cout << ll((ld)A*b) << "\n";
}


Measured memory_bytes: 3744