akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    readLine()
    val sum = LongArray(2)
    val cost = LongArray(2)
    readLine()!!.split(' ').forEachIndexed { i, astr ->
        val a = astr.toLong()
        sum[0] += a
        sum[1] += a
        if (i % 2 == 0) {
            if (sum[0] <= 0) {
                cost[0] += 1 - sum[0]
                sum[0] = 1
            }
            if (0 <= sum[1]) {
                cost[1] += 1 + sum[1]
                sum[1] = -1
            }
        } else {
            if (0 <= sum[0]) {
                cost[0] += 1 + sum[0]
                sum[0] = -1
            }
            if (sum[1] <= 0) {
                cost[1] += 1 - sum[1]
                sum[1] = 1
            }
        }
    }
    println(cost.min())
}


Measured memory_bytes: 49664
#include <iostream>
using namespace std;
int main(){
  string x;
  cin >> x;
  if (x == "A"){
    cout << "T" << endl;
  }
  if (x == "T"){
    cout << "A" << endl;
  }
  if (x == "C"){
    cout << "G" << endl;
  }
  if (x == "G"){
    cout << "C" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

result = [[a[0], sum(a[1:])]]
for i in range(1, n):
    result.append([result[-1][0]+a[i], result[-1][1]-a[i]])
h = []
for i in range(len(result)):
    h.append(abs(result[i][0]-result[i][1]))
print(min(h))

Measured memory_bytes: 54764
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
    long long n;
    cin >> n;
    vector<long long> tmp(n + 1, 0);
    vector<long long > a(n);
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        tmp[a[i]]++;
    }

    for (int j = 1; j < n + 1; j++)
    {
        ans += tmp[j] * (tmp[j] - 1) / 2;
    }

    for (int i = 1; i < n + 1; i++)
    {
        cout << ans - (tmp[a[i - 1]] - 1) << endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];
  sort(d.begin(), d.end());
  int idx = n / 2;
  cout << d[idx] - d[idx - 1] << endl;
  return 0;
}



Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(){
  
  int a,b;
  cin >> a >>b;
 
  int pl=a+b;
  int mi=a-b;
  int ml=a*b;
  
  if(pl>mi){
	if(pl>ml)cout<<pl;
	else cout<<ml;
  }
  
  if(mi>=pl){
	if(ml>mi)cout<<ml;
	else cout<<mi;
  }
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int main(){
    fast;
    int x, n;
    cin >> x >> n;
    int h[105] = {0};
    for(int i = 0; i < n; i++){
        int xx;
        cin >> xx;
        h[xx]++;
    }
    int lft = x, ltans = 0;;
    while(lft > 0){
        if(h[lft] == 0){
            ltans = lft;
            break;
        }
        lft--;
    }
    int rt = x + 1, rtans = 101;
    while(rt < 101){
        if(h[rt] == 0){
            rtans = rt;
            break;
        }
        rt++;
    }
    if(x - ltans <= rtans - x)
        cout << ltans;
    else cout << rtans;
    return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
}

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

using namespace std;

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

    long n;
    cin >> n;
    // char s[n];
    string s;
    // scanf("%s", &s);
    cin >> s;
    long right_e = 0;
    // for (long i = 0; i < n; i++) if (s[i] == 'E') right_e++;
    for (long i = 0; i < n; i++) right_e += (s[i] == 'E');
    // for (long i = 1; i < n; i++) if (s[i] == 'E') right_e++;
    long min_count = right_e;
    long left_w = 0;
    for (long i = 0; i < n; i++) {
    // for (long i = 1; i < n; i++) {
        if (!min_count) break;
        if (s[i] == 'E') {
            right_e--;
        } else {
            right_e++;
        }
        // if (s[i ] == 'W') right_e++;
        // if (s[i -1] == 'W') left_w++;
        min_count = min(min_count, right_e);
    }
    cout << min_count << '\n';
    
    return 0;
}

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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int res = 0;
	for(int i = 1; i <= N; i++) {
		int t = i;
		int tt = 0;
		while(t) {
			tt += t % 10;
			t /= 10;
		}
		if(A <= tt && tt <= B) res += i;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll X = 0;
	ll M = 0;
	//ll M = 0;
	//ll a[200000] = {};
	//ll b[200000] = {};
	ll v[100] = {};
	ll *a, *b, *x;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	

	//char p;
	cin >> N ;
	//cin >> S;

	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(N+1);
	//vector<bool> flag(N);
	
	//count--;
	//	cout << X << endl;
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(is.begin(), is.end());




	v[0] = N / 1000;
	N %= 1000;
	v[1] = N / 100;
	N %= 100;
	v[2] = N / 10;
	N %= 10;
	v[3] = N;
	
	//cout << v[0] << v[1] << v[2] << v[3] << endl;

	if ((v[0] == v[1] && v[1] == v[2]) || (v[1] == v[2] && v[2] == v[3]))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	

	



	


	return 0;

}

