akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

lint gcd(lint a, lint b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int n, w = 1, cnt;
int a[2 * 100010];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		if (a[i] == w) {
			++cnt;
			++w;
		}
	}
	if (cnt == 0) cout << -1 << endl;
	else cout << n - cnt << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k;
	int ans=-2;
	cin >>n>>k;
	string s;
	cin>>s;//ter:1
	int eff=k*2+1;
	bool eof=false;
	V dis;
	int cnt=0;
	char last='1';
	rep(i,n){
		if(last!=s[i]){
			dis.pb(cnt);
			//clog<<cnt<<endl;
			cnt=1;
		}else{
			cnt++;
		}
		last=s[i];
	}
	dis.pb(cnt);
	if (last == '0')
	{
		dis.pb(0);
	}
	dis.pb(-1);
	dis.pb(-1);
//	repi(itr,dis){
//		clog<<(*itr)<<" ";
//	}
	int at=0;
	cnt=0;
	//clog << endl;
	for(at=0;at<eff and !eof;at++){
		if(dis[at]==-1){
			eof=true;
		}else{
			cnt+=dis[at];
			chmax(ans,cnt);
		}
	}
	//clog<<"init:"<<cnt<<endl;
	for(at=eff; !eof;at+=2){
		cnt-=dis[at-eff];
		cnt -= dis[at - eff + 1];
		chmax(ans, cnt);
		if(dis[at]==-1){
			eof=true;
		}else{
			cnt+=dis[at];
			chmax(ans,cnt);
		}
		if (dis[at+1] == -1 and !eof)
		{
			eof = true;
		}else{
			cnt += dis[at+1];
			chmax(ans, cnt);
		}
		//clog<<cnt<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4332
N = int(input())
S = list(input())

rcnt = 0
gcnt = 0
bcnt = 0

for c in S:
    if c == 'R':
        rcnt += 1
    elif c == 'G':
        gcnt += 1
    elif c == 'B':
        bcnt += 1

ans = rcnt * gcnt * bcnt
for i in range(N):
    for j in range(i+1,N):
        k = 2 * j - i
        if k >= N:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1
print(ans)

Measured memory_bytes: 68576
#include <stdio.h>
int main(){
while(1){
int k,n,i,j,x[100000];
long long int max=0,sum=0;
scanf("%d%d",&n,&k);
if(n==0 && k==0) break;
for(i=0;i<n;i++){
scanf("%d",&x[i]);
}
for(i=0;i<k;i++){
	sum+=x[i];
}
for(i=1;i<=n-k;i++){
	if(x[i-1]<x[i+k-1]){
	sum=0;
for(j=i;j<i+k;j++){
sum+=x[j];
}
if(max<sum) max=sum;
	}
}
printf("%lld\n",max);
}
return 0;
}

Measured memory_bytes: 1416
n = int(input())
L = list(map(int,input().split()))
L4 = [x%4 == 0 for x in L]
L2 = [(x%2 == 0 and x%4 != 0) for x in L]
#print(sum(L2),sum(L4))
other = len(L) - sum(L2) - sum(L4)
if sum(L2) == 0:
    if other <= sum(L4)+1:
        print("Yes")
    else:
        print("No")
else:        
    if other <= sum(L4):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14252
#include <stdio.h>
#include <string.h>

int main(void)
{
	int color[8][3] = {
		{0, 0, 0},
		{0, 0, 255},
		{0, 255, 0},
		{0, 255, 255},
		{255, 0, 0},
		{255, 0, 255},
		{255, 255, 0},
		{255, 255, 255}
	};
	char color_name[8][8] = {
		"black",
		"blue",
		"lime",
		"aqua",
		"red",
		"fuchsia",
		"yellow",
		"white"
	};
	
	int d[8], R, G, B, min, i;
	char str[8];
	
	while (scanf("%s", str), strcmp(str, "0") != 0){
		min = 0;
		
		if (str[1] >= '0' && str[1] <= '9'){
			R = (str[1] - '0') * 16;
		}
		else {
			R = (str[1] - 'a' + 10) * 16;
		}
		
		if (str[2] >= '0' && str[2] <= '9'){
			R += str[2] - '0';
		}
		else {
			R += str[2] - 'a' + 10;
		}
		
		if (str[3] >= '0' && str[3] <= '9'){
			G = (str[3] - '0') * 16;
		}
		else {
			G = (str[3] - 'a' + 10) * 16;
		}
		if (str[4] >= '0' && str[4] <= '9'){
			G += str[4] - '0';
		}
		else {
			G += str[4] - 'a' + 10;
		}
		
		if (str[5] >= '0' && str[5] <= '9'){
			B = (str[5] - '0') * 16;
		}
		else {
			B = (str[5] - 'a' + 10) * 16;
		}
		if (str[6] >= '0' && str[6] <= '9'){
			B += str[6] - '0';
		}
		else {
			B += str[6] - 'a' + 10;
		}
		
		for (i = 0; i < 8; i++){
			d[i] = (color[i][0] - R) * (color[i][0] - R) 
			+ (color[i][1] - G) * (color[i][1] - G)
			+ (color[i][2] - B) * (color[i][2] - B);
			
			if (d[min] > d[i]){
				min = i;
			}
		}
		
		printf("%s\n", color_name[min]);
	}
	
	return (0);
}

Measured memory_bytes: 524
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll H,W,M;
    cin>>H>>W>>M;
    v h(H,0);
    v w(W,0);
    map<ll,map<ll,ll>> m;
    vector<pair<ll,ll>> bombs;
    rep(i,0,M){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        h[a]++;w[b]++;
        m[a][b] = 1;
        bombs.push_back(MP(a,b));
    }
    ll hm=0,wm=0;
    rep(i,0,H){
        hm = max(hm,h[i]);
    }
    rep(i,0,W){
        wm = max(wm,w[i]);
    }

    v h_list;
    v w_list;

    rep(i,0,H){
        if(hm == h[i])h_list.push_back(i);
    }
    rep(i,0,W){
        if(wm == w[i])w_list.push_back(i);
    }
    bool p1 = false;
    //cout<<hm<<wm;

    if(h_list.size() * w_list.size() > 300000)p1 = true;
    else {
        rep(i,0,h_list.size())rep(j,0,w_list.size()){
            if(m[h_list[i]][w_list[j]] != 1)p1 = true;
            //cout<<i<<" "<<j<<endl;
        }
    }
    /*rep(i,0,M){
        ll nowh = bombs[i].first;
        ll noww = bombs[i].second;
        bool a = binary_search(all(h_list),nowh);
        bool b = binary_search(all(w_list),noww);
        if(!(a && b))p1 = true;
    }*/
    if(p1)cout<<hm+wm;
    else cout<<hm+wm-1;
    return 0;
}

