akhauriyash/Code-Regression huggingface dataset:
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Solve() {
  NM := NextIntVec()
  N, M := NM[0], NM[1]
  V := make([]int, N)
  G := make([][]int, N)
  for i := range G {
    G[i] = make([]int, 0)
  }
  S := NextLine()
  for i, s := range S {
    V[i] = int(s - rune('A'))
  }
  D := make([][]int, N)
  for i := range D {
    D[i] = make([]int, 2)
  }
  for i := 0; i < M; i++ {
    AB := NextIntVec()
    a, b := AB[0] - 1, AB[1] - 1
    G[a] = append(G[a], b)
    G[b] = append(G[b], a)
    D[a][V[b]]++
    D[b][V[a]]++
  }
  Q := make([]int, 0)
  for i, d := range D {
    if d[0] < 1 || d[1] < 1 {
      Q = append(Q, i)
    }
  }
  for 0 < len(Q) {
    q := Q[0]
    Q = Q[1:]
    for _, adj := range G[q] {
      if D[adj][0] < 1 || D[adj][1] < 1 { continue }
      D[adj][V[q]]--
      if D[adj][V[q]] < 1 { Q = append(Q, adj) }
    }
  }
  for _, d := range D {
    if 0 < d[0] && 0 < d[1] {
      Write("Yes")
      return
    }
  }
  Write("No")
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 34048
def main():
  row_num,col_num=map(int, input().split())  
  table=list()

  for i in range(row_num):
    row = list(map(int, input().split()))
    table.append(row)

    row_sum = 0
    for num in table[i]:
      row_sum += num
    table[i].append(row_sum)

  col_sum = list()
  for i in range(col_num):
    col = 0
    for j in range(row_num):
      col += table[j][i]
    col_sum.append(col)
  
  all_sum = 0
  for i in col_sum:
    all_sum += i
  col_sum.append(all_sum)
  table.append(col_sum)
  
  for row in table:
    print(*row)

if __name__ == '__main__':
  main()


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

const int MOD = 1e9 + 7;

void update(int& x, int a)
{
  x += a;
  if (x >= MOD) {
    x -= MOD;
  }
}

int solve(int n, int m, const std::string& s)
{
  bool has_b = false;
  int max_len = -1;
  for (int i = 0, len = 0; i < m; ++ i) {
    if (i && s[i - 1] != s[i]) {
      if (s[i - 1] == s[0]) {
        if (max_len == -1) {
          max_len = len + 1;
        } else if (len & 1) {
          max_len = std::min(max_len, len + 1);
        }
      }
      // printf("%c %d\n", s[i - 1], len);
      len = 0;
    }
    has_b |= s[i] != s[0];
    len ++;
  }
  std::vector<int> dp(n);
  dp[0] = 1;
  if (has_b) {
    // <=> has A + has B + no consecutive B + len <= max_len
    for (int i = 2, j = 0, sum = 0; i < n; i += 2) {
      update(sum, dp[i - 2]);
      if (i - j > max_len + 1) {
        update(sum, MOD - dp[j]);
        j += 2;
      }
      dp[i] = sum;
    }
    int result = 0;
    for (int len = 2; len <= n && len - 1 <= max_len; len += 2) {
      update(result, 1LL * len * dp[n - len] % MOD);
    }
    return result;
  } else {
    // AA...A <=> has A + no consecutive B
    for (int i = 1, sum = 0; i < n; ++ i) {
      if (i >= 2) {
        update(sum, dp[i - 2]);
      }
      dp[i] = sum;
    }
    int result = 1; // no B
    for (int len = 2; len <= n; ++ len) {
      update(result, 1LL * len * dp[n - len] % MOD);
    }
    return result;
  }
}

int main()
{
  int n, m;
  while (std::cin >> n >> m) {
    std::string s;
    std::cin >> s;
    std::cout << solve(n, m, s) << std::endl;
  }
}


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

int main() {
  int N; cin >> N;
  vector<int> C(N), V(N);
  rep(i,N) cin >> V[i];
  rep(i,N) cin >> C[i];
  int ans=0;
  rep(i,N) {
    int diff = V[i] - C[i];
    if(diff > 0) ans += diff;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, x;
	cin >> a >> b >> x;
	if (x >= a && x < a + b)
		cout << "YES" << "\n";
	else
		cout << "NO" << "\n";
}

Measured memory_bytes: 3544
n, m = map(int, input().split())
a = list(map(int, input().split()))

c = [0] * 8

mt = set()
for aa in a:
    if aa == 1:
        c[2] = 1
        mt.add(2)
    if aa == 2:
        c[5] = max(c[5], 2)
        mt.add(5)
    if aa == 3:
        c[5] = max(c[5], 3)
        mt.add(5)
    if aa == 4:
        c[4] = 4
        mt.add(4)
    if aa == 5:
        c[5] = max(c[5], 5)
        mt.add(5)
    if aa == 6:
        c[6] = max(c[6], 6)
        mt.add(6)
    if aa == 7:
        c[3] = 7
        mt.add(3)
    if aa == 8:
        c[7] = 8
        mt.add(7)
    if aa == 9:
        c[6] = max(c[6], 9)
        mt.add(6)
dp = [-1] * (n+1)
dp[0] = 0
for i in range(n+1):
    tmp = [dp[i]]
    for mtt in mt:
        if i-mtt>= 0 and dp[i-mtt] >= 0:
            tmp.append(dp[i-mtt]*10+c[mtt])
    dp[i] = max(tmp)
print(dp[n])

Measured memory_bytes: 51932
/*
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
ordered_set -> less -> less_equal
ordered_set find_by_order() -> возвращает k-ый элемент(отсчёт с нуля)
ordered_set order_of_key() -> возвращает количество элементов в множестве,строго меньших,чем наш элемент
*/
#include <bits/stdc++.h>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;
using namespace __gnu_pbds;

template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int> > matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=(1ll<<61)-1;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
ll a[maxn];

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll k,n;
    cin>>k>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(i>=2){
            sum+=(a[i]-a[i-1]);
        }
    }
    ll ans=linf;
    ans=min(ans,sum);
    for(int i=2;i<=n;i++){
        ans=min(ans,sum-(a[i]-a[i-1])+a[1]+(k-a[n]));
    }
    cout<<ans;
	exit(0);
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())

