akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

string s, t;
lint Q, a, b, c, d;
vector<lint> ans;
lint sum_a[2][100001];
int main() {
	cin >> s >> t;
	cin >> Q;
	sum_a[0][0] = 0;
	sum_a[1][0] = 0;
	REP(i, SZ(s)) {
		lint pl = (s[i] == 'A' ? 1 : 0);
		sum_a[0][i + 1] = sum_a[0][i] + pl;
	}
	REP(i, SZ(t)) {
		lint pl = (t[i] == 'A' ? 1 : 0);
		sum_a[1][i + 1] = sum_a[1][i] + pl;
	}
	REP(i, Q) {
		cin >> a >> b >> c >> d;
		lint val1 = (sum_a[0][b] - sum_a[0][a - 1]) * 2;
		lint val2 = val1 - (b - (a - 1));
		lint val3 = (sum_a[1][d] - sum_a[1][c - 1]) * 2;
		lint val4 = val3 - (d - (c - 1));
		if (abs(val2 - val4) % 3 == 0) ans.push_back(1);
		else ans.push_back(0);
	}
	REP(i, Q) {
		cout << (ans[i] == 1 ? "YES" : "NO") << endl;
	}
}


Measured memory_bytes: 6092
#include<iostream>
using namespace std;
int main(){
  bool num[1000001] = {false};
  for(int i=2; i<1000; i++) if(!num[i]) for(int j=i*i; j<1000001; j+=i) num[j] = true;
  int n;
  while(cin >>n,n){
    int ans = 0;
    for(int i=2; n>0; i++) if(!num[i]){ans+=i;n--;}
    cout <<ans<<endl;
  }
  return 0;
}

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

