akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


ll dp[1 << 14];

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	vector<int> a(M), b(M), c(M, 0);


	for (int i = 0; i < M; i++)
	{
		cin >> a[i] >> b[i];

		int cnt = 0;
		for (int j = 0; j < b[i]; j++)
		{
			int t;
			cin >> t;
			cnt += (1 << (t - 1));
		}
		c[i] = cnt;
	}
	for (int i = 0; i < 1 << 14 - 1; i++)
	{
		dp[i] = LINF;
	}

	dp[0] = 0;

	for (int i = 0; i < (1 << N); i++)
	{
		for (int j = 0; j < M; j++)
		{
			dp[(i | c[j])] = min(dp[(i | c[j])], dp[i] + a[j]);
		}
	}

	if (dp[(1 << N) - 1] == LINF) {
		cout << "-1" << endl;
	}
	else
	{
		cout << dp[(1 << N) - 1] << endl;
	}

}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> dis(k);
  for(int i = 0;i < k;i++)cin >> dis[i];
  while(1){
    string s = to_string(n);
    bool now = true;
    for(int i = 0;i < s.size();i++){
      bool can = true;
      for(int j = 0;j < k;j++){
        if((int)(s[i] - '0') == dis[j])can = false;
      }
      if(!can)now = false;
    }
    if(now){
      cout << n << endl;
      return 0;
    }
    n++;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n;
  int a,b,c;
  int i;
  int z;

  scanf("%d ",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d ",&a,&b,&c);
    if( a>b ){
      if( a<c ){
	z=a;
	a=c;
	c=z;
      }
    } else {
      if( b>c ){
	z=a;
	a=b;
	b=z;
      } else {
	z=a;
	a=c;
	c=z;
      }
    }

    if( a*a== b*b+c*c )
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

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

int main() {
    long long N, K; cin >> N >> K;
    vector<long long> A(N), F(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<long long>());
    
    long long ng = -1;
    long long ok = A[N-1] * F[0];
    while(abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        long long cut_cost = 0;
        for(int i = 0; i < N; ++i) cut_cost += max(0LL, A[i] - mid / F[i]);
        if(cut_cost <= K) ok = mid;
        else ng = mid;
    }
    
    cout << ok << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#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--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  ll n , m ;
  cin >> n >> m ;
  ll ans = 0 ;
  vector<pair<ll,ll>> dri(n) ;
  
  REP(i,n){
    ll a, b ;
    cin >> a >> b ;
    dri.at(i) = make_pair(a,b) ;
  }
  
  sort(ALL(dri)) ;
  
  ll i = 0 ;
  while(m!=0){
    if(dri.at(i).SE<=m){
      ans += dri.at(i).FI*dri.at(i).SE ;
      m -= dri.at(i).SE ;
      i++ ;
    }
    else{
      ans += dri.at(i).FI*m ;
      m = 0 ;
      i++ ;
    }
  }
  
  
  cout << ans <<endl ;
      
    

  return 0 ;
}

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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c== 'i' || c == 'u' || c == 'e' || c == 'o')
    cout<< "vowel" << endl;
  else
    cout << "consonant" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,0,n-1) cin>>a[i];
    int ans=0;
    rep(i,0,n-2){
        if(a[i]==a[i+1]){
            a[i+1] = 20000;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n;
  cin>>n;
  vector<ll> a(n),b(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i]>>b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  double med_min=(n%2==0)?(a[n/2]+a[n/2-1])*0.5 :a[n/2];
  double med_max=(n%2==0)?(b[n/2]+b[n/2-1])*0.5 :b[n/2];
  cout<<((n%2==0)?1+(ll)((med_max-med_min)*2):1+(ll)(med_max-med_min))<<endl;
}


Measured memory_bytes: 6432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n,m,a;
    int ans=0;
    cin>>m>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a>(m+1)/2){
            ans=a-(m-a)-1;
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // [b,c) イテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

vector<bool> seen;
void dfs(VVI &G, int v, int cnt){
    seen[v] = true;
    ++cnt;
    for (int nv: G[v]){
        if (seen[nv]) continue;
        if (cnt <= 2) dfs(G, nv, cnt);
        else return;
    }
}

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

int N,  M; cin >> N >> M;
VVI G(N+1);
rep(i, 0, M){
    int a, b; cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
}

seen.assign(N+1, false);
dfs(G, 1, 0);
if (seen[N]) cout << "POSSIBLE\n";
else cout << "IMPOSSIBLE\n";

}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



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




























