akhauriyash/Code-Regression huggingface dataset:
S = input()
ans0 = 0
ans1 = 0
for i in range(len(S)):
    if i%2 == 0:
        if S[i] == '0':
            ans1 += 1
        else:
            ans0 += 1
    else:
        if S[i] == '1':
            ans1 += 1
        else:
            ans0 += 1
print(min(ans0,ans1))

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

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int x,y,dir;
	int w,h;
	string command;
	while(cin>>w>>h,w|h){
		x=y=1;dir=0;
		while(cin>>command,command!="STOP"){
			if(command=="FORWARD"){
				int s;
				cin>>s;
				for(int i=0;i<s;i++){
					int nx=x+dx[dir],ny=y+dy[dir];
					if(nx==0||w<nx||ny==0||h<ny)break;
					x=nx;y=ny;
				}
			}else if(command=="RIGHT"){
				dir = (dir+1)%4;
			}else if(command=="LEFT"){
				dir = (dir+3)%4;
			}else if(command=="BACKWARD"){
				int s;
				cin>>s;
				for(int i=0;i<s;i++){
					int nx=x+dx[(dir+2)%4],ny=y+dy[(dir+2)%4];
					if(nx==0||w<nx||ny==0||h<ny)break;
					x=nx;y=ny;
				}
			}
		}
		cout<<x<<' '<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int col[111111],n,m,q,x,y,v[111111],d[111111],c[111111];
vector<int> g[111111];
bool used[111111][11];
void dfs(int i,int dep,int co)
{
	if (!col[i]) col[i]=co;
	if (!dep || used[i][dep]) return;
	used[i][dep]=1;
	dfs(i,dep-1,co);
	for (int j=0;j<g[i].size();j++)
	{
		int to=g[i][j];
		dfs(to,dep-1,co);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);  
	}
	scanf("%d",&q);
	for (int i=1;i<=q;i++)
	{
		scanf("%d%d%d",&v[i],&d[i],&c[i]);
	}
	for (int i=q;i>=1;i--)
	{
		dfs(v[i],d[i],c[i]);
	}
	for (int i=1;i<=n;i++)
	{
		printf("%d\n",col[i]);
	}
	return 0;
}

Measured memory_bytes: 9464
s = input()

a = int(s[:2])
b = int(s[2:])

if a <= 12 and a != 0:
  if b <= 12 and b != 0:
    print("AMBIGUOUS")
  elif b > 12 or b == 0:
    print("MMYY")
else:
  if b > 12 or b == 0:
    print("NA")
  elif b <= 12:
    print("YYMM")
    

Measured memory_bytes: 2940
#! /usr/bin/env python3


N = int(input())
A = list(map(int, input().split()))
cnt = 0
cnt2 = 0
for i in A:
    if i % 4 == 0:
        cnt += 1
    elif i % 2 == 0:
        cnt2 += 1
        
a = cnt >= len(A) // 2
b = cnt + cnt2 // 2 >= len(A) // 2
if a or b:
    print('Yes')
else :
    print('No')


Measured memory_bytes: 14252
def gcd(a,b):
    while a>0:
        a,b  = b%a, a
    return b

N = int(input())
A = [int(c) for c in input().split()]

gcd_l = []
d = A[0]
for a in A:
    d = gcd(d,a)
    gcd_l.append(d)

gcd_r = []
d = A[-1]
for a in reversed(A):
    d = gcd(d,a)
    gcd_r.append(d)
gcd_r = list(reversed(gcd_r))

gcd_a = [gcd_r[1]]
for i in range(1,N-1):
    gcd_a.append(gcd(gcd_l[i-1], gcd_r[i+1]))
gcd_a.append(gcd_l[N-2])

print(max(gcd_a))


Measured memory_bytes: 14400
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int rangesum(int lo, int hi, vi& pre) {
	if(lo==0)
		return pre[hi]%MOD;
	return (pre[hi]-pre[lo-1]+MOD)%MOD;
}
int32_t main(void)
{
	IOS;
	int n, k;
	cin>>n>>k;
	vi a(n);
	for(int i = 0; i < n; i++)
		cin>>a[i];
	int dp[2][k+1];
	vi pre(k+1, 0);
	for(int i = 0; i <= k; i++) {
		if(i <= a[0]) dp[0][i]=1;
		else dp[0][i]=0;
	}
	pre[0]=dp[0][0];
	for(int i = 1; i <= k; i++)
		pre[i]=(pre[i-1]+dp[0][i])%MOD;
	int cur=1;
	// for(int i =	 0; i <= k; i++)
	// 	cout<<dp[0][i]<<" ";
	// cout<<endl;
	for(int i = 1; i < n; i++) {
		// for(int j = 0; j <= k; j++)
		// 	cout<<pre[j]<<" cdc ";
		// cout<<endl;
		for(int j = 0; j <= k; j++)
			dp[cur][j]=0;
		for(int j = 0; j <= k; j++) {
			// cout<<i<<" "<<max(0ll, j-a[i])<<" "<<j<<" "<<rangesum(max(0ll, j-a[i]), j, pre)<<endl;
			dp[cur][j]=rangesum(max(0ll, j-a[i]), j, pre);
		}
		pre[0]=dp[cur][0];
		for(int j = 1; j <= k; j++)
			pre[j]=(pre[j-1]+dp[cur][j])%MOD;
		// for(int j = 0; j <= k; j++)
		// 	cout<<dp[cur][j]<<" ";
		// cout<<endl;
		cur^=1;
	}
	cout<<dp[cur^1][k]<<endl;
	time();
	return 0;
}