Measured memory_bytes: 68108
#include<stdio.h>
int main(void)
{
	int n, count, i, j, flag, times;
	int s[12], c[12];

	while (1) {
		scanf("%d", &n);
		if (n == 0)break;
		times = 0;
		for (i = 0; i < n; i++)
			scanf("%d", &s[i]);

		while (1) {
			for (i = 0; i < n; i++) {
				count = 0;
				for (j = 0; j < n; j++) {
					if (s[i] == s[j])
						count++;
				}
				c[i] = count;
			}
			flag = 1;
			for (i = 0; i < n; i++) {
				if (s[i] != c[i])flag = 0;

				s[i] = c[i];
			}
			if (flag == 1)break;
			times++;
		}
		printf("%d\n", times);
		for (i = 0; i < n; i++) {
			if (i == n - 1)printf("%d\n", s[n - 1]);
			else
				printf("%d ", s[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 596
n = int(input())
l = [int(input()) for x in range(n)]
l.sort()

p1 = []
p2 = []
for i in range(n):
    x = 2
    if i == 0 or i == n-1:
        x = 1
    if i % 2 == 0:
        p1.append(x)
        p2.append(-x)
    else:
        p1.append(-x)
        p2.append(x)
p1.sort()
p2.sort()
# print(p1)
# print(p2)
ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += l[i] * p1[i]
    ans2 += l[i] * p2[i]
    # print(ans1, ans2)

print(max(ans1, ans2))

Measured memory_bytes: 9556
n,l=map(int,input().split())
s=[]
a=0
for i in range(n):
    a=i+l
    s.append(a)
if sum(s)<0:
    s.remove(max(s))
elif 0 in s:
    s.remove(0)
else:
    s.remove(min(s))
print(sum(s))


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

const int N = 18 + 1;
int n;
ll ans;
string s1, s2, s;
map <pss, int> mp;

void solve(int msk) {
	string tmp1, tmp2;
	for (int i = n - 1; i >= 0; i--)
		if (msk & (1LL << i))
			tmp1 += s[n + i];
		else
			tmp2 += s[n + i];
	
//	reverse(tmp1.begin(), tmp1.end());
//	reverse(tmp2.begin(), tmp2.end());
	mp[pss(tmp1, tmp2)]++;
}

void solve2(int msk) {
	string tmp1, tmp2;
	for (int i = 0; i < n; i++)
		if (msk & (1LL << i))
			tmp1 += s[i];
		else
			tmp2 += s[i];
	
	ans += mp[pss(tmp1, tmp2)];
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> s;
	for (int i = 0; i < n; i++)
		s1 += s[i];
	for (int i = n; i < n; i++)
		s2 += s[i];
	
	for (int msk = 0; msk < (1LL << n); msk++)
		solve(msk);
	
	for (int msk = 0; msk < (1LL << n); msk++)
		solve2(msk);
	cout << ans;
}

Measured memory_bytes: 91904
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> a(n);
	int tn=INT_MAX;
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		tn=min(tn,a[i]);
		if(tn==a[i]){
			ans++;
		}
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, a, N) for(int i = a; i < N; i++)

int main() {
    int N;
    cin >> N;
    int A[100010];
    A[0] = 0;
    A[N + 1] = 0;
    rep(i, 1, N + 1) cin >> A[i];

    ll sum = 0;
    rep(i, 1, N + 2) sum += abs(A[i] - A[i - 1]);
    rep(i, 1, N + 1) {
        cout << (ll)(sum - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i - 1])) << endl;
    }
}

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

int main(){
	int n,m,ans = 0;
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		int a[100],ma = 0,x = 0;
		for(int j = 0;j < m;j++){
			cin >> a[j];
			a[j] = (a[j] + (i ? 1 : 0)) % 2;
			if(j && j < m - 1) x += (a[j] + 1) % 2;
		}
		if(m == 1){
			ans += a[0];
			continue;
		}
		ma = x + max(a[0] + (a[m - 1] + 1) % 2,a[m - 1] + (a[0] + 1) % 2);
		x += a[0] + a[m - 1];
		for(int j = 1;j < m - 1;j++){
			ma = max(ma,x + a[j] - (a[j] + 1) % 2);
		}
		ans += ma;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3124
n, k = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] -= 1

l = [-1]*(n + 1)
l[0] = 0

order = 0
now = 0

while k > 0:
    k -= 1
    now = a[now]
    order += 1
    if l[now] == -1:
        l[now] = order
    else:
        loop = order - l[now]
        k %= loop
        break

while k > 0:
    k -= 1
    now = a[now]

print(now + 1)

Measured memory_bytes: 32296
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int wa[100100];
bool ac[100100];

int main(void){
	int n,m,ans[2]={0,0},i,p;
	string s;
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> p >> s;
		--p;
		if(s=="AC"){
			ac[p] = true;
		}else if(!ac[p]){
			++wa[p];
		}
	}
	for(i=0; i<n; ++i){
		if(ac[i]){
			++ans[0];
			ans[1] += wa[i];
		}
	}
	cout << ans[0] << " " << ans[1] << endl;
	return 0;
}


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

using namespace std;

long long p[200005], d[200005];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long k, n;
	cin >> k >> n;
	for(long long i = 0; i < n; ++i) cin >> p[i];
	sort(p, p + n);
	d[0] = k - p[n - 1] + p[0];
	for(long long i = 1; i < n; ++i) d[i] = p[i] - p[i - 1];
	sort(d, d + n);
	cout << k - d[n - 1];

	return 0;
}



