akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a <= b)
            System.out.println(a);
        else
            System.out.println(a - 1);
    }
}

Measured memory_bytes: 21844
from math import factorial as f

n,p=map(int,input().split())
m=sum(map(lambda x:int(x)%2,input().split()))
o=n-m

a=2**o
b=0

if m:
  if p:
    for i in range(1,m+1,2):
      b+=f(m)//(f(m-i)*f(i))
  else:
    for i in range(0,m+1,2):
      b+=f(m)//(f(m-i)*f(i))
  print(a*b)
else:
  if p==0:
    print(a)
  else:
    print(0)


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


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {
    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main() {
    fast();
    string s;cin>>s;
    int g=0,p=0;
    int ans=0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i]=='g'){
            if(p+1>g)g++;
            else ans++,p++;
        }else {
            if(p+1>g)ans--,g++;
            else p++;
        }
    }
    cout<<max(ans,0);
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int a,b,c,d,k; cin >> a >>b >> c >> d >> k;
  int x = a*60 + b;
  int y = c*60 + d;
  int z = (1440 + y - x) % 1440;
  cout << z - k << "\n";
  return 0;
}


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

const int N=200010,mod=int(1e9+7);
struct edge
{
	int s,t,w,n;
} e[2*N];
int n,h[N],fac[N],ifac[N],vis[N],f[N],siz[N],ecnt,cnt,S,p,ans,res;

int ksm(int a,int b)
{
	int x=a;
	a=1;
	while(b)
	{
		if(b&1)  a=1ll*a*x%mod;
		x=1ll*x*x%mod,b>>=1;
	}
	return a;
}

int C(int n,int m)
{
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

void dfs(int x,int fa)
{
	vis[x]=1,cnt++;
	for(int i=h[x],y; y=e[i].t,i; ecnt++,i=e[i].n)
		if(!vis[y])
			f[y]=i,dfs(y,x);
		else if
		((y!=fa)&&(!S)) S=i;
}

void dfs2(int x,int fe)
{
	siz[x]=0,f[x]=1;
	for(int i=h[x],y; y=e[i].t,i; i=e[i].n)
		if((i!=fe)&&((i^p)>1))
		{
			dfs2(y,i^1);
			if(e[i].w>e[fe].w)
				res=1ll*res*ifac[siz[y]]%mod*f[y]%mod;
			else
				siz[x]+=siz[y],f[x]=1ll*f[x]*f[y]%mod*C(siz[x],siz[y])%mod;
		}
	siz[x]++;
}

int main()
{
	scanf("%d",&n),fac[0]=1;
	for(int i=1; i<=2*n; i++)
		fac[i]=1ll*fac[i-1]*i%mod;
	ifac[2*n]=ksm(fac[2*n],mod-2);
	for(int i=2*n; i; i--)
		ifac[i-1]=1ll*ifac[i]*i%mod;
	for(int i=1,x,y,tot=1; i<=2*n; i++)
	{
		scanf("%d %d",&x,&y),y+=n;
		e[++tot]=(edge)
		{
			x,y,x+y,h[x]
		};
		h[x]=tot;
		e[++tot]=(edge)
		{
			y,x,x+y,h[y]
		};
		h[y]=tot;
	}
	ans=fac[2*n];
	for(int i=1,s; i<=2*n; i++)
		if(!vis[i])
		{
			ecnt=cnt=S=s=0,dfs(i,0);
			if(cnt!=ecnt/2)
			{
				puts("0");
				return 0;
			}
			p=S;
			for(int j=S; e[j].s!=e[S].t; j=f[e[j].s])
				p=(e[p].w<e[j].w?j:p);
			res=1;
			dfs2(e[p].s,p);
			s+=1ll*ifac[siz[e[p].s]]*f[e[p].s]%mod*res%mod;
			res=1;
			dfs2(e[p].t,p);
			s+=1ll*ifac[siz[e[p].t]]*f[e[p].t]%mod*res%mod;
			ans=1ll*ans*s%mod;
		}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 14464
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll N, M, ans = 0;
    cin >> N >> M;
    vector<ll> high(N,0);
    vector<ll> A(M), B(M);
    vector<ll> hantei(N,1);
    rep(i, N) cin >> high[i];
    rep(j, M) cin >> A[j] >> B[j];
    rep(k, M) {
        if (high[A[k] - 1] > high[B[k] - 1]) hantei[B[k] - 1] = 0;
        else if (high[A[k] - 1] < high[B[k] - 1]) hantei[A[k] - 1] = 0;
        else if (high[A[k] - 1] == high[B[k] - 1]) {
            hantei[B[k] - 1] = 0;
            hantei[A[k] - 1] = 0;
        }
    }
    rep(x, N) if (hantei[x] == 1) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6376
A, B, C, D = list(map(int, input().split()))

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def get(x):
    return x - x // C - x // D + x // ((C*D)//gcd(C, D))

print(get(B)-get(A-1))



Measured memory_bytes: 2940
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static final int INF = 10_000_000;
    private static Scanner scan = new Scanner(System.in);
    private static int[][] edge;
    private static boolean[][] used;
    private static int[][] data;
    private static int N;
    private static int M;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	M = Integer.parseInt(scan.next());
	edge = new int[N][N];
	data = new int[N][N];
	used = new boolean[N][N];

	for (int i = 0; i < M; i++) {
	    int s = Integer.parseInt(scan.next()) - 1;
	    int d = Integer.parseInt(scan.next()) - 1;
	    int c = Integer.parseInt(scan.next());
	    edge[s][d] = edge[d][s] = c;
	}
	for (int i = 0; i < N; i++) {
	    for (int j = 0; j < N; j++) {
		data[i][j] = (i == j ? 0 : INF);
	    }
	}

	for (int node = 0; node < N; node++) {
	    dijkstra(node);
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
	    for (int j = 0; j < N; j++) {
		if(used[i][j]) count++;
	    }
	}

	System.out.println(M - count/2);
	scan.close();
    }

    private static void dijkstra(int node) {
	boolean[] fix = new boolean[N];	
	int rest = 0;
	for (int i = 0; i < N; i++) {
	    if(data[node][i] < INF) fix[i] = true;
	    else rest++;
	}

	List<List<Integer>> pre = new ArrayList<List<Integer>>(N);
	for (int i = 0; i < N; i++) {
	    pre.add(new ArrayList<Integer>());
	}

	for (int step = 0; step < rest; step++) {
	    int min = INF;
	    int index = 0;
	    for (int i = 0; i < N; i++) {
		if(!fix[i]) {
		    for (int j = 0; j < N; j++) {
			if(fix[j] && edge[j][i] > 0) {
			    int tmp = data[node][j] + edge[j][i];
			    if(tmp < data[node][i]) {
				pre.get(i).clear();
				pre.get(i).add(j);
				data[node][i] = tmp;
			    } else if(tmp == data[node][i]) {
				pre.get(i).add(j);
			    }
			}
		    }
		    if(data[node][i] < min) {
			min = data[node][i];
			index = i;
		    }
		}
	    }
	    fix[index] = true;
	    for(Integer p: pre.get(index)) {
		used[p][index] = used[index][p] = true;
	    }
	    data[index][node] = data[node][index];
	}
    }
}


