akhauriyash/Code-Regression huggingface dataset:
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
card = {
    0: {0: a11, 1: a12, 2: a13},
    1: {0: a21, 1: a22, 2: a23},
    2: {0: a31, 1: a32, 2: a33}
}
n = int(input())
marks = [[0,0,0], [0,0,0], [0,0,0]]
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if card[j][k] == b:
                marks[j][k] = 1
if sum(marks[0]) == 3:
    print("Yes")
elif sum(marks[1]) == 3:
    print("Yes")
elif sum(marks[2]) == 3:
    print("Yes")
elif sum([marks[0][0],marks[1][0],marks[2][0]]) == 3:
    print("Yes")
elif sum([marks[0][1],marks[1][1],marks[2][1]]) == 3:
    print("Yes")
elif sum([marks[0][2],marks[1][2],marks[2][2]]) == 3:
    print("Yes")
elif sum([marks[0][0],marks[1][1],marks[2][2]]) == 3:
    print("Yes")
elif sum([marks[2][0],marks[1][1],marks[0][2]]) == 3:
    print("Yes")
else:
    print("No")

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>
#include <stack>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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 gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}


int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  map<int, int> mp;
  REP(i, n) mp[i] = 0;
  ll ans = 0;
  REP(i, n){
    ans += mp[i-a[i]];
    mp[i+a[i]]++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 26524
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
typedef long long int ll;
using namespace std;
#define maxN 1000005
#define mod 1000000007

ll all[maxN]= {};

void solve() {
	
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	if(n<=m){
		printf("unsafe\n");
	}else{
		printf("safe\n");
	}
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    string a,b;
    cin >> a >> b;
    for(int i=0;i<n;i++)
        cout << a[i] << b[i];
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main{
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
        long MOD = 1000000007;
        //int t = sc.nextInt();
        int t = 1;
        Main sol = new Main();
        while(t -- > 0)
        {
            int n = sc.nextInt();
            int [] cnt = new int[n];
            for(int i = 2; i <= n; i++)
            {
                int boss = sc.nextInt();
                cnt[boss - 1]++;
            }
            for(int i : cnt)
                out.println(i);
            //for(int ii = 0; ii <= n; ii++) System.out.println(Arrays.toString(dp[ii]));
        }
        out.close();
    }
    public String solve(String N){

        char [] c= N.toCharArray();
        int n = c.length;
        char [] c1 = new char[n], c2 = new char[n];
        for(int i = 0; i < n; i++)
        {
            c1[i] = (char)(c[i] - 1);
            if(c[i] == '4') {
                c2[i] = '1';
            }
            else c1[i]++;
        }
        boolean met = false;
        for(int i = 0; i < n; i++)
        {
            if(met) {
                if (c2[i] < '0')
                    c2[i] = '0';
            }
            else if(c2[i] > '0')
                met = true;
        }
        return new String(c1) + new String(c2).trim();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

Measured memory_bytes: 54932
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace Test
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().solve();
        }

        public void solve()
        {
            int a = int.Parse(ReadLine()); 

            int ans = 0;
            for(var i=1; i<=a; i++){
                if(i%2==1 && yakusu(i)==8) {
                    ans++;
                }
            }
            WriteLine(ans);

        }

        static int yakusu(int n){
            int ans = 0;
            int i=1;
            while(i<=n){
                if(n%i++==0)ans++;
            }
            return ans;
        }

    }
}

Measured memory_bytes: 13140
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b){
    if(a % b == 0){
        return(b);
    }
    else{
        return(gcd(b, a % b));
    }
}

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

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

int N, M, i, j, k, l, tmp, ans, L, p, now_count;

