akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

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

int main() {
  int n, k, c[3];
  cin >> n >> k;
  rep(i,3) cin >> c[i];
  int s[n];
  rep(i,n) {
    char t;
    cin >> t;
    s[i] = (t == 'r' ? 2 : (t == 's' ? 0 : 1));
  }
  
  int r = 0;
  rep(i,n) r += c[s[i]];
  
  rep(i,k) {
    int p = s[i], m = 1;
    rep(j,n) {
      if(i+k*(j+1) < n && s[i+k*(j+1)] == p) m += 1;
      else {
        r -= c[p] * (m / 2);
        if(i+k*(j+1) >= n) break;
        p = s[i+k*(j+1)];
        m = 1;
      }
    }
  }
  
  cout << r << endl;
  return 0;
}

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

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


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

  int N, K;
  string S;
  cin >> N >> K >> S;
  vector<int> as, bs; // 1, 0
  int a = 0;
  if (S.front() == '0') as.push_back(0);
  S += "10";
  F0R(i, S.size()) {
    if (!i || S[i] == S[i-1]) {
      a++;
    }
    else {
      if (S[i-1] == '0') {
        bs.push_back(a);
      }
      else {
        as.push_back(a);
      }
      a = 1;
    }
  }
  as.back()--;
  //Print(as);
  //Print(bs);
  int b = min<int>(K + 1, as.size());
  a = 0;
  F0R(i, b) {
    if (i) a += bs[i - 1];
    a += as[i];
  }
  int result = a;
  F0R(i, as.size() - b) {
    a += as[b + i] - as[i] + bs[b+i-1] - bs[i];
    chmax(result, a);
  }
  cout << result;
}
#endif


Measured memory_bytes: 4012
import math
S=input()
count=0
for i in range(len(S)):
    if(i%2==0):
        if(S[i]=="R" or S[i]=="U" or S[i]=="D"):
            count=count+1
    else:
        if(S[i]=="L" or S[i]=="U" or S[i]=="D"):
            count=count+1
if(count==len(S)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJVolume0_0001
{
    class Program
    {
        static List<int> _mountains = new List<int>();
        static int _higest = 0;

        static void Main(string[] args)
        {
            for (int i = 0; i < 10; ++i)
            {
                _mountains.Add(int.Parse(Console.ReadLine()));
            }
            for (int i = 0; i < 3; ++i)
            {
                _higest = _mountains.Where(x =>x>0).Max();
                Console.WriteLine(_higest);
                _mountains.Remove(_higest);
            }
        }
    }
}



Measured memory_bytes: 18216
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
static const int INF = 1e9;

int main(void){
    int n, m; cin >> n >> m;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    vector<int> c(m);
    rep(i, m) cin >> c[i];
    //dp[???????????°???????????????][?????\???]
    int dp[1001][1001];
    rep(i, 1001)rep(j, 1001) dp[i][j] = INF;//?????????
    rep(i, m) dp[0][i] = 0;//?????????
    reps(i, 1, n + 1){
        rep(j, m){
            //?????????
            dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + d[i - 1] * c[j]);
        }
    }
    int ans = INF;
    //?????????????°???????????????¢???
    rep(i, m){
        ans = min(ans, dp[n][i]);
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll A, B;
    cin >> A >> B;
    if (A > B)
        cout << A + std::max(A - 1, B) << endl;
    else
        cout << B + std::max(A, B - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,ans=100000,G[500][500],b[500],cnt[500]={0},cur_max,cur_i,vis[500]={0};
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&G[i][j]);
        }
    }
    for(int i=1;i<=m;i++)b[i]=i;
    for(int i=1;i<=n;i++)cnt[G[i][1]]++;
    for(int i=1;i<=m;i++)
    {
        if(cur_max<cnt[i])
        {
            cur_max=cnt[i];cur_i=i;
        }
    }
    vis[cur_i]=1;
    //cout<<cur_i<<" "<<cur_max<<endl;
    while(cur_max!=0)
    {
        ans=min(cur_max,ans);
        cur_max=0;
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(!vis[G[i][j]])
                {
                    cnt[G[i][j]]++;
                    break;
                }
            }
        }
        //for(int i=1;i<=m;i++)cout<<cnt[i]<<" ";cout<<endl;
        for(int i=1;i<=m;i++)
        {
            if(cur_max<cnt[i]&&!vis[i])
            {
                cur_max=cnt[i];
                cur_i=i;
            }
        }
        vis[cur_i]=1;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 896
