akhauriyash/Code-Regression huggingface dataset:
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

var S = readLine()!.toArray() + [""]              // 100 + 1 -> 101
let T = readLine()!
var ans = "No"
for _ in 0..<S.count {
    for i in ((0..<S.count).map{$0}).reversed() { // (0..<101).reversed() -> (100...0)
        if i > 0 {
            S[i] = S[i-1]                         // S[100] = S[99]
        } else {
            S[i] = S[S.count-1]                   // S[0] = S[100]
            S[S.count-1] = ""
        }
    }
    if S.joinWithSeparator("") == T {
        ans = "Yes"
        break
    }
}
print(ans)


Measured memory_bytes: 6888
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

typedef long long ll;

using namespace std;

int main(void){
	int n; cin >> n;
	static ll a[SIZE];
	rep(i, n){
		cin >> a[i];
	}

	ll x = 0;
	rep(i, n){
		if(i%2 == 0) x +=a[i];
		else x -= a[i];
	}

	static ll ans[SIZE];
	ans[0] = x/2;
	rep(i, n-1){
		ans[i+1] = a[i] - ans[i];
	}
	rep(i, n){
		cout << ans[i]*2;
		if(i != n-1) cout << " ";
	}
	cout << endl;

	return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string ans;
    int n, s = 1;
    cin >> n;
    while (n != 0) {
        ans += (n % 2 != 0) + '0';
        if (n % 2 != 0)
            n -= s;
        n /= 2;
        s *= -1;
    }
    reverse(ans.begin(), ans.end());
    if (ans.size() == 0) {
        ans = "0";
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=1e5+5;

int n;
string s[N];

int dp[N][4][4][4];
char best[N][4][4][4];

int calc(int p,int a,int b,int c){
	if(a<0 || b<0 || c<0){
		return 0;
	}
	if(a>3)a=3;
	if(b>3)b=3;
	if(c>3)c=3;
	if(p==n){
		return 1;
	}
	int &ans=dp[p][a][b][c];
	if(ans!=-1){
		return ans;
	}
	
	ans=0;
	
	if(s[p]=="AB"){
		if(calc(p+1,a+1,b-1,c)){
			ans=1;
			best[p][a][b][c]='A';
		}
		if(calc(p+1,a-1,b+1,c)){
			ans=1;
			best[p][a][b][c]='B';
		}
	}
	if(s[p]=="AC"){
		if(calc(p+1,a+1,b,c-1)){
			ans=1;
			best[p][a][b][c]='A';
		}
		if(calc(p+1,a-1,b,c+1)){
			ans=1;
			best[p][a][b][c]='C';
		}
	}
	if(s[p]=="BC"){
		if(calc(p+1,a,b+1,c-1)){
			ans=1;
			best[p][a][b][c]='B';
		}
		if(calc(p+1,a,b-1,c+1)){
			ans=1;
			best[p][a][b][c]='C';
		}
	}
	return ans;
}

void solve(){
	mem1(dp);
	int a,b,c;
	cin>>n>>a>>b>>c;
	rep(i,0,n){
		cin>>s[i];
	}
	if(a+b+c == 0){
		cout<<"No";
		return;
	}
	
	if(a>3)a=3;
	if(b>3)b=3;
	if(c>3)c=3;
	
	if(calc(0,a,b,c)){
		cout<<"Yes\n";
		int p=0;
		while(p<n){
			if(a>3)a=3;
			if(b>3)b=3;
			if(c>3)c=3;
			cout<<best[p][a][b][c]<<"\n";
			
			if(best[p][a][b][c]=='A'){
				a++;
				if(s[p]=="AB")b--;
				if(s[p]=="AC")c--;
				p++;
				continue;
			}
			if(best[p][a][b][c]=='B'){
				b++;
				if(s[p]=="AB")a--;
				if(s[p]=="BC")c--;
				p++;
				continue;
			}
			if(best[p][a][b][c]=='C'){
				c++;
				if(s[p]=="AC")a--;
				if(s[p]=="BC")b--;
				p++;
				continue;
			}
		}
	}
	else{
		cout<<"No";
	}
	
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 72408
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
	int n; cin >> n;
	string s; cin >> s;
	unordered_map<string, ll> mp;
	for(int i = 0;i < (1<<n); i++){
		int k = 0;
		string t = "", u = "";
		for(int j = 0;j < n; j++){
			if(1&(i >> j)){
				t += s[j];
				k++;
			}
			else{
				u += s[j];
			}
		}
		reverse(all(u));
		t += u + to_string(k);
		if(mp.count(t)) mp[t] += 1;
		else mp[t] = 1;
	}
	s = s.substr(n, n*2);
	reverse(all(s));
	ll ans = 0;
	for(int i = 0;i < (1<<n); i++){
		int k = 0;
		string t = "", u = "";
		for(int j = 0;j < n; j++){
			if(1&(i >> j)){
				t += s[j];
				k++;
			}
			else{
				u += s[j];
			}
		}
		reverse(all(u));
		t += u + to_string(k);
		if(mp.count(t)) {
			ans += mp[t];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 36680
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import copy

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
T = stdin.readline().rstrip()
num = int(stdin.readline().rstrip())
midcount = 1
res = []
ch = ''
for t in range(len(T)):
    if (ch == T[t] and t != 0):
        midcount += 1
    elif (ch != T[t] and t != 0):
        res.append(midcount)
        midcount = 1
    if (ch == T[t] and t == len(T) - 1):
        res.append(midcount)
    ch = T[t]
if (len(T) == 1):
    res = [1]
if (len(res) == 1):
    print(str(int(num * len(T) / 2)))
elif (T[0] == T[len(T) - 1]):
    counter = 0
    tes = []
    tes.append(res[0] + res[len(res) - 1])
    tes += res[1: len(res) - 1]
    for x in tes:
        counter += int(x / 2)
    counter *= num - 1
    for x in res:
        counter += int(x / 2)
    print(counter)
else:
    counter = 0
    for x in res:
        counter += int(x / 2)
    counter *= num
    print(counter)


Measured memory_bytes: 3444
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    A, B = map(int, input().split())

    p = A + B
    m = A * B
    if p == 15:
        write('+\n')
    elif m == 15:
        write('*\n')
    else:
        write('x\n')

main()


Measured memory_bytes: 2940
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
 
using namespace std;
 
using ll = unsigned long long int;
using pii = pair<int, int>;
 
ll arr[100010] = {};
 
ll func(ll a) {
	return (a + 1)*a / 2;
}
 
 
int main() {
 
	string str;
	cin >> str;
 
	ll arr['z' - 'a' + 1] = {};
 
	for (int i = 0; i < str.size(); i++) {
		arr[str[i] - 'a']++;
	}
 
	ll ans = func(str.size()-1);
 
	for (int i = 'a'; i <= 'z'; i++) {
		ans -= func(arr[i - 'a']-1);
	}
 
	cout << ans+1 << endl;
}
 

Measured memory_bytes: 640
#include<stdio.h>
int map[102][102];
int canwalk;
int judgeOK;
maze(int nowy,int nowx,int gy,int gx){
    map[nowy][nowx]=0;
    /*
    printf("%d %d %d\n",nowx,nowy,judgeOK);
    */
    if(nowy==gy&&nowx==gx){
        judgeOK=1;
    }
    if(map[nowy][nowx+1]==canwalk)
        maze(nowy,nowx+1,gy,gx);
    if(map[nowy+1][nowx]==canwalk)
        maze(nowy+1,nowx,gy,gx);
    if(map[nowy][nowx-1]==canwalk)
        maze(nowy,nowx-1,gy,gx);
    if(map[nowy-1][nowx]==canwalk)
        maze(nowy-1,nowx,gy,gx);
    return judgeOK;
}
int main(void){
    int w,h,xs,ys,xg,yg,n,c,d,x,y;
    int i,j,k;
    for(;;){
        for(i=0;i<102;i++){
            for(j=0;j<102;j++){
                map[i][j]=0;
            }
        }
        scanf("%d %d",&w,&h);
        if(w==0&&h==0)
            break;
        scanf("%d %d",&xs,&ys);
        scanf("%d %d",&xg,&yg);
        xs--,ys--,xg--,yg--;
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%d %d %d %d",&c,&d,&x,&y);
            x--,y--;
            if(d==0){
                for(j=0;j<2;j++){
                    for(k=0;k<4;k++){
                            map[y+j][x+k]=c;
                    }
                }
            }
            else{
                for(j=0;j<4;j++){
                    for(k=0;k<2;k++){
                            map[y+j][x+k]=c;
                    }
                }
            }
        }
        /*
        for(i=0;i<w;i++){
            for(j=0;j<h;j++){
                printf("%d ",map[i][j]);
            }
        puts("");
        }
        */
            judgeOK=0;
        if(map[ys][xs]==map[yg][xg]){
            if(map[ys][xs]!=0){
                canwalk=map[ys][xs];
                judgeOK=maze(ys,xs,yg,xg);
            }
        }
        if(judgeOK==1)
            puts("OK");
        else
            puts("NG");
    }
return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
vector<ll> div(ll x) {
    vector<ll> ret;
    ret.push_back(x);
    for (ll i = 2; i*i <= x; i++) {
        if (x % i != 0) continue;
        ret.push_back(i);
        if (i * i != x) ret.push_back(x / i);
    }
    return ret;
}
/* main */
int main(){
    ll N;
    cin >> N;
    vector<ll> div1 = div(N);
    vector<ll> div2 = div(N - 1);
    int ans = 0;
    for (ll d : div2) {if (N % d == 1) ans++; }
    for (ll d : div1) {
        ll tmp = N;
        while (tmp % d == 0) tmp /= d;
        if (tmp % d == 1) ans++;
    }
    cout << ans << '\n';
}


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


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

    cout<<(n-1)*(m-1)<<endl;

    return 0;
}


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

using namespace std;

int main() {
	int k;
	scanf("%d", &k);
	
	long long res = 0;
	
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int ii = 1; ii <= k; ii++) {
				int gcd = __gcd(i, j);
				gcd = __gcd(gcd, ii);
				res += gcd;
			}
		}
	}
	
	printf("%lld\n", res);
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n, k;
  cin >> n >> k;
  vector<ll> p(n), c(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i, n) cin >> c[i];

  ll ans = -INF;
  rep(i, n) {
    ll v = i;
    ll csum = 0, ccnt = 0;
    while (1) {
      csum += c[v];
      ccnt++;
      v = p[v];
      if (v == i) break;
    }
    ll tmp = 0, cnt = 0;
    while (1) {
      cnt++;
      tmp += c[v];
      if (cnt > k) break;
      ll num = (k - cnt) / ccnt;
      ll res = tmp + max(0LL, csum) * num;
      chmax(ans, res);
      v = p[v];
      if (v == i) break;
    }
  }
  cout << ans << '\n';

  
  return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  string s; cin >> s;
  int sum = 0;
  bool f = 0;
  rep(i, s.size()){
    if(f){
      if(s[i] == '0') sum ++;
      f = 0;
    }else{
      if(s[i] == '1') sum ++;
      f = 1;
    }
  }
  int ans = sum;
  sum = 0;
  f = 1;
  rep(i, s.size()){
    if(f){
      if(s[i] == '0') sum ++;
      f = 0;
    }else{
      if(s[i] == '1') sum ++;
      f = 1;
    }
  }
  ans = min(sum, ans);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
x = int(input())
 
a = [i**5 for i in range(1000)]
for i in range(1000):
    for j in range(1000):
        if a[i] - a[j] == x:
            print(i, j)
            exit()
        if a[i] + a[j] == x:
            print(i, -j)
            exit()

Measured memory_bytes: 9196
def main():
  while True:
    n = int(input())
    if not n:
      break
    ss = [s for s in reversed(input())]
    for i in range(n):
      new = []
      app = new.append
      last = ss.pop()
      count = 1
      while ss:
        a = ss.pop()
        if a == last:
          count += 1
        else:
          app(str(count))
          app(last)
          last = a
          count = 1
      app(str(count))
      app(last)
      new = "".join(new)
      ss = [s for s in reversed(new)]
    print(new)

main()


Measured memory_bytes: 7636
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = pow(10, 18);

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    bool ok = true;
    int N;
    cin >> N;
    vector<int> A(N);
    bool zero = false;
    for (int i = 0;i < N; i++) {
        cin >> A[i];
        if (A[i] == 0) zero = true;
    }

    if (zero) {
        cout << 0 << endl;
        return 0;
    }

    int ret= 1;
    for (int i = 0; i < N; i++) {
        double a = log10(A[i]);
        double b = log10(ret);
        double c = a + b;
        if (c > 18.1) {
            ok = false;
            break;
        }
        ret *= A[i];
    }

    int hoge = pow(10, 18);

    if (ok && ret <= hoge) cout << ret << endl;
    else cout << -1 << endl;

    return 0;
}

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

int main() {
	int N , M ;
    cin >> N >> M ;
    int a , b;
    vector<int> city(N);
    for(int i = 0 ; i < M ; i++){
    	cin >> a >> b ;
      	for(int j = 0; j < N; j++){
        	if((j + 1) == a){
            	city.at(j)++;
            }
            if((j + 1) == b){
            	city.at(j)++;
            }
        }
    }
    for(int k = 0; k < N; k++){
    	cout << city.at(k) << endl;
    }
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class BPapersPlease {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt();
            boolean res = true;
            for (int i = 0; i < n; i++) {
                int x = s.nextInt();
                if (x % 2 == 1)
                    continue;
                if (x % 3 != 0 && x % 5 != 0) {
                    res = false;
                }
            }
            if (res)
                w.println("APPROVED");
            else
                w.println("DENIED");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22740
# -*- coding: utf-8 -*-
import sys

def main():
	N, H = map(int, input().split(" "))
	
	atk_max = 0
	turn = 0
	throwing = []
	for _ in range(N):
		a, b = map(int, input().split(" "))
		if atk_max < a:
			atk_max = a
		throwing.append(b)
	
	throwing.sort()
	throwing.reverse()
	for i, val in enumerate(throwing):
		if atk_max < val:
			turn += 1
			H -= val
			if H <= 0:
				print(turn)
				sys.exit()
			
	tmp = H // atk_max
	turn += tmp
	if H % atk_max != 0:
		turn += 1
		
	print(turn)
		
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 7384
class SegmentTreeDual():
    def __init__(self, arr, op=lambda x, y: y if y != -1 else x, ie=-1):
        self.h = (len(arr) - 1).bit_length()
        self.n = 2**self.h
        self.ie = ie
        self.op = op
        self.val = [ie for _ in range(self.n)]
        self.laz = [ie for _ in range(2 * self.n)]
        for i in range(len(arr)):
            self.val[i] = arr[i]

    def propagate(self, k):
        if self.laz[k] == self.ie: return
        if self.n <= k:
            self.val[k - self.n] = self.op(self.val[k - self.n], self.laz[k])
        else:
            self.laz[2 * k] = self.op(self.laz[2 * k], self.laz[k])
            self.laz[2 * k + 1] = self.op(self.laz[2 * k + 1], self.laz[k])
        self.laz[k] = self.ie

    def update(self, lt, rt, x):
        lt += self.n
        rt += self.n
        while rt - lt > 0:
            if lt & 1:
                self.laz[lt] = self.op(self.laz[lt], x)
                lt += 1
            if rt & 1:
                rt -= 1
                self.laz[rt] = self.op(self.laz[rt], x)
            lt >>= 1
            rt >>= 1

    def get(self, idx):
        res = self.val[idx]
        idx += self.n
        while idx:
            res = self.op(res, self.laz[idx])
            idx >>= 1
        return res

import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())

x = [N - 1] * (N - 1) + [0]
y = [N - 1] * (N - 1) + [0]

stx = SegmentTreeDual(x, min, 10**18)
sty = SegmentTreeDual(y, min, 10**18)

res = (N - 2) * (N - 2)

for _ in range(Q):
    q, k = map(int, input().split())
    if q == 1:
        g = stx.get(k - 1)
        res -= g - 1
        sty.update(1, g, k - 1)
    if q == 2:
        g = sty.get(k - 1)
        res -= g - 1
        stx.update(1, g, k - 1)

print(res)

Measured memory_bytes: 167188
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

void RepStr(string& str, const string& from, const string& to){
   string::size_type pos = 0;
 
  while(pos = str.find(from, pos), pos != string::npos) {
     str.replace(pos, from.length( ), to);
     pos += to.length();
   }
}


int main(void){

string ws;
int n;
	cin >> n;
	cin.ignore();
	rep(i,n){
		getline(cin,ws);
		RepStr(ws,"Hoshino","Hoshina");
		cout << ws << endl;
	}
	return 0;
	
}

Measured memory_bytes: 1216
/*
Author- Aasav Badera
Time- Sun Sep 13 17:18:54 2020
*/
#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;
#ifdef LOCAL  
#include <sys/resource.h>
#define meminc             rlimit rlim;if (getrlimit(RLIMIT_STACK, &rlim)) return 1;rlim.rlim_cur = 268435456;if (setrlimit(RLIMIT_STACK, &rlim)) return 2;
#else
#define meminc      
#endif
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define int 				long long int
#define ll                 int
#define vi                 vector<int >
#define ordered_set        tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define rep(i, a, b)       for(int  i=a;i<b;i++)
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (int )x.size()
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define endl               '\n' 
// const int hell = (int)998244353;
const int hell = (int)1e9 + 7;
const double PI = 3.14159265;
const int N = (int) 1e6 + 5;
int n, m, k, a[N];
int dp[2001];
int solve(int sum)
{
	if(!sum)return 1;
	if(sum < 3)return 0;
	int &res = dp[sum];
	if(res != -1)return res;
	res = 0;
	rep(i, 3, sum + 1)
	{
		res += solve(sum - i);
		res %= hell;
	}
	return res;
}

int32_t main()
{
    meminc;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cerr.precision(10);
    cout.precision(25);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    int tests = 1;
    // cin >> tests;
    rep(test, 1, tests+1)
    {
        cin >> n;
        memset(dp, -1, sizeof dp);
        cout << solve(n);
    }
    #ifdef LOCAL
        // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}

Measured memory_bytes: 3668
def main():
    # input
    x = int(input())

    if x<100:
        print(0)
        return
    elif x<106:
        print(1)
        return

    dp = [False for _ in range(x+1)]
    for i in range(6):
        dp[100+i] = True

    # calc
    for i in range(106, x+1):
        for j in range(6):
            if dp[i-100-j]:
                dp[i] = True
                break

    if dp[i]:
        print(1)
    else:
        print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 44656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class AFiveVariables {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a[] = new int[5];
            int index = 0;
            for (int i = 0; i < 5; i++) {
                a[i] = in.nextInt();
                if (a[i] == 0)
                    index = i + 1;
            }
            out.println(index);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

int main(){
	string s;
	cin>>s;
	
	vector<int> a;
	int tmp=1;
	int flag=s[0]-'0';
	for(int i=1;i<s.size();i++){
		if(s[i]-'0'==flag){
			tmp++;
		}else{
			a.push_back(tmp);
			tmp=1;
			flag=abs(flag-1);
		}
	}
	a.push_back(tmp);
	
	if(a.size()==1){
		cout<<s.size()<<endl;
	}else if(a.size()==2){
		cout<<max(a[0],a[1])<<endl;
	}else{
		int ans=0;
		int l=a[0];
		int r=0;
		for(int i=0;i<a.size();i++)r+=a[i];
		for(int i=0;i<a.size()-1;i++){
			r-=a[i];
			l+=a[i+1];
			ans=max(ans,min(l,r));
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 768
A, B, C, X, Y = map(int, input().split())

ans = None
n1 = A*X + B*Y
if X > Y:
    n2 = C * 2*Y + A * (X - Y)
    n3 = C * 2*X
    ans = min(n1, n2, n3)
else:
    n2 = C * 2*X + B * (Y - X)
    n3 = C * 2*Y
    ans = min(n1, n2, n3)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int N, M, C[51];

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		C[a]++, C[b]++;
	}
	for(int i = 1; i <= N; i++)
		printf("%d\n", C[i]);
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
    int k, s;
    cin >> k >> s;

    //int x ,y ,z;
    int ans  = 0;
    for(int x = 0; x <= s; x++){
        for(int y = 0; y <= s - x; y++){
            int z = s - x - y;
            if(z <= k && x <= k && y <= k){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;

int main() {
    ll n;
    cin >> n;
    ll el = n;
    string s;
    while (el > 0) {
        char ch = char('a' + (el-1) % 26);
        s.push_back(ch);
        el = (el - 1) / 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

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

int main() {
    string S,ans="";
    cin >> S;
    rep(i,S.size()){
        if(S[i]=='?') ans +='D';
        else ans += S[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3824
using System;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int N = sc.NextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = sc.NextInt()-1;
        }

        int pos = 0;
        int cnt = 0;
        while (pos != 1)
        {
            if (cnt > 2 * N)
            {
                Console.WriteLine(-1);
                return;
            }
            cnt++;
            pos = A[pos];
            
        }
        Console.WriteLine(cnt);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 15328
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

int main()
{
	int N;
	while (scanf("%d", &N) && N){
		for (int x = 0; x < N; x++){
			int s, t;
			scanf("%d %d", &s, &t);
			if (s <= 0 && t >= 0){
				if (s < 0) s = -s;
				if (t < 0) t = -t;
				printf("%d\n", __builtin_popcount(s) + __builtin_popcount(t));
			}
			else if (s > 0 && t > 0){
				int ct = 0;
				while (s != t){
					for (int i = 30; i >= 0; i--){
						if (s % (1 << i) == 0 && s + (1 << i) <= t){
							ct++;
							s += (1 << i);
							break;
						}
					}
				}
				printf("%d\n", ct);
			}
			else {
				s = -s; t = -t;
				int ct = 0;
				while (s != t){
					for (int i = 30; i >= 0; i--){
						if (s % (1 << i) == 0 && s - (1 << i) >= t){
							ct++;
							s -= (1 << i);
							break;
						}
					}
				}
				printf("%d\n", ct);
			}
		}
		break;
	}
	
	return (0);
}

Measured memory_bytes: 1032
#include <stdio.h>
#define NOT_FREE 1
#define FREE -1
#define N 8

int B[N][N], row[N], col[N],dpos[2 * N - 1], dneg[2 * N - 1], row[N];//?????????????????????????¨?


void init(){
  int i;
  for(i = 0; i < N; i++) row[i] = col[i] = FREE;
  for(i = 0; i < 2 * N - 1; i++) dpos[i] = dneg[i] = FREE;
}

void printBoard(){
  int i, j;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(B[i][j]){
	if(row[i] != j){
	  //	   printf("%d %d %d\n", i, j, row[i]);
	  return;
	}
      }
    }
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(row[i] == j)	printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void putQueen(int i){
  int j; 

  if(i == N){ //
    printBoard();
    return;
  }
  for(j = 0; j < N; j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE) continue;
    // put a queen at (i, j)
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    // try the next row
    putQueen(i+1);
    // remove the queen at (i, j) for backtracking
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}
			  
int main()
{
  int k, r, c, i, j;

  init();

  for(i = 0; i < N; i++)
    for(j = 0; j < N; j++) B[i][j] = 0;
  
  scanf("%d", &k);
  for(i = 0; i < k; i++){
    scanf("%d %d", &r, &c);
    B[r][c] = 1;
  }
  putQueen(0);

  return 0;
}

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

int main() {
    ll a,b,h,m;
    cin >> a >> b >> h >> m;
    h = h * 60 + m;
    ll arg = (m / 60 - h / 60 / 12.0) * 2.0 * acos(-1);
    cout << setprecision(20) << sqrt(a * a + b * b - 2 * a * b * cos(arg)) << endl;
    return 0;
}

Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int X = 0;
  string S, T;
  cin >> S >> T;
  while (X < N){
    cout << S[X];
    cout << T[X];
    X++;
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <fstream>  
#include <algorithm>  
#include <cmath>  
#include <deque>  
#include <vector>  
#include <queue>  
#include <string>  
#include <cstring>  
#include <map>  
#include <stack>  
#include <set>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
using namespace std;
typedef long long LL;
typedef long double db;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
const	int N = 100005;
const	int P = 1e9 + 7;
const	int inf = 1e9;
const	LL Inf = 1e15;

LL C[1005][15], Coef[1005], res[1005], K;

int main(){
	cin >> K;
	REP(i, 0, 1000){
		C[i][0] = 1;
		for(int j = 1; j <= i && j <= 7; j ++){
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
		}
	}
	REP(i, 1, 600) Coef[i] = C[i + 6][7];
	
	int x = 1;
	while(x <= 600 && K >= Coef[x]){
		K -= Coef[x];
		x ++;
	}
	int t = 0;
	for(t = (--x); x; x --){
		res[x] = 1 + K / Coef[x];
		K %= Coef[x];
	}
	REP(i, 1, t){
		printf("FESTIVA");
		REP(j, 1, res[i]) printf("L");
	}

	puts("");
	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long k = sc.nextLong();
    long g = gcd(n, k);
    n = n / g;
    k = k / g;
    n = (n % k);
    System.out.println(Math.min(g * n, g * (k - n)));
  }

  public static long gcd(long x, long y) {
    if(y == 0) return x;
    return gcd(y, (x % y));
  }
}

Measured memory_bytes: 35852
#include <stdio.h>

int main()
{
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);

	int perWeek = A * 7 + B;
	int minWeek = C / perWeek;
	int remainPoint = C % perWeek;
	int minRemainDay = remainPoint / A;
	if (remainPoint % A)
		minRemainDay++;
	if (minRemainDay > 7)
		minRemainDay = 7;

	printf("%d\n", minWeek * 7 + minRemainDay);

	return 0;
}



Measured memory_bytes: 2120
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int a, b;
 
 
    for (a = 1; a < 10; a++) {
        for (b = 1; b < 10; b++) {
            printf("%dx%d=%d\n", a, b, a*b);
        }
    }
    return 0;
}


Measured memory_bytes: 2048
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> B(N);
    rep(i,N) B[i] = A[i]/N;
    ll left = -1, right = 1e18;
    while (right - left > 1) {
        ll mid = left + (right - left) / 2LL;
        ll cnt = 0;
        rep(i,N) {
            if (A[i] + mid < N) continue;
            cnt += (A[i]+mid+1LL)/(N+1LL);
        }
        if (cnt > mid) left = mid;
        else right = mid;
    }

    for (ll i = max(0LL, right - 100000LL); i <= right + 100000LL; i++) {
        ll cnt = 0;
        rep(j,N) {
            if (A[j] + i < N) continue;
            cnt += (A[j]+i+1LL)/(N+1LL);    
        }
        if (cnt == i) {
            cout << i << endl;
            return 0; 
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int N = 1e5 + 10;
VL e[N], w[N];
ll dist[N];

void dfs(int now, int past){
    REP(i,e[now].size()){
        int next = e[now][i];
        if (next == past) continue;
        dist[next] = dist[now] + w[now][i];
        dfs(next, now);
    }
}

int main() {
    int n;
    cin >> n;
    REP(i,n-1){
        int u = in() - 1, v = in() - 1, c = in();
        e[u].push_back(v);
        w[u].push_back(c);
        e[v].push_back(u);
        w[v].push_back(c);
    }

    dfs(0, -1);

    VI ans(n);
    REP(i,n){
        ans[i] = dist[i] % 2;
    }
    REP(i,n) printf("%d\n", ans[i]);

    return 0;
}


Measured memory_bytes: 15872
def submit():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]

    # dpで解く
    # dp[i][j] : マス(i, j)に至るまでに必要な最小flip回数
    dp = [
        [float('inf') for _ in range(w)] for _ in range(h)
    ]
    dp[0][0] = 0 if s[0][0] == "." else 1

    def update(dp, i, j, ni, nj):
        if s[ni][nj] == ".":
            dp[ni][nj] = min(dp[i][j], dp[ni][nj])
        elif s[i][j] == "#":
            dp[ni][nj] = min(dp[i][j], dp[ni][nj])
        else: # 次が黒であり、今が白である => flip必要回数が増える
            dp[ni][nj] = min(dp[i][j] + 1, dp[ni][nj])
    
    for i in range(h):
        for j in range(w):
            if i + 1 < h:
                update(dp, i, j, i + 1, j)
            if j + 1 < w:
                update(dp, i, j, i, j + 1)

    print(dp[h - 1][w - 1])


submit()

Measured memory_bytes: 9380
#include<bits/stdc++.h>
#include<thread>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define show(x, y); cout << x << " " << y << endl;
using namespace std;

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

    int n;
    cin >> n;
    vector<ll> a(n, 0);
    vector<vector<ll> > dp(n, vector<ll>(n,0));
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i > 0){
            dp[i-1][i] = a[i-1] + a[i];
        }
    }
    for(int len = 2; len < n; len++){
        for(int i = 0, j = i + len; j < n; i++, j++){
            dp[i][j] = 1e18L;
            ll sum = 0;
            for(int k = i; k < j; k++){
                sum += a[k];
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j]);
            }
            sum += a[j];
            dp[i][j] += sum;
        }
    }
    cout << dp[0][n-1];
    return 0;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << (A + B) % 24 << endl;

    return 0;
}


Measured memory_bytes: 256