int main(){
    cin >> N;

    if (N >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

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

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

#define NUM_MAX 100000
#define BUF_SIZE (NUM_MAX+50)

int main(void) {
    int num, changes;
    get_int2(&num, &changes);

    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    int i;
    for(i = 0; i < num; i++) str[i] = (str[i] == '1');
    str[num] = !(str[num-1]);

    // #1 #0 #1 #0...
    static int arr[NUM_MAX*4]; // 2*changes + 1 + aidx < NUM_MAX*4
    int aidx = 0;
    char prev = 1;
    int cnt = 0;
    for(i = 0; i <= num; i++) {
        if(str[i] == prev) { cnt++; continue; }
        arr[aidx++] = cnt;
        prev = str[i];
        cnt = 1;
    }
#ifdef DEBUG
    for(i = 0; i < aidx; i++) {
        printf(" %d", arr[i]);
    }
    putchar('\n');
#endif

    static int cum[NUM_MAX*4];
    for(i = 1; i < NUM_MAX*4; i++) {
        cum[i] = cum[i-1] + arr[i-1];
    }

    int ans = 0;
    int ranges = 2*changes+1;
    for(i = 0; i < aidx; i+=2) {
        ans = max(ans, cum[i+ranges] - cum[i]);
        if(i+ranges > aidx) break;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#define N 10000
using namespace std;

/*bool search(int key,int T[],int n){
  int cnt=0;
  for(int i=0;i<n;i++){
    if(key==T[i]) {
      cnt++; 
      break;
    }
    else continue;
  }
  if(cnt>0) return true;
  else return false;
}
*/

int main(){
  int n,q;
  int S[N],T[N];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> S[i];
  }
  cin >> q;

  int cnt=0;

  for(int i=0;i<q;i++){
    cin >> T[i];
    int key=T[i];
    for(int j=0;j<n;j++){
      if(key==S[j]){
	cnt++;
	break;
      }
      else continue;
    }
  }

  cout << cnt << endl;

  return 0;
}





Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  int n;
  cin >> n;
  int p[n];
  REP(i, n) cin >> p[i];
  int count = 0;
  REP(i, n - 2) {
    if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) {
      count++;
    } else if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) {
      count++;
    }
  }
  cout << count << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include <cstdlib>
#include<cctype>
#include <algorithm>    
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define VCOUT(num) for(auto& num:vec)
#define GET_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#define LLINF 1000000000000000000//10^18
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000
#define MAX 100
#define MX 10

//int main(int argc, char const* argv[]){

int main(){ 
    vector<int>vec;
     vector<char>cvec;
      vector<string>svec;
    
   int a,b,x,y,z,count=0;
   string answer;
   cin>>a;
   cin>>b;
   if(a>b) answer="a > b";
    else if(a<b) answer="a < b";
     else answer="a == b";
   
  
   
    
  
  cout<<answer<<endl;
    return 0;
}


Measured memory_bytes: 3132
# 点の個数と原点からの制限距離
in_data = input().split(" ")
p_num = int(in_data[0])
d_lim = int(in_data[1])

# 原点からの制限距離以下の点の個数をカウント
# 原点からの制限距離以下の点の個数をカウントする変数を初期化
n_count = 0
for i in range(p_num):
    in_data = input().split(" ")
    if (int(in_data[0]))**2+(int(in_data[1]))**2 <= d_lim**2:
        n_count += 1
print(n_count)

Measured memory_bytes: 9204
#include<cstdio>
#include<queue>

using namespace std;

static const int N = 100000;

int m,n;

queue<int> Q[N];
int color[N];

void visit(int a,int c){
    color[a] = c;
   while( !(Q[a].size() == 0) ){
        int u = Q[a].front();
        if(color[u] == 0) visit(u,c);
        Q[a].pop();
    }
}

int main(){
    scanf("%d",&n);
    scanf("%d",&m);

    for(int i=0; i<n; i++) color[i] = 0;

    for(int i=0; i<m;i++){
        int u,v;
        scanf("%d",&u);
        scanf("%d",&v);
        Q[u].push(v);
        Q[v].push(u);
    }
    
    int cc = 1;

    for(int i=0; i<n; i++){
        if(color[i] == 0){
            visit(i,cc);
            cc++;
        }
    }

    int l; 
    scanf("%d",&l);
    for(int i =0 ;i<l;i++){
        int x,y;
        scanf("%d",&x);
        scanf("%d",&y);

        if(color[x] == color[y]) printf("yes\n");
        else printf("no\n");

    }

}


Measured memory_bytes: 73212
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
b=list(map(int,input().split()))

anslst=[]
while b:
    for i in range(len(b))[::-1]:
        if b[i]==i+1:
            anslst.append(b[i])
            b.pop(i)
            break
    else:
        print(-1)
        quit()
# print(anslst)
for i in range(n):
    print(anslst[-1-i])

Measured memory_bytes: 70312
#include<stdio.h>

int main(){
int N;
int k=0;
  scanf("%d",&N);
  for(int i=1;i<=9;i++){
  	for(int j=1;j<=9;j++){
        if(N==i*j){
			k=1;
            break;
        }
    }
  }
  if(k==0)printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>

using namespace std;

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

	int32_t n, a, b;
	cin >> n >> a >> b;

	string s;
	cin >> s;

	int32_t num_passed{ a + b };
	for (auto i{ 0 }; i < s.size(); ++i) {
		if (s[i] == 'a' && num_passed > 0) {
			cout << "Yes\n" ;
			--num_passed;
		}else if (s[i] == 'b' && num_passed > 0 && b > 0) {
			cout << "Yes\n";
			--num_passed;
			--b;
		}else {
			cout << "No\n";
		}
	}
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n,k;
cin >> n >> k;
ll ans=0;

for (ll i = k; i <= n+1; i++) {
    ans += (2*n-i+1)*i/2-(i-1)*i/2;
    ans++;
    ans %= MOD;
}
cout << ans%MOD << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define m0(x) memset(x,0,sizeof(x))
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

map<ll, ll> primeFactors(ll n)
{
    map<ll, ll> ret;
    while (n % 2 == 0)
    {
        if( ret.find(2) != ret.end() ) {
            ret[2]++;
        }
        else
        {
            ret[2] = 1;
        }
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            if( ret.find(i) != ret.end() ) {
            ret[i]++;
        }
        else
        {
            ret[i] = 1;
        }
            n = n / i;
        }
    }
    if (n > 2)
        {
            if( ret.find(n) != ret.end() ) {
            ret[n]++;
        }
        else
        {
            ret[n] = 1;
        }
        }
    return ret;
}

void print_map(map<ll, ll> mp){
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        std::cout << "key = " << itr->first           // キーを表示
                        << ", val = " << itr->second << "\n";    // 値を表示
    }
}