ll gcd(ll a, ll b) {
	ll c;
	c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}

	return b;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc167/tasks/abc167_d

def resolve():
    n, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))

    c = 1
    while k:
        if k & 1:
            c = a[c]
        na = [0] * (n+1)
        for i in range(n+1):
            na[i] = a[a[i]]
        a = na
        k >>= 1

    print(c)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 32384
n = int(input())
ans = 0
for i in range(1, n+1):
    if i % 3 == 0 and i % 5 == 0:
        continue
    elif i % 3 == 0:
        continue
    elif i % 5 == 0:
        continue
    else:
        ans += i
print(ans)

Measured memory_bytes: 65156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
 

int main() {
	ll n;
	cin>>n;
	map<ll,ll>ch;
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;		
		if(i!=0){
		ans+=ch[i+1-x];
		}

		ch[x+(i+1)]++;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 26156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  
  cin >> N;
  vector<double> x(N, 0.0);
  vector<double> y(N, 0.0);
  for(int i=0; i<N; i++){
    cin >> x.at(i);
  }
  for(int i=0; i<N; i++){
    cin >> y.at(i);
  }
  
  double sum1 = 0;
  double sum2 = 0;
  double sum3 = 0;
  double max = 0;
  for(int i=0; i<N; i++){
    double sum = fabs(x.at(i) - y.at(i));
    sum1 += sum;
    sum2 += pow(sum, 2.0);
    sum3 += pow(sum, 3.0);
    if(sum > max) max = sum;
  }
  
  cout << std::fixed << std::setprecision(6) << sum1 << endl;
  cout << std::fixed << std::setprecision(6) << sqrt(sum2) << endl;
  cout << std::fixed << std::setprecision(6) << pow(sum3, 1.0 / 3.0) << endl;
  cout << std::fixed << std::setprecision(6) << max << endl;
}


Measured memory_bytes: 3484
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define ll              long long
#define dd              double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define vi              vector<int>
#define vll             vector<long long>
#define vdd             vector<double>
#define vpii            vector<pair<int,int>>
#define vpll            vector<pair<long long,long long>>
#define vvi             vector<vector<int>>
#define vvll            vector<vector<long long>>
#define mii             map<int,int>
#define mll             map<long long,long long>
#define umii            unordered_map<int,int>
#define umll            unordered_map<long long,long long>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep2(i,a,b)     for(int i=a;i<b;i++)
#define rev(i,n)        for(int i=n;i>=0;i--)
#define rev2(i,a,b)     for(int i=a;i>=b;i--)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             9e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define wh(x)           int x; cin>>x; while(x--)
#define fio             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl            '\n'
#define all(x)          x.begin(),x.end()
#define d0(x)           cout <<x<<" "
#define d1(x)           cout <<x<<endl
#define d2(x,y)         cout <<x<<" "<<y<<endl
#define d3(x,y,z)       cout <<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w)     cout <<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define read2(x,y)      cin>>x>>y
#define read3(x,y,z)    cin>>x>>y>>z
#define read4(x,y,z,w)  cin>>x>>y>>z>>w
#define read5(x,y,z,w,a)cin>>x>>y>>z>>w>>a
#define sz(a)           (int)a.size()
#define deb(x)          cout <<#x << " is "<<x<<endl;
const ll mod=1e9+7;
const double PI = 3.14159265359;
const ll MOD=998244353;
void i_o()
{
   #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   #endif
}
int n;
vi A;
int help(){
	umii m;
	rep(i,n) m[A[i]]++;
	int ma=*max_element(all(A));
	vi B;
	for(auto it:m) B.pb(it.ff);
	unordered_map<int,bool> is;
	rep(i,sz(B)) is[B[i]]=true;
	rep(i,n) if(m[A[i]]>1) is[A[i]]=false;
	rep(i,sz(B)){
		for(int j=2*B[i];j<=ma;j+=B[i]){
			if(m.count(j)) is[j]=false;
		}
	}
	int ans=0;
	for(auto it:is) if(it.ss==true) ans++;
	return ans;

}
int main(){
	fio
  i_o();
  cin>>n;
  A=vi(n);
  rep(i,n) cin>>A[i];
  d1(help());

  return 0;

}

