akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define f first
#define s second
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lint, lint>
#define ld long double
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define vi vector<int>

const int N=1e5+5;
const int MOD=1e9+7;
const lint INF=1e18;

lint _add(lint x, lint y)
{
    lint ret=x+y;
    while(ret<0LL)
        ret+=MOD;
    return ret;
}

lint _mult(lint x, lint y)
{
    x%=MOD;
    y%=MOD;
    lint ret=x*y;
    ret%=MOD;
    while(ret<0LL)
        ret+=MOD;
    return ret;
}

using namespace std;
using namespace __gnu_pbds;

template <typename T> 
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n, m, dp[N], togo[N];
pair<int, int> segt[4*N];
char str[N];

inline int lt(int x){return 2*x;}
inline int rt(int x){return 2*x+1;}

void build(int nd, int s, int e)
{
    if(s==e)
    {
        segt[nd]={1e9, 1e9};
        return;
    }
    int m=(s+e)/2;
    build(lt(nd), s, m);
    build(rt(nd), m+1, e);
    segt[nd]={1e9, 1e9};
}

void upd(int nd, int s, int e, int idx, int val)
{
    if(s>idx || e<idx)
        return;
    if(s==e)
    {
        segt[nd]={val, s};
        return;
    }
    int m=(s+e)/2;
    upd(lt(nd), s, m, idx, val);
    upd(rt(nd), m+1, e, idx, val);
    segt[nd]=min(segt[lt(nd)], segt[rt(nd)]);
}

pair<int, int> quer(int nd, int s, int e, int l, int r)
{
    if(s>r || e<l)
        return {1e9, 1e9};
    if(s>=l && e<=r)
        return segt[nd];
    int m=(s+e)/2;
    return min(quer(lt(nd), s, m, l, r), quer(rt(nd), m+1, e, l, r));
}