import java.util.*;
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException {
    PrintWriter out = new PrintWriter(System.out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st  = new StringTokenizer(br.readLine());

    int h = Integer.parseInt(st.nextToken());
    int w = Integer.parseInt(st.nextToken());
    
    st  = new StringTokenizer(br.readLine());

    int cx = Integer.parseInt(st.nextToken())-1;
    int cy = Integer.parseInt(st.nextToken())-1;

    st  = new StringTokenizer(br.readLine());

    int dx = Integer.parseInt(st.nextToken())-1;
    int dy = Integer.parseInt(st.nextToken())-1;


    char[][] grid = new char[h][w];

    for (int i=0; i<h; i++) {
      String s  = (br.readLine());
      for (int j=0; j<w; j++) {
        grid[i][j] = s.charAt(j);
      }
    }

    int[][] dist = new int[h][w];
    for (int i=0; i<h; i++) {
      Arrays.fill(dist[i], Integer.MAX_VALUE);
    }

    Deque<Integer> dq = new LinkedList();

    dq.addFirst(cy);
    dq.addFirst(cx);
    dist[cx][cy] = 0;

    int[][] dirs = new int[][]{{0,1}, {0,-1}, {-1,0}, {1,0}};

    while (!dq.isEmpty()) {
      int curx = dq.removeFirst(), cury = dq.removeFirst();
      for (int[] dir: dirs) {
        int newx = curx + dir[0], newy = cury + dir[1];
        if (!isLegal(h,w,newx,newy)) {
          continue;
        }
        if (grid[newx][newy]=='.') {
          if (dist[newx][newy]>dist[curx][cury]) {
            dist[newx][newy] = dist[curx][cury];
            dq.addFirst(newy);
            dq.addFirst(newx);
          }
        }
      }

      for (int i=curx-2; i<=curx+2; i++) {
        for (int j=cury-2; j<=cury+2; j++) {
          if (!isLegal(h,w,i,j)) {
            continue;
          }
          if (grid[i][j]=='.') {
            if (dist[i][j]>dist[curx][cury]+1) {
              dist[i][j] = dist[curx][cury]+1;
              dq.addLast(i);
              dq.addLast(j);
            }
          }
        }
      }
    }

    if (dist[dx][dy]==Integer.MAX_VALUE) {
      out.println(-1);
    }
    else
      out.println(dist[dx][dy]);


    out.close();
  }

  public static boolean isLegal(int h, int w, int i, int j) {
    if (i>=0 && i<h && j>=0 && j<w) {
      return true;
    }
    return false;
  }



  
}










Measured memory_bytes: 63880
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, M, opt[(int)1e4 + 5], cost[10] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> avail;

void solve(){
  opt[0] = 0; 
  for(int use = 1; use <= N; ++use) opt[use] = -INF;

  for(int use = 1; use <= N; ++use){
    for(int dig : avail){
      if(cost[dig] > use) continue;
      max_self(opt[use], 1 + opt[use - cost[dig]]);
    }
  }

  assert(opt[N] > 0);

  int use = N;
  while(use > 0){
    for(int dig : avail){
      if(cost[dig] > use) continue;
      if(opt[use] == opt[use - cost[dig]] + 1){
        cout << dig;
        use -= cost[dig];
        break;
      }
    }
  }
  
  return;
}
    
    



int main(){
  FAST_IO
  cin >> N >> M;
  avail.resize(M);
  for(int &ele : avail) cin >> ele;

  sort(ALLR(avail));

  solve();
  return 0;
}


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

#define State string::const_iterator
class ParseError {};

int number(State &begin);
int factor(State &begin);
void consume(State &begin, char expected);

// 数字の列をパースして、その数を返す。
int number(State &begin) {
    int ret = 0;

    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}

// 括弧か数をパースして、その評価結果を返す。
int factor(State &begin) {

    consume(begin, '['); // '('を飛ばす。

    if(*begin != '['){
        return number(begin) / 2 + 1; //[23]のような形
    }

    //[[23][31][52]]のような形より[]が多い時に通る。
    priority_queue<int> q;
    while(*begin == '['){
        q.push(-factor(begin)); //[[23][31][52]]のような形になるまで再帰
        consume(begin, ']');
    }
    int ans = 0;
    int siz = q.size();
    for(int i=0; i<siz/2 + 1; i++){
        ans += -q.top();
        q.pop();
    }
    return ans;

}

// beginがexpectedを指していたらbeginを一つ進める。
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'"
             << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

int main() {

    int n;

    cin >> n;

    while(n--){

        string input;

        cin >> input;

        State s = input.begin();

        cout << factor(s) << endl;

    }

    return 0;
}


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

