akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 998244353, INF = 1e16;

template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
typedef modint<MOD> ModInt;

lint N, S;
lint arr[3000];
int main() {
	cin >> N >> S;
	REP(i, N) {
		cin >> arr[i];
	}
	vector<ModInt> dp(S + 1);
	ModInt ans = 0;
	REP(i, N) {
		dp[0] += 1;
		{
			vector<ModInt> dp2(S + 1);
			REP(j, S + 1) {
				dp2[j] += dp[j];
				if (j + arr[i] <= S) dp2[j + arr[i]] += dp[j];
			}
			dp = dp2;
		}
		ans += dp[S];
	}
	cout << ans.a << endl;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

char S[2001];

bool memo[4002];
int Sum[4002], n[4002], amari[4002];

pair<int, int> E[4002];
int Head[2001];
void dfs(int To, int from, int head) {
	if (memo[head]) return;
	memo[head] = true;
	int saidai = 0;
	for (int i = Head[To]; i; i = E[i].second) {
		if (E[i].first != from) {
			dfs(E[i].first, To, i);
			Sum[head] += Sum[i];
			n[head] += n[i];
			saidai = max(saidai, amari[i]);
		}
	}
	if (saidai + saidai < Sum[head]) amari[head] = (Sum[head] + 1) / 2;
	else amari[head] = saidai;
	if (S[To] == '1') n[head]++;
	Sum[head] += n[head];
	amari[head] += n[head];
}

const int cm = 1 << 15;
char cn[cm], *ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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

	fread_unlocked(cn, 1, cm, stdin);

	int N = getint();
	int kazu = 0;
	rep1(i, N) {
		S[i] = *ci++;
		if (S[i] == '1') kazu++;
	}
	if (kazu == 1) {
		co(0);
		return 0;
	}
	ci++;

	int Deg[2001] = {};
	for (int i = 1; i < 2 * N - 2; i += 2) {
		int a = getint(), b = getint();
		Deg[a]++;
		Deg[b]++;
		E[i] = mp(a, Head[b]);
		Head[b] = i;
		E[i + 1] = mp(b, Head[a]);
		Head[a] = i + 1;
	}

	bool OK = 0;
	int saishou = 1e9;
	queue<int> que;
	int kari = 0;
	rep1(i, N) if (Deg[i] > 1) kari = i;
	que.push(kari);
	while(que.size()) {
		int j = que.front();
		que.pop();
		if (Deg[j] > 1) {
			Deg[j] = 1;
			int s = 0;
			int saidai = 0;
			for (int i = Head[j]; i; i = E[i].second) {
				dfs(E[i].first, j, i);
				s += Sum[i];
				saidai = max(saidai, amari[i]);
			}
			if (saidai + saidai > s) {
				for (int i = Head[j]; i; i = E[i].second) {
					if (amari[i] == saidai) que.push(E[i].first);
				}
			}
			else {
				for (int i = Head[j]; i; i = E[i].second) que.push(E[i].first);
				if ((s & 1) == 0) {
					OK = 1;
					saishou = min(saishou, s / 2);
				}
			}
		}
	}

	if (OK) co(saishou);
	else co(-1);

	Would you please return 0;
}

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