// Returns nCr % p
ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    int count = 0;
    int i;
    for (i = C; i > 0; --i){
        C--;
        count++;
        if (B > 0) {
            B--;
            count++;
        } else if (A > 0) {
            A--;
        } else {
            break;
        }
    }
    count += B;
    cout << count << endl;
    return 0;
}


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

int rui1[2010][2010] = {};
int rui2[2010][2010] = {};
int rui3[2010][2010] = {};

int get(int a[][2010], int y1, int x1, int y2, int x2){
    return a[y2][x2] - a[y2][x1-1] - a[y1-1][x2] + a[y1-1][x1-1];
}

void rui(int a[][2010], int n, int m){

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

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

    return;
}

int main(){
    int n, m, q;
    char c[2010][2010];
    cin >> n >> m >> q;

    for(int i = 0;i < n;i++){
        cin >> c[i];
        for(int j = 0;j < m;j++){
            rui1[i+1][j+1] = c[i][j]-'0';
        }
    }


    for(int i = 0;i < n;i++)
        for(int j = 1;j < m;j++)
            rui2[i+1][j+1] = (c[i][j-1] == '1' && c[i][j] == '1');

    for(int i = 1;i < n;i++)
        for(int j = 0;j < m;j++)
            rui3[i+1][j+1] = (c[i-1][j] == '1' && c[i][j] == '1');

    rui(rui1, n, m);
    rui(rui2, n, m);
    rui(rui3, n, m);

    int x1, y1, x2, y2;
    for(int i = 0;i < q;i++){
        cin >> x1 >> y1 >> x2 >> y2;
        cout << get(rui1, x1, y1, x2, y2) - get(rui2, x1, y1+1, x2, y2) - get(rui3, x1+1, y1, x2, y2) << endl;
    }

    return 0;
}


Measured memory_bytes: 52992
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    int ans = 0;
    
    cin >> s;

    int left = 0, right = s.size()-1;

    while (left <= right) {
        if (s[left] != s[right]) {
            ans++;
        }
        left++;
        right--;
    }

    cout << ans << endl;
}


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