int main() {
  int N, ans;
  cin >> N;
  vector<int>d(N);
  for(int i=0; i<N; i++) cin >> d.at(i);
  sort(d.begin(), d.end());
  
  ans = d.at(N/2)-d.at(N/2-1);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3748
n,m = map(int, input().split( ))
a = list(map(int, input().split( )))
a.sort()
manu = []
for i in range(m):
    bi,ci = map(int, input().split( ))
    manu.append((ci,bi))
manu.sort(reverse = True)

cnt = 0
ida = 0

#aを変えるより直接ansに足した方が定数倍速いだろうが省略
for i in range(m):
    cnt = manu[i][1]
    while cnt>0 and ida<n:
        if a[ida]<manu[i][0]:
            a[ida] = manu[i][0]
            cnt-=1
        ida += 1
print(sum(a))




Measured memory_bytes: 71064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  int sum=0;
  int l,r;
  
  for (int i=0;i<N;i++){
    cin >> l >> r;
    sum+=r-l+1;
  }
	cout << sum << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define pb push_back

using namespace std;
typedef long long LL;
int T[200001];
bool vis[200001];
int ans, mulai, selesai;
vector<int> d;
LL K;

void dfs(int nod) {
	vis[nod] = 1;
	d.pb(nod);
	if (K == 0) {
		ans = nod;
		return;
	}
	if (!vis[T[nod]]) K--, dfs(T[nod]);
	else {
		mulai = T[nod];
		selesai = nod;
	}
}

int main() {
	int N;
	scanf("%d%lld", &N, &K);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &T[i]);
	}
	dfs(1);
	if (K > 0) {
		int cycle;
		K--;
		int l1 = d.size();
		for (int i = 0; i < l1; i++) {
			if (d[i] == mulai) {
				for (int j = i; j < l1; j++) {
					if (d[j] == selesai) {
						cycle = j - i + 1;
						mulai = i; selesai = j;
						i = l1;
						break;
					}
				}
			}
		}
		K %= cycle;
		ans = d[mulai + K];
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 9808
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#include <bitset>

using namespace std;

#define FSIO  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define DEBUG(a)   cout<<"DEBUG: "<<(a)<<endl;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define MP make_pair
#define X  first
#define Y  second
#define REP(i,st,ed)    for(int i=st;i<=ed;++i)
#define IREP(i,st,ed)   for(int i=st;i>=ed;--i)
#define TCASE(T)    cin>>T;while(T--)

const int MAXN = 5005;
const ll MOD = 1e9+7 ;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 1e9+7;
const double PI = acos(-1.0);
const double EPS = 1e-8;

int _;

using namespace std;



int main()
{
    //freopen("test.in","r+",stdin);
    //freopen("test.out","w+",stdout);
    FSIO;
    int A, B;
    while(cin>>A>>B)
    {
        if(B%A==0)  cout<<A+B<<endl;
        else    cout<<B-A<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  long N;
  cin >> N;
  
  vector<long> costs(N, 0);
  for (long i = 0; i < N; ++i) cin >> costs[i];
  vector<long> dp(N + 1, 0);
  dp[1] = abs(costs[1] - costs[0]);
  for (long i = 2; i <= N; ++i) {
    dp[i] = min(dp[i-2] + abs(costs[i] - costs[i-2]), dp[i-1] + abs(costs[i] - costs[i-1]));
  }
  cout << dp[N-1] << std::endl;
    
  return 0;
}

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

string s;

int main(){

    cin >> s;

    for (int i=0; i<s.size(); i += 2){
        if (s.at(i) == 'L'){
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i=1; i<s.size(); i += 2){
        if (s.at(i) == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  int N;
  cin >> N;
  long a[N];
  map<long, int> numMap;

  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (numMap.find(a[i]) != numMap.end()) {
      numMap[a[i]] += 1;
    } else {
      numMap[a[i]] = 1;
    }
  }

  int count = 0;
  long A = 0, B = 0, C = 0;
  // TODO try to refactor
  for (auto b = numMap.begin(); b != numMap.end(); b++) {
    // cout << number << ", " << b->second << endl;
    count++;

    if (A == 0) {
      A = b->first;
    } else if (B == 0) {
      B = b->first;
    } else if (C == 0) {
      C = b->first;
    }
  }

  bool result = true;
  if (count == 3) {
    if ((A ^ B ^ C) != 0 || numMap[A] != numMap[B] || numMap[A] != numMap[C]) {
      result = false;
    }
  } else if (count == 2) {
    if (A != 0 && B != 0) {
      result = false;
    } else {
      if (A == 0 && numMap[B] == 2 * numMap[A]) {
      } else if (B == 0 && numMap[A] == 2 * numMap[B]) {
      } else {
        result = false;
      }
    }
  } else if (count == 1) {
    if (A != 0) {
      result = false;
    }
  } else {
    result = false;
  }

  // cout << "count: " << count << endl;
  // cout << A << ", " << B << ", " << C << endl;
  cout << (result ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main () {
    	int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
      	
      	int t;
      	cin >> t;
      
      	cout << arr[t - 1];
      
    }

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

int main()
{
	std::string str;
	std::getline(std::cin, str);
	
	for (int i = 0; i < str.length() - 1; ++i)
	{
		if (str[i] == 'A' && str[i + 1] == 'C')
		{
			std::cout << "Yes";
			return 0;
		}
	}
	
	std::cout << "No";
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    vector<int> P(n), Q(n);
    rep(i, n) cin >> P[i];
    rep(i, n) cin >> Q[i];

    vector<int> array;
    int a = 1, b = 1; bool ap = true, bp = true;
    rept(i, 1, n+1)array.push_back(i);
    do {
        rep(i, n){
            if(array == P)ap = false;
            if(array == Q)bp = false;
        }
        if(ap)a++; if(bp)b++;
    } while (next_permutation(all(array)));

    cout << abs(a - b) << ln;
}

Measured memory_bytes: 3624
from itertools import product
A, B, C, D = map(int, list(input()))
patterns = list(product(("+", "-"), ("+", "-"), ("+", "-")))
for pattern in patterns:
    temp = str(A) + pattern[0] + str(B) + \
        pattern[1] + str(C) + pattern[2] + str(D)
    if eval(temp) == 7:
        print(temp + "=7")
        break


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;

public class Main {

	static int h;
	static int w;

	static String matrix[][];

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

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		h = Integer.parseInt(str[0]);
		w = Integer.parseInt(str[1]);

		int[][] matrix = new int[h][w];
		Queue<Integer> queueX = new ArrayDeque<>();
		Queue<Integer> queueY = new ArrayDeque<>();

		for (int i = 0; i < h; i++) {
			str = br.readLine().split("");
			Arrays.fill(matrix[i], Integer.MAX_VALUE);
			for (int j = 0; j < w; j++) {
				if (str[j].equals("#")) {
					matrix[i][j] = 0;
					queueX.add(j);
					queueY.add(i);
				}
			}
		}
		int ans = 0;

		while (!queueX.isEmpty() && !queueY.isEmpty()) {
			int nowx = queueX.poll();
			int nowy = queueY.poll();
			for (int i = 0; i < 4; i++) {
				if (nowx + dx[i] < 0 || nowx + dx[i] >= w || nowy + dy[i] < 0 || nowy + dy[i] >= h)
					continue;
				int nx = nowx + dx[i], ny = nowy + dy[i];
				if (matrix[ny][nx] == Integer.MAX_VALUE) {
					matrix[ny][nx] = matrix[nowy][nowx] + 1;
					queueX.add(nx);
					queueY.add(ny);
				}
			}
		}
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				ans = Math.max(ans, matrix[i][j]);
		System.out.println(ans);
	}
}

Measured memory_bytes: 110356
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    FAST_IO
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i] == ',') s[i] = ' ';
    }
    cout << s;
}


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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vi f(n,0);
    rep(i,m){
        ll u,v;
        cin>>u>>v;
        u--;v--;
        f[u]++;f[v]++;
    }

    rep(i,n){
        if(f[i]%2 == 1) {
            cout<<"NO\n";
            exit(0);
        }
    }

    cout<<"YES\n";
    timer();
    return 0;
}