Measured memory_bytes: 28804
from collections import deque

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])

ans,j = 0,M

for i in range(N+1):
    
    if a[i] > K:
        break
    
    while b[j] > K - a[i]:
    
        j -= 1
    
    ans = max(ans,i+j)

print(ans)


Measured memory_bytes: 49300
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  sort(p.begin(), p.end());
  int l = n/2, r=l-1;
  cout << p[l]-p[r] << endl;
  return 0;
}

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

long long mod = 998244353;

// 入力
long long X, Y;
string A;
string B;

// その他
long long fact[1 << 18], factinv[1 << 18], inv[1 << 18];
long long fact2[1 << 18];
long long dp[5009][10009];

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 32; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a * modpow(b, m - 2, m)) % m;
}

void init(int maxlim) {
	fact[0] = 1;
	for (int i = 1; i <= maxlim * 4; i++) fact[i] = (1LL * i * fact[i - 1]) % mod;
	for (int i = 0; i <= maxlim * 4; i++) factinv[i] = Div(1, fact[i], mod);
	for (int i = 1; i <= maxlim * 4; i++) inv[i] = Div(1, i, mod);
	for (int i = 0; i <= maxlim * 4; i++) fact2[i] = fact[i] * fact[i] % mod;

	dp[0][0] = 1;
	for (int i = 1; i <= maxlim * 2; i++) dp[1][i] = 1;
	for (int i = 2; i <= maxlim; i++) {
		for (int j = i; j <= maxlim * 2; j++) {
			dp[i][j] = 1LL * i * (dp[i][j - 1] + 1LL * (i + j - 1LL) * dp[i - 1][j - 1]);
			dp[i][j] %= mod;
		}
	}
}

long long ncr(int n, int r) {
	if (n < r || r < 0) return 0;
	return (fact[n] * factinv[r] % mod) * factinv[n - r] % mod;
}

long long product(vector<long long> t) {
	long long s = 1;
	for (int i = 0; i < t.size(); i++) { s *= t[i]; s %= mod; }
	return s;
}