int main() {
    int a,b;
    while(cin>>a>>b, a|b) {
        set<int> fa,fb;
        for(int i=1; i*i<=a; ++i)
            if(a%i == 0) fa.insert(i), fa.insert(a/i);

        for(int i=1; i*i<=b; ++i)
            if(b%i == 0) fb.insert(i), fb.insert(b/i);

        int ans = 1<<29,t;
        int ar[4];

        typedef set<int>::iterator sit;
        for(sit i = fa.begin(); i != fa.end(); ++i)
            for(sit j = fa.begin(); j != fa.end(); ++j)
                for(sit k = fb.begin(); k != fb.end(); ++k)
                    for(sit l = fb.begin(); l != fb.end(); ++l) {
                        if((*i)*(*j) != a || (*k)*(*l) != b) continue;
                        ar[0] = *i,ar[1] = *j, ar[2] = *k,ar[3] = *l,t = 0;
                        sort(ar, ar+4);
                        for(int m=1; m<4; ++m)
                            t += (ar[m]-ar[m-1])*(ar[m]-ar[m-1]);
                        ans = min(ans, t);
                    }

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 912
n=int(input())
p=[int(i) for i in input().split()]
cp=[0]*n
cp[0]=p[0]
for i in range(1,n):
  cp[i]=min(cp[i-1],p[i])
c=0
for i in range(n):
  if cp[i]>=p[i]:
    c+=1
print(c)

Measured memory_bytes: 24744
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
signed main(){
	int n,sum=1000,b;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<n;i++)
		if(a[i+1]>a[i]){
			b=sum/a[i];
			sum%=a[i];
			b*=a[i+1];
			sum+=b;
		}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;;
const int maxn = 500 + 5;

int n , a[maxn] , k;
int res = 1;
int b[maxn];

bool check(int x){
	if(res >= x)return 0;
	int cnt = 0;
	for(int i = 1 ; i <= n ; ++i){
		b[i] = a[i] % x;
		cnt += x - b[i];
	}
	sort(b + 1 , b + n + 1);
	if(b[n] == 0)return 1;
	int used = 0;
	for(int i = 1 ; i <= n ; ++i){
		used += b[i];
		cnt -= x - b[i];
		if(used == cnt && used <= k)return 1;
	}
	return 0;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);	
	int sum = 0;
	cin >> n >> k;
	for(int i = 1 ; i <= n ; ++i){
		cin >> a[i];
		sum += a[i];
	}
	for(int i = 1 ; i * i <= sum ; ++i){
		if(sum % i == 0){
			if(check(sum / i))res = max(res , sum / i);
			if(check(i))res = max(res , i);
		}
	}
	cout << res;
}


Measured memory_bytes: 384
n,a,b=map(int,input().split())
s=input()
ans=list('No'for _ in range(n))
c=a+b
countY=0
countb=0
for i in range(n):
    if countY<c:
        if s[i]=='a':
            ans[i]='Yes'
            countY+=1
        if s[i]=='b' and countb<b:
            ans[i]='Yes'
            countY+=1
            countb+=1
            
print(*ans,sep='\n')

Measured memory_bytes: 6344
/*
      author  : nishi5451
      created : 15.08.2020 12:28:20
*/

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


int main(){
    int n;
    cin >> n;
    vector<int> a(n+1),b(n+1),c(n);
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=n; i++){
        cin >> b[i];
    }
    for(int i=1; i<=n-1; i++){
        cin >> c[i];
    }
    int ans = 0;
    int pre = -2;
    for(int i=1; i<=n; i++){
        ans += b[a[i]];
        if(pre+1==a[i]){
            ans += c[pre];
        }
        pre = a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
from collections import deque

H, W = map(int, input().split())
grid = '#' * (W + 2)
for _ in range(H):
    grid += '#' + input() + '#'
grid += '#' * (W + 2)

root = list(i for i in range(len(grid)) if grid[i] == '.')
start = root[0]
goal = root[-1]

move = [1, -1, W + 2, -(W + 2)]
se = set([start])
q = deque([start])

T = [-1] * len(grid)
T[start] = 0


def bfs():
    while q:
        x = q.popleft()
        for dx in move:
            y = x + dx
            if grid[y] == '#':
                continue
            if y in se:
                continue
            if y == goal:
                return T[x] + 1
            T[y] = T[x] + 1
            se.add(y)
            q.append(y)
    return T[goal]


ret = bfs()
print(len(root[1:]) - ret if ret != -1 else -1)


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

int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  int ans = min((N + A - 1) / A * B, (N + C - 1) / C * D);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3096
#include <vector>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
bool is_prime(int n, int k = 3)
{
    if(n < k * k) { return true; }
     
    if(n % k == 0) { return false; }
     
    return is_prime(n, k + 2);
}
 
int main()
{
    vector<int> prime = {2};
     
    for(int i = 3; i < 101300; i += 2)
    {
        if(is_prime(i))
        {
            prime.push_back(i);
        }
    }
     
    int n, m;
     
    while(true)
    {
        scanf("%d", &n);
        scanf("%d", &m);
         
        if(n == -1 && m == -1) { break; }
         
        int ptr = distance(prime.begin(), lower_bound(prime.begin(), prime.end(), n + 1));
         
        vector<int> c; m--;
        
        for(int i = ptr + m; i >= ptr; i--)
        {
            for(int j = ptr + m; j >= i; j--)
            {
                c.push_back(prime[i] + prime[j]);
            }
        }
        
        sort(c.begin(), c.end());
         
        printf("%d\n", c[m]);
    }
     
    return 0;
}

Measured memory_bytes: 3364
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include<iostream>
#include<math.h>

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	char c;

	cin >> c;
	int count = 0;
	char next;

	c == '0' ? next = '1' : next = '0';

	while (cin >> c) {
		if (next != c) {
			count++;
		}
		next == '1' ? next = '0' : next = '1';
	}
	cout << count << endl;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 2e3 + 5;
int n, ans, a[N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int x = a[i], y = a[j];
            int idx = lower_bound(a, a + n, a[i] + a[j]) - a;
            ans += max(idx - j - 1, 0);
        }
    }
    cout << ans;
    return 0;
}


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