Measured memory_bytes: 1152
import numpy as np

N, D = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for m in range(N)]
X = np.array(X)
l = 0

for i in range(N):
  for j in range(i+1, N):
    if sum((X[i] - X[j])**2)**0.5 % 1 == 0:
      l += 1

print(l)

Measured memory_bytes: 14476
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2136
n = gets.chomp.to_i
b_a = 0
b_x = 0
x_a = 0
default = 0
n.times do |i|
  str = gets.chomp
  if (str[0] == 'B' && str[-1] == 'A')
    b_a += 1
  elsif(str[0] == 'B')
    b_x += 1
  elsif(str[-1] == 'A')
    x_a += 1
  end
  default += str.scan('AB').length
end

if (b_a == 0)
  puts [b_x,x_a].min + default
else
  if ((b_x+x_a) > 0)
    puts b_a + [b_x,x_a].min + default
  elsif((b_x+x_a) == 0)
    puts b_a - 1 + default
  end
end


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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;
const int N = 200001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int p[N], f[N], T[N];

int check(int a, int b, int c) {
	return (a < b && b < c) || (b < c && c < a) || (c < a && a < b);
}

int main() {
	int n = read();
	for(int i = 1; i <= n; i++) p[read()] = i;
	for(int i = n - 1; i; i--) {
		if(!f[i + 1]) {
			if(p[i] > p[i + 1]) T[i] = 1, f[i] = i + 1;
		} else {
			if(check(p[i], p[i + 1], p[f[i + 1]])) T[i] = T[i + 1], f[i] = f[i + 1];
			else T[i] = T[i + 1] + 1, f[i] = i + 1;
		}
	} put(T[1]), puts("");
	return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+1>=c){
    cout<<b+c<<endl;
  }
  else{
    cout<<b+c-(c-(a+b+1))<<endl;
  }
}
   

Measured memory_bytes: 256
import copy
N = int(input())
x_original = list(map(int,input().split()))
x = sorted(copy.copy(x_original))
n = int(N/2)
for i in range(N):
    if(x_original[i]>=x[n]):
        print(x[n-1])
    else:
        print(x[n])