Measured memory_bytes: 3328
def cross(c1, c2):
    return c1.real * c2.imag - c1.imag * c2.real

def ccw(p0, p1, p2):
    if cross(p1 - p0, p2 - p0) > 0:
        return True
    else:
        False

# Andrew's algorithm
import collections

def andrew(point_list):
    point_list.sort(key = lambda c: (c.imag, c.real))
    point_que = collections.deque(point_list)
    convex_hull = []
    rest_points = []
    start_point = point_que.popleft()

    # outward
    convex_hull.append(start_point)
    convex_hull.append(point_que.popleft())

    while point_que:
        new_point = point_que.popleft()
        while ccw(convex_hull[-1], convex_hull[-2], new_point):
            rest_points.append(convex_hull.pop())
            if len(convex_hull) == 1:
                break
        convex_hull.append(new_point)

    # homeward
    rest_points.append(start_point)
    rest_points.sort(key = lambda c: c.imag)

    while rest_points:
        new_point = rest_points.pop()
        while ccw(convex_hull[-1], convex_hull[-2], new_point):
            convex_hull.pop()
        convex_hull.append(new_point)

    # output
    convex_hull.pop()
    print(len(convex_hull))
    for p in convex_hull:
        print("{0:.0f} {1:.0f}".format(p.real, p.imag))

