akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 400001;
const int INF = 0x7fffffff;
struct SegTree
{
    int id;
    int left, right;
    int minv;
    int sum;
};


SegTree stree[maxn];
int A[maxn];

void build(int v, int l, int r)
{
    stree[v].left = l;
    stree[v].right = r;
    if(l == r)
    {
        stree[v].sum = A[l];
        stree[v].minv = A[l];
    }
    else
    {
        int mid = (l + r) / 2;
        build(2 * v, l, mid);
        build(2 * v + 1, mid + 1, r);
        stree[v].sum = stree[v*2].sum + stree[v*2+1].sum;
        stree[v].minv = min(stree[v*2].minv, stree[v*2+1].minv);
    }
}

int findSum(int root, int l, int r)
{
    if(stree[root].left >= l && stree[root].right <= r)
    {
        return stree[root].sum;
    }
    else
    {
        int sumL = 0, sumR = 0;
        int mid = (stree[root].left + stree[root].right) / 2;
        if(l <= mid)
            sumL = findSum(root * 2, l, r);
        if(r > mid)
            sumR = findSum(root * 2 + 1, l, r);
        return sumL + sumR;
    }
}

void update(int id, int pos, int x)
{
    if(stree[id].left == stree[id].right)
    {
        A[stree[id].left] += x;
        stree[id].minv += x;
        stree[id].sum += x;
    }
    else
    {
        int mid = (stree[id].left + stree[id].right) / 2;
        if(pos <= mid) update(id * 2, pos, x);
        else update(id * 2 + 1, pos, x);
        stree[id].sum = stree[id*2].sum + stree[id*2+1].sum;
        stree[id].minv = min(stree[id*2].minv, stree[id*2+1].minv);
    }
}

int main()
{
    int n, q;
    cin >> n >> q;
    for(int i = 1; i <= n; i++)
        A[i] = 0;
    build(1, 1, n);

    for(int i = 0; i < q; i++)
    {
        int com, pos, v;
        cin >> com >> pos >> v;
        if(com == 0) update(1, pos, v);
        else if(com == 1) cout << findSum(1, pos, v) << endl;
    }

    return 0;

}



Measured memory_bytes: 8600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  ll K;
  cin >> K;

  if (K < 10) {
    cout << K << endl;
    return 0;
  }

  vi rr(0);
  vi last = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  while (rr.size() < K) {
    vi tmp(0);
    for (ll n : last) {
      rr.push_back(n);
      if (n % 10 == 0) {
        tmp.push_back(n * 10);
        tmp.push_back(n * 10 + 1);
      } else if (n % 10 == 9) {
        tmp.push_back(n * 10 + 8);
        tmp.push_back(n * 10 + 9);
      } else {
        tmp.push_back(n * 10 + n % 10 - 1);
        tmp.push_back(n * 10 + n % 10);
        tmp.push_back(n * 10 + n % 10 + 1);
      }
    }
    last = tmp;
  }

  ll ans = rr[K - 1];
  cout << ans << endl;
}


Measured memory_bytes: 12052
n = int(input())

arr = list(map(int, input().split()))

cond = True

for i in arr:
  if i % 2 == 0:
    if i % 3 == 0 or i % 5 == 0: continue
    else:
      cond = False
      break
      
if cond: print("APPROVED")
else: print("DENIED")

Measured memory_bytes: 9044
#include <stdio.h>

int main(){
while(1){

 int a, b, i;
 char op;

 scanf("%d %c %d", &a, &op, &b);

 switch( op ){

 case '+' : 
 printf("%d\n", a + b);
 break;
 case '-' : 
 printf("%d\n", a - b);
 break;
 case '*' : 
 printf("%d\n", a * b);
 break;
 case '/' : 
 printf("%d\n", a / b);
 break;
 case '?' : 
 return 0;
 break;

 }
}
 return 0;
}

Measured memory_bytes: 1776
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;


int main() {
	string str;
	int n;
	cin>>n;
	cin>>str;
	if(n&1){
		cout<<"No";
	}else{
		int len=n>>1;
		for(int i=0;i<len;i++){
			if(str[i]!=str[len+i]){
				cout<<"No";
				exit(0);
			}
		}
		cout<<"Yes";
	}
	
	return 0;
}




Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [usize; n]
    }
    let mut p = 2;
    while v[0] % p == 0 {
        p *= 2;
    }
    p /= 2;
    for &x in &v {
        if x % p != 0 || x % (p * 2) == 0 {
            println!("0");
            return;
        }
    }
    let mut l = 1;
    for &x in &v {
        l = lcm(l, x / 2);
    }
    println!("{}", (m / l + 1) / 2);
}

