akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
typedef vector<bool> Array;
typedef vector<Array> Matrix;

//正方行列の掛け算 O(N^3)
Matrix operator*(const Matrix &a,const Matrix &b){
	const int N = a.size();
  //assert(V == a[0].size() && V == b.size() && V == b[0].size()); //正方行列
	Matrix res(N, Array(N, false));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      for(int k = 0; k < N; k++){
        if(a[i][k] && b[k][j]){
          res[i][j] = true;
          break;
        }
      }
    }
  }
	return res;
}
//サイズNの単位行列
Matrix Mat_E(int N){
	Matrix res(N, Array(N, false));
  for(int i = 0; i < N; i++){
		res[i][i] = true;
	}
	return res;
}
//正方行列の累乗 O(M^3 * logn)
Matrix operator^(const Matrix &a, long long n){
  const int M = a.size();
	if(n == 0) return Mat_E(M);
	Matrix res = (a * a)^(n / 2);
	if(n & 1) res = res * a;
	return res;
}
typedef pair<int, int> P;

int main(){
  int N, M;
  long long Z;
  while(cin>>N>>M>>Z){
    if(N == 0) break;
    vector<int> from[50];
    REP(i, M){
      int s, d;
      scanf("%d %d", &s, &d);
      s--; d--;
      from[d].push_back(s);
      from[s].push_back(d);
    }
    vector<P> state;
    state.push_back(P(-1, 0));
    REP(i, N){
      REP(j, from[i].size()){
        state.push_back(P(from[i][j], i));
      }
    }
    Matrix M(state.size(), Array(state.size(), false));
    for(int i = 0; i < state.size(); i++){
      for(int j = 0; j < state.size(); j++){
        if(state[i].second == state[j].first && state[i].first != state[j].second){
          M[i][j] = true;
        }
      }
    }
    M = M ^ Z;
    bool ans = false;
    REP(i, state.size()){
      if(state[i].second == N - 1 && M[0][i]){
        ans = true;
        break;
      }
    }
    if(ans) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1516
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
dp=[[0 for j in range(k+1)] for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
    r=[0]*(k+2)
    for j in range(1,k+2):
        r[j]=(r[j-1]+dp[i-1][j-1])%mod
    for j in range(k+1):
        dp[i][j]=(r[j+1]-r[max(0,j-a[i-1])])%mod
print(dp[n][k]%mod)

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int cnt[10][10]{};
    for(int i = 1; i <= N; i++){
        int dw, up;
        int val = i;
        dw = val % 10;
        while(val > 0){
            up = val % 10;
            val /= 10;
        }
        cnt[up][dw]++;
    }
    int ans = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            ans += cnt[i][j]*cnt[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  string s;
  cin >> s;
  ll idx = 0;
  ll ans = 0;
  ll tmp = 0;
  while (true)
  {
    ll bc = 1;
    if (ans == 0)
    {
      idx = s.find("ABC");
    }
    else
    {
      idx = s.find("ABC", idx + bc * 2 + 1);
    }
    if (idx < 0)
    {
      break;
    }
    else
    {
      ll cnt = 0;
      for (ll i = idx; i >= 0; i--)
      {
        if (s[i] == 'A') {
          cnt++;
        }
        else{
          break;
        }
      }
      for (ll i = idx + 3; i < s.size(); i = i + 2)
      {
        if (s[i] == 'B' && s[i + 1] == 'C')
          bc++;
        else
          break;
      }
      ans += cnt * bc;
      s.insert(idx + bc * 2 + 1, string(cnt, 'A'));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 133000
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;
const int N_MAX = 128;
int T[4][N_MAX];

bool cmp()
{
	bool ret = true;
	/*
	for(int i = 0; i < 20; i++)
	{
		printf("%d ", T[2][i]);
	}
	puts("");
	for(int i = 0; i < 20; i++)
	{
		printf("%d ", T[3][i]);
	}
	puts("");
	*/
	for(int i = 0; i < N_MAX; i++)
	{
		if(T[2][i] != T[3][i])
		{
			ret = false;
			break;
		}
	}
	return ret;
}

void pls()
{
	for(int i = 0; i < N_MAX; i++)
	{
		T[3][i] += T[0][i] + T[1][i];
		while(T[3][i] >= 10)
		{
			T[3][i+1]++;
			T[3][i] -= 10;
		}
	}
	return void();
}

int main()
{
	string str;
	while(cin >> str)
	{
		for(char i = '0'; i <= '9'; i++)
		{
			memset(T, 0, sizeof(T));
			string s;
			s = str;
			int m;
			while(s.find('X') != string::npos)
			{
				m = s.find('X');
				s[m] = i;
			}
			int n = s.find('+'); m = s.find('=');

			

			string S[3];
			S[0] = s.substr(0, n);
			S[1] = s.substr(n+1, m-n-1);
			S[2] = s.substr(m+1, s.size()-1);

			bool ok = false;
			for(int j = 0; j < 3; j++)
			{
				if(S[j].size() > 1 && S[j][0] == '0')
				{
					ok = true;
				}
				else
				{
					reverse(S[j].begin(), S[j].end());
				}
			}
			if(ok)
			{
				continue;
			}
			
			//printf("%s %s %s\n",S[0].c_str() ,S[1].c_str() ,S[2].c_str());
			for(int j = 0; j < 3; j++)
			{
				for(int k = 0; k < S[j].size(); k++)
				{		
					T[j][k] = S[j][k] - '0';
				}
			}

			pls();

			if(cmp())
			{
				cout << i << endl;
				break;
			}
			else if(i == '9')
			{
				cout << "NA" << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>

int main(void) {
    int n, r;
    if(scanf("%d", &n) == 1) {
        if(n >= 1 && n <= 10) {
            r = n + n*n + n*n*n;
        }
    }

    printf("%d\n", r);

    return 0;
}


Measured memory_bytes: 1716
function main(input) {
  const lines = input.trim().split("\n");
  const [N, M, X] = splitN(lines.shift());

  const costs = [];
  const limit = 2 ** N;
  for (let i = 1; i < limit; i++) {
    const flags = i.toString(2).padStart(N, '0').split('').map(Number);
    const total = {cost: 0, a: []}
    flags.forEach((flg, i) => {
      if (flg) {
        const [c, ...a] = splitN(lines[i]);
        total.cost += c;
        total.a = a.map(
          (v, idx) => v + (total.a[idx] || 0)
        );
      }
    });
    if (total.a.every(v => v >= X)) {
      costs.push(total.cost);
    }
  }

  console.log(costs.length ? Math.min(...costs) : -1);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));



function splitN(s) {
  return s.split(' ').map(Number);
}

Measured memory_bytes: 38288
import sys


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
P = []
for _ in range(N):
    x, y, h = list(map(int, input().split()))
    P.append([x, y, h])
    if h != 0:
        tx, ty, th = x, y, h


for cx in range(101):
    for cy in range(101):
        H = th + abs(tx-cx)+abs(ty-cy)
        if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):
            print(cx, cy, H)
            exit(0)


Measured memory_bytes: 3064
def f_a():
    m, d = map(int, input().split())
    c = 0
    for i in range(1, m+1):
        for j in range(22, d+1):
            d1, d2 = j//10, j%10
            if (d2 >= 2) & (d1 * d2 == i):
                c += 1
    print(c)

if __name__ == "__main__":
    f_a()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int a[15];
int main()
{
	int n,ans1=1,ans2=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)if(a[i]&1)ans2*=1;else ans2*=2;
	for(int i=0;i<n;i++)ans1*=3;
	printf("%d\n",ans1-ans2);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] a = new int[30];
		for(int i = 0;i < 28;++i){
			a[sc.nextInt() - 1] = 1;
		}
		for(int j = 0;j < 30;++j){
			if(a[j] == 0) System.out.println(j+1);
		}
	}
}

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

int main() {
	ios_base::sync_with_stdio(false);
	int n; string s; cin >> n >> s;
	vector<int> pre(n, 0);
	for (int i = 0; i < n; ++i) {
		pre[i] = (s[i] == 'M');
		if (i) pre[i] += pre[i - 1];
	}
	auto get = [&](int l,int r) {
		return pre[r] - (l ? pre[l - 1] : 0);
	};
	int q; cin >> q;
	while (q--) {
		int k; cin >> k;
		long long d = 0;
		long long dm = 0;
		long long dmc = 0;
		for (int i = 0; i < n; ++i) {
			if (i - k >= 0 && s[i - k] == 'D') {
				dm -= get(i - k + 1, i - 1);
				d--;
			}
			if (s[i] == 'D') d++;
			else if (s[i] == 'M') dm += d;
			else if (s[i] == 'C') dmc += dm;
		}
		cout << dmc << '\n';
	}
}

Measured memory_bytes: 5276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans=-999999999999999;
  cin >> n;
  vector<vector<long>> f(n,vector<long>(10)),p(n,vector<long>(11));
  for(long i=0;i<n;i++) {
    for(long j=0;j<10;j++) {
      cin >> f[i][j];
    }
  }
  for(long i=0;i<n;i++) {
    for(long j=0;j<11;j++) {
      cin >> p[i][j];
    }
  }
  
  for(long bit=1;bit<(1<<10);bit++) {
    long bitans=0;
    for(long i=0;i<n;i++) {
      long eigyo=0;
      for(long j=0;j<10;j++) {
        if(f[i][j]==1&&(bit&(1<<j))) eigyo++;
      }
      bitans+=p[i][eigyo];
    }
    ans=max(ans,bitans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define MOD 1000000007
template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }
 
int main(){
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    vector<vector<long long>> dp(H+1, vector<long long>(W+1));
    REP(i, H)
        cin >> a[i];
 
    dp[1][1] = 1;
    for(int i=1; i<=H; i++)
        for(int j=1; j<=W; j++)
            if(a[i-1][j-1] == '.'){
                dp[i][j] += (dp[i-1][j] + dp[i][j-1]) % MOD;
                dp[i][j] %= MOD;
            }
    cout << dp[H][W] << endl;
    return 0;
}

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

using vector = std::vector<int>;
using iterator = vector::iterator;

auto print_vector = [](iterator begin, iterator end){
                      while (begin != end)
                        {
                          if (begin+1 < end) std::cout << *begin << " ";
                          else std::cout << *begin << std::endl;
                          ++begin;
                        }
                    };

int merge(iterator begin, iterator mid, iterator end)
{
  auto itr = begin;

  vector left, right;

  for (auto tmp=begin; tmp<mid; ++tmp) left.push_back(*tmp);
  for (auto tmp=mid; tmp<end; ++tmp) right.push_back(*tmp);
  left.push_back(1000000001);
  right.push_back(1000000001);

  // std::cout << "Merging...\n";
  // print_vector(left.begin(), left.end());
  // print_vector(right.begin(), right.end());

  auto itr_left = left.begin();
  auto itr_right = right.begin();

  int ncomp = 0;
  while (itr != end)
    {
      if (*itr_left <= *itr_right)
        {
          *itr = *itr_left;
          ++itr_left;
        }
      else
        {
          *itr = *itr_right;
          ++itr_right;
        }
      ++itr;
      ++ncomp;
    }
  // std::cout << "...finish\n";
  // print_vector(begin, end);

  return ncomp;
}

int mergeSort(iterator begin, iterator end)
{
  if ((begin+1) == end)
    {
      return 0;
    }

  auto n = std::distance(begin, end);
  auto mid = begin + n/2;

  int nct;
  nct = mergeSort(begin, mid);
  nct += mergeSort(mid, end);
  nct += merge(begin, mid, end);

  return nct;
}


int main ()
{
  int n;
  std::cin >> n;
  vector seq;

  for (int i=0; i<n; i++)
    {
      int tmp;
      std::cin >> tmp;
      seq.push_back(tmp);
    }

  auto ncomp = mergeSort(seq.begin(), seq.end());

  print_vector(seq.begin(), seq.end());
  std::cout << ncomp << std::endl;
}



Measured memory_bytes: 7780
x, n = map(int, input().split())
p = list(map(int, input().split())) 

u = [i for i in p if i >= x]
if len(u) == 0:
    u = [x]

l = [i for i in p if i <= x]
if len(l) == 0:
    l = [x]

if len(p)==0:
    print(x)
else:
    for i in range(x,max(u)+2):
        if i not in u:
            um = i
            break
        else:
            continue       
    for i in range(x,min(l)-2,-1):
        if i not in l:
            lm = i
            break
        else:
            continue   
    if abs(x-um) == abs(x-lm):
        print(lm)
    else:
        uu = abs(um - x)
        ll = abs(lm - x)
        if uu > ll:
            print(lm)
        else:
            print(um)

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    char c;
    cin >> c;
    if (c <= 'Z' && c >= 'A')
        cout << "A" << endl;
    else
        cout << "a" << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const ll mod=1e9+7;
const int maxn=2e5;
vector<int> g[maxn+5];
vector<int> tmp[2];
int ans[maxn+5];
int num[3];
int n;
void dfs(int k,int fa,int dep)
{
    tmp[dep&1].push_back(k);
    for(auto u:g[k])
        if(u!=fa)
            dfs(u,k,dep+1);
}
int main()
{

    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    num[0]=n/3;
    num[1]=n/3+(n%3>=1);
    num[2]=n/3+(n%3>=2);
    for(int i=1;i<n;++i)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,0,0);
    if(tmp[0].size()>tmp[1].size()) swap(tmp[0],tmp[1]);
    // cout<<tmp[0].size()<<" "<<tmp[1].size()<<endl;
    if(tmp[0].size()<=num[0])
    {
        for(auto x:tmp[0]) ans[x]=0;
        int i=0;
        for(;i<num[0]-int(tmp[0].size());++i) ans[tmp[1][i]]=0;
        for(;i<num[0]-int(tmp[0].size())+num[1];++i) ans[tmp[1][i]]=1;
        for(;i<tmp[1].size();++i) ans[tmp[1][i]]=2;
    }
    else
    {
        int i=0;
        for(;i<num[1];++i) ans[tmp[1][i]]=1;
        for(;i<tmp[1].size();++i) ans[tmp[1][i]]=0;
        i=0;
        for(;i<num[2];++i) ans[tmp[0][i]]=2;
        for(;i<tmp[0].size();++i) ans[tmp[0][i]]=0;
    }
    // for(int i=1;i<=n;++i) cout<<ans[i]<<" ";cout<<endl;
    num[0]=3;
    num[1]=1;
    num[2]=2;
    for(int i=1;i<=n;++i)
    {
        printf("%d ",num[ans[i]]);
        num[ans[i]]+=3;
    }
    return 0;
}

Measured memory_bytes: 21620
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct dice{
  int d1;
  int d2;
  int d3;
  int d4;
  int d5;
  int d6;
};
void W(struct dice *d){
  int tmp;
  tmp=d->d1;
  d->d1=d->d3;
  d->d3=d->d6;
  d->d6=d->d4;
  d->d4=tmp;
}
void N(struct dice *d){
  int tmp;
  tmp=d->d1;
  d->d1=d->d2;
  d->d2=d->d6;
  d->d6=d->d5;
  d->d5=tmp;
}
void S(struct dice *d){
  int tmp;
  tmp=d->d1;
  d->d1=d->d5;
  d->d5=d->d6;
  d->d6=d->d2;
  d->d2=tmp;
}
void E(struct dice *d){
  int tmp;
  tmp=d->d1;
  d->d1=d->d4;
  d->d4=d->d6;
  d->d6=d->d3;
  d->d3=tmp;
}
void Spin(struct dice *d){		/* サイコロの上面と下面を軸にして回転させる */
  int tmp;
  tmp=d->d2;
  d->d2=d->d3;
  d->d3=d->d5;
  d->d5=d->d4;
  d->d4=tmp;
}
struct dice *copyDice(struct dice *d){ /* サイコロのコピー */
  struct dice *copy;
  copy=malloc(sizeof(struct dice));
  copy->d1=d->d1;
  copy->d2=d->d2;
  copy->d3=d->d3;
  copy->d4=d->d4;
  copy->d5=d->d5;
  copy->d6=d->d6;
  return copy;
}
void initDice(struct dice *d, struct dice *d_backup){ /* サイコロを初期状態に戻す */
  d->d1=d_backup->d1;
  d->d2=d_backup->d2;
  d->d3=d_backup->d3;
  d->d4=d_backup->d4;
  d->d5=d_backup->d5;
  d->d6=d_backup->d6;
}
void roll_top(struct dice *d, int a){ /* サイコロの上面がaになるようにサイコロを転がす */
  int i;
  for(i=0; i<4; ++i){
	if(d->d1==a)
	  return;
	N(d);
  }
  for(i=0; i<3; ++i){
	if(d->d1==a)
	  return;
	E(d);
  }
}
void roll_front(struct dice *d, int b){ /* サイコロの前面がbになるようにサイコロをスピンさせる */
  int i;
  for(i=0; i<4; ++i){
	if(d->d2==b)
	  return;
	Spin(d);
  }
}
void printDice(struct dice *d){
  printf("\n-------\n");
  printf("d1: %d, d2: %d, d3: %d, d4: %d, d5: %d, d6: %d\n", d->d1, d->d2, d->d3, d->d4, d->d5, d->d6);

}
int main(){
  int i;
  char line[100];
  int num;
  int q;
  int a, b;
  struct dice *d;				/* サイコロ */
  struct dice *d_backup;
  d=malloc(sizeof(struct dice));
  //サイコロのめの入力
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d%d%d%d%d%d", &d->d1, &d->d2, &d->d3, &d->d4, &d->d5, &d->d6);
  //
  d_backup=copyDice(d);
   //q
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d", &q);
  //上面と前面から側面を求める
  for(i=0; i<q; ++i){
	/* 上面と前面の入力 */
	fgets(line, sizeof(line), stdin); 
	line[strlen(line)-1]='\0';
	sscanf(line, "%d%d", &a, &b);
	//サイコロの側面を求める
	roll_top(d, a);
	roll_front(d, b);
	printf("%d\n", d->d3);
	//	printDice(d);
	//サイコロを最初の状態に戻す
	initDice(d, d_backup);
  }
  
  free(d);
  free(d_backup);
  return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>
#include <cctype>
int main(void){
    char ch;
    
    while(1){
        scanf("%c",&ch);
        if(isalpha(ch)){
            if(islower(ch)){
                printf("%c",toupper(ch));
            }else if(isupper(ch)){
                printf("%c",tolower(ch));
            }
        }else{
            printf("%c",ch);
        }    
         if(ch == '\n')break;   
    }
    
}



Measured memory_bytes: 2692
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

void pwar() {
  std::cout << "War" << std::endl;
}
void pno() {
  std::cout << "No War" << std::endl;
}

int main() {
  int N, M, X, Y; std::cin >> N >> M >> X >> Y;
  int max_x = X,  min_y = Y;

  for (int i = 0; i < N; i++) {
    int x; std::cin >> x;
    max_x = std::max(max_x, x);
  }

  for (int i = 0; i < M; i++) {
    int y; std::cin >> y;
    min_y = std::min(min_y, y);
  }

  if (max_x < min_y) pno();
  else pwar();
}


Measured memory_bytes: 256
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/3 22:02:32
File Name     :main.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include<random>
#include<ctime>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 1e9
#define bug puts("--------------")
const ll N = 2e5 + 10;
const ll mod = 1e9 + 7;
const int Max_n = 1e6 + 10;
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 1;i <= n;++i){
        int a;
        cin >> a;
        if((a&1)) continue;
        if(a % 3 == 0|| a % 5 == 0) {}
        else return puts("DENIED"),0;
    }
    puts("APPROVED");
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
using namespace std;

static const int INFTY = (1LL<<31)-1;
static const int MAX_N = (1<<17); // 131072

long long K, N, Q, A[MAX_N];

int n;
long long D[2*MAX_N-1];
int F[2*MAX_N-1];

void init(int n_){
  n = 1;
  while( n < n_ ) n *= 2;
  for ( int i = 0; i < 2*n-1; i++ ) D[i] = 0;
  for ( int i = 0; i < 2*n-1; i++ ) F[i] = 0;
}

void update(int k, int a){
  k += n - 1;
  D[k] = a;
  F[k] = (a == 0);
  while( k > 0 ){
    k = (k - 1)/2;
    D[k] = D[k*2+1] + D[k*2+2]*(F[k*2+1]?(-1):1);
    F[k] = (F[k*2+1] + F[k*2+2])%2;
  }
}

// [a, b)
pair<long long,int> query(int a, int b, int k, int l, int r){
  if ( r <= a || b <= l ) return make_pair(0, 0);
  if ( a <= l && r <= b ) return make_pair(D[k], F[k]);
  else{
    //int vl = query(a, b, k*2 + 1, l, (l + r)/2);
    //    int vr = query(a, b, k*2 + 2, (l + r)/2, r);
    //    return min(vl, vr);
    pair<long long, int> vl = query(a, b, k*2 + 1, l, (l + r)/2);
    pair<long long, int> vr = query(a, b, k*2 + 2, (l + r)/2, r);
    pair<long long, int> res;
    res.first = vl.first + vr.first*(vl.second?(-1):1);
    res.second = (vl.second + vr.second)%2;
    return res;
  }
}

// [a, b]
pair<long long,int> findMin(int a, int b){
  return query(a, b+1, 0, 0, n);
}

void dump(){
  for ( int i = 0; i < n; i++ ) cout << D[i] << " ";
  cout << endl;
}

main(){
  int L, R;
  cin >> K >> N >> Q;
  init(N);
  for ( int i = 0; i < N; i++ ) cin >> A[i];
  for ( int i = 0; i < N; i++ ) update(i, A[i]);
  for ( int i = 0; i < Q; i++ ){
    cin >> L >> R; L--; R--;
    swap(A[L], A[R]);
    update(L, A[L]);
    update(R, A[R]);
    pair<long long, int> res = findMin(0, N-1);
    long long p = res.first;
    bool isng = (p < 0);

    if ( isng ) p *= -1;
    p %= K;
    if ( isng ) cout << (p+1)*(res.second?-1:1) << endl;
    else cout << ((K-p)%K+1)*(res.second?-1:1) << endl;
  }


}


Measured memory_bytes: 6940
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int X, A;
	cin >> X >> A;
	if (X < A)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << 10 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N; cin >> N;
  vector<int> P(N);
  map<int, int> mp;
  for(int i = 0; i < N; i++) {
    cin >> P[i];
    mp[P[i]] = i;
  }
  vector<int> vec;
  for(int i = 1; i <= N; i++) {
    vec.push_back(mp[i]);
  }
  int max_len, cnt = 0, grad = -1;
  for(int i = 0; i < N; i++) {
    if(grad < vec[i]) cnt++;
    else max_len = max(max_len, cnt), cnt = 1;
    grad = vec[i];
  }
  max_len = max(max_len, cnt);
  cout << N - max_len << endl;
  return 0;
}


Measured memory_bytes: 11516
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// 標準入力
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] nums = br.readLine().split(" ");
		int a = Integer.parseInt(nums[0]);
		int b = Integer.parseInt(nums[1]);

		System.out.println(a <= b ? a : a - 1);

	}

}


Measured memory_bytes: 20692
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree < int,  null_type,  less<int>,  rb_tree_tag,  tree_order_statistics_node_update > ordered_set;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
#define all(v) v.begin(), v.end()
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a/g)*b ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
char a;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>a;
    if(a>=97)
        cout<<'a';
    else
        cout<<'A';
    return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int x,y,z;
  while(true){
  cin>>x>>y>>z;
  if(!x&&!y&&!z)
    break;
  double l = sqrt(x*x+y*y+z*z-max(x,max(y,z))*max(x,max(y,z)));
  int n,r;
  for(cin>>n;n>0;n--){
    cin>>r;
    if(l<2*r)
      cout<<"OK"<<endl;
    else
      cout<<"NA"<<endl;
  }
  }
  return 0;
}