int main() {
	char s[101], s2[101], p[101];
	cin >> s;
	cin >> p;

	strcpy(s2, s);
	strcat(s, s2);

	if (strstr(s, p) == NULL)
		cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 1160
import java.lang.reflect.Array;
import java.time.Year;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x=sc.nextInt();
        if (x%1000==0){
            System.out.println("0");
        }
        else if (x%1000!=0){
            System.out.println(1000-(x%1000));
        }
    }
}


Measured memory_bytes: 35680
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <cstring>
#include <functional>
#include <climits>
#include <list>
#include <ctime>
#include <complex>

#define F1(x,y,z) for(int x=(y);x<(z);x++)
#define F2(x,y,z) for(int x=(y);x<=(z);x++)
#define F3(x,y,z) for(int x=(y);x>(z);x--)
#define F4(x,y,z) for(int x=(y);x>=(z);x--)
#define mp make_pair
#define pb push_back
#define LL long long
#define co complex<double>
#define fi first
#define se second

#define MAX 100005
#define AMAX 53
#define MOD 1000000007

#define f(c,d) ((1<<(c))*(d))

using namespace std;

int n,m,ta,tb,ans,y[605][605],dp[305][305];
char x[305][305];

int f1(int a){
	if(a>=0&&a<n)return x[n-1-a][ta-1];
	return -1;
}

int f2(int a){
	if(a>=0&&a<n)return x[n-1-a][ta];
	return -2;
}

int main(){
	scanf("%d%d",&n,&m);
	F1(a,0,n)scanf("%s",x[a]);
	F1(aa,1,m){
		ta=aa;
		F2(b,-n,n){
			y[b+n][0]=0;
			F2(c,-n,n)y[b+n][c+n+1]=y[b+n][c+n]+(f1(c)==f2(-b+c));
			//if(b==-1)F2(c,-n,n+1)printf("[%d][%d]=%d  %d %d\n",b,c,y[b+n][c+n],f1(c),f2(-b+c));
		}
		dp[0][0]=0;
		F1(a,0,n)dp[a+1][0]=dp[a][0]+y[a-0+n][n+n+1]-y[a-0+n][a+n];
		F1(a,0,n)dp[0][a+1]=dp[0][a]+y[0-a+n][n+n+1]-y[0-a+n][0+n];
		F1(a,0,n)F1(b,0,n)dp[a+1][b+1]=min(dp[a][b+1]+y[a-b-1+n][n+n+1]-y[a-b-1+n][a+n],dp[a+1][b]+y[a+1-b+n][n+n+1]-y[a+1-b+n][a+1+n]);
		//if(aa==1)F2(a,n,n)F2(b,n,n)printf("dp[%d][%d]=%d %d %d\n",a,b,dp[a][b],y[a-b-1+n][n+n+1],y[a-b-1+n][a+n]);
		//printf("%d-%d: %d\n",aa-1,aa,dp[n][n]);
		ans+=dp[n][n];
	}
	printf("%d\n",ans);
	#ifdef LOCAL_PROJECT
	system("pause");
	#endif
	return 0;
}