fn gcd(n: usize, m: usize) -> usize {
    let mut l = min(n, m);
    let mut r = max(n, m);
    while l > 0 {
        let t = l;
        l = r % l;
        r = t;
    }
    r
}

fn lcm(n: usize, m: usize) -> usize {
    n / gcd(n, m) * m
}


Measured memory_bytes: 4476
import collections

h, w = map(int, input().split())

m = []
for _ in range(h):
    m.append(list(input()))


ans = 0
for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            continue

        checked = [[False]*w for _ in range(h)]
        q = collections.deque()
        q.append((i, j, 0))
        checked[i][j] = True
        while True:
            x, y, s = q.popleft()
            #print(q)

            if x > 0 and m[x-1][y] != '#' and checked[x-1][y] == False:
                q.append((x-1, y, s+1))
                checked[x-1][y] = True

            if x+1 < h and m[x+1][y] != '#' and checked[x+1][y] == False:
                q.append((x+1, y, s+1))
                checked[x+1][y] = True

            if y > 0 and m[x][y-1] != '#' and checked[x][y-1] == False:
                q.append((x, y-1, s+1))
                checked[x][y-1] = True

            if y+1 < w and m[x][y+1] != '#' and checked[x][y+1] == False:
                q.append((x, y+1, s+1))
                checked[x][y+1] = True

            ans = max(ans, s)

            if len(q) == 0:
                break

print(ans)


Measured memory_bytes: 3316
#include <climits>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, X, Y;
  cin >> N >> X >> Y;

  vector<vector<int>> G(N, vector<int>(N, INT_MAX));
  for (int i = 0; i < N - 1; ++i) {
    G[i][i] = 0;
    G[i][i + 1] = 1;
    G[i + 1][i] = 1;
  }
  G[N - 1][N - 1] = 0;
  X--;
  Y--;
  G[X][Y] = 1;
  G[Y][X] = 1;

  // WF
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      int shortX = abs(X - i) + 1 + abs(j - Y);
      int shortY = abs(X - j) + 1 + abs(i - Y);
      G[i][j] = min(abs(j - i), min(shortX, shortY));
    }
  }

  vector<int> answer(N, 0);
  for (int i = 0; i < N; ++i) {
    for (int j = i; j < N; ++j) {
      answer[G[i][j]]++;
    }
  }
  for (int i = 1; i < N; ++i) cout << answer[i] << endl;
  return 0;
}


Measured memory_bytes: 16000
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

public class Main {
    static int MOD = 1000000007;

    public static class Mas {
        int x;
        int y;
        int step;

        Mas(int x, int y, int step) {
            this.x = x;
            this.y = y;
            this.step = step;
        }
    }

    private static final int[] vX = { 1, 0, 0, -1 };
    private static final int[] vY = { 0, 1, -1, 0 };

    public static void main(String[] args) {

        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        Map<String, Integer> map = new HashMap<>();

        for (int i = 0; i < n; i++) {
            map.put(fs.next(), 1);
        }
        System.out.println(map.size());

    }

}


Measured memory_bytes: 62992
// 2011/08/09 Tazoe

#include <iostream>
using namespace std;

void radix(int n)
{
	if(n==0)
		return;

	radix(n/8);

	switch(n%8){
		case 0:
			cout << 0;
			break;
		case 1:
			cout << 1;
			break;
		case 2:
			cout << 2;
			break;
		case 3:
			cout << 3;
			break;
		case 4:
			cout << 5;
			break;
		case 5:
			cout << 7;
			break;
		case 6:
			cout << 8;
			break;
		case 7:
			cout << 9;
			break;
	}
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		radix(n);
		cout << endl;
	}

	return 0;
}

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

namespace test
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string input;
			int a = 0;
			int b = 0;
			int ab = 0;
			int o = 0;
			while ((input = Console.ReadLine()) != null) {
				string[] array = input.Split (',');
				switch (array [1]) {
				case "A":
					a++;
					break;
				case "B":
					b++;
					break;
				case "AB":
					ab++;
					break;
				case "O":
					o++;
					break;
				}
			}

			Console.WriteLine (a);
			Console.WriteLine (b);
			Console.WriteLine (ab);
			Console.WriteLine (o);


		}


	}
	
}

