akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n, k;
	int num = 0;
	int maximum = 1;
	vector<int> a, b, c;
	
	cin>>n>>k;
	
	a.resize(n+1);
	
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	
	for(int i = 1; i <= n; i++){
		vector<int> lis;
		for(int j = i; j < a[i]; j++){
			if(a[j] < a[i]) continue;
			
			if(lis.size() == 0 || lis.back() < a[j]) lis.push_back(a[j]);
			else {
				int it = lower_bound(lis.begin(), lis.end(), a[j]) - lis.begin();
				lis[it] = a[j];
			}
		}
		maximum = max((int)lis.size(), maximum);
	}
	
	cout<<min(maximum + k, n/2)<<endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> t(n),a(n);
  for(int i = 0; i < n; i++)
    cin >> t[i] >> a[i];
  long long p = 1, q = 1;
  // cout << p << ", " << q << endl;
  for(int i = 0; i < n; i++){
    long long s1 = p + q;
    long long s2 = t[i] + a[i];
    if(s1 <= s2){
      if(p <= t[i] && q <= a[i]){
        p = t[i], q = a[i];
      } else if ( p > t[i] ){
        q = a[i] * ((p-1) / t[i] + 1);
        p = t[i] * ((p-1) / t[i] + 1);
      } else {
        p = t[i] * ((q-1) / a[i] + 1);
        q = a[i] * ((q-1) / a[i] + 1);
      }
    }else{
      // long long s3 = s2 * ((s1-1) / s2 + 1);
      long long pp = t[i] * ((s1-1) / s2 + 1);
      long long qq = a[i] * ((s1-1) / s2 + 1);
      if(p <= pp && q <= qq){
        p = pp, q = qq;
      } else if ( p > pp ){
        q = a[i] * ((p-1) / t[i] + 1);
        p = t[i] * ((p-1) / t[i] + 1);
      } else {
        p = t[i] * ((q-1) / a[i] + 1);
        q = a[i] * ((q-1) / a[i] + 1);
      }
    }
    // cout << p << ", " << q << endl;
  }
  cout << p + q << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long gcd(long x,long y){
    long t;
    while(y!=0){
        t=x%y;x=y;y=t;
    }
    return x;
}

int main(){
    unsigned int k;
    unsigned int e=0;
    scanf("%d",&k);
    for(unsigned int i=1;i<=k;i++)for(unsigned int j=1;j<=k;j++)for(unsigned int l=1;l<=k;l++){
        e+=gcd(gcd(i,j),l);
    }
    printf("%d",e);
    return 0;
}


Measured memory_bytes: 3760
package main

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

func main() {
	S := nextString()
	m := map[rune]struct{}{'a': struct{}{}, 'b': struct{}{}, 'c': struct{}{}}
	for _, s := range S {
		delete(m, s)
	}
	if len(m) == 0 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>

int main()

{
    int N,M,a=0,b=0;
    scanf("%d %d",&N,&M);
    if(N<2&&M<2)
    {
        printf("0\n");
    }
    else
    {
        if(N>=2)
            a=(N*(N-1))/2;
        if(M>=2)
            b=(M*(M-1))/2;
            printf("%d\n",a+b);
    }
    return 0;
}



Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
        int n, a, b, p1, p2, x;

        var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);

            if (a * n < b)
                x = a * n;
            else
                x = b;

            Console.WriteLine(x);
            Console.ReadKey();
      
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
ll gcd(ll a,ll b){return a?gcd(b%a,a):b;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> B;
	cout << lcm(A, B) << endl;
}







Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)

typedef long double ld;

typedef complex<ld> P;
typedef vector<P> VP;
const ld eps = 1e-8, pi = acos(-1.0);

struct L { P a, b; };//二点の情報をもつ

//内積 |a||b|cosθ θはaからbに反時計周りにとる
ld dot (P a, P b) { return real(conj(a) * b); }
//外積 |a||b|sinθ θはaからbに反時計周りにとる
ld cross (P a, P b) { return imag(conj(a) * b); }


int ccw (P a, P b, P c) {
  b -= a; c -= a;//原点中心に考えている
  if (cross(b, c) > eps) return 1;   //0<θ<180 // counter clockwise
  if (cross(b, c) < -eps) return -1; //180<θ<360 clockwise
  //上のどちらでもないなら線上にある
  if (dot(b, c) < 0) return 2;       //θ=180// c--a--b on line
  //以下θ=0
  if (norm(b) < norm(c)) return -2;  // a--b--c on line
  return 0;                          // a--c--b on line
}