int main() {
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int>a(n);
	for (auto &x : a)cin >> x;
	list<int>b;
	if (n % 2 == 0) {
		rep(i, n) {
			b.push_back(a[i]);
			if (i != n - 1) {
				i++;
				b.push_front(a[i]);
			}
		}
	}
	else {
		rep(i, n) {
			b.push_front(a[i]);
			if (i != n - 1) {
				i++;
				b.push_back(a[i]);
			}
		}
	}
		for (auto x : b)cout << x << " ";
		cout << endl;
	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll cnt=0;
    rep(i,n){
        while(a[i] %2 == 0){
            a[i] /= 2;
            cnt++;
        }
    }
    cout << cnt <<endl;
    return 0;
}

Measured memory_bytes: 384
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll dp[12][2][12][2];
ll digit(ll inx,ll tem,ll pre,ll st,vector<ll> &v){
	if(inx==-1)return 1;
	if(dp[inx][tem][pre][st]!=-1&&tem==0)
	return dp[inx][tem][pre][st];
	ll r,res=0;
	r=(tem==1?v[inx]:9);
	for(ll i=0;i<=r;i++){
		ll ntem=(i==v[inx]?tem:0);
		if(st==1){
			if(i==0)
			res+=digit(inx-1,ntem,i,1,v);
			else
			res+=digit(inx-1,ntem,i,0,v);
		}
		else if(st==0&&abs(pre-i)<=1){
			res+=digit(inx-1,ntem,i,0,v);
		}
	}
	if(!tem)dp[inx][tem][pre][st]=res;
	return res;
}
ll fun(ll x){
	vi v;
	while(x>0){
		v.push_back(x%10);
		x/=10;
	}
	return  digit(v.size()-1,1,0,1,v);
}
int main(){
	memset(dp,-1,sizeof(dp));
	ll k;cin>>k;
	k++;
	ll s=0,e=1e11,mid,ans=1e12;
	while(s<=e){
		mid=(s+e)/2;
		ll z=fun(mid);

		if(z<k)s=mid+1;
		else{
			if(z==k)ans=min(ans,mid);
			e=mid-1;
		}
	}
	cout<<ans<<endl;
}



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

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int A,B,C;
	cin>>A>>B>>C;
	
	if((A-B)<=C)cout<<C-(A-B);
	
	else cout<<0;
		
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 1e5 + 5;
const long long inf = 1e14 + 5;
int n,v[maxn];
long long c, ans,x[maxn];
long long dp[2][maxn], m[2][maxn];
int main(){
    scanf("%d %lld",&n, &c);
    for(int i = 0; i < n; i++){
        scanf("%lld %d",&x[i],&v[i]);
    }
    for(int i = 0; i < n; i++) dp[0][i] = dp[1][i] = -inf;//初始化
    long long sum = 0;
    for(int i = 0; i < n; i++){
        sum += v[i];
        dp[0][i] = max(dp[0][i - 1], sum - x[i]);//走或不走这个点
        m[0][i] = sum - 2 * x[i];//走回去自然是两倍
    }
    sum = 0;//置为0
    for(int i = n - 1; i >= 0; i--){//反着来
        sum += v[i];
        dp[1][i] = max(dp[1][i + 1], sum - (c - x[i]));
        m[1][i] = sum - 2 * (c - x[i]);
    }
    ans = max(dp[0][n-1], dp[1][0]);//正着走到n-1和反着走到0的最大值
    for(int i = 0; i < n; i++){
        ans = max(ans, m[0][i] + dp[1][i + 1]);//反着走中途倒回去
        ans = max(ans, m[1][n - i] + dp[0][n - i - 1]);//正着走中途倒回去
    }
    if(ans != 0)
        printf("%lld\n",ans);
    else
        printf("0\n");
return 0;
}