int n;
int t[100];
int m;
int p[100], x[100];

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> t[i];
	cin >> m;
	for (i = 0; i < m; i++) {
		cin >> p[i] >> x[i];
		p[i]--;
	}
	
	int sumT = 0;
	for (i = 0; i < n; i++) sumT += t[i];
	
	for (i = 0; i < m; i++) {
		cout << sumT + x[i] - t[p[i]] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int char_count(const char B[]){
  int len=0;
  while(B[len]){
    len++;
  }return len;
}
int main(void)
{
  int N,K;
  char A[200000];
  int num;
  int i=10;
  int k=1;
  int a;


  scanf("%d",&N);
  scanf("%d",&K);
  scanf("%s",A);

  int cnt = 0;
	while (1)
	{
		if (N <= K) {
			cnt++;
			break;
		}
		else {
			N -= (K-1);
			cnt++;
		}
	}
	printf("%d\n", cnt);
  return 0;
}


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

void dfs(int node, vector<vector<int>>& edge, vector<int> &val, priority_queue<int, vector<int>, greater<int>>& c){
    if (val[node] != -1 || c.empty())
        return;
    val[node] = 0; // 仮置き
    for(auto tar: edge[node]){
        if(val[tar] == -1)
            dfs(tar, edge, val, c);
    }
    val[node] = c.top();
    c.pop();
}

int main(){
    int n,a,b,x;
    cin >> n;
    vector<vector<int>> edge(n, vector<int>());
    vector<int> val(n, -1);
    priority_queue<int, vector<int>, greater<int>> c;
    for (int i = 0; i < n-1; i++){
        cin >> a >> b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    ll ans = 0;
    for (int i = 0; i < n; i++){
        cin >> x;
        c.push(x);
        ans += x;
    }
    dfs(0, edge, val, c);
    cout << ans - val[0] << endl;
    for (auto node: val){
        cout << node << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    char a, b;
    std::cin>>a>>b;

    std::string ans;
    if(a < b){
        ans = "<";
    }else if(a > b){
        ans = ">";
    }else{
        ans = "=";
    }

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

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <climits>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <fstream>
#include <functional>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <iomanip>
#define memtst(x) (sizeof(x) / 1024. / 1024.)
#define mem0(x) memset((x), 0, (sizeof x))
#define meminf(x) memset((x), INF, (sizeof x))
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define pf(x) push_front(x)
#define pq std::priority_queue
#define iter iterator
#define mp(x, y) std::make_pair((x), (y))
#define fst first
#define sec second
#define lc(x) ((x) * 2)
#define rc(x) ((x) * 2 + 1) 
#define md(x, y) (((x) + (y)) / 2)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair <int, int> pii;
const double PI = acos(-1);
const double EPS = 1e-6;
const ll MOD = 1e8 + 7;
const ll INF = 0x3F3F3F3F;
template <typename T>
inline T Abs(T x)
{
    return x < 0 ? x * -1 : x;
}
template <typename T>
inline T Max(T x, T y, T z)
{
    return std::max(std::max(x, y), z);
}
template <typename T>
inline T Min(T x, T y, T z)
{
    return std::min(std::min(x, y), z);
}
template <typename T>
inline T Ckmax(T &x, T y)
{
    return x = std::max(x, y);
}
template <typename T>
inline T Ckmin(T &x, T y)
{
    return x = std::min(x, y);
}
template <typename T>
inline T Sqr(T x)
{
    return x * x;
}
template <typename T>
T Pow(T x, T y, T z)
{
    T r = 1;
    while (y > 0)
    {
        if (y % 2 > 0)
            (r *= x) %= z;
        (x *= x) %= z;
        y /= 2;
    }
    return r % z;
}
template <typename T>
inline T gcd(T x, T y)
{
    return y > 0 ? gcd(y, x % y) : x;
}
template <typename T>
inline T lcm(T x, T y)
{
    return x / gcd(x, y) * y;
}
inline void cinspu(void)
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
}
inline ll read(void)
{
    char x;
    while (x = getchar(), x != '-' && !isdigit(x))
        ;
    char flg = x == '-';
    ll num = (flg ? getchar() : x) - '0';
    while (isdigit(x = getchar()))
        ((num *= 10) += x - '0') %= MOD;
    return flg ? -num : num;
}
const int N = 1e5 + 10;
ll ans = 0, tot = 0;
int n;
int main()
{
	cinspu();
	int a, b, c;
	std::cin >> a >> b >> c;
	for (int i = std::min(a, b); i; --i)
	{
		if (!(a % i) && !(b % i))
		{
			--c;
			if (!c)
			{
				std::cout << i << std::endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 888
a, b, c, k = map(int, input().split())

a_times = 0
b_times = 0
c_times = 0

if a <= k:
    a_times = a
    # print('a_times = ', a_times)
    if a_times + b <= k:
        b_times = b
        # print('if - b_times = ', b_times)
    else:
        b_times = k - a_times
        # print('else - b_times = ', b_times)
    if a_times + b_times + c <= k:
        c_times = c
        # print('if - c_times = ', c_times)
    else:
        c_times = k - a_times - b_times
        # print('else - c_times = ', c_times)
else:
    a_times = k


print(a_times * 1 + b_times * 0 + c_times * -1)


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> Array;
typedef vector<Array> Graph;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N, W;
    cin >> N >> W;
    int N_MAX = 110;
    int W_MAX = 10010;
    int v[N_MAX];
    int w[N_MAX];
    REP(i, N){
        cin >> v[i] >> w[i];
    }
    int DP[2][W_MAX];
    REP(i, N){
        REP(j, W+1){
            if(j<w[i]){
                DP[(i+1)&1][j] = DP[i&1][j];
            }else{
                DP[(i+1)&1][j] = max(DP[i&1][j], DP[i&1][j-w[i]] + v[i]);
            }
        }
    }
    cout << DP[N&1][W] << endl;
    return 0;
}

Measured memory_bytes: 3148
import sys
sys.setrecursionlimit(100000000)
from  bisect import bisect_left
input = sys.stdin.readline
INF = 1 << 30

MAXN = 200005
G = [[] for _ in range(MAXN)]
dp = [INF] * MAXN
stack = []
ans = [None] * MAXN
def dfs(v,A,p = -1):
    idx = bisect_left(dp,A[v])
    stack.append((idx,dp[idx]))
    dp[idx] = A[v]
    ans[v] = bisect_left(dp,INF)
    for e in G[v]:
        if e == p:
            continue
        dfs(e,A,v)
    idx,p = stack.pop()
    dp[idx] = p

def main():
    N = int(input())
    A = list(map(int,input().split()))
    for _ in range(N - 1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    dfs(0,A)
    print('\n'.join(map(str,ans[:N])))
if __name__ == '__main__':
    main()
    

    
    


Measured memory_bytes: 284008
import java.util.Scanner;

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

    while (sc.hasNext()) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
      int e = sc.nextInt();
      int f = sc.nextInt();

      calcLinearEquation(a, b, c, d, e, f);
    }
  }

  static void calcLinearEquation(int a, int b, int c, int d, int e, int f) {
    double x = (b*f - c*e) / (double)(b*d - a*e);
    double y = (a*f - d*c) / (double)(a*e - b*d);

    System.out.printf("%.3f %.3f\n", x+0, y+0);
  }
}

Measured memory_bytes: 18184
d = int(input())
c = list(map(int,input().split()))
data = [0]*(26)
ans = 0
for i in range(1,d+1):
    s = list(map(int,input().split()))
    L = []
    for j in range(26):
        sub = s[j]
        for k in range(26):
            if j == k:
                continue
            sub -= c[k]*(i-data[k])
        L.append(sub)
    out = L.index(max(L))
    print(out+1)
    data[out] = i

Measured memory_bytes: 9140
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b = map(int, readline().split())

x = a / 0.08
y = b / 0.1
left = math.floor(min(x, y))
right = math.ceil(max(x, y))
for i in range(left , right + 1):
    if int(i * 0.08) == a and int(i * 0.1) == b:
        print(i)
        exit()
print('-1')

Measured memory_bytes: 3064
a, x = map(int, input().split())
m = [int(input()) for i in range(a)]
ans = len(m)
nokori = x - sum(m)
m.sort()
a = []
for i in range(100000000000):
    if nokori >= m[0]:
        nokori = nokori - m[0]
        ans += 1
        a.append([nokori, ans])
    else:
        break

print(ans)

Measured memory_bytes: 19572
# frozen_string_literal: true

N = gets.chomp.to_i
ans_array = {}
ans_array["AC"] = 0
ans_array["WA"] = 0
ans_array["TLE"] = 0
ans_array["RE"] = 0

N.times do
  ans = gets.chomp
  ans_array[ans] += 1
end
# array = gets.chomp.split.map(&:to_i)

puts "AC x #{ans_array["AC"]}"
puts "WA x #{ans_array["WA"]}"
puts "TLE x #{ans_array["TLE"]}"
puts "RE x #{ans_array["RE"]}"


Measured memory_bytes: 14400
#include<stdio.h>

int main(){
	
	int S,h,m,s;

	scanf("%d\n",&S);

	h = S/3600;
	m = (S-h*3600)/60;
	s = S-h*3600-m*60;

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int indeg[101000],n,m,dist[101000];
vector<int> e[101000];
int a,b;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a>>b;
		indeg[b]++;
		e[a].push_back(b);
	}
	queue<int> q;
	for(int i=1;i<=n;i++)
	   if(indeg[i]==0)
	      q.push(i);
	int res=0;
	while(q.size()){
		int x=q.front();
		q.pop();
		res=max(res,dist[x]);
		for(int i=0;i<e[x].size();i++){
			indeg[e[x][i]]--;
			dist[e[x][i]]=max(dist[e[x][i]],dist[x]+1);
			if(indeg[e[x][i]]==0){
				q.push(e[x][i]);
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 6528
//97A
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int a,b,c,d=0;
   cin >> a >> b >> c >> d;
   if (abs(a-c)<=d or (abs(a-b)<=d and abs(c-b)<=d)){
       cout << "Yes";
   }else{
       cout << "No";
   }
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b) = listOfInt()

    var cnt = 0
    for (i in a..b) {
        val s = i.toString()
        if (s == s.reversed()) cnt++
    }

    println(cnt)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 39732
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 2 * N + 5;


int main(){
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    puts(a / n == b / n && (a % n) && (b % n) ? "NG" : "OK");
}

Measured memory_bytes: 3736
q=int(input())
A=[0 for i in range(10**5+23)]
P=[0 for i in range(10**5+23)]
from math import sqrt
def eratosu(n):
  if not isinstance(n,int):
    raise TypeError("nがint型になってねえぞ")
  if n<2:
    raise ValueError('nが2よりちっちぇえぞ')
  prime = []
  limit = sqrt(n)
  data = [i+1 for i in range(1, n)]  #2,3,4,...,n
  while True:
    p = data[0]
    if limit <= p:
        return prime + data
    prime.append(p)
    data = [e  for e in data if e % p != 0]

for i in eratosu(10**5+6):
    P[i]=1
for i in range(1,len(A)):
    if P[i]==1 and P[(i+1)//2]==1:
        A[i]=A[i-1]+1
    else:
      A[i]=A[i-1]

for i in range(q):
    a,b=map(int,input().split())
    print(A[b]-A[a-1])


Measured memory_bytes: 56284
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;
class Main {
	
	static int[][] map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if(x == 0 && y == 0) break;
			
			int tx = sc.nextInt()-1;
			int ty = sc.nextInt()-1;
			
			int kx = sc.nextInt()-1;
			int ky = sc.nextInt()-1;
			
			map = new int[y][x];
			for(int i = 0; i < y; i++) {
				for(int j = 0; j < x; j++) {
					map[i][j] = sc.nextInt();
				}
			}
			
			int ans = solv(x,y,tx,ty,kx,ky);
			
			if(ans == -1 || ans == 100) {
				System.out.println("NA");
			}
			else {
				System.out.println(ans);
			}
			System.gc();
		}
	}
	static Queue<Data> queue = new ArrayDeque<Data>();
	static HashMap<String,Boolean> h_map = new HashMap<String,Boolean>();
	static int[] vyt = new int[] {1,0,-1,0};
	static int[] vxt = new int[] {0,1,0,-1};
	static int[] vyk = new int[] {-1,0,1,0};
	static int[] vxk = new int[] {0,-1,0,1};
	
	
	static int solv(int x, int y, int tx, int ty, int kx, int ky) {
		queue.clear();
		h_map.clear();
		queue.add(new Data(0,x,y,tx,ty,kx,ky));
		
		while(!queue.isEmpty()) {
			Data data = queue.poll();
			if(data.tx == data.kx && data.ty == data.ky) return data.time;
			bfs(data);
		}
		return -1;
	}
	
	static void bfs(Data a) {
		for(int i = 0; i < 4; i++) {
			
			int movetx = a.tx + vxt[i];
			int movety = a.ty + vyt[i];
			int movekx = a.kx + vxk[i];
			int moveky = a.ky + vyk[i];
			Data next = new Data(a.time+1 ,a.x ,a.y ,movetx ,movety ,movekx ,moveky );
			if(movetx >= a.x || movety >= a.y || movetx < 0 || movety < 0 || map[movety][movetx] == 1) {
				next.tx = a.tx;
				next.ty = a.ty;
			}
			if(movekx >= a.x || moveky >= a.y || movekx < 0 || moveky < 0 || map[moveky][movekx] == 1) {
				next.kx = a.kx;
				next.ky = a.ky;
			}
			if(h_map.containsKey((next.tx+""+next.ty+""+next.kx+""+next.ky))) continue;
			if(next.time >= 100) return;
			h_map.put((next.tx+""+next.ty+""+next.kx+""+next.ky), true);
			
			queue.add(next);
			
		}
	}
	
	
	
	
	
	static class Data {
		int time;
		int x;
		int y;
		int tx;
		int ty;
		int kx;
		int ky;
		
		Data() {
			time = 0;
			x = 0;
			y = 0;
			tx = 0;
			ty = 0;
			kx = 0;
			ky = 0;
		}
		
		Data(int a, int b, int c, int d, int e, int f, int g) {
			time = a;
			x = b;
			y = c;
			tx = d;
			ty = e;
			kx = f;
			ky = g;
		}
		
		
	}
 	
}

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

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

int N, W;
int v[101], w[101];
int dp[101][1001*101];

int solve(int idx, int weight) {
    int& res = dp[idx][weight];
    if (~res) return res;
    if (idx >= N) res = 0;
    else if (weight+w[idx] > W) res = solve(idx+1, weight);
    else {
        res = max(solve(idx+1, weight), solve(idx+1, weight+w[idx])+v[idx]);
    }
    return res;
}

int main() {
    fill(dp[0], dp[101], -1);
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i];
    cout << solve(0, 0) << endl;
    return 0;
}



Measured memory_bytes: 42980
/*
  AOJ 2035
  Title:It Prefokery Pio
  @kankichi573
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define MAXLEN 2000

char a[MAXLEN+1],b[MAXLEN+1];
int lcs[MAXLEN+1][MAXLEN+1];
int lena,lenb;
char answer[MAXLEN+1];
int anslen;

void print_lcs(char a[],char b[],int lcs[][MAXLEN+1],int i,int j)
{
  if(i==0 || j==0)
    return;
  if(a[i-1]==b[j-1])
    {
      print_lcs(a,b,lcs,i-1,j-1);
      answer[anslen]=a[i-1];
      anslen++;
    }
  else if(lcs[i-1][j]>=lcs[i][j-1])
    print_lcs(a,b,lcs,i-1,j);
  else
    print_lcs(a,b,lcs,i,j-1);
}
void strreverse(char a[],char b[],int len)
{
  int i;
  b[lena]='\0';
  for(i=0;i<len;i++)
    b[i]=a[len-1-i];
}
main()
{
  int i,j;
  while(EOF!=scanf("%s",a))
    {
      memset(answer,0,sizeof(answer));
      lena=lenb=strlen(a);
      strreverse(a,b,lena);
      
      for(i=0;i<=lena;i++)
	lcs[i][0]=0;
      for(i=0;i<=lena;i++)
	lcs[0][i]=0;
      for(i=0;i<lena;i++)
	for(j=0;j<lenb;j++)
	  {
	    if(a[i]==b[j])
	      lcs[i+1][j+1]=lcs[i][j]+1;
	    else
	      lcs[i+1][j+1]=max(lcs[i][j+1],lcs[i+1][j]);
	  }
      anslen=0;
      print_lcs(a,b,lcs,lena,lenb);
      answer[anslen+1]='\0';
      printf("%s\n",answer);
    }
      return(0);
}

Measured memory_bytes: 16264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int a, b; cin >> a >> b;
  int ans = max(a+b, a-b);
  ans = max(ans, a * b);
  cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

int main(){
    ll N,K; cin>>N>>K;
  vector<ll> x(N);
  ll ans=0;
  rep(i,N) cin>>x[i];
  rep(i,N){
  	ans+=2*min(K-x[i],x[i]);
  }
  cout<<ans;
}

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

using namespace std;

bool solve(int N, string S) {

	if (N & 1) return false;
	// 4 / 2 => 0 1, 2 3 

	for (int i = 0; i < N / 2; ++i) {
		if (S[i] != S[N/2 + i]) {
			return false;
		}
	}

	return true;
}

int main () {

	ios_base::sync_with_stdio(false); cin.tie(NULL);	
		
	int N;
	string S;

	cin >> N >> S;

	cout << (solve(N, S) ? "Yes" : "No") << '\n';


	return 0;
}
 

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

#define int long long

using namespace std;

signed main()
{
    
    int n; cin >> n;
    
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        ans = ans * i;
        ans = ans % (int)(1e9 + 7);
    }
    
    //　出力
    cout << ans << endl;
}


// if (条件式)｛
     
//    }


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

int main(){
  long long X;
  cin >> X;
  
  int ans = 0;
  
  long long bank = 100;
  while(bank<X){
    bank = bank*1.01;
    ans++;
  }
  
  cout << ans <<endl;
  
  return 0;
}

Measured memory_bytes: 3624
a, b = map(int, input().split())

a_min = a / 0.08
a_max = (a + 1) / 0.08
b_min = b / 0.1
b_max = (b + 1) / 0.1

if max(a_min, b_min) < min(a_max, b_max):
    ans = max(a_min, b_min)
    ans = int(ans) if (ans - int(ans)) == 0 else int(ans) + 1
else:
    ans = -1

print(ans)

Measured memory_bytes: 3064
#if 1

#include<bits/stdc++.h>
using namespace std;

const int N=305;
int n,a,b,c,x;
double d[305][305][305];

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
    {
		scanf("%d",&x);
		if(x == 1) a++;
        if(x == 2) b++;
        if(x == 3) c++;
	}
	for(int k = 0;k <= n;k++)
    {
        for(int j = 0;j <= n;j++)
        {
            for(int i = 0;i <= n;i++)
            {
                if(0 < i+j+k && i+j+k <= n)
                {
                    if(i != 0) d[i][j][k] += d[i-1][j][k] * i;
                    if(j != 0) d[i][j][k] += d[i+1][j-1][k] * j;
                    if(k != 0) d[i][j][k] += d[i][j+1][k-1] * k;
                    d[i][j][k] = (n + d[i][j][k]) / (i + j + k);
                }
            }
        }
	}
	printf("%.10lf",d[a][b][c]);
	return 0;
}

#endif // 1++

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

int main() {
	int n;
	cin>>n;
	int a[n];
	map<int,int> mp1,mp2;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		mp1[x]=i;
		a[i]=x;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		mp2[a[i]]=i;
	}
	int c=0;
	for(auto it1=mp1.begin(),it2=mp2.begin();it1!=mp1.end() && it2!=mp2.end();it1++,it2++)
	{
		if(it1->second%2==1 && it2->second%2==0)
		{
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 9984
n,k,q=map(int,input().split())
a=[int(input())-1 for i in range(q)]
b=[0]*n


for i in range(q):
  b[a[i]]+=1

for i in range(n):
  if k-q+b[i]>0:
    print("Yes")
  else:
    print("No")



Measured memory_bytes: 8640
package main

import (
	"fmt"
)

func chmax(a *int, b int) {
	if *a < b {
		*a = b
	}
}

var dp [][]int

func main() {
	var N, W int
	fmt.Scan(&N, &W)
	w, v := make([]int, N), make([]int, N)
	for i := range w {
		fmt.Scan(&w[i], &v[i])
	}

	dp = make([][]int, N+1)
	for i := range dp {
		dp[i] = make([]int, W+1)
	}

	for i := 0; i < N; i++ {
		for sumW := 0; sumW <= W; sumW++ {
			if sumW-w[i] >= 0 {
				chmax(&dp[i+1][sumW], dp[i][sumW-w[i]]+v[i])
			}
			chmax(&dp[i+1][sumW], dp[i][sumW])
		}
	}

	fmt.Println(dp[N][W])
}


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N;
	cin>>N;
	map<string,ll> mp;
    string s;
    ll max_n = 0;
    rep(i,N){
        cin>>s;
        ++mp[s];
        max_n = max(max_n,mp[s]);
    }

    for(auto itr = mp.begin();itr != mp.end();++itr){
        if(itr->second==max_n){
            cout<<itr->first<<"\n";
        }
    }

	return 0;
}

Measured memory_bytes: 23936
n, y = [ int(v) for v in input().split() ]
y =  y // 1000


ans_list = []
for i in range(y//10+1):
    y2 = y - 10*i
    for j in range(y2//5+1):
        y3 = y2 - 5*j
        if i + j + y3 == n:
            ans_list.append((i,j,y3))

if ans_list != []:
    print(*ans_list[0])
else:
    print(-1,-1,-1)

Measured memory_bytes: 40300
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    ll sum = 0, ans = 1000000000000000000LL, partSum = 0;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
        sum += a[i];
    }
    REP(i, n){
        partSum += a[i];
        if(i<n-1) ans = min (ans, abs(sum-2*partSum));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	int A, B;
	cin >> A >> B;

	cout << (B % A ? B - A : B + A) << "\n";

	return 0;
}

Measured memory_bytes: 256
#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 all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s, t;
	cin >> n >> s >> t;
	for (int i = n; i >= 0; --i) {
		if (s.substr(n - i) == t.substr(0, i)) {
			printf("%d\n", 2 * n - i);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
#define int long long
using ll = long long;
const int MX = 1e6;
const ll inf = 1e13;
const int mod = 1e9+7;


map<ll, ll> prime_factors(ll n) {
    map<ll, ll> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(ll i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
signed main() {
    int a,b,c,x,y;
    cin >> a >> b >>c>>x>>y;
    int ans = a*x+b*y;
    if(x>y) {
        swap(x,y);
        swap(a,b);
    }
    ans = min(ans, c*x*2 + (y-x)*b);
    ans = min(ans, y*c*2);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long li;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// vector 型
template<class T>
std::ostream& operator<<(std::ostream& os, const vector<T>& v){
  // ここでストリームに obj を書き込みます。
  for(const T& t:v) cout << t << " ";
  return os;
}

int main(){
  int n; cin >>n;
  vector<li> a(n),b(n),c(n);
  rep(i,n) cin >>a[i];
  rep(i,n) cin >>b[i];
  rep(i,n) cin >>c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  vector<li> cntb(n,0),cntc(n,0);
  int i=0,j=0; li s=0;
  if(df) print("a:",a,"b:",b,"c:",c);
  while(i<n and j<n){
    if(a[i]<b[j]){
      s++;i++;
    }else{
      cntb[j++]=s;
    }
  }
  while(j<n)cntb[j++]=s;
  i=0;j=0;s=0;
  li ans=0;
  while(i<n and j<n){
    if(b[i]<c[j]){
      s+=cntb[i++];
    }else{
      ans+=(cntc[j++]=s);
    }
  }
  while(j<n)ans+=(cntc[j++]=s);
  if(df){
    print(cntb);
    print(cntc);
  }
  print(ans);
}


Measured memory_bytes: 4224
/*
 * A.cpp
 *
 *  Created on: 2020/08/16
 *      Author: 17k1028
 */



#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define REPD(i,n) for(ll i=n-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=a; i<=ll(b); i++)
#define FORD(i,a,b) for(ll i=a; i>=ll(b); i--)

int main(){
	char s[3];
	REP(i,3) cin >> s[i];
	int count = 0;
	REP(i,3){
		if(s[i] == 'R'){
			count++;
		}
	}
	if(count==2){
		if(s[1]=='R'){
			cout << "2" << endl;
		}else{
			cout << "1" << endl;
		}
	}else{
		cout << count << endl;
	}

	return 0;
}





Measured memory_bytes: 3636
s = Hash.new
nums = Array.new
while (line = gets) != "\n" do
  num,=line.split(",").map(&:to_i)
  s[num]||=0
  s[num]+=1
end
while line = gets do
  num,=line.split(",").map(&:to_i)
  next unless s[num]
  nums << num
  s[num]+=1
end
nums.sort!
nums.each{|n|
  puts n.to_s+" "+s[n].to_s
}

Measured memory_bytes: 2400
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#include <atcoder/all>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N, M;
	cin >> N >> M;
	dsu d(N);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		d.merge(a, b);
	}
	ll ans = d.groups().size() - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8948
import java.util.Collections

fun main(args: Array<String>) {
    val s = readInputLine().toCharArray()
    val t = readInputLine().toCharArray()
    
    val sSize = s.size.toLong()

    val indices = Array(26, {mutableListOf<Long>()})
    
    for ((i, sc) in s.withIndex()) {
        indices[sc - 'a'].add(i.toLong())
    }
    
    for (tc in t) {
        if (indices[tc - 'a'].isEmpty()) {
            println(-1)
            return
        }
    }
    
    var ans = 0L
    
    var lastFound = -1L
    
    for (tc in t) {
        val indicesIndex = upperBound(indices[tc - 'a'], lastFound)
        val nextIndex = if (indicesIndex >= indices[tc - 'a'].size) indices[tc - 'a'].first() else indices[tc - 'a'][indicesIndex]

        ans += if (nextIndex > lastFound) nextIndex - lastFound else sSize - lastFound + nextIndex

        lastFound = nextIndex
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}

fun <T: Comparable<T>> upperBound(list: List<T>, value: T): Int {
    return Collections.binarySearch(list, value, {x, y -> if (x > y) 1 else -1}).inv()
}


Measured memory_bytes: 42508
using System;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			long n = ReadLineLong();
			long sum = 0;
			for (long i = 1; i <= n; i++)
			{
				if (!(i % 3 == 0 || i % 5 == 0)) sum += i;
			}
			Console.WriteLine(sum);
		}

		public static int nCm(int n, int m)
		{
			if (n == 0) return 0;
			if (m == 0) return 1;
			return n * nCm(n - 1, m - 1) / m;
		}

		public static string ReadLine()
		{
			return Console.ReadLine();
		}

		public static int ReadLineInt()
		{
			return int.Parse(ReadLine());
		}

		public static long ReadLineLong()
		{
			return long.Parse(ReadLine());
		}

		public static string[] ReadLineStringSplit(char s = ' ')
		{
			return ReadLine().Split(s).ToArray();
		}

		public static int[] ReadLineIntSplit(char s = ' ')
		{
			return ReadLine().Split(s).Select(x => int.Parse(x)).ToArray();
		}

		public static long[] ReadLineLongSplit(char s = ' ')
		{
			return ReadLine().Split(s).Select(x => long.Parse(x)).ToArray();
		}
	}
}

Measured memory_bytes: 17644
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		int N = int.Parse(Console.ReadLine());
		int[] An = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int Q = int.Parse(Console.ReadLine());

		//現在の合計値
		long sum = 0;
		//バケツ（当該数値が何個あるかを数える）
		int[] bucket = new int[100001];
		//数えるとともに合計値を初期化
		for(int i=0; i<N; i++){
			bucket[An[i]] ++;
			sum += An[i];
		}

		//出力準備（AutoFlushを切る）
		var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(sw);

		//ループ処理
		for(int i=0; i<Q; i++){
			//読み込む
			string[] line = Console.ReadLine().Split(' ');
			int B = int.Parse(line[0]);
			int C = int.Parse(line[1]);

			//それぞれの現在の登場回数
			int times = bucket[B];

			//合計値の変動量を合計値に反映
			long diff = (C-B)*times;
			sum += diff;

			//登場回数を更新
			bucket[B] = 0;
			bucket[C] += times;

			//出力
			Console.WriteLine(sum);
		}

		//出力終了
		Console.Out.Flush();
	}
}



