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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numRow = sc.nextInt();
        int numCol = sc.nextInt();
        int[][] mat = new int[numRow + 1][numCol + 1];
        int i, j;
        for (i = 0; i < numRow; i++) {
            for (j = 0; j < numCol; j++) {
                mat[i][j] = sc.nextInt();
            }
        }
        for (i = 0; i < numRow; i++) {
            for (j = 0; j < numCol; j++) {
                mat[i][numCol] += mat[i][j];
            }
        }
        for (j = 0; j <= numCol; j++) {
            for (i = 0; i < numRow; i++) {
                mat[numRow][j] += mat[i][j];
            }
        }
        for (i = 0; i <= numRow; i++) {
            for (j = 0; j <= numCol; j++) {
                if (j != 0) System.out.print(" ");
                System.out.print(mat[i][j]);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 41640
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define isz(x) (int)(x).size()
int main() {
	int n; std::string s, t;
  	while (std::cin >> n >> s >> t) {
        std::string answ;
        std::reverse(all(s));
        std::reverse(all(t));
        for (int i = 0; i < n; i++) {
            assert(isz(s));
            answ.push_back(s.back()); s.pop_back();
            assert(isz(t));
            answ.push_back(t.back()); t.pop_back();
        }
        std::cout << answ << std::endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = 0;
		int B = 0;
		
		int window = sc.nextInt();
		int curtain = sc.nextInt();
		
		int opensize = window - (2 * curtain);
		
		if(opensize < 0) {
			System.out.println(0);
		}else {
			System.out.println(opensize);
		}
	}
}

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false);
   int n;
   cin >> n;
   vector<int> p(n);
   for (int i = 0; i < n; ++i) {
      cin >> p[i];
   }
   auto finish = [&]() {
      for (int i = 0; i < n; ++i) {
         if (p[i] != i) return false;
      }
      return true;
   };
   vector<int> ans;
   auto go = [&](int k) {
      ans.push_back(k);
      for (int i = k; i < n; ++i) {
         swap(p[i], p[i - k]);
      }
   };
   while (!finish()) {
      if (p[0] < p[n - 1] && p[n - 1] != (n - 1)) {
         go(n - 1);
      } else {
         go(1);
      }
   }
   cout << ans.size() << "\n";
   for (int v : ans) {
      cout << v << "\n";
   }
}


Measured memory_bytes: 760
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            //var line = consoleReader.SplitInt32();
            var N = consoleReader.Int32();
            if (N == 1) return "Hello World";

            var A = consoleReader.Int32();
            var B = consoleReader.Int32();

            return A + B;
        }

        public const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); } public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); } }
}

Measured memory_bytes: 11092
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  if(a % MOD < 0) return MOD + (a % MOD);
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n,a,b; cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
  
  
}

Measured memory_bytes: 3576
using System;

namespace AtCoder
{
	public class ProblemA
	{
		public static void Main(string[] args)
		{
			string[] line = Console.ReadLine().Split(' ');
			long a = long.Parse(line[0]);
			long b = long.Parse(line[1]);
			long x = long.Parse(line[2]);

			long ans1 = a / x;
			long ans2 = b / x;
			long ans = ans2 - ans1;

			if (a % x == 0)
			{
				ans++;
			}

			Console.WriteLine(ans);
		}
	}
}


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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector <int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

    int sum = 0;
    int max_p = 0;
    for (int i = 0; i < N; i++) {
        sum += p[i];
        max_p = max(max_p, p[i]);
    }

    cout << sum - max_p / 2 << endl;
}

Measured memory_bytes: 256
N = int(input())
a = 0
for i in range(N):
  a = list(map(int, input().split()))
  if a[0] < sum(a) - a[0]:
    print("No")
    exit()
  if (sum(a) - a[0] - a[0])%2 != 0:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a, b, c;
    cin >> a >> b >> c;

    cout << min(b + a + 1, c) + b;

    
 
    return 0;
}

Measured memory_bytes: 256
s = input()

li = []

tmp = s[0]

if tmp == '<':
    flag = 0
else:
    flag = 1

now = 1

for i in range(len(s)-1):
    if tmp == s[i+1]:
        now += 1
    else:
        tmp = s[i+1]
        li.append(now)
        now = 1

li.append(now)
#print(li)
ans = 0
#ans_li = [0]

if flag == 0:
    ans_li = [0]
    for i in range(len(li)):
        if i % 2 == 0:
            for j in range(li[i]):
                ans_li.append(j+1)
        else:
            if li[i] > ans_li[-1]:
                ans_li[-1] = li[i]
            for k in range(li[i]):
                ans_li.append(li[i]-k-1)
else:
    ans_li = [li[0]]
    for i in range(len(li)):
        if i % 2 == 1:
            for j in range(li[i]):
                ans_li.append(j+1)
        else:
            if i != 0 and li[i] > ans_li[-1]:
                ans_li[-1] = li[i]
            for k in range(li[i]):
                ans_li.append(li[i]-k-1)