Measured memory_bytes: 8128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class program{
    public static void Main(){
        var str = Console.ReadLine();
        var q = int.Parse(Console.ReadLine());
        for(int i=0; i<q; i++){
            var command = Console.ReadLine().Split();
            var a = int.Parse(command[1]);
            var b = int.Parse(command[2]);
            if(command[0] == "print") print(str,a,b);
            if(command[0] == "reverse") str = reverse(str,a,b);
            if(command[0] == "replace") str = replace(str,a,b,command[3]);
        }
    }

    public static void print(string str, int a, int b){
        Console.WriteLine(str.Substring(a, b-a+1));
    }

    public static string reverse(string str, int a, int b){
        var revstr = new String(str.Substring(a,b-a+1).Reverse().ToArray());
        var af = a==0 ? "" : str.Substring(0, a);
        var sf = b==str.Length-1 ? "" : str.Substring(b+1);
        return af + revstr + sf;
    }

    public static string replace(string str, int a, int b, string p){
        return str.Remove(a,b-a+1).Insert(a,p);
    }
}



Measured memory_bytes: 18296
# -*- coding: utf-8 -*-       
import numpy as np
connected = 0

def dfs(graph, start, v, visited=None):
    if(visited==None):  visited = []
    visited.append(start)    
    if(len(visited)==v):
        global connected
        connected += 1
        return
    for Next in graph[start]:  
        if ( Next in visited ):  continue
        dfs(graph, Next, v, visited)
    return


v, e = map(int, input().split())
graph = np.zeros((e,2)).astype('uint16')

for i in range(e):
    graph[i] = list(map(int, input().split()))

lw = [[] for i in range(v)]
for path in graph:
    lw[path[0]-1].append(path[1]-1)
    lw[path[1]-1].append(path[0]-1)

for path in graph:
    lw[path[0]-1].remove(path[1]-1)
    lw[path[1]-1].remove(path[0]-1)
    dfs(lw,0,v)
    lw[path[0]-1].append(path[1]-1)
    lw[path[1]-1].append(path[0]-1)
print(e-connected)

Measured memory_bytes: 14452
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define mit(a,b) map<a,b>::iterator
#define sit(a) set<a>::iterator
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define printf __mingw_printf
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define MX 100005
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
ll dp[MX],a[MX],n,k,oo=(1ll<<62);
ll abs(ll a,ll b)
{
    return (a>b)?a-b:b-a;
}
int main()
{
     io;
    //string hudai(1000000,'a');
    int T=1;
    //T=gi();
     for(int cas=1;cas<=T;cas++)
    {
        ll i,j;
       n=gi();k=gi();
       for(i=1;i<=n;i++){a[i]=gi();if(i<n-k)dp[i]=oo;}
       for(i=max(n-k,0LL);i<=n;i++){dp[i]= abs(a[n],a[i]) ;}
        for(i=n-k-1;i>0;i--)
        {
            for(j=i+1;j<=i+k;j++){dp[i]=min(dp[i],dp[j]+ abs(a[j],a[i]) );}
        }
        cout<<dp[1];

    }
    return 0;
}