# Acceptance of input
def string_to_complex(s):
    x, y = map(int, s.split())
    return x + y * 1j

import sys

file_input = sys.stdin

n = int(file_input.readline())

P = [string_to_complex(file_input.readline()) for i in range(n)]

# solve
andrew(P)

Measured memory_bytes: 24512
H, N = map(int, input().split())

dp = [[0] + [1e20] * (H) for _ in range(N)]

for i in range(N):
    A, B = map(int, (input().split()))
    for j in range(1, H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)

print(dp[-1][-1])

Measured memory_bytes: 377608
#include<stdio.h>
int main(void){
  int N,T,c,d,cost=2000;
  scanf("%d %d",&N,&T);
  for(int i=0;i<N;i++){
    scanf("%d %d",&c,&d);
    if(d<=T && c<cost){
      cost=c;
    }
  }
  if(cost!=2000){
    printf("%d\n",cost);
  }else{
    printf("TLE\n");
  }
  return 0;
}

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n;cin>>n;
  int p[n];
  rep(i, n){
    cin>>p[i];
    p[i]--;
  }

  int a[n]={};
  int b[n]={};

  rep(i, n){
    int l = p[i]*20000 + 1;
    int r = ten(9) - p[i]*20000;
    a[p[i]] = l+i;
    b[p[i]] = r;
  }

  rep(i, n) cout << a[i] << (i!=n-1 ? " " : "\n");
  rep(i, n) cout << b[i] << (i!=n-1 ? " " : "\n");

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,memo[2][200001],ans=INF;
string s;

signed main() {
    cin >> n >> s;
    rep1(i,n) {
        if (s[i-1] == '#') memo[0][i]++;
        else memo[1][i]++;
    }
    rep1(i,n) memo[0][i] += memo[0][i-1],memo[1][i] += memo[1][i-1];
    rep(i,n+1) ans = min(ans,memo[0][i]+memo[1][n]-memo[1][i]);
    cout << ans << endl;
}



Measured memory_bytes: 3716
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> t3;

using namespace std;

int main()
{
    int n;
    cin >> n;
    map<ll,ll> v;
    for(int i = 0;i < n;i++)
    {
        ll a;
        cin >> a;
        v[a]++;
    }
    vector<ll> ww;
    for(auto p = v.rbegin();p != v.rend();p++)
    {
        ll key = p->first;
        ll value = p->second;
        ll a = value/2;
        for(int i = 0;i < a;i++)
        {
            ww.push_back(key);
        }
        if(ww.size() >= 2)
        {
            break;
        }
    }
    if(ww.size() < 2)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << ww[0] * ww[1] << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

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

using namespace std;

template <class T> int find_index(T x, const std::vector<T> &v) {
    auto it = std::find(v.begin(), v.end(), x);
    if (it != v.end()) { return (int)std::distance(v.begin(), it); }
    return -1;
}

template <class T> void print(T x) {
    std::cout << x << std::endl;
}
// 4近傍（右, 下, 左, 上）
const vector<int> dy = { 0, -1, 0, 1 };
const vector<int> dx = { 1, 0, -1, 0 };




int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, C;
    cin >> N >> C;
    vector<vector<pair<int, int>>> c_s_t(C);
    FOR(i, 0, N) {
        int s, t, c;
        cin >> s >> t >> c;
        c_s_t[c - 1].emplace_back(make_pair(s * 2, t * 2));
    }

    vector<int> memo(2 * 100001, 0);
    FOR(c, 0, C) {
        vector<int> v(2 * 100001, 0);
        FOE(p, c_s_t[c]) {
            v[p.first - 1] += 1;
            v[p.second] -= 1;
        }
        FOR(i, 0, v.size() - 1) {
            v[i + 1] += v[i];
        }
        FOR(i, 0, v.size()) {
            memo[i] += min(v[i], 1);
        }
    }

    print(MAX(memo));

}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iomanip>
using namespace std;

 long double AnsP( long double n,  long double K){
        int i = n;
         long double p = 1;
        if(i >= K)return p;
        else{
                while(i < K){
                        i *= 2;
                        p *= 0.5;
                }
        return  p;
        }
}


int main()
{
         long double N, K;
        cin >> N >> K;
         long double P=0;
        for(int i=1; i<N+1; i++){
                P += AnsP(i, K);
        }
        cout << setprecision(15) << P/N;





}

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