Measured memory_bytes: 5620
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N, T;
int t[200010];
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>T;
    REP(i, N) cin >> t[i];

    lng ans = 0;
    UP(i, 1, N-1) {
        ans += min(T, t[i]-t[i-1]);
    }
    ans += T;
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> Pii;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w,d;
	cin>>h>>w>>d;
	pair<int,int> a[h*w+1];
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			int t;
			cin>>t;
			a[t]=make_pair(i,j);
		}
	}
	int q;
	cin>>q;
	ll t[h*w+1]={};
	for(int i=d+1;i<=h*w;i++){
		t[i]=t[i-d]+abs(a[i].first-a[i-d].first)+abs(a[i].second-a[i-d].second);
	}
	for(int i=0;i<q;i++){
		int l,r;
		cin>>l>>r;
		cout<<t[r]-t[l]<<endl;
	}
	return 0;
}
		


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

int main(){
  
  int N;
  cin >> N;
 vector<int> V(30) , C(30) , S(30);
  rep (i,N) cin >> V.at(i);
    rep (i,N) cin >> C.at(i);
int answer = 0;
    rep (i,N) S.at(i) = V.at(i) - C.at(i);
    rep (i,N) {
     if (S.at(i) > 0)  answer += S.at(i);
    }
 cout << answer << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#define MOD 1000000007
#define pi acos(-1)
#define iil pair<int,int>
#define vii vector<ii>
#define ll  long long int
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
#define REP(i,a,b) for(ll i=a;i<=b;i++)
#define loop(i,n) for(ll i=0;i<n;i++)
#define ll  long long int
#define LL long long int
#define loop2(i,n) for(ll i=1;i<=n;i++)
#define MIN(a,b) (a) < (b) ? (a) : (b)
#define MAX(a,b) (a) > (b) ? (a) : (b)
#define ABS(a) (a) > 0 ? (a) : -(a)
#define rep1(i,a,n) for(i=a;i<(n);i++)
#define pii pair< ll, ll >
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
#define rept(i,n) FOR(i,0,(n)-1)
#define edge pair<int ,int >
#define CLEAR(a) memset((a),0,sizeof(a))
ll add(ll a, ll b) { return a+b-(a+b>=MOD)*MOD; }
ll sub(ll a, ll b) { return a-b+(a-b<0)*MOD; }
ll mult(ll a, ll b) { return (1LL*a*b)%MOD; }
#define all(x)                  (x).begin(),(x).end()
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
ll exponentmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
#define dis(x,y,a,b) sqrt((x-a)*(x-a)+(y-b)*(y-b));
#define maxn 100005
#define rep(i,a,n) for (int i=a;i<n;i++)
#define digits(n)  (floor(log10(n))+1)
#define ll long long int
#define OUT_RT cerr << (float(clock()) / CLOCKS_PER_SEC) << endl
#define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
#define gc getchar_unlocked
#define reset(dp) memset(dp,-1,sizeof(dp))
#define midoftwo(x , y) (x+y)/2
using namespace std;
//US :- 67 S :- 34
//find the holy grail in an  adventure frought with danger
//The bigger the occasion, the better the response.
// Never giving in, fighting to the end



int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll array[2*n];
    loop(i, 2*n){
        cin>>array[i];
    }
    ll ans  = 0 ;
    sort(array,array+2*n);
    for(ll j =  0;j<=2*n-2;j+=2){
        ans+=min(array[j],array[j+1]);
    }
    cout<<ans;
    //OUT_RT;
    return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = double.Parse(ReadLine());
            double b = double.Parse(ReadLine());

            double ans = 2 * b - a;

            WriteLine(ans);
        }
    }
}



Measured memory_bytes: 11092
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int):
    LEN = len(str(N))
    if LEN <= 2:
        print(0)
        return

    answer = 0
    for i in range(3,LEN+1):
        for num in list(itertools.product(['3','5','7'], repeat=i)):

            if num.count('3') >= 1 and num.count('5')>=1 and num.count('7') >=1 and int(''.join(num))<=N:
                answer +=1

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6260
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define INF 100000000
#define mod 1000000007
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //nの下からk桁目
ll gcd(ll n,ll m){
	if(n<m){ll a=m;m=n;n=a;}
	ll r=n%m;
	while(r!=0){
		n=m;
		m=r;
		r=n%m;
	}
	return m;
}
ll lcm(ll n,ll m){
	return n*m/gcd(n,m);
}

