akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int>data(4);
    rep(i,4)data[i] = 0;
    rep(i,n){
        string s;
        cin >> s;
        if(s == "AC")data[0]++;
        else if(s == "WA")data[1]++;
        else if(s == "TLE")data[2]++;
        else if(s == "RE")data[3]++;
    }
    cout << "AC x  " << data[0] << endl;
    cout << "WA x " << data[1] << endl;
    cout << "TLE x " << data[2] << endl;
    cout << "RE x " << data[3] << endl;
    return 0;
}

Measured memory_bytes: 3632
from itertools import product
import re
N = int(input())
MOD = 10 ** 9 + 7


dp = [{''.join(last_3): 0 for last_3 in product('AGCT', repeat=3)} for i in range(N + 1)]
dp[0]['TTT'] = 1
NG_pattern = r'AGC.*|ACG.*|GAC.*|A.GC|AG.C|'

for i in range(N):
    for last_3 in product('AGCT', repeat=3):
        last_3 = ''.join(last_3)
        for next_s in 'AGCT':
            if re.match(NG_pattern, last_3 + next_s).group():
                continue
            else:
                dp[i + 1][last_3[1:] + next_s] += dp[i][last_3]
                dp[i + 1][last_3[1:] + next_s] %= MOD


ans = 0
for key, value in dp[-1].items():
    if re.match(NG_pattern, key).group():
        continue
    ans += value
    ans %= MOD
print(ans)


Measured memory_bytes: 4084
N = int(input())
Alist = list(map(int, input().split()))
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b <= 0:
        return a
    else:
        return gcd(b, a%b)
left = [0, Alist[0]]
right = [Alist[-1]]
for i in range(N-1):
    left += [gcd(Alist[i+1], left[-1])]
    right += [gcd(Alist[N-i-2], right[-1])]
right = right[::-1] + [0]
print(max([gcd(left[i], right[i+1]) for i in range(N)]))

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

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

    int ans = 0;
    for(int i = 1; i <= N; i+=2){
        int cnt = 0;
        for(int j = 1; j <= i; j++){
            if(i % j == 0) cnt++;
        }
        if(cnt == 8) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,m;
int a[6];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>m;
	memset(a,-1,sizeof(a));
	int flag=1;
	while(m--){
		int x,y;
		cin>>x>>y;
		if(x<1||x>n) flag=0;
		if(a[x]==-1||a[x]==y) a[x]=y;
		else flag=0;
	}
	if(a[1]==0&&n!=1) flag=0;
	if(a[1]==-1) 
		if(n==1) a[1]=0;
		else a[1]=1;
	for(int i=2;i<=n;i++){
		if(a[i]==-1) a[i]=0;
	}
	if(flag){
		for(int i=1;i<=n;i++) cout<<a[i];
		cout<<endl;
	}else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl


int main() {
	lint H, W, M;
	cin >> H >> W >> M;
	vector<lint>h(M);
	vector<lint>w(M);
	rep(i, M) {
		cin >> h[i] >> w[i];
	}
	vector<lint>I(H);
	vector<lint>J(W);
	rep(i, M) {
		I[h[i] - 1]++;
		J[w[i] - 1]++;
	}
	set<lint>MI;
	set<lint>MJ;
	lint mi = 0;
	lint mj = 0;
	rep(i, H) {
		mi = max(mi, I[i]);
	}
	rep(i, W) {
		mj = max(mj, J[i]);
	}
	rep(i, H) {
		if (I[i] == mi) {
			MI.insert(i);
		}
	}
	rep(i, W) {
		if (J[i] == mj) {
			MJ.insert(i);
		}
	}
	lint a = MI.size() * MJ.size();
	lint b = 0;
	rep(i, M) {
		if (MI.count(h[i]-1) && MJ.count(w[i]-1)) {
			b++;
		}
	}
	if (a == b) {
		cout << mi + mj - 1 << endl;
	}
	else {
		cout << mi + mj << endl;
	}
}

Measured memory_bytes: 40668
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}




int main() {

	ll X, Y;
	cin >> X >> Y;
	if (abs(X - Y) <= 1)cout << "Brown" << endl;
	else cout << "Alice" << endl;
}

Measured memory_bytes: 3576
package main

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

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

var count int