int main () {
    vector<long long> a(100001, 0);
    long long N;
    cin >> N;
    long long sum = 0;
    for (long long i = 0; i < N; i ++) {
        long long n;
        cin >> n;
        sum += n;
        a[n]++;
    }

    long long Q;
    cin >> Q;
    vector<long long> sum_history(Q);

    for (long long i = 0; i < Q; i++) {
        long long b, c;
        cin >> b >> c;
        sum += a[b] * (c - b);
        a[c] += a[b];
        a[b] = 0;
        sum_history[i] = sum;
    }

    for (long long i = 0; i < Q; i++) {
        cout << sum_history[i] << endl;
    }
}

Measured memory_bytes: 4852
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
struct S{
    mint a, sz, rp;
};
S op(S l, S r) { return {l.a * r.sz + r.a, l.sz * r.sz, l.rp * r.sz + r.rp}; }
S e() { return {0, 1, 0}; }
S mapping(int l, S r) {
    if (l) return {r.rp * l, r.sz, r.rp};
    return r;
}
int composition(int l, int r) { return l ? l : r; }
int id() { return 0; }
signed main(){
    int n, q;
    cin >> n >> q;
    lazy_segtree<S, op, e, int, mapping, composition, id> seg(vector(n, S{1, 10, 1}));
    int l, r, d;
    for (int i = 0;i<q;i++){
        cin >> l >> r >> d;
        seg.apply(--l, r, d);
        cout << seg.all_prod().a.val() << endl;
    }
}

Measured memory_bytes: 12796
def comb(a,b):
    import math
    return math.factorial(a)//(math.factorial(a-b)*math.factorial(b))

from itertools import accumulate
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=1)
va = v[:A]
maxa = sum(va)/A
maxsum = sum(va)
print(maxa)
count = 1
if va[0] == va[-1]:
    v0 = va[0]
    v0c = v.count(v0)
    ans = comb(v0c,A)
    for i in range(A,B):
        if v[i] == v0:
            ans += comb(v0c,i+1)
    print(ans)
else:
    v1 = va[-1]
    v1c = va.count(v1)
    v1c2 = v.count(v1)
    print(comb(v1c2,v1c))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int solve(int N, vector<int> A)
{
    vector<vector<int>> G(N+1);
    for (int i = 0; i < A.size(); i++) {
        G[A[i]].push_back(i+2);
    }
    function<int(int)> recur = [&](int i){
        if (G[i].empty()) return 0;
        vector<int> A;
        for (auto child : G[i]) {
            A.push_back(recur(child));
        }
        sort(begin(A), end(A));
        int k = 0;
        for (int i = 0; i < A.size(); i++, k++) {
            if (k < A[i]) k = A[i];
        }
        return k;
    };
    return recur(1);
}
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N-1); for (auto &a : A) cin >> a;
    cout << solve(N, A) << endl;
    return 0;
}

Measured memory_bytes: 14336
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, K =MI()
    num = [1] * 10
    for m in LI():
        num[m] = 0
    # print(num)

    def check(x):
        s = set(list(str(x)))
        return all([num[int(i)] for i in s])

    while 1:
        if check(N):
            print(N)
            return
        N += 1
    

if __name__ == '__main__':
    solve()



Measured memory_bytes: 9080
#include<cstdio>
#include<climits>
#include<cstring>
#include<algorithm>
#define INF 99999999
using namespace std;

int G[20][20];
int d[1<<20][20];
int dd[20][1<<20];
int n,m;
/*
int dsearch(int cur,int sto)
{
    printf("%d %d %d\n",cur,sto,d[cur][sto]);
    if(d[cur][sto] >= 0) return d[cur][sto];
    if(sto == (1<<n) - 1 && cur == 0) return d[cur][sto] = 0;
    int res = INF;
    for(int i=0;i<n;i++)
        if(!(sto >> i & 1))
            res = min(res,dsearch(i,(sto|(1<<i))) + G[cur][i]);
    return d[cur][sto] = res;
}
*/