Measured memory_bytes: 21120
#include<stdio.h>

int main()
{
	long n,i;
	long ct = 0;
	long sw =0;
	long a[100000];
	scanf("%ld", &n);
	for (i = 1; i < n + 1; i++) {
		scanf("%ld", &a[i]);
		if (i == a[i] && sw == 0) {
			ct++;
			sw++;
		}
		else {
			sw = 0;
		}
	}
	printf("%ld", ct);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  vector<int> data(N);
  int sum = 0;
  
  for(int i=0;i<N;i++)
     cin >> data.at(i);
  
  for(int i=0;i<N;i++){
    int height = data.at(i) - K;
    if(height>=0)
      sum++;
  }
    cout << sum << endl;
}

Measured memory_bytes: 640
<?php
while(true){
list($h,$w) = explode(" ",trim(fgets(STDIN)));
if($h ==0 and $w == 0){
break;
}
for($i=0;$i<$h; $i++){
    echo "#";
    for($j=1;$j<$w; $j++){
    echo "#";
}
    echo PHP_EOL;
}
    echo PHP_EOL;
}


Measured memory_bytes: 9216
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
e = dd(list)
for i in range(N - 1):
  u, v = map(int, input().split())
  e[u].append((v, i))
  e[v].append((u, i))
res = [0] * (N - 1)
def dfs(x):
  global res
  c = 1
  vis = set()
  for y, i in e[x]: vis.add(res[i])
  #print(x, vis)
  for y, i in e[x]:
    if res[i] > 0: continue
    while c in vis: c += 1
    #print(x, c)
    res[i] = c
    vis.add(c)
    dfs(y)
dfs(1)
print(max(res))
for r in res: print(r)