func calc(n int) {
	if n%2 == 0 {
		count++
		calc(n / 2)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := getInt()

	for i := 0; i < n; i++ {
		a := getInt()
		calc(a)
	}
	fmt.Println(count)
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
string s="",t="";
std::cin >> s>>t;
rep(i,t.size()){
  std::cout << s[i]<<t[i];
}
if(s.size()>t.size())std::cout << s[s.size()-1];
std::cout  << '\n';
}


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

int main() {
    int Q;
    cin>>Q;
    int l[Q], r[Q];
    for(int i=0;i<Q;++i){
        cin>>l[i]>>r[i];
    }
    int N = 1e5;

    bool isPrime[N+1];
    for(int i=0;i<=N;++i){
        isPrime[i] = true;
    }
    isPrime[0] = false;
    isPrime[1] = false;

    for(int i=2;i*i<=N;++i){
        if(isPrime[i]){
            for(int j=2;i*j<=N;++j){
                isPrime[i*j] = false;
            }
        }
    }
    /**
    for(int i=0;i<=N;++i){
        cout<<i<<" "<<isPrime[i]<<endl;
    }
    **/

    bool like2017[N+1];
    for(int i=0;i<=N;++i){
        if(isPrime[i] & isPrime[(i+1)/2] & i%2==1){
            like2017[i] = true;
        }
        else like2017[i] = false;
    }
    /**
    for(int i=0;i<=N;++i){
        cout<<i<<" "<<like2017[i]<<endl;
    }
    **/
    int like2017sum[N+1];
    like2017sum[0] = 0;
    for(int i=1;i<=N;++i){
        if(like2017[i]){
            like2017sum[i] = like2017sum[i-1] + 1;
        }
        else {
            like2017sum[i] = like2017sum[i-1];
        }
    }
    /**
    for(int i=0;i<=N;++i){
        cout<<i<<" "<<like2017sum[i]<<endl;
    }
    **/
    for(int i=0;i<Q;++i){
        cout<<like2017sum[r[i]] - like2017sum[l[i]-1]<<endl;
    }
}


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

#define ll   long long int
#define ull   unsigned long long int
#define PI 3.14159265358979
#define zig ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

const ll N=1e18;

int main()
{
    zig
    ull n, a, res=1, i;
    bool flag=false;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a;
        if(a==0)
        {
            res=0;
            flag=false;
        }
        if(res==0)
            continue;
        if(flag)
            continue;
        if(N/res>=a)
            res*=a;
        else
            flag=true;
    }
    if(flag)
        cout<<-1;
    else
        cout<<res<<'\n';
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back
 
typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << 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;
}();

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> arr(n, 0);
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    int ans = INT_MAX;
    for(int i = 0; i <= n-k; i++) {
        if (arr[i] <= 0 && arr[i+k-1] >= 0) {
            int m = min(abs(arr[i]), abs(arr[i+k-1]));
            int M = max(abs(arr[i]), abs(arr[i+k-1]));
            ans = min(ans, m*2 + M);
        } else if (arr[i] > 0) {
            ans = min(ans, arr[i+k-1]);
        } else if (arr[i+k-1] < 0) {
            ans = min(ans, abs(arr[i]));
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
s = input()
n = int(input())
for _ in range(n):
    in_s= input().split()
    command = str(in_s[0])
    a, b = int(in_s[1]), int(in_s[2])
    if(command == "print"):
        print(s[a:b+1])
    elif(command == "reverse"):
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    else:
        p = str(in_s[3])
        s = s[:a] + p + s[b+1:]

Measured memory_bytes: 7632
#include <bits/stdc++.h>
using namespace std;
int amaji(int y,int x,int n1)
{
    if(x%n1==y%n1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
    
}
int main(void){ /*メイン関数を入れる*/
    int n,t[100000],x[100000],y[100000],i=0,z,k;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }
    if(t[0]%2!=(x[0]+y[0])%2)
    {
         cout << "No" << endl;
         return 0;
    }     
    else if(t[0]<x[0]+y[0])
    {
         cout << "No" << endl;
         return 0;
    }

    for(i=1;i<n;i++)
    {
        z=t[i]-t[i-1];
        
        if(z%2!=abs((x[i]+y[i])-(x[i-1]+y[i-1]))%2)
        {
            cout << "No" << endl;
            return 0;
        }
        else if(z<abs((x[i]+y[i])-(x[i-1]+y[i-1])))
        {
            cout << "No" << endl;
            return 0;
        }
    }
            
    cout << "Yes" << endl;
    //わからへん;;
    //もうやりたくないぜ。
    //WAでるな yattaka!?
    //uyeshota
    //※これはA問題ではありません

    return 0;

}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
	SPEED
	int a;
	cin >> a;
	int result = a + (a*a) + (a*a*a);
	cout << result;
	return 0;
}

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

#define MOD 1000000007

int s;

long long memo[2005];
long long dp(int rem) {
	if (rem == 0) return 1;
	if (memo[rem] != -1) return memo[rem];
	memo[rem] = 0;
	for (int i = 3; i <= rem; i++) {
		memo[rem] += dp(rem - i);
		memo[rem] %= MOD;
	}
	return memo[rem];
}

int main() {
	scanf("%d", &s);
	memset(memo, -1, sizeof memo);
	printf("%lld\n", dp(s));
	return 0;
}


Measured memory_bytes: 3824
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    s = list(input())
    string = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ'*2)
    for i in range(len(s)):
        s[i] = string[string.index(s[i])+n]
    print(*s, sep='')
    
if __name__ == '__main__':
    main()

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

typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a < c && c < b) || (b < c && c < a))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3500
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Union-Find
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) {}
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        uf.unite(a, b);
    }
    
    int ans = 0;
    rep(i, n) chmax(ans, uf.size(i));
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 3984
#C
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
# print(ab)
t=[0]*n
for i in ab:
    # print(i)
    if h[i[0] - 1] > h[i[1] - 1]:
        t[i[1] - 1] = -1
    elif h[i[0] - 1] < h[i[1] - 1]:
        t[i[0] - 1] = -1
    elif h[i[0] - 1] == h[i[1] - 1]:
        t[i[0] - 1] = t[i[1] - 1] = -1