print(sum(ans_li))

Measured memory_bytes: 24092
#include<iostream>
using namespace std;
int N_MAX=200000;
int main()
{
  int m,d,i,x;
  long long c,res=0;
  long long t[N_MAX];
  cin >> m;
  for(i=0;i<m;i++){
    cin >> d >> c;
    res+=c-1+d*c/9;
    t[i]=d*c%9;
    if(t[i]==0&&d>0){
      t[i]=9;
      res--;
    }
  }
  for(i=0;i<m-1;res++){
    x=t[i]+t[i+1];
    if(x>=10){
      t[i]=1;
      t[i+1]=x-10;
    }else{
      t[i+1]=x;
      i++;
    }
  }
  cout << res << endl;
  return 0;
}

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

string A,B;
int ans = 0;
void dfs(int p,string C,int k,int c){
	//cout << "[" << C << "]" << " " << k << " " << p << endl;
	if( p < 0 ) {
		if( c == 0 ) {
			
			ans = max( ans , atoi(C.c_str()));
		}
		
		return;
	}else{
		int carry = 0;
		int calc = (int)A[p] - (int)B[p] - (int)c; 
		if( calc >= 0 ){
			dfs(p-1,string(1,'0'+calc)+C,k,0);
		}else{
			calc = 10 + calc;
			//cout << calc << "<<" << endl;
			dfs(p-1,string(1,'0'+calc)+C,k,1);
			if(k) dfs(p-1,string(1,'0'+calc)+C,k-1,0);		
		}
	}
}
int main(){
	int K;
	cin >> A >> B>> K;
	while(B.size() < A.size() ) B = "0" + B;
	while(B.size() > A.size() ) A = "0" + A;
	dfs(A.size()-1,"",K,0);
	cout << ans << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
string s[10005];
bool visit[10005],visit1[10005];
int a[10];
string solve(int n,int m)
{
  // cout<<n<<endl;
  if(n==0)return "";
  if(visit[n])return s[n];
  string r="";
  for (int i = 0; i < m; ++i)
  {
    if(a[vec[i]]==n)
    {
      string g="";
      g+='0'+vec[i];
      int l=g.size();
      int x=r.size();
      if(l>x)r=g;
      else if(l==x)r=max(r,g);
    }
    else if(visit1[n-a[vec[i]]])
    {
      string g="";
      g+='0'+vec[i];
      // cout<<g<<endl;
      g+=solve(n-a[vec[i]],m);
      int l=g.size();
      int x=r.size();
      if(l>x)r=g;
      else if(l==x)r=max(r,g);
    }
  }
  s[n]=r;
  visit[n]=true;
  return r;
}
int main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  a[1]=2;
  a[2]=5;
  a[3]=5;
  a[4]=4;
  a[5]=5;
  a[6]=6;
  a[7]=3;
  a[8]=7;
  a[9]=6;
  int n,m;
  memset(visit,false,sizeof(visit));
  cin>>n>>m;

  for (int i = 0; i < m; ++i)
  {
    /* code */
    int g;
    cin>>g;
    vec.push_back(g);
  }
  memset(visit1,false,sizeof(visit1));
  visit1[0]=true;
  for(int i=1;i<=10000;i++)
  {
    for(int j=0;j<m;j++)
    {
      if(i>=a[vec[j]] && visit1[i-a[vec[j]]]==true)visit1[i]=true;
    }
  }
  string r=solve(n,m);
  cout<<r<<endl;
  return 0;
}

Measured memory_bytes: 33280
#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;
long long n,m;

int main()
{
    IO;
    string s;
    cin>>s;
    int x=s.size();
    if(s[x-1]=='s')
        cout<<s<<"es"<<endl;
    else
        cout<<s<<'s'<<endl;

    return 0;
}


Measured memory_bytes: 3580
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int asc(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int desc(const void* a, const void* b) { return *(int*)b - *(int*)a; }

//qsort(data,10,sizeof(int),compare_int);

int main(void)
{
	int n;
	int h[100000];
	int start, max, cnt;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}

	max = cnt = 0;
	start = h[0];
	for (int i = 1; i < n; i++) {
		
		if (start >= h[i]) {
			cnt++;
			if (i == n - 1) {
				if (max < cnt) {
					max = cnt;
				}
			}
			start = h[i];
		}
		else if (start < h[i]) {
			//printf("%d\n", h[i]);
			if (max < cnt) {
				max = cnt;
				cnt = 0;
			}
			cnt = 0;
			start = h[i];
		}
		//printf("start?%d\n", start);
	}
	printf("%d\n", max);
	return 0;
}

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