Measured memory_bytes: 2560
open Hashtbl
let n = Scanf.scanf " %d" (+) 0
let ws = Array.init n @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let h = create n
let _ = Array.fold_left (fun c w -> if mem h w || c <> w.[0] then (print_endline "No"; exit 0); add h w 1; w.[String.length w - 1]) ws.(0).[0] ws |> ignore; print_endline "Yes"

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int H,W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    REP(i, H) REP(j, W) {
        cin >> a[i][j];
    }
    vector<pair<pair<int, int>, pair<int, int>>> ans;
    REP(i, H){
        REP(j, W-1){
            if(a[i][j] & 1){
                a[i][j+1]++;
                a[i][j]--;
                ans.pb(make_pair(pii(i+1, j+1),  pii(i+1, j+2)));
            } 
        }
        if(i != (H-1) && a[i][W-1]&1){
                a[i+1][W-1]++;
                a[i][W-1]--;
                ans.pb(make_pair(pii(i+1, W),  pii(i+2, W)));           
        }
    }
    pr(ans.size());
    for(auto&& i: ans){
        pr(i.fi.fi, i.fi.se, i.se.fi, i.se.se);
    }
}

Measured memory_bytes: 5232
#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int MAX = 1024;

bitset<MAX> grid[MAX];

void generate(int size) {
    if (size == 1) {
        grid[0][0] = 0;
        return;
    }

    generate(size / 2);

    for (int i = 0; i < size / 2; i++)
        for (int j = 0; j < size / 2; j++) {
            grid[size / 2 + i][j] = grid[i][j];
            grid[i][size / 2 + j] = grid[i][j];
            grid[size / 2 + i][size / 2 + j] = !grid[i][j];
        }
}

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

    int N, M;
    cin >> N >> M;
    int NN = (1 << N) - 1, MM = (1 << M) - 1;
    generate(max(NN, MM) + 1);

    for (int i = 0; i < NN; i++) {
        for (int j = 0; j < MM; j++) {
            int ans = (grid[i][j] ^ grid[i][j + 1] ^ grid[i + 1][j] ^ grid[i + 1][j + 1]);
            cout << ans;
        }

        cout << '\n';
    }
}


Measured memory_bytes: 1408
n = int(input())
a = list(map(int, input().split()))
arr = []

for i in a:
    tmp = 0
    for j in range(1, 30):
        if i % 2 == 0:
            i /= 2
            tmp += 1
        else:
            break
    arr.append(tmp)
print(min(arr))

Measured memory_bytes: 3060
use ::proconio::input;

fn main() {
    input! {
        k: usize,
        a: usize,
        b: usize,
    }
    let mut i: usize = k;
    let mut res: &str = "NG";
    while i <= 1000 {
        if a <= i && i <= b {
            res = "OK";
            break;
        } else {
            i += k;
        }
    }

    println!("{}", res);
}


Measured memory_bytes: 2112
p={}
H,W,D=map(int,input().split())

for h in range(H):
    A=list(map(int,input().split()))
    for w in range(W):
        p[A[w]]=[h,w]

Series=[]
for d in range(1,D+1):
    distance=[0]
    while d+D<=H*W:
        distance.append(distance[-1]+abs(p[d][0]-p[d+D][0])+abs(p[d][1]-p[d+D][1]))
        d+=D
    Series.append(distance)

#print(Series)
Q=int(input())
Ans=[]
for q in range(Q):
    l,r=map(int,input().split())
    if l%D==0:
        Idx=D-1
    else:
        Idx=l%D-1
    Ans.append(Series[Idx][(r-Idx-1)//D]-Series[Idx][(l-Idx-1)//D])

for i in range(Q):
    print(Ans[i])

Measured memory_bytes: 31904
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 1000005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d", &n);
    int a = n % 10;
    if (a == 3) {
        printf("bon");
    } else if (a == 0 || a == 1 || a == 6 || a == 8) {
        printf("pon");
    } else {
        printf("hon");
    }
    return 0;
}

Measured memory_bytes: 3752
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x)      x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? (a=b,1) : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? (a=b,1) : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;

    int N = s.length();

    rep(i, N-1) {
        const char a = s[i];
        const char b = s[i+1];
        const char c = (i+2) < N ? s[i+2] : '~';

        if (a == b) {
            cout << i+1 << ' ' << i+2 << endl;
            return 0;
        }
        if (a == c) {
            cout << i+1 << ' ' << i+3 << endl;
            return 0;
        }
    }

    cout << -1 << ' ' << -1 << endl;

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：大工の褒美
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/0117
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----
const ll INF = 1001001001;