# print(t)
count=0
for i in t:
    if i == 0:
        count += 1
print(count)


Measured memory_bytes: 32032
#include <iostream>
using namespace std;
static const int LINE = 3;
static const int N = 9;

int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};
int ans[LINE][LINE];
int in[LINE][LINE];

int check(){

    for(int i=0; i<LINE; i++){
        for(int j=0; j<LINE; j++){
            if(in[i][j] != ans[i][j])
                return false;
        }
    }

    return true;
}

int dfs(int x, int y, int d,int u,int k){
    if(check()) return d;
    if(d > k) return -1;
    for(int i=0; i<4; i++){
        int vx,vy,val;
        vx = x+dx[i];
        vy = y+dy[i];

        if(vx > 2 || vx < 0 || vy > 2 || vy < 0 || (i + 2) % 4 == u ){
            continue;
        }
        in[y][x] = in[vy][vx];
        in[vy][vx] = 0;
        val  = dfs(vx,vy,d+1,i,k);
        if(val > 0) return val;
        in[vy][vx] = in[y][x];
        in[y][x] = 0;
    }
    return -1;
}


int main(){
    int x,y,sol,cnt=0;

    for(int i=0; i<LINE; i++){
        for(int j=0; j<LINE; j++){
            ans[i][j] = ++cnt;
            if(i == LINE-1 && j == LINE -1) ans[i][j] = 0;
        }
    }

    for(int i=0; i<LINE; i++){
        for(int j=0; j<LINE; j++){
            cin>>in[i][j];
            if(in[i][j] == 0){
                y = i;
                x = j;
            }
        }
    }

    cnt = 1;

    while(1){
        sol = dfs(x,y,0,-1,cnt);
        if(sol >= 0) break;
        cnt++;
    }

    /*for(int i=0; i<LINE; i++){
        for(int j=0; j<LINE; j++){
            cout<<in[i][j];
        }
        cout<<endl;
    }*/ //出力確認


    cout<<sol<<endl;

    return 0;
}





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

int main() 
{
    int n;
    int H[20];
    int counter = 1;
    bool view_flag = true;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> H[i];
    }

    for (int i = 1; i < n; i++) {
        
        for (int j = 0; j < i; j++) {
            if (H[i] - H[j] < 0) {
                view_flag = false;
            }
        }

        if (view_flag == true) {
            counter+=1;
        }

        view_flag = true;
        
    }
     

    cout << counter << endl;

}

Measured memory_bytes: 256
s=input()
if s[0]==s[1]==s[2]=="R":
    print(3)
elif s[0]==s[1]=="R" or s[1]==s[2]=="R":
    print(2)
elif s[0]=="R" or s[1]=="R" or s[2]=="R":
    print(1)
else:
    print(0)

Measured memory_bytes: 9064
import sys
import math
import numpy as np
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, m = na()
a = na()
bc = []

for _ in range(m):
    bci = na()
    bc.append(bci)

bc.sort(key=lambda x:x[1], reverse=True)
#print(bc)

bi, ci = bc[0][0], bc[0][1]
i = 0
for _ in range(n):
    if bi != 0:
        bi -= 1
        a.append(ci)
    else:
        i += 1
        if i > (m - 1):
            break
        else:
            bi, ci = bc[i][0], bc[i][1]
            bi -= 1
            a.append(ci)

a.sort(reverse=True)
print(sum(a[:n]))



Measured memory_bytes: 43440
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
sum_a = sum(a)
# print(a)
ans = 0
for i in range(n):
    if a[i] >= sum_a/(4*m): 
        ans = i+1
