akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

string IntToString(int number) {
    stringstream ss;
    ss << number;
    return ss.str();
}

int main(){
    int n;
    string s;
    while(cin >> n, n){
        cin >> s;
        for(int i=0; i < n; i++){
            string t;
            for(int j=0; j < s.size(); j++){
                string p = s.substr(j, 1);
                int count = 1;
                for(int k=j+1; k < s.size(); k++){
                    j = k;
                    if(s.substr(k, 1) == p)count++;
                    else {j--; break;}
                }
                t += IntToString(count) + p;
            }
            s = t;
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 1356
function main(input) {
  input = input.trim().split("\n");
  const n = Number(input[0]);
  const ps = input.slice(1).map(n => Number(n));
  let result = 0;
  let max = 0;
  for (let i = 0; i < n; i++) {
  	const p = ps[i];
    result += p;
    if (max < p) {
      max = p;
    }
  }
  result -= max/2;
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <stdio.h>
#include <stdbool.h>

int main() {
	int H, W;

	char a[100][101] = { 0 };

	bool delV[100];
	bool delH[100];

	scanf("%d %d", &H, &W);
	
	for(int i = 0; i < H; i++) scanf("%s", &(a[i][0]));


	for (int i = 0; i < H; i++) {
		delV[i] = true;
		for (int j = 0; j < W; j++) {
			if (a[i][j] == '#') {
				delV[i] = false;
				break;
			}
		}
	}

	for (int i = 0; i < W; i++) {
		delH[i] = true;
		for (int j = 0; j < H; j++) {
			if (a[j][i] == '#') {
				delH[i] = false;
				break;
			}
		}
	}


	for (int i = 0; i < H; i++) {
		if (delV[i]) continue;
		for (int j = 0; j < W; j++) {
			if (!delH[j]) printf("%c", a[i][j]);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 128
n=int(input())
b=list(map(int,input().split()))
a=[]
a.append(b[0])
a.append(b[0])
for i in range(1,n-1):
    if(a[i]>b[i]):
        a[i]=b[i]
    a.append(b[i])
print(sum(a))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<char> p(n), q(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> q[i];
  }
  vector<char> temp(n);
  temp = p;
  int count = 0, rec1 = 0, rec2 = 0;
  sort(temp.begin(), temp.end());
  do {
    count++;
    if (temp == p) {
      rec1 = count;
    }
    if (temp == q) {
      rec2 = count;
    }
  } while (next_permutation(temp.begin(), temp.end()));
  cout << abs(rec1 - rec2) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  int cc = 0;
  while(cin>>n, n){
    vector<pair<int,pair<int,string> > > v(n);
    if(cc++ != 0) cout << endl;
    REP(i,n){
      int w,l,e;
      string name;
      cin>>name>>w>>l>>e;
      int point = w*3 + e;
      v[i].f = -point;
      v[i].s.f = i;
      v[i].s.s = name;
    }
    sort(v.begin(), v.end());
    REP(i,n){
      string name = v[i].s.s;
      int point = -v[i].f;
      cout << name << "," << point << endl;
    }
  }
  return 0;
}

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

int main() {
	int N;
	vector<pair<int, int>> v;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int T, A; cin >> T >> A;
		v.push_back(pair<int, int>(T, A));
	}

	long long voteT = 0, voteA = 0;

	for (int i = 0; i < N; i++) {
		long long T = v[i].first;
		long long A = v[i].second;

		if (T >= voteT && A >= voteA) {
			voteT = T;
			voteA = A;
		}
		else {
			long long mulT = voteT / T; if (voteT % T != 0) mulT++;
			long long mulA = voteA / A; if (voteA % A != 0) mulA++;
			long long maxTA = max(mulT, mulA);
			voteT = T * maxTA;
			voteA = A * maxTA;
		}
	}

	cout << voteT + voteA << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int,input().split()))
sum_front_N = sum(W)
sum_back_N = 0
ans = sum_front_N
for i in W:
    sum_back_N +=i
    sum_front_N -=i
    ans = min(ans,abs(sum_front_N - sum_back_N))
print(ans)

Measured memory_bytes: 9072
#include<iostream>
    using namespace std;
     
    int main()
      {
      int n, i, j, count;
      count = 0;
      cin >> n;
      int d[n];
      for(i = 0; i < n; i++)
      {
        cin >> d[i];
      }
      for(i = 1; i < n; i++)
      {
        for(j = 0; j < i; j++)
        {
          if(d[i] == d[j])
          {
            d[i] = 0;
          }
        }
      }
      for(i = 0; i < n; i++)
      {
        if(d[i] != 0)
        {
          count++;
        }
      }
      cout << count << endl;
      return 0;
    }

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

int main(){
    
    string s;
    int a = 0;
    
    cin >> s;
    for(int i = 0;i < s.size();++i)
        a += s[i] - '0';
        
    if(stoi(s) % a == 0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x,0))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,k;
  int cnt=0;
  cin>>n>>k;
  while(n>0){
    cnt ++;
    n /=k;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	d = abs(d);
	ll ans = x;
	ll a = x / d;
	if (a >= k) {
		ans = x - k * d;
	}
	else {
		if ((k - a) % 2 == 0) {
			ans = abs(x % d);
		}
		else {
			ans = abs(x % d - d);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 100005
  #define INF 1000000000000
  #define eps 1e-6
  int dp[N];
  int32_t main()
  {         

    IOS


    //dp[i] denotes the minimum cost to win over h points

    int h,n;
    cin >> h >> n;

      for(int i = 1; i <=h; i++)dp[i] = INF;


    vector<pair<int,int>> v;

    for(int i = 1; i <=n; i++)
    {
      int x, y;
      cin >> x >> y;
      v.PB(MP(x,y));
    }


    sort(all(v)); 

    for(int i = 1; i <= h; i++)
    {
      for(auto j: v)
      {
        if(i < j.first)dp[i] = min(dp[i],j.second);
        else dp[i] = min(dp[i],dp[i-j.first] + j.second);
      }
    }

    dp[0] = 0;



    cout << dp[h];  
    return 0; 
}

Measured memory_bytes: 512
#include <iostream>
#include <climits>
#include <string>
#include <stdlib.h>
#include <algorithm>
using namespace std;

long long int i,j,ans=1;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;

int main(){
	string a[50],b[50];
	int n,m,x,y;
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<m;i++){
		cin>>b[i];
	}
	int count,check=0;
	for(i=0;i<n-m+1;i++){
		for(j=0;j<n-m+1;j++){
			count = 0;
			for(x=i;x<m+i;x++){
				for(y=j;y<m+j;y++){
					if(a[x][y]==b[x-i][y-j]){
						count += 1;
					}
				}
			}
		if(count == m*m){
			check = 1;
			break;
		}
		}
	}
	if(check==1){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n;
  scanf("%d",&n);

  int p[n],i,ans=0,max=0;
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
    ans += p[i];
    if(p[i]>max)
      max = p[i];
  }

  ans -= max/2;

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

Measured memory_bytes: 128
# coding: utf-8
# Your code here!

from collections import deque

N = int(input())
H = deque(list(map(int, input().split())))
tmp = 0
max_num = 0

for i in range(N):
    tmp = H.popleft()
    if H == deque([]):
        print("Yes")
        exit()
    else:
        if tmp - 1 > H[0]:
            print("No")
            exit()
        elif max_num - 1 > tmp:
            print("No")
            exit()
        elif tmp > H[0]:
            if len(H) == 1:
                print("Yes")
                exit()
            elif H[0] > H[1]:
                print("No")
                exit()
        if max_num < tmp:
            max_num = tmp

Measured memory_bytes: 63856
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

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

using namespace std;
using llng = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

int main() {
    int N, M; cin >> N >> M;
    // Aiは位置iの値
    // Ciは値iの数
    // Liは[i-1,i]を覆う区間の数
    vi A(N+1, 0), C(N+1, 0), L(N+1, 0);
    for (int i=1; i<=N; i++) {
        cin >> A[i]; C[A[i]]++;
    }
    for (int i=1; i<=N; i++) {
        for (int j=0; j<C[i]; j++) {
            if (i-j <= 0) break; L[i-j]++;
        }
    }

    int zero = 0;
    for (int i=1; i<=N; i++) if (L[i] == 0) zero++;
    for (int i=1; i<=M; i++) {
        int x, y; cin >> x >> y;
        // 変化前
        if (A[x] - (C[A[x]] - 1) >= 1) {
            L[A[x] - (C[A[x]] - 1)]--;
            if (L[A[x] - (C[A[x]] - 1)] == 0) zero++;
        }
        C[A[x]]--;
        // 変化後
        A[x] = y;
        C[A[x]]++;
        if (A[x] - (C[A[x]] - 1) >= 1) {
            if (L[A[x] - (C[A[x]] - 1)] == 0) zero--;
            L[A[x] - (C[A[x]] - 1)]++;
        }

        cout << zero << endl;
    }

    return 0;
}


Measured memory_bytes: 3840
from collections import deque
def bfs():
    d = [[float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]


h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
sx, sy = 0, 0
gx, gy = h - 1, w - 1

# 白いマスを数える
white = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            white += 1

res = bfs()
if 0 < res < float("inf"):
    # 白いマスの数から最短経路でかかるコスト分を引く
    # ゴールを黒いマスに変えることはできないためその分も引く
    print(white - res - 1)
else:
    print(-1)

Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(LL i=LL(m);i<LL(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

LL snuke(LL k) {
    LL ret = 0;
    while (k) {
        ret += k % 10;
        k /= 10;
    }
    return ret;
}

double calc(LL k) {
    return 1.0 * k / snuke(k);
}

void solve() {
    const int maxv = 20000;
    LL k;
    cin >> k;
    REP(i,0,min((LL)9,k)) cout << i + 1 << endl;
    k -= 9;
    REP(i,0,min((LL)9,k)) cout << i + 1 << 9 << endl;
    k -= 9;    
    int ks = 2;
    int cnt = 1;
    REP(i,0,k) {
        double ns = calc((int)(cnt/10+1) * pow(10,ks+1) - 1);
        double tmp = calc((cnt+1) * pow(10, ks) - 1);
        if (tmp > ns && cnt > 9) {
            cnt /= 10;
            ++ks;
            --i;
            continue;
        }
        cout << cnt;
        REP(j,0,ks) cout << 9;
        cout << endl;
        ++cnt;
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int X[200000] = {};
int x[200000];

int main(void)
{
	int N;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> X[i];
		x[i] = X[i];
	}

	sort(X,X+N);

	for (int i = 0; i < N; i++) {
		if (x[i] <= X[N / 2 - 1]) {
			cout << X[N / 2] << endl;
		}
		else{
			cout << X[N / 2 - 1] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3712
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	int A[100000];
	rep(i, N) A[i] = getint();

	pakuri_sort(N, A);
	int kotae = 0;
	int kazu = 1;
	rep(i, N - 1) {
		if (A[i] == A[i + 1]) kazu++;
		else {
			kotae += kazu & 1;
			kazu = 1;
		}
	}
	kotae += kazu & 1;
	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
    while (true) {
        int N, Q;
        cin >> N >> Q;
        if (N == 0 and Q == 0) {
            break;
        }
        vector<int> num(100, 0);
        for (int i = 0; i < N; i++) {
            int M;
            cin >> M;
            for (int i = 0; i < M; i++) {
                int d;
                cin >> d;
                num[d]++;
            }
        }
        int maxi = 0;
        int maxind = 0;
        for (int i = 0; i < 100; i++) {
            if (maxi < num[i]) {
                maxi = num[i];
                maxind = i;
            }
        }
        if (maxi >= Q) {
            cout << maxind << endl;
        } else {
            cout << 0 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3124
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

int N, W, w1;
auto L = new int[](4);
auto V = new int[][](4);
int[][][][] mem;
int ans = 0;

void dfs(int l0, int l1, int l2, int l3, int v) {
    if (l0 > L[0] || l1 > L[1] || l2 > L[2] || l3 > L[3]) return;
    if (w1 * l0 + (w1+1) * l1 + (w1+2) * l2 + (w1+3) * l3 > W) return;
    if (mem[l0][l1][l2][l3] >= 0) return;
    ans = max(ans, v);
    mem[l0][l1][l2][l3] = v;

    if (l0 < L[0]) dfs(l0+1, l1, l2, l3, v+V[0][l0]);
    if (l1 < L[1]) dfs(l0, l1+1, l2, l3, v+V[1][l1]);
    if (l2 < L[2]) dfs(l0, l1, l2+1, l3, v+V[2][l2]);
    if (l3 < L[3]) dfs(l0, l1, l2, l3+1, v+V[3][l3]);
}

void main() {
    auto s = readln.split.map!(to!int);
    N = s[0];
    W = s[1];
    s = readln.split.map!(to!int);
    w1 = s[0];
    V[0] ~= s[1];
    foreach (i; 0..N-1) {
        s = readln.split.map!(to!int);
        V[s[0]-w1] ~= s[1];
    }

    foreach (i; 0..4) {
        V[i].sort!"a > b"();
        L[i] = V[i].length.to!int;
    }

    mem = new int[][][][](L[0]+1, L[1]+1, L[2]+1, L[3]+1);
    foreach (i; 0..L[0]+1) foreach (j; 0..L[1]+1) foreach (k; 0..L[2]+1) fill(mem[i][j][k], -1);

    dfs(0, 0, 0, 0, 0);
    ans.writeln;
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli data[100100];
bool vis[100100];
bool noFlag;

class edge{
public:
	lli to,cost;
};

vector<vector<edge>> v;


void func(lli now){	
	if(noFlag)return;
	for(auto e:v[now]){
		if(vis[e.to]){
			if(data[e.to] != data[now]+e.cost)
			{
				noFlag = true;
				return;
			}
		}
		else{
			vis[e.to]=true;
			data[e.to] = data[now]+e.cost;
			func(e.to);
		}
	}
	return;
}

signed main(){

	lli n,m;
	cin>>n>>m;
	v.resize(n);

	REP(i,0,m){
		lli l,r,d;
		cin>>l>>r>>d;
		l--,r--;
		v[l].push_back({r,d});
		v[r].push_back({l,-d});
	}

	REP(i,0,n){
		if(noFlag){
			cout<<"No"<<endl;
			return 0;
		}
		if(vis[i])continue;

		data[i]=0;
		vis[i]=true;
		func(i);
	}


	cout<<"Yes"<<endl;

	return 0;
 
}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll n, k; cin >> n >> k;
    vector<ll> h(n);
    for(int i = 0; i < n; ++i){
        cin >> h[i];
    }
    sort(h.begin(), h.end(), greater<ll>());
    ll ans = 0;
    for (int i = k; i < n; ++i) {
        ans += h[i];
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


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

class Main {
	public static void main(String[] args) throws IOException {
		setIO();

		char[] s = f.readLine().toCharArray();
		
		int ans = 0;
		
		for (int i = 0; i < 3; i++) {
			if (s[i] == 'R') {
				int j = i;
				while (j < 2 && s[j+1] == 'R') {
					j++;
				}
				ans = Math.max(ans, j - i + 1);
			}
		}
		
		out.println(ans);
		
		f.close();
		out.close();
	}
	
	static boolean[] generate(int x, int n) {
		boolean[] s = new boolean[n];
		for (int i = 0; i < n; i++) {
			s[i] = (x & (1 << i)) >> i == 1;
		}
		return s;
	}
	
	static boolean valid(int K, char[][] A, boolean[] h, boolean[] v) {
		for (int i = 0; i < h.length; i++) {
			for (int j = 0; j < v.length; j++) {
				if (h[i] && v[i] && A[i][j] == '#') K--;
			}
		}
		
		return K == 0;
	}

	static BufferedReader f;
	static PrintWriter out;
	static StringTokenizer st;

	static int ni(StringTokenizer st) {
		return Integer.parseInt(st.nextToken());
	}

	static int ni() throws IOException {
		return Integer.parseInt(f.readLine());
	}

	static StringTokenizer nl() throws IOException {
		return new StringTokenizer(f.readLine());
	}

	static int[] nia(int N) throws IOException {
		StringTokenizer st = nl();
		int[] A = new int[N];
		for (int i = 0; i < N; i++)
			A[i] = ni(st);
		return A;
	}

	static void setIn(String s) throws IOException {
		f = new BufferedReader(new FileReader(s));
	}

	static void setOut(String s) throws IOException {
		out = new PrintWriter(new FileWriter(s));
	}

	static void setIn() {
		f = new BufferedReader(new InputStreamReader(System.in));
	}

	static void setOut() {
		out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	}

	static void setIO(String s) throws IOException {
		setIn(s + ".in");
		setOut(s + ".out");
	}

	static void setIO() {
		setIn();
		setOut();
	}
}


Measured memory_bytes: 32948
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
d = dict()
z = []
res = [None] * m
for i in range(m):
    a,b = inpl()
    d[(a,b)] = i
    z.append([a,b])
z.sort(key=lambda x:x[1])
z.sort(key=lambda x:x[0])
# print(z)
cnt = 0
now = z[0][0]
for i,t in enumerate(z):
    ind = d[(t[0],t[1])]
    if now == t[0]:
        cnt += 1
        res[ind] = [now,cnt]
    else:
        cnt = 1
        now = t[0]
        res[ind] = [now,cnt]

for a,b in res:
    print(str(a).zfill(6) + str(b).zfill(6))

Measured memory_bytes: 52492
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
	int n; cin>>n; int q; cin>>q;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i]; 
	Query queries[q]; 
	for(int i=0;i<q;i++){
		cin>>queries[i].l; queries[i].l--;
		cin>>queries[i].r; queries[i].r--;
		queries[i].idx = i; 
	}
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


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

int main( int argc, char *argv[] )
{
int i;
char lpIn[ 100 ];
char lpOut[ 100 ];
char C;

	// 入力
	for( i = 0; i < 3; i++ )
	{
		cin >> lpIn;
		C = lpIn[ 0 ];
		lpOut[ i ] = C + 'A' - 'a';
	}

	lpOut[ 3 ] = '\0';

	// 出力
	cout << lpOut << endl;

	return 0;
}






Measured memory_bytes: 256
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(0, n, 2):
        ans += a[i] % 2 == 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9060
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
using namespace std;
int main() {
	// your code goes here
	int start_a, end_a, start_b, end_b, common;
	cin>>start_a>>end_a>>start_b>>end_b;
	/*if(start_a > end_b or start_b > end_a){
		printf("0\n"); return 0;
	}*/
	common = min(end_a, end_b) - max(start_a, start_b);
	printf("%d\n",max(0,common));
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,raw_input().split(" "))
a = []
for i in range(0,n):
	b = map(int,raw_input().split(" "))
	a.append(b)
for j in range(0,m):
	k = input()
	for i in range(0,n):
		a[i][j] = a[i][j] * k
for i in range(0,n):
	s = 0
	for j in range(0,m):
		s = s + a[i][j]
	print str(s)

Measured memory_bytes: 4624
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
using namespace std;
#define MAX 500009
#define MOD 1000000007
#define EPS 0.0000000001
char s[MAX];
int arr[MAX];
int main()
{
    long long int sum=0;
    int i,j=1,current=0;
    char c;

    for(i=1;;i++)
    {
        scanf("%c",&c);
        if(!(c=='>'||c=='<')) break;
        s[i]=c;
    }
    int n=i;
    for(i=n-1;i>=0;i--)
    {
        if(s[i]=='>')
        {
            arr[i]=arr[i+1]+1;
        }
    }
    for(i=0;i<n;i++)
    {
        if(s[i]=='<')
        {
            arr[i+1]=max(arr[i+1],arr[i]+1);
        }
    }
    for(i=0;i<=n;i++)
    {
        sum=sum+arr[i];
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 2688
function Main(arg)
{
  var N = arg.split("\n")[0].split(" ")[0] - 0;
  var K = arg.split("\n")[0].split(" ")[1] - 0;

  var ans = 1;
  while (1) {
    var N = Math.floor(N / K);
    if (N === 0) break;

    ans++;
  }
  console.log(ans);
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){

         ll n;
          cin>>n;

          map<ll,ll>count;

              ll sum=0;



             for(int i=1;i<=n;i++)
              {
                  ll terms = n/i;

                    ll x = (terms * (terms + 1) * i)/2;
                    sum+=x;
              }
            cout<<sum;
}


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

int main(void){
    int x, y;
    cin >> x >> y;
    rep(i, x + 1){
        int k = x - i;
        if(i * 2 + k * 4 == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Gabriel Carrillo
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BFrog2 solver = new BFrog2();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFrog2 {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            long[] dp = new long[n], heights = new long[n];
            for (int i = 0; i < n; i++)
                heights[i] = in.nextLong();
            Arrays.fill(dp, Long.MAX_VALUE);
            dp[0] = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j <= Math.min(i + k, n - 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(heights[i] - heights[j]));
                }
            }

            out.println(dp[n - 1]);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 33124
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a=0,b=0,c=0,K=0;
  cin>>a>>b>>c>>K;
  bool possible=false;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      for(int k=0;k<=K;k++){
        int x=a*(1<<i),y=b*(1<<j),z=c*(1<<k);
        if(i + j + k <=K && x<y && y < z){
        possible=true;
        }
      }
    }
  }
  if(possible){
  cout<<"Yes\n";
  }else{
  cout<<"No\n";
  }
  return 0;
}

Measured memory_bytes: 3504
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

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

        while (sc.hasNext()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            int e = sc.nextInt();
            int f = sc.nextInt();
            double dev = a * e - b * d;
            double x = (c * e - b * f) / dev;
            double y = (f * a - c * d) / dev;

            System.out.println(new BigDecimal(x).setScale(3, RoundingMode.DOWN)
                    + " "
                    + new BigDecimal(y).setScale(3, RoundingMode.DOWN));
        }
    }
}



Measured memory_bytes: 26512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m=0,l=0,sum=0;

        cin>>n;
        while(l<n){
            l++;
            if(l%3!=0&&l%5!=0){
                m+=l;}


        }sum=sum+m;
       cout << sum<<endl;



}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;long long a,b;
	cin>>n;
	cin>>a;
	for(int i=1;i<n;i++)
	{
		cin>>b;
		a=__gcd(a,b);
	}
	cout<<a<<endl;
	return 0;
}

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

int main() {
	string str;
	getline(cin, str);
	for (int i = 0;i < str.length();i++) {
		if (islower(str[i]))
			str[i] = toupper(str[i]);
		else
			str[i] = tolower(str[i]);
	}

	cout << str << endl;
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <cstdio>

using namespace std;

const int P=998244353;
const int L=1000000;

int fact[L+5],invf[L+5];
int n,K,ans;

inline int quick_power(int x,int y)
{
	int ret=1;
	for (;y;y>>=1,x=1ll*x*x%P) if (y&1) ret=1ll*ret*x%P;
	return ret;
}

void pre()
{
	fact[0]=1;
	for (int i=1;i<=L;++i) fact[i]=1ll*fact[i-1]*i%P;
	invf[L]=quick_power(fact[L],P-2);
	for (int i=L;i>=1;--i) invf[i-1]=1ll*invf[i]*i%P;
}

inline int C(int n,int m){return n>=m?1ll*fact[n]*invf[m]%P*invf[n-m]%P:0;}

inline int calc(int n,int m,int t)
{
	if (m-n>=t||t<=0) return 0;
	return (C(n+m,m)-C(n+m,n+t)+P)%P;
}

int main()
{
	pre(),scanf("%d%d",&n,&K),ans=0;
	for (int R=K,B;R>=K-R&&R>=0;--R)
	{
		B=K-R;
		if (R==B) (ans+=calc(R,B-1,R-n+1))%=P;
		else (ans+=calc(R,B,R-n+1))%=P;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8064
N = int(input())
#a = [int(i) for i in input().split()]
F = [[int(j) for j in input().split()] for i in range(N)]
P = [[int(j) for j in input().split()] for i in range(N)]

ans = -999999999999999
for i in range(1,1<<10):
    res = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if ((i>>k)&1 == 1) and (F[j][k] == 1):
                cnt+=1
        res += P[j][cnt]
    ans = max(ans,res)
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
#define MAXN 200005
int a[MAXN], f[MAXN];
int n;
ll k;
ll ok(ll deadline) {
	ll reduction = 0;
	for (int i = 0; i < n; i++) {
		reduction += max(0LL, a[i] - deadline / f[i]);
	}
	return reduction <= k;
}
int main() {

	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> f[i];
	sort(a, a + n);
	sort(f, f + n, greater<int>());
	ll l = 0, r = 1e12;
	while (l < r) {
		ll m = (l + r) / 2;
		if (ok(m)) {
			r = m;
		}
		else {
			l = m + 1;
		}
	}
	cout << r << endl;

	return 0;
	
}

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

int main(){
    ll N;
    cin >> N;
    ll a[5];
    rep(i,5){
        cin >> a[i];
    }
    sort(a,a+5);
    ll x=a[0];
    ll ans;
    if(N>x)ans=5+N/x;
    else ans=5;
    if(x==1)ans=5+(N/x-1);
    cout << ans << endl;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>

struct people {
	int tag, num;
	bool operator<(const people& p) const {
		return num < p.num;
	}
}A[100005];

int main() {
	int N; scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		A[i].tag = i + 1;
		scanf("%d", &A[i].num);
	}
	std::sort(A, A + N);
	printf("%d", A[0].tag);
	for (int i = 1; i < N; i++)
		printf(" %d", A[i].tag);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
int a,b,st[2005],tp;
int s[2005];
int qry(int x,int y){
	printf("? %d %d\n",x-1,y-1);fflush(stdout);
	char t[4];
	scanf("%s",t);
	if (t[0]=='Y') return 1;
	return 0;
}
int main(){
	scanf("%d%d",&a,&b);
	if (a<=b){
		puts("Impossible");
		return 0;
	}
	for (int i=1;i<=a+b;i++){
		if (tp==0 || qry(st[tp],i)) st[++tp]=i;
		else --tp;
	}
	int x=st[tp];
	for (int i=1;i<=a+b;i++) 
		if (i==x) s[i]=1;
		else s[i]=qry(x,i);
	putchar('!');
	for (int i=1;i<=a+b;i++) printf("%d",s[i]); 
}

Measured memory_bytes: 724
a1 = [int(i) for i in input().split()]
a2 = [int(j) for j in input().split()]
a3 = [int(k) for k in input().split()]
b1 = set([a1[0], a2[0], a3[0]])
b2 = set([a1[1], a2[1], a3[1]])
b3 = set([a1[2], a2[2], a3[2]])
c1 = set([a1[0], a2[1], a3[2]])
c2 = set([a1[2], a2[1], a3[0]])
a1 = set(a1)
a2 = set(a2)
a3 = set(a3)
n = int(input())
for l in range(n) :
    num = int(input())
    if num in a1 :
        a1.remove(num)
    if num in a2 :
        a2.remove(num)
    if num in a3 :
        a3.remove(num)
    if num in b1 :
        b1.remove(num)
    if num in b2 :
        b2.remove(num)
    if num in b3 :
        b3.remove(num)
    if num in c1 :
        c1.remove(num)
    if num in c2 :
        c2.remove(num)
if len(a1) == 0 or len(a2) == 0 or len(a3) == 0 or len(b1) == 0 or len(b2) == 0 or len(b3) == 0 or len(c1) == 0 or len(c2) == 0 :
    print("Yes")
else :
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
using pii = pair<int,int>;

pii p[1005];
int dp[(int)1e4 + 10];
int main(){
    int n,h;
    scanf("%d%d",&h,&n);
    for(int i =1;i<=n;i++){
        scanf("%d%d",&p[i].st,&p[i].nd);
    }
    for(int j =1;j<=h;j++){
        dp[j] = 1e9+7;
        for(int i =1;i<=n;i++){
            int x = max(0,j-p[i].st);
            dp[j] = min(dp[j],dp[x] + p[i].nd);
        }
    }
    printf("%d",dp[h]);

}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
q = int(input())

table = [0] * 100010


for i in A:
    table[i] += 1

sum = 0

for i in A:
    sum += i

for i in range(q):
    b, c = map(int, input().split())
    cnt = table[b]
    sum += (c - b) * cnt
    table[c] +=  table[b]
    table[b] = 0
    print(sum)


Measured memory_bytes: 21028
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        Console.ReadLine();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var s2 = s.ToCharArray();
        Array.Reverse(s2);
        var plus = 0; var pos = "";
        for (int i = 0; i < n; i++)
            if (i % 2 == 0 && s2[i] == '*') pos += "1";
            else if (i % 2 == 0 && s2[i] != '*') plus += int.Parse(s2[i].ToString());
            else if (i % 2 == 1 && s2[i] == '*') pos += "2";
            else plus += getDouble(int.Parse(s2[i].ToString()));
        plus %= 10;
        var res = 10 - plus;
        if (res == 10) res = 0;
        var dp = new int[pos.Length, 10];
        goDP(dp, pos, a);
        Console.WriteLine(dp[pos.Length-1,res]);
    }
    public static void goDP (int[,]dp,string pos, int[] a)
    {
        foreach (var x in a)
            if (pos[0] == '1') dp[0, x] = 1;
            else dp[0, getDouble(x)] = 1;
        for (int i = 1; i < pos.Length; i++)
            for (int j = 0; j < 10; j++)
            {
                foreach (var x in a)
                    if (pos[i] == '1') dp[i, (j + x) % 10] += dp[i - 1, j];
                    else dp[i, (j + getDouble(x)) % 10] += dp[i - 1, j];
            }
    }
    public static int getDouble(int a)
    {
        return a >= 5 ? 2 * a - 9 : 2 * a;
    }
}


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

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

#define INF_INT 1001001001
#define DEV 1000000007

// abc 129 -c
int main() {
    int n;
    cin >> n;

    // action[d][i]: d日めの行動i
    vector<vector<int>> action(n, vector<int>(3, 0));
    rep(d, 0, n) { cin >> action[d][0] >> action[d][1] >> action[d][2]; }

    vector<vector<int>> cost(n, vector<int>(3, 0));
    cost[0][0] = action[0][0];
    cost[0][1] = action[0][1];
    cost[0][2] = action[0][2];
    // rep(d, 1, n) {
    //     cost[d][0] = action[d][0] + max(cost[d - 1][1], cost[d - 1][2]);
    //     cost[d][1] = action[d][1] + max(cost[d - 0][2], cost[d - 1][0]);
    //     cost[d][2] = action[d][2] + max(cost[d - 1][0], cost[d - 1][1]);
    // }

    rep(day, 1, n) {
        rep(prevact, 0, 3) {
            rep(corract, 0, 3) {
                if (prevact == corract) continue;
                cost[day][corract] = max(cost[day][corract], cost[day - 1][prevact] + action[day][corract]);
            }
        }
        // printf("day%d: ", day);
        // rep(i, 0, 3) { cout << cost[day][i] << " "; }
        // cout << endl;
    }

    cout << max(cost[n - 1][0], max(cost[n - 1][1], cost[n - 1][2])) << endl;
    // rep(i, 0, 3) { cout << cost[n - 1][i] << " "; }

    return 0;
}



Measured memory_bytes: 11136
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(N > 17)System.out.println("Yes");
		else if(N < 4)System.out.println("No");
		else if(N==5 || N==6 || N==9 || N==10 || N==13 || N==17)System.out.println("No");
		else System.out.println("Yes");
		sc.close();
	}

}

Measured memory_bytes: 23252
#include <iostream>  
#include <cstdio>  
#include <cstring>  
  
using namespace std;  
  
#define MAX_W 101  
  
char map[MAX_W][MAX_W];  
int w,h;  
bool vis[MAX_W][MAX_W];  
int dx[]={1,-1,0,0};  
int dy[]={0,0,1,-1};  
  
void dfs(int x,int y)  
{  
    vis[y][x]=true;  
  
    for(int i=0;i<4;i++)  
    {  
        int nx=x+dx[i],ny=y+dy[i];  
        if(nx>=0 && nx<w && ny>=0 && ny<h && !vis[ny][nx] && map[y][x]==map[ny][nx])  
            dfs(nx,ny);  
    }  
}  
  
int main()  
{  
    scanf("%d%d",&h,&w);  
  
    while(w!=0 || h!=0)  
    {  
        for(int i=0;i<h;i++)  
        {  
            scanf("%s",map[i]);  
        }  
  
        memset(vis,0,sizeof(vis));  
  
        int cnt=0;  
  
        for(int i=0;i<h;i++)  
        for(int j=0;j<w;j++)  
            if(!vis[i][j])  
            {  
                dfs(j,i);  
                cnt++;  
            }  
  
        printf("%d\n",cnt);  
  
        scanf("%d%d",&h,&w);  
    }  
  
    return 0;  
}  

Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	int n,m;cin>>n>>m;
	int a=0ll,b=0ll;
	map<int,int>re;
	re[0]++;
	for(int i=0;i<n;i++){
		cin>>a; b+=a;b=(b%m);re[b]++;
}
	int ans=0ll;
	for(auto&& w:re)ans+=w.second*(w.second-1)/2;
	cout<<ans<<endl;
}


Measured memory_bytes: 4224
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<Integer> list = nextIntArray();
      HashSet<Integer> set = new HashSet<Integer>();
      for(int i = 0; i < list.size(); i++){
        set.add(list.get(i));
      }
      myout(set.size());
	}
	//Method addition frame start


  
	//Method addition frame end
}


Measured memory_bytes: 33232
#include <iostream>

using namespace std;

/*
2つの変数のアドレスをもらって、
アドレスの中身を入れ替える 
*/

void swp(int* p1,int* p2){
  int t= *p1;
  *p1=*p2;
  *p2=t;
}


int main(){

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

  //a<bにする
  if(a>b){
    swp(&a,&b);
  }
  
  //b<cにする
  if(b>c){
    swp(&b,&c);
  }
  //a<bにする
  if(a>b){
    swp(&a,&b);
  }
  
  cout <<a<<" "<<b<<" "<<c<<endl;

  return 0;
}



Measured memory_bytes: 3068