akhauriyash/Code-Regression huggingface dataset:
N,M = list(map(int, input().split()))
A = set([int(input()) for _ in range(M)])
mod = 10**9 + 7

ans = [1]*(N+1) + [0] # ans[n]: n段目まで行く数

for n in range(1,N+1):
  if n in A:
    ans[n] = 0
  else:
    ans[n] = (ans[n-1] + ans[n-2])%mod

print(ans[N])

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

queue<char> toQueue(string s){
	queue<char> q;
	for(int i=0;i<s.length();i++) q.push(s.at(i));
	return q;
}

int main(void){
	char center;
	string s;
	queue<char> r,g;

	while(1){
		if(cin>>s && s=="-") break;

		r = toQueue(s);
		cin>>s; g = toQueue(s);
		cin>>s;

		center = g.front(); g.pop();
		while(!g.empty() || !r.empty()){
			if(s.find(center,0) == string::npos){
				cout<<center;
				center = g.front(); g.pop();
			}
			else{
				center = r.front(); r.pop();
			}
		}
		cout<<center<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <set>
#include <queue>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, n, ans = 0, a;
  scanf("%lld", &n);
  multiset<ll> s;
  priority_queue<ll> q;
  bool flg[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a), flg[i] = true, s.insert(a), q.push(a);
  while(q.size()){
    a = q.top(), q.pop();
    if(s.find(a) == s.end()) continue;
    s.erase(s.find(a));
    ll now = 1;
    while(now <= a) now *= 2;
    now -= a;
    if(*s.lower_bound(now) == now) s.erase(s.find(now)), ++ans;
  }
  printf("%lld", ans);
  return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int64_t> A(n);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());

    if (any_of(A.begin(), A.end(), [](auto &a){return a == 0;})){
        puts("0");
        return 0;
    }

    int64_t ans = 1;
    int64_t b = 1e18;
    for (const auto &a: A){
        if (ans > b / a){
            puts("-1");
            return 0;
        }
        ans *= a;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4048
#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<int,int>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int n, k;
    cin >> n >> k;
    k = min(k,n-1);
    combination c(n);
    mint ans = 0;
    for (int i = 0; i <= k; i++) {
        ans += c(n,i) * c(n-1,i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6376
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    a, b, k = list(map(int, readline().split()))
    st = set()
    for i in range(a, min(a + k, b + 1)):
        st.add(i)
    for i in range(b, max(b - k, a - 1), - 1):
        st.add(i)
    for v in sorted(st):
        print(v)


if __name__ == '__main__':
    solve()


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

int main() {
  const int MAX = 1000000;
  const int SQRT = (int)std::sqrt(MAX);
  bool isPrime[MAX];
  for (int i = 0; i < MAX; i++) {
    isPrime[i] = true;
  }
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < SQRT; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  int n;
  while (std::cin >> n) {
    int cnt = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) cnt++;
    }
    std::cout << cnt << std::endl;
  }
}


Measured memory_bytes: 4004
N = int(input())
dice = [tuple(map(int, input().split())) for _ in range(N)]
count = 0
for d1, d2 in dice:
    if d1 != d2:
        count = 0
        continue
    else:
        count += 1
    if count == 3:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 9176
import java.util.Arrays;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        StringBuffer buff = new StringBuffer();
        String a[] = new String[N];
        for(int i = 0;i < a.length;i++){
            a[i] = sc.next();
        }
        Arrays.sort(a);
        for(int i = 0;i < N;i++){
            buff.append(a[i]);
        }
        System.out.println(buff);
    }
}


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