# print(ans)
# print(sum_a/(4*m))
if ans >=m:
    print("Yes")
else:
    print("No")



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

int main( void ) {
    long long n, num, ans = 0;
    cin >> n;
    cin >> num;
    long long minn, maxn;
    ans = minn = maxn = num;
    for( int i = 1; i < n; ++i ) {
        cin >> num;
        ans += num;
        minn = min( minn, num );
        maxn = max( maxn, num );
    }
    cout << minn << ' ' << maxn << ' ' << ans << '\n';
    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
#define all(x) x.begin(),x.end()
#define ls(x) x<<1
#define rs(x) x<<1|1
using namespace std;
const int N=2e6+9;
const ll mod=998244353;
char s[1050];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,1,1<<n){
		rep(j,1,1<<m){
			if(lb(i)!=lb(j))s[j]='0';
			else s[j]='1';
		}
		printf("%s\n",s+1);
	}
} 

Measured memory_bytes: 1280
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC088
{
    class D
    {
        static void Main(string[] args)
        {

            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = input[0];
            int W = input[1];
            int[,] s = new int[W, H];
            int scount = 0;

            for (int h = 0; h < H; h++)
            {
                string S = Console.ReadLine();
                for (int w = 0; w < W; w++)
                {
                    s[w, h] = S[w];
                    if (S[w] == '#') scount++;
                }
            }

            Queue<Tuple<int, int, int>> q = new Queue<Tuple<int, int, int>>();

            int step = 0;
            q.Enqueue(Tuple.Create(0, 0, step));
            s[0, 0] = '#';

            int[] vx = { 0, 1, 0, -1 };
            int[] vy = { 1, 0, -1, 0 };

            while (0 < q.Count)
            {

                var tq = q.Dequeue();
                int x = tq.Item1;
                int y = tq.Item2;
                step = tq.Item3;

                if (x == W - 1 && y == H - 1)
                {
                    Console.WriteLine(H * W - scount - step - 1);
                    return;
                }

                for (int i = 0; i < 4; i++)
                {
                    int nx = x + vx[i];
                    int ny = y + vy[i];
                    if ((0 <= nx && nx < W) && (0 <= ny && ny < H) && s[nx, ny] == '.')
                    {
                        s[nx, ny] = '#';
                        q.Enqueue(Tuple.Create(nx, ny, step + 1));
                    }
                }
            }
            Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n; cin >> n;
    vector<P> x;
    rep(i,n) {
        int a; cin >> a;
        x.push_back(P(a,i));
    }
    sort(all(x));
    int med_1 = x[n/2-1].first;
    int med_2 = x[n/2].first;
    vint ans(n);
    rep(i,n) {
        if (i <= (n/2-1)) ans[x[i].second] = med_2;
        else ans[x[i].second] = med_1;
    }
    rep(i,n) cout << ans[i] << endl;
}

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

int main(){

int ans = 0;
string x; 

while(1){
    cin >> x;
if(x.at(0) == '0') break;
ans = 0;

rep(i, x.size()){
ans += x.at(i) - '0';
}
cout << ans << endl;
}
}


Measured memory_bytes: 3148
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


struct mint {
	int x;
	mint(int 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(int 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;
	}
};

struct combination {
	vector<mint>fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		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];
	}
};

mint choose(int n, int a) {
	mint x = 1, y = 1;
	rep(i, a) {
		x *= n - i;
		y *= i + 1;
	}
	return x / y;
}

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	mint ans = 2;
	ans = ans.pow(n) - 1;
	ans -= choose(n, a);
	ans -= choose(n, b);
	cout << ans.x << endl;
}

Measured memory_bytes: 256
import fileinput

ps = set()
for i in range(3, 10001, 2):
    for p in ps:
        if p > 100:
            continue
        if i % p == 0:
            break
    else:
        ps.add(i)
    i += 2
ps.add(2)

for line in fileinput.input():
    n = int(line)
    print(sum(i in ps and (n + 1 - i) in ps for i in range(2, n + 1)))

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;
const int MN = 200010;

// 1-indexed, [1, n]
template<class T>
class BIT {
	T bit[MN];
	int n;

public:
	BIT() {
		n = MN;
		memset(bit, 0, sizeof(bit));
	}

	T sum(int i) {
		++i;
		T s = 0;
		while (i > 0) {
			(s += bit[i]) %= MOD;
			i -= i & -i;
		}
		return s;
	}

	void add(int i, T x) {
		++i;
		while (i < n) {
			(bit[i] += x) %= MOD;
			i += i & -i;
		}
	}
};