bool isis_ss(L s, L t) {
 //二つの線分が互いに,「片方の線分の方向ベクトルに対して,もう片方の線分の頂点が反対側にある」という関係であれば交点をもつ.
 //点が一致していてもよいので=0も含む
  return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

int main() {
  int q;
  ld x0, y0, x1, y1, x2, y2, x3, y3;
  cin >> q;
  REP(i,q) {
    cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    L seg1 = (L){P(x0, y0), P(x1, y1)}, seg2 = (L){P(x2, y2), P(x3, y3)};
    if (isis_ss(seg1, seg2)) cout << 1 << endl;
    else cout << 0 << endl;
  }
  return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, l;
	cin >> n >> l;
	ll sum = ((l + (l+n-1)) * n)/2;
	ll ans;
	if (l >= 0){ ans = sum - l; }
	else if (n+l > 0){ ans = sum; }
	else { ans = sum - (l+n-1); }
	cout << ans << endl;
}

Measured memory_bytes: 256
A,B,C=map(int,input().split())

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 998244353
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

i=0
ans=0
while i<=C:
    ans+=B*pow(B-1,A-1-i,p)*cmb(A-1,i,p)
    i+=1

ans=ans%p
print(ans)

Measured memory_bytes: 128088
/***** author :  C0d1ngPhenomena *****/

    #include <bits/stdc++.h>
    #define endl "\n"
    #define ll long long int
    #define TestCases int T; cin>>T; while(T--)
    #define rep(i,n) for(ll i = 0; i < n; i++)
    #define revrep(i,n) for(ll i = n-1; i >= 0; i--)
    #define vll vector<ll>
    #define vvll vector < vll >
    #define pll pair<ll, ll>
    #define vpll vector <pll>
    #define mp(x,y) make_pair(x,y)
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define alld(c) c.begin(),c.end(),greater<int>()
    #define mem(a,val) memset(a,val,sizeof(a))
    #define f first
    #define s second
    #define pb push_back
    using namespace std;
    
    bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
    {
        return (a.second < b.second);
    }




    
    int main()
    {
        std::ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
       
        ll l,r,d;
        cin >> l >> r >> d;
        ll counta = 0;
        for (int i = l; i <= r; ++i)
        {
        	if(i%d == 0)
        		counta++;

        }
        cout << counta;
        return 0;
    }







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

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

    int ans = 0;
    cout << N*N*N << endl;
}