int main(){
    ll n, m;
    cin>>n>>m;
    ll k[n];
    vector<ll> a(m);
    ll flag;
    ll x=0;
    for(ll i=0;i<n;++i){
        cin>>k[i];
        for(ll j=0;j<k[i];++j){
            cin>>flag;
            a[flag-1]++;
        }
    }
    ll ans=0;
    for(ll i=0;i<m;++i){
        if(a[i]==n){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(input().split())
from collections import deque
b=deque()
if n%2==0:
    for i in range(n):
        if i%2==0:
            b.append(a[i])
        else:
            b.appendleft(a[i])
else:
    for i in range(n):
        if i%2==0:
            b.appendleft(a[i])
        else:
            b.append(a[i])
B=[]
for i in range(n):
    B.append(b.popleft())
print(" ".join(B))

Measured memory_bytes: 30480
#include<bits/stdc++.h>
using namespace  std;
int main(){
  int n,T;
  cin>>n>>T;
  int ans=1e9;
  for(int i=1;i<=n;++i){
    int c,t;cin>>c>>t;
    if(t<=T){
      ans=min(ans,c);
    }
  }
  if(ans!=1e9)cout<<ans<<"\n";
  else cout<<"TLE\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  map<int, int> mp;
  mp[4]=mp[6]=mp[9]=mp[11]=1;
  mp[2]=2;

  int x, y; cin >> x >> y;
  if (mp[x] == mp[y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = abs(a - b);
  int y = abs(b - c);
  int z = abs(c - a);
  cout << ((z <= d || x <= d && y <= d) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3636
import collections

N = int(input())

a_list = []
for i in range(N):
    a = input()
    a = ''.join(sorted(a))
    a_list.append(a)

a_list = sorted(a_list)

c = collections.Counter(a_list)

sum = 0
for k, v in c.most_common():
    sum += v*(v-1)//2
print(sum)

Measured memory_bytes: 24508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		n=2*n-1;
		int x=sc.nextInt();
		if(n==1){
			if(x==1){
				System.out.println("Yes");
				System.out.println(1);
				return;
			}else{
				System.out.println("No");
				return;
			}
		}
		if(n==3){
			if(x==2){
				System.out.println("Yes");
				System.out.println(1);
				System.out.println(2);
				System.out.println(3);
				return;
			}else{
				System.out.println("No");
				return;
			}
		}
		if(x==1 || x==n){
			System.out.println("No");
			return;
		}else{
			System.out.println("Yes");
			int count=0;
			for(int i=1;i<=n;i++){
				if(count==(n-5)/2){
					if(x-2==0){
						System.out.println(x+2);
						System.out.println(x-1);
						System.out.println(x);
						System.out.println(x+1);
						System.out.println(x+3);
					}else if(x+2==n+1){
						System.out.println(x-3);
						System.out.println(x-1);
						System.out.println(x);
						System.out.println(x+1);
						System.out.println(x-2);
					}else{
						System.out.println(x+2);
						System.out.println(x-1);
						System.out.println(x);
						System.out.println(x+1);
						System.out.println(x-2);
					}
					count+=5;
				}
				if(x-2==0 && i==x+3)continue;
				if(x+2==n+1 && i==x-3)continue;
				if(i>=x-2 && i<=x+2)continue;
				else{
					System.out.println(i);
					count++;
				}
			}
		}
	}
	
}


Measured memory_bytes: 45840
import java.util.*;

public class Main {
    public static void main(String[] args) {
      
        // 標準入力から値を取得してinputに入れる
        Scanner sc = new Scanner(System.in);
        String inputStr = sc.nextLine();
        char[] inputCh = inputStr.toCharArray();

        int inputNum = Integer.parseInt(inputStr);  // 入力値
        int sn = 0;                                 // 各桁の和
        String answer = "No";                       // 出力結果

        for (int i = 0; i < inputCh.length; i++) {
            int num = Character.getNumericValue(inputCh[i]);
            sn = sn + num;
        }
      
        if (inputNum % sn == 0) {
            answer = "Yes";
        }  
      
        System.out.println(answer);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
const int zzy = 1000000007;
int dp[610][610], n, k;
int g[610], sum[610], to[610];
int main() {
    scanf("%d%d", &n, &k);
    g[0] = 1;
    for (int i = 2; i <= 2 * n; i += 2) g[i] = 1ll * (i - 1) * g[i - 2] % zzy;
    for (int i = 1; i <= k; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        sum[a] = sum[b] = 1;
        to[a] = b, to[b] = a;
    }
    for (int i = 1; i <= 2 * n; i++) sum[i] += sum[i - 1];
    for (int i = 2 * n; i --> 1; ) {
        for (int j = i + 1; j <= 2 * n; j++) {
            int flag = 0;
            for (int k = i; k <= j; k++) if (to[k] && to[k] < i || to[k] > j) flag = 1;
            if (flag) continue;
            dp[i][j] = g[(j - i + 1) - (sum[j] - sum[i - 1])];
            for (int k = i; k < j; k++)
                dp[i][j] = (dp[i][j] - 1ll * dp[i][k] * g[(j - k) - (sum[j] - sum[k])] % zzy + zzy) % zzy;
        }
    }
    int ans = 0;
    for (int i = 1; i < 2 * n; i++)
        for (int j = i + 1; j <= 2 * n; j++) ans = (ans + 1ll * dp[i][j] * g[2 * n - (j - i + 1) - sum[i - 1] - (sum[2 * n] - sum[j])]) % zzy;
    return cout << ans << endl, 0;
}

Measured memory_bytes: 1664
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  string s;
  cin >> s;
  ll n = s.size();
  bool used[26]={};
  if(n != 26){
    for(auto c:s){
      used[c-'a'] = true;
    }
    for(int i=0;i<26;i++){
      if(!used[i]){
        s += (char)('a'+i);
        break;
      }
    }
    cout << s << endl;
  }else{
    for(int i=n-1;i>=0;i--){
      char c;
      for(c=s[i]+1;c<='z';c++){
        if(used[c-'a']){
          break;
        }
      }
      if(c<='z'){
        for(int j=0;j<i;j++){
          cout << s[j];
        }
        cout << c<<endl;
        return 0;
      }
      used[s[i]-'a'] = true;
    }
    cout << -1<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;

/*sortの仕方
 * ■ string s の場合
 * 昇順: sort(s.begin(), s.end())
 * 降順:  sort(s.rbegin(), s.rend())
 *
 * ■ ll a[N] の場合
 * 昇順: sort(a, a+N)
 * 降順: 不明
 */

/*ll alph2ll(char character) {
    ll x = character - 'a';
    return x;
}
*/

// ll my_gcd(ll a, ll b){
// 	return (b==0) ? a : my_gcd(b, a%b);
// }
//
// ll my_lcm(ll a, ll b){
// 	return a*b / my_gcd(a,b);
// }


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

	if(s.length() <= 2){
		cout << s << endl;
		return 0;
	} else {
		cout << s[2] << s[1] << s[0] << endl;
		return 0;
	}
}

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

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a > b){
            System.out.println(a - 1);
        }
        else{
            System.out.println(a);
        }
        //sout
    }


}

Measured memory_bytes: 21844
import sys
from collections import Counter
readline = sys.stdin.buffer.readline


#二項係数(modなし) O(k)
def large_conbination(n,k): #no mod. return nCk.
    res1 = 1
    for i in range(n,n-k,-1):
        res1*=i
    res2 = 1
    for i in range(1,k+1):
        res2*= i
    return res1//res2
n = int(readline())
lst1 = list(map(int,readline().split()))
c = Counter(lst1)

ans = 0
dic1 = dict()
for i,j in c.items():
    res1 = large_conbination(j,2)
    res2 = large_conbination(j-1,2)
    ans += res1
    dic1[i] = (res1,res2)

for i in lst1:
    res12 = dic1[i]
    print(ans-res12[0]+res12[1])

Measured memory_bytes: 80928
#include <stdio.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
int main(void){
  int i,A[5],B[5],C[5],ans=0;
  for(i=0;i<5;i++){
    if(scanf("%d",&A[i])<1)return 1;
    B[i] = (A[i]+9)/10 * 10;
    C[i] = B[i] - A[i];
    ans = MAX(ans,C[i]);
  }
  ans = -ans + B[0] + B[1] + B[2] + B[3] + B[4];
  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 128
import sys
import math
import itertools
import numpy

rl = sys.stdin.readline

r = int(rl())
n1 = tuple(map(int, rl().split()))
n2 = tuple(map(int, rl().split()))
li = list(itertools.permutations(range(1, r+1)))
print(abs(li.index(n1) - li.index(n2)))

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

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

    int h, n;
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        h -= a;
    }
    cout << (h <= 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
mod = 1000000007
ans = pow(2,n,mod) - 1

def solve(nu):
    res = 1
    for i in range(nu):
        res *= n-i
        res %= mod
        res *= pow(i+1,mod-2,mod)
        res%=mod
    return res

ans -=solve(a)
ans %= mod
ans -= solve(b)
ans %= mod

print(ans)

Measured memory_bytes: 38768
#include <iostream>

using namespace std;

int digit_sum(int);

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

    if (N % digit_sum(N)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

int digit_sum(int n) {
    int ret = 0;
    while (n != 0) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>

using namespace std;


int main(){
    int N;
    cin>>N;
    vector<tuple<string,int,int>> vec;

    for (int i = 0; i < N; i++)
    {
        string A;
        int B,C=i+1;
        cin>>A>>B;
        vec.push_back(make_tuple(A,-B,C));
    }
    

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

    for (auto &x : vec)
    {
        cout<<get<2>(x)<<endl;
    }
    
    
}

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

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define FOR(n) for(int i = 0;i < n;i++)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define ipow(x,y) LL(pow(x,y))

//Debug
#define TEST cout << "OK" << endl

const double PI = M_PI;
const long long INF = int(10e9-1);
const long long MOD = int(10e9+7);

//Settings
const bool DO_BENCHMARK = false;
const int DOUBLE_ACCURACY = 15;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t start = clock();
        solve();
        clock_t end = clock();
        const double time = static_cast<double>(end-start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

void solve(){
   GET(N);
   ANS(K,(K==1?0:N-K));
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <bitset>
#include <utility>
#include <queue>

using namespace std;


int main(){

    int H, W;
    cin >> H >> W;

    char field[100][100];    // # :wall, . :way
    int dist[100][100];
    int prev_x[100][100];
    int prev_y[100][100];

    queue<pair<int,int>> que; 
    int x, y;
    
    for(int h=0;h<H;++h){
        for(int w=0;w<W;++w){
            cin >> field[h][w];
            prev_x[h][w] = -1;
            prev_y[h][w] = -1;
            dist[h][w] = -1;
        }
    }

    que.push(make_pair(0,0));
    prev_x[0][0] = -1;
    prev_y[0][0] = -1;
    dist[0][0] = 0;

    // 最短経路を求める
    while(!que.empty()){

        x = que.front().first;
        y = que.front().second;
        que.pop();
        
        // 4方向を探索
        for(int dx=-1;dx<=1;++dx){
            for(int dy=-1;dy<=1;++dy){
                // 斜め移動を省く
                if( (dx + dy) % 2 == 0 ) continue;
                int nx = x + dx, ny = y + dy; 
                // 場外は省く
                if( nx < 0 or nx >= H or ny < 0 or ny >= W )  continue;
                // 壁は除く
                if( field[nx][ny] == '#') continue;
                // 既に行ったところは除く                
                if( dist[nx][ny] != -1 ) continue;
                
                prev_x[nx][ny] = x;
                prev_y[nx][ny] = y;
                dist[nx][ny] = dist[x][y] + 1;
                
                que.push( make_pair(nx, ny));

            }
        }
    }

    if(dist[H-1][W-1] == -1) {
        cout << -1 << endl;
        return 0;
    }
    

    int ans(0);
    for(int h=0;h<H;++h){
        for(int w=0;w<W;++w){
            if(field[h][w]=='.'){
                field[h][w]='#';
                ++ans;
            } 
        }
    }

    x = H-1;
    y = W-1;
    int t;
    
    while(x>=0 and y>=0){
        field[x][y] = '.';
        t = x;
        x = prev_x[t][y];
        y = prev_y[t][y];
    }

    // cout << endl;
    // for(int h=0;h<H;++h){
    //     for(int w=0;w<W;++w){
    //         cout << setw(1) << field[h][w];
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    
    cout << ans - (dist[H-1][W-1]+1) << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int a, b; cin >> a >> b;
	for(int i = 1;i <= 1000;i++){
		if((int)(i*0.08)==a&&(int)(i*0.1)==b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
N, X, Y = list(map(int, input().split(' ')))
X -= 1
Y -= 1
dist_map = {}

def search(origin):
  dist = []
  # X, Yの辺がない場合
  for i in range(N):
    dist.append(abs(origin - i))
  # X, Yの辺がある場合
  if dist[X] < dist[Y]:
    dist[Y] = dist[X] + 1
  elif dist[Y] < dist[X]:
    dist[X] = dist[Y] + 1
  for i in range(N):
    if i - 1 >= 0:
      dist[i] = min(dist[i], dist[i-1]+1)
    if i + 1 < N:
      dist[i] = min(dist[i], dist[i+1]+1)
  for i in reversed(range(N)):
    if i - 1 >= 0:
      dist[i] = min(dist[i], dist[i-1]+1)
    if i + 1 < N:
      dist[i] = min(dist[i], dist[i+1]+1)
  #print(*dist)
  return dist

count = [0 for i in range(N)]
for i in range(N):
  dist = search(i)
  for dis in dist:
    count[dis] += 1

for i in range(1, N):
  print(count[i]//2)

Measured memory_bytes: 52316
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MAX(a, b, c) max(max(a, b), c)
using namespace std;

int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  string s;
  cin >> s;
  s[k-1] = tolower(s[k-1]);
  cout << s << endl;

}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    int ans = max<int>({
        a*10 + b + c,
        b*10 + a + c,
        c*10 + a + b
    });
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

vector<ll> num;

struct Nbase {
    int n;
    int sz = 1;
    long long max = 1e18;

    Nbase(int k = 2){
        n = k;
        while(max != 0){
            max /= n;
            sz++;
        }
        num.resize(sz);
    };

    //繰り返し二乗法
    ll EX(ll x,ll n){
        if(n == 0) return 1;
        else if(n%2 == 1) return EX(x,n-1)*x;
        else return EX(x*x,n/2);
    }

    vector<int> to_n(ll num){
        vector<int> ret(sz);
        for(int i = sz-1; i >= 0; i--){
            long long subtraction = EX(n,i);
            if(subtraction <= num){
                for(int j = 1; j <= n; j++){
                    if(num < j*subtraction){
                        ret[i] = j-1;
                        num -= ret[i]*subtraction;
                    } 
                }
            } else ret[i] = 0;
        }
        return ret;
    }

    long long re_n(vector<int>& vec){
        long long ret = 0;
        vec.resize(sz);
        for(int i = 0; i < sz; i++){
            ret += vec[i]*EX(n,i);
        }
        return ret;
    }

    void supress(const vector<int>& lim,vector<int>& at){
        bool upper = true;
        for(int i = sz; i >= 0; i--){
            if(upper && lim[i] > 0) upper = false;
            if(lim[i] > at[i]) break;
            else if(upper || lim[i] < at[i]) at[i] = lim[i];
            /*if(upper && lim[i] == 1) upper = false;
            if(lim[i] == 1 && at[i] == 0) break;
            else if(lim[i] == 0 || upper) at[i] = 0;*/
        }
    }
};

int main(){
    Nbase base = 2;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        vector<int> sam = base.to_n(a[i]);
        for(int j = 0; j < base.sz; j++){
            if(sam[j] == 1) num[j]++;
        }
    }
    vector<int> x(base.sz);
    for(int i = 0; i < base.sz; i++){
        if(num[i] <= n/2) x[i] = 1;
        else x[i] = 0;
    }
    
    vector<int> kd = base.to_n(k);
    //base.supress(kd,x);
    bool flag = true;
    for(int i = base.sz; i >= 0; i--){
        if(flag && kd[i] == 1) flag = false;
        if(kd[i] == 1 && x[i] == 0) break;
        else if(kd[i] == 0 || flag) x[i] = 0;
    }
    ll X = base.re_n(x);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += X^a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4008
#include<iostream>
using namespace std;
int main(){
    int n,cnt=0,k=0;
    cin>>n;
    int* p = new int[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }

    for(int i=1;i<n-1;i++){
        k=0;
        if(p[i]<p[i-1]){
            if(p[i]>p[i+1]){
                k++;
            }                
        }
        if(p[i]>p[i-1]){
            if(p[i]<p[i+1]){
                k++;
            }  
        }
        if(k==1){
            cnt++;
        }
    }

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

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    input!(
        _n: usize,
        k: usize,
        s: chars,
    );
    let s = s as Vec<char>;
    let mut c = s[0].clone();
    let mut tmp = 0;
    let mut v = Vec::new();
    for i in &s {
        if i != &c {
            v.push(tmp.clone());
            tmp = 0;
            c = i.clone();
        }
        tmp += 1;
    }
    v.push(tmp);

    let c = if s[0] == '0' { 0 } else { 1 };
    let mut l = 0;
    let mut ans = 0;
    let mut tmp = 0;
    let mut mn = 0;
    for i in 0..v.len() {
        tmp += v[i];
        if i % 2 == c {
            l += 1;
        }
        if l > k {
            while i - 2 * k >= mn {
                tmp -= v[mn];
                mn += 1;
            }
            l = k;
        }
        ans = max(ans, tmp);
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
int main(){
int i, K, N, M=0; cin >> K >> N; vector<int> A(N);
for(i=0; i<N; i++){ cin >> A[i]; }
sort(A.begin(), A.end());
for(i=1; i<N; i++){ M=max(M, A[i]-A[i-1]); }
M=max(M, K-A[N-1]+A[0]);
cout << K-M << "\n";
}

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

int main()
{
    int n;
    cin>>n;
    double sum=0;
    while(n--)
    {
        double a;
        string s;
        cin>>a>>s;
        if(s=="JPY")
        {
            sum+=a;
        }
        else
        {
            sum+=(a*380000);
        }
    }
    printf("%.8lf\n",sum);
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int C, D, E;
  C = A+B;
  D = A-B;
  E = A*B;
  if (C >= D && C >= E)
    cout << C << endl;
  else if (D >= C && D >= E)
    cout << D << endl;
  else
    cout << E << endl;
}

Measured memory_bytes: 256
main = do
  li <- getLine
  let [k,n] = map read $ words li
  li <- getLine
  let as = map read $ words li
  let ans = compute k as
  print ans

compute :: Int -> [Int] -> Int
compute k as = k - maximum ds
  where
    ds = zipWith (-) (tail as ++ [k+head as]) as


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

int popcount(int n){
    n = (n & 0x55555555) + (n >> 1 & 0x55555555);
    n = (n & 0x33333333) + (n >> 2 & 0x33333333);
    n = (n & 0x0f0f0f0f) + (n >> 4 & 0x0f0f0f0f);
    n = (n & 0x00ff00ff) + (n >> 8 & 0x00ff00ff);
    return (n & 0x0000ffff) + (n >>16 & 0x0000ffff);
}

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0; i<h; i++){
        cin >> s[i];
    }

    vector<int> dp(1<<w, 0);
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            vector<int> ndp(1<<w, 0);
            for(int bits=0; bits<(1<<w); bits++){
                int pop_total = popcount(bits);
                int pop_prevline = popcount(bits>>j);
                int pop_currline = pop_total -pop_prevline;
                if(i==0 and pop_prevline>0) continue;
                if(i>0 and pop_prevline>(int)s[i-1].length()) continue;
                if(i>0 and j+pop_prevline<(int)s[i-1].length()) continue;
                if(pop_currline > (int)s[i].length()) continue;
                if(i==3 and j==0 and bits==53191){
                }
                // 空白
                if(w-j-1+pop_currline >= (int)s[i].length()){
                    int &next = ndp[bits&~(1<<j)];
                    next = max(next, dp[bits]);
                }
                // 置く
                if(pop_currline+1 <= (int)s[i].length()){
                    int score = 0;
                    char self = s[i][pop_currline];
                    if(i>0 and (bits>>j&1) and self==s[i-1][(int)s[i-1].length()-pop_prevline]){
                        score += 2;
                    }
                    if(j>0 and (bits>>(j-1)&1) and self==s[i][pop_currline-1]){
                        score += 2;
                    }
                    int &next = ndp[bits|(1<<j)];
                    next = max(next, dp[bits]+score);
                }
            }
            swap(dp, ndp);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}



Measured memory_bytes: 3484
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN      
const ll mod=1e9+7;
const int N=1e6+4;
 
int main()                  
{
    ll x,d,k;
    cin>>x>>k>>d;
    
    ll step=abs(x)/d;
    ll rem=abs(x)%d;
    
    ll ans=0;
    if(step>=k)
    {
        ans=(step-k)*d;
        ans+=rem;
    }
    else
    {
        ll cur=k-step;
        if(cur%2==0)
        {
            ans=rem;
        }
        else
        {
            ans=abs(d-rem);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define all(x) begin(x),end(x)
typedef long long ll;
typedef long double ld;
using namespace std;

const vector<int> d4x({1, 0, -1, 0});
const vector<int> d4y({0, -1, 0, 1});

int dfs(vector<vector<int>>& m, int x, int y){
  if(0<=x&&0<=y&&x<m.size()&&y<m[0].size()&&m[x][y]==0){
    m[x][y] = 1;
    for(int range(i,0,4)){
      dfs(m,x+d4x[i],y+d4y[i]);
    }
    return 1;
  }
  return 0;
}
signed main(){
  int n;
  while(cin >> n, n != 0){
    vector<int> l(n), t(n), r(n), b(n);
    for(int range(i,0,n)){
      cin >> l[i] >> t[i] >> r[i] >> b[i];
    }
    set<int> sx, sy;
    for(int range(i,0,n)){
      sx.insert(3*l[i]-1); sx.insert(3*l[i]); sx.insert(3*l[i]+1);
      sy.insert(3*t[i]-1); sy.insert(3*t[i]); sy.insert(3*t[i]+1);
      sx.insert(3*r[i]-1); sx.insert(3*r[i]); sx.insert(3*r[i]+1);
      sy.insert(3*b[i]-1); sy.insert(3*b[i]); sy.insert(3*b[i]+1);
    }

    vector<int> vx(all(sx)), vy(all(sy));
    vector<vector<int>> m(vx.size(), vector<int>(vy.size(), 0));
    
    for(int range(i,0,n)){
      const int ll = lower_bound(all(vx),3*l[i]) - vx.begin();
      const int tt = lower_bound(all(vy),3*t[i]) - vy.begin();
      const int rr = lower_bound(all(vx),3*r[i]) - vx.begin();
      const int bb = lower_bound(all(vy),3*b[i]) - vy.begin();

      for(int range(x,min(ll,rr),max(ll,rr)+1)){
        m[x][tt] = 1;
        m[x][bb] = 1;
      }
      for(int range(y,min(tt,bb),max(tt,bb)+1)){
        m[ll][y] = 1;
        m[rr][y] = 1;
      }
    }
/*     for(int range(x,0,vx.size())){
      for(int range(y,0,vy.size())){
        cout<<m[x][y];
      }
      cout<<endl;
    } */
    int res = 0;
    for(int range(x,0,vx.size())){
      for(int range(y,0,vy.size())){
        res += dfs(m, x, y);
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 7764
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

bool isOK(int mid,ll maxsize,vector<ll> &a){
	ll nowsize = a[mid];
	for(int i=0;i<a.size();i++){
		if(i==mid)continue;
		if(nowsize*2 >= a[i]){
			nowsize += a[i];
		}else break;
	}
	if(nowsize == maxsize)return 1;
	else return 0;
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<ll> a(N);
	ll maxsize = 0;
	for(int i=0;i<N;i++){
		cin >> a[i];
		maxsize += a[i];
	}
	sort(ALL(a));
	int ok = N;
	int ng = -1;
	while(abs(ok-ng)>1){
		int mid = (ok+ng)/2;
		if(isOK(mid,maxsize,a))ok = mid;
		else ng = mid;
	}
	cout << N - ok << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c,d) << endl;
    return 0;
}


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int N, r;
	int result;
	cin >> N;
	if (N / 10 == 0) {
		r = N;
	} else {
		r = N % 10;
	}
	if (r == 3) {
		cout << "bon" << "\n";
	} else if (r == 0 || r == 1 || r == 6 || r == 8 ) {
		cout << "pon" << "\n";
	} else {
		cout << "hon" << "\n";
	}
	return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(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 VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll K, N;
vector<PL> sushi;
priority_queue<PL, vector<PL>, greater<PL>> sp;
map<ll, ll> sk;

int main() {
    cin >> N >> K;
    sushi.resize(N);
    REP(i, N) {
        CINT(t, d);
        sushi[i] = {d, t};
    }
    sort(All(sushi), greater<PL>());
    ll sum = 0;
    REP(i, K) {
        if(sk[sushi[i].second]++ > 0) sp.push(sushi[i]);
        sum += sushi[i].first;
    }
    ll nowk = sk.size();
    ll ans = sum + nowk * nowk;
    FOR(i, K, N) {
        if(sp.empty()) break;
        if(sk[sushi[i].second] == 0) {
            auto s = sp.top();
            sum -= s.first;
            sk[s.second]--;
            sp.pop();
            sk[sushi[i].second]++;
            sum += sushi[i].first;
            nowk++;
            ans = max(ans, sum + nowk * nowk);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6648
#include<iostream>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 99999999

using namespace std;

int main(void) {
	int x1, x2;
	cin >> x1 >> x2;
	if(x2>x1)cout << x2 - x1 << endl;
	else cout << x1 - x2 << endl;
	return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is >> *i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int sum[101];
signed main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    REPF(i,a,b) sum[i]++;
    REPF(i,c,d) sum[i]++;
    int ans=0;
    REP(i,101) {
        if(sum[i]==2) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int n;
  double x,count = 0.0;
  string u;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> x >> u;
    if(u == "JPY"){
      count += x;
    }else{
      count += x * 380000;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
class UnionFind():
    n=1
    par=[0]
    rnk=[0]
    def __init__(self,size):
        self.n=size
        self.par=[i for i in range(self.n)]
        self.rnk=[0 for i in range(self.n)]
    def find(self,vertex1):
        if self.par[vertex1]==vertex1:
            return vertex1
        else:
            self.par[vertex1]=self.find(self.par[vertex1])
            return self.par[vertex1]
    def unite(self,vertex1,vertex2):
        vertex1=self.find(vertex1)
        vertex2=self.find(vertex2)
        if vertex1==vertex2:
            return
        if (self.rnk[vertex1]<self.rnk[vertex2]):
            self.par[vertex1]=vertex2
        else:
            self.par[vertex2]=vertex1
            if(self.rnk[vertex1]==self.rnk[vertex2]):
                self.rnk[vertex1]+=1
    def same(self,vetrex1,vertex2):
        return self.find(vetrex1)==self.find(vertex2)

N,M=map(int,input().split())
A=[0 for i in range(M)]
B=[0 for i in range(M)]
for i in range(M):
    A[i],B[i]=map(int,input().split())
    A[i]-=1;B[i]-=1
G=UnionFind(N)
D=dict()
for i in range(N):
    D[i]=1
ans=[(N*(N-1))//2]
for i in range(M)[::-1]:
    #print([G.find(i) for i in range(N)],A[i],B[i],D,ans[-1])
    a=G.find(A[i])
    b=G.find(B[i])
    G.unite(A[i],B[i])
    x=G.find(A[i])
    if a!=b:
        ans.append(ans[-1]-D[a]*D[b])
        if x==a:
            D[a],D[b]=D[a]+D[b],0
        else:
            D[a],D[b]=0,D[a]+D[b]
    else:
        ans.append(ans[-1])
for line in ans[:-1][::-1]:
    print(line)

Measured memory_bytes: 28456
N, D = map(int, input().split())
X = [[int(i) for i in input().split()] for j in range(N)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        x = [0 for i in range(D)]  
        for k in range(D):
            x[k] = (X[i][k] - X[j][k]) ** 2
        d = sum(x) ** (1/2)
        if d == int(d):
            count += 1

print(count)

Measured memory_bytes: 3188