Measured memory_bytes: 30972
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,y;
	cin>>n;
	
	y=n/15;
	n*=800;
	y*=200;

	cout<<n-y<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
int a,b,c=0,d=0;
pair<int,int> ab[110000];
signed main()
{
	cin>>a>>b;
	rep(i,a){
		cin>>ab[i].first>>ab[i].second;
	}
	sort(ab,ab+a);
	int i=0;
	while(1){
		if(c+ab[i].second>=b){
			d+=(ab[i].first*(b-c));
			cout<<d;
			return 0;
		}else{
			d+=(ab[i].first*ab[i].second);
			c+=ab[i].second;
		}
		i++;
	}
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
int d[100010];

bool compare(const int &a, const int &b)
{
	return a < b;
}


int main()
{
	scanf("%d", &n);
	for (int i = 1 ; i <= n ; i++)
		scanf("%d", &(d[i]));
		
	sort(d + 1, d + n + 1, compare);
		
	int half = n / 2;	//even
	int p = 1;
	int count = 0;
	for (int i = 0 ; i <= d[n] ; i++)
	{
		while ((p <= n) && (d[p] < i))
			p++;
			
		if ((p - 1) == half)
		{
			count++;
		}
	}
	
	
	printf("%d\n", count);
	
	
	return 0;
}

//2
//1 3

Measured memory_bytes: 512
/*input
5 7 5
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,ans=0,sum=0,p,x,y,z;
	cin>>x>>y>>z;
	if(z!=x && z!=y) cout<<z;
	else if(y!=z && y!=x) cout<<y;
	else cout<<x;
}

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

using namespace std;

int n , a , ch , d;

int main()
{
	cin >> n;
	for(int i = 0 ;  i < n ; i++)
	{
		cin >> a;
		if(a % 4 == 0)
			ch++;
		else if(a % 2 == 0)
			d++;
	}
	if(ch >= n / 2)
		cout << "Yes";
	else
	{
		if(d >= n - (ch * 2))
			cout << "Yes";
		else
			cout << "No";
	}
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d %d %d\n" @@ fun n m x y ->
  let max_xs = Array.fold_left max x @@
    Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun x -> x in
  let min_ys = Array.fold_left min y @@
    Array.init m @@ fun _ -> Scanf.scanf "%d " @@ fun y -> y in
  print_endline @@ if max_xs < min_ys then "No War" else "War"


Measured memory_bytes: 512
N = int(input())
S = input()
SS = S
ans = 0
an = []
for x in range(1000):
    check = True
    p = -1
    sx = str(x).zfill(3)
    a = []
    S = SS
    for y in range(3):
        idx = S.find(sx[y])
        if idx < 0:
            check = False
            break
        else:
            S = S[idx + 1:]
    if check:
        an.append(sx)
        ans += 1
print(ans)


Measured memory_bytes: 45020
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define rep(i, n) for(i = 0; i < (int)(n); i++)
using namespace std;

int h, w;
int a[500][500];
int n;
int p[250000], q[250000], r[250000], s[250000];

signed main() {
	int i, j;
	
	cin >> h >> w;
	rep(i, h) rep(j, w) cin >> a[i][j];
	
	rep(i, h) {
		if (i % 2 == 0) {
			for (j = 0; j + 1 < w; j++) {
				if (a[i][j] % 2) {
					p[n] = i; q[n] = j;
					r[n] = i; s[n] = j + 1;
					n++;
					a[i][j]--;
					a[i][j + 1]++;
				}
			}
			if (a[i][w - 1] % 2 && i + 1 < h) {
				p[n] = i; q[n] = w - 1;
				r[n] = i + 1; s[n] = w - 1;
				n++;
				a[i][w - 1]--;
				a[i + 1][w - 1]++;
			}
		}
		else {
			for (j = w - 1; j > 0; j--) {
				if (a[i][j] % 2) {
					p[n] = i; q[n] = j;
					r[n] = i; s[n] = j - 1;
					n++;
					a[i][j]--;
					a[i][j - 1]++;
				}
			}
			if (a[i][0] % 2 && i + 1 < h) {
				p[n] = i; q[n] = 0;
				r[n] = i + 1; s[n] = 0;
				n++;
				a[i][0]--;
				a[i + 1][0]++;
			}
		}
	}
	
	cout << n << endl;
	rep(i, n) { cout << p[i] + 1 << " " << q[i] + 1 << " " << r[i] + 1 << " " << s[i] + 1 << endl; }
	
	/*rep(i, h) {
		rep(j, w) {
			cout << a[i][j];
		}
		cout << endl;
	}*/
	return 0;
}