Measured memory_bytes: 384
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	string S;
	cin >> S;
	int res = 15 - S.size();
	for (char c : S)if (c == 'o')res++;
	cout << (res >= 8 ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input().split()
S_i = [int(s) for s in S]
tmp_result = 0

for num_i in S_i:    
    for num_ii in S_i:
        difference = abs(num_i - num_ii)
        if difference > tmp_result:
            tmp_result = difference
    
print(tmp_result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while(cin >> n and n) {
        vector<int> counter, color;
        for(int i = 1; i <= n; i++) {
            int c;
            cin >> c;
            if(i % 2) {
                if(color.empty() or color.back() != c) {
                    counter.push_back(1);
                    color.push_back(c);
                } else {
                    counter.back()++;
                }             
            } else {
                if(color.back() == c) {
                    counter.back()++;
                } else {
                    int x = counter.back();
                    counter.pop_back();
                    color.pop_back();
                    if(counter.empty()) {
                        counter.push_back(x + 1);
                        color.push_back(c);
                    } else {
                        counter.back() += x + 1;
                    }
                }
            }
        }
        int ans = 0;
        for(int i = 0; i < color.size(); i++) {
            if(not color[i]) {
                ans += counter[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

int n;
int ans=0;
string tfs[]={"3","5","7"};

void dfs(string s){
    vector<bool> f(3,false);
    rep(i,s.size()){
        if(s[i]=='3'){
            f[0]=true;
        }else if(s[i]=='5'){
            f[1]=true;
        }else if(s[i]=='7'){
            f[2]=true;
        }
    }
    if(f[0]&&f[1]&&f[2]){
        ans++;
    }
    rep(i,3){
        string t=s+tfs[i];
        if(stol(t)<=n){
            dfs(t);
        }
    }
}

int main(){

    cin >> n;
    dfs("");

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,w,p,q;
    ans=0;
    int a[3][3],b[3][3];
    rep(i,0,3){
        rep(j,0,3){
        cin>>b[i][j];
        a[i][j]=0;
        }
    }
    cin>>n;
    rep(i,0,n){
        cin>>p;
        rep(j,0,3){
            rep(k,0,3){
                if(b[j][k]==p)
                a[j][k]=1;
            }
        }
    }
    rep(i,0,3){
        if(a[i][0]*a[i][1]*a[i][2]==1||a[0][i]*a[1][i]*a[2][i]==1){
        cout<<"Yes"<<endl;
        return 0;
        }
    }
    if(a[0][0]*a[1][1]*a[2][2]==1||a[2][0]*a[1][1]*a[0][2]==1)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define all(c) c.begin(), c.end()
#define pb push_back
#define ll long long
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll k;
  cin >> k;
  ll s = 0;
  for (ll i = 1; i <= k; i++)
    for (ll j = 1; j <= k; j++)
      for (ll c = 1; c <= k; c++)
        s += __gcd(i,__gcd(j,c));
  cout << s;
  return 0;
}

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

int main()
{
    long int p,q;
    cin>>p;
    vector<long int>v(p);
    for(long int i=0;i<p;i++){
        cin>>q;
        v[i]=q;
    }
    sort(v.begin(),v.end());
    long int diff=v[p/2]-v[(p/2)-1];
    cout<<diff;
    
}



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

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

  if (N == 100) N = N + 1;

  int a;
  a = 1;
  rep(i, D) a *= 100;

  cout << N * a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

char a[800][801];
int d[800][800];
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
signed main() {
	int h, w, k; scanf("%d%d%d", &h, &w, &k);
	int sx, sy;
	rep(i, h) {
		scanf("%s", a[i]);
		rep(j, w) {
			if (a[i][j] == 'S')sx = i, sy = j;
		}
	}
	queue<P>que;
	memset(d, -1, sizeof(d));
	d[sx][sy] = 0; que.push(P(sx, sy));
	while (!que.empty()) {
		P p = que.front(); que.pop();
		rep(i, 4) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&d[nx][ny] == -1 && a[nx][ny] != '#') {
				d[nx][ny] = d[p.first][p.second] + 1;
				if (d[nx][ny] < k)que.push(P(nx, ny));
			}
		}
	}
	int Min = INF;
	rep(i, h)rep(j, w) {
		if (d[i][j] != -1) {
			int c = min({ i, h - i - 1,j, w - j - 1 });
			Min = min(Min, c / k + (c%k > 0) + 1);
		}
	}
	printf("%d\n", Min);
}

Measured memory_bytes: 3328
import random

s = list(map(int, input().split()))
# s[0] = 夏休みの日数
# s[1] = 宿題の個数
a = list(map(int, input().split()))

N = s[1]

if s[0]-sum(a) >= 0:
  print(s[0]-sum(a))
else:
  print("-1")

Measured memory_bytes: 10336
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n,m,l;
    scanf("%d %d %d",&n,&m,&l);
    int A[n][m],B[m][l];
    long long int C[n][l];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            C[i][j] = 0;
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            scanf("%d",&B[i][j]);
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int k = 0; k < l; k++){
            for(int j = 0; j < m; j++){
                C[i][k] += A[i][j]*B[j][k];
            }
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l-1; j++){
            printf("%lld ",C[i][j]);
        }
        printf("%lld\n",C[i][l-1]);
    }
}


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

#define int long long
#define double long double

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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; }

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    
    string s; cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba")
    {
        cout << -1 << endl;
        return 0;
    }

    vb used(26, false);
    REP(i, s.length()) used[s[i]-'a'] = true;

    if(s.length() < 26)
    {
        REP(i, 26)
        {
            if(used[i] == false)
            {
                cout << s + (char)('a'+i) << endl;
                return 0;
            }
        }
    }
    
    int c = 1;
    for(int i = s.length()-1; i >= 0; i--)
    {
        for(int j = s[i]-'a'+1; j < 26; j++)
        {
            if(used[j] == false)
            {
                cout << s.substr(0, s.length()-c) + (char)('a'+j) << endl;
                return 0;
            }
        }
        c++;
        used[s[i]-'a'] = false;
    }
}

Measured memory_bytes: 256
n,k,q = map(int,input().split())
score = [0 for _ in range(n+1)]
for i in range(q):
    next = int(input())
    score[next]+=1
for i in range(1,n+1):
    cur = k-q+score[i]
    if(cur>0):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 4704
// Aizu 0215: Pachimon Creature
// 2017.9.9 bal4u@uu

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

#define abs(a)  ((a)>=0?(a):-(a))
#define INF 0x7fffffff
#define MAX 50000
typedef struct { int t, r, c, k; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
  int l, r;
  int smallest;

  l = LEFT(i), r = RIGHT(i);
  if (l < qsize && que[l].t < que[i].t) smallest = l; else smallest = i;
  if (r < qsize && que[r].t < que[smallest].t) smallest = r;
  if (smallest != i) {
    QUE t = que[i]; que[i] = que[smallest]; que[smallest] = t;
    min_heapify(smallest);
  }
}