// グローバル変数（入力）
ll n, s, g, V, P, K[32][32];

void initK() {
  rep(i, 32) {
    rep(j, 32) { K[i][j] = INF; }
  }
}

// 入力
void input() {
  ll m;
  scanf("%lld%lld", &n, &m);
  initK();
  rep(i, m) {
    ll a, b, c, d;
    scanf("%lld,%lld,%lld,%lld", &a, &b, &c, &d);
    K[a][b] = c;
    K[b][a] = d;
  }
  scanf("%lld,%lld,%lld,%lld", &s, &g, &V, &P);
}

void solve() {
  // ワーシャルフロイド
  rep1(k, n) {
    rep1(i, n) {
      rep1(j, n) { K[i][j] = min(K[i][j], K[i][k] + K[k][j]); }
    }
  }

  cout << V - P - K[s][g] - K[g][s] << endl;
}

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



Measured memory_bytes: 3252
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'

void solve(){
	int n,x,m;
	cin>>n>>x>>m;
	vector<int>pos(m,-1);
	vector<int>val;
	int curr=x;
	int p=0;
	while(p<n){
		if(pos[curr]!=-1){
			p=pos[curr];
			break;
		}
		pos[curr]=p;
		p++;
		val.push_back(curr);
		curr=(curr*curr)%m;
	}
	int ans=0;
	for(int i=0;i<p;i++){
		ans+=val[i];
	}
	if(p<val.size()){
		int total=(val.size()-p);
		int mul=(n-p)/total;
		int rem=(n-p)%total;
		for(int i=p;i<val.size();i++){
			ans+=(mul+(rem>0?1:0))*val[i];
			rem--;
		}
	}
	cout<<ans<<endl;
}

int32_t main(){

	//remove for interactive problems
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	solve();
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

	return 0;
}