Measured memory_bytes: 6016
def resolve():
    n = int(input())
    dic = {}
    count = 0
    for i in range(n):
        s = input()
        sorted_s = "".join(sorted(s))
        count += dic.get(sorted_s, 0)
        dic[sorted_s] = dic.get(sorted_s, 0) + 1

    print(int(count))
resolve()

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

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

    int N;
    cin >> N;

    int x = 0, y = 0, z = 0;

    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if(a % 2) x++;
        else if(a % 4 == 0) z++;
        else y++;
    }


    if(x <= z || (y == 0 && x <= z + 1)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N;
	cin >> N;
	char str[N+1];
	cin >> str;
	int sum=0;
	for(int i=0;i<N-2;i++){
		if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C'){
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate as ac
n,m=map(int,input().split())
l=[0]*(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  if a>b:a,b=b,a
  l[a]+=1
  l[b]-=1

*l,=ac(l)
*l,=filter(lambda x:x%2,l)
if l:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 7868
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
    int K,S;
    cin>>K>>S;
    int count=0;
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            if(0<=S-x-y&&S-x-y<=K)count++;
            }
        }
    
    cout<<count<<endl;
    return 0;
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll pow2_m(ll x, ll n, ll mod) {
 ll ans = 1ll;
 while (n > 0) {
  if ((n & 1) == 1) {
   ans = ans * x % mod;
  }
  x = x * x % mod;
  n >>= 1;
 }
 return ans;
}

void solve(){
    ll n;
    cin>>n;
    Array a(n);
    REP(i,n) cin>>a[i];

    Matrix dp(3,Array(n+5,-INF));
    dp[0][0]=0;
    dp[1][1]=0;
    dp[2][2]=0;

    REP(i,n){
        if(i%2==0){
            chmax(dp[0][i+2],dp[0][i]+a[i]);
            chmax(dp[1][i+3],dp[0][i]+a[i]);
            chmax(dp[2][i+4],dp[0][i]+a[i]);
            chmax(dp[2][i+2],dp[2][i]+a[i]);
        }else{
            chmax(dp[1][i+2],dp[1][i]+a[i]);
            chmax(dp[2][i+3],dp[1][i]+a[i]);
        }
    }


    if(n%2==0) cout<<max(dp[0][n],dp[1][n+1])<<en;
    else cout<<max({dp[0][n-1],dp[1][n],dp[2][n+1]})<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}


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


signed main(){
    std::vector<int> v(2);


    while(1){
        std::cin >> v[0] >> v[1];
        if(v[0] ==0 & v[1] ==0){
            break;
        }
        std::sort(v.begin(), v.end());
        std::cout << v[0] << " " << v[1] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3136
import itertools

t = []
for i in range(5):
  t.append(int(input()))

candidates = []
for check in itertools.permutations(t):
  t = 0
  for i in range(4):
    t+= -((-check[i])//10)*10
  t+=check[-1]
  candidates.append(t)

print(min(candidates))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
typedef pair<double, double> P;
typedef complex<double> xy_t;
int n;
xy_t p[50];
// 図 (1) 内積: a.x*b.x +a.y*b.y
double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
// 図 (2) クロス (外) 積, ベクトル a,b が作る三角形の符号付き面積の二倍: a.x*b.y- b.x*a.y
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }
// (対応図なし) 投影 原点と b を結ぶ直線に点 p を投影
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }

void solve(){
    if(n % 2){
        printf("NA\n");
        return;
    }
    xy_t a = (p[0] + p[n / 2]) * 0.5; 
    for (int i = 1; i < n / 2; ++i) {
        xy_t b = (p[i] + p[i + n / 2]) * 0.5;
        if(abs(a - b) > 0.0001){
            printf("NA\n");
            return;
        }
    }
     printf("%.5f %.5f\n", a.real(), a.imag());
}
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        double x, y;
        cin >> x >> y;
        p[i] = xy_t(x, y);
    }
    solve();
}