int main(){

	int x,a,b;
	cin>>x>>a>>b;
	int xa=max(x-a,a-x);
	int xb=max(x-b,b-x);
	if(xa>xb)cout<<"B"<<endl;
	else cout<<"A"<<endl;

}



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

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

    int n;cin>>n;

    vector<int> a;

    for(int i=0;i<n;i++)
    {
        int ia;cin>>ia;

        auto it = remove(a.begin(),a.end(),ia);
        if(it==a.end())a.push_back(ia);
        else a.erase(it,a.end());
    }

    int ans=a.size();

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3792
a, b = map(int, input().split())

if a == b:
  print(a)
  exit()
elif b - a == 1:
  print(a ^ b)
  exit()

first_even = a if a % 2 == 0 else a + 1
last_odd = b if b % 2 == 1 else b - 1

num_pairs = (last_odd - first_even + 1) // 2
ones = num_pairs % 2
res = (a if a % 2 else 0) ^ ones ^ (b if b % 2 == 0 else 0)
print(res)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 998244353
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;


int main(){

    string s;
    cin >> s;

    int ans;

    if(s == "SUN"){
        ans = 7;
    }else if(s == "MON"){
        ans = 6;
    }else if(s == "TUE"){
        ans = 5;
    }else if(s == "WED"){
        ans = 4;
    }else if(s == "THU"){
        ans = 3;
    }else if(s == "FRI"){
        ans = 2;
    }else if(s == "SAT"){
        ans = 1;
    }

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

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
c = 0
for i in range(n-2):
    if (p[i+1] < p[i]) and (p[i+1] > p[i+2]):
        c += 1
    elif (p[i+1] > p[i]) and (p[i+1] < p[i+2]):
        c += 1

print(c)

Measured memory_bytes: 3060
let readCharArray () = stdin.ReadLine().ToCharArray()
let choice ok ng bool = if bool then ok else ng

readCharArray ()
|> fun x ->
    x.[0] = 'A'
    && x.[2..(x.Length - 2)]
       |> Array.filter ((=) 'C')
       |> Array.length
       |> ((=) 1)
    && x
       |> Array.filter System.Char.IsUpper
       |> Array.length
       |> ((=) 2)
|> choice "AC" "WA"
|> printfn "%s"


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

int cnt[3][31];
int d[31][31];
int n,c;

int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int res = 1e9;

	memset(cnt,0,sizeof(cnt));
	memset(d,0,sizeof(d));

	cin >> n >> c;

	for(int i=1;i<=c;i++)
	{
		for(int j=1;j<=c;j++)
		{
			cin >> d[i][j];
		}
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int x = (i+j)%3;
			int y;

			cin >> y;

			cnt[x][y]++;
		}
	}

	for(int i=1;i<=c;i++)
	{
		for(int j=1;j<=c;j++)
		{
			if(i==j)
			{
				continue;
			}
			for(int k=1;k<=c;k++)
			{
				if(i==k || j==k)
				{
					continue;
				}

				int wrongness = 0;
				for(int l=1;l<=c;l++)
				{
					wrongness += (cnt[0][l]*d[l][i]);
					wrongness += (cnt[1][l]*d[l][j]);
					wrongness += (cnt[2][l]*d[l][k]);
				}

				res = min(res,wrongness);
			}
		}
	}

	cout << res << '\n';

	return 0;	
}

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

int dp[2][2][1000100];

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

  dp[0][0][0] = 1;
  for( int i = 1; i <= N; i++ ){
    for( int z = 0; z < 2; z++ ){
      for( int n = 0; n < 2; n++ ){
        for( int num = 0; num < 10; num++ ){
          int zfg = z;
          int nfg = n;
          if( num == 0 ) zfg = 1;
          if( num == 9 ) nfg = 1;
          dp[zfg][nfg][i] += dp[z][n][i-1];
          dp[zfg][nfg][i] %= MOD;
        }
      }
    }
  }
  cout << dp[1][1][N] << endl;

}


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