Measured memory_bytes: 4628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#define FOR(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
int main (int argc, char *argv[])
{
	std::ios::sync_with_stdio(false);
	string temp;cin>>temp;
	int n=temp.size();
	int nowcnt=0;
	int ans=0;
	FOR(i,0,n-1){
		if (temp[i]=='S'){
			nowcnt++;
		}else{
			if (nowcnt==0)	ans++;
			else nowcnt--;
		}
	}
	cout<<ans*2<<endl;
	return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
long long dist(vector<long long>A,long long n,long long i)
{
    long long cnt = 0;
    for (long long j = 0;j<n;j++){
        cnt+=(A[j]-i)*(A[j]-i);
    }
    return cnt;
}
int main()
{
    long long n;
    cin>>n;
    vector<long long>A(n);
    for (long long i = 0;i<n;i++)cin>>A[i];
    long long  ans = dist(A,n,0);
    for (long long i = 0;i<=100;i++){
        ans = min(ans,dist(A,n,i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int WH[2], x, y, r, A[4], B[4], T = 0;
	cin >> WH[0] >> WH[1] >> x >> y >> r;
	A[0] = x + r; B[0] = y;
	A[1] = x; B[1] = y + r;
	A[2] = x - r; B[2] = y;
	A[3] = x; B[3] = y - r;
	for (auto a : A) {
		if (a >= 0 && a <= WH[0])T++;
	}
	for (auto a : B) {
		if (a >= 0 && a <= WH[1])T++;
	}
	if (T == 8)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3100
#include <stdio.h>

int main(void) {
	int i,j,k,n,m,d,r=0;
	char s[128][128];
	scanf("%d%d%d",&n,&m,&d);
	for(i = 0;i < n;i++){
		scanf("%s",s[i]);
	}
	for(i = 0;i < n;i++){
		for(j = 0;j <= m-d;j++){
			for(k = j;k < j+d;k++){
				if(s[i][k] == '#'){break;}
				if(k == (j+d-1)){r++;}
			}
		}
	}
	for(j = 0;j < m;j++){
		for(i = 0;i <= n-d;i++){
			for(k = i;k < i+d;k++){
				if(s[k][j] == '#'){break;}
				if(k == (i+d-1)){r++;}
			}
		}
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    vector<vector<int>> a(3, vector<int>(3));
    vector<vector<int>> ans(3, vector<int>(3));
    rep(i,3) rep(j,3) cin >> a[i][j];
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    for(int x : b){
        rep(i,3){
            rep(j,3){
                if(x == a[i][j]) ans[i][j]++;
            }
        }
    }
    bool bingo = false;
    if(ans[0][0] == 1 && ans[1][1] == 1 && ans[2][2] == 1) bingo = true;
    if(ans[0][2] == 1 && ans[1][1] == 1 && ans[2][0] == 1) bingo = true;

    rep(i,3){
        if(ans[0][i] == 1 && ans[1][i] == 1 && ans[2][i] == 1) bingo = true;
    }
    rep(i,3){
        if(ans[i][0] == 1 && ans[i][1] == 1 && ans[i][2] == 1) bingo = true;
    }
    // rep(i,3){
    //     rep(j,3){
    //         cout << ans[i][j];
    //     }
    //     cout << endl;
    // }
    if(bingo) cout << "Yes" << endl;
    else cout<< "No" << endl;
    return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < n; i++) 

using namespace std;

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

    if (n%(a+b) < a) {
        cout << a*(n/(a+b)) + n%(a+b);
    }
    else {
        cout << a*(n/(a+b)) + a;
    }
    return 0;
}

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

void swap(int b, int e, int t, long* A);

int main(void){
  int n;
  cin>>n;
  long A[n];
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  int q;
  cin>>q;
  int b,e,t;
  for(int i=0;i<q;i++){
    cin>>b>>e>>t;
    swap(b,e,t,A);
  }
  for(int i=0;i<n-1;i++){
    cout<<A[i]<<" ";
  }
  cout<<A[n-1]<<endl;
  return 0;
}


void swap(int b,int e,int t,long* A){
  long tmp;
  for(int k=0;k<e-b;k++){
    tmp=A[t+k];
    A[t+k]=A[b+k];
    A[b+k]=tmp;
  }
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll x; cin >> x;
  bool beki[1001] = {false};
  beki[1] = true;
  FOR(i, 2, 1001){
    ll c = i*i;
    if(c > 1000) break;
    while(c <= 1000){
      beki[c] = true;
      c *= i;
    }
  }
  IREP(i, x+1){
    if(beki[i]){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
 
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
 
#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)
 
typedef long long ll;
typedef pair<int, int> pii;

#define MAX 200
#define OFFSET 100

int brd[MAX][MAX];
int done[MAX][MAX];

int t, n;
int sx, sy;

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

int ans;

void solve(int depth, int y, int x)
{
	if (depth > t) return;
	if (brd[y][x]) return;
	if (done[y][x] != -1 &&
		depth >= done[y][x]) return;
	done[y][x] = depth;

	rep(i, 6)
		solve(depth+1, y+dy[i], x+dx[i]);
}

int calc()
{
	solve(0, sy+OFFSET, sx+OFFSET);
	int ans = 0;
	rep(j, MAX) rep(i, MAX)
		if (done[j][i] != -1)
			ans++;
	return ans;
}

int main(void)
{
	while (cin >> t >> n, t|n) {
		memset(brd, 0, sizeof(brd));
		memset(done, -1, sizeof(done));

		rep(i, n) {
			int x, y;
			cin >> x >> y;
			brd[y+OFFSET][x+OFFSET] = 1;
		}

		cin >> sx >> sy;
		cout << calc() << endl;
	}
    return 0;
}

Measured memory_bytes: 1476
#include<stdio.h>
int main()
{
    int N;
    scanf("%d",&N);
    int A[1000];
    int max,min,i,p;
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    max=A[0];
    min=A[0];

    for(i=0;i<N;i++){
        if(max<A[i]){
            max=A[i];


    }

    else if(min>A[i]){
            min=A[i];

    }
    }

    p=max-min;
    printf("%d",p);
    return 0;
}


Measured memory_bytes: 128
#素因数分解して列挙する関数、約数列挙ではない！
from collections import Counter
def factorize(n):
  b = 2
  fct = []
  while b * b <= n:
    while n % b == 0:
      n //= b
      fct.append(b)
    b = b + 1
  if n > 1:
    fct.append(n)
  f = Counter(fct).values()
  if 1 not in f and len(set(f))==1:
    return True
  return False

X = int(input())
for i in range(X,0,-1):
  f = factorize(i)
  if f==True or i==1:
    print(i)
    break

Measured memory_bytes: 9392
#include<iostream>
using namespace std;
int main(){
	int input[10],temp,i;
	for(i=0;i<10;i++){
		cin>>input[i];
	}
	for(i=0;i<10;i++){
		for(int j=i+1;j<10;j++){
			if(input[i]<input[j]){
				temp=input[i];
				input[i]=input[j];
				input[j]=temp;
			}
		}
	}
	for(int k=0;k<3;k++)
		cout<<input[k]<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>

int main()
{
  int n, k;
  std::cin >> n >> k;
  std::string s;
  std::cin >> s;
  s.at(k-1) = s.at(k-1) - 'A' + 'a';
  std::cout << s << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector <double> v(n);
  for ( int i; i<n; i++ )  cin >> v[i];
  sort(v.begin(),v.end());
  double t=0;
  t = (v[0]+v[1])/2;
  if(n==2){
    cout << t << endl;
    exit(0);
  }
  double u=0;
  if(n>=2){
    for(int i=2; i<n; i++){
      u = (t + v[i])/2;
      t = u;
    }
    cout << u << endl;
    exit(0);
  }
}

Measured memory_bytes: 256
# ABD106D

N,M,Q=map(int,input().split())
Trs=[tuple(map(int,input().split())) for i in range(M)]
pqs=[tuple(map(int,input().split())) for i in range(Q)]

cs=[[0 for i in range(N+1)] for j in range(N+1)]
for tr in Trs:
    cs[tr[0]][tr[1]]+=1
for i in range(N):
    for j in range(N):
        cs[i+1][j+1]+=cs[i+1][j]
for i in range(N):
    for j in range(N):
        cs[i+1][j+1]+=cs[i][j+1]
        
for pq in pqs:
    p=pq[0]
    q=pq[1]
    n=cs[q][q]-cs[q][p-1]-cs[p-1][q]+cs[p-1][p-1]
    print(n)

Measured memory_bytes: 44520
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int X = sc.nextInt();
            int N = sc.nextInt();
            int[] p = new int[N];
            for (int i = 0; i < N; i++) {
                p[i] = sc.nextInt();
            }

            HashSet<Integer> set = new HashSet<Integer>();
            for (int i = 0; i < N; i++) {
                set.add(p[i]);
            }

            int min = (int) 1e9;
            int minY = (int) 1e9;
            for (int y = -100; y <= 200; y++) {
                if (set.contains(y)) {
                    continue;
                }
                if (Math.abs(y - X) < min) {
                    min = Math.abs(y - X);
                    minY = y;
                }
            }
            System.out.println(minY);
        }
    }
}


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

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

    int a,b;
    cin >> a >> b;
    cout << 6-a-b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, l;
    while(1){
        cin >> n >> l;
        if(n == 0 && l == 0) break;
        vector<int> d(n), a(n);
        vector<vector<int> > now(l + 1, vector<int>());
        vector<vector<int> > next(l + 1, vector<int>());
        int t = 0, idx = 0;
        rep(i, 0, n){
            char c;
            cin >> c >> a[i];
            now[a[i]].push_back(i);
            if(c == 'R'){
                d[i] = 1;
                chmax(t, l - a[i]);
            }else{
                d[i] = 0;
                chmax(t, a[i]);
            }
        }
        rep(i, 0, t){
            rep(j, 0, l + 1) next[j].clear();
            repb(j, l - 1, 1){
                if(now[j].size() == 2){
                    swap(d[now[j][0]], d[now[j][1]]);
                    swap(a[now[j][0]], a[now[j][1]]);
                }
                rep(k, 0, now[j].size()){
                    if(d[now[j][k]] == 1){
                        next[j + 1].push_back(now[j][k]);
                        if(j + 1 == l) idx = now[j][k];
                    }else{
                        next[j - 1].push_back(now[j][k]);
                        if(j - 1 == 0) idx = now[j][k];
                    }
                }
            }
            swap(now, next);
        }
        cout << t << ' ' << idx + 1 << endl;
    }
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main()
{
    int N, Z, W; cin >> N >> Z >> W;

    vector<int> a(N);

    REP(i, N)
        cin >> a[i];

    if( N == 1 )
        cout << abs( a[0] - W ) << endl;
    else
    {
        int hoge = abs( a[N-2] - a[N-1] );
        int fuga = abs( W - a[N-1] );

        cout << max(hoge, fuga) << endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
    int a,i,c=0,j,k,l;

        cin>>a;


i=a%10;a=a/10;
j=a%10;a=a/10;
k=a%10;a=a/10;
l=a%10;

    if(i==j || j==k|| k==l)
        cout<<"Bad\n";

    else

        cout<<"Good\n";

    return 0;
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = 998244353;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
const int maxN = 305;
int dp[maxN][maxN][maxN];
int add_delta[maxN][maxN][maxN];
string s;
int K;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> s >> K;
    K = min(K, (int)s.size() + 1);
    vector < int > sizes;
    vector < int > zeros;
    zeros.emplace_back(-1);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') zeros.emplace_back(i);
    }
    int ones = s.size() - zeros.size() + 1;
    zeros.emplace_back(s.size());
    for (int i = 0; i + 1 < zeros.size(); i++) {
        sizes.emplace_back(zeros[i + 1] - zeros[i] - 1);
    }
    dp[0][0][0] = 1;
    int n = sizes.size();
    vector < int > suf(n);
    suf[n - 1] = sizes[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        suf[i] = suf[i + 1] + sizes[i];
    }
    for (int pos = 0; pos < n; pos++) {
        for (int val = 0; val <= K; val++) {
            int cur_d = 0;
            for (int need = 0; need <= ones; need++) {
                cur_d = sum(cur_d, add_delta[pos][need][val]);
                dp[pos][need][val] = sum(dp[pos][need][val], cur_d);
                if (dp[pos][need][val] == 0) continue;
                int c = sizes[pos];
                for (int will = max(c - need, 0); will <= c; will++) {
                    dp[pos + 1][need - (c - will)][val + c - will] = sum(
                        dp[pos + 1][need - (c - will)][val + c - will], dp[pos][need][val]);
                }
                add_delta[pos + 1][need + 1][val] = sum(add_delta[pos + 1][need + 1][val], dp[pos][need][val]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= K; i++) {
        ans = sum(ans, dp[n][0][i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 58860
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

vector<int> a;
bool f;
set<vector<int> > s;


void solve() {
  rep(i,8) {
    rep(k,4) {
      rep(j,3) {
        swap(a[j],a[j+1]);
        swap(a[j+4],a[j+5]);
      }
      if(s.count(a)) f=1;
    }
    if(i==4) {
      rep(j,3) {
        swap(a[j],a[j+1]);
        swap(a[j+4],a[j+5]);
      }
    }
    swap(a[0],a[3]);
    swap(a[3],a[7]);
    swap(a[4],a[7]);
    swap(a[1],a[2]);
    swap(a[2],a[6]);
    swap(a[5],a[6]);
  }
}

void Main() {
  string t[8];
  while(R t[0]) {
    REP(i,1,8) R t[i];
    vector<int> b(8);
    map<string,int> c;
    s.clear();
    rep(i,8) {
      if(c[t[i]]) b[i]=c[t[i]];
      else {
        int x=c.size();
        c[t[i]]=x;
        b[i]=x;
      }
    }
    sort(all(b));
    do {
      a=b;
      f=0;
      solve();
      if(!f) s.in(b);
    } while(next_permutation(all(b)));
    pr(s.size());
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 1404
#include <iostream>
using namespace std;
int n,m;
int ans;
void dfs(int sum,int i,int n){
  if(n == 0 && sum == m){
    ans++;
    return;
  } 
  if(n == 0 || i == 10)return; 
  dfs(sum,i+1,n);
  dfs(sum+i,i+1,n-1);
}
int main(){
  while(cin >> n >> m,n){
    ans = 0;
    dfs(0,0,n);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
fun main(args : Array<String>) {
    val (a, b, c, x, y) = readLine()!!.split(" ").map { it.toInt() }

    if (a + b <= c * 2) {
        println(a * x + b * y)
        return
    }

    var sum = 0
    if (x > y) {
        sum = c * 2 * y
        if (a >= c * 2) {
            sum += (c * 2)*(x-y)
        } else {
            sum += a * (x-y)
        }
    } else {
        sum = c * 2 * x
        if (b >= c * 2) {
            sum += (c * 2)*(y-x)
        } else {
            sum += b * (y-x)
        }
    }

    println(sum)
}

Measured memory_bytes: 37880
#include<stdio.h>

int main(void){

	int i;
	int dice[7];
	char word[100];
	for (i=1; i<7; i++){
		scanf("%d", &dice[i]);
	}	/* ??????????????????????????????????????¢?????°????????\??? */

	scanf("%s", word);
		for (i=0; word[i] != '\0'; i++) {
		dice[0] = dice[1];
		switch (word[i]) {

		/* ????????????E?????????????????????????????? */
	case 'E':
		dice[1] = dice[4];
		dice[4] = dice[6];
		dice[6] = dice[3];
		dice[3] = dice[0];
			break;

		/* ????????????W?????????????????????????????? */
	case 'W':
		dice[1] = dice[3];
		dice[3] = dice[6];
		dice[6] = dice[4];
		dice[4] = dice[0];
			break;

		/* ????????????N?????????????????????????????? */
	case 'N':
		dice[1] = dice[2];
		dice[2] = dice[6];
		dice[6] = dice[5];
		dice[5] = dice[0];
			break;

		/* ????????????S?????????????????????????????? */
	case 'S':
		dice[1] = dice[5];
		dice[5] = dice[6];
		dice[6] = dice[2];
		dice[2] = dice[0];
			break;
		}
	}
	printf("%d\n", dice[1]);	/* ?????¨?????¢????????£???????????¢?????\????????????????????°???????????? */

	return 0;
}

Measured memory_bytes: 596
from collections import deque

d = deque()
inversion = 1

s = input()

for i in range(len(s)):
    d.append(s[i])

q = int(input())

for i in range(q):
    qn = list(input().split())
    if qn[0] == "1":
        inversion *= -1
    elif qn[0] == "2":
        if qn[1] == "1":
            if inversion == 1:
                d.appendleft(qn[2])
            elif inversion == -1:
                d.append(qn[2])
        if qn[1] == "2":
            if inversion == 1:
                d.append(qn[2])
            elif inversion == -1:
                d.appendleft(qn[2])

for i in range(len(d)):
    if inversion == 1:
        print(d.popleft(), end="")
    if inversion == -1:
        print(d.pop(), end="")

print()


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

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

    set<int> st;
    for(int i = 0; i < 3; i++){
        int a;
        cin >> a;
        st.insert(a);
    }

    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]

    ans = 0
    tmp = 0
    for a in A:
        tmp += 1 / a
    
    ans = 1 / tmp
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 300005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k,mpp[505],x;
string s;
PII p[li];
vector<lo> v;

int main(void){
	scanf("%lld %lld",&n,&m);
	for(lo i=1;i<=n;i++){
		scanf("%lld %lld",&p[i].fi,&p[i].se);
	}
	sort(p+1,p+n+1);
	FOR{
		cev+=p[i].se;
		if(cev>=m){printf("%d\n",p[i].fi);return 0;}
	}
	return 0;
}


Measured memory_bytes: 3072
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt();
    int a = sc.nextInt();
    int[] h = new int[n];
    double[] res = new double[n];
    double min;
    int ans;
    h[0] = sc.nextInt();
    res[0] = t - h[0]*0.006;
    min = Math.abs(a-res[0]);
    ans = 0;
    for(int i=1;i<n;i++){
      h[i] = sc.nextInt();
      res[i] = t - h[i]*0.006;
      if(Math.abs(a-res[i])<min){
        min = Math.abs(a-res[i]);
        ans=i;
      }
    }
    ans++;
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 24404
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskATCCFQCA solver = new TaskATCCFQCA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskATCCFQCA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            char[] ar = in.next().toCharArray();

            int cpos = -1;
            int fpos = -1;

            for (int i = 0; i < ar.length; i++) {
                if (ar[i] == 'C' && cpos == -1) {
                    cpos = i;
                } else if (ar[i] == 'F') {
                    fpos = i;
                }
            }

            if (cpos != -1 && fpos != -1 && cpos < fpos) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }
    }
}


Measured memory_bytes: 9684
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-10;
 
struct C{
  P p;
  double r;
  C(P p,double r=1):p(p),r(r){}
};
 
int getState(C a,C b){
  double dist=abs(a.p-b.p);
  if(dist>a.r+b.r+eps)return 4;
  if(dist>a.r+b.r-eps)return 3;
  if(dist>abs(a.r-b.r)+eps)return 2;
  if(dist>abs(a.r-b.r)-eps)return 1;
  return 0;
}
 
int main(){
  double ax,ay,ar,bx,by,br;
  cin>>ax>>ay>>ar>>bx>>by>>br;
  cout<<getState(C(P(ax,ay),ar),C(P(bx,by),br))<<endl;
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int a,b,h;
  cin>>a>>b>>h;
  cout<< (a+b)*h/2 <<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []  A = new int [n];
        for(int i=0;i<n;i++)A[i] = sc.nextInt();
        int num = partition(A,0,n-1);
        System.out.print(A[0]);
        for(int i=1;i<n;i++){
            if(i!=num) System.out.print(" "+A[i]);
            else System.out.print(" ["+A[i]+"]");
        }
        System.out.println();
    }
    public static int partition(int [] A,int p,int r){
        int x = A[r];
        int i = p-1;
        for(int j=p;j<r;j++){
            if(A[j]<=x){
                i++;
                A=swap(A,i,j);
            }
        }
        A=swap(A,i+1,r);
        return i+1;
    }
    public static int [] swap(int A[],int i,int j){
        int num = A[i];
        A[i] = A[j];
        A[j] = num;
        return A;
    }
}


Measured memory_bytes: 69352
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int ans = 100000000;
    for(int i = 0; i < s.size()-2; i++){
        int plus = (s[i] - '0')*100 + (s[i+1] - '0')*10 + (s[i+2] - '0');
        int res = abs(plus-753);
        ans = min(res, ans);
    }
    cout << ans;
}


Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int n;
map<int,int> times;

int main(){
    cin >> n;
    rep(i,0,n){
        int x;
        cin >> x;
        times[x]++;
    }
    if(sz(times) > 2) puts("No");
    else if(sz(times) == 1) {
        int x = times.begin()->fi;
        if(x == n - 1) puts("Yes");
        else if(1 <= x && x <= n / 2) puts("Yes");
        else puts("No");
    } else if(sz(times) == 2) {
        auto it = times.begin();
        int x = it->fi , xcnt = it->se;
        ++it;
        int y = it->fi , ycnt = it->se;
        if(y != x + 1 || ycnt == 1) puts("No");
        else if(xcnt + 1 <= y && y <= xcnt + ycnt / 2) puts("Yes");
        else puts("No");
    }
    return 0;
}


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

int main(){
	int m, d, ans, month, i, total = 0;
	while(1){
		cin >> m >> d;
		if (m == 0) break;
		for(i = 1; i < m; i ++){
			if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
				total += 31;
			}
			else if(i == 2){
				total += 29;
			}
			else{
				total += 30;
			}
		}
		total += d;

		ans = total % 7;

		switch (ans){
		case 1:cout << "Thursday" << endl;
			break;
		case 2:cout << "Friday" << endl;
			break;
		case 3:cout << "Saturday" << endl;
			break;
		case 4:cout << "Sunday" << endl;
			break;
		case 5:cout << "Monday" << endl;
			break;
		case 6:cout << "Tuesday" << endl;
			break;
		case 0:cout << "Wednesday" << endl;
			break;
		}
		
		ans = 0, total = 0;
	}

	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define pb push_back
#define em emplace
#define vv vector<ll>
#define fr(i,x) for(int i=0;i<x;i++)
#define MAX 10000005
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    
    if(a.first == b.first) return a.second<b.second;
    return (a.first < b.first); 
}

//ll a[MAX];
void sieve(){
    for (int i = 1; i < MAX; i++)
    {
        for (int j = i; j <= MAX; j+=i)
        {
           // a[j]++;
        }
        
    }
    
}
int countDigit(ll n){
    ll c = 0;
    while (n!=0)
    {
        c++;
        n/=10;
    }
    return c;
    
}
ll decimalToBinary(ll N) 
{ 
  
    ll B_Number = 0; 
    ll cnt = 0; 
    while (N != 0) { 
        int rem = N % 2; 
        ll c = pow(10, cnt); 
        B_Number += rem * c; 
        N /= 2; 
        cnt++; 
    } 
    //cout << cnt << endl;
    return cnt; 
} 
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;
    cin >> n;
    string stR;
    for (ll i = 0; i < n; i++)
    {
        cout << "ACL";
    }
    
   
   
}

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
#define int long long

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX;
const int INF = INT_MAX;

inline constexpr int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b)*(1|((a - b)>>(8*sizeof(int))));}

int gcd(int a, int b) {
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

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

	string S;
	cin >> S;

	int Rnum = 0, Gnum = 0, Bnum = 0;
	VI Ridx(N,-1), Gidx(N,-1), Bidx(N,-1);

	int ri = 0, gi = 0, bi = 0;
	rep(i, N) {
		if (S[i] == 'R') Ridx[Rnum++] = i;
		else if (S[i] == 'G') Gidx[Gnum++] = i;
		else Bidx[Bnum++] = i;
	}

	int sum = 0;
	rbf(b, Bidx) {
		if (b < 0) break;
		rbf(g, Gidx) {
			if (g < 0) break;
			int num = Rnum;
			if (b > g) {
				int idx = g - (b - g);
				if (idx >= 0) {
					if (S[idx] == 'R') num--;
				}
				idx = b + (b - g);
				if (idx < N) {
					if (S[idx] == 'R') num--;
				}
				if ((b + g) % 2 == 0) {
					int idx = (b + g) / 2;
					if (S[idx] == 'R') num--;
				}
				sum += num;
			}
			else {
				int idx = b - (g - b);
				if (idx >= 0) {
					if (S[idx] == 'R') num--;
				}
				idx = g + (g - b);
				if (idx < N) {
					if (S[idx] == 'R') num--;
				}
				if ((b + g) % 2 == 0) {
					int idx = (b + g) / 2;
					if (S[idx] == 'R') num--;
				}
				sum += num;
			}

		}
	}

	COL(sum);
	
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n,k;
	cin >> n >> k;
	vector<ll> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	vector<ll> sum;
	for(int i = 0; i < n; i++){
		ll res = 0;
		for(int j = i; j < n; j++){
			res += a[j];
			sum.push_back(res);
		}
	}
	
	ll two = 1;
	for(int i = 0; i < 40; i++){
		two *= 2;
	}
	ll ans = 0;
	for(int l = 0; l <= 40; l++){
		int cnt = 0;
		// for(int i = 0; i < n; i++){
		// 	for(int j = i; j < n; j++){
		// 		if(((ans+two)&a[j]) == (ans+two)){
		// 			cnt++;
		// 		}
		// 	}
		// }
		for(int i = 0; i < sum.size(); i++){
			if(((ans+two)&sum[i]) == (ans+two)){
				cnt++;
			}
		}
		if(cnt >= k){
			//cout << two << endl;
			ans += two;
		}
		two /= 2;
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

int main()
{   
    int k;
    cin >> k;
    int x = 7%k;
    set<int> s;
    int i = 1;
    while(s.count(x)==0) {
        if(x == 0) {
            cout << i << endl;
            return 0;
        }
        s.insert(x);
        x = (x*10+7)%k;
        i++;
    }
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 50464