int main()
{
    scanf("%d%d %s", &n, &m, str);
    build(1, 1, n);
    for(int a=n; a>=0; a--)
    {
        if(str[a]=='1')
            dp[a]=1e9;
        else if(a==n)
            dp[a]=0;
        else
        {
            pair<int, int>here=quer(1, 1, n, a+1, min(a+m, n));
            dp[a]=here.f+1;
            togo[a]=here.s;
            // printf("%d %d ", a+1, min(a+m, n));
        }
        upd(1, 1, n, a, dp[a]);
        // printf("%d %d\n", a, dp[a]);
        // for(int b=1; b<=n; b++)
        //     printf("%d ", quer(1, 1, n, 1, b).f);
        // printf("\n");
        // for(int b=1; b<=m; b++)
        //     if(a+b<=n)
        //         dp[a]=min(dp[a], dp[a+b]);
    }
    if(dp[0]>=1e9)
        printf("-1\n");
    else
    {
        int i=0;
        while(i<n)
        {
            printf("%d ", togo[i]-i);
            i=togo[i];
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
int main()
{
    int a;
    int b;
    scanf("%d",&a);
    scanf("%d",&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    } 
    return 0;   
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
 
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N, K;
ll a[200000];
ll ans = 0;
ll sum[200500];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 1; i <= N; i++) {
        sum[i] = sum[i-1] + a[i-1];
    }
    for(int i = 0; i + K <= N; i++) {
        chmax(ans, sum[i+K] - sum[i]);
    }
    ans += K;
    cout << fixed << setprecision(20) << ans / 2.0;
    return 0;
}

Measured memory_bytes: 6928
#include <stdio.h>

int main()
{
	unsigned long long x,y;
	scanf("%llu %llu", &x, &y);
	if(x%y == 0)
	{
		printf("-1\n");
	}
	else
	{
		printf("%I64u\n",x);
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
t = [[0 for _ in range(3)] for j in range(N-1)]
for i in range(N-1):
    t[i][0], t[i][1], t[i][2] = map(int, input().split())

for i in range(N-1):
    time = t[i][1] + t[i][0]
    for j in range(i+1,  N-1):
        if time < t[j][1]:
            time = t[j][1]
        elif (time - t[j][1]) % t[j][2] == 0:
            pass
        else:
            time += t[j][2] - ((time - t[j][1]) % t[j][2])
        time += t[j][0]
    print(time)
print(0)





Measured memory_bytes: 3188
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int n;
string s;
bool check(char a,char b,vector<char>& t){
	t[0] = a;
	t[1] = b;
	for(int i = 1;i < n-1;i++){
		if(s[i] == 'o'){
			if(t[i] == 'S')t[i+1] = t[i-1];
			if(t[i] == 'W')t[i+1] = (t[i-1] == 'S' ? 'W' : 'S');
		}
		if(s[i] == 'x'){
			if(t[i] == 'S')t[i+1] = (t[i-1] == 'S' ? 'W' : 'S');
			if(t[i] == 'W')t[i+1] = t[i-1];
		}
	}

	bool flag = true;
	for(int i = 0;i < n;i++){
		int prev = ((i - 1) + n) % n;
		int next = (i + 1) % n;
		if(s[i] == 'o'){
			if(t[i] == 'S'){
				if(t[prev] != t[next])return false;
			}
			if(t[i] == 'W'){
				if(t[prev] == t[next])return false;
			}
		}
		if(s[i] == 'x'){
			if(t[i] == 'S'){
				if(t[prev] == t[next])return false;
			}
			if(t[i] == 'W'){
				if(t[prev] != t[next])return false;
			}
		}
	}
	return true;
}


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

	vector<char> t(n);
	if(check('S','W',t)){
		for(int i = 0;i < n;i++)cout << t[i];
		cout << endl;
		return 0;
	}
	if(check('S','S',t)){
		for(int i = 0;i < n;i++)cout << t[i];
		cout << endl;
		return 0;
	}
	if(check('W','S',t)){
		for(int i = 0;i < n;i++)cout << t[i];
		cout << endl;
		return 0;
	}
	if(check('W','W',t)){
		for(int i = 0;i < n;i++)cout << t[i];
		cout << endl;
		return 0;
	}

	cout << -1 << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


int main(void) {
	string s;
	cin >> s;
	int check[26];
	for(int i=0; i<26; i++)check[i]=0;
	for(int i=0; i<s.length(); i++){
		check[s[i]-'a']++;
	}
	cout << endl;
	for(int i=0; i<26; i++){
		if(check[i]==0){
			cout << (char)(i+'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define endl "\n"

#define k first
#define v second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define ALL(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.k << ", " << p.v << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    long long n;
    cin >> n;
    cout << n * (n - 1) / 2 << endl;
}


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

int main() {
  
  int a,b,c,d;
  int tak,aok;
  cin >> a >> b >> c >> d;
  if (c % b == 0){
    tak = c/b;
  }else{
  tak = int((double)c/b)+1;
  }
  if(a % d==0){
    aok = a/d;
  }else{
  aok =  int((double)a/d)+1;
  }
    if (tak <= aok){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int dp[15][15];

int main() {
  // ll n;
  // scanf("%lld",&n);
  // rep(w,n)rep(i,w+1) {
  //   int j = w-i;
  //   rrep(k,i/2) {
  //     if (!dp[i-k*2][j+k]) dp[i][j] = 1;
  //   }
  //   rrep(k,j/2) {
  //     if (!dp[i+k][j-k*2]) dp[i][j] = 1;
  //   }
  // }
  // rep(i,n) {
  //   rep(j,n) printf("%d",dp[i][j]);
  //   newline;
  // }
  ll x,y;
  scanf("%lld%lld",&x,&y);
  if (abs(x-y) > 1) cout<<"Alice"<<endl;
  else cout<<"Brown"<<endl;
  return 0;
}






















Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int k,x,n,y,a;
	scanf("%d%d%d%d",&n,&k,&x,&y);
	if(n<=k)
	{
		a=n*x;
		printf("%d",a);
	}
	else
	{
	a=k*x+(n-k)*y;
	printf("%d",a);
}
	return 0;
 } 

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

int main() {
	int n, v[22], c[22];
  	scanf("%d", &n);
  	for (int i = 0; i < n; i ++) scanf("%d", &v[i]);
  	for (int i = 0; i < n; i ++) scanf("%d", &c[i]);
  	int ans = 0;
  	for (int i = 0; i < n; i ++) ans += max(0, v[i] - c[i]);
  	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
const int MOD = 1e9+7;
using namespace std;

int main(){
	int n, m, p;
	cin >> n >> m;
	vector <int> wa(n+1);
	vector <bool> ac(n+1);
	string s;
	for (int i = 0; i < m; i++){
		cin >> p >> s;
		if (s == "AC" && ac[p] == false){
			ac[p] = true;
		}else if (s == "WA" && ac[p] == false){
			wa[p]++;
		}
	}
	int ans_ac = 0;
	int ans_wa = 0;
	for (int i = 1; i <= n; i++){
		if (ac[i] == true){
			ans_ac++;
			ans_wa += wa[i];
		}
	}

	cout << ans_ac << " " << ans_wa << endl;
	return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())

n = 2*M+1
# Mが奇数の場合
if M%2==1:
    for i in range(1, M//2+1):
        print('{} {}'.format(i,M+1-i))
    for i in range(1, (M+1)//2+1):
        print('{} {}'.format(M+i,2*M+2-i))
# Mが偶数の場合
else:
    for i in range(1, M//2+1):
        print('{} {}'.format(i,M+2-i))
    for i in range(1, M//2+1):
        print('{} {}'.format(M+i+1,2*M+2-i))
    


Measured memory_bytes: 9108
N, K= (int(v) for v in input().split())
A = [0] + [int(v) for v in input().split()] 
first_visit = [0 for i in range(N+1)]

visited = []
current = 1
step = 0
loop_length = 1
loop_start = 0 
while True: 
    if step == K:
        print(current) 
        exit()

    if first_visit[current] != 0: 
        loop_length = step - first_visit[current]
        loop_start = first_visit[current]
        break

    
    first_visit[current] = step
    visited.append(current)
    current = A[current]
    step = step + 1

loop_index = loop_start + (K - loop_start) % loop_length

print(visited[loop_index])

Measured memory_bytes: 31948
n = int(input())
moto = [int(i) for i in input().split()]
 
array=[0]*n
 
for i in reversed(range(1,n+1)):
  if sum(array[i-1::i])%2 != moto[i-1]:
    array[i-1] = 1
    
m = array.count(1)
print(m)
ans = ""
for i in range(n):
  if array[i] == 1:
    print(i+1, end=" ")

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

// 300, 20min?

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

string S;
vector<string> ans_pattern;

signed main()
{
    cin >> S;

    // AKIHABARA に A は 4 つ → 2^4=16パターンの正解がある
    for(int i = 0; i < 16; ++i) {
        string cand = "";
        if((i >> 0) & 1) { cand += "A"; }
        cand += "KIH";
        if((i >> 1) & 1) { cand += "A"; }
        cand += "B";
        if((i >> 2) & 1) { cand += "A"; }
        cand += "R";
        if((i >> 3) & 1) { cand += "A"; }
        ans_pattern.push_back(cand);
    }

    for(auto& pat : ans_pattern) {
        if(pat == S) {
            printf("YES\n");
            return 0;
        }
    }

    printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }

bool is_palindrome(string s)
{
   FOR(i, 0, s.length()/2)
      if (s[i] != s[s.length() - i - 1])
         return false;
   return true;
}

int main()
{
   string s;
   cin >> s;
   int n = s.length();

   if(is_palindrome(s) and is_palindrome(s.substr(0,(n-1)/2)) and is_palindrome(s.substr((n+3)/2-1, (n-1)/2)))
   {
      cout << "Yes" << endl;
      return 0;
   }

   cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "YES":"NO"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		ll N = s.size();
		// [i]: i-1で終わる文字列がvalidかどうか
		vector<bool> dp(N+1);
		dp[0] = 1;
		vector<string> tb = {"dream", "dreamer", "erase", "eraser"};
		REP(i, N+1) if(dp[i]) REP(ti, tb.size()) {
			ll ni = i+tb[ti].size();
			if(ni<N+1 && s.substr(i, tb[ti].size())==tb[ti]) {
				dp[ni] = 1;
			}
		}
		cout<<YN(dp[N])<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 592
def main():
    N = int(input())
    default_time = list(map(int, input().split()))
    M = int(input())

    drink_list = list()

    for m in range(M):
        P, X = map(int, input().split())
        drink_list.append([P, X])

    for d in drink_list:
        P = d[0]
        X = d[1]
        time = default_time[:]
        time[P - 1] = X
        print(sum(time))
main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N;
    cin >> N;
    int S_N = 0;
    for(int i = 0; i < to_string(N).size(); i++){
        S_N += to_string(N)[i] - '0';
    }
    Yes(N % S_N == 0);
}


Measured memory_bytes: 256
#include<stdio.h>


int main(){

  int i,H,A[250];  

  scanf("%d",&H);
  for(i=1; i<=H ; i++){
    scanf("%d",&A[i]);
      }

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

     printf("node %d: key = %d, ",i,A[i]);

   if(i != 1){
     if(i % 2 == 0){
       printf("parent key = %d, ",A[i/2]);
       }
     else{
       printf("parent key = %d, ",A[(i-1)/2]);
	 } 
   }

   if(i * 2  > H ){printf("\n"); continue;}  
   printf("left key = %d, ",A[2*i]);
   if(i * 2 + 1  > H){printf("\n"); continue;} 
   printf("right key = %d, ",A[2*i+1]);
   
   printf("\n");
   }
   return 0;
}
     



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

  ll H, W; cin >> H >> W;
  vector<string> field(H);
  rep(h, 0, H) cin >> field[h];
  bool f = true;
  rep(h, 0, H-1) rep(w, 0, W-1){
    if(field[h][w] == '#'&&field[h][w+1] == '#'
    && field[h+1][w] == '#'&&field[h+1][w+1] == '#') f = false;
    if(field[h][w] == '.'&&field[h][w+1] == '#'
    && field[h+1][w] == '#'&&field[h+1][w+1] == '#') f = false;
    if(field[h][w] == '#'&&field[h][w+1] == '#'
    && field[h+1][w] == '#'&&field[h+1][w+1] == '.') f = false;
  }

  if(f) cout << "Possible" << endl;
  else cout << "Impossible" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int a,b,c;
	int count = 1;
	scanf("%d %d",&a,&b);
	for(int i = 0; i < a ; i++) {
		scanf("%d",&c);
	}
	
	if(a < b){
		count++;
		printf("%d",count);
	}else if (a > b) {
		a -= b;
		while(a > 0){
			a -= (b-1);
			count++;
		}
	}	

	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define lint long long

signed main() {
  lint n, k;
  cin >> n >> k;
  vector<lint> a(200000);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  lint loop = 0;
  lint curr = 0;
  lint interval = 0;
  lint isPast[200000] = {-1};
  for(lint i = 0; i < 200000; i++){
    isPast[i] = -1;
  }
  lint looped = 0;
  isPast[0] = 0;
  do{
    curr = a[curr] - 1;
    looped++;
    if(isPast[curr] != -1){
      interval = isPast[curr];
      loop = looped - interval;
      break;
    }
    isPast[curr] = looped;
    //looped++;
  }while(true);
  
  curr = 0;
  lint remain = 0;
  if(k > interval){
    remain = (k - interval) % loop + interval;
  }else{
    remain = k;
  }
  for(lint i = 0; i < remain; i++){
    curr = a[curr] - 1;
  }
  cout << curr + 1 << endl;
}

Measured memory_bytes: 6428
import numpy as np
# coding: utf-8
# Your code here!
N, K = map(int, input().split())
#S = input()
Ai_list = []
 
for i in range(K):
    di = int(input())
    Ai_list += input().split()
 
#print(Ai_list)
print(N - len(set(Ai_list)))

Measured memory_bytes: 27096
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
int main() {
	int n;
	cin >> n;
	ll sum = 0; 
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i != n - 1) {
			sum += a[i];
		}
	}
	ll ans = a[n-1];
	ll kai = abs(sum-ans);
	for (int i = n - 2; i >0; i--) {
		
			ans += a[i];
			sum -= a[i];
		
		
		kai = min(kai, abs(ans - sum));
	}
	cout << kai << endl;
	return 0;
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		double a = double.Parse(input[0]);
		double b = double.Parse(input[1]);
		double x = double.Parse(input[2]);
		double theta = 0;
		double degree = 0;
		if((x/(a*a))>(b/2))
		{
			theta = Math.Atan((2*(b-(x/(a*a))))/a);
		}
		else
		{
			theta = Math.Atan(b/((2*x)/(a*b)));
		}
		degree = (theta/3.14159265358979d)*180.000000d;
		Console.WriteLine(degree);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N, M; cin >> N >> M;
	//vector<pair<int, int>> gate(M);
	int L = -1, R = 1e7;
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		L = max(L, a), R = min(R, b);
	}
	cout << min(N, max(0,R - L + 1));

}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N;
    cin >> N;
    bool check=false;
    for(int i=1;i<=100000;i++){
        int val=i*1.08;
        if(val==N){
            cout << i << endl;
            check=true;
            break;
        }
    }
    if(!check) cout << ":(" << endl;
}

Measured memory_bytes: 256
import Data.Array.IO
import Control.Applicative
import Data.List
import Control.Monad

getLineN :: Int -> IO [String]
getLineN n = replicateM n getLine

getNum = read <$> getLine :: IO Int
getNumList = map read.words <$> getLine :: IO [Int]

main = do
    [a,b] <- getNumList
    putStrLn.show $ length $ filter (\c -> c < a || (c <= a && c <= b)) [1..12]

Measured memory_bytes: 508
using System;
using System.Collections.Generic;

namespace AOJ.Volume1
{
    public class Abacus
    {
        public static void Main()
        {
            var dic = new Dictionary<string, string>
            {
                {"0", "* = ****"},
                {"1", "* =* ***"},
                {"2", "* =** **"},
                {"3", "* =*** *"},
                {"4", "* =**** "},
                {"5", " *= ****"},
                {"6", " *=* ***"},
                {"7", " *=** **"},
                {"8", " *=*** *"},
                {"9", " *=**** "},
            };

            bool first = true;
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                if (!first) { Console.WriteLine(); }

                input = input.PadLeft(5, '0');
                string[] output = new string[5];
                // 変換
                for (int i = 0; i < 5; i++)
                {
                    output[i] = dic[input.Substring(i, 1)];
                }

                // 出力
                for (int i = 0; i < 8; i++)
                {
                    string line = "";
                    for (int j = 0; j < 5; j++) { line += output[j].Substring(i, 1); }
                    Console.WriteLine(line);
                }

                first = false;
            }
        }
    }
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
pair<pair<string, int>, int> p[110000];

signed main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        string S;
        int P;
        cin >> S >> P;
        p[i] = make_pair(make_pair(S, -P), i);
    }
    sort(p + 1, p + N + 1);
    for (int i = 1; i <= N; i++)cout << p[i].second << endl;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pi 3.1415
	 
int main()
{
	fastio;
	int r;
	cin>>r;
	float ans=(2.0)*pi*r;
	printf("%f\n",ans);
	
	return 0;
	
	
}

Measured memory_bytes: 3784
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import defaultdict

def main():
	s=defaultdict(int)
	n=II()
	for _ in range(n):
		s[RD()]+=1
	m=II()
	for _ in range(m):
		s[RD()]-=1

	ans=0
	for k,v in s.items():
		ans=max(ans,v)
	print(ans)





if __name__ == "__main__":
	main()


Measured memory_bytes: 9488
#include<bits/stdc++.h>
using namespace std;
int main(){
 int a,b,c;
 cin >> a >> b >> c;
 if((a*100+b*10+c)%4 == 0){
	cout << "YES" << endl;
 }else{
 cout << "NO" << endl;
 }
 
 
}

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

const int MAX_N = 2e5 + 5;
int dp[MAX_N];
vector<int> cnt[26];
string A, ans;

int main(){
    cin >> A;

    for(int i=0;i<A.size();i++) cnt[A[i]-'a'].push_back(i+1);
    for(int i=0;i<26;i++) cnt[i].push_back(A.size()+1);

    for(int i=0;i<=A.size();i++) dp[i] = 100005;
    for(int i=A.size();0<=i;i--){
        for(int j=0;j<26;j++){
            int next = *upper_bound(cnt[j].begin(), cnt[j].end(), i);
            dp[i] = min(dp[i], dp[next]+1);
        }
    }

    int cur = 0;
    while(dp[cur]){
        for(int j=0;j<26;j++){
            int next = *upper_bound(cnt[j].begin(), cnt[j].end(), cur);
            if(dp[cur] == dp[next]+1){
                ans += (char)('a'+j); cur = next;
                break;
            }
        }
    }

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

Measured memory_bytes: 2180
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;

#define all(x) x.begin(), x.end()
#define all_r(x) x.rbegin(), x.rend()
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, n) for(int i = n; i >= 0; --i)
#define f first
#define s second
const int MAXN = 2e6 + 1, MOD = 1e9 + 7;
ll f[MAXN], g[MAXN];
ll expmod(int n, int p) {
	ll x = 1, y = n;
	while(p > 0) {
		if(p & 1) x = x * y % MOD;
		y = y * y % MOD;
		p >>= 1;
	}
	return x;
}
ll C(int n, int k) {
	return f[n] * expmod(f[k] * f[n - k] % MOD, MOD - 2) % MOD;
}
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int K, ans = 0, y = 1;
	string S;
	cin >> K >> S;
	f[0] = g[0] = 1;	
	FOR(i, (int)S.size() + K) {
		f[i + 1] = (i + 1LL) * f[i] % MOD;
		g[i + 1] = g[i] * 25LL % MOD;
	}
	int n = (int)S.size() - 1;
	FOR(i, K + 1) {
		ans = (ans + g[K - i] * C(n + K - i, n) % MOD * y) % MOD;
		y = 26LL * y % MOD;
	}
	cout << ans << '\n';
 	return 0;
}

Measured memory_bytes: 35624
/*package whatever //do not write package name here */

import java.io.*;
import java.lang.Math; 
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
	    Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		
		for(int i = 0; i < n; i++){
		    arr[i] = scan.nextInt();
		}
		
		int[] dp = new int[n];
		dp[1] = Math.abs(arr[0]-arr[1]);
		
		for(int i = 2; i < n; i++ ){
		    dp[i] = Math.min(dp[i-1]+Math.abs(arr[i-1]-arr[i]),dp[i-2]+Math.abs(arr[i-2]-arr[i]));
		}
		System.out.println(dp[n-1]);
		
	}
}

Measured memory_bytes: 49696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

int main()
{
	
    ll n;
    cin>>n;
    int a[n+1]={0};
    int x;
    for(int i=1;i<n;i++)
    {
    	cin>>x;
    	a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
    	cout<<a[i]<<endl;
    }
    return 0;
}

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

int main() {
	// your code goes here
	
	int a;
	scanf("%d",&a);
	
	int b;
	scanf("%d",&b);
	int c=0;
	int d=10;
	
	if(a<b){
		
		printf("%d",c);
		
	}else{
		
		printf("%d",d);
		
	}
	return 0;
}

Measured memory_bytes: 256
fn main() {
    fn read<T: std::str::FromStr>() -> T {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        s.trim().parse().ok().unwrap()
    }
    fn read_vec<T: std::str::FromStr>() -> Vec<T> {
        read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
    }

    fn primes(max:i64) -> Vec<i64>{
        let mut k = vec![2,3];
        for c in (1..(max/6)+1){
            let a = c*6-1;
            let b = c*6+1;
            let mut af = true;
            let mut bf = true;
            for d in (0..k.len()) {
                if(af && (a % k[d]) == 0){
                    af = false;
                }
                if(bf && (b % k[d]) == 0){
                    bf = false;
                }
            }
            if(af){
                k.append(&mut vec![a])
            }
            if(bf){
                k.append(&mut vec![b])
            }
        }
        return k
    }
    fn invmod(p:i64, g:i64) -> i64 {
        fn euclidean(px:i64, py:i64, pgcd:i64, x:i64, y:i64, gcd:i64) -> i64 {
            match (pgcd % gcd) {
                0 => x,
                _ => {
                    let d = pgcd /gcd;
                    let m = pgcd % gcd;
                    return euclidean(x, y, gcd, px-(d*x), py-(d*y), m)
                }
            }
        }
        return (euclidean(1,0,p,0,1,g)+g)%g;
    }
    fn multiper(n:i64, m:i64, c:i64) -> (i64, i64) {
        match m % n {
            0 => multiper(n, m/n, c+1),
            _ => (m,c)
        }
    }

    fn comb(n:i64, k:i64, p:i64)-> i64 {
        let mut ans = 1;
        for c in (1..k+1){
            ans = remain(multi(ans , (n-c+1)), p);
            ans = remain(multi(ans, invmod(c, p)), p);
//            ans = remain(divide(ans , c), p);
        }
        return ans
    }

    fn fac(l:Vec<i64>, m:i64) -> Vec<i64> {
        match l.len() {
            0 => vec![1],
             _ => {
                 let mut ll = l;
                 let a = match multiper(ll.pop().unwrap(), m, 0) {
                     (1, 0) => vec![],
                     (1, y) => vec![y],
                     (x, 0) => {
                         return fac(ll, m)
                     }
                     (x, y) => {
                         let mut k = vec![y];
                         k.append(&mut fac(ll,x));
                         return k
                     }
                 };
                 return a;
            }
        }
    }

    fn multi(a:i64, b:i64) -> i64 {a*b}
    fn divide(a:i64, b:i64) -> i64 {a/b}
    fn remain(a:i64, b:i64) -> i64 {a%b}
    fn main() {
        let max = 1000000007;
        let mut nk = read_vec::<i64>();
        let n:i64 = nk[0];
        let m:i64 = nk[1];
        let primes = primes(((m as f64).sqrt() as i64));

        let f = fac(primes, m);
        let mut a = 1;
        for c in f {
            a = remain(multi(a,comb(n+c-1, c, max)),max)
        }
        println!("{}", a);
    }
    main()
}

Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
struct graph
{
    int head[maxn],nxt[maxn<<1],to[maxn<<1],w[maxn<<1],sz;
    void init(){memset(head,-1,sizeof(head));}
    graph(){init();}
    void push(int a,int b,int c){nxt[sz]=head[a],to[sz]=b,w[sz]=c,head[a]=sz++;}
    int& operator[](const int a){return to[a];}
}g;
int n,a[maxn],b[maxn],m;
struct BIT
{
    int bit[maxn];
    vector<pair<int,int> > update(int x,int k){
        vector<pair<int,int> >v;
        while(x<=m){
            if(bit[x]<k){
                v.push_back(make_pair(x,bit[x]));
                bit[x]=k;
            }
            x+=x&-x;
        }
        return v;
    }
    int query(int x){
        int tmp = 0;
        while(x){
            tmp=max(tmp,bit[x]);
            x-=x&-x;
        }
        return tmp;
    }
}bit;
int ans[maxn];
void dfs(int now,int pre)
{
    ans[now]=bit.query(a[now]-1)+1;
    vector<pair<int,int> >v=bit.update(a[now],ans[now]);;
    ans[now]=max(ans[now],ans[pre]);
    for(int i = g.head[now];~i;i = g.nxt[i]){
        if(g[i]==pre)continue;
        dfs(g[i],now);
    }
    for(int i = 0;i < v.size();++i){
        bit.bit[v[i].first]=v[i].second;
    }
}
int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;++i)scanf("%d",&a[i]),b[i]=a[i];
    sort(b+1,b+1+n);
    m = unique(b+1,b+1+n)-b-1;
    for(int i = 1;i <= n;++i)a[i]=lower_bound(b+1,b+1+m,a[i])-b;
    for(int i = 1;i < n;++i){
        int c,d;
        scanf("%d%d",&c,&d);
        g.push(c,d,0),g.push(d,c,0);
    }
    dfs(1,0);
    for(int i = 1;i <= n;++i)printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 38556
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    for i in 0..s.len() - 1 {
        if s[i] == 'A' && s[i + 1] == 'C' {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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


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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#define rep(i,n) for (int i = 0; i < n; ++i)
const int INF = 1001001001;

using namespace std;

struct Pos {
    int x, y, step;
    Pos(int x_, int y_, int step_) {
        x = x_; y = y_; step = step_;
    }
};

bool dis(int w, int h, int nx, int ny) {
    if (nx < 0) return false;
    else if (nx >= w) return false;
    else if (ny < 0) return false;
    else if (ny >= h) return false;
    return true;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> m(h, vector<char>(w));
    int white = 0;
    rep(i,h) {
        rep(j,w) {
            cin >> m[i][j];
            if (m[i][j] == '.') white++;
        }
    }

    queue<Pos> q;
    q.emplace(0, 0, 0);
    int nx, ny, ns;
    int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};

    while (!q.empty()) {
        for (auto d: dir) {
            nx = q.front().x + d[0];
            ny = q.front().y + d[1];
            ns = q.front().step + 1;
            if (nx == w-1 && ny == h-1) {
                cout << white - ns - 1 << endl;
                return 0;
            } else if (dis(w, h, nx, ny)) {
                if (m[ny][nx] == '.') {
                    q.emplace(nx, ny, ns);
                    m[ny][nx] = '#';
                }
            }
        }
        q.pop();
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

// 素因数分解を求めてベクトル化するライブラリ
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// コンビネーションを求めるライブラリ
const int MAX = 210000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
    int n, m;
    COMinit();
    cin >> n >> m;
    auto vec = prime_factorize(m);
    ll ans = 1;
    for (auto pa : vec) {
        ll num = pa.second;
        ll tmp = COM(num+n-1, n-1);
        ans = (ans * tmp) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>


using namespace std;

int main(){
  int N;
  cin >> N;
  int h[N];
  for(int i=0;i<N;i++) cin >> h[i];
  int dp[N];
  for(int i=0;i<N; i++) dp[i] = INT_MAX;
  dp[0] = 0;
  for(int i = 0 ; i <N; i++){
     if(i+1<N){ dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1])); }
     if(i+2<N){ dp[i+2] = min(dp[i+2], dp[i] + abs(h[i]-h[i+2])); }
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#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<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
#define Endl endl
const int INF=100000000;

int main(){
	ll a,b;
	cin>>a>>b;
	if(a%b==0){
		cout<<-1<<endl;
	}
	else{
		cout<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int a[105][105], b[105][105];

int main( void ) {
    int n, m, l;
    cin >> n >> m >> l;
    for( int i = 0; i < n; ++i ) {
        for( int j = 0; j < m; ++j ) {
            cin >> a[i][j];
        }
    }
    for( int i = 0; i < m; ++i ) {
        for( int j = 0; j < l; ++j ) {
            cin >> b[i][j];
        }
    }
    for( int i = 0; i < n; ++i ) {
        for( int j = 0; j < l; ++j ) {
            ll num = 0;
            for( int k = 0; k < m; ++k ) {
                num += a[i][k] * b[k][j];
            }
            cout << num << ( j == l - 1 ? '\n' : ' ' );
        }
    }
    return 0;
}



Measured memory_bytes: 3168
// i'm a failure
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<bits/stdc++.h>
#include<chrono>
#include<unordered_map>
#include<random>
#include<complex> 
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned ll 
#define endl '\n'
#define mk make_pair
#ifndef ONLINE_JUDGE
int __builtin_popcount(int mask) {
	int cnt = 0;
	for (int i = 0; i < 23; i++)
		if (mask & (1 << i)) ++cnt;
	return cnt;
}
#endif
void fast_in_out() {
	std::ios_base::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
}
int dx[] = { 0,0,-1,1,-1,1,-1,1,0 };
int dy[] = { -1,1,0,0,-1,-1,1,1,0 };
int lx[] = { 2, 2, -1, 1, -2, -2, -1, 1 };
int ly[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
const ld eps = 1e-9;
const int N = 1e6 + 50, M = 1e5 + 10, mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll t = gcd(a, b); return t ? (a / t * b) : 0; }
set<int>sx;
set<int>sy;
struct point {
	int x, y, val;
};
struct query {
	int sx, sy, ex, ey;
};
int main() {
	fast_in_out();
	//cout << fixed << setprecision(9);
	//kolo ra7
	ll n, a, b;
	cin >> n >> a >> b;
	if (abs(a - b) % 2 == 0) {
		cout << abs(a - b)/2 << endl;
	}
	else {
		cout << min(n - b, a - 1)+1+(b-a-1)/2 << endl;
	}
	return 0;
}

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

#define int long long

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

int A, B;

signed main() {
    cin >> A >> B;
    int ans = 0;
    for (int i = A; i <= B; i++) {
        string S = to_string(i);
        if (S[0] == S[4] && S[1] == S[3]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
	int n,m,i,j,count = 0,a[30]={0},k;
	scanf("%d %d",&n,&m);
	
	for(i=0;i<n;i++){
		scanf("%d",&k);
		for(j=0;j<k;j++){
			int l;
			scanf("%d",&l);
			a[l-1]++;
		}
	}
	for(i=0;i<m;i++){
		if(a[i]==n)count++;
	}
	
	printf("%d",count);
	
	return 0;
}

Measured memory_bytes: 128