int deq(int *r, int *c, int *k)
{
  if (qsize == 0) return 0;
  *r = que[0].r, *c = que[0].c, *k = que[0].k;
  que[0] = que[--qsize];
  min_heapify(0);
  return 1;
}

void enq(int r, int c, int t, int k)
{
  int i, ii;

  i = qsize++;
  que[i].r = r, que[i].c = c, que[i].t = t, que[i].k = k;
  while (i > 0 && que[ii = PARENT(i)].t > que[i].t) {
    QUE tt = que[i]; que[i] = que[ii]; que[ii] = tt;
    i = ii;
  }
}

typedef struct { int r, c; } TBL;
TBL start, goal, tbl[5][1002]; int len[5];
int node[1002][1002][5];
char map[1002][1002]; int w, h;

int search(int item)
{
	int r, c, r2, c2, i, k, fin, f, f2;
	TBL *tp;

	qsize = 0;
	memset(node, -1, sizeof(node));
	fin = (item + 4) % 5;
	node[start.r][start.c][item] = 0;
	enq(start.r, start.c, 0, item);
	while(deq(&r, &c, &f)) {
		if (r == goal.r && c == goal.c) continue;
		f2 = f + 1; if (f2 >= 5) f2 = 0;
		if (f == fin) {
			r2 = goal.r, c2 = goal.c;
			k = node[r][c][f] + abs(r2 - r) + abs(c2 - c);
			if (node[r2][c2][f] < 0 || k < node[r2][c2][f]) node[r2][c2][f] = k, enq(r2, c2, k, f);
		} else for (tp = tbl[f2], i = 0; i < len[f2]; i++, tp++) {
			r2 = tp->r, c2 = tp->c;
			k = node[r][c][f] + abs(r2 - r) + abs(c2 - c);
			if (node[r2][c2][f2] < 0 || k < node[r2][c2][f2]) node[r2][c2][f2] = k, enq(r2, c2, k, f2); 
		}
	}
	return node[goal.r][goal.c][fin];
}

int main()
{
	int r, c, s, g, i, ii, ans;

	while (scanf("%d%d", &w, &h) && w) {
		for (r = 0; r < h; r++) scanf("%s", map[r]);
		memset(len, 0, sizeof(len));
		for (s = g = r = 0; r < h; r++) for (c = 0; c < w; c++) {
			char cc = map[r][c];
			if      (cc == 'S') start.r = r, start.c = c, s = 1;
			else if (cc == 'G') goal.r = r, goal.c = c, g = 1;
			else if (cc >= '1' && cc <= '5') {
				cc -= '1';
				tbl[cc][len[cc]].r = r, tbl[cc][len[cc]].c = c, len[cc]++;
			}
		}
		if (!s || !g) { puts("NA"); continue; }
		for (ans = -1, i = 0; i < 5; i++) {
			int k = search(i);
			if (k < 0) continue;
			if (ans < 0 || k < ans) ans = k, ii = i;
		}
		if (ans < 0) puts("NA");
		else printf("%d %d\n", ii+1, ans);
	}
	return 0;
}