Measured memory_bytes: 3280
using System;
using System.Collections.Generic;

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

            var s = Console.ReadLine();
            int n = int.Parse(s);
            var s2 = Console.ReadLine().Split(' ');
            var s3 = Console.ReadLine().Split(' ');
            var a = new int[n + 1];
            var b = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s2[i]);
                b[i] = int.Parse(s3[i]);
            }
            a[n] = int.Parse(s2[n]);
            int templeft = a[0];
            long killed = 0;
            for (int i = 0; i < n; i++)
            {
                if (templeft <= b[i])
                {
                    if (a[i + 1] >= b[i] - templeft)
                    {
                        templeft = a[i + 1] - (b[i] - templeft);
                        killed += b[i];
                    }
                    else
                    {
                        killed += templeft + a[i + 1];
                        templeft = 0;
                    }
                }
                else
                {
                    killed += b[i];
                    templeft = a[i + 1];
                }
            }
            Console.WriteLine(killed);


#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


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

using namespace std;

#define INF 1e9

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

    int a,b,c,x;
    cin>>a>>b>>c>>x;

    int ans=0;

    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                int sum=500*i+100*j+50*k;

                if(sum==x)ans++;
                
            }
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = Integer.parseInt(sc.next());
		ArrayList<Pair> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(new Pair(i+1,sc.next(), Integer.parseInt(sc.next())));
		}
		Collections.sort(list, new PairComparator());
		
		for (int i = 0; i < N; i++) {
			System.out.println(list.get(i).num);
		}
		
		
	}


}
class Pair{
	int num;
	String name;
	int score;
	