int N;
int lo[MN], hi[MN];
BIT<int> T;

int main() {
	cin >> N;
	vector<pii> vec(N);

	vi vs;

	rep(i, N) {
		int X, V;
		cin >> X >> V;
		vec[i] = mp(X, V);
		vs.pb(V);
	}

	sort(ALL(vec));
	sort(ALL(vs));

	rep(i, N) {
		int v = vec[i].se;
		v = lower_bound(ALL(vs), v) - vs.begin();
		vec[i].se = v;

		if (i) {
			hi[i] = max(hi[i-1], v);
		} else {
			hi[i] = v;
		}
	}

	for (int i = N-1; i >= 0; --i) {
		if (i != N-1) {
			lo[i] = min(lo[i+1], vec[i].se);
		} else {
			lo[i] = vec[i].se;
		}
	}

	rep(i, N) {
		int r = T.sum(hi[i]);
		if (lo[i] >= 2) r -= T.sum(lo[i]-2);
		if (lo[i] == 0) ++r;

		r %= MOD;
		if (r < 0) r += MOD;

		T.add(hi[i], r);
	}

	int ret = T.sum(N-1) - T.sum(N-2);
	ret %= MOD;
	if (ret < 0) ret += MOD;
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 5108
#include <stdio.h>

int main(){
    char C[2][4];

    scanf("%s", C[0]);
    scanf("%s", C[1]);

    if(C[0][0] == C[1][2] && C[0][1] == C[1][1] && C[0][2] == C[1][0])
        printf("YES\n");
    else
        printf("NO\n");
    
    return 0;
}

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

long long mod = 1000000007;

long long power(long long x, long long y)
{
    long long ret = 1;
    while(y > 0)
    {
        if (y & 1)
        {
            ret = (ret * x) % mod;
        }
        x = (x * x) % mod;
        y >>= 1;
    }
    return ret;
}

int main(void)
{
    long long N;
    cin >> N;
    long long count = 1;
    long long count9 = 1;
    long long count8 = 1;
    for (long long i = 0; i < N-2; i++)
    {
        count = (count * 10 ) % mod;
    }
    long long ans = count;
    for (long long i = 3; i <= N; i++)
    {
        count9 = (((count9 * 9) % mod) + (((count8 * 8) % mod))) % mod;
        count = (count * power(10, mod -2) )%mod;
        count8 = (count8 * 8) % mod;
        ans = (ans + count * count9) % mod;
    }
    ans = (ans * 2) % mod;

    if (N == 1)
    {
        cout << 0 << endl;
        exit(0);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
 private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1);
 private String inputData = null;
 
 private String[] data;

 private int x;
 private int y;

 private int field_00001;
 private int field_00002;

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

 public void start() {
  try {
  this.inputData = reader.readLine();
  } catch(IOException e) {
   e.printStackTrace();
  }

  this.data = this.inputData.split(" ");
  this.x = Integer.parseInt(this.data[0]);
  this.y = Integer.parseInt(this.data[1]);

  this.field_00001 = this.x * this.y;
  this.field_00002 = this.x * 2 + this.y * 2;
  System.out.println(this.field_00001 + " " + this.field_00002);
 }

}

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

using namespace std;

int main(int argc, char* argv[]){
	long long int a,b,c,k;
	cin >> a >> b >> c >> k;
	if(k%2==0) a = a-b;
	else a = b-a;
	if(a> pow(10,18)) cout << "Unfair" << endl;
	else cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int[] ant = new int[5];
		for(int i = 0; i < 5; i++) {
			ant[i] = sc.nextInt();
		}
		int k = sc.nextInt();
		boolean isCom = true;
		for(int i = 0; i < 5; i++) {
			for(int j = i + 1; j < 5; j++) {
				if(Math.abs(ant[i] - ant[j]) > k) {
					isCom = false;
				}
			}
		}
		System.out.println(isCom ? "Yay!" : ":(");
	}
}