long long solve(int pos) {
	long long ret = 0;
	for (int i = pos; i <= X; i++) {
		long long v = ncr(Y, pos);
		long long r1 = (dp[pos][i] * fact[i] % mod) * fact[pos] % mod;
		long long r2 = (fact[X + Y] * factinv[Y - pos] % mod) * (factinv[X - i] * factinv[pos + i] % mod) % mod;
		long long r3 = (v * v % mod) * fact2[Y - pos] % mod;
		long long r4 = ncr(X, i) * fact2[X - i] % mod;
		ret += (r1 * r2 % mod) * (r3 * r4 % mod);
		ret %= mod;
	}
	return ret;
}

int main() {
	init(5000);
	cin >> A >> B;
	for (int i = 0; i < A.size(); i++) {
		if (A[i] == '1' && B[i] == '1') X += 1;
		if (A[i] == '1' && B[i] == '0') Y += 1;
	}

	long long Answer = 0;
	for (int i = 0; i <= min(X, Y); i++) Answer += solve(i);
	cout << Answer % mod << endl;
	return 0;
}

Measured memory_bytes: 316296
#include <cstdio>

const int MAX_N = 100;

int arr[MAX_N+1];
int swap_count;

void swap(int i, int j) {
    int t = arr[i];
    arr[i] = arr[j];
    arr[j] = t;
    swap_count++;
}

int main(int argc, char const *argv[])
{
    int N;
    scanf("%d", &N);

    for (int i = 0; i < N; ++i)
        scanf("%d", &arr[i]);

    for (int i = 0; i < N; ++i)
        for (int j = N-1; j > i; --j)
            if (arr[j] < arr[j-1])
                swap(j, j-1);

    for (int i = 0; i < N; ++i) {
        if (i > 0) putchar(' ');
        printf("%d", arr[i]);
    }
    printf("\n%d\n", swap_count);
    return 0;
}

Measured memory_bytes: 1032
N = int(input())
A = list(map(int, input().split()))
total = 1000
kabu = 0

for i in range(N - 1):
    total += (kabu * A[i])
    kabu = 0
    if (A[i] < A[i + 1]):
        kabu += total // A[i]
        total -= kabu * A[i]

# 最後
i += 1
total += (kabu * A[i])
kabu = 0
print(total)

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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
ll a[SZ];
//ll b[SZ];



int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    for(i = 400, k = 8; i <= 1800; i += 200, k--) {
        fora(j, i, i+199) a[j] = k;
    }

    cin1(n);
    cot1(a[n]);

    return 0;
}



Measured memory_bytes: 3656
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count = 0
bi = 0
for j in range(M):
    if count + B[j] > K:
        break
    count += B[j]
    bi += 1
a=0
ai = 0
p = bi
for i in range(N):
    #ep('s1:',count,ai,bi)
    if a + A[i] > K:
        break;
    a += A[i]
    count += A[i]
    ai+=1
    #ep('s2:',count,ai,M)
    
    while count>K:
        count-=B[bi-1]
        bi-=1
    #ep('s3:',count,ai,M)
    if count <= K:
        p=max(p,ai+bi)
    #ep('s4',count,p,ai,M)
print(p)


Measured memory_bytes: 40592
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	ll sum = 0;
	rep(i, n){
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	cout << a[0] << ' ' << a[n - 1] << ' ' << sum << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, q;
    cin >> n >> q;
    
    string s;
    cin >> s;

    vector<char> t(q);
    vector<char> d(q);
    for (int i=0; i<q; i++) {
        cin >> t[i] >> d[i];
    }

    int ll=-1, lr=n-1;
    int rl=0, rr=n;
    while(ll < lr) {
        int m=(lr+ll+1)/2;
        int md=m;
        bool v=false;
        for(int i=0; i<q; i++){
            if (t[i]!=s[md]) continue;

            if (d[i]=='L') md--;
            if (d[i]=='R') md++;
            if (md<=-1 || md>=n) {
                v=(md<=-1);
                break;
            }
        }
        if (v){
            ll=m;
        }
        else {
            lr=m-1;
        }
        // cout << ll << " " << lr << " " << m << endl;
    }

    while(rl < rr) {
        int m=(rr+rl)/2;
        int md=m;
        bool v=false;
        for(int i=0; i<q; i++){
            if (t[i]!=s[md]) continue;

            if (d[i]=='L') md--;
            if (d[i]=='R') md++;
            if (md==-1 || md>=n) {
                v=(md>=n);
                break;
            }
        }
        if (v){
            rr=m;
        }
        else {
            rl=m+1;
        }
        // cout << rl << " " << rr << " " << m << endl;
    }

    cout << rl - ll - 1<< endl;

    return 0;
}

Measured memory_bytes: 900
S = list(input())
n = len(S)
cur = 0
count = [0] * 2020
count[0] = 1
for i, c in enumerate(map(int, S[::-1])):
    cur = (cur + c * pow(10, i, 2019)) % 2019
    count[cur] += 1
    
