akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

int main(void){
    // Here your code !
    int N,t = 0;
    ll res = 0;
    cin >> N;
    
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
        res += a[i];
    } 
    
    ll tmp = 0;
    for(int i = 1; i <= N; i++ ) tmp+=i;
    
    if(res % tmp){
        cout << "NO" << endl;
        return 0;
    } 
    
    ll tmp1 = res / tmp;
   
    for(int i = 0; i < N; i++){
        
        int tmp2 = a[i] - a[(i+1)%N]+ tmp1;
        
        if(tmp2%N != 0 || tmp2 < 0 ){
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;

    return 0;
    
}


Measured memory_bytes: 640
io = STDIN
n=io.gets.chomp.to_i
a=io.gets.chomp.split.map(&:to_i)
hash=Hash.new{|h,k|h[k]=0}
ar=[]
a.each do |x|
  if x<3200
    hash[x/400]+=1
  else
    ar<< x
  end
end
min = hash.keys.size
max = (hash.keys.size+ar.size)
puts "#{min==0 ? 1 : min} #{max}"


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

int main()
{
string d="ABC";
int N,c=0;
cin>>N;
char A[N];
for (int i=0;i<N;i++){
	cin>>A[i];
}
string r = "";

//char A[N];
//for(int i=0;i<N;i++)
//cin>>A[i];
for(int i=0;i<=N-3;i++){
	r += A[i]; r += A[i + 1];r+=A[i+2];
	if (r==d){
		
		c+=1;
		}
	r="";	
	}	
	

	
cout<<c;	
		
}
	





Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for (int i=a;((c>0)?i<b:i>b);i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) a.begin(),a.end()
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

#define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

class Piece {
public:
  int x1, x2, y1, y2;
  Piece() {}
  Piece(int x1, int x2, int y1, int y2) {
	this->x1 = x1;
	this->x2 = x2;
	this->y1 = y1;
	this->y2 = y2;
  }

  int area() const {
	return (x2 - x1) * (y2 - y1);
  }
  
  bool operator < (const Piece& r) const {
	int a = this->area();
	int b = r.area();
	return a < b;
  }
};

int n, w, d;
vector<Piece> pieces;

void cut(int p, int s_) {
  Piece cur = pieces[p];
  pieces.erase(pieces.begin() + p);
  int x_length = cur.x2 - cur.x1;
  int y_length = cur.y2 - cur.y1;
  if (test) dump(x_length);
  s_ %= (x_length + y_length) * 2;

  Piece next1, next2;
  next1 = cur;	
  next2 = cur;
  if (s_ < x_length) {
	int x = cur.x1 + s_;
	next1.x2 = x;
	next2.x1 = x;
  }

  else if (s_ < x_length + y_length) {
	int y = cur.y1 + s_ - x_length;
	next1.y2 = y;
	next2.y1 = y;
  }

  else if (s_ < x_length * 2 + y_length) {
	int x = cur.x1 + x_length * 2 + y_length - s_;
	next1.x2 = x;
	next2.x1 = x;
  }

  else if (s_ < x_length * 2 + y_length * 2) {
	int y = cur.y1 + x_length * 2 + y_length * 2 - s_;
	next1.y2 = y;
	next2.y1 = y;
  }

  else {
	cerr << "!" << endl;
	exit(0);
  }

  if (next2 < next1) swap(next1, next2);
  pieces.push_back(next1);
  pieces.push_back(next2);
}

void solve() {
  cin >> n >> w >> d;
  if (n == 0 && w == 0) exit(0);
  pieces.clear();
  Piece start(0, w, 0, d);
  pieces.push_back(start);
  rep(i, n) {
  	int p, s;
  	cin >> p >> s;
  	p--;
  	cut(p, s);
  }
  sort(all(pieces));
  cout << pieces[0].area();
  rep2(i, 1, (int)pieces.size()) {
	cout << " " << pieces[i].area();
  }
  cout << endl;
}

signed main() {
  int T = (int)1e9;
  rep(i, T) {
  	char s[MAX];
  	if (scanf("%s", s) == EOF) break;
  	rrep(i, strlen(s)) {
  	  ungetc(s[i], stdin);
  	}
  	solve();
  }
  return 0;
}

Measured memory_bytes: 3156
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
  exit()

sm=1 if n!=m else 2
while n>0:
  sm=(sm*n)%(10**9+7)
  n-=1
while m>0:
  sm=(sm*m)%(10**9+7)
  m-=1
print(sm)


Measured memory_bytes: 9120
N, H = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

a, b = zip(*((a, b) for a, b in X))
am = max(a)
b = sorted(b, reverse=True)

ans = 0
h = H
for v in b:
    if v > am:
        h -= v
        ans += 1

    if h <= 0:
        break
        
if h > 0:
    ans += -(-h // am)

print(ans)


Measured memory_bytes: 82392
s = input()
t = input()
max_count = 0
for i in range(len(s) - len(t)):
    count = 0
    for j in range(len(t)):
        if s[i + j] == t[j]:
            count += 1
    max_count = max(count, max_count)
if len(s) == len(t):
    for i in range(len(t)):
        if s[i] == t[i]:
            max_count +=1
print(len(t) - max_count)

Measured memory_bytes: 9096
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
int gcd(int a, int b) // assuming a,b >= 1
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    if (a % b == 0)
        return b;
    return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
    return  a * b / gcd(a, b);
}
using namespace std;
#pragma endregion
signed main() {
    string S, T;
    int N;
    N = 0;
    cin >> S >> T;
    rep(i, 3) {
        if (S[i] == T[i])
            N++;
    }     
    cout << N;
}

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

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};