Measured memory_bytes: 118180
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<double>
#define vv vector<v>
#define p pair<ll,ll>
int main()
{
	int n,k;
	cin>>n>>k;
	v arr(n+1);
	for (int i=1; i<=n; i++)
		cin>>arr[i];
	v dp(k+1,0);
	for (int i=1; i<=k; i++)
	{
		for (int j=1; j<=n; j++)
			if (i>=arr[j] && dp[i-arr[j]]==0)
				dp[i]=1;
	}
	if (dp[k])
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
//#define int long long

//greedyの基本は交換しても悪化しない

void solve() {
	int n; cin >> n;
    vector<int> l(2 * n);
    rep(i, 2 * n) {
        cin >> l[i];
    }
    sort(all(l));
    int ans = 0;
    for(int i = 0; i < 2 * n; i += 2) {
        ans += l[i];
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

void solve() {
    int n, m;
    cin >> n >> m;

    map<int, int> mp;
    map<int, int> isAc;
    int cr = 0, p = 0;
    for (int i = 0; i < m; i++) {
        int a;
        string b;
        cin >> a >> b;

        if (b == "AC" and isAc[a] == 0) {
            isAc[a] = 1;
            cr++;
            p += mp[a];
            mp[a] = 0;
        } else {
            if (isAc[a] == 0) {
                mp[a]++;
            }
        }
    }
    cout << cr << " " << p << endl;
}


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
 
#define pb push_back
#define mp make_pair

typedef long long ll; 

#define fi first
#define se second
 
#define all(x) (x).begin(), (x).end()
 
using namespace std;             
//using namespace __gnu_pbds;
 
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int INF = (int)1e10;

ll n;

void solve() {        
    cin >> n;     
    string s;
    cin >> s;                   

    cout << (s.substr(0, n / 2) == s.substr(n / 2, n / 2) && n % 2 == 0 ? "Yes" : "No");
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

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

bool jump(int x, int y, string s){ //s[x]からs[y]までに追い抜きできる場所があればtrue(1 < x < y < n)
  for (int i = x; i < y+1; i++){
    if((s[i-2]=='.'&&s[i-1]=='.')&&s[i]=='.')  return true;
  }
  
  return false;
}

bool go(int x, int y, string s){ //s[x]からs[y]まで進めるときtrue(1 <= x < y <= n)
  if(y-x<3) return true;
  for (int i = x; i < y-2; i++){
    if(s[i]=='#'&&s[i+1]=='#') return false;
  }
  return true;
}

int main(){
  int n,a,b,c,d;
  cin >> n>>a>>b>>c>>d;
  string s;
  cin >> s;

  if(c<d){
    if(go(a,c,s)&&go(b,d,s)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }

  if(d<c){
    if((go(a,c,s)&&go(b,d,s))&&jump(b,d,s)) cout << "Yes" << endl;
    else cout << "No" << endl;   
    return 0; 
  }
}


Measured memory_bytes: 1156
# from math import factorial,sqrt,ceil
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
t,x = map(int,input().split())

ans = t/x

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=15,M=1010;
int h,w,k;
int s[N][M];

int main(){
    cin>>h>>w>>k;

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++) {
            char m;
            cin>>m;
            int e=m-'0';
            s[i][j]=e+s[i-1][j]+s[i][j-1]-s[i-1][j-1];    
            //这题出题人良心，直接把要算的设置成1，不要算的设置成0
        }
    }

    int minsum=h+w-2;
    for(int i=0;i<(1<<(h-1));i++){//枚举横切情况
        vector<int> q;
        q.push_back(0);//记得加第0条边界线，方便统一处理
        int sum=0;

        for(int j=0;j<h-1;j++){
            if(i>>j&1) {
                q.push_back(j+1);
                sum++;
            }
        }
        q.push_back(h);//最外面的边界线，处理最后一个格子和不切的情况

        bool flag=true;
        int lastline=0;
        for(int j=1;j<=w;j++){//贪心纵切
            int wmax=0;
            for(int d=1;d<q.size();d++){
                wmax=max(wmax,s[q[d]][j]-s[q[d]][lastline]-s[q[d-1]][j]+s[q[d-1]][lastline]);
            }
            if(wmax>k){
                if(j==1){
                    flag=false;
                    break;
                }
                sum++;
                lastline=j-1;
            }
        }
        if(!flag) continue;
        minsum=min(minsum,sum);
    }
    cout<<minsum<<endl;
    return 0;
}


Measured memory_bytes: 256
'use strict'
function main(input) {
  input = input.split('\n')
  const length = Number(input[0])
  input = input[1].split(' ')

  const gcd = (a, b) => {
    if (b === 0) return a
    return gcd(b, a % b)
  }

  const l = [0]
  const r = []
  r[length - 1] = 0

  for (let i = 1; i < length; i++) {
    l[i] = gcd(l[i-1], Number(input[i-1]))
  }

  for (let i = length - 1; i > 0; i--) {
    r[i-1] = gcd(r[i], Number(input[i]))
  }
  
  const result = []
  for (let i = 0; i < length; i++) {
    result[i] = gcd(l[i], r[i])
  }

  console.log(Math.max(...result))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main() {
  vector<vector<int>> A(3, vector<int>(3,0));
  for(int i = 0; i < 3; i++){
    for(int j =0; j < 3; j++){
      cin >> A.at(i).at(j);
    }
  }

  vector<vector<bool>> flag(3, vector<bool>(3,false));
  int N;
  cin >> N;

  vector<int> B(N);

  for(int i = 0; i < N; i++){
    cin >> B.at(i);
  }
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(B.at(i) == A.at(j).at(k)) flag.at(j).at(k) = true;
      }
    }
  }

  bool result = false;

  //縦横
  for(int i = 0; i < 3; i++){
    if(flag.at(0).at(i) == true && flag.at(1).at(i) == true && flag.at(2).at(i) == true){
      result = true;
    }
    if(flag.at(i).at(0) == true && flag.at(i).at(1) == true && flag.at(i).at(2) == true){
      result = true;
    }
  }
  //ななめ
  if(flag.at(0).at(0) == true && flag.at(1).at(1) == true && flag.at(2).at(2) == true){
    result = true;
  }
  if(flag.at(0).at(2) == true && flag.at(1).at(1) == true && flag.at(2).at(0) == true){
    result = true;
  }

  if(result) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int numberOfProblems = sc.nextInt();
        int numberOfSubmissions = sc.nextInt();
        int[] wa = new int[numberOfProblems+1];
        int correct =0, penalties = 0;
         while (numberOfSubmissions-->0){
             int indexOfQuestion = sc.nextInt();
             String result = sc.next();

             if(wa[indexOfQuestion]==-1){
                 continue;
             }
             if(result.equals("WA")){
                 wa[indexOfQuestion]++;
             }else {
                 correct++;
                 penalties += wa[indexOfQuestion];
                 wa[indexOfQuestion] = -1;
             }
         }
        System.out.println(correct+ " "+penalties);
    }
}

Measured memory_bytes: 63036
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
ss=[input().rstrip() for i in range(n)]
m=I()
ts=[input().rstrip() for i in range(m)]
u=Counter(ss)
v=Counter(ts)
#print(u)
#print(v)
ans=[]
for j in u.keys():
    ans.append(u[j]-v[j])