Measured memory_bytes: 20820
#include<stdio.h>
int main()
{
    int a,i,j,c=0,c1=0,r=0,r1=0,f=0,f1=0;
    scanf("%d",&a);
    int b[a];
    for(i=1;i<=a;i++)
    {
        scanf("%d",&b[i]);
    }
    for(i=1,j=a;i<=a;i++,j--)
    {
        if(b[i]==i)
            c++;
        if(b[i]==j)
            c1++;
    }
    if(c==a)
        printf("YES");
    else if(c==a-2)
    {
        for(i=1;i<=a;i++)
        {
            if(b[i]!=i)
            {
                b[i]=i;
                r++;
            }
        }
        if(r==2)
            {
              for(i=1;i<=a;i++)
        {
            if(b[i]==i)
            {
                f++;
            }
        }
        if(f==a)
            printf("YES");
        else
            printf("NO");
            }
        else
            printf("NO");
    }
    else if(c<a-2)
        printf("NO");
    else if(c1==a)
        printf("YES");
    else if(c1==a-2)
    {
        for(i=1,j=a;i<=a;i++,j--)
        {
            if(b[i]!=j)
            {
                b[i]=j;
                r1++;
            }
        }
        if(r1==2)
            {
              for(i=1,j=a;i<=a;i++,j--)
        {
            if(b[i]==j)
            {
                f1++;
            }
        }
        if(f1==a)
            printf("YES");
        else
            printf("NO");
            }
        else
            printf("NO");
    }
    else if(c1<a-2)
        printf("NO");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  if(n == 1){
    cout << 0 << endl;
    return 0;
  }
  ll init = n;
  map<ll,ll> mp;
  for(ll i=2;i*i<=init;i++){
    while(n%i == 0){
      mp[i]++;
      n /= i;
    }
  }
  if(n > 1) mp[n]++;
  if(mp.size() == 0){
    cout << 1 << endl;
    return 0;
  }
  ll ans = 0;
  for(auto p : mp){
    ll b = p.second;
    ll cnt = 1;
    while(b-cnt >= 0){
      b -= cnt;
      cnt ++;
      ans ++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>

#define rep(i,n) for(int i = 0; i < n; ++i)
#define reps(i,f,n) for(int i = f; i < n; ++i)
using namespace std;
using ll=long long;
using PII=pair<int,int>;

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

  ll mx = a+n*b;
  ll my = a*n+b;

  cout << max(mx - my + 1LL, 0LL) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
 
typedef uint64_t ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const ll mod = 1e9+7;
 
 
int r,c,n;
 
 
ll fz(int y, int x){
	if(x ==0) return 0 + y;
	if(y ==r) return r + x;
	if(x ==c) return r+c+r - y;
	if(y ==0) return r+c+r+c - x;
	return -1;
}
 
int main()
{
	
	vector<pair<ll,int>> vp;
	//cin.tie(0); ios_base::sync_with_stdio(false);
	cin >>c >>r >>n;
 
	rep(i,n){
	
		int ar,ac,br,bc;
		cin >>ac >>ar >>bc >>br;
	
		ll aa = fz(ar, ac);
		ll bb = fz(br, bc);
	
		if(aa ==-1 || bb ==-1) continue;
		vp.emplace_back(aa, i);
		vp.emplace_back(bb, i);
	}
	
	sort(all(vp));
	//for(auto x: vp) printf("%lld:%d ",x.first,x.second);puts("");
	
	stack<int> stc;
	for(auto x: vp){
		if(!stc.empty() && stc.top() == x.second) stc.pop();
		else stc.push(x.second);
	}
	
	cout <<(stc.empty()? "YES":"NO") <<"\n";
	return 0;
}

Measured memory_bytes: 6256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()

	now := 1
	for i := 0; i < int(n); i++ {
		if now*2 > now+k {
			now += k
		} else {
			now = now * 2
		}
	}
	fmt.Println(now)
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

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

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

int main() {
  // 入力
  int H, W;
  cin >> H >> W;
  int c[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c[i][j];
    }
  }
  int a[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }

  // ワーシャルフロイド法で最小の魔力を求めれば良い
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] == -1 || a[i][j] == 1) continue;

      ans += c[a[i][j]][1];
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,w;
ll dp[N];
int main()
{
    memset(dp,inf,sizeof(dp));
    dp[0]=0;
    scanf("%d%d",&n,&w);
    while(n--)
    {
        int x,v;scanf("%d%d",&x,&v);
        for(int i=100000;i>=v;i--)
            dp[i]=min(dp[i],dp[i-v]+x);
    }
    ll ans=0;
    for(int i=1;i<=100000;i++)
        if(dp[i]<=w) ans=i;
    printf("%lld\n",ans);
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
  int n,i;
  cin>>n;
  int a[n-1];
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=(n-1);i>=0;i--){
    cout<<a[i];
    if(i>0){
      cout<<" ";
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3100
MOD = 10**9+7

def sum(a,d,n):
    return n*(2*a+(n-1)*d)//2

def main():
    n,m = map(int,input().split())

    s = 0
    if n == 1:
        s = m+1
    else:
        s = sum(m+1,-n+1,1+m//(n-1))
        s *= 2
        s -= (m+1)

    print(s%MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7788
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
int pos[maxn],root[maxn];
struct Psdtree
{
	int tot,cnt[maxn*40],lson[maxn*40],rson[maxn*40];
	void update(int& rt,int prt,int l,int r,int pos,int val)
	{
		rt=++tot,cnt[rt]=cnt[prt]+val;
		lson[rt]=lson[prt],rson[rt]=rson[prt];
		if(l==r) return;
		int mid=(l+r)>>1;
		if(pos<=mid) update(lson[rt],lson[prt],l,mid,pos,val);
		else update(rson[rt],rson[prt],mid+1,r,pos,val);
	}
	int query(int rt,int l,int r,int pos)
	{
		if(pos<=l) return cnt[rt];
		int mid=(l+r)>>1;
		if(pos>mid) return query(rson[rt],mid+1,r,pos);
		else return query(lson[rt],l,mid,pos)+cnt[rson[rt]];
	}
}t;
int main()
{
	int n,q,x,l,r;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		t.update(root[i],root[i-1],1,n,i,1);
		if(pos[x])
			t.update(root[i],root[i],1,n,pos[x],-1);
		pos[x]=i;
	}
	while(q--)
	{
		scanf("%d%d",&l,&r);
		printf("%d\n",t.query(root[r],1,n,l));
	}
}

Measured memory_bytes: 239188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    ll N;
    cin >> N;
    ll tmp;
    ll lst[200001];
    REP(i, 200001)
    lst[i] = 0;
    ll ans = 0;
    REP(i, N)
    {
        cin >> tmp;
        lst[tmp] = lst[tmp - 1] + 1;
        chmax(ans, lst[tmp]);
    }
    cout << N - ans << endl;
    //system("pause");
}


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

int main() {
  double a, b, m;
  
  cin >> a >> b;
  
  m = (a + b) / 2.0;
  
  int im = m;
  
  m == im ? cout << im << endl : cout << im + 1<< endl;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
o, e = v[0::2], v[1::2]
co, ce = Counter(o).most_common(), Counter(e).most_common()
if co[0][0] == ce[0][0]:
    if len(co) == len(ce) == 1:
        print(n // 2)
    elif len(co) == 1:
        print(n // 2 - ce[0][1])
    elif len(ce) == 1:
        print(n // 2 - co[0][1])
    else:
        print(min(n - (co[1][1] + ce[0][1]),n - (co[0][1] + ce[1][1])))
else:
    if len(co) == len(ce) == 1:
        print(0)
    elif len(co) == 1:
        print(n // 2 - ce[0][1])
    elif len(ce) == 1:
        print(n // 2 - co[0][1])
    else:
        print(n - (co[0][1] + ce[0][1]))

Measured memory_bytes: 21084
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
    int D, T, S;
    cin >> D >> T >> S;
    
    if(T * S >= D) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3588
#include<stdio.h>
int main(void){
int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  while(1){
c-=b;
    if(c<=0){printf("Yes");
    return 0;
  }
    a-=d;
    if(a<=0){printf("No");
             return 0;
            }
  }
  return 0;
}

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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

void solve() {
    vl A(5);
    FOR(i, 0, 5)
        cin >> A[i];
    FOR(i, 0, 5) {
        if(A[i] == 0) {
            cout << i + 1;
            return;
        }
    }
	
}

int main() {
	
	fastio;

//  	rd1(ll, t);
	ll t = 1;

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

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
  long a,b;
  cin >> a >> b;
  long ansAm = 0;
  long ansB = 0;
  if(a>0 && (a%4 == 2 || a%4 == 3))ansAm++;
  if(b%4 == 1 || b%4 == 2)ansB++;

  for(long bit = 2;bit<=b;bit*=2){
    if((a-1)%(bit*2)>=bit && (a-1)%2==0)ansAm+=bit;
    if(b%(bit*2)>=bit && b%2==0)ansB+=bit;
  }
  long ans = ansAm^ansB;
  cout << ans << endl;
}


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

using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = (1 << 30);
const i64 INFL = (1LL << 62);

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

int main() {
    i64 n, t;
    cin >> n >> t;
    vector<i64> a(n);
    vector<i64> b(n);
    rep(i, n) { cin >> a[i] >> b[i]; }

    i64 dp1[n + 2][t] = {};
    i64 dp2[n + 2][t] = {};

    // i, j: 1-indexed
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j < t; ++j) {
            chmax(dp1[i][j], dp1[i - 1][j]);
            if (a[i - 1] <= j) {
                chmax(dp1[i][j], dp1[i - 1][j - a[i - 1]] + b[i - 1]);
            }
        }
    }

    for (int i = n; i >= 1; --i) {
        for (int j = 1; j < t; ++j) {
            chmax(dp2[i][j], dp2[i + 1][j]);
            if (a[i - 1] <= j) {
                chmax(dp2[i][j], dp2[i + 1][j - a[i - 1]] + b[i - 1]);
            }
        }
    }
    i64 ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < t; ++j) {
            chmax(ans, dp1[i - 1][j] + dp2[i + 1][t - j - 1] + b[i - 1]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 141056
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S;

	cin >> S;
	int count = 0;

	for(int i = 0; i < S.length() / 2; i++) {
		if(S[i] != S[S.length() - 1 - i]) count++;
	}

	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long;
#define pii pair<int, int>;
int N, M;
int pos[100010], cnt[100010];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> N >> M;
  pos[0] = 1;
  fill_n((int*)cnt, 100010, 1);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cnt[x]--; cnt[y]++;
    if (pos[x]) {
      if (cnt[x] == 0) pos[x] = 0;
      pos[y] = 1;
    }
  }
  cout << accumulate(pos, pos + N, 0) << endl;
  return 0;
}

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


const int MOD = 1e9 + 7;

//累乗(a^n) O(logn)
long long modpow1(long long a, long long n) {
	//二分累乗法
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = (res * a) % MOD;
		a = (a*a) % MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	int N;
	multiset<int> A;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int x; cin >> x;
		A.insert(x);
	}

	multiset<int> Z;
	for (int i = 0; i < N; i++) {
		int x = 0;
		if (N % 2 == 0) {
			x = i % 2 == 0 ? i + 1 : i;
		}
		else {
			x = i % 2 == 0 ? i : i + 1;
		}
		Z.insert(x);
	}

	if (A == Z) {
		long long count = modpow1(2, N / 2);		
		cout << count << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 9600
def maxHeapify(heap, i):
    left = i * 2
    right = i * 2 + 1
    if left <= n and heap[left] > heap[i]:
        largest = left
    else:
        largest = i
    if right <= n and heap[right] > heap[largest]:
        largest = right
    
    if largest != i:
        heap[i], heap[largest] = heap[largest], heap[i]
        maxHeapify(heap, largest)

def buildMaxHeap(heap):
    for i in range(n // 2, 0, -1):
        maxHeapify(heap, i)
        

n=int(input())
heap = list(map(int,input().split()))
heap.insert(0, None)

buildMaxHeap(heap)
print(" ", end = "")
for i in range(n - 1):
    print(heap[i + 1 ], end = " ")
print(heap[n], end = "")
print("")


    


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

int H, W;
int a[1001][1001];
static const int mod = 1e9+7;
int dy[2] = {1, 0}, dx[2] = {0, 1};
int dp[1001][1001];

int rec(int i, int j){
    if(dp[i][j] != -1) return dp[i][j];
    if(a[i][j]== 1) return dp[i][j]=0;
    int ret = 0;
    for(int v = 0; v < 2; v++){
        if(i+dy[v] >= H || j + dx[v] >= W) continue;
        ret += rec(i+dy[v], j + dx[v]);
        ret %= mod;
    }
    
    return dp[i][j] = ret;
}

int main(void){
    // Your code here!
    cin >> H >> W;
    char c;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> c;
            if(c == '.'){
                a[i][j] = 0;
            } else{
                a[i][j] = 1;
            }
            dp[i][j] = -1;
        }
    }

    dp[H-1][W-1] = 1;
    cout << rec(0, 0) % mod << endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int mx = accumulate(all(a), 0);
    vector<int> dv;
    for(int i=1; i*i<=mx; i++){
        if(mx%i == 0){
            dv.push_back(i);
            if(i*i != mx) dv.push_back(mx/i);
        }
    }
    sort(all(dv));
    // repe(i, dv) cout << i << " "; cout << endl;
    int ans = 1;
    repe(d, dv){
        int tmpans = 101010101;
        vector<int> tmp;
        int rem = 0;
        repe(j, a){
            if(j%d <= (d-j%d)){
                tmp.push_back(-j%d);
                rem += j%d;
            }else{
                tmp.push_back(d-j%d);
                rem += -d+j%d;
            }
        }
        // repe(i, tmp) cout << i << " "; cout << endl;
        // cout << rem << endl;

        sort(all(tmp));
        if(rem < 0) reverse(all(tmp));
        rem /= d;
        if(rem < 0){
            rem *= -1;
            rep(i, rem){
                tmp[i] -= d;
            }
        }else{
            rep(i, rem){
                tmp[i] += d;
            }
        }
        int pos = 0, neg = 0;
        repe(i, tmp){
            if(i >= 0) pos += i;
            else neg -= i;
        }
        tmpans = max(pos, neg);
        if(tmpans <= k) ans = d;


    }
    cout << ans << endl;


}

Measured memory_bytes: 256