Measured memory_bytes: 2048
N,W=map(int,input().split())
w=[]
v=[]

for i in range(N):
    x,y=map(int,input().split())
    w.append(x)
    v.append(y)

S=sum(v)

DP=[1000000000000]*(S+1)
DP[0]=0


for i in range(N):
    for v1 in range(S,v[i]-1,-1):
        DP[v1]=min(DP[v1-v[i]]+w[i],DP[v1])

for i in range(S,0,-1):
    if DP[i]<=W:
        print(i)
        exit()

Measured memory_bytes: 41068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m, a, b;
int dp[1000][1000];

int main(){
	while (cin >> n >> m&&n + m){
		REP(i, 1000)REP(j, 1000)dp[i][j] = INF;
		REP(i, m){
			cin >> a >> b;
			dp[a][b] = 1;
			dp[b][a] = 1;
		}
		FOR(k, 1, n + 1){
			FOR(i, 1, n + 1){
				FOR(j, 1, n + 1){
					dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
				}
			}
		}
		int ans = 0;
		FOR(i, 2, n + 1){
			if (dp[1][i] <= 2)ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, p;
    cin >> a >> p;
    p += a * 3;
    cout << p / 2 << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	string a,b;
	while(cin>>a>>b){
		int n=a.size(),m=b.size();
		vector<vector<int> >dp(n+1,vector<int>(m+1));
		loop(i,1,n+1)loop(j,1,m+1){
			if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;
		}
		int ma=0;
		rep(i,n)rep(j,m)ma=max(ma,dp[i+1][j+1]);
		cout<<ma<<endl;
	}
}

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

using namespace std;

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

    string ans = "";
    if (N == 0) ans = "0";
    
    while (abs(N) > 0) {
        if (N%2) {
            ans = '1' + ans;
            if (N < 0) N = (N - 1)/(-2);
            else N = N/(-2);
        } else {
            ans = '0' + ans;
            N = N/(-2);
        }
    }
    
    cout << ans << endl;
    return 0;
}

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


int main() {
    int n, k;
    cin >> n >> k;
    vector< int> v(n);
    for(int &e: v) cin >> e;
    sort(v.rbegin(), v.rend()); 
    cout << accumulate(v.begin(), v.begin() + k, 0) << endl;
}

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

string solve(vector<int>& v,int k){

  bool dp[k+1];
  memset(dp,0,sizeof dp);
  for(int i=1;i<=k;i++){
    for(int move :v){
        if(move>i){
          continue;
        }
        if(dp[i-move]==0){
          dp[i]=1;
        }
    }
  }
  return dp[k] ? "First":"Second";

}


int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<=n;i++){
      cin>>v[i];
    }
   cout<<solve(v,k);  
}

Measured memory_bytes: 3720
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        if len(str(i)) % 2 != 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 15740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