Measured memory_bytes: 22516
#include<bits/stdc++.h>
using namespace std;
string s="CODEFESTIVAL2016";
string a;
long long ans;
int main(){
    cin>>a;
    if(a[0]!='C') ans++;
    if(a[1]!='O') ans++;
    if(a[2]!='D') ans++;
    if(a[3]!='E') ans++;
    if(a[4]!='F') ans++;
    if(a[5]!='E') ans++;
    if(a[6]!='S') ans++;
    if(a[7]!='T') ans++;
    if(a[8]!='I') ans++;
    if(a[9]!='V') ans++;
    if(a[10]!='A') ans++;
    if(a[11]!='L') ans++;
    if(a[12]!='2') ans++;
    if(a[13]!='0') ans++;
    if(a[14]!='1') ans++;
    if(a[15]!='6') ans++;
    cout<<ans<<endl;
}

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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  
  vector<int> kouyaku(100);
  int count = 0;
  for(int i = 1; i <= 100; i++){
  	if(a % i == 0 && b % i == 0){
      kouyaku[count] = i;
      count++;
    }
  }
  
  cout << kouyaku[count - k] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  int x=0;
  int mod = a%b;
  for(;;){
    x += a;
    if(x % b == c){
      cout << "YES" << endl;
      break;
    }
    if(x != a && x%b == mod){
      cout << "NO" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int l=0, r=n/2;
    int ans=0;
    while(l<=r){
        int d=(l+r)/2;
        bool found=false;
        for(int i=0; i+d<n; ++i){
            string t=s.substr(i, d);
            if(s.find(t, i+d)!=string::npos){
                found=true;
                break;
            }
        }
        if(found){
            ans=max(ans, d);
            l=d+1;
        } else
            r=d-1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# 再帰関数を使うとTLEになるので、3重ループにしてみる。
from collections import defaultdict

N = int(input())
A = list(map(int,input().split()))

sushi = [0,0,0]
for a in A:
  sushi[a-1] += 1

# dp[i][j][k]:寿司3個のお皿がi枚、2個のがj枚、1個がk枚のときの期待値
# dp[i][j][k] = i/N * dp[i-1][j+1][k]
#             + j/N * dp[i][j-1][k+1]
#             + k/N * dp[i][j][k-1]
#             + (N-i-j-k)/N * dp[i][j][k]
#             + 1
# dp[i][j][k]を移項すると、
# dp[i][j][k] = 1/(i+j+k) * (i * dp[i-1][j+1][k]
#                          + j * dp[i][j-1][k+1]
#                          + k * dp[i][j][k-1]
#                          + N)
dp = [[[0.0 for _ in range(N+1)] for _ in range(N+1)] for _ in range(N+1)] # 型推論で時間がかからないように0ではなく0.0とする。

for i in range(N+1):
  for j in range(N+1):
    for k in range(N+1):
      if i+j+k > N or i+j+k == 0:
        continue
      if i>0:
        dp[i][j][k] += i * dp[i-1][j+1][k]
      if j>0:
        dp[i][j][k] += j * dp[i][j-1][k+1]
      if k>0:
        dp[i][j][k] += k * dp[i][j][k-1]
      dp[i][j][k] += N
      dp[i][j][k] /= (i+j+k)

print(dp[sushi[2]][sushi[1]][sushi[0]])

Measured memory_bytes: 261004
program shift_only
  implicit none
  integer :: n, a(200) = 0, i
  read(*,*) n
  read(*,*) a(1:n)
  do i = 0, 31
    if (any(btest(a(1:n), 0))) then
      write(*,'(i0)') i
      stop
    end if
    a(1:n) = rshift(a(1:n), 1)
  end do
end program shift_only

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


  
int main(){
  

  int N;
  cin >> N  ;
  if (N >= 65 && N <= 90){
    cout << "1\n";
  }else  if (N>=97 && N<=122){
  cout << "2\n"; }
  else {
    cout << "0\n";
  }
 return 0;
}


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

int main() {
  vector<int> C(3);
  cin >> C[0] >> C[1] >> C[2];
  
  sort(C.begin(), C.end());
  
  if (C[0] + C[1] == C[2]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

static const int MAX_N = 1000;

//int n, m, k[MAX_N];
//int kk[MAX_N * MAX_N];


int main () {
    int k, s;
    cin >> k >> s;
    
    vector<int> Zs(k + 1);

    for (int i = 0; i <= k; i++) {
        Zs[i] = i;
    }

    int cnt = 0;
    for (int x = 0; x <= k; x++) {
        for(int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (binary_search(Zs.begin(), Zs.end(), z)) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

class node {
public:
	int parent,children[2],depth,height,sib;
	node() {
		parent = -1;
		children[0] = -1;
		children[1] = -1;
		depth = -1;
		height = -1;
		sib = -1;
	}
	int deg() {
		int c = 0;
		for(int i=0;i<2;i++)if(children[i]!=-1)c++;
		return c;
	}
	string typ() {
		if(parent == -1)return "root";
		else if(deg() == 0)return "leaf";
		else return "internal node";
	}
};

int n;
node d[100000];

int dfs(int ind,int dep){
	int h = -1;
	for(int i = 0;i < 2;i++) {
		int y = d[ind].children[i];
		if (y == -1)continue;
		d[y].parent = ind;
		d[y].depth = dep+1;
		d[y].height = dfs(y,dep+1);
		h = max(h,d[y].height);
	}
	return h + 1;
}

int main(void) {
	cin >> n;
	for(int i = 0;i < n;i++){
		int a,b,c;
		cin >> a >> b >> c;
		d[a].children[0] = b;
		d[a].children[1] = c;
		d[b].sib = c;
		d[c].sib = b;
		d[b].parent = a;
		d[c].parent = a;
	}
	int rt = -1;
	for(int i = 0;i < n;i++){
		if(d[i].parent == -1) {
			rt = i;
		}
	}
	d[rt].depth = 0;
	d[rt].height = dfs(rt,0);
	for(int i = 0;i < n;i++){
		cout << "node " << i << ": parent = " << d[i].parent << ", sibling = " << d[i].sib << ", degree = " << d[i].deg() << ", depth = " << d[i].depth << ", height = " << d[i].height << ", " << d[i].typ() << endl;
	}
}



Measured memory_bytes: 5548
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  if (B%A==0) {
    cout << A+B << endl;
  }
  else {
    cout << B-A << endl;
  }
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<vector<LL>> a;
  vector<LL> dp, score;
  Solver(LL n) : n(n), a(n, vector<LL>(n)), dp((1 << n), -LINF), score(1 << n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        for (int mask = 0; mask < (1 << n); ++mask) {
          if (((mask >> i) & 1) && ((mask >> j) & 1)) {
            score[mask] += a[i][j];
          }
        }
      }
    }
    dp[0] = 0;
    for (int mask = 0; mask < (1 << n); ++mask) {
      if (mask & 1) {
        dp[mask] = score[mask];
      }
    }
    for (int i = 1; i < n; ++i) {
      for (int mask = 0; mask < (1 << n); ++mask) {
        if (!((mask >> i) & 1)) {
          for (int k = (1 << i); k < (1 << n); k += (1 << (i + 1))) {
            if ((mask & k) == 0) {
              dp[mask | k] = max(dp[mask | k], dp[mask] + score[k]);
            }
          }
        }
      }
    }
    cout << dp[(1 << n) - 1] << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(void)
{
        int k, s;
        int x, y;
        int p = 0;

        scanf("%d %d", &k, &s);
        for (x = 0; x <= ((k < s) ? k : s); x++) {
                for (y = 0; y <= ((k < s - x) ? k : s - x); y++) {
                        p += (k >= s - x - y) ? 1: 0;
                }
        }
        printf("%d\n", p);
        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,flag=0,a;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a%2==0)
			if(a%3==0||a%5==0)
				continue;
			else
				flag=1;
	}
	if(flag==1)
		puts("DENIED");
	else
		puts("APPROVED");
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import bisect


# def getNearestIndexOf(query: int, s: "List[int]"):
#     findTarget = s
#     while len(findTarget) != 1:
#         if len(findTarget) == 2:
#             if abs(findTarget[0] - query) < abs(findTarget[1] - query):
#                 findTarget = [findTarget[0]]
#             else:
#                 findTarget = [findTarget[1]]
#             continue
#         middle = int(len(findTarget)/2)
#         if findTarget[middle] > query:
#             findTarget = findTarget[0:middle + 1]
#         else:
#             findTarget = findTarget[middle:]
#     #print(f"▫️{query} from {s} -> {findTarget[0]}")
#     return findTarget[0]


# def getCostByOrder(begin: int, s: "List[int]", t: "List[int]"):
#     nc = 0
#     nx = bisect.b
#     nc += abs(nx-begin)
#     nx2 = getNearestIndexOf(nx, s)
#     nc += abs(nx2 - nx)
#     return nc


def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    s = [-1 * 10**18] + s + [10**18]
    t = [-1 * 10**18] + t + [10 ** 18]
    for query in x:
        nearS = bisect.bisect_right(s, query)
        nearT = bisect.bisect_right(t, query)
        res = 10 ** 18
        for S in [s[nearS - 1], s[nearS]]:
            for T in [t[nearT - 1], t[nearT]]:
                d1 = abs(T - query) + abs(T - S)
                d2 = abs(S - query) + abs(T - S)
                res = min(res, d1, d2)
        print(res)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    s = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    t = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(A, B, Q, s, t, x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18348
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
//#define endl '\n'  
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1e9+7;
const ll inf=1e15+5;
const ll N=700+10;
bool graph[N][N];
bool visited[N];
int n,m;
bool is_valid=1;
std::vector<pair<int,int> > bipartate;
std::vector<int> clr(N,-1);
void dfs(int node,bool flag)
{
	visited[node]=1;
	clr[node]=flag;
	if(flag) bipartate.back().ss++;
	else bipartate.back().ff++;
	for(int i=0;i<n;i++)
	{
		if(visited[i]==0 and not graph[node][i] and i!=node) dfs(i,!flag); 
		else
		{
			if(visited[i]==1 and not graph[node][i] and i!=node)
			{
				if(clr[i]==(int)flag) is_valid=0;
			}
		}
	}

}
int main()
{
	boost;
	cin>>n>>m;
	is_valid=1;
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		graph[a][b]=1;
		graph[b][a]=1;
	}
	for(int i=0;i<n;i++)
	{

		if(visited[i]==0) 
		{
			bipartate.pb(mp(0,0));
			dfs(i,0);

		}
	}
	if(!is_valid)
	{
		cout<<"-1";
		return 0;
	}
	std::vector<bool> posi(N,0),prev;
	posi[0]=1;
	for(auto &temp : bipartate)
	{
     	int a=temp.ff,b=temp.ss;
		prev=posi;
		fill(all(posi),0);
		for(int i=0;i<=n;i++)
		{
			if(prev[i] and (i+a)<=n) posi[i+a]=1;
			if(prev[i] and (i+b)<=n) posi[i+b]=1;
		}
	}
	ll a=n/2;
	while(posi[a]==0 ) a--;
	ll b=n-a;
	cout<<(a*a+b*b-a-b)/2;

	return 0;
} 


Measured memory_bytes: 768
n = int(input())
s = input()
list1 = []
for counter in range (n+1):
  d = s.count("D",0,counter)
  i = s.count("I",0,counter)
  number = i-d
  list1.append(number)

if max(list1) <=0:
  print(0)
else:
  print(max(list1))

Measured memory_bytes: 3060
N, M, K = map(int, input().split())
if K % N == 0 or K % M == 0:
    print('Yes')
    exit()
candidates = set()
for i in range(1, N):
    curr = i * M
    for j in range(1, M):
        curr += N - 2 * i
        candidates.add(curr)
print('Yes') if K in candidates else print('No')


Measured memory_bytes: 20804
#include<stdio.h>
int main()
{
	int a,b,x,y,B,t;
	scanf("%d %d %d %d",&a,&b,&x,&y);
	
	if(a>b) t=b;
	if(a<=b) t=a;
	if(x>y) B=y;
	if(x<=y) B=x;
	
	
    printf("%d\n",B+t);
  
	return 0;
}

Measured memory_bytes: 2128
N, M = map(int, input().split())
H = list(map(int, input().split()))
ND = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  ND[a-1] += [b-1]
  ND[b-1] += [a-1]
#
y = 0
for i in range(N):
  m = 0
  for j in ND[i]:
    m = max(m, H[j])
  if m < H[i]:
    y += 1
#
print(y)


Measured memory_bytes: 29432
///
// File:  alds1_9_a.cpp
// Author: ymiyamoto
//
// Created on Sun Oct 15 22:39:25 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

#define NIL INT64_MAX

static vector<int64_t> array;

int64_t parent(uint32_t index)
{
  if (index == 1) return NIL;

  return array[index / 2 - 1];
}

int64_t left(uint32_t index)
{
  int32_t left_key = index * 2;
  if (left_key - 1 < (int32_t)array.size()) {
    return array[left_key - 1];
  } else {
    return NIL;
  }
}

int64_t right(uint32_t index)
{
  int32_t right_key = index * 2 + 1;
  if (right_key - 1 < (int32_t)array.size()) {
    return array[right_key - 1];
  } else {
    return NIL;
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    int64_t val;
    cin >> val;
    array.push_back(val);
  }

  for (uint32_t i = 1; i <= array.size(); i++) {
    cout << "node " << i << ": key = " << array[i - 1] << ", ";
    if (parent(i) != NIL) {
      cout << "parent key = " << parent(i) << ", ";
    }
    if (left(i) != NIL) {
      cout << "left key = " << left(i) << ", ";
    }
    if (right(i) != NIL) {
      cout << "right key = " << right(i) << ", ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3116
$c=<>=~$";($\+=($_[$_-1]-$_[-$_])*$c)%=$%=1e9+7,$c=$c*$_%$%*($i[$j]=($%/++$j|0)*-$i[$%%$j]%$%||1)%$%for$'..(@_=sort{$a-$b}glob<>);print

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

static const int MAX = 200000;

int main() {
	int R[MAX], n, maxv, minv;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> R[i];
	}
	maxv = -2000000000;
	minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max( maxv, R[i]-minv );
		minv = min( minv, R[i]);
	}
	cout << maxv << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3848
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll a,b;
    cin>>a>>b;
    if(a>b) swap(a,b);
    if(a==1){
        if(b==2) cout<<3<<endl;
        else if(b==3) cout<<2<<endl;
    }
    else if(a==2){
        if(b==3) cout<<1<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll x;
	cin >> x;

	ll n = x % 100;
	ll n2 = x / 100;

	if (n2 * 5 < n) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

typedef struct node {
  i32 s, t;
} node;

int cmp (const void *a, const void *b) {
  i32 d = ((node *)a)->t - ((node *)b)->t;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  node *p = (node *) calloc (n, sizeof (node));
  for (i32 i = 0; i < n; ++i) {
    i32 s, t;
    scanf ("%" SCNi32 "%" SCNi32, &s, &t);
    p[i] = (node) {s, t};
  }
  qsort (p, n, sizeof (node), cmp);
  i32 ans = 0;
  i32 now = 0;
  for (i32 i = 0; i < n; ++i) {
    if (now < p[i].s) {
      now = p[i].t;
      ans++;
    }
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 2916
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = IR(n)
ans = 0
cur = 0
for i in range(n):
    if not A[i]:
        cur = 0
    else:
        if cur % 2:
            ans += 1
            A[i] -= 1
        ans += A[i] // 2
        cur = A[i] % 2


print(ans)

Measured memory_bytes: 45148
#include <stdio.h>
#include <cmath>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)

bool isPrime(int n) {
    if (n % 2 == 0) return false;
    if (n % 3 == 0) return false;

    for (int i = 5; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int N;
    scanf("%d", &N);
    int a[N];

    int cnt = 0;
    int idx = 0;
    while (idx != N) {
        int temp = ((cnt + 1) * 5) + 1;
        if (isPrime(temp)) {
            a[idx] = temp;
            idx++;
        }
        cnt++;
    }

    REP(i, N - 1) {
        printf("%d ", a[i]);
    }
    printf("%d\n", a[N - 1]);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int ans = 0;
    string s;
    cin >> n;
    cin >> s;
    for (int i = 0; i < n-2; i++)
    {
        if(s[i]=='A' &&s[i+1] == 'B' && s[i+2]=='C'){
            ans++;
        }
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    sort(A.begin(), A.end());
    long long ans = -A[0];
    for (int i = 1; i < N-1; i++) {
        if (A[i] <= 0) ans += -A[i];
        else ans += A[i];
    }
    ans += A[N-1];
    cout << ans << endl;

    long long ma = A[N-1];
    long long mi = A[0];
    for (int i = 1; i < N-1 && A[i] <= 0; i++) {
        cout << ma << " " << A[i] << endl;
        ma -= A[i];
    }
    for (int i = N-2; 0 < i && A[i] > 0; i--) {
        cout << mi << " " << A[i] << endl;
        mi -= A[i]; 
    }
    cout << ma << " " << mi << endl;
}   


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    int D,T,S;
    cin >> D >> T >> S;
    
    if(D <= T*S) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, n;
	scanf("%d%d", &h, &n);
	while(n--) {
		int x;
		scanf("%d", &x);
		h -= x;
	}
	puts(h > 0 ? "No" : "Yes");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define is_bit(x,y) (x%(1<<(y+1))>=(1<<y))
#define eror(x) cout<<#x<<'='<<(x)<<endl;
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(int i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define All(x) x.begin(),x.end()
#define gett(x) scanf("%d",&x);
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=1e5+99;

int n,c,x,mv,ans,res,a[N],b[N],mark[N];
map<int,int> t,tn;
vector<int> g[N];

void dfs(int x){
    mark[x]=1;
    f(i,0,g[x].size())
        if(!mark[g[x][i]])
            dfs(g[x][i]);
    ans+=g[x].size();
}

int main(){
    cin>>n;
    f(i,1,n+1){
        gett(a[i]);
        a[0]^=a[i];
        t[a[i]]++;
    }
    t[a[0]]++;
    f(i,1,n+1){  
        gett(b[i]);
        b[0]^=b[i];
    }
    f(i,0,n+1){
        t[b[i]]--;
        if(t[b[i]]<0)
            return cout<<-1,0;
    }
    f(i,0,n+1){
        if(!tn[a[i]]){
            c++;
            tn[a[i]]=c;
        }
    }
    f(i,0,n+1){
        a[i]=tn[a[i]];
        b[i]=tn[b[i]];
        if(a[i]!=b[i]) g[a[i]].pb(b[i]);
    }
    f(i,1,n+1)
        if(b[i]==a[0] && b[0]==a[0])
            mv=1;
    f(i,1,n+2)
        if(!mark[i] && sz(g[i])){
            res++;
            dfs(i);
        }
    if(ans==0) return cout<<0,0;
    cout<<ans+res-(a[0]!=b[0])*2-mv;
}
            

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

int main(){
   int W,H,x,y,r;
   cin >> W >> H >> x >> y >> r;

   if ((x-r) >= 0 && (x + r) <= W) {
       
        if ((y - r) >= 0 && (y + r) <= H) {
            cout << "Yes" << endl;       
       } else {
        cout << "No" << endl;    
       }   
   } else {
    cout << "No" << endl;    
   }
    return 0;
}

Measured memory_bytes: 1160
n = int(input())
a = [int(input()) for x in range(n)]

copied_arr = a.copy()
max1 = max(a)
copied_arr.remove(max1)
max2 = max(copied_arr)

for x in a:
    if x == max1:
        print(max2)
    else:
        print(max1)


Measured memory_bytes: 14176