int main(){
    int n ;
    cin >> n ;
    vector<int> v(n) ;
    for(int &x : v){
        cin >> x ;
    }
    sort(v.rbegin(),v.rend());
    int cnt = 1 ;
    int cur = v[0];
    for(int i=1;i<n;i++){
        if ( v[i] < cur ){
            cur = v[i] ;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0 ;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
Sn = [input() for _ in range(N)]

C = Counter(Sn)
most = C.most_common()
max = most[0][1]
ans = []
for i in most:
    if max == i[1]:
        ans.append(i[0])
    else:
        break

ans.sort()
for word in ans:
    print(word)


Measured memory_bytes: 47636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string S; cin >> S;
  sort(ALL(S));
  if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> A) {
    if (A.size() == n+1) {
        int now = 0;
        for (size_t i = 0; i < q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }

    A.push_back(A.back());
    while (A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main(int argc, char const *argv[]) {
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    for (size_t i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,K,R,S,P; cin>>N>>K>>R>>S>>P;
    ll ans=0;
    string s; cin>>s;
    //MOD iについて
    rep(i,K){
        ll tmp=0;
        
        if(sz(s)%K==0) tmp=sz(s)/K;
        else{
            if(i<sz(s)%K) tmp=(sz(s)+K-1)/K;
            else tmp=(sz(s)+K-1)/K-1;
        }
        
        //dp[j][k]:j番目にkを出したときの最高点数
        vector<vector<ll> > dp(tmp+1,vector<ll>(3,0));
        
        ll now=5;
        rep1(j,tmp){
            if(s[K*(j-1)+i]=='r'){
                if(now!=2){
                    ans+=P;
                    now=2;
                }
                else if(j<tmp){
                    if(s[K*j+i]=='p') now=0;
                    else now=1;
                }
            }
            else if(s[K*(j-1)+i]=='s'){
                if(now!=0){
                    ans+=R;
                    now=0;
                }
                else if(j<tmp){
                    if(s[K*j+i]=='r') now=1;
                    else now=2;
                }
            }
            else{
                if(now!=1){
                    ans+=S;
                    now=1;
                }
                else if(j<tmp){
                    if(s[K*j+i]=='r') now=0;
                    else now=2;
                }
            }
            
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 8752
import java.util.Scanner;

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

        int count = 0;

        while(true){
            count++;
            if(h <= a) break;
            h = h - a;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

class Main {

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

        int n = scan.nextInt();
        
        int a[] = new int[n];
        for (int i =0; i<n; i++) {
            a[i] = scan.nextInt();
           

            
        }

        for(int i = n-1 ; i>=0 ; i--){
            if(i<n-1){
                System.out.print(" ");
            }
            System.out.print(a[i]);
        }
        System.out.println("");
    }

}
 


Measured memory_bytes: 26188
n,k=map(int,input().split())
import math
ans=0
for i in range(1,n+1):
    if i<k:
        res=math.ceil(math.log2(k/i))
        ans+=(1/n)*0.5**res
    else:
        ans+=(n-i+1)/n
        break
print(ans)

Measured memory_bytes: 2940
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string s,t;
cin >> s >> t;
ll cnt = 0;
rep(i,s.size()){
    if(s[i] != t[i])
        cnt++;
}
cout << cnt << endl;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<ll> a(n), b(n);
  REP(i,n) cin >> a[i]>> b[i];
  sort(ALL(a));
  sort(ALL(b));
  ll ans;
  if(n%2==0){
    ans = b[n/2-1] + b[n/2] - (a[n/2-1] + a[n/2]) + 1;
  }else{
    ans = b[n/2] - a[n/2] + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6324
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define MAX 59049

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

	int a[10][3];
	long long ans = 0;
	
	int la[MAX];

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 3; j++) {
      a[i][j] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[i][1] = (tmp % 2);
    a[i][0] = 1 - a[i][1];
    a[i][2] = 1 - a[i][1];
	}

	
	for (int i = 0; i < MAX; i++) {
		la[i] = 0;
	}

	int itr = -1;
	
  for (int i9 = 0; i9 < 3; i9++) {
    for (int i8 = 0; i8 < 3; i8++) {
      for (int i7 = 0; i7 < 3; i7++) {
        for (int i6 = 0; i6 < 3; i6++) {
          for (int i5 = 0; i5 < 3; i5++) {
            for (int i4 = 0; i4 < 3; i4++) {
              for (int i3 = 0; i3 < 3; i3++) {
                for (int i2 = 0; i2 < 3; i2++) {
                  for (int i1 = 0; i1 < 3; i1++) {
                    for (int i0 = 0; i0 < 3; i0++) {
											itr++;
                      if (a[0][i0] * a[1][i1] * a[2][i2] * a[3][i3] * a[4][i4] *
                              a[5][i5] * a[6][i6] * a[7][i7] * a[8][i8] *
                              a[9][i9] ==  0) {
												//ans++;
												la[itr] = 1;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
	}

	int na = 1;
	for (int i = 0; i < n; i++) {
		na *= 3;
	}
	
	for (int i = 0; i < na; i++) {
		//cerr << la[i] << endl;
		ans += la[i];
	}


  cout << ans << endl;

  return 0;
}

/*
NSNNSNSN

NNEW

W


*/

Measured memory_bytes: 512
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    s.sort()
    if s[0] == s[1] and s[1] != s[2] and s[2] == s[3]:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        int temp;
        if(A>B){temp=A; A=B; B=temp;}
        if(B>C){temp=B; B=C; C=temp;}
        if(A>B){temp=A; A=B; B=temp;}
        System.out.println(C*10+B+A);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=55,M=N*N*2;
int n,tot,sum,x[N],y[N],head[N],nex[M],to[M],wi[M];
map<pair<int,int>,int>mp;
vector<int>v[N][M];
void add(int u,int v,int w)
{
    to[++tot]=v;nex[tot]=head[u];head[u]=tot;wi[tot]=w;
    to[++tot]=u;nex[tot]=head[v];head[v]=tot;wi[tot]=w;
}
bool vis[N];
void dfs(int u,int p)
{
    sum++;
    vis[u]=true;
    for(int i=0;i<v[u][p].size();i++)
    {
        int y=v[u][p][i];
        if(!vis[y])
            dfs(y,p);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&x[i],&y[i]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
    {
        if(i==j) continue;
        pair<int,int>s=make_pair(x[i]-x[j],y[i]-y[j]);
        int t=mp[s];
        if(!t) t=mp[s]=++tot;
        v[i][t].push_back(j);
        v[j][t].push_back(i);
    }
    int ans=n;
    for(int i=1;i<=tot;i++)
    {
        int res=0;
        memset(vis,false,sizeof(vis));
        for(int j=1;j<=n;j++)
            if(!vis[j])
        {
            res++;
            vis[j]=true;
            dfs(j,i);
        }
        ans=min(ans,res);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 8320
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	int X, t;
	cin >> X >> t;
	cout << max(X - t,0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template< typename T >
struct edge {
  int src, to, sgn;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
struct UnionFind {
  vector< int > data;
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
  int size(int k) {
    return (-data[find(k)]);
  }
};
template< typename T >
T kruskal(Edges< T > &edges, int V) {
  sort(begin(edges), end(edges), [](const edge< T > &a, const edge< T > &b) {
    return (a.cost < b.cost);
  });
  UnionFind tree(V);
  T mi = INF, ma = 0;
  for(auto &e : edges) {
    if(tree.unite(e.src, e.to)) {
      mi = min(mi, e.sgn * e.cost);
      ma = max(ma, e.sgn * e.cost);
    }
  }
  return (ma - mi);
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    int n, m; cin >> n >> m;
    if(n == 0 && m == 0) break;
    Edges<ll> eds;
    UnionFind uf(n);
    for(int i=0;i<m;++i) {
      int a, b, w; cin >> a >> b >> w;
      a--;
      b--;
      eds.push_back(edge<ll>(a, b, w));
      uf.unite(a, b);
    }
    bool ok = true;
    for(int i=0;i<n;++i) {
      if(uf.size(i) != n) {
        cout << -1 << endl;
        ok = false;
        break;
      }
    }
    if(!ok) continue;
    int mi = INF;
    for(int i=0;i<m;++i) {
      Edges<ll> now;
      vector<int> sgn(m);
      int c = eds[i].cost;
      for(int j=0;j<m;++j) {
        now.push_back(edge<ll>(eds[j].src, eds[j].to, abs(eds[j].cost - c)));
        now[j].sgn = (int)(eds[j].cost - c > 0) * 2 - 1;
      }
      int ans = kruskal(now, n+1);
      mi = min(mi, ans);
    }
    cout << mi << endl;
  }
}



Measured memory_bytes: 3320
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())-1])

Measured memory_bytes: 2940
use std::str::FromStr;
use std::io;

fn whitespace_second() -> (usize, usize) {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
    (it.next().unwrap(), it.next().unwrap())
}

fn main() {
    let (a, b) = whitespace_second();
    let ans = if(a >= 6 && a <= 12) {
        b / 2
    } else if (a >= 13) {
        b
    } else {
        0 as usize
    };
    println!("{}", ans);
}

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

int main() {
  int N;
  cin >>N;
  vector<int> A(N+1),B(N),C(N+1);
  for(int i=0; i<N+1;i++)
    cin >> A[i];
  for(int i=0; i<N;i++)
    cin >> B[i];
  for(int i=0; i<N+1;i++)
    C[i]=A[i];
  int d=0;
  for(int i=0; i<N; i++){
    d=min(A[i],B[i]);
    A[i]=A[i]-d;
    B[i]=B[i]-d;
    if(B[i] > 0)
      A[i+1] =A[i+1]-min(A[i+1],B[i]);
  }
  int64_t b=0;
  for(int i=0; i<N+1; i++)
    b+=(C[i]-A[i]);
    
  cout << b;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>

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

    int maxCount = 0;
    int tmpCount = 0;

    for (int i = 0; i < s.size(); i++) {
        char current = s[i];
        if (current == 'A' || current == 'C' || current == 'G' || current == 'T') {
            tmpCount++;
            if (tmpCount > maxCount) {
                maxCount = tmpCount;
            }
        } else {
            tmpCount = 0;
        }
    }
    
    std::cout << maxCount << std::endl;
}

Measured memory_bytes: 256
using System;

public class Program
{
    static long n;
    static long k;

    static long[] d;

    static string output;

    public static void Main(string[] args)
    {
        Input();
        Proc();
        Output();
    }

    static void Input()
    {
        string[] input = null;

        // スペース区切りの整数の入力(横、個別)
        input = Console.ReadLine().Split(' ');

        n = long.Parse(input[0]);   // N円の品物
        k = long.Parse(input[1]);   // 嫌いな数の個数

        // スペース区切りの整数の入力(横、配列)
        input = Console.ReadLine().Split(' ');

        d = new long[k];
        for (long idx = 0; idx < k; idx++)
        {
            d[idx] = long.Parse(input[idx]);    // 嫌いな数
        }
    }

    static void Proc()
    {
        long money = n;

        // OKの最小を得る
        long okMin = GetOkMin();

        // メイン処理
        long inc = 1;

        while (IsOk(money, inc) == false)
        {
            while ((money / inc) % 10 == okMin)
            {
                inc *= 10;
            }

            money += inc;
        }

        output = money.ToString();
    }

    static long GetOkMin()
    {
        for (int okValue = 0; okValue < 10; okValue++)
        {
            bool okFlag = true;
            foreach (long ng in d)
            {
                if (okValue == ng)
                {
                    okFlag = false;
                }
            }

            if (okFlag == true)
            {
                return okValue;
            }
        }

        return -1;
    }

    static bool IsOk(long money, long inc)
    {
        long workMoney = money;
        workMoney /= inc;

        while (workMoney > 0)
        {
            long chkValue = workMoney % 10;

            foreach (long ng in d)
            {
                if (chkValue == ng)
                {
                    return false;
                }
            }

            workMoney /= 10;
        }

        return true;
    }

    static void Output()
    {
        // 出力
        Console.WriteLine(output);
        output = string.Empty;
    }
}


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

int main() {
	int n; cin >> n;
	map<int, int>a;
	for (int i = 0,tmp; i < n; i++) {
		cin >> tmp; a[tmp]++;
	}

	long long ans = 0;
	for (auto&& x : a) {
		if (x.first > x.second)ans += x.second;
		else if (x.first < x.second)ans += (x.second - x.first);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>

#define N 500001

int h,i,A[N];

void maxHeapify(int);
void buildMaxHeap(void);

int left(int);
int right(int);

int left(int i)
{
  return 2*i;
}

int right(int i)
{
  return 2*i+1;
}

void maxHeapify(int i){
  int l,r,largest,tmp;

  l=left(i);
  r=right(i);

  if(l<=h && A[l]>A[i]) largest=l;

  else largest=i;

  if (r<=h && A[r]>A[largest]){
 
   largest=r;

  }

  if (largest!=i){

    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;

    maxHeapify(largest);
  }
}

  void buildMaxHeap(void){
    for(i=h/2;i>=1;i--){
      maxHeapify(i);
    }
  }

  int main()
  {

    scanf("%d",&h);

    for(i=1;i<=h;i++){

      scanf("%d",&A[i]);

    }

  buildMaxHeap();

   for(i=1;i<=h;i++){

   printf(" %d",A[i]);

   }

 printf("\n");

    return 0;
  }

Measured memory_bytes: 2552
import java.util.Scanner;

class Main
{
    public static void main(String args[])
    {
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.print(a*b+" ");
        System.out.println(2*a+2*b);
    }
}


Measured memory_bytes: 25820
#include <iostream>

using namespace std;

int main() {
    int N, T, c, t, ans = 1e+9;

    cin >> N >> T;

    for (int i=0; i<N; i++) {
        cin >> c >> t;
        if (t <= T && c <= ans) {
            ans = c;
        }
    }

    if (ans == 1e+9) cout << "TLE" << endl;
    else             cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,k,n) for(int i=k;i<=n;i++)
using namespace std;
const int maxn=100005;
ll a[maxn];
ll b[maxn];
int n;
ll cnt[maxn];
int main()
{
	cin>>n;
	rep(i,0,n) cin>>a[i];
	rep(i,0,n-1) cin>>b[i];
	if(a[0]>=b[0]) cnt[0]=b[0];
	else cnt[0]=a[0],cnt[1]=b[0]-a[0];
	rep(i,1,n)
	{
		if(cnt[i]>=a[i])
		{
			cnt[i+1]=b[i];
		}
		else
		{
			if(cnt[i]+b[i]>=a[i])
			cnt[i+1]=cnt[i]+b[i]-a[i],cnt[i]=a[i];
			else cnt[i]+=b[i];
		}
	}
	ll ans=0;
	rep(i,0,n)
	ans+=min(cnt[i],a[i]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define f first
#define s second
#define int ll
using namespace std;
using ll = long long;
using ii = pair<int, int>;

// FFT
#define REP(i,n) for(int i = 0; i < int(n); ++i)
typedef double ld; // &#39;long double&#39; is 2.2 times slower
struct C { ld real, imag;
	C operator * (const C & he) const {
		return C{real * he.real - imag * he.imag,
				real * he.imag + imag * he.real};
	}
	void operator += (const C & he) { real += he.real; imag += he.imag; }
};
void dft(vector<C> & a, bool rev) {
	const int n = a.size();
	for(int i = 1, k = 0; i < n; ++i) {
		for(int bit = n / 2; (k ^= bit) < bit; bit /= 2);;;
		if(i < k) swap(a[i], a[k]);
	}
	for(int len = 1, who = 0; len < n; len *= 2, ++who) {
		static vector<C> t[30];
		vector<C> & om = t[who];
		if(om.empty()) {
			om.resize(len);
			const ld ang = 2 * acosl(0) / len;
			REP(i, len) om[i] = i%2 || !who ?
					C{cos(i*ang), sin(i*ang)} : t[who-1][i/2];
		}
		for(int i = 0; i < n; i += 2 * len)
			REP(k, len) {
				 const C x = a[i+k], y = a[i+k+len]
						* C{om[k].real, om[k].imag * (rev ? -1 : 1)};
				a[i+k] += y;
				a[i+k+len] = C{x.real - y.real, x.imag - y.imag};
			}
	}
	if(rev) REP(i, n) a[i].real /= n;
}
template<typename T>vector<T> multiply(const vector<T> & a, const vector<T> & b) {
	if(a.empty() || b.empty()) return {};
	int n = a.size() + b.size();
	vector<T> ans(n - 1);
	/* if(min(a.size(),b.size()) < 190) { // BRUTE FORCE
		REP(i, a.size()) REP(j, b.size()) ans[i+j] += a[i]*b[j];
		return ans; } */
	while(n&(n-1)) ++n;
	auto speed = [&](const vector<C> & w, int i, int k) {
		int j = i ? n - i : 0, r = k ? -1 : 1;
		return C{w[i].real + w[j].real * r, w[i].imag
				- w[j].imag * r} * (k ? C{0, -0.5} : C{0.5, 0});
	};
	vector<C> in(n), done(n);
	REP(i, a.size()) in[i].real = a[i];
	REP(i, b.size()) in[i].imag = b[i];
	dft(in, false);
	REP(i, n) done[i] = speed(in, i, 0) * speed(in, i, 1);
	dft(done, true);
	REP(i, ans.size()) ans[i] = is_integral<T>::value ?
			llround(done[i].real) : done[i].real;
	//REP(i,ans.size())err=max(err,abs(done[i].real-ans[i]));
	return ans;
}

constexpr ll P = 200003;

ll pw(ll base, ll exp) {
	ll res = 1;
	while (exp) {
		if (exp & 1) (res *= base) %= P;
		exp >>= 1, (base *= base) %= P;
	}
	return res;
}

ll inv(ll x) { return pw(x, P - 2); }

int dlog[P], dexp[P];

signed main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    for (int i = 0, m = 1; i < P-1; ++i, m = (m<<1)%P) dexp[i] = m, dlog[m] = i;

    int N; cin >> N;
    vector<int> A(P), cnt(P);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (A[i]) ++cnt[dlog[A[i]]];
    }
    
    vector<int> ans = multiply(cnt, cnt), mult(P);
    for (int i = 0; i < ans.size(); ++i) {
        if (ans[i]) mult[dexp[i%(P-1)]] += ans[i];
    }
    for (int i = 0; i < N; ++i) --mult[(ll)A[i]*A[i]%P];
    
    ll out = 0;
    for (int i = 1; i < P; ++i) out += mult[i]/2*i;
    cout << out;
}

Measured memory_bytes: 37596
import itertools

n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

x = [i + 1 for i in range(m)]
A = itertools.combinations_with_replacement(x, n)

ans = 0
for i in A:
    score = 0
    for j in abcd:
        if i[j[1] - 1] - i[j[0] - 1] == j[2]:
            score += j[3]
    ans = max(ans, score)
print(ans)

Measured memory_bytes: 9172
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<pair<int, int> > ab;
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        ab.push_back({x, y});
    }
    sort(ab.begin(), ab.end());
    vector<pair<int, int> > adj[n+1];
    for (int i = 0; i < m; i++) {
        int l, r; cin >> l >> r;
        int p = lower_bound(ab.begin(), ab.end(), make_pair(l, -1)) - ab.begin(),
            q = upper_bound(ab.begin(), ab.end(), make_pair(r, 2)) - ab.begin();
        if (p < q) {
            adj[p].push_back({q, i+1});
            adj[q].push_back({p, i+1});
        }
    }

    int B[n+1];
    {
        int tmp = 0;
        int prev = 0;
        for (auto e : ab) {
            B[tmp++] = prev ^ e.second;
            prev = e.second;
        }
        B[n] = accumulate(B, B+n, 0) % 2;
    }
    vector<bool> visited(n+1, false);

    fill(visited.begin(), visited.end(), false);
    vector<int> ans;
    function<int(int)> dfs = [&](int i) {
        int res = 0;
        visited[i] = true;
        for (pair<int, int> e : adj[i]) {
            int j = e.first;
            if (visited[j]) continue;
            int k = dfs(j);
            if (k != B[j]) {
                res++;
                ans.push_back(e.second);
            }
        }
        return res % 2;
    };

    for (int i = 0; i <= n; i++) {
        if (visited[i]) continue;
        int k = dfs(i);
        if (k != B[i]) {
            cout << "-1\n";
            return 0;
        }
    }

    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for (int j : ans) cout << j << " ";
    cout << endl;
}


Measured memory_bytes: 20036
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long P = sc.nextLong();
		HashMap<Long, Long> map = new HashMap<Long, Long>();
		
		boolean flag = true;
		out : while(flag) {
			for(long i = 2; i <= Math.sqrt(P); i++) {
				if(P % i == 0) {
					if(map.containsKey(i)) {
						P /= i;
						map.put(i, map.get(i) + 1);
						continue out;
					} else {
						P /= i;
						map.put(i, (long)1);
						continue out;
					}
				}
			}
			if(map.containsKey(P)) {
				map.put(P, map.get(P) + 1);
			} else {
				map.put(P, (long)1);
			}
			flag = false;
		}
		
		long ans = 1;
		for(long i : map.keySet()) {
			long temp = map.get(i) / N;
			if(temp >= 1) {
				ans = ans * (long)Math.pow(i, temp); 
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    string S,T;
    cin >> S >> T;
    if(S.size() +1 != T.size()){
            cout << "No" << endl;
            return 0;
    }
    rep(i,S.size()){
        if(S[i] != T[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextInt();
		long d = in.nextInt();
		long ans;

		ans = (long) Math.ceil((double)n / (d*2+1));



		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include<stdio.h>

int main(){
	char N[18];
	scanf("%s",N);
	int l,flag=1;
	for(int i=0;N[i]!='\0';i++){
		l++;
		if(l>=2 && N[i]!='9')flag=0;
	}
	if(flag==1)printf("%d\n",(N[0]-'0')+(l-1)*9);
	else printf("%d\n",(N[0]-'0')+(l-1)*9-1);
	return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A1222 solver = new A1222();
        solver.solve(1, in, out);
        out.close();
    }

    static class A1222 {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            out.println(in.string().chars().filter(c -> c == '2').count());
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



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

using namespace std;

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

int main() {
  
  int N; cin >> N;
  
  double x[N], y[N];
  rep(i, N) {
    cin >> x[i] >> y[i];
  }
  
  double sum = 0;
  rep(i, N) {
    sum += (x[i]-x[(i+1)%N])*(y[i]+y[(i+1)%N]);
  }
  
  printf("%.1f\n", sum/2.);
  
  return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
class Dijkstra{
    private:
        struct edge{
            ll to,cost;
        };
        vector<vector<edge>> G;
        vector<ll> d;
        int siz;
    public:
        Dijkstra(int n){
            G.resize(n);
            siz = n;
        }
        void add_edge(int from,int to,ll cost){
            G[from].push_back(edge{to,cost});
            G[to].push_back(edge{from,cost});
        }
        vector<ll> dijkstra(int s){
            priority_queue<P,vector<P>,greater<P>> q;
            d.assign(siz,INF);
            d[s] = 0;
            q.push(P(0,s));
            while(!q.empty()){
                P p = q.top();q.pop();
                int v = p.second;
                if (d[v] < p.first) continue;
                for(edge &e:G[v]){
                    if (chmin(d[e.to],d[v]+e.cost)){
                        q.push(P(d[e.to],e.to));
                    }
                }
            }
            return d;
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,s,t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    Dijkstra g1(n),g2(n);
    ll u,v,a,b;
    rep(i,m){
        cin >> u >> v >> a >> b;
        u--;
        v--;
        g1.add_edge(u,v,a);
        g2.add_edge(u,v,b);
    }
    vector<ll> yen = g1.dijkstra(s);
    vector<ll> snuke = g2.dijkstra(t);
    vector<ll> cost(n);
    rep(i,n){
        cost[i] = yen[i]+snuke[i];
    }
    rep(i,n-1){
        chmin(cost[n-i-2],cost[n-i-1]);
    }
    ll k = 1e15;
    rep(i,n){
        PRINT(k-cost[i]);
    }
}


Measured memory_bytes: 20552
program main
  implicit none

  integer :: n, i, cnt
  integer(16) :: ans
  integer(16), allocatable :: a(:)

  read(*,*) n
  allocate(a(n))
  
  ans = 0
  cnt = 0
  read(*,*) a
  call quicksort(a, 1, n)
  do i = n, 2, -1
     if(a(i) == a(i-1)) then
        ans = a(i)
        cnt = i
        exit
     end if
  end do

  do i = cnt-2, 2, -1
     if(a(i) == a(i-1)) then
        ans = ans * a(i)
        exit
     end if
     if(i == 2) then
        ans = 0
     end if
     
  end do

  write(*,*) ans

  stop
  
contains
  recursive subroutine quicksort(a, first, last)
    implicit none
    integer(16) ::  a(*)
    integer :: first, last
    integer :: i, j
    integer ::  x, t
    
    x = a( (first+last) / 2 )
    i = first
    j = last
    do
       do while (a(i) < x)
          i=i+1
       end do
       do while (x < a(j))
          j=j-1
       end do
       if (i >= j) exit
       t = a(i);  a(i) = a(j);  a(j) = t
       i=i+1
       j=j-1
    end do
    if (first < i - 1) call quicksort(a, first, i - 1)
    if (j + 1 < last)  call quicksort(a, j + 1, last)
  end subroutine quicksort

end program main

  


Measured memory_bytes: 4528
#!/usr/bin/env python3
import sys
import math
from decimal import *

def solve(A: int, B: int):
    A = Decimal(str(A))
    B = Decimal(str(B))
    s8 = Decimal('0.08')
    s10 = Decimal('0.10')
    n8 = [math.ceil(A/s8), math.floor((A+1)/s8)]
    n10 = [math.ceil(B/s10), math.floor((B+1)/s10)]

    # print(n8, n10)
    if n10[0] <= n8[0] < n10[1]:
        print(int(n8[0]))
    elif n8[0] <= n10[0] < n8[1]:
        print(int(n10[0]))
    else:
        print('-1')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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


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


    vector<int> dp(N, 1e+9);  // dp[i]: minimum cost to reach i
    dp[0] = 0;
    for( int i = 1; i < N; ++i ){
        int loop_max = (i <= K)? i: K;
        for( int j = 1; j <= loop_max; ++j ){
            dp[i] = min( dp[i], abs(h[i] - h[i-j]) + dp[i-j] );
        }
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

struct edge
{
    int to, cost;
};
typedef pair<int, int> P; //firstは最短距離,secondは頂点の番号
#define V 100010
vector<edge> G[V];
int d[V];

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);
    d[s] = 1;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        for (int i = 0; i < G[v].size(); i++)
        {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

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

    int k;
    cin >> k;
    rep(i, k) G[i].push_back({(i + 1) % k, 1});
    rep(i, k) G[i].push_back({(i * 10) % k, 0});
    dijkstra(1);
    cout << d[0] << endl;
}

Measured memory_bytes: 9276
// AGC 040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    string s; cin >> s;
    int len = s.length();
    ll a[len+1], c = 0;
    a[0] = 0;
    bool f = false;
    ll ans = 0;
    for(int i = 1; i <= len; i++){
        if(s[i-1] == '<'){
            if(f){
                a[i] = 1; f = false; 
                if(a[i-1]<0){
                    ans += (c+1)*abs(a[i-1]);
                }else if(a[i-1]>0){
                    ans -= (c)*a[i-1];
                }
                c=0;
            }else{
                a[i] = a[i-1]+1;
            }

        }else{
            f = true;
            a[i] = a[i-1]-1; c++;
        }
        ans += a[i];
    }

    if(s[len-1] == '>'){
        if(a[len]<0){
            ans += (c+1)*abs(a[len]);
        }else if(a[len]>0){
            ans -= (c)*a[len];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4740
#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>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
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;
 
 
 
signed main(){
	int N;
	cin >> N;
	vector<string>v(N);
	REP(i, N) {
		cin >> v[i];
	}
	vector<vector<vector<int>>>vs;
	REP(i, N) {
		vector<vector<int>>tmp(v[i].size() + 1, vector<int>(26));
		REP(j, v[i].size()) {
			REP(k, 26) {
				tmp[j + 1][k] += tmp[j][k] + (v[i][j] - 'a' == k);
			}
		}
		vs.emplace_back(tmp);
	}
	vector<int>id(N);
	iota(ALL(id), 0);
	auto dfs = [&](auto&&f, vector<int>&a, int tail) -> long long {
		vector<int>cnt(26);
		REP(i, a.size()) {
			if(v[a[i]].size() - tail == 1) {
				++cnt[v[a[i]][0] - 'a'];
			}
		}
		long long ret = 0;
		REP(i, a.size()) {
			REP(j, 26) {
				int t = vs[a[i]][vs[a[i]].size() - tail - 1][j] - vs[a[i]][0][j];
				if(t) ret += cnt[j];
			}
		}
		ret -= accumulate(ALL(cnt), 0ll);
		vector<vector<int>>next(26);
		REP(i, a.size()) {
			if(v[a[i]].size() - tail == 1) continue;
			next[v[a[i]][v[a[i]].size() - tail - 1] - 'a'].emplace_back(a[i]);
		}
		vector<int>().swap(a);
		REP(i, 26) {
			if(next[i].size() == 0) continue;
			ret += f(f, next[i], tail + 1);
			vector<int>().swap(next[i]);
		}
		return ret;
	};
	out(dfs(dfs, id, 0));
}

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

typedef long long int LL;
#define REP(n) for(LL i = 0; i < (n); i++)
#define COUT(val) cout << (val) << endl
#define CIN(val) cin >> (val)
#define SORT(vec) sort(vec.begin(), vec.end())
#define SORT_GRE(vec) sort(vec.begin(), vec.end(), greater<LL>())

int main(){
    int n, m;
    cin >> n >> m;
    int v[n][m+1];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m+1; j++){
            v[i][j] = 0;
        }
    }
    int size;
    for(int i = 0; i < n; i++){
        size = 100;
        for(int j = 0; j <= size; j++){
            if(j == 0){
                cin >> v[i][j];
                size = v[i][j];
            } else {
                cin >> v[i][j];
            }
        }
    }
    vector<int> M(m+1);
    for(int i = 0; i <= m; i++){
        M[i] = 0;
    }
    for(int i = 0; i < n; i++){
        for(int j = 1; j < m+1; j++){
            M[v[i][j]]++;
        }
    }
    int ans = 0;
    for(int i = 1; i < M.size(); i++){
        if(M[i] == n) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
CSF = [list(map(int, input().split())) for i in range(n - 1)]
CSF.append([0, 0, 0])
for i in range(n):
    c, s, f = CSF[i]
    t = s + c
    for j in range(i + 1, n):
        c, s, f = CSF[j]
        if f == 0:
            break
        if t > s:
            s = s + (t - s + (f - 1)) // f * f
        t = s + c
    print(t)

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

#define   ll     long long int

void sortt(ll &a, ll &b, ll &c)
{
    if (a < b) swap(a, b);
    if (b < c) swap(c, b);
    if (a < b) swap(a, b);
}

ll func(ll h, ll w)
{
    ll i, j, k, s = 1e15;
    ll first, second, third;
    ll w_second = w / 2;
    ll w_third = w - w_second;

    for (i = 1; i < h; i++) {
        first = i * w;
        j = h - i;
        second = j * w_second;
        third = j * w_third;
        sortt(first, second, third);
        s = min(s, first - third);

        first = i * w;
        ll h_second = j / 2;
        ll h_third = j - h_second;
        second = h_second * w;
        third = h_third * w;
        sortt(first, second, third);
        s = min(s, first - third);
        //cout << i << ' ' << first << ' ' << second << ' ' << third << '\n';
    }
    return s;
}

int main( )
{
    ll h, w;
    cin >> h >> w;
    if (h % 3 == 0 || w % 3 == 0) {
        cout << "0\n";
        return 0;
    }
    cout << min(func(h, w), func(w, h)) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
 
#define pb push_back
#define VDEL(v, n) v.erase(v.begin() + (n))
#define ALL(v) v.begin(), v.end()
 
#define INT_INF 200000000
 
#define TINT(str) atoi(str.c_str())
#define TSTR(num) to_string(num)
 
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int>> VII;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
 
//the end of library zone

int N, H, W;

signed main(){
	cin >> N >> H >> W;
	int i = (N - H + 1) * (N - W + 1);
	cout << i << endl;
    return 0;
}


Measured memory_bytes: 256