akhauriyash/Code-Regression huggingface dataset:
from collections import deque
N,M,Q = map(int,input().split())
st = deque(range(N))
for a in map(int,input().split()):
    st.rotate(((-1)**((a&1)+1))*a)
    st.popleft()
st = set(st)
print("\n".join("1" if q in st else "0" for q in map(int,input().split())))



Measured memory_bytes: 28004
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    double R; cin >> R;
    cout << 2 * acos(-1) * R << endl;
    return 0;
}


Measured memory_bytes: 3824
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

def f(n):
    ans=0
    for i in range(n,n-n%4-1,-1):
        ans^=i
    return ans

A,B=mint()
print(f(A-1)^f(B))

Measured memory_bytes: 69724
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
int main(void){
    // Your code here!
 int n;
 cin >> n;
 int bi4 = 0,bi2 = 0,p = 0;
 for(int i = 0; i < n; i++){
     int a;
     cin >> a;
     if(a % 4 == 0){
         bi4++;
     }
     else if(a % 2 == 0){
         bi2++;
     }
     else{
         p++;
     }
 }  
 if(bi4 >= p){
     cout << "Yes" << endl;
 }
 else if(bi2 == 0 && bi4 +1 >= p){
     cout << "Yes" << endl;
 }
 else{
     cout << "No" << endl;
 } 
 
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < n;i++)
using namespace std;
 