Measured memory_bytes: 25660
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	Int N, M;
	cin >> N >> M;

	vector<Int> a(8);//a[i]: i本のマッチで作れる数字の最大値（デフォルト）

	Int temp;
	for (Int i = 0; i < M; i++) {
		cin >> temp;
		if (temp == 1) {
			a[2] = 1;
		}
		else if (temp == 7) {
			a[3] = 7;
		}
		else if (temp == 4) {
			a[4] = 4;
		}
		else if (temp == 8) {
			a[7] = 8;
		}
		else if (temp == 6 || temp == 9) {
			a[6] = max(a[6], temp);
		}
		else {
			a[5] = max(a[5], temp);
		}
	}

	vector<string> dp(N + 10);//dp[i]: i本のマッチで作れる最大整数

	string tempS;
	for (Int i = 2; i < 8; i++) {
		if (a[i]) {
			tempS = to_string(a[i]);
			dp[i] = tempS;
		}
	}



	//dp
	Int len1;
	Int len2;
	for (Int i = 0; i < N; i++) {
		if (dp[i]=="") {
			continue;
		}

		for (Int j = 2; j < 8; j++) {
			if (a[j]==0) {
				continue;
			}
			if (i+j>N) {
				break;
			}
			else {

				tempS = dp[i];
				tempS+=to_string(a[j]);

				len1 = tempS.size();
				len2 = dp[i + j].size();

				if (len2>len1) {
					continue;
				}
				else if (len2<len1) {
					dp[i + j] = tempS;
				}
				else if (tempS>dp[i+j]) {//長さが一緒の場合
					dp[i + j] = tempS;
				}

			}
		}

	}
	cout << dp[N] << "\n";
}


Measured memory_bytes: 45056
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>
#include<numeric>
#include<stdlib.h>

using namespace std;

int main()
{

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

  int cnt = 0;
  if(a != b){
    cnt++;
  }
  if(a != c){
    cnt++;
  }
  if(b != c){
    cnt++;
  }

  if(cnt == 0){
    cnt = 1;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef struct proc {
    string name;
    int time;
} Proc;

Proc newProc(string n, int t) {
    Proc p = {n, t};
    return p;
}

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

    queue<Proc> Q;

    for (int i = 0; i < n; i++) {
        string n;
        int t;
        cin >> n >> t;
        Q.push(newProc(n, t));
    }

    int all_time = 0;
    while (!Q.empty()) {
        Proc p = Q.front();
        if (p.time <= q) {
            all_time += p.time;
            cout << p.name << " " << all_time << endl;
            Q.pop();
        } else {
            all_time += q;
            Q.pop();
            p.time -= q;
            Q.push(p);
        }
    }

    return 0;
}



Measured memory_bytes: 6272
#include <iostream>
#include <vector>
using namespace std;
typedef vector <double> DVEC;

int Aout(DVEC &A, int n){
	for (int i=0; i<n; i++){
		if (i!=0) cout<<" ";
		cout<<A[i];
	}
	cout<<endl;
	return 0;
}

int insertionsort(DVEC &A, int n){
	double key;
	int i;
	for (int j=1; j<n; j++){
		key = A[j];
		i = j-1;
		while (i>=0){
			if (A[i] <= key) break;
			A[i+1] = A[i];
			i--;
		}
		A[i+1] = key;
		Aout(A, n);
	}
	return 0;
}

int main(void){
	int n;

	cin>>n;
	DVEC A(n);

	for (int i=0; i<n; i++)
		cin>>A[i];
	Aout(A, n);
	insertionsort(A, n);

	return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



ll gcd(ll x,ll y){

	x = abs(x);
	y = abs(y);

	if(x < y){
		swap(x,y);
	}
	if(y == 0){
		return x;
	}else{
		return gcd(y,x%y);
	}
}

ll N,X;
vector<ll> V;

int main(){

	scanf("%lld %lld",&N,&X);
	V.push_back(X);

	ll tmp;
	for(ll i = 0; i < N; i++){

		scanf("%lld",&tmp);
		V.push_back(tmp);
	}

	sort(V.begin(),V.end());

	ll base = V[1]-V[0];
	for(int i = 1; i < V.size()-1; i++){

		base = gcd(base,V[i+1]-V[i]);
	}

	printf("%lld\n",base);

	return 0;
}


Measured memory_bytes: 4244
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i < N; i++){
    cin >> vec.at(i);
  }
  int ans = 0;
  for(int i=0; i < N; i++){
    for(int j=i+1; j < N; j++){
      ans += vec.at(i)*vec.at(j);
    }
  }
  cout << ans << endl;
  return 0;
}
      

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<tuple>
#include<numeric>
#include<limits>

using wight_graph = std::vector<std::vector<std::pair<size_t, size_t>>>;