int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=0;i<n;i++)
            fill(G[i],G[i]+n,INF);

        for(int i=0;i<m;i++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            G[a][b] = c;
        }

        for(int i=0;i<(1<<n);i++)
           fill(d[i],d[i]+n,INF);
       /* for(int i=0;i<n;i++)
            fill(d[i],d[i]+(1<<n),INF);*/


        d[(1 << n) - 1][0] = 0;

        for(int i = (1<<n) - 2; i >= 0; i--)
            for(int j = 0; j < n; j++)
                for(int k = 0; k < n; k++)
                    if(!(i >> k & 1))
                        d[i][j] = min(d[i][j],d[i | 1 << k][k] + G[k][j]);

        printf("%d\n",d[0][0]==INF?-1:d[0][0]);
        //printf("%d\n",dsearch(0,0));
    }
    return 0;
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int X;
    cin >> X;
    if (400 <= X && X <= 599) ans = 8;
    if (600 <= X && X <= 799) ans = 7;
    if (800 <= X && X <= 999) ans = 6;
    if (1000 <= X && X <= 1199) ans = 5;
    if (1200 <= X && X <= 1399) ans = 4;
    if (1400 <= X && X <= 1599) ans = 3;
    if (1600 <= X && X <= 1799) ans = 2;
    if (1800 <= X && X <= 1999) ans = 1;
    cout << ans << endl;
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_a && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3608
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
#include <cassert>
#include <memory>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//↑templete
signed main(){

    int N, K;
    cin>>N>>K;

    vint A;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        A.pb(a);
    }
    sort(A.begin(), A.end());
    int sum = 0;
    for(int i=0;i<K;i++)
        sum+=A[i];

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	string s;
	cin>>s;
	bool check=false;
	if(s[0]==s[1] && s[1]==s[2])check=true;
	if(s[1]==s[2] && s[2]==s[3])check=true;
	cout<<((check)?"Yes":"No")<<endl;
	return 0;
}

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

void chmin(int &a, int b) {
    if (a > b) a = b;
}

int main() {
    int n, k;
    cin >> n >> k;

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

    vector<int> dp(n + k, 1e9);
    dp[0] = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    
    cout << dp[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const double eps = 1e-9;
struct V {
  double x, y;
  V(double x=0, double y=0): x(x), y(y) {}
  V& operator+=(const V& v) { x += v.x; y += v.y; return *this;}
  V operator+(const V& v) const { return V(*this) += v;}
  V& operator-=(const V& v) { x -= v.x; y -= v.y; return *this;}
  V operator-(const V& v) const { return V(*this) -= v;}
  V& operator*=(double s) { x *= s; y *= s; return *this;}
  V operator*(double s) const { return V(*this) *= s;}
  V& operator/=(double s) { x /= s; y /= s; return *this;}
  V operator/(double s) const { return V(*this) /= s;}
  double dot(const V& v) const { return x*v.x + y*v.y;}
  double cross(const V& v) const { return x*v.y - v.x*y;}
  double norm2() const { return x*x + y*y;}
  double norm() const { return sqrt(norm2());}
  
  int ort() const { // orthant
    if (fabs(x) < eps && fabs(y) < eps) return 0;
    if (y > 0) return x>0 ? 1 : 2;
    else return x<0 ? 3 : 4;
  }
  bool operator<(const V& v) const {
    int o = ort(), vo = v.ort();
    if (o != vo) return o < vo;
    return cross(v) > 0;
  }
};
std::istream& operator>>(std::istream& is, V& v) {
  is >> v.x >> v.y; return is;
}
std::ostream& operator<<(std::ostream& os, const V& v) {
  os<<"("<<v.x<<","<<v.y<<")"; return os;
}

ll N;

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

  std::vector<V> vs(N);

  for( auto &v : vs )
    std::cin >> v;

  std::sort( all(vs) );

  double ans = 0;

  rep( l, N ) {
    ll r = l;
    V len;

    double ma = 0;

    rep( i, N ) {
      len += vs[r];

      chmax( ma, len.norm() );

      r = (r+1)%N;
    }

    chmax( ans, ma );
  }

  printf( "%.12f\n", ans );

  return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  string s;
  char t[3];
  cin >> s;
  rep(i,3) {
    if (s[i] == '1') t[i] = '9';
    if (s[i] == '9') t[i] = '1';
  }
  cout << t << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#include <vector>
#include <limits.h>
#include <stack>
#include <queue>
#include<cstdlib>
#define maxn 10000000
#define pi acos(-1)
using namespace std;
#define M 1000007
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){//将字符转换为数值；
	if ( ch == 'A') return 1;
	else if ( ch == 'C') return 2;
	else if ( ch == 'G') return 3;
	else if ( ch == 'T') return 4;
	else return 0;
}

/* 将字符串转换为数值并生成key */
long long getKey(char str[]){
	long long sum = 0, p = 1, i;
	for ( i = 0; i < strlen(str); i++ ){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
	long long key,i,h;
		key=getKey(str);
		for(i=0;;i++)
		{
			h=(h1(key)+i*h2(key))%M;
			if(strcmp(H[h], str)==0)return 1;
			else if(strlen(H[h])==0)return 0;
		}
		return 0;
}

int insert(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++)
	{
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h], str)==0)return 1;
		else if(strlen(H[h])==0)
		{
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
		int i, n, h;
		char str[L], com[9];
		for ( i = 0; i < M; i++ ) H[i][0] = '\0';
		
		scanf("%d", &n);
		
		for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
		}

		return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

