akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}


int main() {
	int a = 0, b = 0, c = 0;
	std::cin >> a >> b;
	std::cout << a - b + 1 << std::endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	vector<int> a(3);
	rep(i, 3) cin >> a[i];

	sort(all(a));

	int ret = 0;
	ret += a[2] - a[1];
	a[1] = a[2];
	a[0] += ret;
	
	if ((a[2] - a[0]) % 2) {
		ret += (a[2] - a[0] + 1) / 2 + 1;
	} else {
		ret += (a[2] - a[0]) / 2;
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<algorithm>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

int INF = 10e8;
int n, d;
stack<int> st[1000];
int csum[1000];
int csort[1000];

void init(){
    REP(i, n){
        csort[i] = csum[i];
    }
}

void sortcsort(){
    sort(csort, csort+n, greater<int>());
}

int main(){
    while(1){
        cin >> n >> d;

        if(n==0) break;

        REP(i, 1000) csum[i] = 0;
        REP(i, 1000) csort[i] = 0;
        REP(i, 1000) st[i] = stack<int>();

        REP(i, n){
            int m;
            cin >> m;
            REP(j, m){
                int c;
                cin >> c;
                csum[i] += c;
                st[i].push(c);
            }
        }

        init();
        sortcsort();

        while(1){
            int end = true;
            REP(i, n){
                while(!st[i].empty()){
                    int c = st[i].top();
                    int max_c = csort[0];
                    if(max_c == csum[i]){
                        max_c = max(csum[i]-c, csort[1]);
                    }
                    if(max_c - (csum[i]-c) <= d){
                        st[i].pop();
                        csum[i] -= c;
                        init();
                        sortcsort();
                        end = false;
                    } else {
                        break;
                    }
                }
            }

            int flag = true;
            REP(i, n){
                if(!st[i].empty()) flag = false;
            }
            if(flag){
                cout << "Yes" << endl;
                break;
            }
            if(end){
                cout << "No" << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3856
# coding: utf-8
import sys
from functools import lru_cache
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array(lr(), np.int64)
limit = int(max(A.max(), K)).bit_length()
bit_cnt = [((A>>k)&1).sum() for k in range(limit)]

@lru_cache(None)
def solve(K, index):
    if index < 0:
        return 0
    bit = 1 << index
    # bitを使わない（整数Xのこの桁のbitは0）
    ret = (bit_cnt[index]<<index) + solve(min(K, bit-1), index-1)
    if bit <= K:
        ret = max(ret, ((N-bit_cnt[index])<<index) +  solve(K-bit, index-1))
    return ret

answer = solve(K, limit-1)
print(answer)



Measured memory_bytes: 23608
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	vector<int>p(n), q(n);
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> p.at(i);
		q.at(i) = p.at(i);
	}
	int cnt = 0;
	sort(q.begin(), q.end());
	for (i = 0; i < n; i++)
	{
		if (p.at(i) != q.at(i))
			cnt++;
	}
	if (cnt == 0 || cnt == 2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    REP(i, N) cin >> H[i];
    vector<vector<int>> G(N);
    REP(i, M){
        int A, B;
        cin >> A >> B;
        --A, --B;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    int ans = 0;
    REP(i, N){
        bool is_good = true;
        for(auto e: G[i]){
            if(H[i] <= H[e]){
                is_good = false; 
                break;
            } 
        }
        if(is_good) ++ans;
    } 
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8752
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    int sum = 0;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            sum += d[i] * d[j];
        }
    }
    cout << sum;

    return 0;
}


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

const int MAX = 2000;
const long long MOD = 1e9 + 7;
long long dp[MAX];

int main() {
  int S;
  cin >> S;
  dp[0] = 1;

  for (int i = 1; i <= S; i++) {
    if (i < 3) {
      dp[i] = 0;
    } else {
      dp[i] = (dp[i-3] + dp[i-1]) % MOD;
    }
  }

  cout << dp[S] << endl;
  return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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 n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = LLINF;
    for (ll t = -100; t <= 100; t++) {
        ll sum = 0;
        rep(i, n) sum += (t - a[i]) * (t - a[i]);
        chmin(ans, sum);
    }
    cout << ans << endl;
}


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

const ll mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int k, i;
	cin >> k;
	for (i=0; i<k; ++i)
		cout << "ACL";
	cout << "\n";
	return 0;
}


Measured memory_bytes: 3564
from collections import deque
n=int(input())
con=[[] for _ in range(n)]
dist_f_k=[0]*n

for _ in range(n-1):
	a,b,c=map(int,input().split())
	con[a-1].append((b-1,c))
	con[b-1].append((a-1,c))

q,k=map(int,input().split())
que=deque([k-1])
while que:
	cur=que.popleft()
	for nxt,dd in con[cur]:
		if dist_f_k[nxt]==0 and nxt!=k-1:
			que.append(nxt)
			dist_f_k[nxt]=dist_f_k[cur]+dd

for _ in range(q):
	x,y=map(int,input().split())
	print(dist_f_k[x-1]+dist_f_k[y-1])

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,x,n) for(int i=(x);i<(n);i++)
#define INT_MAX 2147483647

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main(){
    
    int n,d,ans=0;
    cin >> n >> d;

    while(n > 0){
        ans++;
        n -= 2*d+1;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
n=int(input())
s=list(input())
s=s+s
x=[["S","S"],["S","W"],["W","S"],["W","W"]]

for temp1 in x:
    if s[0]=="o":
        c=temp1[1]
    else:
        if temp1[1]=="S":
            c="W"
        else:
            c="S"
    for i in range(1,n+1):
        if s[i]=="o":
            if temp1[i]=="S":
                temp1.append(temp1[i-1])
                
            else:
                if temp1[i-1]=="S":
                    temp1.append("W")
                else:
                    temp1.append("S")
        else:
            if temp1[i]=="W":
                temp1.append(temp1[i-1])
            else:
                if temp1[i-1]=="W":
                    temp1.append("S")
                else:
                    temp1.append("W")
    
    
    if temp1[0]==temp1[-2] and temp1[1]==temp1[-1]:
        print("".join(temp1[:n]))
        exit()
print(-1)

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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;

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

    string s;

    cin >> s;

    size_t n = s.size();
    
    // primeiro 1
    int n1 = 0;
    for(int i = 1; i <= n; i++) {
        if(i % 2 == 1 && s[i-1] != '1')
            n1++;
        else if(i % 2 == 0 && s[i-1] != '0')
            n1++;
    }

    // primeiro 0
    int n2 = 0;    
    for(int i = 1; i <= n; i++) {
        if(i % 2 == 1 && s[i-1] != '0')
            n2++;
        else if(i % 2 == 0 && s[i-1] != '1')
            n2++;
    }

    if(n == 1)
        cout << 0 << endl;
    else 
        cout << min(n1, n2) << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long a,b,c;
  cin >> a >> b >> c;
  long x,y,answer;
  x = a/(b+c);
  x = x*b;
  y = a%(b+c);
  if(y>b)
    y = b;
  answer = x+y;
  
  if(b ==0)
    answer = 0;
  cout << answer << endl;
}

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

int main() {
  long long H,N;
  cin >> H >> N;
  long long A = 0,tmp;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    A += tmp;
  }
  if(H <= A){
    cout << "Yes";
  } else {
    cout << "No";
  }  
}


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

long long check(string s) {
    int prv = -1;
    long long rt = 0;
    for (char c : s) if (c == prv) {
        ++rt;
        prv = -1;
    } else prv = c;
    return rt;
}

int main() {
    string s; int k; cin >> s >> k;
    if (k <= 100) {
        string t;
        for (int i = 0; i < k; ++i) t += s;
        cout << check(t) << endl;
    } else if (k % 2 == 0) {
        string t;
        for (int i = 0; i < 50; ++i) t += s;
        long long zz = check(t);
        long long zzz = check(t + s + s);
        cout << zz + (zzz - zz) * (k - 50) / 2 << endl;
    } else {
        string t;
        for (int i = 0; i < 51; ++i) t += s;
        long long zz = check(t);
        long long zzz = check(t + s + s);
        cout << zz + (zzz - zz) * (k - 51) / 2 << endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


/*
vvl comb(int n, int r) {
vvl v(n + 1,vl(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}
*/

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}


int main(){
	int n;
	ll a;
	cin>>n;
	multiset<int> se;
	rep(i,0,n){
		cin>>a;
		auto itr=se.lower_bound(a);
		if(itr!=se.begin())se.erase(prev(itr));
		se.insert(a);
	}
	print(se.size());

}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	string sAns;
	register int nCount = 0, i;
	getline(cin, sAns);
	for (i = 0; i < sAns.length(); ++i){
		if (sAns[i] == '1')
			++nCount;
	}
	cout << nCount << endl;
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
import math

n, x = map(int, input().split())
list_x = list(map(int, input().split()))
list_x.append(x)
list_x.sort()
delta_list = []
for i in range(len(list_x) - 1):
    delta_list.append(list_x[i+1] - list_x[i])
common = delta_list[0]
for num in delta_list:
    common = math.gcd(common, num)
print(common)

Measured memory_bytes: 20524
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;

    if ( s.substr(5,2) == "04" | s.substr(5, 2) == "03" | s.substr(5, 2) == "02" | s.substr(5,2) == "01" ) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
# 総和0を平均KとするためKを引く
A = [a-K for a in LIST()]

# dp[i][j] := i番目まで見て、和がjとなる通り数
dp = [defaultdict(int) for i in range(N+1)]
dp[0][0] = 1
for i, a in enumerate(A):
    for k, v in dp[i].items():
        dp[i+1][k] += v
        dp[i+1][k+a] += v
# 部分和が0になった通り数から、1つも選ばない分の1を引く
print(dp[N][0] - 1)


Measured memory_bytes: 5344
N=gets.to_i
a = 1
b = 0
answers = []
while a < N && b < N && b >= 0 do
  b = N - a
  ax = a.to_s.split""
  bx = b.to_s.split""
  sumA = 0
  sumB = 0
  ax.each do |k|
    sumA += k.to_i
  end
  bx.each do |k|
    sumB += k.to_i
  end
  answers << sumA + sumB
  a += 1
end
puts answers.min


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

int R, C;

bool a[10][10000];

int main(){
	while(cin >> R >> C && (R || C)){
		int res = 0;
		rep(i, R)rep(j, C){
			cin >> a[i][j];
		}

		rep(i, 1 << R){
			int cnt = 0;
			rep(j, C){
				int c = 0;
				rep(k, R){
					if(a[k][j] ^ !(i & (1 << k))) c++;
				}
				cnt += max(c, R - c);
			}
			res = max(cnt, res);
		}
		cout << res << endl;
	}
	return 0;
}

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

using ll = long long;

int main(){
    ll n;
    cin >> n;

    ll a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];

    ll cnt = 0;
    for(ll i = 0; i < n - 1; i++){
        while(a[i] > a[i + 1]){
            a[i + 1]++;
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

vector<ll> num(55),p(55);

ll rec(int level, ll x){
	if(level == 0)return 1;//LEVEL0バーガー
	if(x == 1)return 0;//下のバン
	else if(x < (num[level]+1)/2)return rec(level-1,x-1);//下のL-1バーガー
	else if(x == (num[level]+1)/2)return p[level-1]+1;//真ん中のパティ
	else if(x < num[level])return rec(level-1,x-(num[level]+1)/2)+p[level-1]+1;//上のL-1バーガー
	else return p[level];//上のバン
}

int main(void){
	ll n,x;
	cin>>n>>x;

	num[0]=1;
	p[0]=1;
	rep(i,n){
		num[i+1]=2*num[i]+3;
		p[i+1]=2*p[i]+1;
	}

	cout<<rec(n,x)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> K;
    cin >> S;

    if(S.size() <= K)cout << S;
    else
    {
        rep(i,K)
        {
            cout<< S[i];
        }
        cout << "...";
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, vis[N], sum[N], dep[N], fa[N], lab[N], cyc_u, cyc_v;
vector<int> G[N];
void dfs(int u, int lst, int depth) {
	fa[u] = lst;
	vis[u] = 1;
	dep[u] = depth;
	sum[u] = ((depth % 2 == 0) ? 1 : -1);
	for (int v : G[u]) if (v != lst) {
		if (!vis[v]) {
			dfs(v, u, depth + 1);
			sum[u] += sum[v];
		} else {
			cyc_u = u;
			cyc_v = v;
		}
	}
}
inline void solve_tree() {
	if (sum[1]) {
		puts("-1");
		return;
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) ans += abs(sum[i]);
	printf("%lld\n", ans);
}
inline void solve_odd() {
	if (sum[1] % 2) {
		puts("-1");
		return;
	}
	int delta = -sum[1] / 2;
	for (int u = cyc_u; u; u = fa[u]) sum[u] += delta;
	for (int u = cyc_v; u; u = fa[u]) sum[u] += delta;
	long long ans = abs(delta);
	for (int i = 1; i <= n; i++) ans += abs(sum[i]);
	printf("%lld\n", ans);
}
inline void solve_even() {
	if (sum[1]) {
		puts("-1");
		return;
	}
	vector<int> vec;
	vec.push_back(0);
	for (int u = cyc_v; u != cyc_u; u = fa[u]) {
		lab[u] = 1;
		vec.push_back(sum[u]);
	}
	sort(vec.begin(), vec.end());
	int mid = vec[vec.size() / 2];
	long long ans = 0;
	for (int i = 1; i <= n; i++) if (!lab[i]) ans += abs(sum[i]);
	for (int i = 0; i < (int)vec.size(); i++) ans += abs(vec[i] - mid);
	printf("%lld\n", ans);
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0, 0);
	if (m == n - 1) {
		solve_tree();
	} else if ((dep[cyc_v] - dep[cyc_u]) % 2 == 0) {
		solve_odd();
	} else {
		solve_even();
	}
	return 0;
}

Measured memory_bytes: 19088
n = int(input())
a = list(map(int, input().split()))
b = 0
ans = 0

for i in range(n):
    if a[i] < 0:
        b += 1
        a[i] = abs(a[i])
        
if (0 in a) or ((b % 2) == 0):
    pass
else:
    ans -= min(a) * 2

ans += sum(a)
print(ans)

Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
ll pow(ll x,ll y){
if(y==0){return 1;}
else if(y%2){return x*pow(x,y-1);}
ll temp=pow(x,y/2);
return temp*temp;
}
int main(){
 ll t=1;
 //cin>>t;
 while(t--){
ll n;
cin>>n;
ll a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n);
ll sum=a[0];
ll first=1;
for(int i=1;i<n;i++){
    sum+=a[i]*first;
    first*=2;
}
cout<<(double)sum/(double)pow(2,n-1)<<endl;
 }
}


Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )
#define rep2(n) for( int j = 0 ; j < n ; j++ )
#define REP2(n) for( int j = 1 ; j <= n ; j++ )
#define repll2(n) for( ll j = 0 ; j < n ; j++ )
#define REPll2(n) for( ll j = 1 ; j <= n ; j++ )

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  	int a , b;
  	cin >> a >> b;
  	cout << ( a - 1 ) * ( b - 1 );
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

	static long mod = 1000000007;
	static long INF = Long.MAX_VALUE;

	static long chmin(long a, long b) {
		return Math.min(a, b);
	}

	static long chmax(long a, long b) {
		return Math.max(a, b);
	}

	public static void main(String[] args) {
		// AtCoder_C
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
	    // Scannerクラスのインスタンスをクローズ
		sc.close();

		String ans = "";

		while (N>0) {
			N -= 1;
			ans = (char)('a'+(N%26)) + ans;
			N /= 26;
		}

		System.out.print(ans);
	}
}

Measured memory_bytes: 39220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

ll N, A, B;

bool solve(ll x, vector<ll> &v){
	// printf("x %lld\n", x);
	ll cnt = 0;
	ll C = A - B;
	for(auto u : v) {
		ll d = u - x * B;
		// printf("u %lld d %lld\n", u, d);
		if(d <= 0) continue;
		ll k = d / C + (d % C ? 1 : 0);
		// printf("%lld\n", k);
		cnt += k;
	}
	if(cnt <= x) return true;
	else return false;
}

int main(void) {
	cin >> N >> A >> B;
	vector<ll> h(N);
	rep(i, N){
		cin >> h[i];
	}

	ll l = 0, r = INF + 1;
	while(r - l > 1) {
		ll m = (l + r) / 2;
		if(solve(m, h)) r = m;
		else l = m;
	}
	for (ll i = max(0ll, l - 10); i <= r + 10; ++i) {
		if(solve(i, h)){
			printf("%lld\n", i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;
const int  Inv2 = (MOD+1)/2;

     signed main(){
  int n,k,c;
  cin>>n>>k>>c;
  string s;
  cin>>s;
int t=0;
int a[n],b[n];a[0]=0;b[n-1]=0;
for(int i=0;i<n-1;i++){
   if(t>0||s[i]=='x'){a[i+1]=a[i];t--;}
   else {a[i+1]=a[i]+1;t=c;}
}
t=0;
for(int i=n-1;i>0;i--){
   if(t>0||s[i]=='x'){b[i-1]=b[i];t--;}
   else {b[i-1]=b[i]+1;t=c;}
}
for(int i=0;i<n;i++)if(a[i]+b[i]<k)cout<<i+1<<endl;
      
      
      }

        


Measured memory_bytes: 4996
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/
int main(){
    ll N,A;
    cin >> N>>A;
    if(N % A==0)cout << N/A << endl;
    else cout << N /A+1<<endl;
}

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();
		sc.nextLine();
		String s = sc.nextLine();
		int[] alb = new int[26];
		boolean t = true;
		for(int i = 0 ; i<s.length(); i++) {
			
			alb[s.charAt(i)-'a']++;
		}
		for(int i = 0 ; i<26; i++) {
			if(alb[i]%2!=0) {
				
				t = false;
				break;
			}
		}
	//	System.out.println(Arrays.toString(alb));
		if(t)System.out.println("Yes");
		else System.out.println("No");
	}
}


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

int main(){
    string t;
    cin >> t;
    for(int i = 0; i < t.length(); i++){
        if(t[i] == '?'){
            t[i] = 'D';
        }
    }
    cout << t << endl;
    return 0;
}

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

int main(){
  long long n, d, x, a;
  cin >> n >> d >> x;
  for (int i = 0; i < n; i++) {
    cin >> a;
    x += (d + a - 1) / a;
  }
  cout << x << endl;
  return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    string S;
    cin >> S;
    for(int i=0;i<a;i++){
        if(!('0'<=S[i]&&S[i]<='9')){
            cout << "No" << endl;
            return 0;
        }
    }
    if(!(S[a]=='-')){
        cout << "No" << endl;
        return 0;
    }
    for(int i=a+1;i<a+b+1;i++){
        if(!('0'<=S[i]&&S[i]<='9')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define chmax(a,b) a=max(a,b);
#define chmin(a,b) a=min(a,b);
typedef long long ll;

using namespace std;
ll gcd(ll a,ll b){
  if(a<b)swap(a,b);
  if(b==0)return a;
  return gcd(a%b,b);
}
#define N 2010
ll b[N],a[N],n;
vector<ll> g[N];

class Aoki{
  public:
  ll nz[N];
  void buildg(){
    lol(i,n)g[i].clear();
    lol(i,n)lol(j,i){
      if(gcd(b[i],b[j])>1){
	g[j].push_back(i);
	nz[i]++;
      }
    }
  }
  void main(){
    lol(i,n)nz[i]=0;
    buildg();
    //cout<<"b=";lol(i,n)cout<<b[i]<<" ";cout<<endl;
    //lol(i,n)cout<<nz[i]<<" ";cout<<endl;
    priority_queue<pair<ll,ll> >Q;
    lol(i,n)if(nz[i]==0)Q.push(make_pair(b[i],i));
    vector<ll> res;
    unordered_set<ll> vis;
    while(!Q.empty()){
      ll val=Q.top().first;
      ll x=Q.top().second;
      Q.pop();
      if(vis.find(x)!=vis.end())continue;
      vis.insert(x);
      res.push_back(val);
      for(auto y:g[x]){
	nz[y]--;
	if(nz[y]==0)Q.push(make_pair(b[y],y));
      }
    }
    lol(i,n){
      if(i)cout<<" ";
      cout<<res[i];
    }cout<<endl;
  }
};Aoki kensho;

class Takahashi{
  public:
  void buildg(){
    lol(i,n)lol(j,n){
      if(i!=j&&gcd(a[i],a[j])>1){
	g[i].push_back(j);
      }
    }
  }
  unordered_set<ll> vis;
  vector<ll> res;
  void dfs(ll x){
      if(vis.find(x)!=vis.end())return;
      vis.insert(x);
      res.push_back(x);
      vector<ll> v;
      for(auto y:g[x]){
       v.push_back(y);
      }
      sort(v.begin(),v.end());
      for(auto y:v){
          dfs(y);
      }
  }
  void main(){
    buildg();
    //cout<<"buildend"<<endl;
    lol(i,n){
     dfs(i);
    }
    //cout<<"#"<<res.size()<<endl;
    //cout<<"a=";lol(i,n)cout<<res[i]<<" ";cout<<endl;
    lol(i,n)b[i]=a[res[i]];
  }
};Takahashi chokudai;

int main(){
    cin>>n;
    lol(i,n)cin>>a[i];
    sort(a,a+n);
    chokudai.main();
    //cout<<"chokudai-end"<<endl;
    kensho.main();
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<vector<int>>ab(n, vector<int>(2));
	for (int i = 0; i < n; i++)cin >> ab.at(i).at(0) >> ab.at(i).at(1);
	for (int i = 0; i < n; i++)ab.at(i).at(0) = ab.at(i).at(0) % ab.at(i).at(1);
	long long ans = 0;
	for (int i = n-1; i >= 0; i--) {
		if ((ab.at(i).at(0) + ans) % ab.at(i).at(1) == 0)continue;
		else ans += ab.at(i).at(1) - ((ab.at(i).at(0) + ans) % ab.at(i).at(1));
	}
	cout << ans << endl;
}

Measured memory_bytes: 5760
local n = io.read("*n", "*l")
local rowmap = {}
for i = 1, n do
  local tmps = io.read()
  rowmap[i] = {}
  tmps = tmps .. tmps
  for j = 1, n do
    rowmap[i][j] = tmps:sub(n + 2 - j, n + 2 - j + n - 1)
  end
end

local colmap = {}
for i = 1, n do
  local tmps = ""
  for j = 1, n do
    tmps = tmps .. rowmap[j][1]:sub(i, i)
  end
  colmap[i] = {}
  tmps = tmps .. tmps
  for j = 1, n do
    colmap[i][j] = tmps:sub(n + 2 - j, n + 2 - j + n - 1)
  end
end

local function check(r, c)
  for k = 1, n do
    local row_tgt = k + n - r
    if n < row_tgt then row_tgt = row_tgt - n end
    local row_ofst = 1 + c
    local col_tgt = k + n - c
    if n < col_tgt then col_tgt = col_tgt - n end
    local col_ofst = 1 + r
    if rowmap[row_tgt][row_ofst] ~= colmap[col_tgt][col_ofst] then return 0 end
  end
  return 1
end
local ret = 0
for i = 0, n - 1 do
  for j = 0, n - 1 do
    ret = ret + check(i, j)
  end
end
print(ret)


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

using namespace std;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        int dice[] = {1,3,6,4,2,5};
        int sum = 1;
        while(N--) {
            string cmd;
            cin >> cmd;
            if(cmd == "North") {
                int tmp = dice[0];
                dice[0] = dice[4];
                dice[4] = dice[2];
                dice[2] = dice[5];
                dice[5] = tmp;
            }
            else if(cmd == "East") {
                int tmp = dice[0];
                dice[0] = dice[3];
                dice[3] = dice[2];
                dice[2] = dice[1];
                dice[1] = tmp;
            }
            else if(cmd == "South") {
                int tmp = dice[0];
                dice[0] = dice[5];
                dice[5] = dice[2];
                dice[2] = dice[4];
                dice[4] = tmp;
            }
            else if(cmd == "West") {
                int tmp = dice[0];
                dice[0] = dice[1];
                dice[1] = dice[2];
                dice[2] = dice[3];
                dice[3] = tmp;
            }
            else if(cmd == "Right") {
                int tmp = dice[4];
                dice[4] = dice[1];
                dice[1] = dice[5];
                dice[5] = dice[3];
                dice[3] = tmp;
            }
            else if(cmd == "Left") {
                int tmp = dice[4];
                dice[4] = dice[3];
                dice[3] = dice[5];
                dice[5] = dice[1];
                dice[1] = tmp;
            }
            sum += dice[0];
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vector<vector<pair<ll, ll>>> G;
vl visited;
vl d(MAX_N);
bool ok = true;

void dfs(ll v, ll dist) {
    if(visited[v]) {
        if(d[v] != dist) {
            ok = false;
            return;
        }
        return;
    }
    visited[v] = 1;
    d[v] = dist;
    for(auto p : G[v]) {
        ll u = p.first;
        ll cost = p.second;
        dfs(u, d[v] + cost);
    }
    return;
}

int main() {
    ll n, m;
    cin >> n >> m;    

    G.resize(n);
    rep(i, m) {
        ll L, R, D;
        cin >> L >> R >> D;
        L--;  R--;
        G[L].pb(make_pair(R, D));
        G[R].pb(make_pair(L, -D));
    }

    visited.resize(n);
    rep(v, n) {
        if(!visited[v]) {
            dfs(v, 0);
        }
    }

    if(ok) {
        out("Yes");
    }
    else {
        out("No");
    }
    
    re0;
}

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

int main(){
    int k;
    cin>>k;
    queue<ll int> que;
    rep(i,9) que.push(i+1);
    ll int num;
    rep(i,k){
        num=que.front();
        int amari=num%10;
        que.pop();
        if(amari!=0) que.push(num*10+amari-1);
                      que.push(num*10+amari);
        if(amari!=9) que.push(num*10+amari+1);
    }
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <tuple>
#include <vector>

template <class... Ts> using tuple_t = std::tuple<Ts...>;
template <class T, class U> using map_t = std::map<T, U>;
template <class T, class U> using pair_t = std::pair<T, U>;
template <class T> using vector_t = std::vector<T>;
template <class T> using set_t = std::set<T>;

int min(const vector_t<int> &nums) {
	int min_ = std::numeric_limits<int>::max();
	for (auto &i : nums)
		if (min_ > i)
			min_ = i;
	return min_;
}

int max(const vector_t<int> &nums) {
	int max_ = std::numeric_limits<int>::min();
	for (auto &i : nums)
		if (max_ < i)
			max_ = i;
	return max_;
}
bool is_prime(int n){
	for(int i=2;i*i<=n;++i)
		if(n%i==0)
			return false;
	return true;
}

int f(int n){
	int s=0;
	for(int i=3;i*i*i*i*i*i*i<=n;i+=2)
	{
		if(!is_prime(i))
			continue;
		if(i % 2)
		{
			++s;
		}
	}
	return s;
}
int g(int n){
	int s=0;
	for(int i=3;i*i*i<=n;i+=2){
		if(!is_prime(i))
			continue;
		for(int j=3;i*i*i*j<=n;j+=2){
			if(!is_prime(j))
				continue;
			if(i!=j && i*i*i*j<=n)
			{
				++s;
			}
		}
	}
	return s;
}

int h(int n){
	int s=0;
	for(int i=3;i*i*i<=n;i+=2){
		if(!is_prime(i))
			continue;
		for(int j=i+2;i*j*j<=n;j+=2){
			if(!is_prime(j))
				continue;
			for(int k=j+2;i*j*k<=n;k+=2){
				if(!is_prime(k))
					continue;
				++s;
			}
		}
	}
	return s;
}

int main() {
	int N;
	std::cin>>N;
	std::cout<<f(N)+g(N)+h(N)<<std::endl;
	return 0;
}


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

const long long int DENOMI = 1000000007;
const int A = 0b00;
const int C = 0b01;
const int G = 0b10;
const int T = 0b11;
#define U(a, b, c, d) (a << 6 | b << 4 | c << 2 | d)

#include <string>

int main()
{
	int n;
	cin >> n;
	auto dp = vector<vector<long long int>>(n + 1, vector<long long int>(1 << 6));
	for(auto i = 0; i < 1 << 6; ++i){
		if(i == 0b001001 || i == 0b000110 || i == 0b100001) continue;
		dp[3][i] = 1;
	}
	auto f = vector<bool>(1 << 8, true);
	f[U(A, A, C, G)] = f[U(A, A, G, C)] = f[U(A, C, G, A)] = f[U(A, C, G, C)] =
		f[U(A, C, G, G)] = f[U(A, C, G, T)] = f[U(A, G, A, C)] = f[U(A, G, C, A)] =
		f[U(A, G, C, C)] = f[U(A, G, C, G)] = f[U(A, G, C, T)] = f[U(A, G, G, C)] =
		f[U(A, G, T, C)] = f[U(A, T, G, C)] = f[U(C, A, C, G)] = f[U(C, A, G, C)] =
		f[U(C, G, A, C)] = f[U(G, A, C, A)] = f[U(G, A, C, C)] = f[U(G, A, C, G)] =
		f[U(G, A, C, T)] = f[U(G, A, G, C)] = f[U(G, G, A, C)] = f[U(T, A, C, G)] =
		f[U(T, A, G, C)] = f[U(T, G, A, C)] = false;
	long long int ans = 0;
	for(auto i = 4; i <= n; ++i){
		for(auto j = 0; j < 1 << 6; ++j){
			for(auto k = A; k <= T; ++k){
				int s = j << 2 | k;
				if(f[s]) dp[i][s % (1 << 6)] = (dp[i][s % (1 << 6)] + dp[i - 1][j]) % DENOMI;
			}
		}
	}
	for(auto i = 0; i < 1 << 6; ++i){
		ans = (ans + dp[n][i]) % DENOMI;
	}
	if(n < 3) cout << 0 << endl;
	else if(n == 3) cout << 61 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main() {
    int K;
    cin >> K;
    queue<int64_t> q;
    for (int i = 1; i <= 9; i++) q.push(i);
    for (int i = 0; i < K - 1; i++) {
        auto t = q.front();
        q.pop();
        auto a = t % 10;
        if (a > 0) q.push(t * 10 + a - 1);
        q.push(t * 10 + a);
        if (a < 9) q.push(t * 10 + a + 1);
    }
    cout << q.front() << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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 () {
  double a, b, x;
  cin >> a >> b >> x;

  double ans;
  //debug(atan(2*x/(a*a*a))*180/M_PI);
  if (x >= a*a*b/2.0) {
    double s = 2.0*b/a - 2.0*x/(a*a*a);
    ans = atan(s)*180.0/M_PI;
  }
  else {
    double s = (a*b*b)/(2.0*x);
    ans = atan(s)*180.0/M_PI;
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 200
typedef pair<int,int> P;
vector<P> G[MAX];
int ans=0,n,m;
set<set<int> > ss;
void dfs(set<int> v){
  int res=0;
  if(ss.find(v)!=ss.end()) return;
  ss.insert(v);
  //cout<<v.size()<<":";
  for(auto i:v){
    //cout<<i<<" ";
    int tmp=-1;
    for(int j=0;j<(int)G[i].size();j++){
      if(v.find(G[i][j].first)!=v.end()){
	if(tmp<0) tmp=G[i][j].second;
	else tmp=min(tmp,G[i][j].second);
      }
    }
    if(tmp<0){
      res=0;
      break;
    }
    res+=tmp;
  }
  //cout<<":"<<res<<endl;
  ans=max(ans,res);
  set<int> u(v);
  for(int i=0;i<n;i++){
    if(v.find(i)!=v.end()) continue;
    bool f=1;
    for(auto j:v){
      bool ff=0;
      for(int k=0;k<(int)G[j].size();k++) ff|=(i==G[j][k].first);
      f&=ff;
    }
    if(f){
      u.insert(i);
      dfs(u);
      u.erase(i);
    }
  }
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int u,v,f;
    cin>>u>>v>>f;
    u--;v--;
    G[u].push_back(P(v,f));
    G[v].push_back(P(u,f));
  }
  set<int> v;
  dfs(v);
  cout<<ans<<endl;
  return 0;
}

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

int main(){
    int n;
    int taro_point = 0;
    int hanako_point = 0;
    string taro_card, hanako_card;

    cin >> n;

    for ( int i = 0; i < n; i++ ){
        cin >> taro_card; cin >> hanako_card;
        if (taro_card > hanako_card){
            taro_point += 3;
        } else if (taro_card < hanako_card){
            hanako_point += 3;
        } else {
            taro_point++;
            hanako_point++;
        }
    }
    cout << taro_point << " " << hanako_point << endl;
    return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int x,n;
    cin >> x >> n;
    set<int> data;
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    rep(i,0,n){
        int a;
        cin >> a;
        data.insert(a);
    }
    
    rep(i,0,n+10){
        if(!data.count(x-i)){
            cout<<x-i<<endl;
            break;
        }else if(!data.count(x+i)){
            cout<<x+i<<endl;
            break;
        }
    }
    
  return 0;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var QHSD = ReadSplitLong();
            var N = ReadLong();
            var Q = QHSD[0];
            var H = QHSD[1];
            var S = QHSD[2];
            var D = QHSD[3];

            var oneMin = Min(Min(Q * 4, H * 2), S);
            var twoMin = Min(oneMin * 2, D);
            Println((N / 2 * twoMin) + (N % 2 * oneMin));
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 11348
def A(x):
  if ord(x) - ord('a') >= 0:
    print('a')
  else:
    print('A')


def B(n, k, p_list):
  p_list = sorted(p_list)
  print(sum(p_list[:k]))


def C(N):
  for i in range(99):
    if N < 26**i:
      ans = []
      for j in range(i):
        ans += chr(ord('a') + N % 26)
        N //= 26
      return ''.join(ans[::-1])
    else:
      N -= 26**i


def main():
  # letter = input()
  # A(letter)
  # for x in ['A', 'Z', 'a', 'z']:
  #   A(x)

  # n, k = map(int, input().split())
  # p_list = map(int, input().split())
  # B(n, k, p_list)
  print(C(int(input())))
  #for i in range(1, 27):
  #  print(C(26 + i))
  # C(703)
  # C(18279)
  # C(475254)


if __name__ == '__main__':
  main()


Measured memory_bytes: 9140
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int res=0;
	for(int i=1;i<=n;i++){
		int a,k;
		scanf("%d%d",&a,&k);
		while(a%k)a=a-(a/k+1)*((a-a/k*k-1)/(a/k+1)+1);
		res^=a/k;
	}
	if(res)puts("Takahashi");
	else puts("Aoki");
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  char a[101]={};
  int i,n=0,x=0;
  
  scanf("%s",a);
  while (a[n]!='\0'){
    n++;
  }
  for(i=0;i<n/2;i++){
    if(a[i]!=a[(n-1)-i]){
      x++;
    }
  }
  printf("%d\n",x);
  return 0;
}


Measured memory_bytes: 128
function main(input){
  const [x, y] = input.split(' ').map(Number);
  if(y < 2*x) {console.log('No'); return;}
  for(let m=0; m<=x; m++){
	const n = x-m;
    if((2*m + 4*n) === y){
      console.log('Yes');
      return;
    }
  }
  
  console.log('No');
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 29560
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn solve(n : i32, m : i32, a : Vec<i32>) -> i64 {
    let mut map = HashMap::<i32, i32>::new();
    map.reserve((n + 1) as usize);

    let mut ans : i64 = 0;
    let mut acc : i32 = 0;
    map.insert(acc, 1);
    for i in 0..n {
        acc = (acc + a[i as usize]) % m;

        let count = map.entry(acc).or_insert(0);
        ans += *count as i64;
        *count += 1;
    }
    ans
}

fn main() {
    let nm = read_vec::<i32>();
    let a = read_vec::<i32>();
    println!("{}", solve(nm[0], nm[1], a));
}


Measured memory_bytes: 8444