int main(){
    
    size_t v, e;
    std::cin >> v >> e;

    wight_graph g(v);

    for(size_t i = 0; i < e; i++){
        size_t s, t, w;
        std::cin >> s >> t >> w;

        g.at(s).emplace_back(t, w);
        g.at(t).emplace_back(s, w); // 婿向グラフリスト表現
    }

    std::vector<size_t> cost(v, std::numeric_limits<size_t>::max()); // 添字(頂点)の最も小さいコスト
    std::vector<size_t> seen(v, false);
    std::priority_queue<std::pair<size_t, size_t>,
                        std::vector<std::pair<size_t, size_t>>, 
                        std::greater<std::pair<size_t, size_t>>> candidate; // firsr: 重み second: 添字(頂点)

    cost.at(0) = 0; // 始点のコストをゼロに
    candidate.emplace(0, 0); // 始点を候補へ追加

    while(!candidate.empty()){
        size_t weight, index;
        std::tie(weight, index) = candidate.top(); candidate.pop(); // c++14 (c++17: structured bindings)
        seen.at(index) = true;

        for(size_t i = 0; i < g.at(index).size(); i++){
            if(cost.at(g.at(index).at(i).first) > g.at(index).at(i).second){
                if(!seen.at(g.at(index).at(i).first)){
                    cost.at(g.at(index).at(i).first) = g.at(index).at(i).second;
                    candidate.emplace(cost.at(g.at(index).at(i).first), g.at(index).at(i).first);
                }
            }
        }
    }
    
    std::cout << std::accumulate(cost.begin(), cost.end(), 0ul) << std::endl;
    
    return 0;
}



Measured memory_bytes: 8992
while 1:
    try:
        s=raw_input()
        joi=0
        ioi=0
        for i in range(len(s)-2):
            if(s[i+1]=="O" and s[i+2]=="I"):
                if(s[i]=="J"):
                    joi+=1
                if(s[i]=="I"):
                    ioi+=1
        print joi
        print ioi
    except EOFError:
        break

Measured memory_bytes: 4320
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m; cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int t; cin >> t;
    n -= t;
  }
  cout << max(-1, n) << '\n';
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int count_str(string str1, string str2)
{
    int ans = 0;
    for(char c = 'a'; c <= 'z'; c++)
    {
        bool found_left = false;
        bool found_right = false;

        REP(i, str1.length())
        {
            if (str1[i] == c)
            {
                found_left = true;
            }
        }

        REP(i, str2.length())
        {
            if (str2[i] == c)
            {
                found_right = true;
            }
        }

        if (found_left && found_right)
        {
            ans++;
        }
    }

    return ans;
}

int main()
{
    int n = 0;
    string s = "";

    cin >> n >> s;

    int ans = 0;

    REP(i, n)
    {
        int tmp = count_str(s.substr(0, i), s.substr(i));
        ans = max(tmp, ans);
    }
    COUT(ans);
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)		memset(v, d, sizeof(v))
const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>P;
const ll mod = ll(1e9 + 7);
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
const int N = 1000001;
#define endl '\n'
#define ever ;;
#define F first
#define S second
#define pii pair<int,int>
#define sz(v) ((int)((v).size()))
#define pll pair<ll,ll>
void stop() {
#ifndef ONLINE_JUDGE
	system("pause");
#endif
}
void file() {
#ifndef ONLINE_JUDGE
	freopen("pizza.in", "r", stdin);
	freopen("pizza.out", "w", stdout);
#endif
}
struct point {
	double x, y;
};
ull gcd(ull a, ull b) { return !b ? a : gcd(b, a % b); }
ll fixMod(ll a, ll b) { return ((a%b) + b) % b; }
double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3) {
	return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.;
};
ll dis(point a, point b) {
	ll x = a.x - b.x, y = a.y - b.y;
	return x * x + y * y;
}
ull LCM(ull a, ull b) {
	return a / gcd(a, b)*b;
}
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}
int main() {
	fast
		string s;
	cin >> s;
	for (int i = 0; i < 3; i++)if (s[i]==s[i+1])return cout << "Bad", 0;
	cout << "Good";
	stop();
	return 0;
}

Measured memory_bytes: 504
#include<stdio.h>

void fibonacchi(int,int);
int compute_finisshed[44];
int value_of_fibonacchi[44];
int main()
{
  int index_of_fibonacchi,i;

  scanf("%d",&index_of_fibonacchi);
  fibonacchi(0,index_of_fibonacchi);
  printf("%d\n",value_of_fibonacchi[index_of_fibonacchi]);
  //for(i = 0; i < index_of_fibonacchi; i++)printf("f(%d):%d\n",i,compute_finisshed[i]);
    
}

void fibonacchi(int i , int index_of_fibonacchi)
{
 
  compute_finisshed[i]++;
  

      if(i == 0 || i == 1)
        {
          //printf("%d\n",i);
          value_of_fibonacchi[i] = 1;
          
          fibonacchi(i+1,index_of_fibonacchi);
        }
      else if(i<=index_of_fibonacchi)
        {
          value_of_fibonacchi[i] = value_of_fibonacchi[i-1] + value_of_fibonacchi[i-2];
          fibonacchi(i+1,index_of_fibonacchi);
        }
 
      
                                    
                                    
}