print(sum(c * (c - 1) // 2 for c in count))

Measured memory_bytes: 11760
# Acceptance of input

import sys

file_input = sys.stdin

X, Y, E = map(int, file_input.readline().split())

v_num = X + Y + 2

adj_mat = [[0] * (v_num) for i in range(v_num)]

for line in file_input:
    x, y = map(int, line.split())
    adj_mat[x][X + y] = 1

s = X + Y
t = s + 1

for i in range(X):
    adj_mat[s][i] = 1

for i in range(X, s):
    adj_mat[i][t] = 1

# Dinic's algorithm

import collections

# BFS for residual capacity network to construct level graph
def bfs(start, goal, parent):
    level = [v_num] * v_num
    unvisited = [True] * v_num
    queue = collections.deque()
    queue.append(start)
    level[start] = 0
    unvisited[start] = False
    while queue:
        u = queue.popleft()
        next_level = level[u] + 1
        for v, r_capacity in enumerate(adj_mat[u]):
            if (level[v] >= next_level) and (r_capacity > 0):
                level[v] = next_level
                parent[v].append(u)
                if unvisited[v]:
                    queue.append(v)
                    unvisited[v] = False
    return level[goal]

# DFS for level graph and construct blocking flow
def dfs(goal, path, parent, blocking_flow):
    v = path[-1]
    if v == goal:
        aug_path_flow = 10000
        for x, y in zip(path[1:], path[:-1]):
            aug_path_flow = min(aug_path_flow, adj_mat[x][y])
        for x, y in zip(path[1:], path[:-1]):
            adj_mat[x][y] -= aug_path_flow
            adj_mat[y][x] += aug_path_flow
        blocking_flow[0] += aug_path_flow
    else:
        for u in parent[v]:
            path.append(u)
            dfs(goal, path, parent, blocking_flow)
            path.pop()

def dinic(source, sink):
    max_flow = 0
    parent = [[] for i in range(v_num)]
    while bfs(source, sink, parent) != v_num:
        blocking_flow = [0]
        path = [sink]
        # search in reverse direction from sink
        dfs(source, path, parent, blocking_flow)
        max_flow += blocking_flow[0]
        parent = [[] for i in range(v_num)]
    return max_flow

# output
print(dinic(s, t))

Measured memory_bytes: 8420
N,M,X = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(N)]

ans = 10**8
for i in range(2**N):
    cnt = 0
    temp = [0]*M
    for j in range(N):
        if i & (1<<j) == 0:
            continue
        for k in range(M):
            temp[k] += L[j][k+1]
        cnt += L[j][0]
    f = True
    for k in range(M):
        if temp[k] < X:
            f = False
            break
    if f:
        ans = min(ans, cnt)

if ans == 10**8:
    ans = -1
print(ans)

Measured memory_bytes: 9224
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>

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

using namespace std;
void B_147()
{
  string S;
  cin >> S;

  int S_size = (int)S.size();
  int count = 0;
  for (int i = 0; i < S_size / 2; ++i)
  {
    if (S[i] != S[S_size -1 - i]) ++count;
  }
  cout << count << endl;
}

int main()
{
  //C_140();
  //C_141();
  //C_142();
  //C_143();
  //C_144();
  //C_145();
  //C_146();
  //C_147();
  //C_148();
  //C_149();
  //A_149();
  //B_149();
  //A_148();
  //B_148();
  //A_147();
  B_147();
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef pair < int, int> P;
/****Union-Ford-Tree***/
int par[int(0x7ffffff)];//Parent
int Rank[int(0x7ffffff)];//Deep_of_the_Tree

//int a[100] = { 4,2,3,1,5 }, m[100] ={3,2,2};
//int n = 0;
//const ll mod = 1000000007;


//n要素で初期化
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		Rank[i] = 0;
	}
}
//木の根探し
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;

	if (Rank[x] < Rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

/************************************************************************************
//*無向グラフのBELL_MAN_FORD;*//*
struct edge { int from, to, cost; };
edge es[10000];
int d[10000];
void shortest_path(int s) {
	for (int i = 0; i < V; i++)d[i] = INF;
	d[s] = 0;
	while (true) {
		bool update = false;
		for (int i = 0; i < E*2; i++) {
			edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update)break;
	}

}
int main() {
	cin >> V >> E;
	for (int i = 0; i < E*2; i = i+2) {
		edge e;
		cin >> e.from >> e.to >> e.cost;
		es[i] = e;
		swap(e.to, e.from);
		es[i + 1] = e;

	}
	shortest_path(0);
	cout << d[6] << endl;
}
*////////////////////////////////////////*
int gcd(int a, int b) {//最大公約数を求める
	if (b == 0) return a;
	return gcd(b, a%b);
}
/*****************************************************************************/
//int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1};
//vector<int> G[10000];


//struct edge { int to, cost; };
//vector<edge>G[100000];


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


/****
//priority_queue<int> //大きいものから順番に出てくる
//priority_queue<int,vector<int>,greater<int>>//小さいものから出てくる（順位キュー）
.top();
.pop();
.empty();
**/
//void solve();
//int V, E;
//void shortest_path(int);
typedef long double ld;
typedef unsigned long long ull;
const int MX = 3007;


int N, A[100000];
int main()
{
	cin >> N;
	ll sum = 0;
	int res = 0;
	for (int i=0; i < N; i++) cin >> A[i];
	int counter = 0;
	for (int i=0; i < N; i++) {
		if (A[i] < 0) {
			//res = max(res, A[i]);
			A[i] = abs(A[i]);
			counter++;
		}
		sum += A[i];
	}
	//cout << counter << endl;
	sort(A, A + N);
	res = A[0];
	//cout << A[0] << endl;
	if (counter % 2 == 0) {
		cout << sum << endl;
	}
	else {
		cout << sum - res*2 << endl;
	}

	
	
	
}

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

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

    cout << setprecision(12) << fixed;
    double n, k;
    cin >> n >> k;
    double ans = max(n - k + 1, 0.0);

    for (double i = 1.0; i < k * 2; i *= 2.0)
    {
        ans += (max(0.0, min(n + 1, ceil(k / i)) - ceil(k / i / 2))) / i / 2;
    }

    cout << ans / n << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int f(int x){
    int r = 2000 - x;
    return (r + 199)/200;
}

int32_t main(){
    fast_io;
    int x;
    cin>>x;
    cout<<f(x)<<endl;
    return 0;
}

Measured memory_bytes: 3644
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

d = {}
for y in range(H):
    for x in range(W):
        d[A[y][x]] = (y, x)

t = [[0] * (H * W // D + 1) for _ in range(D)]
for i in range(D):
    j = 0
    if i == 0:
        j = 1
    while i + (j + 1) * D <= H * W:
        y1, x1 = d[i + j * D]
        y2, x2 = d[i + (j + 1) * D]
        t[i][j + 1] = abs(y1 - y2) + abs(x1 - x2)
        j += 1
    for j in range(H * W // D):
        t[i][j + 1] += t[i][j]

Q = int(input())
result = []
for _ in range(Q):
    L, R = map(int, input().split())
    i = L % D
    result.append(t[i][(R - i) // D] - t[i][(L - i) // D])
#print('\n'.join(str(i) for i in result))
print(*result, sep='\n')


Measured memory_bytes: 34964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

ll solve(ll cnt, ll piv, std::vector<long long> now, long long N, long long M, long long Q, std::vector<long long> a,
         std::vector<long long> b, std::vector<long long> c, std::vector<long long> d) {
    if (cnt == 0 || piv == N) {
        std::vector<long long> e(N);
        rep(i, N) {
            if (i == 0)
                e[i] = now[i];
            else
                e[i] = e[i - 1] + now[i];
        }
        // rep(i, N) { cout << e[i] << " "; }
        // cout << endl;
        ll res = 0;
        rep(i, Q) {
            if (e[b[i]] - e[a[i]] == c[i]) res += d[i];
        }
        return res;
    } else {
        std::vector<long long> e(N);
        rep(i, N) { e[i] = now[i]; }
        ll res = 0;
        rep(i, cnt) {
            e[piv] = i;
            res = max(res, solve(cnt - i, piv + 1, e, N, M, Q, a, b, c, d));
        }
        return res;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> a(Q);
    std::vector<long long> b(Q);
    std::vector<long long> c(Q);
    std::vector<long long> d(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
        a[i]--;
        b[i]--;
        scanf("%lld", &c[i]);
        scanf("%lld", &d[i]);
    }
    std::vector<long long> now(N);
    cout << solve(M, 0, now, N, M, Q, std::move(a), std::move(b), std::move(c), std::move(d)) << endl;
    return 0;
}


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

int main(){
  int n;
  int minimum=1000000001;
  long sum=0;

  cin>>n;

  int tmp;
  int neg_cnt=0;
  for(int i=0;i<n;i++){
    cin>>tmp;
    if(tmp<0)neg_cnt++;

    sum+=abs(tmp);
    minimum=min(minimum,abs(tmp));
  }

  long ans=(neg_cnt%2)==0 ? sum : sum-(minimum*2);
  cout<< ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  if(s[1] != s[2])cout << "No" << endl;
  else if(s[1]==s[0] || s[2]==s[3])cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long  N,A,B;
long long value[51];
bool comp(long long a,long long b)
{
    return a>b?true:false;
}

long long dp[51][51];

void init()
{
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=1; i<=50; i++)
    {
        dp[i][0]=1;
        for(int j=1; j<=i; j++)
            dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin>>N>>A>>B;
    init();
    for(int i=0; i<N; i++)
    {
        cin>>value[i];
    }
    sort(value,value+N,comp);
    double sum=0.0;
    for(int i=0; i<=A-1; i++)
    {
        sum+=value[i];
    }
    long long  num=0,k=0;
    for(int i=0; i<N; i++)
    {
        if(value[i]==value[A-1])
        {
            num++;
            if(i<A)
                k++;
        }
    }
    long long ans=0;
    if(k==A)//前A个相同,可以增加个数
    {
        for(int i=A; i<=B; i++)
            ans+=dp[num][i];
    }
    else
        ans+=dp[num][k];

    cout.precision(15);
    cout <<setiosflags(ios::fixed)<<sum/A<<endl;
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  
  vector<string> S(N);
for (int i = 0; i < N; i++) {
  cin >> S.at(i);
}
  
  int sw1=0;
  int sw2=0;
  int sw3=0;
  int sw4=0;
  
  for(int i=0;i<N;i++){
    if(S.at(i)=="AC"){
      sw1++;
    }else if(S.at(i)=="WA"){
      sw2++;
    }else if(S.at(i)=="TLE"){
      sw3++;
    }else{
      sw4++;
    }
  }
  
  
  cout<<"AC x "+to_string(sw1)<<endl;
  cout<<"WA x "+to_string(sw2)<<endl;
  cout<<"TLE x "+to_string(sw3)<<endl;
  cout<<"RE x "+to_string(sw4)<<endl;
}



  

Measured memory_bytes: 6424
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

const (
	z  = 'Z'
	a  = 'A'
	ln = z - a + 1
)

func rot(n int, s string) string {
	rns := make([]rune, len(s))
	for i, r := range s {
		c := int(r) + n
		for c > z {
			c -= ln // number of all alphabet
		}
		rns[i] = rune(c)
	}
	return string(rns)
}

func main() {
	n, s := nextInt(), nextString()
	r := rot(n, s)
	fmt.Println(r)
}


Measured memory_bytes: 768
N = int(input())

if N == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr = factorization(N)

min_nums = [1]
num_lists = [1]
num_dic = {1: 1}

ans = 0

for Z in arr:
    o = Z[1]
    for i, num in enumerate(num_lists):
        if num > o:
            ans += num_dic[num_lists[i-1]]
            break
    if num <= o:
        o = o - num
        _ans = len(min_nums)
        n = min_nums[-1]+1
        while o >= n:
            o -= n
            min_nums.append(n)
            _ans += 1
            num_lists.append(n+num_lists[-1])
            num_dic[num_lists[-1]] =  _ans
            n += 1
        ans += _ans

print(ans)
        


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a <= b) {
    if (c <= d) cout << a+c << endl;
    else cout << a+d << endl;
  } else {
    if (c <= d) cout << b+c << endl;
    else cout << b+d << endl;
  }
}

Measured memory_bytes: 256
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
x=list(map(int,input().split()))

ans=float('inf')
for i in range(100):
    tmp=0
    for j in range(n):
        tmp+=(x[j]-i-1)**2
    ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 70656
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x, c, result,min,max;
		// ??????????¨????
		n = 0;
		x = 0;
		c = 1;// min????¬????????????????
		result = 0;// ??????????????°
		min = 1;//????°????
		max = 0;//?????§???

		while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		}
		System.out.print(new String(sb));
	}
}

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

using namespace std;

using ll = long long;
int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll r;
    if (n >= b) {
        r = b - 1;
    } else {
        r = n;
    }
    cout << (a * r) / b << "\n";

    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  int a[3],i=0,cnt=3;
  while(i<3){
    scanf("%d",&a[i]);
    if(a[i]==a[i-1]||a[i]==a[i-2]){
      cnt--;
    }
    i++;
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
r,s=map(int,input().split())
a = 1
d = 1
b = 0
c = 0
while s:
    q=r//s
    
    ss = s
    rr = r
    aa = a
    bb = b
    cc = c
    dd = d
    
    r = ss
    s = rr % ss
    a = cc
    c = aa - q * cc
    b = dd
    d = bb - q * dd
print(a,b)



Measured memory_bytes: 5592
class Number:
    value = ''
    plus = False
    
    def __init__(self, value, plus = False):
      self.value = value
      self.plus = plus

    def __str__(self) -> str:
        return '+' + str(self.value) if self.plus else str(self.value)


count = 0


def solve(numbers, k):
    global count
    if k >= len(numbers):
        x = ''.join([str(n) for n in numbers])
        count += sum(int(x) for x in x.split('+'))
        return

    b = []

    for i, n in enumerate(numbers):
        if i == k:
            b.append(Number(n.value, True))
        else:
            b.append(n)

    solve(numbers, k + 1)
    solve(b, k + 1)


s = input()

numbers = [Number(x) for x in s]

solve(numbers, 1)

print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
int s;
int ans[100005];
int mx=1000000000;

int main(void){
	scanf("%d%d%d",&n,&k,&s);
	if(k==0){
		if(s>=n+1){
			for(int i=0;i<n;i++){
				ans[i]=1;
			}
		}else{
			for(int i=0;i<n;i++){
				ans[i]=mx;
			}
		}
	}else{
		for(int i=0;i<k;i++){
			ans[i]=s;
		}
		if(s==mx){
			for(int i=k;i<n;i++){
				ans[i]=1;
			}
		}else{
			for(int i=k;i<n;i++){
				ans[i]=mx;
			}
		}
	}
	for(int i=0;i<n;i++){
		printf("%d%c",ans[i],i+1==n?'\n':' ');
	}
	return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int a, b, c, d; cin >> a >> b >> c >> d;
    if ((c + b - 1) / b <= (a + d - 1) / d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <math.h>

using namespace std;
 
int main() {
	string ans;
	string str;
	cin >> str;
	if(str=="Sunny")ans = "Cloudy";
	if(str=="Cloudy")ans ="Rainy";
	if(str=="Rainy")ans = "Sunny";
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr LL inv(LL x, LL m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr LL mpow(LL a, LL k, LL m) { LL r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }

int main() {
    int n;
    scanf("%d", &n);
    multiset<int> S;
    for (int x, i = 1; i <= n; i++) scanf("%d", &x), S.insert(x);
    int ans = 0;
    while (!S.empty()) {
        int x = *S.rbegin(), y = 1;
        S.erase(S.find(x));
        while (y <= x) y *= 2;
        if (S.find(y - x) != S.end()) S.erase(S.find(y - x)), ans++;
    }
    printf("%d\n", ans);
}


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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    vector<int> v;
    for(int i=0;i<n;++i){
        int x;
        cin >> x;
        v.push_back(x);
    }
    auto sorted = v;
    sort(sorted.begin(), sorted.end());
    int left = sorted[n/2-1], right = sorted[n/2];
    for(int i=0;i<n;++i){
        if(v[i] >= right)cout << left;
        else cout << right;
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3828
using System;
using System.Collections.Generic;
// using System.Globalization;
using System.IO;
// using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        FastScanner sc = new FastScanner(Console.OpenStandardInput());
        int N = sc.nextInt();
        string[] S = sc.stringArray(N);
        string[] judge = new string[] { "AC", "WA", "TLE", "RE" };
        string mul = " x ";
        int[] C = new int[judge.Length];
        Array.Fill(C, 0);
        for (int i = 0; i < N; i++) C[Array.IndexOf(judge, S[i])]++;
        for (int i = 0; i < judge.Length; i++)
            Console.WriteLine(judge[i] + mul + C[i]);
        return;
    }
}

// FastScanner start
public class FastScanner
{
    public readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public FastScanner(Stream stream)
    {
        str = stream;
    }
    private T[] enumerate<T>(int n, Func<T> f)
    {
        var a = new T[n];
        for (int i = 0; i < n; ++i) a[i] = f();
        return a;
    }
    public char nextChar()
    {
        byte b = 0;
        do
        {
            b = read();
        }
        while (33 < b && b < 126 && !isEof);
        return (char)b;
    }
    public string nextString()
    {
        byte b = 0;
        StringBuilder builder = new StringBuilder();
        b = read();
        while (33 < b && b < 126 && !isEof)
        {
            builder.Append((char)b);
            b = read();
        }
        return builder.ToString();
    }
    public int nextInt()
    {
        return (isEof) ? int.MinValue : (int)nextLong();
    }
    public long nextLong()
    {
        if (isEof)
        {
            return long.MinValue;
        }
        long ret = 0;
        byte b = 0;
        var ng = false;
        do
        {
            b = read();
        }
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-')
        {
            ng = true;
            b = read();
        }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
            {
                return ng ? -ret : ret;
            }
            else ret = ret * 10 + b - '0';
        }
    }
    public int[] intArray(int n)
    {
        return enumerate(n, nextInt);
    }
    public long[] longArray(int n)
    {
        return enumerate(n, nextLong);
    }
    public char[] charArray(int n)
    {
        return enumerate(n, nextChar);
    }
    public string[] stringArray(int n)
    {
        return enumerate(n, nextString);
    }
    private byte read()
    {
        if (isEof)
        {
            return 0;
        }
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
}
// FastScanner end

Measured memory_bytes: 39800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
int cnt[maxn];
int main()
{
	int n;
	cin >> n;
	for(int i = 2; i <= n; ++i)
	{
		int fa;
		cin >> fa;
		++cnt[fa];
	}
	for(int i = 1; i <= n; ++i)
		cout << cnt[i] << endl;
	 
	return 0;
}

Measured memory_bytes: 4376
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

a,b,c,k=map(int,input().split())
if k%2:
    print(b-a)
else:
    print(a-b)

Measured memory_bytes: 61640
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> vs(m);
    for (auto& v : vs)
    {
        cin >> v;
    }
    const vector<int> cost = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

    vector<int> dp(n + 1, -1);
    vector<int> recon(n + 1, 10);
    dp[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (auto v : vs)
        {
            auto a = cost[v];
            if (i - a >= 0 && (dp[i] < dp[i - a] + 1 || (dp[i] == dp[i - a] + 1 && recon[i] < v)))
            {
                dp[i] = dp[i - a] + 1;
                recon[i] = v;
            }
        }
    }
    vector<int> ret;
    while (n > 0)
    {
        ret.push_back(recon[n]);
        n -= cost[recon[n]];
    }
    for (auto v : ret)
    {
        cout << v;
    }
    cout << endl;
}

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

using namespace std;

bool check_prime(int n) {
	if (n % 2 == 0) {
		if (n != 2)return false;
	}

	int r = sqrt(n);
	for (int i = 2; i <= r; i++) {
		if (n%i == 0) {
			return false;
		}
	}

	return true;;
}

int main() {
	int n,counter = 0;
	cin >> n;
	while (n--) {
		int a;cin >> a;
		if (check_prime(a)) counter++;
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<math.h>

int main (void)
{
	int input1,input2;
	int i,j;
	do
	{
		scanf("%d %d",&input1,&input2);
		if(input1 == 0 && input2 == 0)
		{
			break;
		}
		for(i = 0 ; i < input1 ; i++)
		{
			for(j = 0 ; j < input2 ; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}while(1);
	return 0;
}


Measured memory_bytes: 2056
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long n = Long.parseLong(br.readLine());
        System.out.println(solve(n));
    }

    private static int solve(long n){
        if(n==1)
            return 0;
        if(isPrime(n))
            return 1;
        int[] factors = new int[1000001];
        long temp = n;
        for(int prime=2;prime<=1000000;prime++){
            while(temp%prime==0){
                factors[prime]++;
                temp/=prime;
            }
        }
        int count=0;
        for(int i=2;i<=1000000;i++){
            int fac = factors[i];
            for(int j=1;j<=fac;j++){
                fac-=j;
                count++;
            }
        }
        if(temp>1)
            count++;
        return count;
    }

    private static boolean isPrime(long n){
        for(long prime=2;prime*prime<=n;prime++){
            if(n%prime==0)
                return false;
        }

        return true;
    }


}

Measured memory_bytes: 29736
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define mod 1000000007
vector<pii> vec;
ll dp[3005]={};
ll afac[500005];
ll invfac[500005];
ll modexp(ll a,ll b)
{
	if(b==0)
		return 1;
	ll f=modexp(a,b/2);
	f=(f*f)%mod;
	if(b%2)
		return (a*f)%mod;
	else
		return f;
}
ll fac()
{
	ll i,f=1;
	for(i=1;i<=500000;i++)
	{
		f=(f*i)%mod;
		afac[i]=f;
	}
}
ll comp()
{
	invfac[500000]=modexp(afac[500000],mod-2);
	int i;
	for(i=499999;i>=0;i--)
		invfac[i]=((i+1)*invfac[i+1])%mod;
}
ll func(ll u,ll v,ll x,ll y)
{
	if((u-x)<0||(v-y)<0)
		return 0;
	ll num=afac[u-x+v-y];
	ll den=(invfac[u-x]*invfac[v-y])%mod;
	return (num*den)%mod;
}
int main()
{
	ll h,w,n,x,y,i,j,ans,u,v;
	fac();comp();
	cin>>h>>w>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x>>y;
		vec.push_back(make_pair(x,y));
	}
	sort(vec.begin(),vec.end());
	for(i=0;i<n;i++)
	{
		u=vec[i].first;
		v=vec[i].second;
		dp[i]=func(u,v,1,1);
		//cout<<dp[i]<<endl;
		for(j=0;j<i;j++)
			dp[i]=(dp[i]-(dp[j]*func(u,v,vec[j].first,vec[j].second))%mod+mod)%mod;
		//cout<<dp[i]<<endl;
	}
	ans=func(h,w,1,1);
	//cout<<ans<<endl;
	for(i=0;i<n;i++)
		ans=(ans-(dp[i]*func(h,w,vec[i].first,vec[i].second))%mod+mod)%mod;
	cout<<ans<<endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
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 () {
  int n = in();
  vi p(n);
  rep(i,n) cin >> p[i];
  vi q(n);
  rep(i,n) cin >> q[i];

  vi a(n);
  rep(i,n) a[i] = i+1;
  map<vi,int> mp;
  do {
    mp[a] = mp.size();
  } while (next_permutation(all(a)));

  int ans = abs(mp[p]-mp[q]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5248