using namespace std;

typedef long long ll;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n; cin>>n;
  
  rep(i, 26) {
    rep(j, 15) {
      int sum = 4*i + 7*j;
      if(sum == n) {
        cout<<"Yes";
        return 0;
      }
    }
  }
  
  cout<<"No";
  
  return 0;
}

Measured memory_bytes: 3624
# ABC141E - Who Says a Pun?
def resolve():
    N = int(input())
    S = input().rstrip()
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg, checked = 0, set()
        for i in range(N - 2 * mid + 1):
            checked.add(hash(S[i : i + mid]))
            if hash(S[i + mid : i + 2 * mid]) in checked:
                flg = 1
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter
    print(ok)  # max length of substrings appeared twice or more


resolve()

Measured memory_bytes: 3376
#t = Time.now
#N, K, Q = 2000, 10, 10
#as = (0...N).to_a.shuffle
N, K, Q = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

ia = N.times.map{|i|[i, as[i]]}.sort_by{|arr|arr[1]}

ans = Float::INFINITY
used = Array.new(N) + [true]
(N-Q+1).times do |i|
    if ia[i+Q-1][1] - ia[i][1] >= ans
        used[ia[i][0]] = true
        next
    end
    avail = []
    tmp = []
    d = 0
    (N+1).times do |j|
        if used[j]
            if d >= K
                tmp.sort!
                avail.concat(tmp[0, d-K+1])
            end
            tmp = []
            d = 0
        else
            d += 1
            tmp.push(as[j])
        end
    end
    avail.sort!
    if avail.length >= Q
        cand = avail[Q-1] - ia[i][1]
        ans = cand if ans > cand
    end
    used[ia[i][0]] = true
end

puts ans
#p Time.now - t