/*
#include<stdio.h>

int fibonacchi(int);
int compute_finisshed[44];
int main()
{
  int index_of_fibonacchi,i;

  scanf("%d",&index_of_fibonacchi);
  printf("%d\n",fibonacchi(index_of_fibonacchi));
  for(i = 0; i < index_of_fibonacchi; i++)printf("f(%d):%d\n",i,compute_finisshed[i]);
    
}


int fibonacchi(int i)
{

  compute_finisshed[i]++;
  if(i == 0 || i == 1)
    {
      //printf("%d\n",i);
      return 1;
    }
  if(i - 1 >=0 )
    {
      
    return fibonacchi(i -1) + fibonacchi(i - 2);
    }

}
*/


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  vector<long long> w(n);
  for (int i = 0; i < n; i++){
    cin >> w[i];
  }
  long long S = 0;
  long long M = 0;
  for (int i = 0; i < n; i++){
    S += w[i];
    M = max(M, w[i]);
  }
  long long tv = S;
  long long fv = M - 1;
  while (tv - fv > 1){
    long long mv = (tv + fv) / 2;
    int c = 0;
    int l = 0;
    for (int i = 0; i < n; i++){
      if (l + w[i] <= mv){
        l += w[i];
      } else {
        l = w[i];
        c++;
      }
    }
    c++;
    if (c <= k){
      tv = mv;
    } else {
      fv = mv;
    }
  }
  cout << tv << endl;
}


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

int max(int a,int b){
	if(a>b)return a;
	return b;
}

int min(int a,int b){
	if(a<b)return a;
	return b;
}

int compare_char(char *a,char *b){
	return strcmp(a,b);
}

int intsort(const void *a, const void *b){
	return *(int*)b - *(int*)a;
	/*qsort(a,aの配列数,sizeof(int),intsort);*/
}

int longsort(const void *a, const void *b){
	long *A=(long *)a;
	long *B=(long *)b;
	if(*A>*B) return -1;
	if(*A<*B) return 1;
	return 0;
}

void rotate(char ss[],int N){
  int i;
  char a=ss[0];
  for(i=0;i<N-1;i++){
	ss[i]=ss[i+1];
  }
  ss[N-1]=a;
}