	Pair(int num, String name, int score){
		this.num = num;
		this.name = name;
		this.score = score;
	}
}

class PairComparator implements Comparator<Pair> {

	@Override
	public int compare(Pair p1, Pair p2) {
		if(p2.name.compareTo(p1.name) != 0)
			return p1.name.compareTo(p2.name);
		else {
			return p2.score < p1.score ? -1 : 1;
		}
	}
}



Measured memory_bytes: 23380
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main(void){
    long X;
    std::cin >>X;
    bool flag=0;
    for(long i=-3000;i<=3000;i++){
        for(long j=-3000; j<=3000; j++){
            if(i*i*i*i*i-j*j*j*j*j==X){
                std::cout << i << " " << j;
                flag=1;
                break;
            }
        }
        if(flag){
            flag=0;
            break;
        }
    }
    return 0;
}

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

using namespace std;

using ll = long long;
const int N = 21;
int a[N], b[N], c[N];

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    for (int i = 1; i < n; i++) {
        cin >> c[i];
    }
    ll ans = 0;
    int last = -1;
    for (int i = 1; i <= n; i++) {
        int dish = a[i];
        ans += b[dish];
        if (dish - 1 == last) {
            ans += c[dish - 1];
        }
        last = dish;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

int main() {
	int array[5];
	for (int i = 0; i < 5; i++) {
		scanf("%d", &array[i]);
	}
	int k;
	scanf("%d", &k);
	int min = array[0];
	int max = array[0];
	for (int i = 0; i < 5; i++) {
		if (max < array[i]) {
			max = array[i];
		}
		if (min > array[i]) {
			min = array[i];
		}
	}
	if (max - min > k) {
		std::cout << ":(";
	}
	else {
		std::cout << "Yay!";
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<string.h>
#include<cmath>
#include<cstdlib>
using namespace std;
const int maxn = 1e2 + 5;
#define PI 3.14159265359
int main(){
	char a[maxn],b[maxn];
	scanf("%s %s",a,b);
	if(strlen(a) > strlen(b)){
	cout << "GREATER" << endl;
		return 0;
	}
	else if (strlen(a) < strlen(b)){
		cout << "LESS" << endl;
		return 0;
	}
	if(strcmp(a,b) > 0 ) cout << "GREATER" << endl;
	if(strcmp(a,b) == 0) cout << "EQUAL" << endl;
	if(strcmp(a,b) < 0) cout << "LESS" << endl;
	return 0;
}

Measured memory_bytes: 256