int main(){
    vector<char> s(4);
    rep(i,4) cin >> s.at(i);
    string ans;
    rep(i,3){
        if(s.at(i) != s.at(i + 1)){
            ans = "Good";
        }else{
            ans = "Bad";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main(){
    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4? "Heisei" : "TBD") << endl;
    return 0;
}


Measured memory_bytes: 256
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

ans = [[0] * 3 for _ in range(3)]

for k in range(n):
  for i in range(3):
      for j in range(3):
        if a[i][j] == b[k] :
          ans[i][j] = 1

chk = False
if ans[0][0] == ans[0][1] == ans[0][2] == 1:
  print("Yes")
elif ans[1][0] == ans[1][1] == ans[1][2] == 1:
  print("Yes")
elif ans[2][0] == ans[2][1] == ans[2][2] == 1:
  print("Yes")
elif ans[0][0] == ans[1][0] == ans[2][0] == 1 :
  print("Yes")
elif ans[0][1] == ans[1][1] == ans[2][1] == 1 :
  print("Yes")
elif ans[0][2] == ans[1][2] == ans[2][2] == 1 :
  print("Yes")
elif ans[0][0] == ans[1][1] == ans[2][2] == 1 :
  print("Yes")
elif ans[0][2] == ans[1][1] == ans[2][0] == 1 :
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 9244
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
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...));
}
int main(){
    int n; ll x;
    cin>>n>>x;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    
    vector<vector<ll>> m(n+1,vector<ll>(n+1));
    rep(i,n) m[i][0]=a[i];
    
    rep(i,n){
        rep(j,n){
            m[i][j+1]=min(m[i][j],a[(i-j-1+n)%n]);
        }
    }
    
    ll ans=LINF;
    
    rep(k,n){
        ll now=(ll)k*x;
        
        rep(i,n) now+=m[i][k];
        
        ans=min(ans,now);
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 31616
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
# minimum spanning tree
res = 0
pos = []
for i in range(N):
    p = tuple(int(x) for x in input().split())
    p = (p[0], p[1], i)
    pos.append(p)
x_order = sorted(pos)
y_order = sorted(pos, key=lambda x: x[1])

uf = UnionFind(N)
x_i = y_i = 0
num_edge = 0

edge = []
for i in range(len(x_order) - 1):
    v1 = x_order[i+1]
    v2 = x_order[i]
    edge.append((v1[0] - v2[0], v1[2], v2[2]))
    v1 = y_order[i+1]
    v2 = y_order[i]
    edge.append((v1[1] - v2[1], v1[2], v2[2]))

edge.sort()
i = 0
while num_edge < N-1:
    e = edge[i]
    i += 1
    if uf.same_check(e[1], e[2]):
        continue
    else:
        res += e[0]
        uf.union(e[1], e[2])
        num_edge += 1

print(res)

Measured memory_bytes: 51292
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int a[3];

    int min = 101;
    int max = 0;

    for (int i = 0; i < 3; i++) {
        cin >> a[i];
        min = std::min(min, a[i]);
        max = std::max(max, a[i]);
    }

    cout << max - min << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

All = abs(A[0]) + abs(A[-1])
for i in range(len(A)-1):
    All += abs(A[i+1] - A[i])

print(All - ( abs(A[0]) + abs(A[1]-A[0])) + abs(A[1]))
for i in range(1, len(A)-1):
    print(All- (abs(A[i+1]-A[i]) + abs(A[i-1] - A[i])) + abs(A[i+1]-A[i-1]))

print(All - (abs(A[-1])+abs(A[-1]-A[-2])) + abs(A[-2]))


Measured memory_bytes: 14048
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n = II()
d = [0]+[1]*n
for i in range(2,n+1):
	for j in range(i,n+1,i):
		d[j]+=1
for i in range(1,n+1):
	d[i]*=i
	d[i]+=d[i-1]
print(d[n])


Measured memory_bytes: 224300
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define MP make_pair
#define PB push_back
using namespace std;

typedef long long ll;

int main()
{
    int n, m, a, b;
    vector<pair<int, int>> v;
    cin >> n >> m;
    FOR(i, 0, n)
    {
        cin >> a >> b;
        v.PB(MP(a, b));
    }
    sort(v.begin(), v.end());

    ll cnt = 0, res = 0, i = 0;
    while (cnt < m)
    {
        if (v[i].second > 0)
        {
            res += v[i].first;
            v[i].second--;
            cnt++;
        }
        else
        {
            i++;
        }
    }

    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    double a, b, C;
    cin >> a >> b >> C;
    double rdc = C * acos(-1) / 180;
    printf("%.8lf\n", a * b * sin(rdc) / 2);
    printf("%.8lf\n", a + b + sqrt(a * a + b * b - 2 * a * b * cos(rdc)));
    printf("%.8lf\n", b * sin(rdc));
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
pair<ll,ll> robot[maxn];
int n;
vector<int> g[maxn];
stack<int> stk;
bool vis[maxn];
ll dfs(int x)
{
	ll ans=1;
	vis[x]=1;
	for(int i=0;i<g[x].size();i++)
	{
		ans=ans*(dfs(g[x][i]))%mod;
	}
	return (ans+1)%mod;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&robot[i].first,&robot[i].second);
		robot[i].second+=robot[i].first;
	}
	sort(robot+1,robot+1+n);
	
	for(int i=n;i>=1;i--)
	{
		while(!stk.empty()&&(robot[stk.top()].first)<(robot[i].second))
		{
			g[i].push_back(stk.top());
			stk.pop();
		}
		stk.push(i);
	}
	ll ans=1;
	for(int i=1;i<=n;i++)
	{
		if(vis[i])continue;
		ans=(ans*dfs(i))%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

ll field[60][60];
bool f[60][60];
ll W, H;

void dfs(ll h, ll w)
{
	if (f[h][w]) return;
	f[h][w] = true;
	for (ll i = -1; i <= 1; ++i)
		for (ll j = -1; j <= 1; ++j)
		{
			ll nw = w + i;
			ll nh = h + j;
			if (nw < 0 || nw > W || nh < 0 || nh > H) continue;
			if (field[nh][nw])
				dfs(nh, nw);
		}
}

int main(int argc, char **argv)
{
	while (cin >> W >> H, true)
	{
		if (W == 0 && H == 0) break;
		memset(f, 0, sizeof f);
		memset(field, 0, sizeof field);

		vector<pair<ll, ll>> search;
		search.reserve(50*50);
		for (ll h = 0; h < H; ++h)
			for (ll w = 0; w < W; ++w)
			{
				cin >> field[h][w];
				if (field[h][w] == 1)
				{
					search.push_back(pair<ll, ll>(h, w));
					// std::cout << "(h, w) : " << h << ", " << w << std::endl;
				}
			}
		
		ll res{0};
		for (ll i = 0; i < (ll)search.size(); ++i)
		{
			if (!f[search[i].first][search[i].second])
			{
				// std::cout << "(h, w) : " << search[i].first << ", " << search[i].second << std::endl;
				dfs(search[i].first, search[i].second);
				++res;
			}
		}
		std::cout << res << std::endl;

	}
}


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

int main()
{
	int a, b, c;
	while (cin >> a >> b >> c, a | b | c) {
		int N;
		cin >> N;
		vector<int> res(a + b + c, 2);
		vector<vector<int>> no;
		for (int i = 0; i < N; i++) {
			int x, y, z, t;
			cin >> x >> y >> z >> t; x--, y--, z--;
			if (t) {
				res[x] = res[y] = res[z] = 1;
			}
			else {
				no.push_back(vector<int>({ x, y, z }));
			}
		}
		for (auto t : no) {
			int x = t[0], y = t[1], z = t[2];
			if (res[x] == 1 && res[y] == 1) {
				res[z] = 0;
			}
			else if (res[y] == 1 && res[z] == 1) {
				res[x] = 0;
			}
			else if (res[z] == 1 && res[x] == 1) {
				res[y] = 0;
			}
		}
		for (int i = 0; i < a + b + c; i++) {
			cout << res[i] << endl;
		}
	}
	return 0;
}



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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    int count = 0;
    for (int i = a; i <= b; i++) {
        if (!(c % i)) {
            count++;
        }
    }
    
    cout << count << endl;
}


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

int main(){
    while(true){
        int e;
        int f;
        int ans=1000000;
        cin >> e;
        if(!e) break;
        for(int i=0;i<=100;++i){
            f = e - i*i*i;
            if(f < 0) break;
            for(int j=0;j<=1000;++j){
                if(j*j > f){
                    ans = min(ans, f-(j-1)*(j-1)+j-1+i);
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
// AtCoder Beginner Contest 159 B.cpp

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int size = 0, half = 0;
	string n;
	bool flag = true;
	cin >> n;
	size = n.size() - 1;
	half = n.size() / 2;
	for (int i = 0; i < n.size() / 4; i++) {
		if (n[i] != n[half - 1 - i]) {
			flag = false;
			break;
		}
		if (n[half + 1 + i] != n[size - i]) {
			flag = false;
			break;
		}
	}
	for (int i = 0; flag == true && i < n.size() / 2; i++) {
		if (n[i] != n[size - i]) {
			flag = false;
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

int main()
{
    int n;
    char c;
    bool b[1001];
    string s = "";

    for( int i = 0; i < 1001; i++ )
        b[i] = 0;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> c;
        s += c;
    }
    
    for( int i = 0; i < s.size(); i++ )
    {
        for( int j = 1; j <= s.size() - i; j++ )
        {
            string t = s.substr( i, j );
            int sum = 0;
            for( int k = 0; k < t.size(); k++ )
            {
                sum *= 10;
                sum += ( t[k] - '0' );
                if( sum > 1000 )
                    break;
            }
            if( sum <= 1000 )
                b[sum] = true;
        }
    }

    for( int i = 0; i < 1001; i++ )
        if( !b[i] )
        {
            cout << i << endl;
            break;
        }

    return 0;
}


Measured memory_bytes: 3208
#include <iostream>

using namespace std;

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

    auto isPrime = [](int n) {
        if (n < 2) {
            return false;
        }
        else if (n == 2) {
            return true;
        }
        else if (n % 2 == 0) {
            return false;
        }
        for (int i = 3; (i * i) <= n; i += 2) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    };

    int count{0};
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (isPrime(x)) {
            count += 1;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3108
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;

int main() {
  int N; cin >> N;
  vector<int>A(N);
  vector<int>B(N);
  vector<int>C(N);

  ll ans = 0;

  for ( int i = 0; i < N; i++ ) cin >> A[i];
  for ( int i = 0; i < N; i++ ) cin >> B[i];
  for ( int i = 0; i < N; i++ ) cin >> C[i];

  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());

  for ( int i = 0; i < N; i++ ) {
    auto it1 = lower_bound(A.begin(),A.end(),B[i])-A.begin();
    //cout << it1 << endl;
    auto it2 = C.end() - upper_bound(C.begin(),C.end(),B[i]);
    //cout << it2 << endl;
    ans += it1 * it2;
  }

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


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define il inline
 
namespace io {
 
#define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n')
 
#define I_int ll
inline I_int read() {
    I_int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
char F[200];
inline void write(I_int x) {
    if (x == 0) return (void) (putchar('0'));
    I_int tmp = x > 0 ? x : -x;
    if (x < 0) putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int
 
}
using namespace io;
 
using namespace std;
 
#define N 200010
 
int n = read(), m = read();
struct edge {
	int to, nxt, v;
}e[N<<1];
int head[N], cnt, d[N], vis[N];
 
int flag = 0;
void dfs(int u) {
	vis[u] = 1;
	for(int i = head[u]; i; i = e[i].nxt) {
		if(vis[e[i].to]) {
			if(d[e[i].to] == d[u] + e[i].v) continue;
			else {
				flag = 1;
				return;
			}
		} else {
			d[e[i].to] = d[u] + e[i].v;
			dfs(e[i].to);
		}
	}
}

void ins(int u, int v, int w) {
	e[++cnt] = {v, head[u], w};
	head[u] = cnt;
}
 
int main() {
    for(int i = 1; i <= m; ++i) {
    	int l = read(), r = read(), t = read();
    	ins(l, r, t); ins(r, l, -t);
	}
	for(int i = 1; i <= n; ++i) dfs(i);
	if(flag) puts("No");
	else puts("Yes");
}

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

int main(){
    double r, ans;
    cin >> r;
    ans = r * 2.0 * 3.1415;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3772
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<set>
#include<string.h>
#include<queue>
#include<map>
#include<unordered_map>
#include<vector>
//~#include<algorithm>
#include<iomanip>
#include<limits>
#include<string.h>

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
 
#define pb push_back
#define ii pair<int, int>
#define vai freopen("in","r",stdin);
#define inf 0x3f3f3f3f
#define f first
#define s second

const ll INF = 1e18;
const double dinf = 12345678;
const int MOD = 1000000007;
const int maxn = 1000010;
int a, b;


//~ output :5 4 4 8

signed main (){
	
	//~ ios_base::sync_with_stdio(0); cin.tie(nullptr);  
	cin >> a >> b;
	
	
	cout << (a-1) + (b>=a) << '\n';
 
}


Measured memory_bytes: 256
<?php
 
fscanf(STDIN, '%d', $n);
for ($count = 0; $count < $n; $count++) {
    $a = explode(' ', trim(fgets(STDIN)));
    $b = 0;
    $c = 0;
    for ($i = 0; $i < 10; $i++) {
        if ($a[$i] > $b) {
            $b = $a[$i];
        } elseif ($a[$i] > $c) {
            $c = $a[$i];
        } else {
            break;
        }
    }
 
    echo $i === 10 ? 'YES' : 'NO';
    echo PHP_EOL;
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, k;
    vector<int> v;
    cin >> n >> k;
    bool f0 = false;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        if (!tmp)
            f0 = true;
        v.push_back(tmp);
    }

    int cost = INF;
    for (int i = 0; i < n - k + 1; i++)
    {
        int mncost;
        // if (v[i] == 0)
        // {
        //     mncost = abs(v[i + k - 2]);
        // }
        // else if (v[i + k - 1] == 0)
        // {
        //     mncost = abs(v[i + 1]);
        // }
        if (v[i] < 0 && v[i + k - 1] < 0)
        {
            mncost = abs(v[i]);
        }
        else if (v[i] >= 0)
        {
            mncost = abs(v[i + k - 1]);
        }
        else
        {
            mncost = min(abs(v[i]) * 2 + abs(v[i + k - 1]), abs(v[i]) + abs(v[i + k - 1] * 2));
        }
        cost = min(mncost, cost);
    }

    cout << cost << endl;
}

Measured memory_bytes: 1400
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55

using namespace std;
 


int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);

    int n,x;cin>>n>>x;
    int num[n];
    arrayin(num,n)

    int res=0;
    for(int i=0;i<n-1;i++){
    	if(num[i]+num[i+1]>x){
    		int temp=num[i]+num[i+1]-x;
    		num[i+1]=num[i+1]-temp;
    		if(num[i+1]<0){
    			num[i]=num[i]+num[i+1];
    			num[i+1]=0;
    		}
    		res+=(temp);
    	}
    }
    cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a; cin >> a;
  int arr[a + 50];
  for(int i=0; i<a; i++)
    cin >> arr[i];
  int ans = 1, mi = arr[0];
  for(int i=1; i<a; i++)
  {
    if(arr[i] <= mi) ans ++;
    mi = min(arr[i], mi);
  }
  cout << ans << '\n';
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;
char a[222222];
int l, c;

int main() {
	cin >> s;
	l = (int)s.length();
	rep(i,l) {
		if (s[i]=='T' && c>0 && a[c-1]=='S') c--;
		else a[c++] = s[i];
	}
	cout << c << ln;
}

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

// 素数判定
int isprime(int a) {
  int i;
  
  if (a == 2) return 1;
  if (a < 2 || (a % 2 == 0)) return 0;
  
  i = 3;
  while (i <= sqrt(a)) {
    if (a % i == 0) return 0;
    i = i + 2;
  }
  
  return 1;
}

int main () {
  int *a, i, n, cnt;
  
  // 動的配列の生成
  scanf("%d", &n);
  a = (int *)malloc(sizeof(int) * n);
  
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  cnt = n;
  
  for (i = 0; i < n; i++) {
    if (!isprime(a[i])) cnt--;
  }

  printf("%d\n", cnt);
  
  return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    string s = "",t = "";
    for(int i = 0; i < b; ++i){
        t += char(a + '0');
    }
    for(int i = 0; i < a; ++i){
        s += char(b + '0');
    }

    if(s > t) cout << t << endl;
    else cout << s << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

/*二項係数(mod付き)*/
struct Combination{
	const int num=51e4;			//num:=(要素数). 適宜変更する!
	const int mod=1e9+7;
	vector<llong> fact,inv,finv;//fact[i]:=(iの階乗),inv[i]:=(iの逆元),finv[i]:=(iの逆元の階乗).
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){//組み合わせ.
		if(n<k or (n<0 or k<0)) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	template<typename Type>
	Type big_nCk(Type n,int k){//nが大きい場合に使用.
		if(n<k or (n<0 or k<0)) return 0;
		llong res=1LL;
		REP(i,k) res=res*((n-i)%mod)%mod;
		res=res*finv[k]%mod;
		return Type(res);
	}
	int nPk(int n,int k){//順列.
		if(n<k) return 0;
		return fact[n]*finv[n-k]%mod;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

int main(){//Refering other editorials.
	int n,k;
	cin>>n>>k;
	
	vector<llong> a(n);
	REP(i,n) cin>>a[i];
	sort(ALL(a));
	
	llong ans=0LL;
	Combination ob;
	REP(i,n){
		if(i-0>=k-1) ans=(ans+a[i]*ob.nCk(i-0,k-1)%MOD)%MOD;
		if(n-1-i>=k-1) ans=(ans-a[i]*ob.nCk(n-1-i,k-1)%MOD+MOD)%MOD;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 15936
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N, M; cin >> N >> M;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    vector<vector<int>> vec(N);
    int A, B;
    rep(i, M) {
        cin >> A >> B;
        A--; B--;
        vec[A].push_back(B);
        vec[B].push_back(A);
    }
    bool flag;
    int cnt = 0;
    rep(i, N) {
        flag = true;
        rep(j, vec[i].size()) {
            if (H[i] <= H[vec[i][j]]) {
                flag = false;
                break;
            }
        }
        if (flag){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 8800
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    d = {str(i): 0 for i in list(map(int, input().rstrip('\n').split()))}

    for i in range(n, 10 ** 15):
        t = str(i)
        b = True
        for j in range(len(t)):
            if t[j] in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39408
#include<iostream>
#include<cmath>

using namespace std;

int main(){
	int n, i, j;

	// ループ
	cin >> n;
	while(n > 0){
		int cnt = 0;
		// n = 1 の場合を別に処理
		if(n == 1){
			cout << "1" << endl;
			cin >> n;
			continue;
		}
		// 素数検索ループ
		for(i = n + 1;i <= n * 2;i++){
			const int rooti = (int)sqrt((double)i);
			bool flag = true;
			// 偶数は省く
			if((i % 2) == 0){
				continue;
			}
			// 素数判定
			for(j=3;j<=rooti;j+=2){
				if((i % j) == 0){
					flag = false;
					break;
				}
			}
			if(flag == true){
				// 素数をカウント
				cnt++;
			}
		}
		// 結果の表示
		cout << cnt << endl;
		// n の入力
		cin >> n;
	}

	return 0;
}

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

int x[510];
int a[250010];

struct S {
	int pos, i, num;
	bool operator < (const S& s) const {
		return pos < s.pos;
	}
};

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

	int N;
	cin >> N;
	memset(a, -1, sizeof a);
	vector<S> l, r;
	for(int i = 0; i < N; i++) {
		cin >> x[i];
		x[i]--;
		a[x[i]] = i;
		r.push_back(S{ x[i], i, N - i - 1 });
		l.push_back(S{ x[i], i, i });
	}
	sort(r.rbegin(), r.rend());
	sort(l.begin(), l.end());
	int left = 0, right = N * N - 1;
	for(int i = 0; i < N; i++) {
		{
			S ls = l[i];
			int rem = ls.num;
			while(rem) {
				if(left == ls.pos) {
					cout << "No" << endl;
					return 0;
				}
				if(a[left] != -1) {
					left++;
					continue;
				}
				a[left] = ls.i;
				left++;
				rem--;
			}
		}
		{
			S rs = r[i];
			int rem = rs.num;
			while(rem) {
				if(right == rs.pos) {
					cout << "No" << endl;
					return 0;
				}
				if(a[right] != -1) {
					right--;
					continue;
				}
				a[right] = rs.i;
				right--;
				rem--;
			}
		}

	}

	cout << "Yes" << endl;
	for(int i = 0; i < N * N; i++) {
		cout << a[i] + 1;
		if(i == N * N - 1) cout << endl;
		else cout << " ";
	}
}

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = sc.nextInt();
        for (int i = 1; i < N; i++) {
            ans = gcd(ans, sc.nextInt());
        }

        System.out.println(ans);
        sc.close();

    }

    public static int gcd(int a, int b){
        if(a < b) return gcd(b, a);
        if(b == 0) return a;
        return gcd(b, a%b);
    }

}


Measured memory_bytes: 50764
fun main(array: Array<String>) {
    val (n, k, q) = readLine()!!.split(" ").map { it.toInt() }
    //最初のポイント
    val point = k - q
    //listで初期ポイント格納
    var pointList = Array(n){point}.toMutableList()
    repeat(q) {
        var idx = readLine()!!.toInt() - 1
        pointList[idx] += 1 
    }
    for(p in pointList) {
        if(p > 0) println("Yes")
        else println("No")
    }
}

Measured memory_bytes: 48576
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    vector<int> p;
    for(int i = 6; i < 300000; i+=5){
        for(int k = 0; k < 2; k++){
            if(k==1)
                i+=2;
            bool f=false;
            for(int j = 0; j < p.size(); j++){
                if(i%p[j]==0){
                    f=true;
                    break;
                }
            }
            if(!f){
                p.push_back(i);
            }
        }
    }
    while(cin>>n&&n!=1){
        vector<int> v;
        for(int i = 0; i < p.size(); i++){
            if(n%p[i]==0)
                v.push_back(p[i]);
        }
        cout<<n<<": ";
        for(int i = 0; i < v.size(); i++){
            cout<<v[i];
            if(i==v.size()-1)
                cout<<endl;
            else
                cout<<" ";
        }
    }

    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#define rep (i, n) for (int i = 1; i <= n; i++)

using namespace std;

int main() {
	int a, b, k;
	cin >> k >> a >> b;
	
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK\n";
			return 0;
		}
	}
	
	cout << "NG\n";
	
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define ll long long
#define fm_t  ll t;cin>>t;while(t--)
#define fr(i,a,b) for( ll i=a;i<b;i++)
#define fr1(i,n,a) for( ll i=n-1;i>=a;i--)
#define sz(x) (ll)(x).size()
#define all(v)  (v).begin(), (v).end()
#define Sort(x) sort(x.begin(),x.end())
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
const ll mod = 998244353;
#define Mod 1000000007

#define inf 1e18
#define ld long double
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll >
#define pi pair<ll, ll>
#define ppi pair<pair<ll, ll>, ll>
#define ump unordered_map<ll,ll>
#define pri priority_queue< pair<ll,ll> , vector< pair<ll,ll> >, greater< pair<ll,ll> > >
void ingraph(vl graph[], ll m){ll x, y;fr(i,0,m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)

//setprecision(10)
//greater<int>()
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}


ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll modinv(ll a){
    return modpower(a,mod-2);
}   
     
int main()
{
      
  fast;
  ll n;
  cin>>n;
  ll h[n+5];
  fr(i,0,n)
    cin>>h[i];
    fr(i,n,n+5)
    h[i]=0;
  ll dp[n+5];
  for(ll i=0;i<n+5;i++)
  {
    dp[i]=inf;
   // dp[i][1]=inf;
  }
  dp[0]=0;

  for(ll i=0;i<n;i++)
  {
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
  }
  cout<<dp[n-1]<<endl;


    
//cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
using ll=long long;

ll INF = 1e12;

ll dp[100005];
ll h[100005];
ll N, K;

int main()
{
    cin >> N >> K;
    for(int i = 0;i < N;i++)
    {
        cin >> h[i];
    }
    for(int i =0;i < N;i++)
    {
        dp[i] = INF;
    }
    dp[0] = 0;
    for(ll i = 1;i < N;i++)
    {
        for(ll j = 1;j <= min(i, K);j++)
        {
            dp[i] = min(dp[i], dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1

template<typename F>
struct FixPoint : F {
  FixPoint(F&& f) :F(forward<F>(f)) {}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f) {
  return FixPoint<F>{forward<F>(f)};
}

constexpr int MOD = 1e9 + 7; // 1e9 + 7

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  vector<vector<bool>> a(H, vector<bool>(W));
  F0R(i, H) {
    F0R(j, W) {
      char c;
      cin >> c;
      a[i][j] = c != '#';
    }
  }

  vector<vector<int>> dp(H, vector<int>(W, -1));
  dp[H - 1][W - 1] = 1;

  auto result = MFP([&](auto dfs, int r, int c)->int {

    if (dp[r][c] >= 0) return dp[r][c];

    //cout << r << "," << c << newl;
    int result = 0;
    if (c < W - 1 && a[r][c + 1]) {
      result += dfs(r, c + 1);
    }
    if (r < H - 1 && a[r + 1][c]) {
      result += dfs(r + 1, c);
    }

    if (result >= MOD) result -= MOD;

    return dp[r][c] = result;

  })(0, 0);

#if 0
  F0R(i, H) {
    F0R(j, W) {
      cout << "dp[" << i << "," << j << "]=" << dp[i][j] << newl;
    }
  }
#endif


  cout << result;
}
#endif


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

int digitsSum(int num){
    int sum = 0;
    while(num > 0){
        sum += num % 10;
        num /= 10;
    }

    return sum;
}

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

    int sumA = 0;
    int sumB = 0;
    int ans = 1000;

    for(int i = 1; i < n; i++){
        sumA = digitsSum(i);
        sumB = digitsSum(n - i);
        ans = min(ans, (sumA + sumB));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,ans;
int a[100010],b[100010];
int c[100010];
signed main(){
	cin>>n;
	for(int i=1;i<=n+1;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<=n+1;i++){
		int need=a[i]-c[i];
		if(need<0){
			c[i+1]=b[i];
			c[i]=a[i];
		}else{
			if(need>b[i]){
				c[i+1]=0;
				c[i]+=b[i];
			}else{
				c[i+1]=b[i]-need;
				c[i]=a[i];
			}
		}
	}
	for(int i=1;i<=n+1;i++)ans+=c[i];
	cout<<ans<<endl;
	return 0;
}


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

// @author: pashka

const long MOD = 1000000007;

long mult(long a, long b) {
    return a * b % MOD;
}

long power(long a, long b) {
    long res = 1;
    while (b > 0) {
        if (b & 1) res = mult(res, a);
        a = mult(a, a);
        b /= 2;
    }
    return res;
}

long inv(long a) {
    return power(a, MOD - 2);
}

long calc(long a, long n) {
    long p = 1;
    for (long i = 0; i < a; i++) {
        p = mult(p, n - i);
    }
    long q = 1;
    for (long i = 1; i <= a; i++) {
        q = mult(q, i);
    }
    return mult(p, inv(q));
}

int main() {
    ios::sync_with_stdio(false);

    long n, a, b;
    cin >> n >> a >> b;
    long res = power(2, n) - 1;
    res -= calc(a, n);
    res -= calc(b, n);
    res %= MOD;
    if (res < 0) res += MOD;
    cout << res;

    return 0;
}

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

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

bool kaibun(string s){
    string t=s;
    reverse(s.begin(),s.end());
    return t==s;
}

int main(void)
{
    ll n,a,b; cin>>n>>a>>b;
    ll ans=0;
    ll s=n/(a+b),r=n%(a+b);
    ans+=s*a;
    ans+=min(a,r);
    cout<<ans<<endl;
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int check(int val)
{
	int cnt = 0;

	while (val % 2 == 0)
	{
		cnt++;
		val /= 2;
	}

	return cnt;
}

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

	vector<int> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		ans += check(a[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int a, b, k;
  cin >> k >> a >> b;
  for(int i = a; i <= b; i++){
    if(i % k== 0){
      cout << "OK\n";
      return 0;
    }
  }
  cout << "NG\n";
  return 0;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String input;
        try {
            while((input = reader.readLine()) != null){
                String[] inputArray = input.split(" ");
                int a = Integer.parseInt(inputArray[0]);
                int b = Integer.parseInt(inputArray[1]);
                int c = Integer.parseInt(inputArray[2]);
                int d = Integer.parseInt(inputArray[3]);
                int e = Integer.parseInt(inputArray[4]);
                int f = Integer.parseInt(inputArray[5]);
                double x = ((double)(c*e-f*b))/(a*e-d*b);
                double y = ((double)(c*d-a*f))/(b*d-a*e);
                DecimalFormat df=new DecimalFormat();
                df.applyPattern("0");
                df.setMaximumFractionDigits(3);
                df.setMinimumFractionDigits(3);
                System.out.println(df.format(((double)Math.round(x*1000))/1000)+" "+df.format(((double)Math.round(y*1000))/1000));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_backa
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  ll n;cin>>n;
  string s;cin>>s;
  ans1(n%2==0&&s.substr(n/2)==s.substr(0,n/2));
  bool judge = true;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fine cout<<"fine"<<endl;
#define ll long long int
#define pb push_back
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
const ll inf=(ll)2e18;
const int mod=1e9+7;
bool overflow(ll a,ll b){
    if (a <= (inf+b-1)/b) return false;
    return true;
}
int main(){
FASTIO;
ll x,y,a,b,c,i;
cin>>x>>y>>a>>b>>c;
vector<ll> p,q,r;
ll sum=0;
for(i=0;i<a;i++){
    ll temp;
    cin>>temp;
    p.pb(temp);
}
for(i=0;i<b;i++){
    ll temp;
    cin>>temp;
    q.pb(temp);
}
for(i=0;i<c;i++){
    ll temp;
    cin>>temp;
    r.pb(temp);
}
sort(all(r),greater<ll>());
sort(all(p),greater<ll>());
sort(all(q),greater<ll>());
priority_queue<ll,vector<ll>,greater<ll> > pq;
for(i=0;i<x;i++){
    sum+=p[i];
    pq.push(p[i]);
}
for(i=0;i<y;i++){
    sum+=q[i];
    pq.push(q[i]);
}
for(i=0;i<c;i++){
    if(!pq.size())
        break;
    ll temp=pq.top();
    if(temp>=r[i])
        break;
    sum-=pq.top();
    sum+=r[i];
    pq.pop();
}
cout<<sum<<endl;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define CLEAR(a) memset(a,0,sizeof a)
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fr freopen("input.txt", "r", stdin);
#define fw freopen("output.txt", "w", stdout);
#define int long long 
typedef long long LL;
typedef pair<int,int> pii;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;
vector<int> g[MAX];

int dfs(int u){
  vector<int> t;
  for(int i=0;i<g[u].size();i++){
    int v = g[u][i];
    t.pb(dfs(v));
  }
  sort(t.begin(), t.end());
  int ret = 0;
  REP(i, t.size()){
    ret = max(ret, t[i]) + 1;
  }
  return ret;
}

 main() {
     int n;
    cin >> n;
    FOR(i,2,n){
      int p;
      cin >> p;
      g[p].pb(i);
    }
    cout << dfs(1);

    return 0;
}

Measured memory_bytes: 13568
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	vector<pair<int, int> >a[N];
	int b[N];
	int c[N];
	int n, k,m;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n,&m);
	f(i, m){
		scanf("%d %d", &x, &y);
		a[x - 1].push_back(make_pair(y,i));
	}
	f(i, n){
		sort(a[i].begin(), a[i].end());
		f(j, a[i].size()){
			b[a[i][j].second] = i+1;
			c[a[i][j].second] = j+1;
		}
	}
	f(i, m){
		printf("%06d%06d\n", b[i], c[i]);
	}


	return 0;
}

Measured memory_bytes: 10112
package main

import (
	"fmt"
)

func main() {
	// scanner := bufio.NewScanner(os.Stdin)
	// scanner.Scan()
	// text := scanner.Text()
	var s string
	fmt.Scan(&s)

	ed := len(s)
	isYes := true
	for ed > 0 {
		if ed-5 >= 0 && (s[ed-5:ed] == "dream" || s[ed-5:ed] == "erase") {
			ed = ed - 5
		} else if ed-6 >= 0 && s[ed-6:ed] == "eraser" {
			ed = ed - 6
		} else if ed-7 >= 0 && s[ed-7:ed] == "dreamer" {
			ed = ed - 7
		} else {
			isYes = false
			break
		}
	}

	if isYes {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1280