int main() {

    int K;
    cin >> K;

    int64_t s = 0;

    for (int c = 1; c <= K; ++c)
    {
        for (int b = 1; b <= K; ++b)
        {
            for (int a = 1; a <= K; ++a)
            {
                s += std::gcd(gcd(a, b), c);
            }
        }
    }

    cout << s << endl;

    return 0;
}


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

int main(void) {
	int n, k;
	char s[11];
	char c;
	
	scanf("%d %s %d", &n, &s[0], &k);
	c = s[k-1];
	
	for (int i = 0; i < n; i++) {
		if (s[i] != c)
			printf("*");
		else
			printf("%c", s[i]);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
bool bo[100000] = { false };
int main(){
	int n, k, a, b;
	long long ans = 1, co = 1000000008;
	cin >> n >> k;
	vector<vector<int>> vec(n+10);
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		vec[a].emplace_back(b);
		vec[b].emplace_back(a);
	}
	ans *= k;
	k--;
	queue<pair<int,int>> que;
	que.emplace(make_pair(1,0));
	bo[1] = true;
	while (!que.empty()) {
		int k1 = k;
		for (int j = 0; j < vec[que.front().first].size(); j++) {
			if (bo[vec[que.front().first][j]] == false) {
				bo[vec[que.front().first][j]] = true;
				que.emplace(make_pair(vec[que.front().first][j], que.front().second + 1));
				ans = ans * k1 % 1000000007;
				k1--;
			}
		}
		if (que.front().second < 1) {
			if (co != que.front().second) {
				co = que.front().second;
				k--;
			}
		}
		que.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 7032
#include <iostream>      // cout, endl, cin
#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;

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


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
int a[10] , res;
int main()
{
    int n , t = 0;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if(x >= 1 && x < 400)
            a[0] = 1;
        else if(x < 800)
            a[1] = 1;
        else if(x < 1200)
            a[2] = 1;
        else if(x < 1600)
            a[3] = 1;
        else if(x < 2000)
            a[4] = 1;
        else if(x < 2400)
            a[5] = 1;
        else if(x < 2800)
            a[6] = 1;
        else if(x < 3200)
            a[7] = 1;
        else
            t++;
    }
    res = a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7];
    cout << max(res , 1) << " " << res + t << endl;
}


Measured memory_bytes: 256
n, t = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
l = []
flag = False
for i in range(n):
    if a[i][1] <= t:
        l.append(a[i][0])
        flag = True
if flag:
    print(min(l))
else:
    print('TLE')

Measured memory_bytes: 9184
input_nums = [int(c) for c in input().split(" ")]
h = input_nums[0]
w = input_nums[1]

count = 0

for i in range(h):
	for c in input():
		if c == "#":
			count += 1

if count == h+w-1:
	print("Possible")
else:
	print("Impossible")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,k,ans,m;

signed main(){
	cin>>n;
	cout<<ceil2(n,1000)*1000-n<<endl;
}

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

#define PI 3.14159265358979323846

// #define ll long long int
#define ff first
#define ss second
#define int long long int
#define pb push_back

#define N 10000010
#define MOD 1000000007

int bexp(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n, k;
    cin >> n >> k;
    int p[n + 1] = {}, c[n + 1] = {};

    for(int i = 1; i <= n; ++i)
        cin >> p[i];

    for(int i = 1; i <= n; ++i)
        cin >> c[i];
    
    int visi[n + 1] = {};    
    int ans = INT_MIN;
    for (int i = 1; i <= n; ++i)
    {
        int cnt = min(n + 1, k), no = 0, in = i;
        int l = cnt, c1 = 0;
        while(cnt--)
        {
            if (visi[in])
            {
                l = min(n + 1, k) - cnt - 1;
                c1 = in;
                break;
            }

            visi[in] = 1;
            no += c[p[in]];
            in = p[in];
            ans = max(ans, no);
        }

        if (c1)
        {   
            // cout << l << " " << in << endl;
            no = (k / l - 1) * no;
            cnt = k % l + l;
                ans = max(ans, no);
            while(cnt--)
            {
                no += c[p[in]];
                in = p[in];
                ans = max(ans, no);
            }
        }

        memset(visi, 0, sizeof(visi));
    }

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


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,ll> pii;
const int max_N=1e5+10;
int n,W;
const int inf=1e9+5;
vector <pii> G[max_N],rg[max_N];
vector<int>p(105,0);
ll w[105];
ll v[105];
int main()
{
  cin >> n>> W;
  for(int i=1;i<=n;i++)
    {
      cin >> w[i] >> v[i];
    }
  vector<vector<ll> >dp(105,vector<ll>(100005,inf));
  dp[0][0]=0;
  ll ans=0;
  for(int i=1;i<=n;i++)
    {
      for(int j=0;j<=100000;j++)
	{
	  dp[i][j]=dp[i-1][j];
	  if(j-v[i]>=0)
	    {
	      dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
	    }
	}
    }
  for(int i=0;i<=100000;i++)
    {
      if(dp[n][i]<=W)
	{
	  ans=i;
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 88064
//writer：Sakura
//problem：Remainder Reminder
//id：arc091_D
//from：AtCoder

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	//double i=2,j=3;
	ll ans=0;
	//cout<<i<<" "<<j<<endl;
	/*while(i<j && i<=N && j<=N){
		//cout<<i%j<<endl;
		//cout<<i<<" "<<j<<endl;
		if(i%j>=K){
			//cout<<i<<" "<<j<<endl;
			//cout<<i/j<<endl;
			if(j%i>=K)ans++;
			ans++,j++;
			if(i<=N && j>N){
				i++,j--;
			}
		}
		else i++,j--;
		//if(j<N && i>=N)break; 
	}*/
	//cout<<i<<" "<<j<<endl;
	int n,k;
	scanf("%d %d",&n,&k);
	if (k==0){
		for(int b=1;b<=n;b++)
			ans+=n/b*b+n%b;
		printf("%lld\n", ans);
		return 0;
	}
	for (int b=k+1;b<=n;b++){
		ans+=b-k;
		for (int i=1;(i+1)*b<=n;i++)
			ans+=b-k;
		if(n%b!=0 && n>b) ans+=max(0,n%b-k+1);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
A,B = map(int,input().split())
S = input()

res = True
if S[A] != '-':
	res = False

if res == True:
	for i in range(len(S)):
		if i == A:
			continue
		else:
			if S[i] >= "0" and S[i] <= "9":
				continue
			else:
				res = False
				break

print("Yes" if res == True else "No")

Measured memory_bytes: 3060
from collections import Counter

N=int(input())
a=list(map(int,input().split()))
ans={}

for i in a:
  if i-1 in ans:
    ans[i-1]+=1
  else:
    ans.setdefault(i-1,1)  

  if i in ans:
    ans[i]+=1
  else:
    ans.setdefault(i,1)
    
  if i+1 in ans:
    ans[i+1]+=1
  else:
    ans.setdefault(i+1,1)

answer= sorted(ans.values())
print(answer[-1])

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

int main()
{
  int len;

  while (scanf("%d", &len), len){
    int a[25];
    for (int i = 0; i < len; i++){
      scanf("%d", &a[i]);
    }
    int n = 32;
    for (int i = 0, j = 0;; i++){
      if (i % 2 == 0){
        n -= (n - 1) % 5;
      }
      else {
        n -= a[j % len];
        j++;
      }
      if (n <= 0){
        n = 0;
        printf("%d\n", n);
        break;
      }
      printf("%d\n", n);
    }
  }

  return (0);
}

Measured memory_bytes: 1188
function Main (input) {
  input = input.split("\n");
  input[1] = input[1].split(" ");
  var N = parseInt(input[0], 10);
  var S = input[1][0].split("");
  var T = input[1][1].split("");
  var ans = "";
  for (var i = 0; i < N; i++) {
    ans += S[i];
    ans += T[i];
  }
  console.log(ans);
}

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

Measured memory_bytes: 11468
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] d = new int[N+1];
		d[0] = X;
		for (int i = 1; i < N+1; i++) {
			int xi = sc.nextInt();
			d[i] = xi;
		}
		Arrays.sort(d);
		int dmin = Integer.MAX_VALUE;
		for (int i = 1; i < d.length; i++) {
			int dir = d[i] - d[i-1];
			if (dir != 0) {
				dmin = Math.min(dir, dmin);
			}
		}
		int index = 2;
		int dmins = dmin;
		while (true) {
			boolean key = true;
			for (int i = 0; i < d.length; i++) {
				int dir = Math.abs(X-d[i]);
				if (dir%dmin != 0) {
					while (true) {
						if (dmins%index == 0) {
							dmin = dmins/index;
							index++;
							break;
						} else {
							index++;
						}
					}
					key = false;
					break;
				}
			}
			if (key) {
				break;
			}
		}
		System.out.println(dmin);
	}
}


Measured memory_bytes: 59716
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        double x1,y1,x2,y2,x3,y3;
        cin >> x1 >>y1 >>x2 >> y2 >> x3 >> y3;
        double a1,a2,b1,b2,c1,c2,x,y,r;
         a1=2*(x2-x1);
         b1=2*(y2-y1);
         c1=x1*x1-x2*x2+y1*y1-y2*y2;
         a2=2*(x3-x2);
         b2=2*(y3-y2);
         c2=x2*x2-x3*x3+y2*y2-y3*y3;
         x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
         y=(c1*a2-c2*a1)/(a1*b2-a2*b1);
         r=hypot(x-x1,y-y1);
        printf("%.3lf %.3lf %.3lf\n",x,y,r);
    }
}



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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, k;
    ll res = 0;
    cin >> n >> k;
    vector<ll> num(n + 2);
    FOR (i, 1, n + 2) num[i] = i - 1;
    FOR (i, 1, n + 2) num[i] += num[i - 1];
    FOR (i, k, n + 2) {
        ll l = num[i] - num[0];
        ll r = num[n + 1] - num[n + 1 - i];
        res += (r - l + 1);
        res %= MOD;
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 4748
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

pair< double, double > polarToCartesian(pair< double, double > origin, double row, double theta) {
  return pair< double, double > (origin.first + row * cos(theta), origin.second + row * sin(theta));
}

void kochCurve(pair< double, double > origin, double row, double theta, int n) {
  if (n == 0) {
    pair< double, double > holder = polarToCartesian(origin, row, theta);
    cout << abs(holder.first) << ' ' << abs(holder.second) << endl;
    return;
  }
  kochCurve(origin, row/3, theta, n-1);
  kochCurve(polarToCartesian(origin, row/3, theta), row/3, theta+M_PI/3, n-1);
  kochCurve(polarToCartesian(origin, row/(sqrt(3)), theta+M_PI/6), row/3, theta-M_PI/3, n-1);
  kochCurve(polarToCartesian(origin, 2*row/3, theta), row/3, theta, n-1);
  return;
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  cout << fixed << setprecision(8);
  cout << 0.0 << ' ' << 0.0 << endl;
  kochCurve(pair< double, double > (0.0, 0.0), 100.0, 0.0, n);
  return 0;
}



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

void solve(){
    long long c = 7;
    int k; cin >> k;
    for(int i = 0; i < k; i++){
        if(c%k == 0){
            cout << i+1 << "\n";
            return;
        }
        c = ((c*10)+7)%k;
    }
    cout << -1 << "\n";
}

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

    bool multitest = false;
//    multitest = true;
    if(multitest){
        int t; cin >> t;
        while(t--)
            solve();
    }
    else
        solve();
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; 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 fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
//---------------------------------------------------------------------------//

int main(){
        ll a,b,x;
        cin>>a>>b>>x;
        ll i=a/x;
        if(a%x!=0) {
                i++;
        }
        ll j=b/x;
        cout<<j-i+1<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int main()
{
      string s;
      cin>>s;
      ll i;
       ll n=s.size();
       for(i=0;i<n;i++)
       {
       	if(s[i]==s[i+1] && i<n-1)
       	{
       		cout<< i+1 << " "<<i+2;
       		return 0;
		}
		else if(s[i]==s[i+2] && i<n-2)
		{
			cout<<i+1 <<" "<<i+3;
			return 0;
		}
	   }
	   cout<<"-1 -1";
	   return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <queue>
using namespace std;
struct st{int l, r, x, y;};
int n, a[200005], m[200005][20];
priority_queue<st> pq;
bool operator < (st p, st q) {return a[p.x]>a[q.x];}

int mn(int p, int q) {return a[p]<a[q] ? p:q;}

int f(int l, int r) {
	int j=0;
	while(1<<(j+1) <= r-l+1) j++;
	return mn(m[l][j], m[r-(1<<j)+1][j]);
}

void add(int l, int r) {
	int x, y;
	if(l>r) return;
	x = f(l, r);
	y = x+1==r ? r : mn(f(x+1, r-1), r);
	pq.push({l,r,x,y});
}

int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i=0; i<n; i++) scanf("%d", a+i), m[i][1] = i;
	for(j=2; ; j++) {
		k = 1<<j;
		if(k>n) break;
		for(i=0; i+k<=n; i++) m[i][j] = mn(m[i][j-1], m[i+k/2][j-1]);
	}
	for(add(0, n-1); !pq.empty(); ) {
		st t = pq.top(); pq.pop();
		printf("%d %d ", a[t.x], a[t.y]);
		add(t.l, t.x-1);
		add(t.x+1, t.y-1);
		add(t.y+1, t.r);
	}
	return 0;
}

Measured memory_bytes: 18676
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            //var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = int.Parse(Console.ReadLine());
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());

            Console.WriteLine((X - A) % B);
            //Console.Out.Flush();

        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define taskname "123"
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a, b, c;
int gt[maxn], igt[maxn];
int prob_a, prob_b, temp;

void read_input()
{
    cin >> n >> a >> b >> c;
}

int power(int x, int k)
{
    if(k == 0) return 1;
    int t = power(x, k / 2);
    if(k % 2 == 0) return 1LL * t * t % mod;
    else return 1LL * t * t % mod * x % mod;
}

void init()
{
    gt[0] = 1;
    for(int i = 1; i < maxn; ++i)
        gt[i] = gt[i - 1] * 1LL * i % mod;
    igt[maxn - 1] = power(gt[maxn - 1], mod - 2);
    for(int i = maxn - 2; i >= 0; --i)
        igt[i] = igt[i + 1] * 1LL * (i + 1) % mod;
    prob_a = a * 1LL * power(a + b, mod - 2) % mod;
    prob_b = b * 1LL * power(a + b, mod - 2) % mod;
    temp = 100 * 1LL * power(100 - c, mod - 2) % mod;
}

inline int C(int k, int n)
{
    return gt[n] * 1LL * igt[k] % mod * igt[n - k] % mod;
}

void solve()
{
    int ans = 0;
    for(int i = n; i < 2 * n; ++i)
    {
        int f;
        f = C(n - 1, i - 1) * 1LL * (power(prob_a, n) * 1LL * power(prob_b, i - n) % mod +
                                     power(prob_b, n) * 1LL * power(prob_a, i - n) % mod) % mod;
        ans = (ans + f * 1LL * i) % mod;
    }
    ans = ans * 1LL * temp % mod;
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);
    read_input();
    init();
    solve();
}


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