Measured memory_bytes: 5240
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[100001];
	int men[100000];
	int i;
	long long  sum;
	int now,next;
	cin>>n;
	for(i=0;i<=n;i++)	cin>>box[i];
	for(i=0;i<n;i++)	cin>>men[i];
	sum=0;
	for(i=0;i<n;i++){
		now=min(box[i],men[i]);
		sum+=now;
		next=min(box[i+1],men[i]-now);
		box[i+1]-=next;
		sum+=next;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long 
#define ld long double
using namespace std;
const ll INF = 1e18;
const ll MOD = 998244353;


vector<string> vec_splitter(string s) {
		s += ',';
		vector<string> res;
		while(!s.empty()) {
				res.push_back(s.substr(0, s.find(',')));
				s = s.substr(s.find(',') + 1);
		}
		return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
		if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
		stringstream ss; ss << H;
		cerr << args[idx] << " = " << ss.str();
		debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define deb(...) 42
#endif
int dp[200000];
vector<vector<int>> edges;
bool line[200000];

void dfs(int u, int par = -1){
	for(auto v : edges[u]) {
		if(v != par){
			if((int)edges[v].size() == 2)	dfs(v, u);
			else {
				dp[v]++;
				return;
			}
		}
	}
}

int32_t main() {
	ios::sync_with_stdio(!cin.tie(NULL));

	int n;
	cin >> n;
	int u, v;
	edges.resize(n + 1);
	for(int i = 0; i < n - 1 ; i++){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	int root = 0;
	for(int i = 0; i < n; i++){
		if(edges[i].size() > edges[root].size())	root = i;
	}
	if(edges[root].size() < 3){
		cout << 1 << "\n";
		return 0;


	}
	memset(dp, 0, sizeof(dp));
	int res = 0;
	for(int i = 0; i < n; i++)	if((int)edges[i].size() == 1) dfs(i);
	for(int i = 0; i < n; i++)	res += max(0, dp[i] - 1);
	cout << max(1, res) << "\n";
}




Measured memory_bytes: 10076
N = int(input()) 
h = list(map(int, input().split()))

Dp = [None]*N

Dp[0] = 0
Dp[1] = abs(h[1]-h[0])

for i in range(2,N):
  Dp[i] = min(Dp[i-1]+abs(h[i]-h[i-1]),Dp[i-2]+abs(h[i]-h[i-2]))


print(Dp[N-1])

Measured memory_bytes: 13980
from fractions import gcd

a, b = map(int, raw_input().strip().split())
g = gcd(a, b)

ans = 1

for d in xrange(2, g + 1):
    if (d * d) > g: break

    if (g % d == 0):
        ans += 1
        while (g % d == 0):
            g /= d

if (g > 1): ans += 1

print ans

Measured memory_bytes: 34792
#[allow(dead_code)]
fn main() {
    let n = i::u();
    let a = i::uv(n + 1);
    let sum = a.iter().sum();

    //なるべく早くsumまで枝を広げる
    let mut current_branch = 1;
    let mut leaves = 0;
    let mut ans = 0;
    for k in a {
        if current_branch - leaves < k {
            println!("{}", -1);
            return;
        }
        ans += current_branch - leaves;
        leaves += k;
        current_branch = min(sum, current_branch * 2 - leaves);
       // dbg!(&ans, &leaves, &current_branch);
    }
    if sum > leaves {
        println!("{}", -1);
        return;
    }
    println!("{}", ans);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn str() -> String {
        read()
    }
    pub fn s() -> Vec<char> {
        str().chars().collect()
    }
    pub fn i() -> i64 {
        read()
    }
    pub fn u() -> usize {
        read()
    }
    pub fn u2() -> (usize, usize) {
        (read(), read())
    }
    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }
    pub fn u4() -> (usize, usize, usize, usize) {
        (read(), read(), read(), read())
    }
    pub fn u5() -> (usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read())
    }
    pub fn u6() -> (usize, usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read(), read())
    }
    pub fn f() -> f64 {
        read()
    }
    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }
    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }
    pub fn iv3(n: usize) -> Vec<(i64, i64, i64)> {
        (0..n).map(|_| iv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }
    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }
    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }
    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }
    pub fn uv4(n: usize) -> Vec<(usize, usize, usize, usize)> {
        (0..n)
            .map(|_| uv(4))
            .map(|a| (a[0], a[1], a[2], a[3]))
            .collect()
    }
    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }
    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

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

  vector<int> A(N);
  for(int x = 1; x*x < N; ++x){
    for(int y = 1; x*x + y*y < N; ++y){
      for(int z = 1; x+x + y*y + z*z < N; ++z){
        int v = x*x + y*y + z*z + x*y + y*z + z*x;
        if(v > N) continue;
        ++A[v-1];
      }
    }
  }
  for(auto e : A)
    cout << e << "\n";
}


Measured memory_bytes: 3492
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

int kLunLun(int k) {
    queue<int> q;
    q.push(0);

    int count = -1;

    while (q.size()) {
        const int x = q.front();
        q.pop();
        count++;
        if (count == k) return x;

        for (int i = 0; i < 10; i++) {
            if (x == 0 && i == 0) continue;
            if (abs(x % 10 - i) <= 1 || x == 0) {
                q.push(x * 10 + i);
            }
        }
    }
}

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

    int k;
    cin >> k;

    cout << kLunLun(k) << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <array>
#include <vector>

using namespace std;

template<int mod>
struct Ring_mod {
    int val;
    Ring_mod(): val(0) {}
    Ring_mod(int x)
    {
        x += (x < 0 ? mod : 0);
        x -= (x >= mod ? mod : 0);
        val = x;
    }
    explicit operator int() { return val; }
    Ring_mod operator+(const Ring_mod& b) { return Ring_mod(val + b.val); }
    Ring_mod operator-(const Ring_mod& b) { return Ring_mod(val - b.val); }
    void operator+=(const Ring_mod& b) { val = Ring_mod(val + b.val).val; }
    void operator-=(const Ring_mod& b) { val = Ring_mod(val - b.val).val; }
};
typedef Ring_mod<(int) 1e9 + 7> int_mod;

