akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
using namespace std;

bool prime[60001];
int main(){
  memset( prime ,true ,sizeof(prime) );
  prime[0] = prime[1] = false;
  for( int i=2 ; i*i<=60000 ; i++ ){
    if( prime[i] == true ){
      for( int j=i+i ; j<=60000 ; j+=i ){
	prime[j] = false;
      }
    }
  }

  int n;
  while( cin >> n ){
    for( int j=n-1 ; j>=0 ; j-- ){
      if( prime[j] == true ){
	cout << j << " ";
	break;
      }
    }
    for( int j=n+1 ; j<60001 ; j++ ){
      if( prime[j] == true ){
	cout << j << endl;
	break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

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

    if(a>b || n==1 && a!=b){
        cout << 0 << endl;
        return 0;
    }else if(n==1){
        cout << 1 << endl;
        return 0;
    }else{
        ll max_value = (n-1)*b + a;
        ll min_value = (n-1)*a + b;
        cout << max_value - min_value + 1 << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;

int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    int ans;
    ans = H * W - h * W - w * H + h * w;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int h, w, a, b, i, j;
	cin >> h >> w >> a >> b;

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if ((j < a || i < b) && !(j < a && i < b)) {
				cout << "0";
			} else {
				cout << "1";
			}
		}
		cout << endl;
	}
	return 0;
}

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int n; cin >> n;
    if (n == 0) return;
    vi32 a(n); cin >> a;
    f80 avg = 0;
    rep(i, n) avg += a[i];
    avg /= n;
    int ans = 0;
    rep(i, n) if (a[i] <= avg) ans++;
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3184
# coding: utf-8
import math
N = int(input())
ans = 0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):
            if len(set([i,j,k])) == 3:
                cnt = 6
            elif len(set([i,j,k])) == 2:
                cnt = 3
            else:
                cnt = 1
            ans += math.gcd(math.gcd(i,j),k) * cnt
            
print(ans)

Measured memory_bytes: 9160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
#define LL long long
#define REP(i, a, b) for(int i = a; i <= b; ++i)
#define PER(i, a, b) for(int i = a; i >= b; --i)

inline int read() {
	int x = 0, flag = 1; char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * flag;
}
int n, m;
const int N = 1e5 + 5;
struct node {
	int id, x, y;
}a[N];
string s[N];
int aa[6], now[N];

bool cmp(node a, node b) {
	return a.x == b.x ? a.y < b.y : a.x < b.x;
}

int main() {
	n = read(); m = read();
	REP(i, 1, m) a[i].x = read(), a[i].y = read(), a[i].id = i;
	sort(a + 1, a + m + 1, cmp);
	REP(i, 1, m) {//880 000000 
		int x = a[i].x; int nn = 100000; int cnt = 0;
		while(nn > x) {
			nn /= 10;
			s[a[i].id] += '0';
		}
		while(x) {
			aa[++cnt]= (x % 10);
			//cout << aa[cnt] << " ";
			x /= 10;
		}
		PER(j, cnt, 1) s[a[i].id] += (aa[j] + '0');
		//cout << s[a[i].id] << endl;
		int y = (++now[a[i].x]); nn = 100000; cnt = 0;
		while(nn > y) {
			nn /= 10;
			s[a[i].id] += '0';
		}
		while(y) {
			aa[++cnt]= (y % 10);
			//cout << aa[cnt] << " ";
			y /= 10;
		}
		PER(j, cnt, 1) s[a[i].id] += (aa[j] + '0');
		//cout << s[a[i].id] << endl;
	}
	REP(i, 1, m) cout << s[i] << endl;
	return 0;
}
 

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


void solve() {
  char ch[4+1];
  scanf("%s", &ch);
  string ans = "Good";
  if (ch[0]==ch[1] || ch[1]==ch[2] || ch[2]==ch[3]) {
    ans = "Bad";
  }
  cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,ans=1,a[N],du[N],pre[N],cnt[N],f[N];
bool vis[N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),du[a[i]]++;
    for(int i=1;i<=n;i++) {
        if(du[i]>2) return puts("0"),0;
        if(du[i]<2||vis[i]) continue;
        int p=i;
        do {
            if(vis[p]) return puts("0"),0;
            vis[p]=1;pre[a[p]]=p;p=a[p];
        } while(p!=i);
    }
    for(int i=1;i<=n;i++)
        if(!du[i]) {
            int p=i,l1=0,l2=0;
            while(!vis[p]) vis[p]=1,p=a[p],l1++;
            do l2++,p=pre[p]; while(du[p]!=2);
            if(l1<l2) ans=2ll*ans%mod;
            else if(l1>l2) return puts("0"),0;
        }
    for(int i=1;i<=n;i++)
        if(!vis[i]) {
            int p=i,l=0;
            do p=a[p],l++,vis[p]=1; while(p!=i);
            cnt[l]++;
        }
    for(int i=1;i<=n;i++) {
        int mul=1;if(i!=1&&(i&1)) mul++;
        f[0]=1;f[1]=mul;
        for(int j=2;j<=cnt[i];j++) f[j]=(1ll*f[j-2]*(j-1)%mod*i%mod+1ll*f[j-1]*mul%mod)%mod;
        ans=1ll*ans*f[cnt[i]]%mod;
    }
    printf("%d\n",ans);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,int> P;

int main() {
	string s;
	cin>>s;
	int ls=s.length();
	int a[27]={};
	for(int i=0;i<ls;++i){
		int k=s[i]-97;
		a[k]++;
	}
	bool flg=true;
	for(int i=0;i<27;++i){
		if(a[i]%2!=0)flg=false;
	}
	if(flg){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
h[0] -= 1
for i in range(1,n):
  if h[i] > h[i-1]:
    h[i] -= 1
  elif h[i] < h[i-1]:
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 20608
n, m, x = map(int, input().split())
a_list = list(map(int, input().split()))

cost_1 = 0

current = x
while current != n:
    current += 1
    if current in a_list:
        cost_1 += 1

cost_2 = 0
current = x
while current != 0:
    current -= 1
    if current in a_list:
        cost_2 += 1

print(min(cost_1, cost_2))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

template<typename T>
struct PascalTriangle{
    int n;
    vector<vector<T>> table;
    PascalTriangle(int n) : n(n){
        table.resize(n + 1, vector<T>(n + 1, 0));

        table[0][0] = 1;
        for(int i = 0; i < n; ++i){
            table[i + 1][0] = table[i][0];
            table[i + 1][i + 1] = table[i][i];
        }
        for(int i = 0; i < n; ++i){
            for(int j = 1; j < n; ++j){
                if(j >= i + 1)  continue;
                table[i + 1][j] = table[i][j - 1] + table[i][j];
            }
        }
    }

    T get_value(int n, int k){
        if(n < 0 || k < 0 || n < k) return 0;
        return table[n][k];
    }
};

using ld = long double;

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

    int n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    for(int i = 0; i < n; ++i)  cin >> v[i];
    sort(v.begin(), v.end(), greater<ll>());
    vector<ll> S(n + 1);
    S[0] = 0;
    for(int i = 0; i < n; ++i)  S[i + 1] = S[i] + v[i];

    ld lb = 0, ub = v[0];
    for(int i = 0; i < 100; ++i){
        ld mid = (lb + ub) / 2;
        bool ok = false;
        for(int c = a; c <= b; ++c){
            ld val = (ld)S[c] / c;
            if(val >= mid){
                ok = true;
                break;
            }
        }
        if(ok)  lb = mid;
        else    ub = mid;
    }

    PascalTriangle<ll> C(n + 1);

    map<ll, int> mp;
    ll ans = 0;
    for(int i = 0; i < a - 1; ++i)  ++mp[v[i]];
    for(int c = a; c <= b; ++c){
        ld val = (ld)S[c] / c;
        if(abs(lb - val) < EPS){
            ++mp[v[c - 1]];
            map<ll, int> mp2 = mp;
            for(int i = c; i < n; ++i){
                if(mp.find(v[i]) != mp.end()){
                    ++mp2[v[i]];
                }
            }
            ll add = 1;
            for(auto it : mp){
                add *= C.get_value(mp2[it.first], it.second);
            }
            ans += add;
        }
        else    break;
    }

    cout << fixed << setprecision(10);
    cout << lb << '\n' << ans << '\n';
}

Measured memory_bytes: 3856
// AOJ 2014 "土地囲い" (ICPC模擬国内予選 2007 Problem C)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int w = sc.nextInt();
            int h = sc.nextInt();
            if (w == 0) {
                break;
            }
            
            StringBuffer[] field = new StringBuffer[h];
            for (int i = 0; i < field.length; i++) {
                field[i] = new StringBuffer(sc.next());
            }
            
            for (int i = 0; i < field.length; i++) {
                for (int j = 0; j < field[i].length(); j++) {
                    if (field[i].charAt(j) == 'W') {
                        dfs(field, j, i, 'w');
                    } else if (field[i].charAt(j) == 'B') {
                        dfs(field, j, i, 'b');
                    }
                }
            }
            
            int bArea = 0;
            int wArea = 0;
            for (int i = 0; i < field.length; i++) {
                for (int j = 0; j < field[i].length(); j++) {
                    if (field[i].charAt(j) == 'b') {
                        bArea++;
                    } else if (field[i].charAt(j) == 'w') {
                        wArea++;
                    }
                }
            }
            System.out.println(bArea + " " + wArea);
        }
    }
    
    public static void dfs(StringBuffer[] field, int x, int y, char c) {
        int[] dx = {0, 1, 0, -1};
        int[] dy = {1, 0, -1, 0};
        
        for (int i = 0; i < dx.length; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            
            if (0 <= ny && ny < field.length && 0 <= nx && nx < field[ny].length()) {
                if (field[ny].charAt(nx) == '.') {
                    field[ny].setCharAt(nx, c);
                    dfs(field, nx, ny, c);
                } else if ((field[ny].charAt(nx) == 'b' && c == 'w')
                || (field[ny].charAt(nx) == 'w' && c == 'b')) {
                    field[ny].setCharAt(nx, 'g');
                    dfs(field, nx, ny, c);
                }
            }
        }
    }
}