int main(){
    Stream io;

    int N;
    io.read(N);

    vector<int> v(2 * 10000 + 1, 0);
    
    for(int x = 1; x < 150; x++){
        for(int y = 1; y < 150; y++){
            for(int z = 1; z < 150; z++){
                int n = (x + y) * (x + y) + (y + z) * (y + z) + (z + x) * (z + x);
                if(n <= 2 * 10000) v[n]++;
            }
        }
    }
    for(int i = 1; i <= N; i++){
        cout << v[2 * i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 3644
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

L, R = LI()

ret = INF

for i in range(L, min(L+2019+1, R+1)):
    for j in range(i+1, min(L+2019+1, R+1)):
        ret = min((i*j)%2019, ret)

print(ret)

Measured memory_bytes: 42732
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------

void Main(){
  int n;
  cin>>n;
  vi a(n),b(n);
  vi sa(n,0),sb(n,0);
  vi ret(n,0);
  cin>>a>>b;
  sa[0  ]=a[0  ];
  sb[n-1]=b[n-1];
  rep(i,n-1){
    sa[i+1] = sa[i  ]+a[i+1]; 
  }
  drep(i,n-1){
    sb[i  ] = sb[i+1]+b[i  ]; 
  }
  rep(i,n){
    ret[i] = sa[i]+sb[i];
  }
  cout<<*max_element(rng(ret))<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 256
//2019.5.17 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-10
#define RG register
inline int read() {
    res s=0,ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s;
}
inline LL Read() {
    RG LL s=0;
    res ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s;
}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int kcz=1e9+7;
namespace MAIN {
    int n;
    inline void add(res &x,const res &y){
        x+=y,x>=kcz?x-=kcz:1;
    }
    inline int mul(const res &x,const res &y){
        return int(1LL*x*y%kcz);
    }
    int ans;
    inline int qpow(res x,res y){
        res ret=1;
        while(y){
            if(y&1)ret=mul(ret,x);
            x=mul(x,x),y>>=1;
        }
        return ret;
    }
    int pw=1;
    inline void MAIN(){
        n=read();
        for(res i=0;i<n;i++)pw=mul(pw,3),add(ans,qpow(mul(pw,n-i),kcz-2));
        printf("%d\n",mul(ans,qpow(n,kcz-2)));
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("graph.in","r",stdin);
//    freopen("graph.out","w",stdout);
    MAIN::MAIN();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define cinf(n,x,y,z) for(int i=0;i<(n);i++) cin >> x[i]>>y[i]>>z[i];
typedef long long int ll;
using namespace std;
int MAX=100010;
vector<int> prime(MAX,1);
int main(){
	prime[0]=0; prime[1]=0;
	for(int i=2;i<MAX;i++){
		if(!prime[i]) continue;
		for(int j=i*2;j<MAX;j+=i){
		 prime[j]=0;
		}
	}
	vector<int> a(MAX,0);
	for(int i=0;i<MAX;i++){
		if(i%2==0) continue;
		if(prime[i]&&prime[(i+1)/2])a[i]=1;
	}
	vector<int> s(MAX+1,0);
	for(int i=0;i<MAX;i++){
		s[i+1]=s[i]+a[i];
	}
	int q; cin >>q;
	for(int i=0;i<q;i++){
		int l,r; cin >>l>>r;
		cout << s[r+1]-s[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#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 chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int H, W, K;
	cin >> H >> W >> K;

	string S[6];
	rep(i, H) cin >> S[i];

	int kotae = 0;
	rep(i, 1 << H) rep(j, 1 << W) {
		int cnt = 0;
		rep(p, H) rep(q, W) {
			if (i >> p & 1) {
				if (j >> q & 1) {
					if(S[p][q] == '#') cnt++;
				}
			}
		}
		if (cnt == K) kotae++;



	}

	co(kotae);







	Would you please return 0;
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
string S;

int main()
{
	cin >> S;
	N = S.size();

	FOR(i,0,N - 1){
		if(S.substr(i,2) == "AC"){
			puts("Yes");
			return 0;
		}
	}
	puts("No");

	return 0;
}


Measured memory_bytes: 256
#include<queue>
#include <map>
#include<iostream>
#include<cstring>
using namespace std;
typedef pair<int,int> P;

queue<P> qu;

int main()
{
  int table[200][200];
  int n;
  cin>>n;
  for(int x=0;x<n;x++) // ノード数
    {
      int r;   // ノード番号
      int k;   // rにつながるノード数
      cin>>r>>k;
      for(int i=0;i<k;i++)
	{
	  int t; // rにつながるノード番号
	  cin>>t;
	  table[r][t]=1;
	}
    }
  int p;
  cin>>p;
  for(int x=0;x<p;x++)
    {
      int s,d,v;
      cin>>s>>d>>v;
      int ans = -1;
      queue<P> qu;
      int c[200];
      memset(c,-1,sizeof(c));  //経路到達情報の初期化
      if(v>1)                   //TTLが1のときは追加しない
	for(int i=0;i<200;i++)
	  if(table[s][i]==1)    //s->iの経路があればキューに追加
	    qu.push(P(i,2));
       
      while(!qu.empty()) {     //キューが空になるまで続ける
	P a = qu.front(); qu.pop(); //キューの先頭を取出
	//	cout<<a.first<<"  "<<a.second<<endl;
	//a.firstがゴールなら、終了
	if(a.first==d) { ans=a.second;break; }
	if(a.second+1<=v) { // パケットのTTLが0にならないとき
	  for(int i=0;i<200;i++) {
	    //隣接かつ今までそのノードに到達していなければキューに追加
	    if(table[a.first][i]==1 && c[i]==-1) {
	      c[i] = 1;
	      qu.push(P(i,a.second+1));
	    }
	  }
	}
	
      }
      if(ans!=-1)
	cout<<ans<<endl;
      else
	cout<<"NA"<<endl;
      
    }
  

  

}

Measured memory_bytes: 1284
from collections import deque
import copy
S = deque(input())
S2 = deque([])
counter = 0
while True:
    flag = True
    while True:
        if len(S) == 0:
            break
        s = S.popleft()
        if len(S2) == 0:
            S2.append(s)
            flag = False
            continue
        
        elif s!=S2[-1]:
            S2.pop()
            flag = False
            counter +=2
        else:
            S2.append(s)
    
    if flag:
        break
    else:
        S = copy.deepcopy(S2)
print(counter)

Measured memory_bytes: 6680
import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    b_count = 0
    a_count = 0
    b_and_a_count = 0
    ans = 0

    for i in range(n):
        s = sys.stdin.readline().rstrip("\n")
        len_s = len(s)
        for j in range(len_s-1):
            if s[j] == "A":
                if s[j+1] == "B":
                    ans += 1
        if s[0] == "B" and s[-1] == "A":
            b_and_a_count += 1
        elif s[0] == "B":
            b_count += 1
        elif s[-1] == "A":
            a_count += 1

    if b_and_a_count > 0:
        ans += (b_and_a_count-1)
        if a_count > 0:
            ans += 1
            a_count -= 1
        if b_count > 0:
            ans += 1
            b_count -= 1

    ans += min(a_count, b_count)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 42352
#include <stdio.h>

int main() {
	int i, j, k, n, v;
	int a[100];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for (i = 0; i < n; i++) {
		v = a[i];
		j = i - 1;

		while (j >= 0 && a[j] > v) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;

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

		printf("%d\n", a[n - 1]);
	}

	return 0;
}



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

int gcd(int p,int q){
	while(q!=0){
		int r=p%q;
		p=q;
		q=r;
	}
	return p;
}

int main(){
	int n;
	cin >> n;
	int sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				sum+=gcd(gcd(i,j),k);
			}
		}
	}
	cout << sum << endl;
	return 0;
} 

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

bool irohaLike(int n, const unordered_set<int> m){
	while(n){
		if(m.count(n % 10)) {
			return false;
		}
		n /= 10;
	}
	return true;
}

int main() {
	int n, k;
	unordered_set<int> m;
	cin >> n >> k;
	for(int i = 0; i < k; i++){
		int tmp;
		cin >> tmp;
		m.insert(tmp);
	}
	while(1) {
		if (irohaLike(n, m)) break;
		n++;
	}
	cout << n;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

ll len[51],pat[51];
ll rec(ll k, ll x){
  if(x == len[k]) return pat[k]; //x層の数がlenと同じだったら全パティの数を返せば良い
  ll ans = 0;
  x--;
  
  if(x > 0){//まず下のバーガーから計算
    ll l = min(x,len[k-1]); //xがk-1レベルのバーガーを超えていたらlenにする。(xが下段のバーガーに収まるかチェック)
    ans += rec(k-1,l);
    x -= l;
  }
  
  if(x > 0){//真ん中のパティ
    ans++;
    x--;
  }
  
  if(x > 0){//上段のバーガー
    ll l = min(x,len[k-1]);
    ans += rec(k-1,l);
    x -= l;
  }
  
  return ans;
}

int main(){
  ll n,x; cin >> n >> x;
  //先にバーガーの長さとパティの数を計算して配列に入れておく
  len[0] = pat[0] = 1;
  for(int i = 1; i <= n; i++){
    len[i] = len[i-1] * 2 + 3;
    pat[i] = pat[i-1] * 2 + 1;
  }
  
  cout << rec(n,x) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int N, Q;
vector<int> edges[200000];
int64_t num[200000];
 
void dfs(int i, int p){
    for(int j : edges[i]) if(j != p){
        num[j] += num[i];
        dfs(j, i);
    }
}
 
int main(){
    cin >> N >> Q;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }
    for(int i=0; i<Q; i++){
        int p, x;
        cin >> p >> x;
        num[p-1] += x;
    }
    dfs(0, -1);
    for(int i=0; i<N; i++) cout << num[i] << " \n"[i==N-1];
    return 0;
}

Measured memory_bytes: 24320
S = input()

if S == 'SAT':
    print(1)
elif S == 'FRI':
    print(2)
elif S == 'THU':
    print(3)
elif S == 'WED':
    print(4)
elif S == 'TUE':
    print(5)
elif S == 'MON':
    print(6)
elif S == 'SUN':
    print(7)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	#define pb push_back
	#define mp make_pair
	#define sz(a) ll(a.size())
	#define trace(c,x) for(auto &x:c)
	#define F first
	#define S second		
	ll mod = 1e9 + 7;   //change acc to question

ll fastexpo(ll x,ll y)
{
	ll a=1;
	while(y>0)
	{
		if(y&1)a = (a*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}	
	return a;
}

int memo[100005];
int a[103];
int n;

int dp(int i)
{
	// cout<<i<<endl;
	if(i==0)
		return 0;
	if(i<0)
		return 1;
	if(memo[i]!=-1)
		return memo[i];

	int val = 0;
	memo[i] = 0;
	for(int j=0;j<n;j++)
	{
		val = dp(i-a[j]);
		if(val==0)
			memo[i] = 1;
	}

	return memo[i];
}


int main()
{

	ios::sync_with_stdio(false);

	int k;
	cin>>n>>k;

	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<=k;i++)
		memo[i] = -1;

	if(dp(k)==1)
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	return 0;

	}	

Measured memory_bytes: 5376
import java.util.*;
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		X -= A;
		while (X >= B) {
			X -= B;
		}
		System.out.println(X);
	}
}

Measured memory_bytes: 21716
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.io.PrintWriter;
import java.util.Arrays;;
import java.util.StringTokenizer;

/**
 * The Java template file for AtCoder online judge.
 */
public class Main {

  private static FastScanner scanner;
  private static PrintWriter printer;

  public static void solve() {
    int n = scanner.nextInt();
    int w = scanner.nextInt();
    int[] weights = new int[n];
    int[] values = new int[n];
    for (int i = 0; i < n; i++) {
      weights[i] = scanner.nextInt();
      values[i] = scanner.nextInt();
    }
    int total_values = 0;
    for (int value : values) {
      total_values += value;
    }
    long[] dp = new long[total_values + 1];
    Arrays.fill(dp, Long.MAX_VALUE/2);
    dp[0] = 0L;
    for (int i = 0; i < n; i++) {
      for (int j = total_values; j >= values[i]; j--) {
        dp[j] = Math.min(dp[j], dp[j - values[i]] + weights[i]);
      }
    }
    int result = 0;
    for (int i = total_values; i >= 0; i--) {
      if (dp[i] <= w) {
        result = i;
        break;
      }
    }
    printer.println(result);
  }

  public static void main(String[] args) {
    scanner = new FastScanner();
    printer = new PrintWriter(System.out);
    solve();
    printer.flush();
  }

  private static class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(Reader in) {
      br = new BufferedReader(in);
    }

    public FastScanner() {
      this(new InputStreamReader(System.in));
    }

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

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    public int[] readIntArray(int size) {
      int[] ret = new int[size];
      for (int i = 0; i < size; i++) {
        ret[i] = nextInt();
      }
      return ret;
    }
  }
}


Measured memory_bytes: 21972
//2018.09.21 10min

#include <iostream>
using namespace std;

int main() {

    string c1,c2;
    cin >> c1 >> c2;

    if(c1[0]==c2[2] && c1[1]==c2[1] && c1[2] == c2[0]) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, m);
  vector<pair<int, int>> job(n);
  rep(i, n) cin >> job[i].first >> job[i].second;
  sort(all(job));

  int i = 0;
  priority_queue<int> que;
  int ans = 0;
  rep(j, m) {
    while (i < n && job[i].first <= j + 1) {
      que.push(job[i].second);
      ++i;
    }
    if (que.empty()) continue;
    ans += que.top();
    que.pop();
  }
  out(ans);
}


Measured memory_bytes: 4688
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305, OFF = 305;

int N, M, ans;
int pst[2*MAXN][MAXN], psk[2*MAXN][MAXN];
vector<int> tambah[2*MAXN], kurang[2*MAXN];

int solve(int R, int C, vector<vector<char>> arr, int corner) {
	vector<vector<int>> ps(R+C+5, vector<int>(R+5, 0));
	for (int i = 1; i <= R; i++) {
		for (int j = 1; j <= C; j++) {
			if (arr[i][j] == '#') {
				ps[i+j][i] = ps[i+j][i-1]+1;
			} else {
				ps[i+j][i] = ps[i+j][i-1];
			}
		}
	}
	
	int ret = 0;
	for (int i = 2; i <= R+C; i++) {
		for (int r1 = max(1, i-C); r1 <= min(R, i-1); r1++) {
			for (int r2 = r1+1; r2 <= min(R, i-1); r2++) {
				int c1 = i-r1, c2 = i-r2;
				if (arr[r1][c1] != '#' || arr[r2][c2] != '#') continue;
				int dist = r2-r1 + c1-c2;
				assert(dist > 0);
				if (i-dist >= 2) {
					int l = max(0, r2-dist-corner);
					int r = min(min(R, i-dist-1), r1-1+corner);
					ret += ps[i-dist][r]-ps[i-dist][l];
					//~ if (r1 == 2 && r2 == 3) cerr << r << " " << ps[i-dist][l] << " " << ps[i-dist][r] << endl;
					//~ if (ps[i-dist][r]-ps[i-dist][l] != 0) cerr << r1 << " " << r2 << endl;
				}
				if (i+dist <= R+C) {
					int l = max(0, r2-corner);
					int r = min(min(R, i+dist-1), r1+dist-1+corner);
					ret += ps[i+dist][r]-ps[i+dist][l];
					//~ if (ps[i+dist][r]-ps[i+dist][l] != 0) cerr << r1 << " " << r2 << endl;
				}
			}
		}
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> M;
	vector<vector<char>> arr(N+5, vector<char>(M+5));
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			cin >> arr[i][j];
		}
	}
	
	int ans = solve(N, M, arr, 1);
	
	vector<vector<char>> rotated(M+5, vector<char>(N+5));
	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= N; j++) {
			rotated[i][j] = arr[N+1-j][i];
		}
	}
	ans += solve(M, N, rotated, 0);
	
	cout << ans << "\n";
}