ll divisor=1e9+7;
int main(){
	string s;
	cin>>s;
	int a[4];
	int sum=0;
	rep(i,4){
		a[i]=stoi(s.substr(i,1));
		sum+=a[i];
	}
	int diff=sum-7;
	if(diff==0){
		cout<<a[0]<<"+"<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"=7"<<endl;
	}else if(diff==2*a[1]){
		cout<<a[0]<<"-"<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"=7"<<endl;
	}else if(diff==2*a[2]){
		cout<<a[0]<<"+"<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"=7"<<endl;
	}else if(diff==2*a[3]){
		cout<<a[0]<<"+"<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"=7"<<endl;
	}else if(diff==2*(a[1]+a[2])){
		cout<<a[0]<<"-"<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"=7"<<endl;
	}else if(diff==2*(a[1]+a[3])){
		cout<<a[0]<<"-"<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"=7"<<endl;
	}else if(diff==2*(a[2]+a[3])){
		cout<<a[0]<<"+"<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"=7"<<endl;
	}else{
		cout<<a[0]<<"-"<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"=7"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ( abs(a - c) <= d || abs(a-b) <= d && abs(b-c) <= d ) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k;
	int ans=1;
	cin >>n>>k;
	V a(n);
	rep(i,n){
		cin>>a[i];
	}
	for(int i=k;i<n;i++){
		cout << solve(a[i - k] < a[i]) << endl;
		if(a[i-k] >=a[i+1]){
			ans=0;
		}
	}
	//cout<<solve(ans==1)<<endl;
}

Measured memory_bytes: 4836
// AOJ 0552: Exposition
// 2018.1.28 bal4u

#include <stdio.h>
#include <string.h>

int x[100002], y[100002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, xx, yy, xmin, xmax, ymin, ymax, d1, d2, ans1, ans2;

	n = in();
	xx = in(), yy = in();
	x[0] = xx + yy, y[0] = xx - yy;
	xmin = xmax = x[0], ymin = ymax = y[0];
	for (i = 1; i < n; i++) {
		xx = in(), yy = in();
		x[i] = xx + yy, y[i] = xx - yy;
		if      (x[i] < xmin) xmin = x[i];
		else if (x[i] > xmax) xmax = x[i];
		if      (y[i] < ymin) ymin = y[i];
		else if (y[i] > ymax) ymax = y[i];
	}

	ans1 = ans2 = 0;
	for (i = 0; i < n; i++) {
		d1 = x[i]-xmin, yy = y[i]-ymin;	if (yy > d1) d1 = yy;
		d2 = xmax-x[i], yy = ymax-y[i]; if (yy > d2) d2 = yy;
		if (d1 > d2) d1 = d2;
		if (d1 > ans1) ans1 = d1;

		d1 = x[i]-xmin, yy = ymax-y[i];	if (yy > d1) d1 = yy;
		d2 = xmax-x[i], yy = y[i]-ymin; if (yy > d2) d2 = yy;
		if (d1 > d2) d1 = d2;
		if (d1 > ans2) ans2 = d1;
    }
	if (ans1 > ans2) ans1 = ans2;
    printf("%d\n", ans1);
    return 0;
}


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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

const ll mod = 1000000007;

int main()
{
  ll n; cin>>n;
  vector<ll> a(n);
  vector<ll> d(n+1);
  rep(i, n) cin>>a[i];
  d[0] = 3;
  ll ans = 1;

  rep(i, n) {
    ans = (ans * d[a[i]]) % mod;
    d[a[i]]--;
    d[a[i]+1]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4844
import bisect
n, d, a = map(int, input().split())
fox = [None]*n
for i in range(n):
  x, h = map(int, input().split())
  fox[i] = (x, h)

fox.sort()
x = [int(fox[i][0]) for i in range(n)]
h = [int(fox[i][1]) for i in range(n)]

ans = 0
bit = [0]*n
for i in range(n):
  if i != 0:
    bit[i] += bit[i-1]
  if bit[i] >= h[i]:
    continue
  sub = (h[i]-bit[i]-1)//a+1
  ans += sub
  bit[i] += sub*a
  index = bisect.bisect_right(x, x[i]+2*d)
  if index == n:
    continue
  bit[index] -= sub*a
print(ans)

Measured memory_bytes: 70308
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

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

int S[100010];
int arr[100010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);

    int N;
    while (cin >> N, N)
    {
        string s;
        cin >> s;

        int a[N], b[N];
        for (int i = 0; i < N; ++i)
        {
            cin >> a[i] >> b[i];
            a[i]--;
            b[i]--;
        }
        reverse(a, a + N);
        reverse(b, b + N);

        for (int i = 0; i < N; ++i)
        {

            int sa = b[i] - a[i];

            sa %= 26;
            s[a[i]] = (char)((s[a[i]] - 'a' + sa) % 26 + 'a');
            s[b[i]] = (char)((s[b[i]] - 'a' + sa) % 26 + 'a');
            swap(s[a[i]], s[b[i]]);
        }

        cout << s << endl;
    }

    return 0;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lef(x) (x<<1)
#define rig(x) (lef(x)+1)

const int N=200100;

ll tree[4*N];
pair<ll,ll> a[N];

ll query(int p,int tl,int tr,int l,int r){
	if(l>r)
		return -1;

	if(tl==l && tr==r)
		return tree[p];

	int mid=(tl+tr)/2;
	return max(query(lef(p),tl,mid,l,min(r,mid)),query(rig(p),mid+1,tr,max(l,mid+1),r));
}


void update(int p,int tl,int tr,int k,ll x){
	if(tl==tr)
		tree[p]=x;
	else{
		int mid=(tl+tr)/2;
		if(mid>=k){
			update(lef(p),tl,mid,k,x);
		}else{

			update(rig(p),mid+1,tr,k,x);
		}
		tree[p]=max(tree[lef(p)],tree[rig(p)]);
	}
}







int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i].first;
	}

	for (int i = 0; i < n; ++i)
	{
		cin>>a[i].second;
	}
	// update(1,1,n,a[0].ft,a[0].second);
	for (int i = 0; i < n; ++i)
	{
		ll r=query(1,1,n,1,a[i].first);
		if((r+a[i].second)>query(1,1,n,a[i].first,a[i].first))
			update(1,1,n,a[i].first,r+a[i].second);
	}
	cout<<query(1,1,n,1,n)<<"\n";
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int n;
  string s;
  cin >> n >> s;
  vvi dp(n,vi(n));
  rep(i,n) dp[n-1][i] = (s[i] == s[n-1]);
  for(int i=n-2;i>=0;i--){
    for(int j=n-1;j>=0;j--){
      if(j > i) dp[i][j] = dp[j][i];
      else{
        if(s[i] == s[j]) dp[i][j] = dp[i+1][j+1] + 1;
        else dp[i][j] = 0;
      }
    }
  }
  int ans = 0;
  rep(i,n){
    rep(j,n){
      ans = max(ans, min(abs(j-i),dp[i][j]));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 98176
#include <stdio.h>
#include <math.h>

int main(void) {
	
	int i,w,n,x,y,k;
	int a[31];

	scanf("%d",&w);
	scanf("%d",&n);

	for(i=1;i<=w;i++){
		a[i]=i;
	}

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

	for(i=1;i<=w;i++){
		printf("%d\n",a[i]);
	}
	
	return 0;
}

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define int long long

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int layer(int level){
    return pow(2,level+2)-3;
}

int burger(int level,int x){
    if(level==0) return 1;
    else if(x==1) return 0;
    else if(1<x && x<=layer(level-1)+1) return burger(level-1,x-1);
    else if(x==layer(level-1)+2) return burger(level-1,layer(level-1))+1;
    else if(layer(level-1)+2<x && x<layer(level)) return burger(level-1,layer(level-1))+1+burger(level-1,x-layer(level-1)-2);
    else if(x==layer(level)) return burger(level-1,layer(level-1))*2+1;
    else return -1;
}

void atcoder(){
    int n,x;
    cin>>n>>x;
    cout<<burger(n,x)<<ENT;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a[200010],A[200010];
int main()
{
	int n,k,ans=0;
	cin>>n>>k;
	for(int i=1;i<=k;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=k-1;i++)
		A[i]=a[i+1]-a[i];
	A[k]=n-a[k]+a[1];
	sort(A+1,A+1+k);
	for(int i=1;i<=k-1;i++)
		ans=ans+A[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
str_a, str_b ,str_c = input().split()
a, b , c = int(str_a),int(str_b), int(str_c)
if a <= b <= c :
    print(str(a) + " " + str(b) + " " + str(c))
elif a <= c <= b:
    print(str(a) + " " + str(c) + " " + str(b))
elif b <= a <= c:
    print(str(b) + " " + str(a) + " " + str(c))
elif b <= c <= a:
    print(str(b) + " " + str(c) + " " + str(a))
elif c <= a <= b:
    print(str(c) + " " + str(a) + " " + str(b))
else:
    print(str(c) + " " + str(b) + " " + str(a))


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

int main()
{
    int n,x;
    cin >> n >> x;
    int a[n];
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    for(int i = 0; i < n; i++){
        x -= a[i];
        if((i < n-1 && x >= 0) || (i == n-1 && x == 0)){
            ans++;
        }else{
            break;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string s1,s2;
	int count=0;
	cin>>s1>>s2;
	for(int i=0;i<3;i++)
	{
		if(s1[i]==s2[i]) count++;
	}
	cout<<count<<endl;
	return 0;
 } 

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

int main(){
  int n;
  cin>>n;
  long long max = pow(10,9)+7;
  long long all = 1;
  long long no1 = 1;
  long long no2 = 1;
  for(int i=0;i<n;i++){
    all = (10*all)%max;
    no1 = (8*no1)%max;
    no2 = (9*no2)%max;
  }
  long long ans = (all+no1-2*no2)%max;
  if(ans<0) ans += max;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3508
import sys
sys.setrecursionlimit(10**6)

n,A,B,C = map(int,input().split())
s = [[*input()] for _ in range(n)]
a = {"A":A, "B":B, "C":C}
ans = ["Yes"]+[0]*n
def dfs(i):
    if i==n:
        print("\n".join(ans))
        exit()
    for p,m in [s[i],s[i][::-1]]:
        if a[m]:
            a[p]+=1; a[m]-=1; ans[i+1]=p
            dfs(i+1)
            #一つ戻る
            a[p]-=1; a[m]+=1
dfs(0)
print("No")

Measured memory_bytes: 122812
import sys

def JudgeLunLun(num):
  val = num
  next = 0
  if num <= 12:
    val = num
  else:
    # 真面目なルンルン数判定。文字列に変換して1桁毎の処理を行う。
    # 加算処理に備えて文字として扱う
    A = str(num)
    for i in range(len(A)-1):
      if abs(int(A[i])-int(A[i+1])) > 1:
        val = 0
        # A[i+1]が大きい時は、A[i]をカウントアップするしかない。
        if int(A[i]) < int(A[i+1]):
          head = str(int(A[:i+1])+1)
          body = '0'
          tail = '0' * (len(A) - (i+2))
        else:
          if int(A[i]) - int(A[i+1]) > 2:
            head = A[:i+1]
            body = str(int(A[i]) -1)
            tail = '0' * (len(A) - (i+2))            
          else:
            head = A[:i+1]
            body = str(int(A[i+1]) +1)
            tail = '0' * (len(A) - (i+2))
            if body == '10':
              head = str(int(head)+1)
              body = '0'
        
        # 編集後の値を結合して数値変換して返す
        next = int(head+body+tail)
  
  return val, next

def main():
  K = int(input())
  cnt = 0
  i = 1
  while cnt < K:
    val, next = JudgeLunLun(i)
    # ルンルン数判定
    if val > 0:
      i += 1
      cnt += 1
      if cnt == K:
        break
    else:
      i = next
    
  print(val)

if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
  int h, w, a, b;
  scanf("%d %d %d %d", &h, &w, &a, &b);
  
  for (int i = 0; i < b; i++){
    for (int j = 0; j < a; j++){
      printf("%d", 1);
    }
    for (int j = a; j < w; j++){
      printf("%d", 0);
      if (j == w - 1) printf("\n");
    }
  }
  for (int i = b; i < h; i++){
    for (int j = 0; j < a; j++){
      printf("%d", 0);
    }
    for (int j = a; j < w; j++){
      printf("%d", 1);
      if (j == w - 1) printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll ans = 1, max = 1000000000000000000, prev = 1;
    if(a[n-1] == 0){
        cout << 0 << endl;
        return 0;
    }
    rep(i, n){
        ans *= a[i];
        if(ans > max || ans < prev){
            cout << -1 << endl;
            return 0;
        }
        prev  = ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
<?php
$input = file_get_contents('php://stdin');
$inarr = explode("\n", $input);

$card = array_map(function ($e) {
  return explode(" ", $e);
}, array_splice($inarr, 0, 3));

$n = intval($inarr[0]);
$b = array_splice($inarr, 1, $n);

foreach ($b as $_b) {
  foreach ($card as &$row) {
    $key = array_search($_b, $row);
    if ($key !== false) {
      $row[$key] = 0;
    }
  }
}

$bingo = false;
for ($i = 0; $i < 3; $i++) {
  if (array_sum($card[$i]) === 0) {
    $bingo = true;
  }
  if ($card[0][$i] + $card[1][$i] + $card[2][$i] === 0) {
    $bingo = true;
  }
  if ($card[0][0] + $card[1][1] + $card[2][2] === 0) {
    $bingo = true;
  }
  if ($card[0][2] + $card[1][1] + $card[2][0] === 0) {
    $bingo = true;
  }
}

echo ($bingo ? "Yes" : "No") . PHP_EOL;


Measured memory_bytes: 4604
N = int(input())
B = list(map(int, input().split()))
A = [0 for _ in range(N)]
A[1] = A[0] = B[0]
for i in range(1,N-1):
    #print("i",i)
    A[i] = min(B[i], B[i-1])
    #A[i+1] = B[i]
    #print("Ai",A[i])
A[N-1] = B[N-2]
print(sum(A))

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
//ll MOD = 1000000007;
ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

//デバッグ
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

bool need(vector<ll> A, vector<ll> B, set<ll> X){//xの要素のみでA->Bが全て実現可能か
  ll dist[51][51];
  rep(i, 51)rep(j, 51) dist[i][j] = 1;
  rep(i, 51) dist[i][i] = 0;
  for(ll i = 0; i < 51; i++){
    for(auto itr = X.begin(); itr != X.end(); itr++){
      dist[i][i%(*itr)] = 0;
    }
  }
  rep(k, 51)rep(i, 51)rep(j, 51) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  rep(i, A.size()){
    if(dist[A[i]][B[i]] != 0) return 0;
  }
  return 1;
}

ll sub(vector<ll> X){
  ll sum = 0;
  ll M = 0;
  rep(i, X.size()){
    sum += X[i];
    M = max(M, X[i]);
  }
  if(M > (sum - M)){
    return 2 * M - sum;
  }else{
    return sum % 2;
  }
}

ll N;
vector<ll> A;
vector<ll> E[100010];

ll dfs(ll now, ll from){
  vector<ll> xs;
  ll M = 0;
  for(ll to : E[now]){
    if(to == from) continue;
    xs.pb(dfs(to, now));
    M += xs.back();
    if(xs.back() == -1) return -1;
  }
  if(xs.size() == 0) return A[now];
  ll m = sub(xs);
  ll M_loop = (M - m) / 2;
  if(A[now] < m + M_loop || A[now] > M) return -1;
  return 2 * A[now] - M;
}

int main(){
  cin >> N;
  A.resize(N);
  rep(i, N) cin >> A[i];
  rep(i, N-1){
    ll a, b;
    cin >> a >> b;
    a--, b--;
    E[a].pb(b);
    E[b].pb(a);
  }
  if(N == 2){
    if(A[0] == A[1]){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
    return 0;
  }
  ll x = -1;
  rep(i, N){
    if(E[i].size() != 1) x = i;
  }
  if(dfs(x, -1) == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 17920
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if(N % 10 == 7 || (N / 10) % 10 == 7 || (N / 100) == 7) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n;
  cin>>n;
  int p[n],q[n],a[n];
  for(int i=0;i<n;i++){
    int b;
    cin>>b;
    p[i]=b;
  }
  for(int i=0;i<n;i++){
    int b;
    cin>>b;
    q[i]=b;
  }
  for(int i=0;i<n;i++){
    a[i]=i+1;
  }
  bool temp1=false,temp2=false;
  int ans1=0,ans2=0;
  do{
    if(!temp1){
      for(int i=0;i<n;i++){
        if(a[i]!=p[i]){
          ans1++;
          break;
        }
        if(i==n-1){
          ans1++;
          temp1=true;
        }
      }
    }
    if(!temp2){
      for(int i=0;i<n;i++){
        if(a[i]!=q[i]){
          ans2++;
          break;
        }
        if(i==n-1){
          ans2++;
          temp2=true;
        }
      }
    }
    if(temp1 and temp2) break;
  }while(next_permutation(a,a+n));
  cout<<abs(ans1-ans2)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,m;
Vi v[100001];
bool chk[100001];
int dfs(int N,int des)
{
	chk[N]=1;
	if(N==des)return 1;
	for(int next:v[N])
	{
		if(!chk[next])
			return dfs(next,des);
	}
	return 0;
}
int main(){
	scanf("%d%d",&n,&m);
	fup(i,1,m,1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	fup(i,1,n,1)if(v[i].size()&1)return !printf("No");
	Vi vv;
	fup(i,1,n,1)
	{
		if(v[i].size()>=6)return !printf("Yes");
		if(v[i].size()==4)vv.pb(i);
	}
	if(vv.size()>=3)return !printf("Yes");
	if(vv.size()<2)return !printf("No");
	int cnt=0;
	for(int y:v[vv[0]])
	{
		MEM0(chk);
		chk[vv[0]]=1;
		cnt+=dfs(y,vv[1]);
	}
	puts(cnt==2?"Yes":"No");
}

Measured memory_bytes: 5760