print(max(max(ans),0))

Measured memory_bytes: 3316
#include <cstdio>
#include <string>
#include <iostream>
#include <cstring>
using namespace std;

int change[7][7]={
	{18,17,16,14,12,11,9},
    {17,15,14,12,10,9,7},
    {16,14,13,11,9,8,6},
    {14,12,11,9,7,6,4},
    {12,10,9,7,5,4,2},
    {11,9,8,6,4,3,1},
    {9,7,6,4,2,1,0}
};
string str;

bool dfs(){
	for(int i=0;i<(1<<19);i++){
		int num[19];
		for(int j=0;j<19;j++){
			num[j]=(i>>j)&1;
		}
		int c[7]={};
		for(int j=0;j<7;j++){
			for(int k=0;k<7;k++){
				if(num[change[j][k]])c[j]+=(1<<k);
			}
			c[j]=str[c[j]]-'0';
		}
		int d=0;
		for(int k=0;k<7;k++){
			if(c[k])d+=(1<<k);
		}
		if(str[d]-'0'!=c[3])return false;
	}
	return true;
}

int main(void){
	while(1){
		cin >> str;
		if(str=="#")break;
		printf("%s\n",dfs()?"yes":"no");
	}
	return 0;
}

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

const int MAX = 101000;

int main() {
    int N;
    string s;
    cin >> N >> s;
    int westAc[N+1], eastAc[N+1];
    westAc[0]=0;
    eastAc[0]=0;
    for(int i=0;i<N;++i) {
        if(s[i] == 'W') {
            westAc[i+1] = westAc[i]+1;
            eastAc[i+1] = eastAc[i];
        }
        else {
            eastAc[i+1] = eastAc[i]+1;
            westAc[i+1] = westAc[i];
        }
    }
    int ans = N;
    for(int i=0;i<N;++i) {
        int c = westAc[i]+ (eastAc[N]-eastAc[i+1]);
        ans = min(ans, c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 1;
//-----------------------------------------------//

int N, K;
int cnt[212345];

int main() {
	cin >> N >> K;
	REP(i, N) {
		int a;
		scanf("%d", &a);
		cnt[a]++;
	}
	
	vector<int> v;
	REP(i, 212345) if (cnt[i]) v.push_back(cnt[i]);
	sort(ALL(v));
	
	int ans = 0;
	REP(i, (int)v.size() - K) ans += v[i];
	cout << ans << endl;
	
	return 0;
}

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

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int k;
    long[] d;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
//        System.out.println(main.solve());
    }
    void solve() throws IOException{
        String s1 = "AAA", s2 = "BBB";
        String s = sc.next();
        String ans = "Yes";
        if(s.equals(s1)||s.equals(s2)) ans= "No";
        System.out.println(ans);
    }
}



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

int main(){
    int N,K;
    cin >> N >> K;
    int p[N];
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    sort(p,p+N);
    long sum=0;
    for(int i=0; i<K; i++){
        sum+=p[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
from itertools import product

N = int(input())
F = [input().split(" ") for _ in range(N)]
P = [input().split(" ") for _ in range(N)]

max_res = 0

for i,j in enumerate(product("01",repeat=10)):
    if i != 0:
        res = [0 for _ in range(N)]
        for k, flag in enumerate(j):
            if flag == "1":
                for l,f in enumerate(F):
                    if f[k] == "1":
                        res[l] += 1
        buf = 0
        for m in range(N):
            buf += int(P[m][res[m]])
        if i==1:
            max_res = buf
        else:
            max_res = max(buf,max_res)

print(max_res)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, B: "List[int]"):
    A = [0]*N
    A[0] = B[0]
    for i in range(1, N-1):
        A[i] = min(B[i-1], B[i])
    A[N-1] = B[N-2]
    print(sum(A))
    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
    B = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2222;
char g[maxn][maxn];
int val[maxn][maxn];
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> g[i][j];
	for(int i = 0; i < n; i++){
		int now = 0;
		for(int j = 0; j < m; j++){
			val[i][j] += now;
			if(g[i][j] == '.') now++;
			else now = 0;
		}
		now = 0;
		for(int j = m - 1; j >= 0; j--){
			val[i][j] += now;
			if(g[i][j] == '.') now++;
			else now = 0;
		}
	}
	for(int j = 0; j < m; j++){
		int now = 0;
		for(int i = 0; i < n; i++){
			val[i][j] += now;
			if(g[i][j] == '.') now++;
			else now = 0;
		}
		now = 0;
		for(int i = n - 1; i >= 0; i--){
			val[i][j] += now;
			if(g[i][j] == '.') now++;
			else now = 0;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) if(g[i][j] != '#') ans = max(ans, val[i][j]);
	cout << ans + 1<< endl;
	return 0;
}


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

int n, a[1025][1025], vis[1025];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (a[x][a[x][0]] == i && !vis[i] && !vis[x]) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<int> ls(n);
    for (int i = 0; i < n; i++)
    {
        cin >> ls[i];
    }
    sort(ls.begin(), ls.end());
    long ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
        {
            ans += distance(ls.begin() + j + 1, lower_bound(ls.begin(), ls.end(), ls[i] + ls[j]));
        }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


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

int main()
{
    ios::sync_with_stdio();cin.tie(0);cout.tie(0);
    #define pb push_back
    #define mk make_pair
    //#define int long long int
    int t,n,sum=0;
    cin>>t>>n;
    int a[n+10];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>t)cout<<-1<<endl;
    else cout<<t-sum<<endl;



    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> point;
double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
	return real(conj(a)*b);
}

typedef vector<point> polygon;
enum { OUT, ON, IN };
int contains(const polygon& P, const point& p) {
	bool in = false;
	for (int i = 0; i < P.size(); ++i) {
		point a = P[i] - p, b = P[(i+1)%P.size()] - p;
		if (imag(a) > imag(b)) swap(a, b);
		if (imag(a) <= 0 && 0 < imag(b))
			if (cross(a, b) < 0) in = !in;
		if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
	}
	return in ? IN : OUT;
}

int main() {
	int n;
	while (cin >> n) {
		polygon pol(n);
		for (auto& p : pol) {
			int x, y;
			cin >> x >> y;
			p = point(x, y);
		}
		int q;
		cin >> q;
		for (int i = 0; i < q; i++) {
			int x, y;
			cin >> x >> y;
			cout << contains(pol, point(x, y)) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

struct SegmentTree{
	std::vector<int> seg;
	int sz = 1;
	
	SegmentTree(int n){
		while(sz < n) sz *= 2;
		seg.assign(sz * 2, 0);
	}
	
	void add(int k, int x){
		k += sz - 1;
		seg[k] += x;
		
		while(k){
			k = (k - 1) / 2;
			seg[k] = seg[2 * k + 1] + seg[2 * k + 2];
		}
	}
	
	int get(int a, int b){
		return get(a, b, 0, 0, sz);
	}
	
	int get(int a, int b, int k, int l, int r){
		if(b<=l||r<=a) return 0;
		if(a<=l&&r<=b) return seg[k];
		
		return get(a, b, 2 * k + 1, l, (l + r) / 2) + get(a, b, 2 * k + 2, (l + r) / 2, r);
	}
};

int main(){
	long n, k; cin >> n >> k; std::vector<long> a(n + 1), vec;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) a[i + 1] += a[i];
	for(long i = 0; i <= n; i++) a[i] -= i * k;
	for(int i = 0; i <= n; i++) vec.push_back(a[i]);
	sort(begin(vec), end(vec)); vec.erase(unique(begin(vec), end(vec)), end(vec));
	SegmentTree	seg(vec.size());
	
	long ans = 0;
	for(int i = n; i >= 0; i--){
		int A = lower_bound(begin(vec), end(vec), a[i]) - begin(vec);
		
		ans += seg.get(A, vec.size());
		seg.add(A, 1);
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  string s;
  while (cin >> s) {
    if (s.at(0) != '0') {
      ll ans = 0;
      rep(i, s.size()) ans += ctoi(s.at(i));
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
const int C=1;
const int N=1000010;
int p[N],pnum;
bool b[N];
long long lcm(long long x,long long y){
	if (!(x&&y)) return x^y;
	return (__int128)x*y/__gcd(x,y);
}
const int P=510;
int a[P][P],c[P][P];
long long re[P][P];
int main(){
	int n; scanf("%d",&n);
	for (int i=2; pnum<2000; ++i){
		if (!b[i]) p[pnum++]=i;
		for (int j=0; j<pnum&&i*p[j]<=1000000; ++j){
			b[i*p[j]]=1;
			if (i%p[j]==0) break;
		}
	}

	int d=0;
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=n; ++j)
			if ((i+j)&1) a[i][j]=p[(i+j)/2];
	/*for (int i=1; i<=n; ++i,putchar('\n'))
	  for (int j=1; j<=n; ++j) printf("%d ",a[i][j]);*/

	
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=n; j++)
			if ((i+j)&1) c[i][j]=p[(i-j+n)/2+600];


	/*for (int i=1; i<=n; ++i,putchar('\n'))
	  for (int j=1; j<=n; ++j) printf("%d ",c[i][j]);*/

	
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=n; j++)
			re[i][j]=a[i][j]*c[i][j];

	/*for (int i=1; i<=n; ++i,putchar('\n'))
	  for (int j=1; j<=n; ++j) printf("%lld ",re[i][j]);*/
	
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=n; j++)
			if ((i+j)%2==0){
				re[i][j]=lcm(re[i-1][j],lcm(re[i][j-1],lcm(re[i][j+1],re[i+1][j])))+C;
		}
	if (re[1][1]==re[2][2]) re[2][2]+=re[1][1]-1;
	for (int i=1; i<=n; ++i,putchar('\n'))
		for (int j=1; j<=n; ++j) printf("%lld ",re[i][j]);
}


Measured memory_bytes: 9216
s = input()
a = 'Yes'

for i in range(len(s)):
    if s[i] == 'U' or s[i] == 'D':
        continue
    
    if i % 2 == 0:
        if s[i] == 'R':
            continue
        else:
            a = 'No'
            break
    else:
        if s[i] == 'L':
            continue
        else:
            a = 'No'
            break

print(a)

Measured memory_bytes: 2940
#include <stdio.h>

int main(void){
	int n,m,sum,num,sumx=0,i,o;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){
		sum=0;
		for(o=0;o<m;o++){
			scanf("%d",&num);
			if(num==1)
				sum++;
		}
		if(sumx<sum)
			sumx=sum;
	}
	printf("%d\n",sumx);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<P> edge;
  int ans = (n-1) * (n-2) / 2;
  if(ans < k) out(-1);
  else {
    rep(i, n-1) {
      edge.emplace_back(0, i+1);
    }
    for(int i = 1; i < n && ans > k; ++i) {
      for(int j = i + 1; j < n && ans > k; ++j) {
        ans--;
        edge.emplace_back(i, j);
      }
    }
    out(edge.size());
    for(auto e : edge) out(e.first + 1 << ' ' << e.second + 1);
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n,m=0;
    string s;
    cin >> n>> s;
    for (int i = 0; i < n-1; i++) {
        if (s[i] == s[i + 1]) m++;
    }
    cout << n - m << endl;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;

ll a[MAX_N];

ll ans[MAX_N];

int main(void) {
  // Here your code !
  scanf("%d", &n);

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

  ll acc = 0;

  for (int i = 0; i < n - 1; ++i) {
    if (i % 2 == 0) acc += a[i];
    else acc -= a[i];
  }

  ans[0] = acc + a[n - 1];

  for (int i = 1; i < n; ++i) {
    ans[i] = 2 * (a[i - 1] - ans[i - 1] / 2);
  }

  for (int i = 0; i < n; ++i) {
    printf("%lld ", ans[i]);
  }

  printf("\n");

  return 0;
}


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

int main()
{
  int n, c = 0;
  cin >> n;
  vector<int> d(n + 1);
  for (int i = 1; i <= n; i++)
  {
    cin >> d[i];
  }

  sort(d.begin(), d.end());
  if (d[n / 2] != d[n / 2 + 1])
  {
    c++;
    int k = d[n / 2] + 1;
    int i = n / 2 + 1;
    while (d[i] != k)
    {
      k++;
      c++;
    }
  }

  cout << c << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
using namespace std;

int main(){
    char ch;
    while(1){
        scanf("%c", &ch);
        if ('a' <= ch && ch <= 'z'){
            printf("%c", ch - 32);
        } else if ('A' <= ch && ch <= 'Z'){
            printf("%c", ch + 32);
        } else{
            printf("%c", ch);
        }
        if ( ch == '\n' ) break;
    }
    return 0;
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int dfs(const vvi& qs,int u,vi& deps,vi& ps)
{
	if(deps[u]==-1){
		int d=-1,p=-1;
		for(int v:qs[u]){
			int t=dfs(qs,v,deps,ps);
			if(d<t)
				d=t,p=v;
		}
		deps[u]=d+1;
		ps[u]=p;
	}
	return deps[u];
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,m;cin>>n>>m&&n|m;){
		vi us(n-1+m),vs(n-1+m);
		vi degs(n);
		vvi qs(n);
		rep(i,n-1+m){
			cin>>us[i]>>vs[i]; us[i]--,vs[i]--;
			degs[us[i]]++;
			qs[vs[i]].push_back(us[i]);
		}
		vi deps(n,-1),ps(n,-1);
		rep(i,n) if(degs[i]==0)
			dfs(qs,i,deps,ps);
		rep(i,n)
			cout<<ps[i]+1<<endl;
	}
}


Measured memory_bytes: 17664
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
int lcm(int a, int b){return a*b / gcd(a, b);}

int main(){
    ll a, b, c;
    cin >> a >> b >> c;

    if(a%2 == 0 || b%2 == 0 || c%2 == 0){
        cout << 0 << endl;
    }
    else{
        cout << min(a*b, min(b*c, c*a)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  (_,as,bs) <- readParams
  print $ solve as bs

readParams :: IO (Int,[Int],[Int])
readParams = do
  n <- readLn
  as <- readInts
  bs <- readInts
  return (n,as,bs)

readInts :: IO [Int]
readInts = map b2int . B.words <$> B.getLine
  where b2int = fst . fromJust . B.readInt

solve :: [Int] -> [Int] -> Int
solve = solve' 0

solve' :: Int -> [Int] -> [Int] -> Int
solve' n _ [] = n
solve' n (x:y:ys) (z:zs)
  | x < z     = solve' (n+x+rest) (y-rest:ys) zs
  | otherwise = solve' (n+z) (y:ys) zs
  where rest = min y (z-x)


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;cin >> h >> w;
	vector<string> s(h);
	vector<vector<bool>> memo(h,vector<bool>(w));
	rep(i,h) cin >> s.at(i);
	ll ans=0;
	rep(i,h){
		rep(j,w){
			if(!memo[i][j]){
				queue<pii> q;
				q.push(mp(i,j));
				ll cntw=0,cntb=0;
				memo[i][j]=true;
				while(!q.empty()){
					pii cur=q.front();
					q.pop();
					if(s[cur.first][cur.second]=='.') cntw++;
					else cntb++;
					if(cur.first>0 && !memo[cur.first-1][cur.second] && s[cur.first][cur.second]!=s[cur.first-1][cur.second]){
						q.push(mp(cur.first-1,cur.second));
						memo[cur.first-1][cur.second]=true;
					}
					if(cur.first<h-1 && !memo[cur.first+1][cur.second] && s[cur.first][cur.second]!=s[cur.first+1][cur.second]){
						q.push(mp(cur.first+1,cur.second));
						memo[cur.first+1][cur.second]=true;
					}
					if(cur.second>0 && !memo[cur.first][cur.second-1] && s[cur.first][cur.second]!=s[cur.first][cur.second-1]){
						q.push(mp(cur.first,cur.second-1));
						memo[cur.first][cur.second-1]=true;
					}
					if(cur.second<w-1 && !memo[cur.first][cur.second+1] && s[cur.first][cur.second]!=s[cur.first][cur.second+1]){
						q.push(mp(cur.first,cur.second+1));
						memo[cur.first][cur.second+1]=true;
					}
				}
				ans+=cntw*cntb;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		boolean result = true;
		for (int i = 0; i < N; i++) {
			int A = sc.nextInt();
			if(A % 2 ==0 && (A % 3 !=0 && A % 5 !=0)) {
				result = false;
			}
		}
		if(result) {
			System.out.println("APPROVED");
		} else {
			System.out.println("DENIED");
		}
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private int H;
    private int W;
    private int N;
    private int[] a;

    public Main() {
	H = Integer.parseInt(scan.next());
	W = Integer.parseInt(scan.next());
	N = Integer.parseInt(scan.next());
	a = new int[N];
	for (int i = 0; i < N; i++) {
	    a[i] = Integer.parseInt(scan.next());
	}
	scan.close();
    }

    public final void answer() {
	int[] number = new int[H*W];
	int index = 0;
	for (int i = 0; i < N; i++) {
	    for (int j = 0; j < a[i]; j++) {
		number[index] = i+1;
		index++;
	    }
	}

	StringBuilder str = new StringBuilder();
	for (int h = 0; h < H; h++) {
	    for (int w = 0; w < W; w++) {
		if(h%2 == 0) {
		    str.append(number[h*W + w]);
		} else {
		    str.append(number[(h+1)*W -1 - w]);
		}

		if(w < W-1) str.append(' ');
	    }
	    str.append('\n');
	}

	System.out.println(str.toString());
    }
}


Measured memory_bytes: 27952