int main()
{
    int n;
    cin >> n;
    vector<vector<char> > compat(n, vector<char>(n));
    for (auto& r : compat)
        for (auto& c : r)
            cin >> c;

    vector<int_mod> dp(1 << n);
    dp[0] = 1;
    for (int mask = 1; mask < 1 << n; ++mask) {
        int i = __builtin_popcount(mask) - 1;
        for (int j = 0; j < n; ++j)
            if (((mask >> j) & 1) && compat[i][j] == '1')
                dp[mask] += dp[mask ^ (1 << j)];
    }
    cout << (int) dp[(1 << n) - 1];
    return 0;
}


Measured memory_bytes: 8448
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

// 素数の列挙
vector<ll> baisu(10000010,0);

int main(){
    ll N;
    cin>>N;
    ll ans=0;
    REP2(i,1,10000010){
        REP2(j,1,10000010){
            if(i*j>10000010) break;
            baisu[i*j]++;
        }
    }
    REP2(i,1,N+1){
        ans+=i*baisu[i];
    }
    cout<<ans<<endl;
    
    

    
}

Measured memory_bytes: 81244
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define ll long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000005
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define PI M_PI
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
int add(int a, int b) {a=(a%mod + b%mod)%mod;return a;}
int sub(int a, int b) {a =(a%mod - b%mod + mod)%mod ;return a;}
int mul(int a, int b) {return (a%mod * b%mod) % mod;}


void solve()
{  int n,i,temp=0,cur,flag=0,ans=0;
    cin >> n;int A[n+5],active[n+5];
  for(i=0;i<=n;i++)
  {
    cin >> A[i];
    active[i]=100000000000000000;
  }
  
  for(i=0;i<=n;i++)
  {
    if(i==0)
    {
      if(A[i]>1)flag=1;
      //temp=A[i];
      cur=1;
     // ans=1;
    }
    else
    {
      if((cur) < A[i] )
      flag=1;
    }
    active[i]=cur-A[i];
    cur=(cur-A[i])*2;
    if(cur>=100000000000000000)break;
  }
  if(flag==1)
  {
    cout<<"-1"<<endl;
    return ;
  }
 // cout<<temp<< " "<<ans<<endl;
  for(i=n;i>=0;i--)
  {
    if(i==0)
    {
      ans+=1;
      //temp=A[i];
    }
    else
    { //cout << active[i-1]<<" ";
       temp=temp + A[i];
       temp=min(temp,active[i-1]*2);
      if(n>50)ans+=temp;
      else 
      { 
        int y=pow(2,i);
        ans+=min(y,temp);
        temp=min(y,temp);
      }
      //cout<<temp<<" "<<endl;
    }
    //temp=()
  }
  cout << ans << endl;
}

signed main()
{ boost
  int test=0,t;
    //cin >> t ;
    t=1;
   while(test++ <t){
	  //cout<<"Case #"<<test<<": ";
	   solve();}
  
}

Measured memory_bytes: 5236
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(min(a+b,a+c),b+c)<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int W = scanner.nextInt();
		int H = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int r = scanner.nextInt();
		if (x - r < 0 || x + r > W || y - r < 0 || y + r > H)
			System.out.println("No");
		else
			System.out.println("Yes");
		scanner.close();
	}
}

Measured memory_bytes: 17360
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;


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

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

	ll ans=INT_MAX;

	for(ll x=1;x<=100;++x)
    {
        ll cost=0;
        for(ll i=0;i<n;++i)
        {
            cost+=(x-ar[i])*(x-ar[i]);
        }
        ans=min(ans,cost);
    }
    cout<<ans<<endl;

	return(0);
}


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