int main(){
  int i,N,f=0;
  char sr[100],sl[100];
  scanf("%s",sr);
  scanf("%s",sl);
  N=strlen(sr);
  
  for(i=0;i<N;i++){
    if(strcmp(sr,sl)==0){
      printf("Yes\n");
      return 0;
    }
    rotate(sr,N);
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

template<class D>
struct Hungarian {
    V<D> le, ri;
    V<int> perm;

    Hungarian(const VV<D> &c) {
        int n = int(c.size()), m = int(c[0].size());
        assert(n <= m);
        le = V<D>(n, D(0)); ri = V<D>(m, D(0));
        perm = V<int>(n);
        V<int> to_r(n, -1), to_l(m, -1);

        for (int s = 0; s < n; s++) {
            V<bool> l_u(n), r_u(m); l_u[s] = true;
            V<int> tr(m, -1), min_l(m, s);
            V<D> min_cost(m);
            for (int j = 0; j < m; j++) min_cost[j] = c[s][j] + le[s] + ri[j];
            while (true) {
                int r = -1;
                D d = numeric_limits<D>::max();
                for (int j = 0; j < m; j++) {
                    if (!r_u[j] && min_cost[j] < d) {
                        r = j;
                        d = min_cost[j];
                    }
                }
                for (int i = 0; i < n; i++) if (l_u[i]) le[i] -= d;
                for (int j = 0; j < m; j++) {
                    if (r_u[j]) ri[j] += d;
                    else min_cost[j] -= d;
                }
                tr[r] = min_l[r];
                int l = to_l[r];
                if (l == -1) {
                    while (r != -1) {
                        int nl = tr[r], nr = to_r[nl];
                        to_l[r] = nl; to_r[nl] = r;
                        r = nr;
                    }
                    break;
                }
                l_u[l] = r_u[r] = true;
                for (int j = 0; j < m; j++) {
                    D cost = c[l][j] + le[l] + ri[j];
                    if (cost < min_cost[j]) {
                        min_l[j] = l;
                        min_cost[j] = cost;
                    }
                }
            }
        }
        perm = to_r;
    }
};

 
using D = double;
const D PI = acos(D(-1)), EPS = 1e-10;
using P = complex<D>;
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
 
    D ans = 0;
 
    int n;
    cin >> n;
    V<P> up(n), dw(n);
    D x, y;
    cin >> x >> y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y; up[i] = P(x, y);
        cin >> x >> y; dw[i] = P(x, y);
        ans += abs(up[i]-dw[i]);
    }
 
    int l = int(up.size()), r = int(dw.size());
    VV<D> cost(l, V<D>(r));
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < r; j++) {
            cost[i][j] = abs(up[i] - dw[j]);
        }
    }
    auto perm = Hungarian<D>(cost).perm;
    for (int i = 0; i < l; i++) {
        ans += cost[i][perm[i]];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3868
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X = ii()
    fh = X // 500
    fy = (X - (fh * 500)) // 5
    print(fh * 1000 + fy * 5)


if __name__ == '__main__':
    main()


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

int main(){
  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 total = 500 * i + 100 * j + 50 * k;
        if(total == x) ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  int N,K;
  int L[50];
  int i,j;
  int temp;
  int sum = 0;
  
  scanf("%d %d",&N,&K);
 
  for(i = 0;i < N;i++){
    scanf("%d",&L[i]);
  }
 
  for(i = 0;i < K;i++){
    for(j = 0;j < N;j++){
      if(L[temp] < L[j]){
	temp = j;
      }
    }
    sum += L[temp];
    L[temp] = 0;
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
def solve():
    n,w = map(int,input().split())
    w_list,v_list = [0]*n,[0]*n
    for i in range(n):
        w_list[i],v_list[i] = map(int,input().split())
    dp = [[0]*(w+5) for i in range(n+5)]
    for i in range(n):
        for j in range(w+1):
            if j-w_list[i]>=0:
                dp[i][j] = max(dp[i-1][j],
                               dp[i-1][j-w_list[i]]+v_list[i])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[n-1][w])
    return 0
 
if __name__ == "__main__":
    solve()

Measured memory_bytes: 119536
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define reprs(i, m, n) for(int i = n; i >= m; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pl;
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}


int main(){

  int N,D;
  cin >> N>>D;

  double dist=0;
  int X[N][D];

  rep(i,N){
    rep(j,D){
      cin>>X[i][j];
    }
  }

  int ct=0;

  rep(i,N-1){
    reps(j,i+1,N){
      dist=0;
      rep(k,D){
        dist+=pow(X[i][k]-X[j][k],2);
      }
      if(sqrt(dist)==floor(sqrt(dist))) ct++;
    }
  }
  cout << ct <<endl;
  return 0;
}


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

int main() {
int64_t n;
  cin>>n;
  int64_t ans;
  ans=0;
  int64_t t=1000000007;
  vector<int64_t> vec(n); 
   //cout<<1<<endl;//qqqqqqq
  for(int64_t i=0;i<n;i++){
  cin>>vec.at(i);
  }
  //cout<<1<<endl;//qqqqqqq
  for(int64_t j=0;j<n;j++){
  ans=ans+vec.at(j);
  }
   //cout<<1<<endl;//qqqqqqq
  ans=ans%t;
  ans=(ans*ans)%t;
  for(int64_t i=0;i<n;i++){
  ans=(ans+t-((vec.at(i)%t)*(vec.at(i)%t))%t)%t;
  }
  if(ans%2==0){cout<<ans/2<<endl;}
  else{cout<<(ans+t)/2<<endl;};
}


Measured memory_bytes: 4788
package main

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

func main() {
	n := readInt()

	ans := readInt()
	for i := 0; i < n-1; i++ {
		ans = gcd(ans, readInt())
		if ans == 1 {
			fmt.Println(ans)
			return
		}
	}
	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 2176
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	x = 1000
	for i in 1:n-1
		if a[i]<a[i+1]
			k = div(x,a[i])
			x += k*(a[i+1]-a[i])
		end
	end
	println(x)
end

main()

Measured memory_bytes: 164356
def translate(W, a, b) : 
  if (a <= b <= a + W) or (a <= b + W <= a + W) :
    return 0
  else :
    if a <= b : 
      return b - (a + W)
    
    else : 
      return a - (b + W)


W, a, b = tuple(map(int, input().split()))

print(translate(W, a, b))

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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












int main() {
	ll n;
	cin >> n;
	ll sum = 0, s = 0;
	REP(i, n) {
		ll d;
		cin >> d;
		sum += d;
		s += d * d;
	}
	cout << (sum * sum - s) / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int x, int y){
    if(x<y){
        int temp=x;
        x=y;
        y=temp;
    }
    int r=x%y;
    while(r!=0){
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}
int main(void){
    int n,dis;
    scanf("%d%d",&n,&dis);
    int x,ans;

    for(int i=0; i<n; i++){
        scanf("%d",&x);
        if(ans==0)ans=x-dis>=0?x-dis:dis-x;
        ans=gcd(ans,x-dis>=0?x-dis:dis-x);
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==7 && b==5 && c==5) cout<<"YES"<<endl;
  else if(a==5 && b==7 && c==5) cout<<"YES"<<endl;
  else if(a==5 && b==5 && c==7) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256