Measured memory_bytes: 5228
import java.util.*

fun f(a: List<Long>): Array<Long> {
    val res = Array(a.size) { 0L }
    val stack = ArrayDeque<Pair<Long, Int>>()

    stack.push(Pair(0L, -1))
    for (i in a.indices) {
        while (stack.peek().first > a[i]) {
            stack.pop()
        }
        res[i] = i - stack.peek().second.toLong()
        stack.push(Pair(a[i], i))
    }

    return res
}

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }.toMutableList()

    val ll = f(a)
    Collections.reverse(a)
    val rl = f(a).toMutableList()
    Collections.reverse(rl)
    Collections.reverse(a)

    var res = 0L
    for (i in a.indices) {
        res += ll[i] * rl[i] * a[i]
    }

    println(res)
}


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

int main(){
  while(1){
    int H,W;
    cin >> H >> W;
    if(H==0 && W==0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cout << "#";
      }
      cout << endl;
    }
   cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1152
# A - ∴ (Therefore)
def main():
    N = int(input())
    if N % 10 in {2, 4, 5, 7, 9}:
        print("hon")
    elif N % 10 in {0, 1, 6, 8}:
        print("pon")
    else:
        print("bon")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
#include<stdio.h>

int main()
{
	int a, b;
	while(scanf("%d %d", &a, &b) != EOF)
	{
		int digit = 1;
		int result = a + b;
		while(result >= 10)
		{
			result/=10;
			digit++;
		}
		printf("%d\n", digit);
	}

	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>

int main() {
  int i,j,N,key;
  scanf("%d", &N);
  int A[N];
  for(i = 0;i < N;i++) {
    scanf("%d", A+i);
    if(i != N-1) {
      printf("%d ", A[i]);
    }else{
      printf("%d\n", A[i]);
    }
  }
  for(i = 1;i < N;i++) {
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    for(j = 0;j < N;j++) {
      if(j != N-1) {
	printf("%d ", A[j]);
      }else{
	  printf("%d\n", A[j]);
      }
      
    }
  }

  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

int main(){
  int i,j;
  string s;
  cin>>s;
  for(i=0;i<s.size();i++){
    cout<<'x';
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};

int main(){
    int N, M; cin >> N >> M;
    UnionFind uni(N);

    for(int i=0; i<M; ++i){
        int x, y, z; cin >> x >> y >> z;
        --x; --y;
        uni.connect(x, y);
    }

    vector<bool> flg(N, false);
    for(int i=0; i<N; ++i){
        flg[uni.root(i)] = true;
    }

    int ans = 0;
    for(int i=0; i<N; ++i) if(flg[i]) ++ans;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
import math
n = int(input())
m = math.floor(math.sqrt(n)) + 1
ans = 10**12

for a in range(1,m+1):
    b = n/a
    if b.is_integer():
        move = a+b-2
    else:
        continue
    ans = min(ans,move)
print(int(ans))

Measured memory_bytes: 9100
import bisect

N = int(input())

lst = [1]
for i in range(2, 31+1):
  var = i ** 2
  while True:
    if var <= 1000:
      lst.append(var)
      var *= i
    else:
      break

lst = list(set(lst)) 
lst.sort()
#print(lst)
idx = bisect.bisect_right(lst, N)
#print(idx)
print(lst[idx-1])

Measured memory_bytes: 3060
//Author:- Yatin Patel
//Mail:- yatinpatel.gt@gmail.com

#include <bits/stdc++.h>
#define FILEIN ifstream fin;fin.open("input.txt");
#define FILEOUT ofstream fout;fout.open("output.txt");

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

#define FAST ios::sync_with_stdio(false);ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define MOD 1000000007
#define INF LONG_MAX
#define MINF LONG_MIN

ll power(ll x, unsigned ll y){
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

//#define fin cin
//#define fout cout

int main(){

    FAST;
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    for(ll i=0;i<n;i++){
        cin>>v[i];
    }
    vector<ll> dp(n+k+2,INF);
    dp[0] = 0;
    for(ll i=0;i<n;i++){
        for(ll j=1;j<=k;j++){
            dp[j+i] = min(dp[j+i],dp[i]+abs(v[j+i]-v[i]));
        }
    }
    cout<<dp[n-1];
    return 0;
}






Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 3 * 1000 + 47;
const double EPS = 1e-8;
const int MOD = 1000 * 1000 * 1000 + 7;



int DP[MAX][MAX][2];

void add(int & x, int y)
{
    x += y;
    if (x >= MOD) x -= MOD;
}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    FOR(i, 0, n+1)DP[0][i][i==0] = 1;
    
    FOR(i, 0, m)
        FOR(j, 0, n+1)
            FOR(k, 0, 2)
    {
        if (!DP[i][j][k])continue;
        
        if (j)
        {
            add(DP[i+1][j-1][k || j == 1], DP[i][j][k]);
            add(DP[i+1][j][k || j == 1], DP[i][j][k]);
        }
        
        if (j < n)
        {
            add(DP[i+1][j+1][k], DP[i][j][k]);
            add(DP[i+1][j][k], DP[i][j][k]);
        }
        
    }
    int ans = 0;
    FOR(i, 0, n+1)add(ans, DP[m][i][1]);
    cout << ans << endl;
    
}
    
    


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

int fun(int x)
{
 
 int ans=0 ;
 int a = floor(x/500);
 ans+= (a*1000);
 x =  x -(a*500);
 
 int b = floor(x/5);
 ans +=  (b*5);
 
 return ans;
    
}

int main()
{
    int x  ;
    cin>>x;
    int ans=  fun(x);
    cout<<ans<<endl;
}



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

int main() {
  int a,b,c,d; cin >> a >> b >> c >>d;
  int y = d-b;
  int x = c-a;

  cout << c - y << " " << d + x << " " << a - y << " " << b + x << endl;
}

Measured memory_bytes: 256
#include <cstdio>

const int MOD = 1e9+7;
const int MAXN = 21;

bool solved[MAXN][1 << MAXN];
int mem[MAXN][1 << MAXN];
int n;
int a[MAXN][MAXN];


int dp(int x, int mask) {
  if (x == n) return 1;

  int &ret = mem[x][mask];
  if (solved[x][mask]) return ret;
  solved[x][mask] = 1;

  for (int i = 0; i < n; ++i) {
    if ((mask >> i) & 1) continue;
    if (a[x][i] == 0) continue;
    ret = (ret + dp(x+1, mask | (1 << i))) % MOD;
  }

  return ret;
}

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

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


Measured memory_bytes: 203008
import copy

N = int(input())
w  = [['a']]
for n in range(1,N):
    nw = [[] for _ in range(n+1)]
    for i in range(n):
        nw[i] += [x+chr(97+j) for j in range(i+1) for x in w[i]]
        nw[i+1] += [x+chr(97+i+1) for x in w[i]]
    w = copy.deepcopy(nw)

ans = []
for i in range(N):
    ans += [x for x in w[i]]
for x in sorted(ans):
    print(x)

Measured memory_bytes: 16628
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;

class MathLib{
    public static long floor_sum(long n, long m, long a, long b){
        long ans = 0;
        if(a >= m){
            ans += (n-1) * n * (a/m) / 2;
            a %= m;
        }
        if(b >= m){
            ans += n * (b/m);
            b %= m;
        }

        long y_max = (a*n+b) / m;
        long x_max = y_max * m - b;
        if(y_max == 0) return ans;
        ans += (n - (x_max+a-1)/a) * y_max;
        ans += floor_sum(y_max, a, m, (a-x_max%a)%a);
        return ans;
    }
}

public class Main {
    public static long digit(long ans, int i){
		if (ans<i) return ans;
		else return (ans%i)+digit(ans/i,i);
	}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int t=0; t<T; t++){
            long N = sc.nextLong();
            long M = sc.nextLong();
            long A = sc.nextLong();
            long B = sc.nextLong();
            System.out.println(MathLib.floor_sum(N, M, A, B));
        }
    }
}

Measured memory_bytes: 58896
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;

struct WarshallFloyd{
  void solve(const VV<P<int, ll>> &G, VV<ll> &v){
    int n = G.size();
    v.assign(n, V<ll>(n, LINF));
    FOR(i, 0, n){
      for(pair<int, ll> p:G[i]) v[i][p.first] = p.second;
      v[i][i] = 0;
    }
    FOR(k, 0, n)FOR(i, 0, n)FOR(j, 0, n) v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
  }
} wf;
int n, m, l, q;
VV<P<int, ll>> e;
VV<ll> v;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> l;
  e.assign(n, V<P<int, ll>>());
  FOR(i, 0, m){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    e[a].pb({b, c});
    e[b].pb({a, c});
  }
  wf.solve(e, v);
  e.assign(n, V<P<int, ll>>());
  FOR(i, 0, n) FOR(j, 0, i) if(v[i][j] <= l) e[i].pb({j, 1}), e[j].pb({i, 1});
  wf.solve(e, v);
  cin >> q;
  FOR(_, 0, q){
    int s, t;
    cin >> s >> t;
    s--; t--;
    cout << (v[s][t]==LINF ? -1 : (v[s][t]-1)) << endl;
  }
}

Measured memory_bytes: 3584
import sys
import numpy as np


def main():
    MOD = int(1e9 + 7)

    n, k = map(int, input().split())
    can = [[int(c) for c in input().split()] for _ in range(n)]
    #can = np.matrix(can, 'O')

    can = np.array(can, 'O')

    # b = np.eye(n, n, 0, 'O')
    # while k:
    #     b = [b, b*can % MOD][k & 1]
    #     can = can*can % MOD
    #     k >>= 1

    # print(b.sum() % MOD)

    answer = np.eye(n, dtype=object)
    while k:
        if k % 2:
            answer = np.dot(answer, can) % MOD
        can = np.dot(can, can) % MOD
        k //= 2

    total = 0
    for i in range(n):
        for j in range(n):
            total += answer[i,j]
            if total >= MOD:
                total -= MOD

    print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14564
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce

# random variable is all you need


def score(D, C, S, T):
    last = [-1] * 26
    # scores = [0]
    score = 0
    for d in range(D):
        # scores.append(scores[-1] + S[d][T[d]])
        score += S[d][T[d]]
        last[T[d]] = d
        for i in range(26):
            # scores[-1] -= C[i] * (d - last[i])
            score -= C[i] * (d - last[i])
    return score


from random import choices

D = a_int()
C = ints()
S = read_tuple(D)

candi = list(range(26))

T = choices(candi, k=D)
# print(score(D, C, S, T))

print(*mina(*T, sub=-1), sep='\n')


Measured memory_bytes: 78048
#include <stdlib.h>
#include <stdio.h>

#define NODE_TYPE(node, type)           \
  do {                                  \
    if (node.parent == -1) {            \
      type = "root";                    \
    } else if (node.children == NULL) { \
      type = "leaf";                    \
    } else {                            \
      type = "internal node";           \
    }                                   \
  } while (0)

typedef struct { int id, parent, *children, size; } node;

static int count_depth(node *nodes, int id) {
  int depth;

  for (depth = -1; id > -1; ++depth) id = nodes[id].parent;
  return depth;
}

int main(int argc, char **argv) {
  int n, i, j, id, k, depth;
  node *nodes;
  char *type;

  scanf("%d", &n);
  nodes = (node *) malloc(sizeof(node) * n);
  for (i = 0; i < n; ++i) {
    nodes[i].parent = -1;
    nodes[i].children = NULL;
  }
  for (i = 0; i < n; ++i) {
    scanf("%d %d", &id, &k);
    nodes[id].id = id;
    nodes[id].size = k;
    if (k == 0) continue;
    nodes[id].children = (int *) malloc(sizeof(int) * k);
    for (j = 0; j < k; ++j) {
      scanf("%d", &nodes[id].children[j]);
      nodes[nodes[id].children[j]].parent = id;
    }
  }
  for (i = 0; i < n; ++i) {
    NODE_TYPE(nodes[i], type);
    depth = count_depth(nodes, i);
    printf("node %d: parent = %d, depth = %d, %s, [",
        nodes[i].id, nodes[i].parent, depth, type);
    for (j = 0; j < nodes[i].size; ++j) {
      if (j > 0) printf(", ");
      printf("%d", nodes[i].children[j]);
    }
    printf("]\n");
  }
  for (i = 0; i < n; ++i) free(nodes[i].children);
  free(nodes);
  exit(0);
}


Measured memory_bytes: 4192
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    W, H, x, y = LI()
    s = W * H * 0.5
    d = 1 if (x == W / 2.0 and y == H / 2.0) else 0
    print(s, d)
    return

main()

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

using namespace std;

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> D(k + 1, 0);
	vector<int> a(n, 0);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (a[j] <= i && !D[i - a[j]]) {
				D[i] = 1;
				break;
			}
		}
	}
	printf("%s\n", D[k] == 1 ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:https://arc086.contest.atcoder.jp/tasks/arc086_b>
 問題文============================================================
 すぬけ君は長さ N の数列 a を持っています。a の (1-indexedでの) i 番目の数は ai です。
 
 すぬけ君は以下の操作を何度でも行うことができます。
 
 操作：1 以上 N 以下の整数 x,y を選び、ay に ax を加算する。
 すぬけ君はこの操作を 0 回以上 2N 回以下行って a が下記の条件を満たすようにしたいです。
 そのような操作手順の一例を示してください。
 なお、この問題の制約下で、条件を満たすような操作の手順が必ず存在することが証明できます。
 
 条件：a1≤a2≤…≤aN
 制約
 2≤N≤50
 −10^6≤ai≤10^6
 与えられる入力は全て整数
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> a(N);
    for(auto &in:a) cin >> in;
    ll Max_Idx = max_element(a.begin(), a.end()) - a.begin();
    vector<pll> ans;
    vector<ll> T = a;
    bool f = true;
    for(int i = 0; i < N;i++){
        T[i] += T[Max_Idx];
        if(T[i] < 0){
            f = false; break;
        }
        ans.push_back({Max_Idx,i});
    }
    if(f){
        cout << 2*N - 1 << endl;
        for(auto p:ans){
            cout << p.first +1 << " " << p.second + 1 << endl;
        }
        for(int i = 1; i < N; i++){
            cout << i << " " << i + 1 << endl;
        }
        return 0;
    }
    ans.clear();
    T = a;
    ll Min_Idx = min_element(a.begin(), a.end()) - a.begin();
    cout << 2*N - 1 << endl;
    for(int i = 1; i <= N; i++){
        cout << Min_Idx + 1 << " " << i << endl;
    }
    for(int i = N; i > 1; i--){
        cout << i << " " << i-1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int fibonacci(int);
int F[45];

int main(){
  int i,n;

  for(i=0;i<45;i++) F[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fibonacci(n));

  return 0;
}

int fibonacci(int n){
  
  if(n==0||n==1) return F[n]=1;
  if(F[n]!=-1) return F[n];
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>l(n);
	int ma = 0;
	int sum = 0;
	rep(i, n) {
		cin >> l[i];
		sum += l[i];
		ma = max(l[i], ma);
	}
	sum -= ma;
	if (ma < sum)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

int main()
{
    ll N;
    cin >> N;
    map<ll, ll> mp;

    for (ll i = 0; i < N; i++)
    {
        ll ai;
        cin >> ai;
        mp[ai] += 1;
    }

    map<ll, ll> nmp;
    for (auto &&e : mp)
    {
        if (nmp[e.first] > 1) {
            continue;
        }

        if (e.second > 1) {
            nmp[e.first] = INT_MAX;
        } else if (e.second == 1) {
            nmp[e.first] = 1;
        }

        for (ll i = 2; i <= 1e6; i++)
        {
            if (i * e.first > 1e6)
            {
                break;
            }
            nmp[i * e.first] = INT_MAX;
        }
    }
    ll cnt = 0;
    for (auto &&e : nmp)
    {
        if (e.second == 1) {
            cnt += 1;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 78476
#include<iostream>
#include<algorithm>

int run(){
	int a, b, c;
	std::cin >> a >> b >> c;
	if( b-a == c-b ){ return 1; }
	return 0;
}

int main(){
	std::cout << (run()?"YES":"NO") << std::endl;
	return 0;
}


Measured memory_bytes: 256
/*
 *  Created on: 21 / 6 / 2020
 *  Author:     Eslam Waheed
 */

#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO

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

#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)
#define test(t)      while(t--)

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e9 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
        ll n; cin >> n;
    map<ll, ll>mp;
    vector<ll>v(n);
    ll sum = 0;
    for (auto& it : v)
    {
        cin >> it;
        mp[it]++;
        sum += it;
    }
    ll q; cin >> q;
    while (q--)
    {
        ll a, b; cin >> a >> b;
        if (mp[a])
        {
            ll x = a * mp[a];
            ll y = b * mp[a];
            sum -= x;
            sum += y;
            mp[b] += mp[a];
            mp.erase(a);
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 8148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    String s1;
    String s2;
    String s3;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.s1 = sc.next();
        this.s2 = sc.next();
        this.s3 = sc.next();
    }
    
    //解答処理
    private String solve() {
    	char S1 = s1.toUpperCase().charAt(0);
    	char S2 = s2.toUpperCase().charAt(0);
    	char S3 = s3.toUpperCase().charAt(0);
        String answer = String.valueOf(S1) + String.valueOf(S2) + String.valueOf(S3);
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 38852
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

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

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}

int gcd (int a, int b) {
    while (b > 0) {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

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

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for (int i = 6; n; i += 5) {
        if (is_prime(i)) {
            cout << i << " "; n--;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
function main(lines) {
  const N = lines[0];

  let res;

  if ( /[24579]$/.test(N) ) res = 'hon';
  else if ( /[0168]$/.test(N) ) res = 'pon';
  else if ( /[3]$/.test(N) ) res = 'bon';

  console.log(res);
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}

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


int main ()
{
long long N;
scanf ("%lld",&N);
long long a = N+0;
long long sum=0 ,num;
while(a>0){
  num = a % 10;
  sum = sum + num;
  a = a / 10;
}
string c;
c = to_string(N);
int d = c.length();
int e = c[0] - '0';
long long f = e-1 + 9*(d-1);
std::cout << max(sum,f) << '\n';
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[1000001];
int calc(int n)
{
  if(n==1) return 0;
  if(a[n] != 0) return a[n];
  a[n] = ((n % 2) == 0 ? calc(n/2) : calc(3*n+1));
  a[n]++;
  return a[n];
}
int main()
{
  int n;
  for(;;){
    cin >> n;
    if(n==0) break;
    cout << calc(n) << endl;
  }
  return 0;
}

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

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a - b - ((a - b) / c) * c << endl;
    return 0;
}

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

using namespace std;

#define  N 100100

int a[N];

void solve() {

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    long long ans = 1e18;
    for (int best = -100; best <= 100; best++) {
        long long tot_sum = 0;
        for (int i = 1; i <= n; i++) {
            tot_sum += (a[i] - best) * (a[i] - best);
        }
        ans = min(ans, tot_sum);
    }
    cout << ans << endl;


}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef qwerty
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif


    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
signed main(){
    
    int n,k;
    int a;
    cin>>n>>k;
    unordered_map<int,int> m;
    vector<int> v;
    rep(i,n){
        cin>>a;
        m[a]++;
    }
    int co=0;
    for(auto x:m){
        v.push_back(x.second);
        co++;
    }
    if(co<=k){
        cout<<0<<endl;
        return 0;
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<co-k;i++){
        ans+=v[i];
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 11592
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    multiset<string> mp;
    string s;
    string S[N];
    rep(i, N){
        cin >> s;
        S[i] = s;
        mp.insert(s);
    }

    ll M;
    cin >> M;
    multiset<string> mn;
    rep(i, M){
        cin >> s;
        mn.insert(s);
    }

    ll ans = 0;
    ll count;
    rep(i, N){
        count = mp.count(S[i]) - mn.count(S[i]);
        ans = max(ans, count);
    }

    cout << ans << endl;

    return 0;
}

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

namespace Atcoder
{

    class Program
    {
        static void Main(string[] args)
        {
            int n_1 = 0;
            int n_2 = 0;
            int n_3 = 0;
            int N = int.Parse(Console.ReadLine());
            int[] ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] p =Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            for (int i = 0; i < p.Length; i++)
            {
                if (p[i] <= ab[0]) n_1++;
                else if (ab[0] < p[i] && p[i] <= ab[1]) n_2++;
                else n_3++;
            }
            Console.WriteLine(Math.Min(n_1,Math.Min(n_2,n_3)));
        }
    }
}


Measured memory_bytes: 11348