int main() {
  vector<int> nums(3); 
  for (int i = 0; i< 3; i++) cin >> nums[i];
  
  int answer = *max_element(nums.begin(), nums.end()) - 
               *min_element(nums.begin(), nums.end());
    
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,k,x,y,sx,sy; //k-sx
    cin >> n >> k >> x >> y;
    sx = 0;
    sy = 0;
    if (n > k) {
        for (int i = 0; i < k; ++i) {
            sx = x + sx;
        }
    } else {
        for (int i = 0; i < n; ++i) {
            sx = x + sx;
        }
    }
    sy = sx;
    if (n > k) {
        for (int j = k; j < n; j++) {
            sy = y + sy;
        }
    }
    cout << sy << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int head, tail;
    char tmp;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'A')
        {
            head = i;
            break;
        }
    }
    for(int i = s.size() - 1; i > head - 1; i--) 
    {
        if(s[i] == 'Z')
        {
            tail = i;
            break;
        }
    }
    cout << tail - head + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n,z,w;
  cin>>n>>z>>w;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  reverse(all(a));

  if(n==1){
    cout << abs(w - a[0]) << endl;
    return 0;
  }

  vector<int> x(n), y(n);
  // a[i]以下が残っている状態でx,yの番になったときの結果
  rep(i,n){
    if(i+1==n){
      x[i] = abs(a[0] - w);
      y[i] = abs(a[0] - z);
    }
    else  x[i] = y[i] = abs(a[0] - a[i+1]);
    rep(j,i) x[i] = max(x[i], y[j]);
    rep(j,i) y[i] = min(y[i], x[j]);
  }
  
  cout << x[n-1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int tm1[10001][722];

int main()
{
    while(1){
        int n,m,r,q;
        cin >> n >> m;
        if(n == 0 && m == 0){
            break;
        }
        rep(i,m){
            memset(tm1[i],0,sizeof(tm1[i]));
        }
        cin >> r;
        rep(i,r){
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            c--;
            if(d){
                tm1[c][a-540]++;
            }else{
                tm1[c][a-540]--;
            }
        }
        rep(i,m){
            rep(j,720){
                tm1[i][j+1] += tm1[i][j];
            }
        }
        cin >> q;
        rep(i,q){
            int a,b,c;
            cin >> a >> b >> c;
            int res = 0;
            a -= 540, b -= 540;
            for(int j=a;j<b;j++){
                if(tm1[c-1][j]){
                    res++;
                }
            }
            cout << res << "\n";
        }
    }
}



Measured memory_bytes: 30388
#include<bits/stdc++.h>
using namespace std;
int dp[10001];
int main(){
  dp[1]=2;
  for(int i=2;i<10001;i++){
    dp[i] = dp[i-1] + i;
  }
  int n;
  while(cin>>n){
    cout<<dp[n]<<endl;
  }
}

Measured memory_bytes: 1200
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int n,x,a[100010];
int main(){
	cin>>n;
	int cnt=0;
	for(int i=0;i<100010;i++)a[i]=0;
	for(int i=0;i<n;i++){
		cin>>x;a[x]++;
	}
	for(int i=0;i<100010;i++){
		if(a[i]>1)cnt+=a[i]-1;
	}
	if(cnt%2==1)cnt++;
	cout<<n-cnt<<endl;
	return 0;	
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) << endl ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }


int main(){
	ll a,b ;
	cin >> a >> b ;
	cout << a*b << endl ;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 1000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    int AC = 0;
    int WA = 0;
    int TLE = 0;
    int RE = 0;
    for(int i = 0;i < N;i++) {
        string S;
        cin >> S;
        if(S == "AC") {
            AC++;
        }
        else if(S == "WA") {
            WA++;
        }
        else if(S == "TLE") {
            TLE++;
        }
        else {
            RE++;
        }
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
}

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

using namespace std;

int h, w, flg = true, cnt = 0;
string *lines;

bool resolve(int y, int x){
  if(!flg) return false;
  if(y >= h || x >= w || lines[y][x] == '.') return false;
  else if(y == h - 1 && x == w - 1) return true;
  if(!(resolve(y + 1, x) ^ resolve(y, x + 1))) flg = false;
  cnt++;
  return true;
}

int main(){
  cin >> h >> w;
  lines = new string[h];
  for(int i = 0; i < h; i++) cin >> lines[i];
  resolve(0, 0);
  for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) if(lines[i][j] == '#') cnt--;
  cout << (flg && !++cnt? "Possible" : "Impossible") << endl;
  delete[] lines;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
	using namespace std;
	#define int long long int
	#define pb push_back
	const int mod=1e9+7;
	#define all(x) x.begin(),x.end()
	#define endl '\n'
	#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
	
	int32_t main(){
		IOS;
		string s;
		cin>>s;
		if(s[s.size()-1]=='s'){
			cout<<s+"es"<<endl;
		}
		else{
			cout<<s+'s'<<endl;
		}
		return 0;
	}


Measured memory_bytes: 3664