int main(){
    int x = -1,y = -1;
    while(true){
        cin >> x >> y;
        if(x==0 && y==0){
            break;
        }
        if(x<=y){
            cout << x << " " << y << endl;
        }
        if(x>y){
            cout << y << " " << x << endl;
        }
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  int N, W;
  cin >> N >> W;
  ll dp[110][110000];
  // dp[i+1][v]: i番目までの商品を使って価値vとなるときの最小の重み
  // dp[i+1][v] = min(dp[i][v], dp[i][v-v[i]] + w[i]);
  // 答えはfor(i=0...vmax*N) if(dp[N][i]!=INF) ans = i;とかで求める
  const ll INF = 1e10;
  for(int i=0; i<110; i++) for(int j=0; j<110000; j++) dp[i][j] = INF;

  ll w[N];
  ll v[N];
  for(int i=0; i<N; i++) cin >> w[i] >> v[i];

  dp[0][0] = 0; //でいいのか？
  for(int i=0; i<N; i++){
    for(int j=0; j<=1000*N; j++){
      if(j >= v[i]){
        dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]);
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
      }else dp[i+1][j] = dp[i][j];
    }
  }
  
  ll ans = 0;
  for(int j=0; j<=N*1000; j++){
    if(dp[N][j] <= W) ans = j;
  }
  
  cout << ans << endl;
  return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> num(m);
    for(int i = 0;i < m;i ++){
        cin >> num[i].first;
        if(num[i].first==8) num[i].second=7;
        if(num[i].first==9||num[i].first==6) num[i].second=6;
        if(num[i].first==5||num[i].first==3||num[i].first==2) num[i].second=5;
        if(num[i].first==4) num[i].second=4;
        if(num[i].first==7) num[i].second=3;
        if(num[i].first==1) num[i].second=2;
    }
    sort(num.begin(),num.end());
    string dp[10001];
    fill(dp,dp+10001,'X');
    for(int i = 0;i < m;i ++){
        dp[num[i].second] = to_string(num[i].first);
    }
    for(int i = 0;i < 10001;i ++){
        for(int j = 0;j < m;j ++){
            if(i-num[j].second>=0&&dp[i-num[j].second]!="X"){
                string s = to_string(num[j].first) + dp[i-num[j].second];
                if(dp[i].size()<=s.size())dp[i] = s;
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 32384
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int n, A[CMax], ats;
string S;

int main() {
    cin >> S;

    for (int i = 0; i < S.length()-1; i++) {
        if (S[i] == 'A' && S[i+1] == 'C') {
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 a,b,c;
    cin >> a >> b >> c;
    Yes(c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
int main()
{
    string a;
    getline( cin, a );
    transform( begin( a ), end( a ), begin( a ), ::toupper );
    REP( i, (int)a.size() )
    {
        if( i == 0 || a[ i - 1 ] == ' ' )
        {
            cout << a[ i ];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>

using namespace std;

int N;
map<int, int> mp;

int main(){
	cin >> N;
	int a;
	for(int i = 0; i < N; i++){
		cin >> a;
		if(mp.find(a) == mp.end()){
			mp[a] = 1;
		}else{
			mp[a]++;
		}
	}
	int ans = 0;
	for(map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){
		if(it->second % 2 == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4864
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

int f(int x) {
  int tot = 0;
  while (x > 0) {
    tot += x % 10;
    x /= 10;
  }
  return tot;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int mi = 1e8;
  REP(a, 1, n) {
    int b = n - a;
    mi = min(mi, f(a) + f(b));
  }
  cout << mi << endl;
}


Measured memory_bytes: 892
def make_bit(n):
    bit = []
    for i in range(2**n):
        bit.append(bin(i)[2::])
    i = 0
    while i < len(bit):
        while len(bit[i]) < len(bin(2**n-1)[2::]):
            bit[i] = "0" + bit[i]
        i += 1

    return bit

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

c = [list(input()) for _ in range(h)]

h_pats = make_bit(h)
w_pats = make_bit(w)
ans = 0
for h_pat in h_pats:
    for w_pat in w_pats:
        cnt = 0
        for i in range(h):
            for j in range(w):
                if h_pat[i] == "1" or w_pat[j] == "1":
                    continue
                if c[i][j] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Measured memory_bytes: 73888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pi 3.14159265358979323846
#define mod 1000000007
int main()
{
    IOS;
    ll a,b,c,d,e,cnt=7;
    cin>>a;
    string A;
    cin>>A;
    ll W=0,R=0;
    for(b=0;b<a;b++)
    {
        if(A[b]=='R') 
        {
            R++;
        }
    }
    for(b=0;b<R;b++)
    {
        if(A[b]=='W') 
        {
            W++;
        }
    }
    cout<<W<<endl;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define INF 0x3f3f3f3f
#define MS(x, i) memset(x, i, sizeof x)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define MOD 1000000007
#define NOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


int a[MAXN];
int dp[MAXN];

inline ll read() {
    ll ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-') sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        ret = ret*10 + ch - '0';
        ch = getchar();
    }

    return ret*sgn;
}

int main()
{
     NOS
    int n;
    cin >> n;
    int flag = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if(a % 2 == 0)
        {
            if(a % 3 != 0 && a % 5 != 0)
                flag = 1;
        }
    }
    if(!flag)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;
}


Measured memory_bytes: 256
#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 <array>
#include <bitset>
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define inf 0x3f3f3f3f3f3f3f3f
#define endl '\n'
using namespace std;

signed main() {
    fastio;
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int maxi = b * d;
    maxi = max(b * c, maxi);
    maxi = max(c * a, maxi);
    maxi = max(a * d, maxi);
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

bool coinuv[600][600];
int rua[601][601];
int rub[601][601];

signed main() {
    int H, W;
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            char c;
            cin >> c;
            if (c == '#')coinuv[i - j + 300][i + j] = true;
        }
    }
    int ans = 0;
    rep(i, 600) {
        rep(j, 600) {
            if (coinuv[i][j]) {
                for (int k = 1; i - k >= 0; ++k) {
                    if (coinuv[i - k][j]) {
                        if (j + k < 600 && coinuv[i][j + k])ans++;
                        if (j - k >= 0 && coinuv[i][j - k])ans++;
                    }
                }
                for (int k = 1; i + k < 600; ++k) {
                    if (coinuv[i + k][j]) {
                        if (j + k < 600 && coinuv[i][j + k])ans++;
                        if (j - k >= 0 && coinuv[i][j - k])ans++;
                    }
                }
            }
        }
    }

    rep(i, 600) {
        rep(j, 600) {
            rua[i + 1][j] = rua[i][j] + coinuv[i][j];
            rub[i][j + 1] = rub[i][j] + coinuv[i][j];
        }
    }

    rep(i, 600) {
        rep(j, 600) {
            if (coinuv[i][j]) {
                for (int k = 1; i + k < 600; ++k) {
                    if (coinuv[i + k][j]) {
                        //i+1~i+k-1[j+-k]
                        if (j + k < 600)ans += rua[i + k][j + k] - rua[i + 1][j + k];
                        if (j - k >= 0)ans += rua[i + k][j - k] - rua[i + 1][j - k];
                    }
                }
                for (int k = 1; j + k < 600; ++k) {
                    if (coinuv[i][j + k]) {
                        //[i+-k]j+1~j+k-1
                        if (i + k < 600)ans += rub[i + k][j + k] - rub[i + k][j + 1];
                        if (i - k >= 0)ans += rub[i - k][j + k] - rub[i - k][j + 1];
                    }
                }
            }
        }
    }

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


Measured memory_bytes: 6272
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int h,w;
    cin >>h>>w;
    string s[h],ww="";
    for(int i=0;i<w;i++){
        ww+=".";
    }
    for(int i=0;i<h;i++){
        cin>>s[i];
        if(s[i]==ww){
            i--;
            h--;
        }
    }
    
    for(int i=0;i<w;i++){
        bool b =true;
        for(int j=0;j<h;j++){
            if(s[j][i]=='#'){
                j=h;
                b=false;
                
            }
        }
        if(b){
            for(int j=0;j<h;j++){
                s[j] = s[j].substr(0,i)+s[j].substr(i+1);
            }
            i--;
            w--;
        }
    }
    
    
    
    for(int i=0;i<h;i++){
        cout<<s[i]<<endl;
    }
    
}


Measured memory_bytes: 256
Q,H,S,D=map(int,input().split())
N=int(input())
N2,N1=divmod(N,2)
tmp2=min(8*Q,4*H,2*S,D)
tmp1=min(4*Q,2*H,S)
ans2=N2*tmp2
ans1=N1*tmp1
ans=ans1+ans2
print(ans)


Measured memory_bytes: 9072
#include <iostream>
#include <string>
#include <map>
#include <queue>

using namespace std;
int dx[4] = {1, -1, 4, -4};
map<string,int> step;


void bfs(void)
{
  queue<string> state;
  state.push("01234567");
  while(!state.empty())
  {
    string v=state.front();
    state.pop();
    int pos = 0;
    for(int i = 0; i < 8; ++i)
	{
      if(v[i] == '0')
	  {
		  pos = i;
	  }
	}

    for(int i = 0; i < 4; ++i)
	{
      if(0 <= pos + dx[i] && pos + dx[i] < 8 && !(pos == 3 && i == 0) && !(pos == 4 && i == 1))
	  {
		string u = v;
		swap(u[pos], u[pos + dx[i]]);

		if(step[u] == 0)
		{
		  state.push(u);
		  step[u] = step[v] + 1;
		}
      }
    }
  }
}

int main()
{
  step["01234567"] = 1;
  bfs();
  string s;
  while(cin >> s)
  {
	char c;
    for(int i = 0; i < 7; ++i)
	{
		cin >> c;
		s += c;
    }
    cout << step[s] - 1 << endl;
  }
  return(0);
}

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

def main():
    N, K = map(int, input().split())
    hList = list(map(int, input().split()))
    ans = 0
    hList.sort(reverse=True)
    for h in hList:
        if h >= K:
            ans += 1
        else:
            break
    print(ans)

if __name__ == '__main__': main()

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

using namespace std;

int main(){
        int H, W;
        string str[111];
        cin>>H>>W;
        for(int i=1;i<=H;i++){
                cin>>str[i];
        }
        for(int i=0;i<W+2;i++){
                str[0]+='#';
                str[H+1]+='#';
        }
        for(int i=1;i<=H;i++){
                str[i].insert(str[i].begin(), '#');
                str[i]+='#';
        }
        for(int i=0;i<=H+1;i++){
                cout<<str[i]<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,m,n,k,l;
    scanf("%d %d",&m,&n);
    int x[m][n],y[n][1],z[m][1];
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            scanf("%d",&x[i][j]);
        }
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&y[i][0]);
    }
    for(i=0;i<m;i++)
    {
        z[i][1]=0;
        for(j=0;j<n;j++)
        {
           z[i][1]+=x[i][j]*y[j][0];
        }
        printf("%d\n",z[i][1]);
    }
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

signed main(){

    int N; cin >> N;
    if(N == 2){
        cout << -1 << endl;
        return 0;
    }

    int N0 = N;
    while(N0 > 4 && N0 % 2 == 0) N0 /= 2;
    mat ans(N0, vec(N0 - 1));
    if(N0 == 4){
        ans[0] = vec({1, 2, 3});
        ans[1] = vec({2, 3, 0});
        ans[2] = vec({3, 1, 0});
        ans[3] = vec({1, 0, 2});
    }else{
        REP(i, N0) REP(j, N0) ans[i][j] = (i + j + 1) % N0;
    }

    while(N0 < N){
        N0 *= 2;
        mat ans2(N0, vec(N0 - 1));
        REP(i, N0){
            ans2[i][0] = (i + 1) % N0;
            REP(j, N0 / 2 - 1){
                if(i % 2 == 0) ans2[i][j + 1] = ans[i / 2][j] * 2;
                else ans2[i][j + 1] = (i + 3 + 2 * j) % N0;
            }
            REP(j, N0 / 2 - 1){
                if(i % 2 == 1) ans2[i][j + N0 / 2] = ans[i / 2][j] * 2 + 1;
                else ans2[i][j + N0 / 2] = (i + 3 + 2 * j) % N0;
            }
        }
        ans = ans2;
    }
    REP(i, N){
        REP(j, N - 1) cout << ans[i][j] + 1 << " ";
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 512
def e_almost_everywhere_zero():
    N = input()
    K = int(input())

    def digit_dp(n):  # n は文字列で与える
        """n 以下の非負整数で、0でない数字がちょうど K 個あるような数の個数"""
        digit = len(n)

        dp = [[[0] * (K + 2) for j in range(2)] for i in range(digit + 1)]
        dp[0][0][0] = 1
        for i in range(digit):
            for j in range(2):
                for k in range(K + 1):
                    lim = 9 if j == 1 else ord(n[i]) - ord('0')
                    for d in range(lim + 1):
                        if d != 0:
                            t = k + 1
                            if t >= K + 2:
                                t = K + 1
                        else:
                            t = k
                        dp[i + 1][j or (d < lim)][t] += dp[i][j][k]
        return sum(dp[digit][j][K] for j in range(2))
    return digit_dp(N)

print(e_almost_everywhere_zero())

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N;
  vector<llong> A;

  cin >> N;
  A.resize(N);
  for (auto &in: A) {
    cin >> in;
  }

  map<llong, llong> m;
  llong ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += m[i - A[i]];
    ++m[i + A[i]];
  }
  
  cout << ans << endl;

  return 0;
}


/*

距離の絶対値が 2 値の和

ある Ai の 見る範囲 j は i - Ai <= j <= i + Ai

累積和っぽく解きたい

*/

Measured memory_bytes: 27368
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <limits>

using namespace std;

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

  int N;
  vector<long long> v;
  vector<vector<long long>> dp;
  vector<long long> dp2;

  std::cin >> N;
  v.resize(N);
  dp = vector<vector<long long>>(N, vector<long long>(N, 0));

  for (int i = 0; i < N; ++i)
  { 
    long long val;
    cin >> val;
    v[i] = val;
  }

  for (int i = N-1; i >= 0; --i)
  {
    for (int j = i; j < N; ++j)
    {   
      if (i == j) { dp[i][j] = v[i]; continue; }
      long long a = v[i] - dp[i+1][j];
      long long b = v[j] - dp[i][j-1];
      dp[i][j] = max(a, b); 
    }   
  }

  std::cout << dp[0][N-1];

  return 0;
}

Measured memory_bytes: 70784
N=int(input())
t,x,y=0,0,0
f=True
for i in range(N):
    ti,xi,yi=map(int,input().split())
    if ti-t<abs(xi-x)+abs(yi-y) or (ti-t)%2!=((xi-x)+(yi-y))%2:
        f=False
        break
    else:
        t,x,y=ti,xi,yi
print('Yes' if f else 'No')

Measured memory_bytes: 46184
N, A, B, C, D = map(int ,input().split())
S = list(input())

"""
基本的にはシャープが2連続するとだめ
ただし，片方が間に必ず入っている場合は，...が三連続するところがないとダメ
"""

if A<B and C>D:
    for i in range(B-2,D-1):
        if S[i:i+3] == [".", ".", "."]:
            print("Yes")
            exit()
    print("No")
    exit()
elif A>B and C<D:
    for i in range(A-2,C-1):
        if S[i:i+3] == [".", ".", "."]:
            print("Yes")
            exit()
    print("No")
    exit()
else:
    for i in range(min(A,B)-1, max(C,D)-1):
        if S[i] == S[i+1] == "#":
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 4868
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	vector<long long> b(n);
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		b[i] = a[i] - (i + 1);
		sum += b[i];
	}
	
	sort(b.begin(), b.end());
	long long t = b[n / 2];	
	
	long long mid = sum / n;
	long long ans1 = 0;
	long long ans2 = 0;
	long long ans3 = 0;
	long long tmp = mid - 1;
	long long ttmp = mid + 1;
	for(int i = 0; i < n; i++)
	{
		ans1 += (b[i] - t > 0) ? b[i] - t : -(b[i] - t);
		//ans2 += (b[i] - tmp > 0) ? b[i] - tmp : -(b[i] - tmp);
		//ans3 += (b[i] - ttmp > 0) ? b[i] - ttmp : -(b[i] - ttmp);
	}
	
	//cout << ((ans1 > ans2 ? ans2 : ans1) > ans3 ? ans3 : (ans1 > ans2 ? ans2 : ans1)) << endl;
	cout << ans1 << endl;
	
	return 0;
}

Measured memory_bytes: 3328
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

pre=a[0]
ans=b[pre-1]
for i in range(1,n):
    now=a[i]
    ans+=b[now-1]
    if a[i]==pre+1:
        ans+=c[pre-1]
    pre=now
print(ans)


Measured memory_bytes: 3064
import numpy as np 
H, W = map(int, input().split())
S = (np.array([list(input()) for _ in range(H)]) == '.')
 

up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)
 
for i in range(H):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]
    
for i in range(W):
    left[:, i] = (left[:, i-1] + 1) * S[:, i]
    right[:, -i-1] = (right[:, -i] + 1) * S[:, -i-1]

print(np.max(up+down+left+right) - 3)

Measured memory_bytes: 219812
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if(H==0&&W==0) break;
    for(int j=1;j<=H;j++){
        for(int k=1;k<=W;k++){
            if(j%2==0 && k%2==1 || j%2==1 && k%2==0){
                cout << ".";
            }else if(j%2==0 && k%2==0 || j%2==1 && k%2==1){
                cout << "#";
            }
        }
        cout << endl;
    }
    cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int ans=0;
    if(n<k) ans+=n*x;
    if(k<=n) ans+= k*x+(n-k)*y;
    cout<< ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,rs;
    reverse(all(rs));
    cin >> s;
    rs = s;
    reverse(all(rs));
    string a,ra,b,rb;
    int N = s.size();
    rep(i,(N-1)/2){
        a.push_back(s[i]);
    }
    for(int i = (N+1)/2;i < N;i++){
        b.push_back(s[i]);
    }
    ra = a; rb = b;
    reverse(all(ra));
    reverse(all(rb));
    if(s == rs&&a == ra && b == rb) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    // a+b + 2*sqrt(ab) < c
    ll tmp = c - (a+b);
    if (tmp >= 0 && a*b*4 < tmp*tmp)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,j,n,u,k,num,v[101][101];
  
  for(i=0;i<101;i++){
    for(j=0;j<101;j++){
      v[i][j]=0;
    }
  }
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
      scanf("%d %d",&u,&k);
      for(j=0;j<k;j++){
      scanf("%d",&num);
      v[u][num]=1;
      }
    }

    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	if(j>1) printf(" ");
	printf("%d",v[i][j]);
      }
      printf("\n");
    }
  
  return 0;
}



Measured memory_bytes: 2148
from heapq import heapify, heappop, heappush
n = int(input())
v = list(map(int, input().split()))

heapify(v)
for i in range(n-1):
  a = heappop(v)
  b = heappop(v)
  heappush(v, (a+b)/2)
  
print(heappop(v))



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

int main()
{
	ll a,b;
	char c;
	cin>>a>>c>>b;
	if(c=='+')cout<<a+b<<endl;
	else cout<<a-b<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
  k = int(input())
  a, b = map(int, input().split())
  
  i = 0
  res = 0
  while True:
    i += 1
    if res >= a:
      break
    res = k*i
  
  print("OK" if (res >= a and res <= b) or (a==b and a%k==0) else "NG")
  
if __name__ == '__main__':
  main()


Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[110];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>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++){
				if(a[i]==a[j]||a[i]==a[k]||a[j]==a[k])continue;
				if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
using namespace std;
int n,m;
int a[400][400];
int v[400],vv[400];
stack<int> st[305];

int main()
{
	int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	for (i=1;i<=n;i++)
	{
		for (j=m;j>=1;j--)
			st[i].push(a[i][j]);
	}
	int x=0,maxnum;
	memset(vv,0,sizeof(vv));
	for (j=1;j<=n;j++)
		vv[st[j].top()]++;
	for (j=1;j<=m;j++)
		if (vv[j]>x)
		{
			x=vv[j];
			maxnum=j;
		}
	int ans=x;
	for (i=1;i<=m-1;i++)
	{
		v[maxnum]=1;
		for (j=1;j<=n;j++)
		{
			while (v[st[j].top()]==1) st[j].pop();
		}
		x=0;
		memset(vv,0,sizeof(vv));
		for (j=1;j<=n;j++)
			vv[st[j].top()]++;
		for (j=1;j<=m;j++)
			if (vv[j]>x)
			{
				x=vv[j];
				maxnum=j;
			}
		ans=min(ans,x);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){

	int r, w, C, R, ans;
	while(1){
		cin>>r>>w>>C>>R;
		if(r == 0 && w == 0 && C == 0 && R == 0) break;
		// r + R * ans / w > C 
		if(w * C - r <= 0) ans = 0;
		else if ((w * C - r) % R == 0) ans = (w * C - r) / R;
		else ans = (w * C - r) / R + 1;
		cout<<ans<<endl;
	}

	return 0;
} 



Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n, k;
  cin >> n >> k;
  vector<Pll> a;
  for (ll i = 1; i <= n;i++){
    a.pb(mp(0, i));
  }
  ll total = 0;
  rep(i, n){
    ll A;
    cin >> A;
    a[A - 1].F++;
    if(a[A-1].F==1){
      total++;
    }
  }
  sort(all(a));
  ll count = 0;
  ll kinds = total - k;
  rep(i, n){
    if(kinds<=0){
      break;
    }
    if(a[i].F==0){
      continue;
    }
    else{
      count += a[i].F;
      kinds--;
    }
  }
  print(count);
}

Measured memory_bytes: 7480
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<stdint.h>
#include<limits.h>

#include<sstream>
using namespace std;

 
int main() {
	string s, c;
	int nr = 0;
	cin >> s >> c;
	for (int i = 0;i <= 2;i++)
		if (s[i] == c[i])
			nr++;
	cout << nr;
	return 0;
}

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

int main() {
    int h,w,k;cin>>h>>w>>k;
    string s[h];
    for (int i=0;i<h;i++)
        cin>>s[i];
    int ans=0;
    for (int i=0;i<1<<h;i++)
        for (int j=0;j<1<<w;j++) {
            int c=0;
            for (int l=0;l<h;l++)
                for (int m=0;m<w;m++)
                    if (~i&1<<l&&~j&1<<m&&s[l][m]=='#')
                        c++;
            if (c==k)
                ans++;
        }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <math.h>
void chk(float x1,float y1,float x2,float y2,float x3,float y3);
int main(){
	int sn;
	float x1,y1,x2,y2,x3,y3;
	int i;

	scanf("%d",&sn);
	for(i=1;i<=sn;i++){
		scanf("%f %f %f %f %f %f ",&x1,&y1,&x2,&y2,&x3,&y3);
		chk(x1,y1,x2,y2,x3,y3);
	}
	return 0;
}

void chk(float x1,float y1,float x2,float y2,float x3,float y3){


	float a,b,c,d,e,f;
	float x,y;
	double R;

//	(x1,y1)(x2,y2) line
//	(y1-y2)X - (x1-x2)Y = (y1-y2)x2 - (x1-x2)y2
//	-> vertical & center-cross
//	(x1-x2)(X - (x1+x2)/2 ) + (y1-y2) (Y - (y1+y2)/2 ) =0
//	->
//	(x1-x2)X +(y1-y2)Y = (x1^2-x2^2)/2 + (y1^2-y2-2)/2

	a=x1-x2;
	b=y1-y2;
	c=x1*x1-x2*x2 + y1*y1-y2*y2;
	c=c/2.0;

	d=x3-x2;
	e=y3-y2;
	f=x3*x3-x2*x2 + y3*y3-y2*y2;
	f=f/2.0;

	x=(-e*c+b*f)/(-a*e+b*d);
	y=(+d*c-a*f)/(-a*e+b*d);

	R=sqrt((double)((x1-x)*(x1-x)+(y1-y)*(y1-y)));

	if(y<0.0005 && y>=-0.0005)y=0.0;
	if(y<0.0005 && y>=-0.0005)y=0.0;
	printf("%.3f %.3f %.3lf\n",x,y,R);
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

int n,m,nn,a[100010],b[100010],mna=1e9,mnb=1e9,ans,x,y,z;

int main()
{
	cin>>n>>m>>nn;
	rep(i,n)
	{
		cin>>a[i];
		mna=min(mna,a[i]);
	}
	rep(i,m)
	{
		cin>>b[i];
		mnb=min(mnb,b[i]);
	}
	ans=mna+mnb;
	rep(i,nn)
	{
		cin>>x>>y>>z;
		x--;
		y--;
		ans=min(ans,a[x]+b[y]-z);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
s = input()
x = ""
y = ""
x_con = 0
y_con = 0
for i in range(len(s)):
  if i % 2 == 0:
    x += "0"
    y += "1"
  else:
    x += "1"
    y += "0"

for i in range(len(s)):
  if s[i] != x[i]:
    x_con += 1
  if s[i] != y[i]:
    y_con += 1
  
print(min(x_con, y_con))

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

int ok(int P,int n,int w[],int k){
  int i=0;
  for(int j=0;j<k;j++){
    int s=0;
    while(s+w[i]<=P){
      s+=w[i];
      i++;
      if(i==n) return n;
    }
  } 
  return i;
}
int main(){
  int n,k;
  cin>>n>>k;
  int w[n];
  for(int i=0;i<n;i++){
    cin>>w[i];
  }
  int l=0,h=1000000000;
  while(l+1<h){
    int m=(l+h)/2;
    if(ok(m,n,w,k)>=n) h=m; else l=m;
  }
  printf("%d\n",l+1);
  return 0;
}

Measured memory_bytes: 3580
unittest
{
	assert( [ "2 1 3 0", "AB", "AC" ].parse.expand.solve == "Yes\nA\nC" );
	assert( [ "3 1 0 0", "AB", "BC", "AB" ].parse.expand.solve == "No" );
	assert( [ "1 0 9 0", "AC" ].parse.expand.solve == "No" );
//	assert( [ "8 6 9 1", "AC", "BC", "AB", "BC", "AC", "BC", "AB", "AB" ].parse.expand.solve == "Yes\nC\nB\nB\nC\nC\nB\nA\nA" );
	assert( [ "8 6 9 1", "AC", "BC", "AB", "BC", "AC", "BC", "AB", "AB" ].parse.expand.solve == "Yes\nC\nC\nA\nC\nC\nC\nA\nB" );
	
	assert( [ "3 1 1 0", "AB", "BC", "AC" ].parse.expand.solve == "Yes\nB\nC\nA" );		// 追加ケース
	assert( [ "3 1 1 0", "AB", "AC", "BC" ].parse.expand.solve == "Yes\nA\nC\nB" );		// 追加ケース
	assert( [ "3 1 0 0", "AB", "BC", "AC" ].parse.expand.solve == "Yes\nB\nC\nA" );		// 追加ケース
}



import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nabc = input.front.split.to!( long[] );
	auto ss = new string[ nabc[ 0 ] ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front;
	}
	return tuple( nabc[ 1 .. $ ], ss );
}

auto solve( long[] abc, string[] ss )
{
	// 変数が3つしかないので貪欲でいける
	auto anss = new string[ ss.length ];
	foreach( i, s; ss )
	{
		auto xc = s[ 0 ];
		auto yc = s[ 1 ];
		auto xi = cast( long )( xc - 'A' );
		auto yi = cast( long )( yc - 'A' );
		if( abc[ xi ] <= 0 && abc[ yi ] <= 0 ) return "No";
		if( abc[ xi ] < abc[ yi ] )
		{
			abc[ xi ]++;
			abc[ yi ]--;
			anss[ i ] = s[ 0 .. 1 ];
		}
		else if( abc[ yi ] < abc[ xi ] )
		{
			abc[ xi ]--;
			abc[ yi ]++;
			anss[ i ] = s[ 1 .. 2 ];
		}
		else
		{
			if( ss.length <= i + 1 || ss[ i + 1 ][ 0 ] == xc || ss[ i + 1 ][ 1 ] == xc )
			{
				abc[ xi ]++;
				abc[ yi ]--;
				anss[ i ] = s[ 0 .. 1 ];
			}
			else
			{
				abc[ xi ]--;
				abc[ yi ]++;
				anss[ i ] = s[ 1 .. 2 ];
			}
		}
	}
	return format( "Yes\n%s", anss.join( "\n" ) );
}


Measured memory_bytes: 8340
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(10);

  int a,b;
  double k;
  cin >> a >> b;

  k = ((double)max(a,b) - min(a,b)) / 2;

  if (fmod(k,1.0) == 0) {
    cout << (int)k + min(a,b) << "\n";
  } else {
    cout << "IMPOSSIBLE" << "\n";
  }

  return 0;
}


Measured memory_bytes: 384
#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>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#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
int main(){
	int n;
	cin >> n;
	vector<vector<int>> gogo;
	map<int, int> aa;
	REP(i, n) {
		vector<int> nya;
		REP(q, 6) {
			int a, b;
			cin >> a >> b;
			nya.push_back(a * 60 + b);
			aa[a * 60 + b] = 1;
		}
		gogo.push_back(nya);
	}
	int ans = 0;
	for (auto i = aa.begin(); i != aa.end(); ++i) {
		for (auto q = aa.begin(); q != aa.end(); ++q) {
			for (auto j = aa.begin(); j != aa.end(); ++j) {
				int start_a = i->first;
				int start_b = q->first;
				int start_c = j->first;
				int as = 0;
				for (int t = 0; t < n; ++t) {
					if (gogo[t][0] <= start_a && start_a <= gogo[t][1] && gogo[t][2] <= start_b && start_b <= gogo[t][3] && gogo[t][4] <= start_c && start_c <= gogo[t][5]) {
						as++;
					}
				}
				ans = max(ans, as);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
#include<string>
#include<iomanip>
#define ll long long int 

using namespace std;
void x(ll a[],ll n){
    ll bb[n];
    for(ll i=0;i<n;i++)
    bb[i]=a[i];
    for(ll i=1;i<n;i++)
    if(i!=n-1)a[i]=bb[i-1];
    a[0]=bb[n-1];
}
int main()
{
	ll T,n;
   
	//cin>>T;
	//while(T--){
	    ll k,m,p;
	    //b,e=0,o=0,d=0,c=0;
	    cin>>n>>k>>p;
if(n*k<=p)cout<<n*k<<endl;
else cout<<p<<endl;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    string s;cin>>s;
    ll ans=0;rep(i,0,s.size()) {if(s[i] == '+') ans++; else ans--;}
    cout << ans << ednl;
}


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

int main(){
 int N;
 int a[100];
 int c;
 int i;
 int temp;
 cin>>N;
 for(c=0;c<N;c++){
 	cin>>a[c];
 }
 for(c=0;c<N-1;c++){
 	for(i=0;i<N-1;i++){
		if(a[i]<a[i+1]){
			temp=a[i+1];
			a[i+1]=a[i];
			a[i]=temp;
		}
	}
 }
 cout<<a[0]-a[N-1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define data_type long long
#define endl "\n"
vector<data_type> digit(11,0);
bool check(data_type n)
{
   while(n)
   {
      if(digit[n%10])
      return 1;
      n/=10;
   }
   return 0;
}
int  main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,i;
    cin>>n>>k;

   while(k--)
      cin>>i,digit[i]=1;
    while(check(n))
   n++;

   cout<<n<<endl;



    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
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;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};
int N, M;
int main() {
  cin >> N >> M;
  UnionFind uf(N);
  int ans = N;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (!uf.same(a, b))
      ans--;
    uf.unite(a, b);
  }
  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 3784
import java.util.Scanner;
import java.io.*;
import java.lang.Math;

public class  Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		do{
			int x = i;
			if(x%3==0){
				System.out.print(" "+i);
				continue;
			}
			do{
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}
				x/=10;
			}while(x!=0);
		}while(++i<=n);
		System.out.println();
	}
}

Measured memory_bytes: 28496
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }

double pi = 3.14159265358979323846264338327950288419716939937510582097494459230;
int modulo = 1e9 + 7;

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s; cin >> s;
    int n = s.length();
    string ans = "Good";
    FOR(i,1,n)
    {
        if (s[i] == s[i-1])
        {
            ans = "Bad";
            break;  
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toInt()}
    val A = IntArray(n + 2)
    for(i in 1 .. n){
        A[i] = a[i - 1]
    }
    var sum = 0
    for(i in 0 .. n){
        sum += Math.abs(A[i + 1] - A[i])
    }
    for(i in 1 .. n){
        println(sum - Math.abs(A[i] - A[i - 1]) - Math.abs(A[i + 1] - A[i]) + Math.abs(A[i + 1] - A[i - 1]))
    }
}

Measured memory_bytes: 54952