akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define HEN_KAZU 3

int main(void)
{

        int i = 0, j = 0, k = 0;
        int n = 0, memo = 0;
        unsigned int hen[HEN_KAZU] = {0, 0, 0};

        scanf("%d",&n);
        for(k = 0; k < n; k++)
        {
                scanf("%d %d %d", &hen[0], &hen[1], &hen[2]);
                for(i = 0; i < HEN_KAZU; i++)
                {
                        for(j = i + 1; j < HEN_KAZU ;j++ )
                        {
                                if(hen[i] > hen[j])
                                {
                                        memo =  hen[i];
                                        hen[i] = hen[j];
                                        hen[j] = memo;
                                }
                        }
                }
                if(hen[2]*hen[2] == (hen[1] * hen[1]) + (hen[0] * hen[0]))
                {
                        printf("YES\n");
                }
                else
                {
                        printf("NO\n");
                }
        }

        return 0;
}

Measured memory_bytes: 580
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
	string s;
	string t;
	cin >> s;
	cin >> t;
	int n = s.size();
	int m = t.size();
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '?') {
			count++;
		}
	}
	if (count == 0) {
		cout << s << endl;
		return 0;
	}
	for (int i = n - m; i >= 0; i--) {
		bool isWrong = false;
		for (int j = 0; j < m; j++) {
			if (s[i + j] != '?' && s[i + j] != t[j]) {
				isWrong = true;
				break;
			}
		}
		if (!isWrong) {
			for (int k = 0; k < n; k++) {
				if (s[k] == '?') {
					if (k < i || k >= i + m) {
						s[k] = 'a';
					} else {
						s[k] = t[k - i];
					}
				}
			}
			cout << s << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int is_prime(int n){
	int i;
	if(n<=1) return 0;
	if(n==2) return 1;
	if(n%2==0) return 0;

	for(i=3;i * i<=n;i+=2)
		if(n%i==0)
			return 0;
	return 1;
}

int main(void){
	int i;
	int n;

	for(;;){
		scanf("%d",&n);
		if(!n)
			break;

		for(i=n;i>=2;i--)
			if(is_prime(i)) 
				if(is_prime(i-2)){
					printf("%d %d\n",i-2,i);
					break;
				}
	}

	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3

N = int(input().split()[0])
x_list = list(map(int, input().split()))

min_cost = float("inf")
for i in range(1, 101):
    t = sum([(x - i) ** 2 for x in x_list])
    min_cost = min(t, min_cost)
ans = min_cost

print(ans)


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

using namespace std;

int main() {
  string S;
  cin >> S;

  int bucket[26];
  fill(bucket, bucket + 26, 0);

  for (unsigned i = 0; i < S.size(); i++) {
    bucket[(int)S[i] - 97] += 1;
  }

  string missed;
  for (int i = 0; i < 26; i++) {
    if (bucket[i] == 0) {
      missed.push_back(char(i + 97));
    }
  }

  sort(missed.begin(), missed.end());

  if (missed.size() > 0) {
    cout << missed[0] << endl;
  } else {
    cout << "None" << endl;
  }
}


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

int main() {
	string s;
    cin >> s;
    string a = "";
    for(int i=0; i<s.size(); i++){
        if(s.at(i) != 'B'){
          a += s.at(i);
        }
        else if(s.at(i) == 'B'){
          if(a != ""){
            int j = a.length()-1;
            a.erase(j);
          }
        }
    }
    cout << a << endl;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int x, y;
    cin >> x >> y;

    bool ok = false;
    if ((y - 2 * x) % 2 == 0 && (4 * x - y) % 2 == 0)
        if (y - 2 * x >= 0 && 4 * x - y >= 0)
            ok = true;

    puts(ok ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var s = consoleReader.String;
            return $"{s[0]}{s.Length - 2}{s[s.Length - 1]}";
        }


        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    static class Ext
    {
        public static Dictionary<TKey, int> GroupCount<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) => source.GroupBy(keySelector).ToDictionary(g => g.Key, g => g.Count());
        public static Dictionary<TKey, int> GroupCount<TKey>(this IEnumerable<TKey> source) => source.GroupCount(i => i);
    }
    public class ConsoleReader { private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); private string[] line = Array.Empty<string>(); private int linePosition; private TextReader textReader; public ConsoleReader(TextReader tr) { textReader = tr; } public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string String { get { if (linePosition >= line.Length) { linePosition = 0; line = ReadLineSplit(); } return line[linePosition++]; } } public class SplitLine { private string[] splited; public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); } public int[] Int => String.Select(x => int.Parse(x)).ToArray(); public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray(); public long[] Long => String.Select(x => long.Parse(x)).ToArray(); public double[] Double => String.Select(x => double.Parse(x)).ToArray(); public string[] String => splited; } public SplitLine Split => new SplitLine(this); public class RepeatReader : IEnumerable<ConsoleReader> { ConsoleReader cr; int count; public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; } public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); public IEnumerable<string> String => this.Select(cr => cr.String); public IEnumerable<int> Int => this.Select(cr => cr.Int); public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1); public IEnumerable<long> Long => this.Select(cr => cr.Long); public IEnumerable<double> Double => this.Select(cr => cr.Double); } public RepeatReader Repeat(int count) => new RepeatReader(this, count); }
    #endregion
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int A,B;
    cin>>A>>B;

    if(A==B){
        cout<<1<<endl;
        return 0;
    }

    int a,b;


    int k;
    for(k=60;;k--)if((A>>k&1)!=(B>>k&1))break;



    vpint v;

    v.pb({A,B});


    a=A+(1ll<<k);
    b=a;
    for(int i=k-1;i>=0;i--)b|=(1ll<<i);

    v.pb({a,b});

    a=A+(1ll<<k);
    for(int i=k-1;i>=0;i--)a^=((a>>i&1)<<i);
    b=B;
    int l=k-1;
    while(l>=0&&(B>>l&1)==0)l--;
    for(int i=l;i>=0;i--)b|=(1ll<<i);

    v.pb({a,b});

    sort(all(v));

    int ans=0;
    for(int i=0;i<3;i++){
        ans+=max(v[i].se-v[i].fi+1,0ll);
        for(int j=i+1;j<3;j++){
            chmax(v[j].fi,v[i].se+1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

N, Q = map(int, input().split())
V = [0] * N
E = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
for _ in range(Q):
    p, x = map(int, input().split())
    V[p-1] += x

stack = deque()
stack.append(0)
ans = [0] * N
ans = V

while stack:
    v = stack.popleft()
    for e in E[v]:
        ans[e] += ans[v]
        stack.append(e)

print(*ans)



Measured memory_bytes: 89904
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

int main() {
    int N; cin >> N;
    for(int i=0; 4*i<=N; i++){
        for(int j=0; 7*j<=N; j++){
            if(4*i + 7*j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n; int ans = 0;
    rep(i,n){
        int x; cin >> x;
        if(i % 2 == 1) continue;
        if(x % 2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int a,b,average,r;
  cin >> a >> b;
  r = (a+b) % 2;
  if (r == 1)
    average = (a + b) / 2 + 1;
  else
    average = (a + b) / 2;
  cout << average << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s[n];
    set<string> ans;
    for(int i=0;i<n;i++){
        cin >> s[i];
        ans.insert(s[i]);
    }
    cout << ans.size();
    return 0;
}

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

int main(){
  int a, b;
  char op;
  while (true){
    cin >> a >> op >> b;
    if (op == '?'){
      break;
    }
    else if (op=='+'){
      cout << a+b << endl;
    }
    else if (op=='-'){
      cout << a-b << endl;
    }
    else if (op=='*'){
      cout << a*b << endl;
    }
    else {
      cout << a/b << endl;
    }

  }
  
}



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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n;cin>>n;
	string s;cin>>s;
	int cnt=0;
	rep(i,s.size()){
		if(s[i]=='R')cnt++;
	}
	int ans=0;
	rep(i,cnt){
		if(s[i]=='W')ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	ll x, y;
	cin>>x>>y;
	for(int i=0; i<105; i++)
	{
		for(int j = 0; j<105; j++)
		{
			if(i+j == x && (2*i + 4*j == y))
			{
				cout<<"Yes\n";
				return;
			}
		}
	}
	cout<<"No\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> bc;
    bc.push_back(s[0] == '#');
    for(int i = 1; i < s.length(); i++){
        int t = bc[i-1];
        if(s[i] == '#'){
            bc.push_back(t+1);
        }
        else{
            bc.push_back(t);
        }
    }
    int mi = n - bc[n-1];
    for(int i = 1; i <= s.length(); i++){
        int t = bc[i-1]+(n-i)-(bc[n-1]-bc[i-1]);
        if(t < mi) mi = t;
    }
    cout << mi << endl;
}

Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007

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

    vector<int>v;
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        v.pb(k);
    }
    sort(v.begin(),v.end());
    ll ans=0;
    for(int i=n-1;i>=0;i--)
    {
        for(int j=i-1;j>=0;j--)
        {
            auto itr=lower_bound(v.begin(),v.end(),v[i]+v[j]);
            ll ng=distance(itr,v.end());
            ans+=(n-1-i)-ng;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3648
# n個のデータを0,...n-1でナンバリング
# 再帰上限に注意
import sys
sys.setrecursionlimit(10**9)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1 for _ in range(n)]

    def find(self, n):
        x = self.parents[n]
        if x < 0:
            return n
        else:
            self.parents[n] = self.find(self.parents[n])
            return self.parents[n]

    def union(self, n, m):
        x = self.find(n)
        y = self.find(m)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x


n, m = map(int, input().split())
U = UnionFind(n)
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    U.union(a, b)

P = U.parents
ans = 0
for p in P:
    if p < 0:
        ans += 1
print(ans-1)


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

using namespace std;

using ll = long long;

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

    array<int, 13> group = {0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
    int x, y;
    cin >> x >> y;

    if (group[x] == group[y]) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


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

#define MAX 100000
#define INF INT32_MAX

int N, A, B;
int h[MAX];

bool enough( long long t )
{
	long long sum = 0;
	long long base = t * B;
	for( int i = 0; i < N; i++ ) {
		if( h[i] > base ) {
			long long d = (h[i] - base) / (A - B);
			if( (h[i] - base) % (A - B) ) {
				d++;
			}
			sum += d;
		}
		else {
			break;
		}
	}
	return sum <= t;
}

long long serch( long long l, long long r )
{
	while( r - l > 1 ) {
		long long m = (r + l) / 2;
		if( enough( m ) ) {
			r = m;
		}
		else {
			l = m;
		}
	}
	return r;
}

int main()
{
	cin >> N >> A >> B;
	for( int i = 0; i < N; i++ ) {
		cin >> h[i];
	}

	sort( h, h + N, greater<int>() );
	long long ans = serch( 0, INF );

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int A, B, C;

int main(int argc, const char * argv[]) {
    A = inputValue();
    B = inputValue();
    C = inputValue();

    output(min(B/A, C));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int64_t N, K, ans = 0;
    cin >> N >> K;
    vector<int64_t> A(N + 1);
    map<int64_t, int64_t> B;
    for (int i = 0; i < N; i++) {
        int64_t a;
        cin >> a;
        if (i == 0) {
            A.at(i + 1) = a - 1;
            continue;
        }
        A.at(i + 1) = A.at(i) + a - 1;
    }
    for (int i = 0; i < N + 1; i++) {
        B[A.at(i) % K]++;
        if (i - K >= 0) {
            B[A.at(i - K) % K]--;
        }
        ans += B[A.at(i) % K] - 1;

    }
    cout << ans << endl;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    for(int i = 1; i <= 9; ++i){
        for(int j = 1; j <= 9; ++j){
            if(N == i * j){
                cout << YES << endl;
                return;
            }
        }
    }
    cout << NO << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3720
#include <stdio.h>

int main(int argc, char *argv[]) {
  int i, j;
  for(i=1; i<10; ++i) {
    for(j=1; j<10; ++j) {
      printf("%dx%d=%d\n", i, j, i*j);
    }
  }
  return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline


N = int(input())
XYP = [list(map(int, input().split())) for _ in range(N)]

INF = 10**18

def scores(Xs):
    L = len(Xs)
    dp = [[INF]*(L+1) for _ in range(L+1)]
    # k = 0
    init = 0
    for x, p in Xs:
        init += abs(x)*p
    if L == 0:
        return [0]
    # k = 1
    for ix, (x, p) in enumerate(Xs):
        dp[ix][0] = init
        score = 0
        for jx, (y, q) in enumerate(Xs):
            score += min(abs(y)*q, abs(x-y)*q)
        dp[ix][1] = score
    
    # k > 1
    for k in range(1, L):
        for ix, (x, p) in enumerate(Xs):
            for iy in range(ix+1, L):
                y, q = Xs[iy]
                tmp = dp[ix][k]
                for iz in range(ix+1, L):
                    z, r = Xs[iz]
                    new = abs(z-y)
                    pre = min(abs(z), abs(z-x))
                    if new < pre:
                        tmp += (new - pre)*r
                dp[iy][k+1] = min(dp[iy][k+1], tmp)
    
    ret = [INF]*(L+1)
    for k in range(L+1):
        for j in range(L+1):
            ret[k] = min(dp[j][k], ret[k])

    return ret

ans = [INF]*(N+1)
for bit in range(1<<N):
    Xs = []
    Ys = []
    for i, (x, y, p) in enumerate(XYP):
        if (1<<i)&bit:
            Xs.append((x, p))
        else:
            Ys.append((y, p))

    Xs.sort()
    Ys.sort()
    dpx = scores(Xs)
    dpy = scores(Ys)
    for i, x in enumerate(dpx):
        for j, y in enumerate(dpy):
            ans[i+j] = min(ans[i+j], x+y)

print(*ans, sep="\n")


Measured memory_bytes: 73784
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	int ans=-n,t;
	while(n--){
		cin>>t;
		ans+=t;
	}
	cout<<ans<<"\n";
	return 0;
}





























Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int w;

    int a=1150;
    int b=125;
    int c=140;
    int d=160;
    int e=4280;
    
    while(true){
    cin>>w;  
    if(w==-1)break;

    else if(w<10) cout<<e-a<<endl;
    else if(w<20) cout<<e-(a+(w-10)*b)<<endl;
    else if(w<30) cout<<e-(a+b*10+(w-20)*c)<<endl;
    else if(30<=w) cout<<e-(a+b*10+c*10+(w-30)*d)<<endl;
    }
    
    
}



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

int main()
{
	ll n, m;
	cin >> n >> m;
	if(n == 1 || m == 1)	puts("1");
	else{
		cout << (n * m + 1) / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 100;
long long arr[N],l[N],r[N];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for(int i = 1;i <= n;++i)cin >> arr[i];
    stack<int> s;
    for(int i = 1;i <= n;i++){
        while((int)s.size() && arr[s.top()] > arr[i]){
            s.pop();
        }
        if((int)s.size())
        l[i] = s.top() + 1;
        else
        l[i] = 1;
        s.push(i);
    }
    while((int)s.size() > 0)s.pop();
    for(int i = n;i >= 1;i--){
        while((int)s.size() && arr[s.top()] > arr[i]){
            s.pop();
        }
        if((int)s.size())
        r[i] = s.top() - 1;
        else
        r[i] = n;
        s.push(i);
    }
    long long ans = 0;
    for(int i = 1;i <= n;i++)ans += (arr[i] * (i - l[i] + 1) * (r[i] - i + 1));
    cout << ans;
	return 0;
} 

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> H(N);
    rep(i, N) cin >> H[i];

    int maxLower =0;
    int now = 0;
    REP(i, 0, N-1){
        if(H[i]>=H[i+1]){
            now++;
            if (now >= maxLower){
                maxLower = now;
            }
        }else{
            now = 0;
        }
    }
    cout << maxLower << endl;
    return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int a,b,n,i,a1,a2;
    cin>>a>>b>>n;
     i=n;
    while(i>=b)
    {
        i--;
    }
    a1=((a*i)/b);
    a2=(i/b);
    cout<<a1-a*a2;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

int gcd(int x, int y) {
	if(y == 0) return x;
	return gcd(y, x % y);
}

signed main(){
	int N;
	cin >> N;
	vector<pair <int,int>> a(N);

	for(int i=0; i< N; i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(ALL(a));
    int res=0;
    for(int i=0;i<N;++i){
       if(a[i].second %2 !=i%2){
            ++res;
        }
    } 
    cout << res /2 << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
	int N,L,M;
	cin >> N;
	string s;
	cin >> s;
	L = s.size();
	while (1) {
		M = L;
		for (int i = 0; i < L - 1; i++)
		{
			if (s[i] == s[i + 1])
			{
				s.erase(s.begin() + i + 1);
				L--;
			}
		}
		if (M == L)
			break;
	}
	cout << s.size();
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#define ll long long 
int cmp(const void *a,const void *b){return *(long long*)a-*(long long*)b;}
int main(){
    int n;
    scanf("%d",&n);
    ll a[n];
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    qsort(a,n,sizeof(long long),cmp);
    int count=0;
    for(int i=0;i<n-1;i++){
        if(a[i]!=a[i+1])
            count++;
    }
    if(count==n-1)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

Measured memory_bytes: 3324
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;
 
signed main(){
	int A,V,B,W,T;
	cin>>A>>V>>B>>W>>T;
	int diff = abs(A-B);
	if(W >= V){
		out("NO");
	}else{
		int speed = V - W;
		if(speed * T >= diff)out("YES");
		else out("NO");
	}
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

int n;
int p[100100];
pair<pii, int> a[100100], b[100100];

vector<pair<int, pii> > edges;
ll ans;

int get(int a) {
	if(a == p[a]) return a;
	return p[a] = get(p[a]);
}

bool merge(int a, int b) {
	a = get(a);
	b = get(b);
	if(a == b) return 0;
	p[a] = b;
	return 1;	
}

int main() {

	cin >> n;
	for(int i = 1; i <= n; i++) {
		int x, y;
		cin >> x >> y;
		a[i] = mp(mp(x, y), i);
		b[i] = mp(mp(y, x), i);
		p[i] = i;
	}

	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);

	for(int i = 2; i <= n; i++) {
		edges.pb(mp(a[i].f.f - a[i-1].f.f, mp(a[i].s, a[i-1].s)));
		edges.pb(mp(b[i].f.f - b[i-1].f.f, mp(b[i].s, b[i-1].s)));
	}

	sort(edges.begin(), edges.end());

	for(int i = 0; i < edges.sz; i++) {
		
		int x = edges[i].s.f;
		int y = edges[i].s.s;
		int w = edges[i].f;

		//cout << x << " " << y << " " << w << endl;

		if(merge(x, y)) {
			ans += w;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7668
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	string S;
	cin >> S;
	int ans = 0;
	REP(i, 3) {
		if (S[i] == '1')ans++;
	}
	OUT(ans);
}

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

int main() {
    while (true) {
        int n;
        long long a, b;
        cin >> n >> a >> b;
        if (!n) return 0;
        --a; --b;
        vector<bool> up(n);
        for (int i = n - 1; i >= 0; --i) {
            if (a < (1L << i)) {
                up[i] = true;
                a = (1L << i) - a - 1;
            }
            else {
                up[i] = false;
                a -= 1L << i;
            }
        }
        string ans = "";
        for (int i = 0; i < n; ++i) {
            if (up[i]) {
                if (b < (1L << (n - i - 1))) {
                    ans += 'L';
                    b = (1L << (n - i - 1)) - b - 1;
                }
                else {
                    ans += 'R';
                    b = (1L << (n - i)) - b - 1;
                }
            }
            else {
                if (b < (1L << (n - i - 1)))
                    ans += 'R';
                else {
                    ans += 'L';
                    b -= (1L << (n - i - 1));
                }
            }
        }
        cout << ans << "\n";
    }
}



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


int main() {
    string s;
    cin >> s;
    int cnt = 0;
    if (s[0] == '1') {
        ++cnt;
    }
    if (s[1] == '1') {
        ++cnt;
    }
    if (s[2] == '1') {
        ++cnt;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int count=0;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    if(x%2!=0) count++;
  }
  if(count%2==0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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


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

	int a, b;
	cin >> a >> b;
	
	cout << a / b << " " << a % b << " " << fixed << setprecision(6) << (double)a / b << "\n";
	
	return 0;
}

Measured memory_bytes: 1276
module ABC086

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none
  
  type obj_taskA

    ! data field
    integer(INT16), private :: a
    integer(INT16), private :: b
  
    ! contained <subroutine>s and <function>s are below
    contains

    procedure :: Product    => taskA_Product
    procedure :: IsProdEven => taskA_IsProdEven
  
  end type obj_taskA

  ! constructor
  interface obj_taskA
    module procedure taskA_constructor
  end interface obj_taskA

  ! contained <subroutine>s and <function>s are below
  contains

  function taskA_constructor () result(obj)

    ! return value of this <function>
    type(obj_taskA) :: obj

    read(unit=INPUT_UNIT, fmt=*) obj%a, obj%b

    return

  end function taskA_constructor

  pure function taskA_Product (obj_self) result(Product)

    ! arguments for this <function>
    class(obj_taskA), intent(in) :: obj_self

    ! return value of this <function>
    integer(INT16) :: Product

    Product = obj_self%a * obj_self%b

    return

  end function taskA_Product

  pure function taskA_IsProdEven (obj_self) result(stat)

    ! arguments for this <function>
    class(obj_taskA), intent(in) :: obj_self

    ! return value of this <function>
    logical :: stat

    stat = (mod( a=obj_self%product(), p=2_INT16 ) .eq. 0_INT16)

    return

  end function taskA_IsProdEven

end module ABC086


program main

  ! <module>s to import
  use, non_intrinsic :: ABC086

  ! require all variables to be explicitly declared
  implicit none

  type(obj_taskA) :: obj_given_data

  ! STEP.01
  ! initialize the instace
  obj_given_data = obj_taskA()

  ! STEP.02
  ! compute & output the answer of ABC086 A
  if ( obj_given_data%IsProdEven() ) then
    write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Even'
  else
    write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Odd'
  end if

end program main

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
int data[101];
int main(){
    int N, M;
    cin >> N >>M;
    for(int i=0;i<M;i++)
        cin >> data[i];
    sort(data,data+M);
    bool chk = false;
    for(int i=M-1;i>0;i--){
        if(data[i]>=data[i-1])
            data[i-1] = data[i] - data[i-1];
        else{
            sort(data,data+i);
            chk = true;
        }
    }
    if(!chk)
        cout << (data[0]-1) << endl;
    else
        cout << "0" << endl;
}


Measured memory_bytes: 256
def func(h):
    cost = [0]*len(h)

    for i in range(1,len(h)):
        if i == 1:
            cost[i] =abs( h[i] - h[i-1] )
        else:
            if i >1:
                cost[i] = min((cost[i - 1]+ abs(int(h[i])-int(h[i-1]))), (cost[i - 2]+ abs(int(h[i])-int(h[i-2]) ) ))

    #print(cost)
    
    return cost[-1]



n = int(input())
h = list(map(int, input().strip().split(" ")))[:n]

print(func(h))

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

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}

int main(){
    int H, W, K;
    cin>>H>>W>>K;
    int a[H][W+1];
    char c;
    rep(i, H){
        a[i][0]=0;
    }
    rep(i, H){
        for(int j=1;j<=W;j++){
            cin>>c;
            if(c=='1'){
                a[i][j]=a[i][j-1]+1;
            }
            else{
                a[i][j]=a[i][j-1];
            }
        }
    }
    int cnt;
    vector<int> r;
    int p;
    int check;
    int q;
    int ans=10000;
    for(int bit=0;bit<(1<<H-1);bit++){
        cnt=0;
        r.clear();
        rep(i, H-1){
            if(bit>>i&1){
                r.push_back(i);
                cnt++;
            }
        }
        r.push_back(H-1);
        int b[cnt+1][W+1];
        rep(i, cnt+1){
            rep(j, W+1){
                b[i][j]=0;
            }
        }
        rep(i, cnt+1){
            rep(j, W+1){
                if(i==0){
                rep(k, r.at(i)+1){
                    b[i][j]+=a[k][j];
                }
                }
                else{
                    for(int k=r.at(i-1)+1;k<=r.at(i);k++){
                        b[i][j]+=a[k][j];
                    }
                }
            }
        }
        p=0;
        check=0;
        q=cnt+1;
        rep(i, W+1){
            rep(j, q){
                if(b[j][i]-b[j][p]>K){
                    if(i==p+1){
                        check=2;
                    }
                    else{
                        p=i-1;
                        cnt++;
                        check=1;
                        i--;
                        break;
                    }
                }
            }
            if(check==2){
                break;
            }
        }
        if(check==2){
            continue;
        }
        ans=min(ans, cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define next(a) ( ((a)+1)%SIZE )
#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000
#define SIZE 100000

typedef struct queue
{
	int front;
	int rear;
	int *data;
}queue;

/*
void init(queue* p)
{
	p->front = 0;
	p->rear = 0;
}

void enqueue(queue *p,int x)
{
	if (next(p->rear) == p->front)
		printf("OVERFLOW!\n");
	p->data[p->rear] = x;
	p->rear = next(p->rear);
}

int dequeue(queue *p)
{
	int x;

	if (p->front == p->rear)
		printf("NO DADA\n");

	x = p->data[p->front];
	p->front = next(p->front);

	return x;
}

int empty(queue *p)
{
	return p->front == p->rear;
}

void print(char* str, int a, int b)
{
	int i;

	for (i = a; i <= b; i++)
		printf("%c", str[i]);
	printf("\n");
}
*/

void reverse(char* str, int a, int b)
{
	int i,j=0;
	char t;

	for (i = a; i <= (a + b) / 2; i++)
	{
		t = str[i];
		str[i] = str[b - j];
		str[b - j] = t;
		j++;
	}
}

void replace(char* str, int a, int b, char* temp)
{
	int i, j=0;

	for (i = a; i <= b; i++)
	{
		str[i] = temp[j];
		j++;
	}
}

double rad(int C)
{
	return M_PI * C / 180;
}

double distance(int* a, int* b, int n, int p)
{
	double sum = 0.0;

	int i, j;

	int max = 0;

	for (i = 0; i < n; i++)
	{
		sum += pow(ABS(a[i] - b[i]), p);

		if (ABS(a[i] - b[i]) > max)
			max = ABS(a[i] - b[i]);
	}

	if (p == INF)
		return max;

	return pow(sum, (double)1 / p);
}

/*
typedef struct Vector
{
	int data[10];
	int size;
	int max;
}Vector;

Vector *init()
{
	Vector* p;

	//p = malloc(sizeof(int)*(10+2));
	p = (Vector*)(sizeof(int) * 12);
	//p->data = (int*)malloc(sizeof(int) * 10);
	p->size = 0;
	p->max = 10;

	return p;
}

Vector* Extend(Vector* p)
{
	Vector* q;

	q = (Vector*)malloc(sizeof(int) * p->max * 2);

	memcpy(q, p, sizeof(int) * p->size);

	p->max *= 2;

	free(p);

	return q;
}

Vector *pushBack(Vector *p,int x)
{
	if (p->size == p->max)
		p = Extend(p);

	p->data[p->size++] = 1;

	return p;
}

int randomAccess(Vector* p,int x)
{
	return p->data[x];
}

Vector* popBack(Vector* p)
{
	//free(p->data[--(p->size)]);
	--p->size;
	return p;
}
*/


int main()
{
	int n;
	int R[200000];
	int min = INF;
	int max = -INF;
	int i, j;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
		scanf("%d", &R[i]);


	min = R[0];

	for (i = 1; i < n; i++)
	{
		if (R[i] - min > max)
			max = R[i] - min;

		if (R[i] < min)
			min = R[i];
	}

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

	/*
	Vector* p=NULL;

	p = init(p);

	int n,x,temp;
	int i, j, k;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &temp);
		if (temp == 0 || temp == 1)
		{
			scanf("%d", &x);
			if (temp == 0)
				p = pushBack(p, x);
			else if (temp == 1)
				printf("%d\n",randomAccess(p, x));
		}
		else if (temp == 2)
			p = popBack(p);

		printf(":::%d\n", p->size);
	}*/

	return 0;
}



Measured memory_bytes: 2628
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    final int K = sc.nextInt();
    final String S = sc.next();
    sc.close();
    String ans;
    int len = S.length();
    if(K<len) {
    	ans = S.substring(0, K) + "...";
    }else {
    	ans = S;
    }
    System.out.println(ans);
  }
}

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

using namespace std;

int main() {

	int n, m, l;
	cin >> n >> m >> l;

	vector<vector<int>> a(n, vector<int>(m, 0));
	vector<vector<int>> b(m, vector<int>(l, 0));
	vector<vector<long long>> c(n, vector<long long>(l, 0));


	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> b[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			for (int k = 0; k < m; k++) {
				c[i][j] += a[i][k]* b[k][j];
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l-1; j++) {
				cout << c[i][j] << " ";
		}
		cout << c[i][l - 1] << endl;
	}

}


Measured memory_bytes: 3280
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

//question_a
using namespace std;
using ll = long long;
int main() {
	constexpr ll mod = 1e9 + 7;
	int s;
	cin >> s;
	ll** dp = new ll*[s/3];
	for (int i = 0;i < s / 3;i++) {
		dp[i] = new ll[s];
		for (int j = 0;j < s;j++) {
			dp[i][j] = 0;
		}
	}
	for (int i = 2;i < s;i++) {
		dp[0][i] = 1;
	}
	for (int i = 1;i < s / 3;i++) {
		for (int j = 2;j < s;j++) {
			for (int k = j - 3;k >= 3*i - 1;k--) {
				dp[i][j] += dp[i - 1][k];
				dp[i][j] %= mod;
			}
		}
	}
	ll ans=0;

	for (int i = 0;i < s / 3;i++) {
		ans += dp[i][s-1];
		ans %= mod;
	}
	cout << ans << endl;
}



Measured memory_bytes: 13560
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;


int main() {
    ios_base::sync_with_stdio(false);

    int n,m;
    cin >> n >> m;
    vector<int> a(n),b(n),c(m),d(m);
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,m) cin >> c[i] >> d[i];
    rep(i,n) {
        int mi=INF;
        int ans;
        rep(j,m) {
            int dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if (dis<mi) {
                mi=dis;
                ans=j;
            }
        }
        cout << ans+1 << endl;
    }
    

    return 0;   
}


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

typedef pair<int, int> P;

static const int MAX_H = 50;
static const int MAX_W = 50;

int H, W;
int sh = -1, sw = -1, gh = -1, gw = -1;
char grid[MAX_H][MAX_W + 1];
int count[MAX_H][MAX_W];

//#define OCTAS
#ifdef OCTAS
static const int dh[] = {-1, -1, -1, 0, 0, +1, +1, +1};
static const int dw[] = {-1, 0, +1, -1, +1, -1, 0, +1};
#else
static const int dh[] = {-1, 0, 0, +1};
static const int dw[] = {0, -1, +1, 0};
#endif

// CAUTION!!!
// Call init_count() first!!!
//
void init_count() {
  fill_n(::count[0], MAX_H * MAX_W, -1);
}

int bfs(int h, int w) {
  queue<P> que;
  ::count[h][w] = 0;
  que.push(P(h, w));

  while (!que.empty()) {
    P p = que.front();
    que.pop();
    int cnt = ::count[p.first][p.second];
    if (p.first == gh && p.second == gw) {
      return cnt;
    }
    ++cnt;
    for (int i = 0; i < sizeof(dh) / sizeof(int); ++i) {
      int nh = p.first + dh[i];
      int nw = p.second + dw[i];
      if (nh < 0 || nh >= H ||
          nw < 0 || nw >= W ||
          ::count[nh][nw] >= 0 ||
          grid[nh][nw] == '#')
        continue;
      ::count[nh][nw] = cnt;
      que.push(P(nh, nw));
    }
  }

  return -1;
}

int main() {
  init_count();
  scanf("%d%d", &H, &W);
  sh = 0;
  sw = 0;
  gh = H - 1;
  gw = W - 1;

  int white_num{};
  for (int h = 0; h < H; ++h) {
    scanf("%s", &grid[h][0]);
    for (int w = 0; w < W; ++w) {
      if (grid[h][w] == '.') ++white_num;
    }
  }

  int num = bfs(sh, sw);
  printf("%d\n", num < 0 ? num : white_num - num - 1);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const int maxn=200020,K=30;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
struct item{
	int a,b;
	bool operator<(const item &it)const{
		ll s1=1ll*(1-a)*it.b,s2=1ll*(1-it.a)*b;
		if(s1!=s2) return s1<s2;
		return b<it.b;
	}
}it[maxn];
int n,t,a[maxn],b[maxn],pos,ans,arr[maxn];
ll f[maxn][31];
int main(){
	n=read();t=read();
	FOR(i,1,n){
		it[i].a=read()+1;
		it[i].b=read()+it[i].a;
	}
	sort(it+1,it+n+1);
	FOR(i,1,n) a[i]=it[i].a,b[i]=it[i].b;
	FOR(i,0,n) FOR(j,0,K) f[i][j]=5e18;
	f[0][0]=0;
	ROF(i,n,0) if(a[i]!=1){pos=i+1;break;}
	arr[0]=0;
	FOR(i,1,n-pos+1) arr[i]=arr[i-1]+b[pos+i-1];
	FOR(i,1,pos-1) FOR(j,0,K){
		f[i][j]=f[i-1][j];
		if(j){
			ll s=f[i-1][j-1]*a[i]+b[i];
			if((s-b[i])/a[i]==f[i-1][j-1]) f[i][j]=min(f[i][j],s);
		}
	}
	FOR(i,0,K) FOR(j,0,n-pos+1) if((ull)f[pos-1][i]+arr[j]<=(ull)t) ans=max(ans,i+j);
	printf("%d\n",ans);
}
// swap(C, D)

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    map<string, int> m;
    string S;
    rep(i, N) {
        cin >> S;
        m[S]++;
    }
    cout << "AC x " << m["AC"] << "\n";
    cout << "WA x " << m["WA"] << "\n";
    cout << "TLE x " << m["TLE"] << "\n";
    cout << "RE x " << m["RE"] << "\n";
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

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

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

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

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

  int ans=0;

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        int all=A[i]+A[j]+A[k];
        int m=0;
        chmax(&m,A[i]);
        chmax(&m,A[j]);
        chmax(&m,A[k]);

        if(A[i]==A[j] || A[j]==A[k] || A[k]==A[i]){
          continue;
        }

        all-=m;//他の2辺
        if(m<all){
          ans++;
        }
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 1736
K = int(input())
A, B = (int(x) for x in input().split())
length = (B-A) + 1
answer = True

for i in range(length):
    if A%K == 0:
        answer = True
        break
    else:
        answer = False
    A += 1

if answer:
    print('OK')
else:
    print('NG')


Measured memory_bytes: 9108
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

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

  vector <int> A(N), B(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    B[i] = A[i];
  }
  sort(B.begin(), B.end(), greater<int>());
  
  for (int i = 0; i < N; i++){
    if (A[i] == B[0]){
      cout << B[1] << endl;
    }else{
      cout << B[0] << endl;
    }
  }
  
  return 0;
}


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

int main(){

    int N;
    cin>>N;
    vector<int> A(N-1),B(N-1),X(N-1),S(N);
    for(int i=0;i<N-1;i++){
        cin>>A[i]>>B[i]>>X[i];
        X[i]=X[i]%2;
    }
    S[A[0]-1]=2;
    int cnt=0;
    while(cnt!=N-1){
        cnt=0;
    for(int i=0;i<N-1;i++){
        if(S[B[i]-1]==0){
        if(S[A[i]-1]==2){
            if(X[i]==0) S[B[i]-1]=2;
            else S[B[i]-1]=3;
            cnt++;
        }
        if(S[A[i]-1]==3){
            if(X[i]==0) S[B[i]-1]=3;
            else S[B[i]-1]=2;
            cnt++;
        }
        }
        else{
        if(S[B[i]-1]==2){
            if(X[i]==0) S[A[i]-1]=2;
            else S[A[i]-1]=3;
            cnt++;
        }
        if(S[B[i]-1]==3){
            if(X[i]==0) S[A[i]-1]=3;
            else S[A[i]-1]=2;
            cnt++;
        }
        }
    }
    }
    for(int i=0;i<N;i++){
        if(S[i]==2) cout<<0<<endl;
        else cout<<1<<endl;
    }
}

Measured memory_bytes: 2048