akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >>y;
    if(x + y< 24) cout << x + y << endl;
    else cout << x + y - 24 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powmod(x*x%MOD,n/2);
    if(n % 2)ans = ans * x % MOD;
    return ans;
}
ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}
ll combi(ll n,ll r){
    ll num = 1;
    for(ll i = 1;i <= r;i++){
        num = divmod((n-i+1)*num,i);
    }
    return num;
}
main(){
    int N,M;
    cin >> N >> M;
    map<int,int> mp;
    for(int i = 2;i * i <= M;i++){
        while(M % i == 0){
            M /= i;
            mp[i]++;
        }
    }
    if(M != 1)mp[M]++;
    ll ans = 1;
    for(auto p:mp){
        //cout << p.first << " " << p.second << endl;
        ll n = N, r = p.second;
        ll cnt = combi(n + r - 1, r);
        ans = ans * cnt % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto ss = new string[](N);
    auto ts = new int[](N);
    foreach (i; 0..N) {
        auto st = readln.split;
        ss[i] = st[0];
        ts[i] = st[1].to!int;
    }
    auto X = readln.chomp;
    int r;
    foreach (i; 0..N) {
        r += ts[i];
        if (ss[i] == X) r = 0;
    }
    writeln(r);
}

Measured memory_bytes: 256
#pragma GCC optimize "O3"
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define REP_FROM(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#ifndef LOCAL
#define cerr if (false) cerr
#endif
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) { return min(max(a, l), r); } // [l, r]
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int solve(int n) {
	int cnt = 0;
	REP(a, 10)
		REP(b, 10)
			REP(c, 10)
				REP(d, 10)
					if(a+b+c+d == n)
						cnt++;
	return cnt;
}

int main(int argc, char *argv[]) {
	// Something to do
	int n;
	while(cin >> n) {
		cout << solve(n) << endl;
	}
	return 0;
}

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

int main(void){
	
	int x, y;
	
	while(1){
    	cin >> x >> y;
    	if ( x == 0 && y == 0 ) break;
		
		if ( x < y ){
			//x, y ???????????????;
			cout << x << ' ' << y << endl;
		} else {
			//y, x ???????????????;
			cout << y << ' ' << x << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 2996
import math
A, B, H, M = map(int, input().split())
h_d = H * 30
h_d += 30 * (M/60)
m_d = M * 6
d = min(360-abs(h_d-m_d), abs(h_d-m_d))
c = A*A+B*B-2*A*B*math.cos(math.radians(d))
print(math.sqrt(c))

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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define FILE "file"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const ull ULLINF = numeric_limits<ull>::max();
const double PI = acos(-1.0);

int main()
{
//    freopen(FILE".in", "r", stdin);
//    freopen(FILE".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    map<int, int> pos;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        pos[a]++;
        pos[a - 1]++;
        pos[a + 1]++;
    }
    int ans = 0;
    for(auto k: pos)
        ans = max(ans, k.second);
    cout << ans;
    return 0;
}


Measured memory_bytes: 4736
N, M = map(int,input().split())
H = list(map(int,input().split()))

A = []
B = []
cmb = {}
cnt = 0
flag = 1
ma = [0]*N

for i in range(M):
	a,b = map(int,input().split())

	cmb.setdefault(i, [])
	cmb.setdefault(a-1, []).append(b-1)
	cmb.setdefault(b-1, []).append(a-1)

	ma[a-1] = max(ma[a-1], H[b-1])
	ma[b-1] = max(ma[b-1], H[a-1])
# print(cmb)

for j in range(N):
	# # print("展望台:", j)
	# k = list(set(cmb[j]))
	# # print(k)
	# if len(cmb[j])==0:
	# 	# print('正しく分岐')
	# 	cnt +=1
	# else:
	# 	# print(H[j], '>', ma[j])

	if H[j] > ma[j]:
		# print('GOOD')
		cnt += 1
print(cnt)

Measured memory_bytes: 38616
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};


int main(){
    IOS;
    make2(ll,x,k);
    make(ll,d); if(x<0) x*=-1;
    ll m=((x-x%d)/d);
    ll ans;
        if(m>=k) ans=abs(x-d*k);
        else ans=abs(x-(m)*d);

    if((k-m)%2!=0 && (k-m)>0) ans=min(abs(ans-d),abs(ans+d));
    cout<<abs(ans)<<endl;

    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main()
{
	int x, y;
	scanf("%d %d", &x, &y);

	for (int i = 0; i <= x; i++)
	{
		if ((i * 2 + (x - i) * 4) == y)
		{
			printf("Yes\n");
			return 0;
		}
	}

	printf("No\n");
	return 0;
}

Measured memory_bytes: 1660
import java.util.Scanner;

public class Main {
    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        String symbol = "";

        if(a > b)
            symbol = ">";
        else if (a < b)
            symbol = "<";
        else
            symbol = "==";

        System.out.println("a " + symbol + " b");
    }
}



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

int main() {
    int n;
    string s[52] = {}, t[52] = {};
    int a[52] = {}, b[52] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        s[i] = t[i] = str[0];
        a[i] = b[i] = str[1] - '0';
    }
    bool flag=1;
    for (int i = 0; flag;i++) {
        flag = 0;
        for (int j = n - 1; j > i; j--) {
            if (a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                swap(s[j], s[j - 1]);
                flag = 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << s[i] << a[i];
    }
    cout << endl;
    cout << "Stable" << endl;
    for (int i = 0; i < n - 1; i++) {
        int m = b[i], k = i;
        for (int j = i + 1; j < n;j++) {
            if (m > b[j]) {
                m = b[j];
                k = j;
            }
        }
        if (k != i) {
            swap(b[k], b[i]);
            swap(t[k], t[i]);
        }
    }
    bool check = 1;
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << t[i] << b[i];
        if (s[i] != t[i]) check = 0;
    }
    cout << endl;
    if (check) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
}


Measured memory_bytes: 3160
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

void printM(vector<vector<long> > &vec, long height, long width){
    F(i, 0, height){
        F(j, 0, width){
            cout << vec[i][j] << space;
        }
        cout << endl;
    }
}

#define TST 0
int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ull x;
    cin >> x;
    ull money = 100;
    ull time = 0;
    while(money < x){
        money *= 1.01;
        time ++;
    }
    cout << time << endl;

#if TST==1

#endif
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

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

int exist[1500001];

int main() {
	int n, m;
	while(cin >> n >> m, n||m) {
		memset( exist, 0, sizeof(exist) );
		int h[n], w[m];
		for(int i=0; i<n; i++) {
		   	cin >> h[i];
		}
		for(int i=0; i<m; i++) {
		   	cin >> w[i];
		}
		rep(i,n) {
			int sum = h[i];
			exist[sum]++;
			for(int j=i+1; j<n; j++) {
				sum += h[j];
				exist[sum]++;
			}
		}
		int cnt = 0;
		rep(i,m) {
			int sum = w[i];
			cnt += exist[sum];
			for(int j=i+1; j<m; j++) {
				sum += w[j];
				cnt += exist[sum];
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 7036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;

signed main(){
    int n,k;cin>>n>>k;
    int a[n];
    bool dp[k+3];
    rep(i,n)cin>>a[i];
    rep(i,k+3) dp[i]=false;
    REP(i,k){
        rep(j,n){
            if(i>=a[j] and dp[i-a[j]]==false) dp[i]=true;
        }
    }
    cout<<(dp[k]?"First":"Second")<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 300005;

i64 n, k;

i64 a[MAXN];
i64 b[MAXN];

i64 f(i64 c) {
    i64 R = 0;
    for (i64 i = 0; i < n; i++) {
        i64 t = a[i] * b[i] <= c ? 0 : (a[i] - c / b[i]); // +(c % b[i] ? 1 : 0));

        R += t;
        //cerr << ((a[i] - t) * b[i]) << " ";
    }
    return R;
}

bool g(i64 c) {
    return f(c) <= k;
}

i64 bin(i64 l, i64 r) {
    if (l == r) {
        return l;
    }
    if (l + 1 == r) {
        if (g(l)) {
            return l;
        }
        else {
            return r;
        }
    }

    i64 t = (l + r) / 2;
    if (!g(t)) {
        return bin(t, r);
    }
    else {
        return bin(l, t);
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> k;

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

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

    sort(a, a + n);
    sort(b, b + n, greater<i64>());

    i64 m = a[0] * b[0];
    for (i64 i = 0; i < n; i++) {
        m = max(m, a[i] * b[i]);
    }


    //for (i64 i = 0; i <= m; i++) {
    //    cerr << "g(i) = " << i << " " << (g(i)) << endl;
    //}

    /*
    for (i64 i = 0; i < n; i++) {
        cerr << a[i] << " ";
    }
    cerr << endl;

    for (i64 i = 0; i < n; i++) {
        cerr << b[i] << " ";
    }
    cerr << endl;

    const i64 c = 12;

    i64 R = 0;
    for (i64 i = 0; i < n; i++) {
        i64 t = a[i] * b[i] <= c ? 0 : (a[i] - c / b[i]); // +(c % b[i] ? 1 : 0));

        R += t;
        cerr << ((a[i] - t) * b[i]) << " ";
    }

    cerr << endl;

    cerr << R;
    */
    i64 R = bin(0, m);
    cout << R << endl;
    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

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

    REP(i, S.length()) cout << (char)((S[i]-'A'+N)%26+'A');
    cout << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> seito(n);
    int a;
    for(int i = 0; i < n; i++){
        cin >> a;
        seito.at(i) = make_pair(a, i+1);
    }
    sort(seito.begin(), seito.end());
    for(int i = 0; i < n; i++){
        cout << seito[i].second << endl;
    }
}


Measured memory_bytes: 1664
import sys
input = sys.stdin.readline
Q = int(input())
Y = []
D = []
S = [0] * Q
s = 0
for i in range(Q):
    a = list(map(int, input().split()))
    Y.append(a)
    if a[0] == 1:
        D.append(a[1])
        s += a[2]
    S[i] = s

D = sorted(list(set(D)))
INV = {}
for i in range(len(D)):
    INV[D[i]] = i

N = 17
X = [0] * (2**(N+1)-1)
C = [0] * (2**(N+1)-1)

def add(j, x):
    i = 2**N + j - 1
    while i >= 0:
        X[i] += x
        C[i] += 1
        i = (i-1) // 2

def rangeof(i):
    s = (len(bin(i+1))-3)
    l = ((i+1) - (1<<s)) * (1<<N-s)
    r = l + (1<<N-s)
    return (l, r)

def rangesum(a, b):
    l = a + (1<<N)
    r = b + (1<<N)
    s = 0
    while l < r:
        if l%2:
            s += X[l-1]
            l += 1
        if r%2:
            r -= 1
            s += X[r-1]
        l >>= 1
        r >>= 1
    return s
def rangecnt(a, b):
    l = a + (1<<N)
    r = b + (1<<N)
    s = 0
    while l < r:
        if l%2:
            s += C[l-1]
            l += 1
        if r%2:
            r -= 1
            s += C[r-1]
        l >>= 1
        r >>= 1
    return s

c = 0
su = 0
CC = [0] * (2**N)
for i in range(Q):
    y = Y[i]
    if y[0] == 1:
        add(INV[y[1]], y[1])
        CC[INV[y[1]]] += 1
        c += 1
        su += y[1]
    else:
        l, r = 0, 2**N
        while True:
            m = (l+r)//2
            rc = rangecnt(0, m)
            if rc >= (c+1)//2:
                r = m
            elif rc + CC[m] <= (c-1)//2:
                l = m
            else:
                break
        rs = rangesum(0, m)
        print(D[m], D[m]*rc-rs+(su-rs)-(c-rc)*D[m]+S[i])


Measured memory_bytes: 116308
# ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)
# readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
# gets.split.map(&:to_i)

n,a,b = gets.split.map(&:to_i)

sum = 0
n.times do |i|
  num = (i+1).to_s.split("").map { |s| s.to_i }.inject(:+)
  if a <= num && num <= b
    sum += i+1
  end
end

puts sum


Measured memory_bytes: 2044
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<int> D;
int N,K;

int main(void) {
    cin>>N>>K;
    int R;
    R = min(N,K);

    for(int i = 0;i < N;i++) {
        int v;
        cin>>v;
        D.push_back(v);
    }

    int ans = 0;
    
    for(int i = 0;i <= R;i++) {
        for(int j = 0;j+i <= R;j++) {
            set<int> have;
            int temp = 0;
            for(int l = 0;l < i;l++) {
                have.insert(D[l]);
                temp += D[l];

            }
            for(int r = 0;r < j;r++) {
                have.insert(D[N-1-r]);
                temp += D[N-1-r];
            }
            //cout<<i<<" "<<j<<" "<<temp<<endl;
            for(int k = 0;k < K-(i+j);k++) {
                auto it = have.begin();
                if(*it < 0) {
                    temp -= *it;
                    have.erase(it);
                } else {
                    break;
                }
            }
            //cout<<temp<<endl;
            
            ans = max(ans,temp);
        }
    }

    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
typedef long long int lli;
const lli inf = 1e18;

int main(){
	lli a,b,c;
	cin >> a >> b >> c;
	cout << b +min(c, a+b+1) << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, a, b = LI()
    a, b = min(a,b), max(a,b)
    ans = 0
    if (b-a)%2 == 0:
        ans = (b-a)//2
    else:
        ans = min(a+(b-a-1)//2, n-b+1+(n-(a+n-b+1))//2)
    print(ans)
main()


Measured memory_bytes: 74556
#include <bits/stdc++.h>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    fast_io();
    int n;
    cin >> n;
    int t = n, m;
    cin >> m;
    for (int i = 1; i < n; i++) {
        int tmp;
        cin >> tmp;
        if (m < tmp) {
            --t;
        } else if (m > tmp) {
            m = tmp;
        }
    }
    cout << t;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val pList = readIntegerList().toTypedArray()
    val qList = readIntegerList().toTypedArray()

    val permutationList = permutationListFrom(Array(n) { it + 1 })

    val a = permutationList.indexOfFirst {
        pList.zip(it)
            .all { p -> p.first == p.second}
    }
    val b = permutationList.indexOfFirst {
        qList.zip(it)
            .all { p -> p.first == p.second}
    }
    out.println(abs(a - b))
}

/** O((array.size)!) */
fun <T : Comparable<T>> permutationListFrom(array: Array<T>): List<Array<T>> {
    val current = array.copyOf()
    val permutationList = mutableListOf<Array<T>>()
    do { permutationList += current.copyOf() } while (nextPermutation(current))
    return permutationList
}

/** O(n): n = currentPermutation.size */
fun <T : Comparable<T>> nextPermutation(currentPermutation: Array<T>): Boolean {
    fun <T> Array<T>.reverse(start: Int, end: Int) {
        val midPoint = ((start + end) / 2) - 1
        if (midPoint < 0) return
        var reverseIndex = end - 1
        for (index in start..midPoint) {
            val tmp = this[index]
            this[index] = this[reverseIndex]
            this[reverseIndex] = tmp
            reverseIndex--
        }
    }

    val n = currentPermutation.size
    var i = n - 2
    while (i >= 0) {
        if (currentPermutation[i] < currentPermutation[i + 1]) break
        i--
    }
    if (i < 0) return false
    var j = n
    do { j-- } while (currentPermutation[i] > currentPermutation[j])
    if (currentPermutation[i] < currentPermutation[j]) {
        val tmp = currentPermutation[i]
        currentPermutation[i] = currentPermutation[j]
        currentPermutation[j] = tmp
        currentPermutation.reverse(i + 1, n)
        return true
    }
    return false
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 57740
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
//#include<iostream>
//#include<assert.h>
using namespace std;

char s[33]; int cnt[33];
int n;
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	for (int i=1;i<=n;i++) cnt[s[i]-'a']=1;
	
	if (n<26) for (int i=0;i<26;i++) if (!cnt[i])
	{for (int j=1;j<=n;j++) putchar(s[j]); putchar(i+'a'); return 0;}
	for (int i=n;i;i--)
	{
		for (int j=s[i]-'a'+1;j<26;j++) if (!cnt[j])
		{
			for (int k=1;k<i;k++) putchar(s[k]);
			putchar(j+'a');
			return 0;
		}
		cnt[s[i]-'a']--;
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = Double.parseDouble(sc.next());
        double b = Double.parseDouble(sc.next());
        double x  = Double.parseDouble(sc.next());

        double degree;
        if(x<(0.5*a*a*b)) {
            degree  = Math.toDegrees(Math.atan((a*b*b)/(2*x)));
        }else if(x>(0.5*a*a*b)){
            degree = Math.toDegrees(Math.atan((2*a*a*b - 2*x)/(a*a*a)));
        }else{
            degree = Math.toDegrees(Math.atan(b/a));
        }
        System.out.println(degree);
    }
    
    private static void sort(int[] d, int left, int right){
        if(left>=right){return;}
        int p = d[(left+right)/2];
        int l=left, r=right;
        int tmp;
        while(l<=r){
            while(d[l]>p){l++;}
            while(d[r]<p){r--;}
            if(l<=r){
                tmp=d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++; r--;
            }
        }
        sort(d, left, r);
        sort(d, l, right);
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Sun Dec 22 21:00:17 JST 2019
 **/

signed main() {
    Int n = in();
    string s = in(), t = in();
    REP(i, n) {
        cout << s[i] << t[i];
    }
    cout << endl;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    double result{0};
    double n; cin >> n;
    //lol k; cin >> k;
    /*
    vector<lol> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    result = 2*n*PI;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3808
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		String w = in.next();
		boolean[] f = new boolean[26];
		for (int i=0; i<w.length(); i++) {
			f[w.charAt(i) - 'a'] = !f[w.charAt(i) - 'a'];
		}
		for (int i=0; i<26; i++) {
			if (f[i]) {
				out.println("No");
				return;
			}
		}
		out.println("Yes");
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 9428
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N + 1, vector<int>());
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(N + 1, inf);
    dist[1] = 0;

    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int from = q.front();
        q.pop();

        for (int to : G[from]) {
            if (dist[to] != inf)
                continue;

            dist[to] = dist[from] + 1;
            q.push(to);
        }
    }

    cout << (dist[N] == 2 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}

Measured memory_bytes: 13168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int price = 700;
		for(int i = 0; i < 3; i++) {
			if(s.charAt(i) == 'o') {
				price = price + 100;
			}
		}
		System.out.println(price);
	}
}

Measured memory_bytes: 21716
import java.util.*;
public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);

        String S = sc.nextLine();
        String T = sc.nextLine();

        sc.close();

        char[] s = S.toCharArray();
        char[] t = T.toCharArray();

        int cnt = 0;
        
        for (int i=0;i < 3;i++){
            if(s[i]==t[i]) 
                cnt++;
            
    
        }   
        
        System.out.println(cnt);
    }
       
}       

Measured memory_bytes: 23636
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 4 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;

bool compare(int a){
    return (a%10)==0;
}
bool check(int a , int b){
    return ((a%10) > (b%10));
}
int counter = 0;

void operation(int a){
    int t = a%10;
    if(t!=0){
        a += (10 - t);
    } 
    counter+=a;
    return;
}

auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 
    vi v(5);

    iv(v);

    auto itr = partition(all(v),compare);

    sort(itr,v.end(),check);

    for_each(v.begin() , v.end()-1 , operation);

    cout<<counter + v[4]<<endl;


    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("bin","r",stdin);
    freopen("bout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 256
# 2020/02/15
# AtCoder Beginner Contest 065 - A

# Input
x, a, b = map(int,input().split())

# Calc
if a >= b:
    ans = "delicious"
elif a + x >= b:
    ans = "safe"
else:
    ans = "dangerous"

# Output
print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int main(){
    string s;
    cin>>s;
    for(int i=0;i<3;i++)if(s[i]=='7')return printf("Yes\n"),0;
    printf("No\n");
    return 0;
}

Measured memory_bytes: 3596
from itertools import accumulate
import collections
n , m = map(int,input().split())
a = list(map(int,input().split()))

p = list(accumulate(a))

for i in range(n):
    p[i] %= m
    
c = collections.Counter(p)
ans = 0

for k , v in c.items():
    ans += v*(v-1)//2
    if k == 0:
        ans += v
print(ans)

Measured memory_bytes: 100124
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

int main(){
    int n, r; cin>>n>>r;
    if(n<10){
        r += 100*(10-n);
    }
    cout << r << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

double roundPoint4(double x) {
  x = x * 1000;
  if (x >= 0.0) {
    return floor(x + 0.5)/ 1000;
  } else {
    return -1.0 * floor(fabs(x) + 0.5) / 1000;
  }
}

int main (int ac, char **av )
{
  while (feof(stdin) == 0) {
    double a , b , c, d, e, f = 0;
    fscanf(stdin, "%lf %lf %lf %lf %lf %lf\n", &a, &b, &c, &d, &e, &f);
    double x,y = 0.0;
    double div = a*e-b*d;
    if (fabs(div) == 0) {
      x = 0.0;
      y = 0.0;
    } else{
      x = ((e * c - f * b) / (a*e-b*d));
      y = ((c * d - a * f) / (b*d-a*e));
    }

    if (x == 0) { x =0;}
    if (y ==0) { y =0;}
    fprintf(stdout, "%.3f %.3f\n", x, y);
  }
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    double v[n];
    rep(i,n) cin >> v[i];
    sort(v,v+n);
    double ans = v[0];
    rep(i,n-1) ans = (ans+v[i+1])/2.0;
    printf("%.9f",ans);
    return 0;
}

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

using ll = long long;
template<class T>
using V = vector<T>;

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i=m; i<n; i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = b - 1; i >= int(a); i--)

int main(){
    int N, K;
    cin >> N >> K;
    V<int> H(N);
    rep(i, N) cin >> H.at(i);

    V<ll> dp(N);
    dp.at(N-1) = 0;
    for(int i=N-2; i>=N-1-K && i>=0; i--) dp.at(i) = abs(H.at(N-1) - H.at(i));

    for(int i=N-2-K; i>=0; i--){
        ll min = 1000000000;
        for(int j=i+1; j<=i+K && j<N; j++){
            ll cost = dp.at(j) + abs(H.at(j) - H.at(i));
            if(cost < min) min = cost;
        }
        dp.at(i) = min;
    }
    
    cout << dp.at(0) << endl;
}

Measured memory_bytes: 4240
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    
    b = 0
    count = {0:1}
    ans = 0
    
    for a in A:
        b = (a+b) % M
        if b in count:
            ans += count[b]
            count[b] += 1
        else:
            count[b] = 1
            
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define pb push_back

typedef long long ll;
using namespace std;

typedef long double ldouble;

const ll MAXN = 1e5 + 1;

int n, h, w, sum;

int main()
{
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1);
    return 0;
}


Measured memory_bytes: 256
# coding:utf-8

INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


# aのp乗を求めるアルゴリズム
# MOD版
def pow_mod(a, p):
    if p == 0: return 1
    if p < 0: return 0

    if p % 2 == 0:
        half_p = p // 2
        half = pow_mod(a, half_p)
        return half * half % MOD
    else:
        return a * pow_mod(a, p - 1) % MOD


S = input()

# dp = [[0 for _ in range(4)] for _ in range(len(S) + 1)]
# dp = [len(S)][3] = 1
# for i in range(3):
#     dp[len(S)][i] = 0

A = [-INF for _ in range(len(S))]
C = A[:]
Q = A[:]

A[0] = 1 if S[0] == 'A' else 0
C[0] = 1 if S[0] == 'C' else 0
Q[0] = 1 if S[0] == '?' else 0

for i in range(1, len(S)):
    A[i] = A[i - 1] + 1 if S[i] == 'A' else A[i - 1]
    C[i] = C[i - 1] + 1 if S[i] == 'C' else C[i - 1]
    Q[i] = Q[i - 1] + 1 if S[i] == '?' else Q[i - 1]

pow_three = [1]
for i in range(Q[-1]):
    tmp = pow_three[-1] * 3
    tmp %= MOD
    pow_three.append(tmp)

ans = 0
for i in range(1, len(S) - 1):
    if S[i] == 'A' or S[i] == 'C':
        continue

    # A, B, Cの個数
    tmp = Q[i - 1] + Q[-1] - Q[i]
    if tmp < 0: tmp = 0
    ans += A[i - 1] * (C[-1] - C[i]) * pow_three[tmp]
    # ?, B, Cの個数
    tmp = Q[i - 1] - 1 + Q[-1] - Q[i]
    if tmp < 0: tmp = 0
    ans += Q[i - 1] * (C[-1] - C[i]) * pow_three[tmp]
    # A, B, ?の個数
    tmp = Q[i - 1] + Q[-1] - Q[i] - 1
    if tmp < 0: tmp = 0
    ans += A[i - 1] * (Q[-1] - Q[i]) * pow_three[tmp]
    # ?, B, ?の個数
    tmp = Q[i - 1] + Q[-1] - Q[i] - 2
    if tmp < 0: tmp = 0
    ans += Q[i - 1] * (Q[-1] - Q[i]) * pow_three[tmp]

    ans %= MOD

print(ans)


Measured memory_bytes: 12788
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<stdio.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

void solve(void){
    int n;
    cin  >> n;
    int ans = 0;
    for(int i = 1;i < n+1;i+=2){
        int count = 0;
        for(int j = 1;j < i+1;j++){
            if(i%j == 0)count++;
        }    
        if(count == 8) ans++;  
    }
    cout << ans <<endl;
}


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


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 114：B - 754


def main():
    S = raw_input().strip()

    min753 = 1000
    for i in range(len(S)-2):
        n = int(S[i:i+3])
        d = abs(753 - n)
        if d < min753:
            min753 = d
    print min753


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
n = int(input())

i = 1
ele = []
while i * i <= n:
    if n % i == 0:
        ele.append([i,n//i])
    i += 1

ans = 10**13
for i in range(len(ele)):
    ans = min(ans,ele[i][0]+ele[i][1]-2)
print(ans)

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N; cin >> N;
    string s; cin >> s;
    int cnt=0;
    for(int i=0;i<N-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#define MX 100000
#define mod
#define ll long long
const double pi = acos(-1.0);

using namespace std;

int main()
{
	int a[100001];
	int b[100001];
	memset(b,0,sizeof(b));
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]==i)
		b[i]=1;
	}
	int len=n;
	int ans=0;
	for(int i=1;i<=len;i++){
		if(b[i]==b[i+1]&&b[i]==1){
			ans++;
			b[i]=b[i+1]=0;
		}
		else if(b[i]==1&&a[i+1]!=i)
		{
			ans++;
			b[i]=0;
		}
	}
	printf("%d",ans);
}




Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static long N { get; private set; }
        public static long M { get; private set; }
        public static long Q { get; private set; }
        public static long MaxPoint { get; set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            (N, M, Q) = Read3Longs();
            var a = new long[Q];
            var b = new long[Q];
            var c = new long[Q];
            var d = new long[Q];
            for (int i = 0; i < Q; i++)
            {
                (a[i], b[i], c[i], d[i]) = Read4Longs();
            }

            MaxPoint = 0L;
            var A = new List<long>();
            NewMethod(a, b, c, d, A);

            return MaxPoint;
        }

        private static void NewMethod(long[] a, long[] b, long[] c, long[] d, List<long> A)
        {
            if (A.Count == N)
            {
                MaxPoint = Math.Max(MaxPoint, GetPoint(a, b, c, d, A));
                return;
            }

            var start = A.Count > 0 ? A.Last() : 0;
            for (long i = start; i < M; i++)
            {
                var copy = Copy(A);
                copy.Add(i);
                NewMethod(a, b, c, d, copy);
            }
        }

        private static List<long> Copy(List<long> l)
        {
            var r = new List<long>();
            foreach (var item in l)
            {
                r.Add(item);
            }
            return r;
        }

        private static long GetPoint(long[] a, long[] b, long[] c, long[] d, List<long> A)
        {
            var point = 0L;
            for (int i = 0; i < Q; i++)
            {
                if (A[(int)b[i] - 1] - A[(int)a[i] - 1] == c[i])
                {
                    point += d[i];
                }
            }

            return point;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

using namespace std;

int c[10][10], A[222][222];

int main()
{
	int H, W, r = 0;
	cin >> H >> W;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			cin >> c[i][j];
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++)
			cin >> A[i][j];
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			if (A[h][w] < 0) continue;
			int d[10] = {};
			d[A[h][w]] = 1;
			priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
			q.push(make_pair(1, A[h][w]));
			while (q.top().second != 1) {
				int u = q.top().second;
				q.pop();
				for (int i = 0; i < 10; i++) {
					int v = i;
					int l = c[u][v];
					if (d[v] && d[v] <= d[u] + l)
						continue;
					d[v] = d[u] + l;
					q.push(make_pair(d[v], v));
				}
			}
			r += d[1] - 1;
		}
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll l[26],r[26];
char s[110];
int main(){
	rep(i,0,26){
		l[i]=1000;
		r[i]=-1;
	}

	ll n;
	scanf("%lld%s",&n,s);
	rep(i,0,n){
		int t=s[i]-'a';
		l[t]=min(l[t],i);
		r[t]=max(r[t],i);
	}
	
	ll ans=0;
	rep(i,1,n){
		int cnt=0;
		rep(j,0,26)if(l[j]<i&&i<=r[j])cnt++;
		ans=max(ans,cnt);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128