Measured memory_bytes: 43376
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(){
    string s;
    cin >> s;
    bool len=false,fig=false,up=false,low=false;
    if(s.size() >= 6) len = true;
    for(int i=0;i<s.size();i++){
        if(isdigit(s[i])) fig = true;
        else if(isupper(s[i])) up = true;
        else if(islower(s[i])) low = true;
    }
    cout << ((len && fig && up && low)? "VALID" : "INVALID") << endl;
}

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

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

  ll n, q, sum = 0;
  map<ll, ll> map;
  
  cin >> n;
  
  for (ll i = 0; i < n; i++)
  {
    ll a;
    cin >> a;
    sum += a;
    if (map.count(a)) map[a]++;
    else map[a] = 1;
  }

  cin >> q;

  for (int i = 0; i < q; i++)
  {
    ll b, c, match;
    cin >> b >> c;
    if (map.count(b))
    {
      match = map.at(b);
      map.at(b) = 0;
    }
    else
    {
      cout << sum << endl;
      continue;
    }

    sum = sum - (match * b) + (match * c);

    if (map.count(c))
      map.at(c) += match;
    else
      map[c] = match;

    cout << sum << endl;
  }

  return 0;
}

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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    const int MAX_V = 1e5;
    vector<int> odd(MAX_V + 1), even(MAX_V + 1);
    for (int i = 0; i < n; ++i) {
        int v; cin >> v;
        if (i % 2 == 0) ++odd[v];
        else ++even[v];
    }

    pair<int, int> o1, o2, e1, e2;
    for (int v = 0; v <= MAX_V; ++v) {
        if (o2.second < odd[v]) o2 = make_pair(v, odd[v]);
        if (o1.second < o2.second) swap(o1, o2);

        if (e2.second < even[v]) e2 = make_pair(v, even[v]);
        if (e1.second < e2.second) swap(e1, e2);
    }

    if (o1.first != e1.first)
        cout << (n / 2 - o1.second) + (n / 2 - e1.second) << endl;
    else if (o2.second == 0 && e2.second == 0)
        cout << n / 2 << endl;
    else if (o1.second + e2.second <= o2.second + e1.second)
        cout << (n / 2 - o2.second) + (n / 2 - e1.second) << endl;
    else
        cout << (n / 2 - o1.second) + (n / 2 - e2.second) << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

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

    vector<vector<int>> x(n);
    rep(i,n){
        x[i].resize(d);
        rep(j,d){
            cin >> x[i][j];
        }
    }


    int cnt = 0;
    rep(i,n){
        rep(j,n){
            if(i<j){
                int sum = 0;
                rep(k,d) sum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);

                bool ok = false;
                for(int dist=sqrt(sum)-1;dist<=sqrt(sum)+1;dist++){
                    if(dist*dist == sum){
                        ok = true;
                    }
                }
                if(ok) cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=500005;

char s[N];
int a[N],pre[N],nxt[N];
int ans,n,lst;

il void init(){
	pre[0]=0;
	rep(i,1,lst) pre[i]=(a[i]==a[i-1]?pre[i-1]:i);
	nxt[lst]=lst;
	per(i,lst-1,0) nxt[i]=(a[i]==a[i+1]?nxt[i+1]:i);
}

il void inc(){
	int p=n-1;
	while(a[p]==9) a[p--]=0;
	++a[p];
	if(p<=lst) init();
}

int main(){
//	fileio("test");
	scanf("%s",s),n=strlen(s);
	rep0(i,n) a[i]=s[i]-'0';
	lst=qmax(0,n-8);
	init();
	for(int i=0,j;i<n;i=j){
		j=i;
		if(j<lst) for(j=nxt[j];j<lst&&a[j+1]>a[j];j=nxt[j+1]);
		if(j>=lst){
			while(j+1<n&&a[j+1]>=a[j]) ++j;
			if(j!=n-1) while(j>lst&&j>i&&a[j-1]==a[j]) --j;
		}
		if(j<=lst) j=qmax(pre[j],i);
		++j,++ans;
//		cerr<<i<<" "<<j<<endl;
//		rep0(i,n) cerr<<a[i];cerr<<endl;
		if(j>=n) break;
		inc();
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 6656
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

bool check(string S, int a, int b)
{
	// aからbにイク
	if (a > b) swap(a, b);

	vector<int> P(S.size(), -1); // ブロックがあっていけない→1 , なにもない→ 0 
	// いけた 2 
	FOR(i, S.size()) {
		auto c = S[i];
		if (c == '.') {
			P[i] = 0;
		}
		else if (c == '#') {
			P[i] = 1;
		}
	}

	queue<int> Q;
	Q.push(a);
	while (!Q.empty()) {
		auto now = Q.front(); Q.pop();
		if (now >= S.size()) continue;

		if (P[now] == 0) {
			P[now] = 2;
			Q.push(now + 1);
			Q.push(now + 2);
		}
		//S[now] = "x";
	}
	if (P[b] == 2) return true;
	return false;
}

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll A, B, C, D, N;
	cin >> N >> A >> B >> C >> D;
	A -= 1;
	B -= 1;
	C -= 1;
	D -= 1;
	string S;
	cin >> S;
	string ans = "No";
	if (C < D) {
		if (check(S, A, C) and check(S, B, D)) {
			ans = "Yes";
		} else ans = "No";
	} else {
		FOR(_i, N - 2) {
			auto i = _i + 1;
			if (S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.' and (B <= i and i <= D)) {
				if (check(S, A, C) and  check(S, B, D)) {
					ans = "Yes";
					break;
				}
			}
		}
	} // この場合が怖い
	cout << ans << endl;

	return 0;
}


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

vector<P>Div(ll n){
  vector<P> d;
  for(ll i = 2; i*i <= n; i++){
    ll cnt = 0;
    while(n % i == 0){
      n /= i;
      cnt++;
    }
    d.push_back(P(i,cnt));
  }
  if(n != 1) d.push_back(P(n,1));
  return d;
}

int main(void){
  ll n;
  cin >> n;
  vector<P> d = Div(n);
  ll ans = 0;
  for(ll i = 0; i < d.size(); i++){
    for(ll j = 1; j <= d[i].second; j++){
      ll tmp = pow(d[i].first,j);
      if(n % tmp != 0) continue;
      n /= tmp;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int main(void){
    #ifdef ccsnoopy
        freopen("D:/Code/in.txt","r",stdin);
    #endif

    int n;
    int fr, to;
    sc(n);
    sc(fr);sc(to);
    vi arr;
    arr.assign(n,0);
    int x;
    FOR(i,n){
        sc(x);
        arr[i] = x;
    }

    sort(arr.begin(), arr.end());
    vi::const_iterator it = lower_bound(arr.begin(), arr.end(),fr);
    vi::const_iterator it2 = lower_bound(arr.begin(), arr.end(), to);
    printf("%d\n", n - (int)(it2-it));

    return 0;
}





Measured memory_bytes: 256
import java.io.*;

/**
 * Created by Ayushi on 27/07/2019.
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int[] in = new int[n];
        temp = r.readLine().split(" ");
        r.close();
        int wp = 0;
        for (int i = 0; i < n; i++) {
            in[i] = Integer.parseInt(temp[i]);
            if (in[i] != i+1) wp++;
        }

        if (wp > 2) System.out.println("NO");
        else System.out.println("YES");
    }
}


Measured memory_bytes: 21204
from sys import exit
# A,B,C = [int(n) for n in input().split()]
# a = [int(input()) for _ in range(N)]
S = str(input())
L = len(S)
# T = str(input())
# exit()
mind = 119000000000
for i in range(L-2):
    if abs(753 - int(S[i]+S[i+1]+S[i+2])) < mind:
        mind = abs(753 - int(S[i]+S[i+1]+S[i+2]))
print(mind)


Measured memory_bytes: 2940
import java.util.*;
import java.text.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int h = sc.nextInt();
    int w = sc.nextInt();
    char[][] arr = new char[h][w];
    int[][] d = new int[h][w];
    int[] dx = {1, 0, -1, 0};
    int[] dy = {0, 1, 0, -1};
    boolean[][] flag = new boolean[h][w];
    Queue<Pair> queue = new ArrayDeque<>();

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

    void run() {

        for (int i=0; i<h; i++) {
            arr[i] = sc.next().toCharArray();
        }

//        for (int i=0; i<h; i++) {
//            for (int j=0; j<w; j++) {
//                d[i][j] = Integer.MAX_VALUE;
//            }
//        }

        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                if (arr[i][j] == '#') {
//                    d[i][j] = 0;
                    queue.add(new Pair(i, j));
                }
            }
        }

        bfs();

        int cnt = 0;
        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
//                if (arr[i][j] == '#') continue;
                cnt = Math.max(cnt, d[i][j]);
//                System.out.println(d[i][j]);
            }
        }

        System.out.println(cnt);

    }

    void bfs() {
        while (!queue.isEmpty()) {
//            Pair pair = queue.peek();
            Pair pair = queue.remove();
            int y = pair.y;
            int x = pair.x;
            flag[y][x] = true;
            for (int i=0; i<4; i++) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (ny<0 || h<=ny || nx<0 || w<=nx) continue;
                if (arr[ny][nx] == '#') continue;
                if (flag[ny][nx]) continue;
                d[ny][nx] = d[y][x] + 1;
                queue.add(new Pair(ny, nx));
                flag[ny][nx] = true;
            }
//            queue.poll();
        }
    }

    class Pair {
        int y, x;

        public Pair(int y, int x) {
            this.y = y;
            this.x = x;
        }
    }



}


Measured memory_bytes: 89404
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long mae[200001] = {};
long long usiro[200001] = {};
int main() {
#define int long long
	long long l, n;
	cin >> l >> n;
	vector<long long> inputs;
	REP(i, n) {
		long long a;
		cin >> a;
		inputs.push_back(a);
	}
	long long ans = 0;
	REP(t, 2) {
		ans = max(ans, inputs[inputs.size() - 1]);
		for (int q = 0; q < inputs.size(); ++q) {
			if (q != 0) {
				mae[q] = mae[q - 1];
			}
			mae[q] += inputs[q];
		}
		for (int q = inputs.size() - 1; q >= 0; --q) {
			usiro[q] = usiro[q + 1] + (l - inputs[q]);
		}
		for (int i = 0; i < inputs.size()-1; ++i) {
			long long bobo_itr = (inputs.size() - i - 1LL);//remaining
			if (bobo_itr % 2 == 1) {
				//left to right would be final move
				long long now_geko = mae[bobo_itr/2 + i];
				now_geko -= mae[i];
				now_geko += inputs[i];
				now_geko += usiro[inputs.size() - bobo_itr / 2];
				now_geko *= 2LL;
				now_geko -= inputs[i + bobo_itr / 2];
				long long tmp = llabs(inputs[i + bobo_itr / 2 + 1] - inputs[i + bobo_itr / 2]);
				now_geko += max(tmp, l - tmp);
				ans = max(ans, now_geko);
			}
			else {
				long long now_geko = mae[bobo_itr / 2 + i - 1];
				now_geko -= mae[i];
				now_geko += inputs[i];
				now_geko += usiro[inputs.size() - bobo_itr / 2];
				now_geko *= 2LL;
				now_geko += inputs[i + bobo_itr / 2];
				ans = max(ans, now_geko);
			}
		}
		REP(q, inputs.size()) {
			inputs[q] = l - inputs[q];
		}
		sort(inputs.begin(), inputs.end());
	}
	cout << ans << endl;
}


Measured memory_bytes: 5104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

int main() {
  
  int n;
  int ans = 0;
  scanf("%d", &n);
  
  vector<int> A(n);
  vector<int> B(n);
  vector<int> C(n - 1);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
  }
  
  for (int i = 0; i < n; ++i) {
    scanf("%d", &B[i]);
  }
  
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d", &C[i]);
  }
  
  int i = 0;
  while (i < n) {
    i++;
    if (A[i] - A[i - 1] == 1) {
      ans += B[A[i - 1] - 1];
      ans += C[A[i - 1] - 1];
    } else {
      ans += B[A[i - 1] - 1];
    }
  }
  
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double sum = 0;

		for(int i=0; i<N; i++) {
			double x = sc.nextDouble();
			if ("JPY".equals(sc.next())) {
				sum += x;
			} else {
				sum += x * 380000;
			}
		}

		System.out.println(sum);


	}
}


Measured memory_bytes: 24148
x, n = map(int, input().split())
p = list(map(int, input().split()))
len=float("inf")
memo=list(range(-100,300))
ans=[[float("inf")] for i in range(10000)]
for i in p:
    memo.remove(i)
for i in memo:
    if abs(x-i)<=len:
        len=abs(x-i)
        ans[len].append(i)
ans[len].sort()
print(ans[len][0])

Measured memory_bytes: 10248
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

// #define DEBUG 100

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

const ll oo = 1e10 + 7;
const ll mod = 1e9 + 7,maxn = 100010;
const double PI = acos(-1);

string solve(int n){
    for (int i=0; i*3<=n; i++){
        int val = n - 3*i;
        if (val%7 == 0 ) return "YES";
    }
    return "NO";
}

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

    if (s == "RRR") cout << 3 << endl;
    else if(s == "SRR" || s == "RRS") cout << 2 << endl;
    else if (s == "SSS") cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 3628
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[A[i] for i in reversed(range(N)) if A[i]<0]
C=[A[i] for i in range(N) if A[i]>=0]
s=0
if len(B)>0 and len(C)>0:
  s=sum(B)*-1
  s+=sum(C)
else:
  if len(B)>0:
    s=B[0]-(sum(B)-B[0])
  else:
    s=sum(C)-C[0]*2
print(s)
tmp=0
if len(B)==0:
  tmp=C[0]
  for i in range(2,len(C)):
    print(tmp,C[i])
    tmp-=C[i]
  print(C[1],tmp)
  
  
elif len(C)==0:
  tmp=B[0]
  for i in range(1,len(B)):
    print(tmp,B[i])
    tmp-=B[i]
else:
  tmp=C[0]
  tmp2=B[0]
  for i in range(1,len(B)):
    print(tmp,B[i])
    tmp-=B[i]
  for i in range(1,len(C)):
    print(tmp2,C[i])
    tmp2-=C[i]
  print(tmp,tmp2)
  tmp-=tmp2


Measured memory_bytes: 14092
'use strict'

function main(s) {

  s = s.split('\n');

  const o = s[0].split('');
  const e = s[1].split('');

  let ans = '';

  for (let i = 0; i < o.length + e.length; i++) {
    if (o[i]) ans += o[i];
    if (e[i]) ans += e[i];
  }

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		while(0 < 1) {
			String str = sc.next();
			StringBuffer strbf = new StringBuffer(str);
			if(str.equals("-")) break;
			int shuffle = sc.nextInt();
			for(int i = 0;i < shuffle;i++) {
				int num = sc.nextInt();
				strbf.append(strbf.substring(0,num));
				//System.out.println(strbf);
				strbf.delete(0, num);
				//System.out.println(strbf);
			}
			System.out.println(strbf);
		}
		sc.close();
	}
}


Measured memory_bytes: 26272
import { homedir } from 'os';

const main = lines => {
  console.log(solve(lines));
};

const solve = (lines: string[]): string => {
  const { N, H } = parseLines(lines);

  const a = N - 1;

  let tmp = 0;
  let result = 0;

  for (let i = 0; i < a; ++i) {
    if (H[i] >= H[i + 1]) ++tmp;
    else {
      result = Math.max(tmp, result);
      tmp = 0;
    }
  }

  return Math.max(tmp, result).toString();
};

const parseLines = (lines: string[]) => {
  const N = +lines[0];
  const H = lines[1].split(' ').map(i => +i);
  const obj = { N, H };
  debug(obj);
  return obj;
};

const debug = (message?: any, ...optionalParams: any[]) => {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
};

if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume();
  input.setEncoding('utf8');
  const lines = [];
  require('readline')
    .createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}

export default solve;


Measured memory_bytes: 27596
import java.util.Scanner;

public class Main {
	static final double EPS = 1.0e-9;
	public static void main(String[] args) {
		doIt();
	}
	static void doIt() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int[] x = new int[n];
			int[] y = new int[n];
			int[] v = new int[n];
			double xx = 0, yy = 0, d = Double.MAX_VALUE, cons = 10, rate = 0.98;
			for (int i = 0; i < n; i++) {
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
				v[i] = sc.nextInt();
				xx += x[i];
				yy += y[i];
			}
			xx /= n;
			yy /= n;
			double t = 0;
			int idx = 0;
			for (int i = 0; i < n; i++) {
				double tmp = Math.sqrt((xx - x[i])*(xx - x[i]) + (yy - y[i])*(yy - y[i])) / v[i];
				if(t < tmp){
					t = tmp;
					idx = i;
				}
			}
			d = t;
			while(true){
				//System.out.println(xx + " : " + yy + " : " + cons);
				t = 0;
				idx = 0;
				for (int i = 0; i < n; i++) {
					double tmp = Math.sqrt((xx - x[i])*(xx - x[i]) + (yy - y[i])*(yy - y[i])) / v[i];
					if(t < tmp){
						t = tmp;
						idx = i;
					}
				}
				double vv = cons / Math.sqrt((xx - x[idx])*(xx - x[idx]) + (yy - y[idx])*(yy - y[idx]));
				double txx = xx + (x[idx] - xx) * vv;
				double tyy = yy + (y[idx] - yy) * vv;
				if(Math.sqrt((txx - xx)*(txx - xx) + (tyy - yy)*(tyy - yy)) < EPS) break;
				t = 0;
				for (int i = 0; i < n; i++) {
					double tmp = Math.sqrt((txx - x[i])*(txx - x[i]) + (tyy - y[i])*(tyy - y[i])) / v[i];
					if(t < tmp) t = tmp;
				}
				//if(t < d){
					xx = txx;
					yy = tyy;
					d = t;
				//}
				cons *= rate;
			}
			System.out.println(d);
		}		
	}
}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

// 解説AC
int main()
{
    int H, W;
    cin >> H  >> W;

    vector<vector<int>> a(H, vector<int>(W));
    rep(i, H) rep(j, W) cin >> a[i][j];

    int ph=-1, pw=-1;
    bool c=false;

    vector<vector<int>> ans;

    for (int h = 0; h < H; h++) {
        if (h % 2 == 0) {
            for (int w = 0; w < W;w++){
                if (c) ans.push_back(vector<int>{ph + 1, pw + 1, h + 1, w + 1});
                if(c){
                    if(a[h][w]%2==1){
                        c = false;
                    }
                }else{
                    if(a[h][w]%2==1){
                        c = true;
                    }
                }
                ph = h;
                pw = w;
            }
        } else {
            for (int w = W - 1;w>=0;w--){
                if (c) ans.push_back(vector<int>{ph + 1, pw + 1, h + 1, w + 1});
                if (c) {
                    if (a[h][w] % 2 == 1) {
                        c = false;
                    }
                } else {
                    if (a[h][w] % 2 == 1) {
                        c = true;
                    }
                }
                ph = h;
                pw = w;
            }
        }
    }

    cout << ans.size() << endl;
    for(auto a:ans){
        cout << join(a, " ") << endl;
    }
}


Measured memory_bytes: 11052
#include<iostream>
#include<algorithm>
using namespace std;
#define FOR(i, a, n) for(int i=a; i<n; i++)
#define RFOR(i, a, n) for(int i=n-1; i>=a; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)

int main()
{
	int n, m;
	while (cin >> n >> m, n || m) {
		int taro[100], hanako[100];
		int staro = 0, shanako = 0;
		REP(i, n) {
			cin >> taro[i];
			staro += taro[i];
		}
		REP(i, m) {
			cin >> hanako[i];
			shanako += hanako[i];
		}

		int sum = staro + shanako;
		if ((sum % 2) == 1) {
			cout << -1 << endl;
			continue;
		}

		int t = -1, h = -1;
		int minv = 1000;
		int prod;
		(staro < shanako) ? prod = 1 : prod = -1;

		REP(i, n) {
			int val = prod * abs(sum / 2 - staro) + taro[i];
			REP(j, m) {
				if (val == hanako[j]) {
					if (taro[i] + hanako[j] < minv) {
						t = taro[i];
						h = hanako[j];
						minv = t + h;
					}
				}
			}
		}
		if (t == -1) cout << -1 << endl;
		else cout << t << " " << h << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
using namespace std;
#define ll long long
int main () {
  ll n, m;
  cin >> n >> m;
  if (n > m) {
    swap(n, m);  
  }  
  if (n == 1) {
    if (m < 2) {
      cout << m*n << endl;
    }
    else {
      cout << m*n-2 << endl;  
    }
  }
  else {
    cout << m * n - (n * 2 + m * 2 - 4) << endl;  
  }
}

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

int main() {
  //input & calc
  int five_count = 0;
  int seven_count = 0;
  int v;
  rep(i,3) {
    cin >> v;
    switch(v) {
      case 5:
        five_count++;
        break;
      case 7:
        seven_count++;
        break;
      default:
        break;
    }
  }
  //calc
  string answer = ( five_count == 2 && seven_count == 1 ) ? "YES" : "NO";
  //output
  cout << answer << endl; 
}

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

struct work{
    int time;
    int limit;

    work(int inputted_time, int inputted_limit){
        time = inputted_time;
        limit = inputted_limit;
    }
    bool operator<(const work &another) const{
        return limit < another.limit;
    };
};

int main(){
    int n;
    cin >> n;
    int a[n+1];
    int b[n+1];
    vector<work> worklist;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
        worklist.push_back(work(a[i], b[i]));
    }
    sort(worklist.begin(), worklist.end());
    int now = 0;
    string ans = "Yes";
    for(int i = 0; i < worklist.size(); i++){
        now += worklist[i].time;
        if(now > worklist[i].limit){
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int a, b;
    char o;
    cin >> a >> o >> b;
    if (o == '+') {
        cout << a + b << endl;
    }
    else {
        cout << a - b << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+5;
int a[N],x,n,mn[N];
int main()
{
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),mn[i]=1e9+1;
    ll ans=1e18;
    for(int i=0;i<n;i++)
    {
        ll sum=1ll*i*x;
        for(int j=1;j<=n;j++)
        {
            mn[j]=min(mn[j],a[(j+i-1)%n+1]);
            sum+=mn[j];
        }
        ans=min(ans,sum);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 2304
from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
    from io import BytesIO as stream
else:
    from io import StringIO as stream
 
 
if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)
 
        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)
 
        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)
 
    input = raw_input
    range = xrange
 
    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip
 
 
def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.
 
    Args:
        sync (bool, optional): The new synchronization setting.
 
    """
    global input, flush
 
    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')
 
        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

def main():
    # sys.stdin  = open("input.txt")
    n=int(input())
    arr=[]
    for i in range(n):
        a=list(map(int,input().split()))
        arr.append(a[:])
    for i in range(n-2):
        if arr[i][0]==arr[i][1] and  arr[i+1][0]==arr[i+1][1] and  arr[i+2][0]==arr[i+2][1]:
            print("Yes")
            return
    print("No")

if __name__ == '__main__':
    sync_with_stdio(False)
    main()

Measured memory_bytes: 68124
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=0
for i in range(n):
  ans+=B[A[i]-1]
  if i>0 and A[i]==A[i-1]+1:
    ans+=C[A[i-1]-1]


print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int x, a; cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int P = scanner.nextInt();
    char[] S = scanner.next().toCharArray();
    int[] digits = new int[N];
    for (int i = 0; i < N; i++) digits[i] = S[i] - '0';

    long res = 0;
    if (P == 2 || P == 5) {
      for (int i = N - 1; i >= 0; i--) {
        if (digits[i] % P == 0) res += i + 1;
      }
    } else {
      Map<Long, Integer> freq = new HashMap<>();
      long num = 0;
      freq.put(0L, 1);
      for (int i = N - 1; i >= 0; i--) {
        num += modpow(10, N - i - 1, P) * digits[i] % P;
        num %= P;
        res += freq.getOrDefault(num, 0);
        freq.put(num, freq.getOrDefault(num, 0) + 1);
      }
    }
    System.out.println(res);
  }

  private static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }
}


Measured memory_bytes: 45924
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,a[1000002],m,k;
int main(){
	n=read(),m=read();k=read();
	printf("%d",((n-1)/m+1)*k);
}

Measured memory_bytes: 1604