Measured memory_bytes: 1340
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long[] abcde = new long[5];

		for (int i = 0; i < 5; i++) {
			abcde[i] = sc.nextLong();
		}
		Arrays.sort(abcde);

		System.out.println((long) Math.ceil((double) n / abcde[0]) + 4);
		sc.close();
	}
}

Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    int y, x;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            string s;
            cin >> s;
            if (s == "snuke") {
                y = i;
                x = j;
            }
        }
    }
    cout << (char)(x + 'A') << y + 1 << endl;
    return 0;
}


Measured memory_bytes: 764
// abc135_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int a, b;
  cin >> a >> b;
  if (a % 2 != b % 2) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << (a+b)/2 << endl;
  }
  return 0;
}


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

int main() {
  int l,r,d;
  cin >> l >> r >> d;
 
  cout << r/d-(l-1)/d << endl;
  
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  REP(i,N) { cin >> H[i]; }

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

  ll ans;
  if (N <= K){
    ans = 0;
  } else {
    ans = accumulate(H.begin(), H.end()-K, 0LL);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int a,n,i;
	while(scanf("%d",&a)!=EOF){
	i=a%39;
	if(i==0)
	{
	printf("3C39\n");
	}
	else if(i<=9)
	{
		printf("3C0%d\n");
	}
	else
	{
		printf("3C%d\n",i);
	}
	}
	return 0;
}

Measured memory_bytes: 608
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	vector<vector<int> > g(n);
	for (int a,b,i = 0; i < m; ++i) {
		scanf("%d%d", &a, &b);
		--a; --b;
		g[a].push_back(b);
		swap(a, b);
		g[a].push_back(b);
	}
	for (int i = 0; i < n; ++i) {
		sort(g[i].begin(), g[i].end());
		if (i && i != n - 1 && g[i].size() >= 2) {
			if (g[i][0] == 0 && g[i][g[i].size() - 1] == n - 1) {
				puts("POSSIBLE");
				return 0;
			}
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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;
}

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

    int n, m, x;
    cin >> n >> m >> x;
    vi c(n);
    vii a(n, vector<int>(m));
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }

    int ans = INF;
    rep(bit, (1 << n)) {
        vector<int> s;
        vector<int> v(m, 0);
        int money = 0;
        rep(i, n) if (bit & (1 << i)) s.push_back(i);

        rep(i, s.size()) {
            money += c[s[i]];
            rep(j, m) {
                v[j] += a[s[i]][j];
            }
        }

        bool all_ok = true;
        rep(i, m) if (v[i] < x) all_ok = false;

        if (all_ok) {
            chmin(ans, money);
        }
    }

    if (ans == INF)
        out(-1);
    else
        out(ans);
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> A(N*N,-1),B(N);
  vector<pair<int,int>> C(N);
  for(int i=0;i<N;i++){
    cin>>B[i];
    B[i]--;
    A[B[i]]=i+1;
    C[i]=make_pair(B[i],i);
  }
  sort(C.begin(),C.end());
  int n=0,m=1;
  for(int i=0;n<N;n++,m=1)
    for(;m<C[n].second+1;i++)
      if(A[i]==-1)
        A[i]=C[n].second+1,m++;
  n=N-1,m=N;
  for(int i=N*N-1;n>=0;n--,m=N)
    for(;m>C[n].second+1;i--)
      if(A[i]==-1)
        A[i]=C[n].second+1,m--;
  for(int i=1;i<=N;i++){
    int n=0,j=0;
    for(;j<N*N;j++){
      if(A[j]==i)
        n++;
      if(n==i)
        break;
    }
    if(j!=B[i-1]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  for(int i=0;i<N*N;i++){
    cout<<A[i];
    if(i==N*N-1)
      cout<<endl;
    else
      cout<<' ';
  }
}

Measured memory_bytes: 5352
from heapq import heappush,heappop

def main():
  n,m,s,t=map(int,input().split())
  INF=10**20
  G1,G2 = [{} for _ in range(n)],[{} for _ in range(n)]
  for i in range(m):
    u,v,a,b=map(int,input().split())
    G1[u-1][v-1] = G1[v-1][u-1] = a
    G2[u-1][v-1] = G2[v-1][u-1] = b

  def dijkstra(G,start = 0):
      d = [INF for i in range(len(G))]
      d[start] = 0
      que = []
      heappush(que, (0, start))

      while len(que):
          p = heappop(que)
          v = p[1]
          if d[v] < p[0]:
              continue
          for u in G[v].keys():
              if d[u] > d[v] + G[v][u]:
                  d[u] = d[v] + G[v][u]
                  heappush(que, (d[u], u))
      return d

  d1 = dijkstra(G1,s-1)
  d2 = dijkstra(G2,t-1)

  ans=[]
  MIN = INF
  for i in range(n-1,-1,-1):
    MIN = min(MIN,d1[i]+d2[i])
    if i == s-1:
      MIN = min(MIN,d2[s-1])
    if i == t-1:
      MIN = min(MIN,d1[t-1])

    ans.append(MIN)

  print(*[10**15-ans[-i-1] for i in range(n)])
  
if __name__=="__main__":
  main()

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

char buf[100];
int main() {
	int q; cin >> q;
	rep(i, q) {
		ll s; scanf("%llx", &s);
		string t = bitset<32>(s).to_string();
		string a = t.substr(1, 24);
		int b = 0, p = 1;
		for (int i = a.size() - 1; i >= 0; i--) {
			b += p*(a[i] - '0'); p *= 2;
		}
		double d = 0, y = 0.5;
		string c = t.substr(25);
		rep(i, c.size()) {
			d += y*(c[i] - '0'); y /= 2;
		}
		double ans = b + d;
		if (t.front() == '1')ans = -ans;
		sprintf(buf, "%.20lf", ans);
		string u = buf;
		while (u.back() == '0')u.pop_back();
		if (u.back() == '.')u.pop_back();
		if ((int)u.find('.') == -1)u += ".0";
		cout << u << endl;
	}
}

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

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const int N = 50000;
const int M = 20;
const int INF = 1e9;
int n, m;
int d[M], dp[N+1];

int main() {
  fscanf(stdin, "%d%d ", &n, &m);
  REP(i,m) fscanf(stdin, "%d ", d+i);
  REP(i,N+1) dp[i] = INF;
  dp[0] = 0;
  REP(i,m) REP(j,n+1) {
    if (j - d[i] < 0) continue;
    dp[j] = min(dp[j], dp[j - d[i]] + 1);
  }
  fprintf(stdout, "%d\n", dp[n]);
  return 0;
}



Measured memory_bytes: 3424
#include <stdio.h>
int main(void) {
    int a,b,n,i,j,x,y;
    while (scanf("%d %d",&a,&b)!=EOF&&(a!=0||b!=0)) {
        int map[18][18]={{0}};
        scanf("%d",&n);
        for (i=0; i<n; i++) {
            scanf("%d %d",&x,&y);
            map[x][y]=-1;
        }
        if (map[1][1]==-1) {
            printf("0\n");
            continue;
        } else {
            map[1][1]=1;
        }
        for (i=1; i<=a; i++) {
            for (j=1; j<=b; j++) {
                if (map[i][j]==-1) {
                    map[i][j]=0;
                } else {
                    map[i][j]+=map[i-1][j]+map[i][j-1];
                }
            }
        }
        printf("%d\n",map[a][b]);
    }
    return 0;
}

Measured memory_bytes: 600
N = int(input())
MOD = 10**9+7
if N == 1:
    print(0)
    exit()
ans = 1
dp = [[8, 1, 1, 0] for _ in range(N)]
for i in range(1, N):
    dp[i][0] = dp[i-1][0]*8 % MOD
    dp[i][1] = dp[i-1][1]*9 % MOD+dp[i-1][0]
    dp[i][2] = dp[i-1][1]*9 % MOD+dp[i-1][0]
    dp[i][3] = dp[i-1][3]*10 % MOD+dp[i-1][1]+dp[i-1][1]
print(dp[-1][-1] % MOD)


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

typedef long long ll;

int a[105];

int main()
{
  ios::sync_with_stdio(false);
  int n; cin >> n;
  for(int i = 0; i < n; ++ i) {
    cin >> a[i];
  }
  int ans = 0;
  for(int i = 0; i <= 100; ++ i) {
    int pre = 0;
    for(int j = 0; j < n; ++ j) {
      if(a[j] == 0) pre = 0;
      else {
        if(pre == 0) ans ++;
        pre = 1; -- a[j];
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	int N;
	cin >> N;
	VL a;
	FOR(i, 0, N)
		a.push_back(IN<LL>());

	LL cost = INF;
	FOR(i, -100, 101) {
		LL nowcost = 0;
		FOR(j, 0, a.size()) {
			nowcost += pow((a[j] - i), 2);
		}
		cost = min(cost, nowcost);
	}
	O(cost);

	return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
edge = { i:[] for i in range(1,N+1)}
for _ in range(M):
    x,y = map(int,input().split())
    edge[x] += [y]
import sys 

sys.setrecursionlimit(10**5+1)
dp = [-1]*(N+1)
def distance(start):
    if dp[start] > 0:
        return dp[start]
    elif len(edge[start]) == 0:
        dp[start] = 0
        return 0
    else:
        temp = [distance(e) + 1 for e in edge[start]]
        dp[start] =  max(temp)
        return dp[start]

for i in range(1,N+1):
    go = distance(i)
print(max(dp))

Measured memory_bytes: 118372
package main

import(
	"fmt"
)

func main() {
	var a,b,c,d,e,k int
	fmt.Scan(&a,&b,&c,&d,&e,&k)
	
	if (e - a <= k) {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <vector>

using namespace std;

const int MAXN = 1e5 + 10;
int n, m, a[MAXN], d[MAXN], cnt = 0;
long long ans = 1e18, now = 0;
vector <int> v[MAXN];

void push(int st, int ed, int k) {
	if (st > m)
		st -= m;
	if (ed > m)
		ed -= m;
	v[st].push_back(k);
	v[ed].push_back(-k);
	if (st > ed) {
		now -= d[k];
		now += ed - 1;
		++ cnt;
	}
}

int main() {
//	freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	for (int i = 1; i < n; ++i)
		now += d[i] = a[i+1] >= a[i] ? a[i+1] - a[i] : a[i+1] + m - a[i];
	for (int i = 1; i < n; ++i)
		push(a[i]+1, a[i+1]+1, i);
	for (int i = 1; i <= m; ++i) {
		int sz = v[i].size();
		for (int j = 0; j < sz; ++j) {
			int x = v[i][j];
//			cerr << x << endl;
			if (x > 0) {
				++ cnt;
			}
			else {
				x = -x;
				now += d[x];
				-- cnt;
			}
		}
		now -= cnt;
		ans = min(ans, now + cnt);
//		cerr << now << " " << cnt << endl;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
      cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int count=0;
  
  if(vec.at(n/2) == vec.at(n/2-1)){
    count=0;
  }
  else{
      for(int i=vec.at(n/2-1); i<vec.at(n/2); i++){
    count++;}
  }
  cout << count << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int a,b,c;
	a=n%10;
	n=n/10;
	b=n%10;
	n=n/10;
	c=n%10;
	if(c<b || (b==c && a>b)) cout << c+1 << c+1 << c+1;
	else{
        cout << c << c << c;
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256