ll N, M;
struct mint {
    long long x;
    mint(long long _x=0):x((_x%M+M)%M){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= M) x -= M;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += M-a.x) >= M) x -= M;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= M;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint Mpow(long long t) const {
        if (!t) return 1;
        mint a = Mpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime M
    mint inv() const {
        return Mpow(M-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& a){
        os << a.x;
        return os;
    }
};

vec<mint> dp, ans;
vvec<int> G;

mint dfs1(int cur, int pre) {
    mint res = 1;
    for(auto& nv: G[cur]){
        if(nv == pre)continue;
        res *= (dfs1(nv, cur) + 1);
    }
    dp[cur] = res;
    return res;
}

//rerooting
void dfs2(int cur, int pre){
    ans[cur] = dp[cur];
    
    int sz = G[cur].size();
    //子のdpの値の左右の累積積
    deque<mint> l(sz+1,1), r(sz+1,1);
    rep(i,sz){
        l[i+1] = l[i] * (dp[G[cur][i]] + 1);
    }
    for(int i = sz-1; i >= 0; i--){
        r[i] = r[i+1] * (dp[G[cur][i]]+1); 
    }
    //print(l);print(r);
    rep(i, sz){
        // dp[cur] / dp[i]をしたいが、modの値が素数でないので逆元は使えない
        //ここで、左右からの累積積を持っておくとそこを除いた計算が素早くできる
        int nv = G[cur][i];
        if(nv == pre)continue;
        mint tmp_cur = dp[cur];
        mint tmp_nv = dp[nv];
        dp[cur] = l[i] * r[i+1];//親との縁切り　実質割り算
        dp[nv] *= (dp[cur] + 1);//繋ぎかえ　俺が親になってやるぜー
        dfs2(nv, cur);
        dp[cur] = tmp_cur;
        dp[nv] = tmp_nv;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    cin >> N >> M;
    G.resize(N);
    dp.assign(N, -1);
    ans.resize(N);
    rep(i,N-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs1(0, -1);
    dfs2(0, -1);
    //print(dp);print(ans);
    rep(i,N){
        cout << ans[i] <<endl;
    }
}

Measured memory_bytes: 114944
#include <bits/stdc++.h>
using namespace std;
#define INF 0X3f3f3f3f
#define M 1000000007
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back 
#define fi first
#define se second
#define endl "\n"
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

int a, b;

int main(void){
	cin >> a >> b;
	int x = a*b;

	if(x%2 == 0){
		cout << "Even" << endl;
	}
	else{
		cout << "Odd" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int H,W,i,j,k;
    
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0)
        break;
    
    for(i=0;i<H;i++){
        
        if(i==0||i==H-1){
            for(k=0;k<W;k++){
                printf("#");
            }
        }
        else{
            for(j=0;j<W;j++){
                if(j==0||j==W-1){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
        }
        printf("\n");
    }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2104
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    if a[i]==0:
        print(0)
        quit()
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        quit()
print(ans)

Measured memory_bytes: 83296
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 200001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

//double rat;
L A[Mx+5],B[Mx+5];


int main()
{
    scanf("%lld%lld",&m,&n);
    for(L i=0;i<n;i++){
        scanf("%lld",&d);
        A[d]=1;
    }
    c1=m;c2=m;
    while(true){
        if(c1<=0){
            printf("%lld\n",c1);
            return 0;
        }
        if(A[c1]==0){
            printf("%lld\n",c1 );
            return 0;
        }
        if(A[c2]==0){
            printf("%lld\n",c2 );
            return 0;
        }
        c1--;c2++;
    }
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3800
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    unsigned long long Mul = 1;
    bool bOverflow = false;
    bool bZero = false;
    for (int n = 0; n < N; ++n) {
        unsigned long long A;
        cin >> A;
        if (A == 0) {
            bZero = true;
            break;
        }
        unsigned long long Tmp = Mul * A;
        if (Tmp > INFLL || Tmp < Mul || Tmp < A) {
            bOverflow = true;
        }
        Mul = Tmp;
    }
    
    if (bZero) {
        cout << 0 << endl;
    } else if (bOverflow) {
        cout << -1 << endl;
    } else {
        cout << Mul << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  string s;
  cin >> s;
  if (s.size() < 8) {
    cout << s << endl;
    return 0;
  }
  rep(i, s.size() - 7) {
    unordered_map<char, int> v;
    loop(j, i, i + 8) v[s[j]]++;
    if (v['A'] == 2 && v['I'] == 1 && v['N'] == 2 && v['U'] == 1 && v['Y'] == 1 && v['D'] == 1) {
      s.replace(i, 8, "AIZUNYAN");
      i += 7;
    }
  }
  cout << s << endl;
}

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    ll n, r;
    cin >> n >> r;
    if (n < 10)
    {
        cout << r + 100 * (10 - n) << endl;
    }
    else
    {
        cout << r << endl;
    }
}

Measured memory_bytes: 256
import sys
# input = sys.stdin.readline


def parse(s):
    bottom = 0
    delta = 0
    for c in s:
        delta += (1 if c == "(" else -1)
        bottom = min(bottom, delta)
    return bottom, delta


def compute(pars):
    pars.sort(reverse=True)
    h = 0
    for bottom, delta in pars:
        if h + bottom < 0:
            print("No")
            sys.exit()
        h += delta
    return h


def main():
    N = int(input())

    incs = []
    decs = []
    for _ in range(N):
        bottom, delta = parse(input())
        if delta > 0:
            incs.append((bottom, delta))
        else:
            decs.append((bottom-delta, -delta))

    inc_tot = compute(incs)
    dec_tot = compute(decs)
    if inc_tot == dec_tot:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 80268