Measured memory_bytes: 0
inp = input()

max_len = 0
list_match = []

for i in inp:
  if i in ('A','T','G','C'):
    list_match.append(1)
  else:
    list_match.append(0)



for i in range(len(list_match)):
  cnt_char = 0
  if list_match[i] == 1:
    cnt_char += 1
    
    for _j in range(len(list_match)):
      if i + 1 == len(list_match):
        break
      elif list_match[i+1] == 1:
        cnt_char += 1
        i += 1
      else:
        break      
    
    if max_len < cnt_char:
      max_len = cnt_char
      
print(max_len)
      

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map <ll,bool>  mp;
int main() {
    ll k;
    cin>>k;
    ll digits=0;
    ll k1=k;
    while(k)    k/=10,digits++;
    ll now=0;
    for(ll i=1;i<=digits;i++){
        now*=10;
        now+=7;
    }
    if(now==k1){
        cout<<digits;
        return 0;
    }
    if(now<k1){
        now*=10;
        now+=7;
        digits++;
    }
    ll ans=-1;
    for(ll i=digits;;i++){
        if(mp[now]) break;
        mp[now]=1;
        if(!(now%k1)){
            ans=i;
            break;
        }
        now=now-(now/k1)*k1;
        now*=10;
        now+=7;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 66028
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll X, Y;
        cin >> X >> Y;
        ll cnt = 0;
        rep(i, 0, 1000000) {
                if (X * intpow(2, i) > Y) break;
                ++cnt;
        }
        cout << cnt << endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(sorted(map(int, input().split())))
x = 0
for k in range(n - 2):
    for j in range(k + 1):
        for i in range(j + 1):
            if l[i] < l[j + 1] < l[k + 2] and l[i] + l[j + 1] > l[k + 2]:
                x += 1
print(x)

Measured memory_bytes: 9172
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int h,w,le[60][60],at[60][60];
char a;
int main()
{
	cin>>h>>w;
	for(int i=1;i<=h;i++)
	  for(int j=1;j<=w;j++)
	  {
	  	cin>>a;
	  	if(a=='#')
	  	{
	  		at[i][j]=1;
	  		le[i][j+1]++;
	  		le[i][j-1]++;
	  		le[i-1][j]++;
	  		le[i-1][j-1]++;
	  		le[i+1][j]++;
	  		le[i+1][j+1]++;
	  		le[i+1][j-1]++;
	  		le[i-1][j+1]++;
		}
	  }
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
	  	if(at[i][j]==1)
	      cout<<'#';
	    else cout<<le[i][j];
		cout<<endl;
	} 
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

s = STDIN.gets.chomp
len = s.size

s1 = s[0, (len - 1) / 2]
s2 = s[(len + 3) / 2 - 1, len]

ans = (s == s.reverse and s1 == s1.reverse and s2 == s2.reverse) ? "Yes" : "No"

puts ans


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

long long arr[10000005];
int main(){

	int n ;
	cin >> n ;

	for(int i=1;i<=n;i++){
        for(int j=i; j<=n ; j+=i)
            arr[j]++;
	}

	long long ans=0,i;

	for(i = 1 ; i <= n; i++){
		long long z=i*arr[i];
		ans+=z;
	}

	cout << ans << endl ;

	return 0;
}


Measured memory_bytes: 81708
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
vector<string> s;
int n;
int main(void){
    cin >> n;
    s.resize(n);

    rep(i, n){
        cin >> s[i];
    }
    
    int ans = -1;

    rep(i, n){
        bool f = true;
        int ma = 0;
        vector<int> c(n, -1e9);
        c[i] = 1;
        queue<pair<int,int>> q;
        q.push({i, 1});
        while(!q.empty()){
            int now = q.front().first;
            int nowc = q.front().second;
            ma = max(ma, nowc);
            q.pop();
            int nextc = nowc + 1;
            rep(j, n){
                if(s[now][j] == '1'){
                    if(c[j] != -1e9){
                        if(c[j] != nowc - 1 && c[j] != nextc){
                            f = false;
                        }
                        continue;
                    } else {
                        c[j] = nextc;
                        q.push({j, nextc});
                    }
                }
            }

        }
        if(f){
            ans = max(ans, ma);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;

int main(void){
  string s;
  cin >> s;

  bool flag = true;
  rep(i,s.length()){
	if(i%2 == 0){
	  if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') continue;
	}
	if(i%2 == 1){
	  if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') continue;
	}
	flag = false;
	break;
  }

  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)



int main(){



    FAST
//	PRECISE


ll a;
cin>>a;
cout<<a+a*a+a*a*a;



return 0;
 }

Measured memory_bytes: 3652
def near(x, X):
    i = bisect_left(X, x)
    if i == 0: return [X[i]-x]
    elif i == len(X): return [X[i-1]-x]
    else: return [X[i]-x, X[i-1]-x]
from bisect import *
A, B, Q = map(int, input().split())
S, T = [], []
for _ in range(A):
    S.append(int(input()))
for _ in range(B):
    T.append(int(input()))
for _ in range(Q):
    res = 1<<40
    x = int(input())
    for a in near(x,S):
        for b in near(x,T):
            res = min(abs(a)+abs(a-b), abs(b)+abs(b-a), res)
    print(res)

Measured memory_bytes: 89704
n=int(input())
l=[int(i) for i in input().split()]
sm=l[0]
req=0 
pr=1 
if sm>0:
    pass 
else:
    req+=-sm+1 
    sm=1 
for i in range(1,n):
    if pr==1:
        n1=sm+l[i]
        if n1<0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req+=sm+1 
            sm=-1 
    else: 
        n1=sm+l[i]
        if n1>0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req+=(-sm+1) 
            sm=1 
    pr=1-pr  
req1=0 
pr=0
sm=l[0]
if sm<0:
    pass 
else:
    req1+=sm+1 
    sm=-1 
for i in range(1,n):
    if pr==1:
        n1=sm+l[i]
        if n1<0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req1+=sm+1 
            sm=-1 
    else: 
        n1=sm+l[i]
        if n1>0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req1+=(-sm+1) 
            sm=1 
    pr=1-pr  
print(min(req,req1))

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
 
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	for(int i = 0; i < s.size(); i++){
		cout << (char)((s[i] - 'A' + n) % 26 + 'A');
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define N ((ll)(2e6+100))
#define MAX ((ll)(1e18+100))
#define ARRS ((ll)(2e6+100))
#define MOD ((ll)(1e9+7))
#define pb push_back

ll n;
ll a[ARRS];

int main(){
	cin>>n;
	for(int i=0; i<n; i++)cin>>a[i];
	ll l=2,r=2;
	for(int i=n-1; i>=0; i--){
		ll t=(l+a[i]-1)/a[i];
		if(a[i]*t>r){
			cout<<-1;
			return 0;
		}
		l=a[i]*t;
		t=(r+a[i])/a[i];
		r=a[i]*t-1;
	}
	cout<<l<<" "<<r<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vll vector<long long>
#define vs vector<string>

int main() {
    ll N; cin >> N;
    vll d(N);
    rep(i,N) cin >> d[i];

    ll sum = 0;
    rep(i,N){
        xrep(j,i+1,N){
            sum += (d[i] * d[j]);
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3604
def main():

    # N = int(input())
    # S = input()
    # N, M = map(int, input().split())

    N = int(input())
    D = list(map(int, input().split()))
    M = int(input())
    T = list(map(int, input().split()))

    d1 = dict()
    for v in D:
        d1[v] = d1.get(v, 0) + 1
    d2 = dict()
    for v in T:
        d2[v] = d2.get(v, 0) + 1

    for v in d2:
        if v not in d1:
            return "NO"
        elif d2[v] > d1[v]:
            return "NO"
    return "YES"
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 56788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int d,t,s;
	cin >> d >> t >> s;
	int mult = t*s;
	cout << (mult >= d ? "Yes" : "No") << endl;
	return 0;
}

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


public class Main {
	static long MOD = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		Arrays.sort(s);
		StringBuilder sb = new StringBuilder();
		//append
		sb.append(s);

		int zeroind = sb.lastIndexOf("0") + 1;
		int oneind = sb.length()-zeroind;

		System.out.println(Math.min(zeroind,oneind)*2);

	}
}


Measured memory_bytes: 39928
#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<set>
using namespace std;
set<string> S;
string s[207];
void godo(int x)
{
    string now = s[x];
    string next = "";
    int z = 0;
    for(;;)
    {
        if(now[z]==':')break;
        next+=now[z];
        z++;
    }
    z++;
    if(x==1||S.count(next))
    {
        S.erase(next);
        next = "";
        for(z;z<now.size();z++)
        {
            if(now[z]==','||now[z]=='.')
            {
                S.insert(next);
                next = "";
            }
            else next +=now[z];
        }
    }
}
int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)break;
        S.clear();
        for(int i=1;i<=n;i++)cin>>s[i];
        godo(1);
        for(int i=2;i<=n;i++)
        {
            for(int j=2;j<=n;j++)
            {
                godo(j);
            }
        }
        cout<<S.size()<<endl;
    }
    return 0;
}

Measured memory_bytes: 3276
#include <stdio.h>

int main(void){
	int tarou[100], hanako[100], n, m, i, j, sum, T, H, tsum, hsum, check;

	while (1){
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0) break;

		tsum = 0; hsum = 0; check = 0; sum = 201;
		for (i = 0; i < n; i++){
			scanf("%d", &tarou[i]);
			tsum = tsum + tarou[i];
		}
		for (i = 0; i < m; i++){
			scanf("%d", &hanako[i]);
			hsum = hsum + hanako[i];
		}

		for (i = 0; i < n; i++){
			for (j = 0; j < m; j++){
				if ((tsum - tarou[i] + hanako[j]) == (hsum - hanako[j] + tarou[i])){
					if (sum > (tarou[i] + hanako[j])){
						T = tarou[i]; H = hanako[j];
						sum = tarou[i] + hanako[j];
						check = 1;
					}
				}
			}
		}
		if (check == 0) printf("-1\n");
		else printf("%d %d\n", T, H);
	}

	return 0;
}

Measured memory_bytes: 612
#include <iostream>

using namespace std;

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

    int n; int a; int b; cin >> n >> a >> b;
    bool terminar = false;
    int turno = 0;

    while(!terminar){
        if(turno % 2 == 0){
            if(a + 1 == b){
                if(a == 1)
                    terminar = true;
                else
                    --a;
            }
            else{
                ++a;
            }
        }
        else{
            if(b - 1 == a){
                if(b == n)
                    terminar = true;
                else
                    ++b;
            }
            else
                --b;
        }
        ++turno;
    }

    if(a > b){
        if(turno % 2 == 0)
            cout << "Borys\n";
        else
            cout << "Alice\n";
    }else{
        if(turno % 2 != 0)
            cout << "Borys\n";
        else
            cout << "Alice\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

void A();
void B();
int flagToInt(int flag, int num);
string flagToOp(int flag);

int main() {
	string s;
	int i;
	cin >> s;
	int a, b, c, d;
	a = s[0] - '0';
	b = s[1] - '0';
	c = s[2] - '0';
	d = s[3] - '0';

	for (i = 0; i < 8; ++i) {
		int num = a + flagToInt(i, b) + flagToInt(i >> 1, c) + flagToInt(i >> 2, d);
		if (num == 7) break;
	}
	cout << to_string(a) + flagToOp(i) + to_string(b) + flagToOp(i >> 1) + to_string(c) + flagToOp(i >> 2) + to_string(d) + "=7" << endl;
	return 0;
}

int flagToInt(int flag, int num) {
	int BIT_FLAG_1 = 0x0001;
	if (flag & BIT_FLAG_1) {
		return -num;
	}
	return num;
}

string flagToOp(int flag) {
	int BIT_FLAG_1 = 0x0001;
	if (flag & BIT_FLAG_1) {
		return "-";
	}
	return "+";
}

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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string n;
	cin >> n;
	
	ll sum = 0LL;
	for(int i = 0; i < (int)n.size(); ++i) {
		sum += (ll)(n[i] - '0');
	}
	
	if( sum % 9LL == 0 ) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3752
import collections
H, W = map(int, input().split())
l = [input() for _ in range(H)]
check = [([0] * (W)) for _ in range(H)]
white = 0
for i in range(H):
    white += l[i].count(".")
q = collections.deque()
check[0][0] = 1
q.append([0, 0])
g = False
while q:
    h, w = q.popleft()
    for i, j in ([0, 1], [0, -1], [1, 0], [-1, 0]):
        new_h = h + i
        new_w = w + j
        if new_w < 0 or new_h < 0 or new_w > W-1 or new_h > H-1 or l[new_h][new_w] == "#":
            continue
        elif check[new_h][new_w] == 0:
            check[new_h][new_w] = check[h][w] + 1
            q.append([new_h, new_w])
print(white - check[H-1][W-1] if check[H-1][W-1] != 0 else -1)

Measured memory_bytes: 3316
H, W, A, B = map(int,input().split())

if (A==0 and B==0):
    pr = ['0']*W
    pr =''.join(pr)
    for h in range(H):
        print(pr)
    exit()

pr = []
pr2 = []
for w in range(A):
    pr.append('0')
    pr2.append('1')
for w in range(W-A):
    pr.append('1')
    pr2.append('0')
pr = ''.join(pr)
pr2 = ''.join(pr2)

for h in range(B):
    print(pr)

for h in range(H-B):
    print(pr2)


Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll H, W;
const ll INF = 1 << 29;

ll Func(ll h, ll w){
    ll s = INF;
    for(ll i = 1; i < h; ++i){
        ll sa = i * w;
        ll j = w / 2;
        if(j != 0){
            ll sb1 = (h - i) * j;
            ll sc1 = (h - i) * (w - j);
            ll smax1 = max({sa, sb1, sc1});
            ll smin1 = min({sa, sb1, sc1});
            s = min(s, smax1 - smin1);
        }
        ll k = (h - i) / 2;
        if(k != 0){
            ll sb2 = k * w;
            ll sc2 = (h - i - k) * w;
            ll smax2 = max({sa, sb2, sc2});
            ll smin2 = min({sa, sb2, sc2});
            s = min(s, smax2 - smin2);
        }
    }
    return s;
}

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

    cin >> H >> W;
    cout << min(Func(H, W), Func(W, H)) << endl;
    

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	N := sc.i()
	A := sc.is(N)
	count := make([]int, N+1)
	for _, a := range A {
		count[a]++
	}
	//fac, ifac := range
	total := 0
	for _, c := range count {
		if c >= 2 {
			total += c * (c - 1) / 2
		}
	}
	for _, a := range A {
		c := count[a]
		if c >= 2 {
			t := total - (c - 1)
			fmt.Println(t)
		} else {
			fmt.Println(total)
		}
	}
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//------------------------------

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

// a^{-1} (mod) を計算
func Inv(a int) int {
	return Pow(a, mod-2)
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 7276