static const int INF=1000000;
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];
    }
  }
  for(int k=0;k<10;k++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        if(C[i][j]>C[i][k]+C[k][j])C[i][j]=C[i][k]+C[k][j];
      }
    }
  }
  int temp;
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>temp;
      if(temp !=-1) ans+=C[temp][1];
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
Mat = [[0]*10 for _ in range(10)] #[sentou][ushiro]
for i in range(1,N+1):
  s = str(i)
  Mat[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
  for j in range(10):
    ans += Mat[i][j]*Mat[j][i]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,m,a[MAXN],ans=1e9;
inline bool chk(int k){
	int tmp=0;
	Rep(i,2*k+1,n+k){
		if(a[2*(n+k)-i+1]+a[i]<m)return 0;
		tmp=max(tmp,a[2*(n+k)-i+1]+a[i]-m);
	}Rep(i,1,k)tmp=max(tmp,a[i]+a[2*k-i+1]);
	return ans=min(ans,tmp),1;
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read();Rep(i,1,2*n)a[i]=read();sort(a+1,a+2*n+1);
	for(int mid,l=0,r=n;l<=r;)chk(mid=l+r>>1)?r=mid-1:l=mid+1;
	cout<<ans<<'\n';
	return 0;
}




Measured memory_bytes: 4368
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, count, ans=400000;
    string S;

    cin >> N >> S;

    count = 0;

    for(i=1; i<N; i++){
        if(S[i]=='W'){
            count++;
        }
    }

    chmin(ans, N-1-count);

    for(i=1; i<N; i++){
        if(S[i-1] == 'E'){
            count++;
        }
        if(S[i] == 'W'){
            count--;
        }

        chmin(ans, N-1-count);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 900
s=str(input())
can=int(1)

if s[0]!='A':
    can=0

count=int(0)
big=int(0)

for i in range(2,len(s)-1):
    if s[i]=='C':
        count+=1
        big=i

if count!=1:
    can=0

for i in range(1,len(s)):
    if i==big:
        continue

    if s[i].isupper():
        can=0

if can:
    print("AC")
else:
    print("WA")

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

typedef long long LL;
const LL MX=1e18;

int main()
{
	int n; scanf("%d",&n);
	LL ans=1;
	LL ai;
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&ai);
		if(ai==0) ans=0;
		if(ans==0||ans==-1) continue;
		if(MX/ans<ai) ans=-1;
		else ans=ans*ai;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3820