akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int ax[305][305];
int bx[305];
int cx[305];
int n,m,res;

void shan (int w){
    int i,j;
    memset(cx,0,sizeof(cx));
    bx[w]=1;
    for(i=1;i<=n;i++){
        while(bx[ax[i][ax[i][0]]])ax[i][0]++;
        cx[ax[i][ax[i][0]]]++;
    }
}

int main()
{
    int max,num;
    int i,j,a,b;
    scanf("%d%d",&n,&m);
    res = n;
    for(i=1;i<=n;i++){
        ax[i][0]=1;
        for(j=1;j<=m;j++){
            scanf("%d",&ax[i][j]);
        if(j==1) cx[ax[i][j]]++;
            }
    }
    for(i=0;i<m-1;i++){
        max = 0;
        for(j=1;j<=m;j++){
            if(cx[j]>max){
                max = cx[j];
                num = j;
            }
        }
        res = min(max,res);
    shan(num);
    }
    printf("%d",res);
}


Measured memory_bytes: 640
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if(A<B)
        {
            if(A==1)
            {
                System.out.println("Alice");
            }
            else
            {
                System.out.println("Bob");
            }
        }
        else if(A>B)
        {
            if(B==1)
            {
                System.out.println("Bob");
            }
            else
            {
                System.out.println("Alice");
            }
        }
        else
        {
            System.out.println("Draw");
        }
    }
}

Measured memory_bytes: 22356
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    count = 0
    for n in range(N):
        for nn in range(n+1, N):
            for nnn in range(nn+1, N):
                if L[n] != L[nn] and L[nn] != L[nnn]:
                    if L[n] + L[nn] > L[nnn]:
                        count += 1

    print(count)



if __name__ == '__main__':
    solve()

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

int main(){
    int L,m,n;
    while(cin>>L, L){
        int s = 0;
        bool ok =false;
        int ans = -1;
        for(int i=0; i<12; i++){
            cin>>m>>n;
            s +=(m-n);
            if(s>=L && !ok){
                ok =true;
                ans = i+1;
            }
        }
        if(ok){
            cout << ans << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (char i = '0'; i <= '9';i++){
        for (char j = '0';j <= '9';j++){
            for(char k = '0';k <= '9';k++){
                char tmp[3] = {i, j, k};
                int cur = 0;
                rep(si, n)
                {
                    if(s[si] == tmp[cur])cur++;
                }
                if(cur == 3){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (n % 111 == 0) {
		cout << n << endl;
	}
	else {
		int x = n / 111 + 1;
		cout << 111 * x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 500000
#define INFTY 1000000001;

void mergeSort(int *,int,int);
void merge(int *,int ,int ,int);

int cnt;

int main()
{
  int n,i,S[N];

  scanf("%d",&n);

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

  mergeSort(S,0,n);



  for(i=0;i<n;i++)
  {
    if(i!=n-1)printf("%d ",S[i]);
    else printf("%d\n",S[i]);
  }
  printf("%d\n",cnt);

  return 0;
}


void merge(int S[] ,int left ,int mid ,int right)
{
  int n1,n2,k,*L,*R,i,j;
  n1 = mid - left;
  n2 = right - mid;
  // L[0...n1], R[0...n2] を生成
  L = (int *)malloc((n1+1)*sizeof(int));
  R = (int *)malloc((n2+1)*sizeof(int));
  for(i=0;i<n1;i++)L[i] = S[left + i];
  for(i=0;i<n2;i++)R[i] = S[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k=left;k<right;k++)
    {
      if( L[i] <= R[j])
        {
          S[k] = L[i];
          i = i + 1;
        }

      else
        {
          S[k] = R[j];
          j = j + 1;
        }
        cnt++;
    }
}

void mergeSort(int S[], int left, int right)//初期値：S,０、n
{
  int mid;
  if(left+1 < right)
    {
      mid = (left + right)/2;

      mergeSort(S, left, mid);

      mergeSort(S, mid, right);

      merge(S, left, mid, right);
    }
}



Measured memory_bytes: 64428
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);
		long n = scan.nextInt();

		long ans = 0;
		for (int i = 1; i < n + 1; i++) {
			for (int j = 1; j * i <= n; j++) {
				ans = ans + (j * i);
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 27128
function Main (input) {
  input = input.split("\n").map(Number);
  var A = input[0];
  var B = input[1];
  var ans;
  if (A > B) {
    ans = "GREATER";
  }
  else if (B > A) {
    ans = "LESS";
  }
  else if (A == B) {
    ans = "EQUAL";
  }
  console.log(ans);
}

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

Measured memory_bytes: 7372
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

//二部グラフの最大マッチングを求める
//ford-fulkerson的に貪欲なパスを埋めていく
class BipartiteMatching {
protected:
	vector<vector<int>>graph;
	//match=対応する頂点、ない場合は-1　alive=0にすると無効にできる(継承クラスで使用)　used=使われたかどうか
	vector<int>match, alive, used;
	int stamp;
	int V;
	bool dfs(int v) {
		used[v] = stamp;
		for (auto u : graph[v]) {
			int w = match[u];
			if (!alive[u])continue;
			if (w == -1 || (used[w] != stamp&&dfs(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
public:
	BipartiteMatching(int n)
		:stamp(0), V(n), graph(n), match(n, -1), alive(n, 1), used(n, 0)
	{}
	//uとvに辺を追加する
	void addedge(int u, int v) {
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	//グラフの最大マッチングを求める
	int getMatch() {
		int ret = 0;
		for (int i = 0; i < V; ++i) {
			if (!alive[i])continue;
			if (match[i] == -1) {
				++stamp;
				ret += dfs(i);
			}
		}
		return ret;
	}
};

//頂点修正などをある程度高速に処理できる
class FixMatching : public BipartiteMatching
{
public:
	FixMatching(int sz) : BipartiteMatching(sz) {}
	//頂点kを加えたときのフローを求める
	int add(int k) {
		alive[k] = 1;
		++stamp;
		return (dfs(k));
	}
	//頂点kを削除したときのフローを求める
	int kill(int k) {
		alive[k] = 0;
		if (match[k] == -1) return (0);
		match[match[k]] = -1;
		++stamp;
		int ret = dfs(match[k]);
		match[k] = -1;
		return (ret - 1);
	}
};

int N;
vector<pair<int, int>>R, B;

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		R.push_back({ x,y });
	}
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		B.push_back({ x,y });
	}
	BipartiteMatching bp(N + N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (R[i].first < B[j].first && R[i].second < B[j].second) {
				bp.addedge(i, j + N);
			}
		}
	}
	int ans = bp.getMatch();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    int sum = 0 , j = 1;
    while(sum < N){
        sum+=j;
        j++;
    }
    int A = sum - N;
    for(int i = 1; i < j; i++){
        if(i != A){
            cout << i << endl;
        }
    }
}

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

using namespace std;

int main(){
    int a, b, c, k, ans = 0;
    cin >> a >> b >> c >> k;
    ans += min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 200000
#define INF (1e+9)

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX];
    fget_array(arr, num);

    int i;
    int ans = -INF;
    int prev = arr[0];
    for(i = 1; i < num; i++) {
        int cur = arr[i];
        ans = max(cur-prev, ans);
        prev = min(prev, cur);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2548
import java.util.Scanner;

public class Main {

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

        String op = "+";
        while (!"?".equals(op)) {
            int a = scanner.nextInt();
            String ope = scanner.next();
            int b = scanner.nextInt();
            
            op=ope;
            
            
            if ("+".equals(op)) {
                int c = a + b;
                System.out.println(c);
            }
            if ("-".equals(op)) {
                int c = a - b;
                System.out.println(c);
            }
            if ("*".equals(op)) {
                int c = a * b;
                System.out.println(c);
            }
            if ("/".equals(op)) {
                int c = a / b;
                System.out.println(c);
            }
            if ("?".equals(op)) {
                break;
            }
        }
    }
}

Measured memory_bytes: 26304
#include <stdio.h>

int main(void){
	int a=0;
	int b=0;
	int c=1;
	int d=0;
	scanf("%d %d",&a,&b);
	if(b<10){
		d=a*10+b;
	}else{
		if(b<100){
			d=a*100+b;
		}else{
			d=a*1000+b;
		}
	}
	while(c<400){
		if((c*c)==d){
			puts("Yes");
			return 0;
		}else{
			c++;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 100010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

vector <int> v;
ll sum[MAX];

void solve(void){
    int N;
    cin >> N;
    rep(N, i) {
        int A; scanf("%d ", &A);
        v.push_back(A);
    }
    sort(v.begin(), v.end());
    sum[0] = v[0];
    rep(N-1, i) sum[i+1] = v[i+1] + sum[i];
    int mini = 0;
    rep(N-1, i) {
        if (v[i]*2 >= v[i+1]) continue;
        else {
            mini = i+1;
            while (sum[mini-1]*2 >= v[mini]) {
                mini--;
            }
        }
    }
    int ans = N - mini;
    printf("%d\n", ans);
}

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


Measured memory_bytes: 1656
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;


signed main() {
    ll n, m;
    cin >> n >> m;
    
    if (n >= m) {
        mes(0);
        re0;
    }
    
    vll x(m);
    rep(i, m) {
        cin >> x[i];
    }
    Sort(x);
    
    vll d(m-1);
    ll sum = 0;
    rep(i, m-1) {
        d[i] = x[i+1] - x[i];
        sum += d[i];
        
    }
    
    rSort(d);
    
    
    rep(i, n-1) {
        sum -= d[i];
        
    }
    
    mes(sum);
    
    
        
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 4728
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int INF=int(1e9);
int n,goal;
int con[15][2];
int dp[15][100005];
int DP(int x,int y)
{
    if(y<=0) return 0;
    if(x<1) return INF;
    if(dp[x][y]) return dp[x][y];
    dp[x][y]=INF;
    for(int i=0;i<con[x][0];i++)
        dp[x][y]=min(dp[x][y],DP(x-1,y-i*x)+i);
    dp[x][y]=min(dp[x][y],DP(x-1,y-con[x][0]*x-con[x][1])+con[x][0]);
    return dp[x][y];
}
int main()
{
    scanf("%d%d",&n,&goal);
    goal/=100;
    for(int i=1;i<=n;i++)
        scanf("%d%d",&con[i][0],&con[i][1]),con[i][1]/=100;
    printf("%d\n",DP(n,goal));
    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  string s; cin >> s;
  int ri = n - 1;
  int ans = 0;
  for (int li = 0; li < n; li++) {
    if (s[li] == 'R') continue;
    while (1) {
      if (ri < 0) break;
      if (s[ri] == 'R') break;
      ri--;
    }
    if (li >= ri) break;
    swap(s[li], s[ri]);
    ans++;
  }

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


Measured memory_bytes: 3752
from collections import deque
n = int(input())
a = list(map(int, input().split()))
b = deque()
last = n%2==0
for i in range(n):
  if last:
    b.append(a[i])
  else:
    b.appendleft(a[i])
  last = not last
print(*b)
    

Measured memory_bytes: 25412
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  vector<int> p(N,0);
  for(int i = 0;i < N-1;i++) {
    int a;
    cin >> a;
    a--;
    p[a]++;
  }

  for(int i = 0;i < N;i++) {
    cout << p[i] << endl;
  }

}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 1001001001;

    int r = 0, w = 0;
    rep(i,n){
        if(s[i] == 'R') r++;
        else w++;
    }

    ans = min(r,w);
    int l = 0;
    r = n-1;
    if(ans >= 1){
        int cnt = 0;
        while(l<r){
            while(l < r && s[l] == 'R')l++;
            while(l < r && s[r] == 'W')r--;
            if(l >= r){
                ans = min(ans, cnt);
                break;
            }
            cnt++;
            l++;
            r--;
        }
        ans = min(ans, cnt);
    }

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




Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
using namespace std;
const long long MOD = 1000000007;
const int MAX = 2000001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    long long n;
    long long k;
    cin >> n >> k;

    comb_init();

    long long ans = 0;
    for(int i = 0; i <= min(n, k); i++){
        long long tmp = (comb(n, i) * comb(n - 1, i)) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc() {
	ll l;
	double ans = 0;

	cin >> l;

	double n = (double)l / 3;
	ans = n * n * n;

	cout << fixed;
	cout << setprecision(12) << ans;
}

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

	solve_abc();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1e15+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<int> a(3,0);
    rep(i,0,s.size()){
      a[s[i]-'a']++;
    }
    sort(all(a));
    if(a[2]-a[0]<=1){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
program ABC_053_C_XYetAnotherDieGame
   implicit none
   integer(8) x
   read(*, *) x
   if(mod(x,11) == 0) then
	   write(*, *) 2 * (x / 11)
   else if(mod(x,11) <= 6) then
	   write(*, *) 2 * (x / 11) + 1
   else 
	   write(*, *) 2 * (x / 11) + 2
   end if
end program ABC_053_C_XYetAnotherDieGame

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

//ABC170D
//ABC170C
int main(void) {
  int x, n, k, i, cou=0, tmp;
  scanf("%d %d", &x, &n);
  int p[n];
  for(i=0; i<n; i++){
    scanf(" %d", &p[i]);
  }

  if(n==0){
    printf("%d", x);
    return 0;
  }

  for(i=0; i<n; i++){
    if(p[i]==x) break;
    else if(i==n-1){
      printf("%d", x);
      return 0;
    }
  }

  for(k=1; k<110; k++){
    for(i=0; i<n; i++){
      if(p[i]==x-k) break;
      else if(i==n-1){
        printf("%d", x-k);
        return 0;
      }
    }
    for(i=0; i<n; i++){
      if(p[i]==x+k) break;
      else if(i==n-1){
        printf("%d", x+k);
        return 0;
      }
    }
  }
}

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

int main()
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::vector<int> sorted = a;

    std::sort(sorted.begin(), sorted.end(), std::greater<int>());

    int max = sorted[0], second_max = sorted[1];

    for (auto c : a) {
        std::cout << (c == max ? second_max : max) << std::endl;
    }
}


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

int main(void)
{
	int a[4], b[4], hit, blow;

	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
		hit = 0;
		blow = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (a[i] == b[j]) {
					if (i == j) hit++;
					else blow++;
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;

struct process{
	char name[11];
	int time;
};

const long LEN=510029;

class queue {
	process data[LEN];
	int head, tail;
public:
	queue(): head(0), tail(0) {}  

	void enqueue(const process&);
	process& dequeue();

	bool isEmpty(){ return head == tail;  }
	bool isFull(){  return (tail+1) % LEN == head;  }
};
void queue::enqueue(const process& p)
{
	if( isFull() ){
		cout<<"full!"<<endl;
		exit(1);
	}
	data[tail+1]=p;
	tail= (tail+1) % LEN;
}
process& queue::dequeue()
{
	if( isEmpty() ){
		cout<<"empty!"<<endl;
		exit(1);
	}
	head= (head+1) % LEN;
	return data[head];
}

int main()
{
	queue q;


	int n;
	short quan;
	cin>>n>>quan;

	process p;



	int passTime=0;

	for( int i=0; !q.isEmpty() || i<n; i++ ) {

		if( i<n ){
			scanf("%s %d", &p.name, &p.time);
		}
		else
			p=q.dequeue();
			


		if( p.time - quan <=0 ){
			passTime+=p.time;
			printf("%s %d\n", p.name, passTime);

		}else{
			passTime+=quan;
			p.time-=quan;
			q.enqueue(p);
		}


	}

}

Measured memory_bytes: 5336
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL kpw(LL x,LL y){
	LL ans = 1,tmp = x;
	while(y){
		if(y & 1) ans = (ans * tmp) % N;
		tmp = (tmp * tmp) % N;
		y >>= 1;
	}
	return ans;
}

LL comb(LL x,LL y){
	LL tmp = 1,ret = 1;
	for(LL i = 1;i <= y;i ++) tmp = (tmp * i) % N;
	tmp = kpw(tmp,N - 2);
	for(LL i = 1;i <= y;i ++) ret = (ret * (x - i + 1)) % N;
	return (ret * tmp) % N;
}

int main() {
	LL n,a,b;
	cin >> n >> a >> b;
	cout << ((kpw(2,n) - comb(n,a) - comb(n,b) - 1) % N + N) % N << endl;
	return 0;
}

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

vector<ll> v;
ll dp[3001][3001];

ll taro(ll start,ll end){
	if(start==end){
		return v[start];
	}
	if(start>end){
		return 0;
	}
	if(dp[start][end]==-1){
		ll a=v[start]+min(taro(start+2,end),taro(start+1,end-1));
		ll b=v[end]+min(taro(start+1,end-1),taro(start,end-2));
		dp[start][end]=max(a,b);
	}	
	return dp[start][end];
}

int main(){
 ll n;
 cin>>n;
 ll sum=0;
 for(ll i=0;i<n;i++){
 	ll d;
 	cin>>d;
 	sum+=d;
	v.push_back(d);
 }
 memset(dp,-1,sizeof dp);
 ll x=0,y=0;
 ll ans=taro(0,n-1);
 cout<<2*ans-sum<<endl;
 
 return 0;
}

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

int gcd(int a,int b);

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

int main(){
  int N;
  cin >> N;
  vector <int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int ans = A[0];
  for(int i=1;i<N;i++){
    ans = gcd(ans,A[i]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 640
while true do
    h,w=gets.chomp.split(" ").map(&:to_i)
    break if h == 0 && w == 0
    (1..h).each do |i|
        line = "#." * ((w+2)/2)
        if i.odd?
            puts line.slice(0, w)
        else
            puts line.slice(1, w)
        end
    end
    puts
end


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

int main(){
  int max = 2e9;
  int x,y,cnt=0;
  cin >> x >> y;
  int a = y-x;
  int b = y+x+1;
  int c = -y-x+1;
  int d =-y+x+2;
  if(a<0) a = max;
  if(b<0) b = max;
  if(c<0) c = max;
  if(d<0) d = max;
  cout << min({a,b,c,d}) << endl;
}

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

int main(){
        double n;
        scanf("%lf", &n);
        vector<pair<ll, ll>> xy(n);
        for(int i=0; i<n; i++) scanf("%lld %lld", &xy[i].first, &xy[i].second);

        double summa = 0;
        for(int i=0; i<n-1; i++){
                for(int j=i+1; j<n; j++){
                        summa += sqrt(pow(xy[i].first-xy[j].first,2) + pow(xy[i].second-xy[j].second, 2));
                }
        }
        printf("%lf\n", summa*2.0/n);
        return 0;
}

Measured memory_bytes: 256
using System;

namespace ForAtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int x = (a > b) ? a : b;
            int y = (a > b) ? b : a;

            string rslt = "";

            for (int i = 0; i < x; i++)
            {
                rslt += y;
            }

            Console.WriteLine(rslt);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)

int a[25], b[25], c[25];
int main() {
    int n; cin >> n;
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];
    for(int i=0; i<n-1; i++) cin >> c[i];
    int res = 0;
    int prev = -1;
    for(int i=0; i<n; i++) {
        int now = a[i] - 1;
        res += b[now];
        if(prev == -1) prev = now;
        else {
            if(now == prev+1) res += c[prev];
            prev = now;
        }
    }
    cout << res << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N), A(M), B(M);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
  }

  vector<vector<int>> g(N);
  for (int i = 0; i < M; ++i) {
    g[A[i] - 1].push_back(B[i] - 1), g[B[i] - 1].push_back(A[i] - 1);
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    bool is_good = true;
    for (size_t j = 0; j < g[i].size(); ++j) {
      if (H[i] <= H[g[i][j]]) {
        is_good = false;
      }
    }

    if (is_good) {
      ++ans;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 9604
x,y = map(int,input().split())
if y > 2*x:
   print(0)
   exit()
elif (2*x-y) % 3 != 0:
    print(0)
    exit()
else:
   h = x - (2*x-y) // 3 * 2
   v = (2*x-y) // 3
   #print(h,v)
# calcurate h+vCv
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb((h+v),h,mod)
print(a)

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    while(true){
        int n, x; cin >> n >> x;
        if(n == 0 && x == 0) break;

        int ans = 0;
        for(int i=1; i<=n; i++){
            for(int j=i+1; j<=n; j++){
                for(int k=j+1; k<=n; k++){
                    if(i+j+k == x) ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	string S;
	cin >> N >> S;
	int tmp = 0;
	int ans = 0;
	rep(loop,1000){
		string T = to_string(tmp);
		int k = T.size();
		rep(j,3-k){
			T = "0" + T;
		}
		int num = 0;
		rep(j,N){
			if(S[j] == T[num]) ++num;
			if(num == 3) break;
		}
		if(num == 3) ++ans;
		++tmp;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    string first=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ",secound="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
    string conversion[32]={"101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001",
    "110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111",
    "1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
    while(getline(cin,str)){
        string Midstream;
        for(int i=0;str[i]!='\0';i++){
            for(int j=0;j<33;j++)if(str[i]==first[j])Midstream+=conversion[j];
        }
        for(int i=0;i<Midstream.size()%5;i++)Midstream+='0';
        for(int i=0,point=0;Midstream[i]!='\0';i++){
            if(i%5==4){
                int num=0;
                for(int j=point,kawa[5]={1,2,4,8,16};j<=i;j++)num+=(Midstream[j]-'0')*kawa[i-j];
                cout<<secound[num];
                point=i+1;
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <string.h>
#define SIZE 100000

int main(){
  int n;
  int i;
  char bit = '0';
  char str[SIZE];
  int result0 = 0,result1 = 0;
  scanf("%s",str);
  n = strlen(str);
  //printf("%s\n",str);
  //printf("%d\n",n);
  for(i = 0;i<n;++i){
    if(bit == str[i]){
      ++result0;
    }else{
      ++result1;
    }
    if(bit == '0'){
      bit = '1';
    }else{
      bit = '0';
    }
  }
  if(result0 < result1){
    printf("%d\n",result0);
  }else{
    printf("%d\n",result1);
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a[3];
  int x;
  int i,j;
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if(a[i]>a[j]){
	x = a[i];
	a[i] = a[j];
	a[j] = x;
      }
    }
  }
  
  printf("%d %d %d\n",a[0],a[1],a[2]);
  
  return(0);
}

Measured memory_bytes: 1796
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <float.h>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main()
{
	int nAddCnt = 0;
	char str[10001];
	memset(str, NULL, sizeof(str));
	cin >> nAddCnt;
	cin >> str;
	
	for (int i = 0; i < strlen(str); i++)
	{
		int nCh = str[i] + nAddCnt;
		if ('Z' < str[i] + nAddCnt)
			str[i] = str[i] + nAddCnt - 26;
		else
			str[i] = str[i] + nAddCnt;
	}
	cout << str;
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, ans, sum, last, cnt;
struct Edge { LL to,cost; };
vector<Edge>vec[100];
string a[1000], b[1000];
map<string, LL>ma;
bool f=0;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main(){
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		ma[a[i]] ++;
	}
	cin >> m;
	rep(i, m) {
		cin >> b[i];
		ma[b[i]]--;
	}
	rep(i, n) {
		ans = max(ma[a[i]], ans);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
	int n, x;
	cin >> n;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		cin >> x;
		int l = 0, r = a.size() - 1;
		while (l <= r) {
			int m = (l + r) / 2;
			if (a[m] < x) {
				r = m - 1;
			} else {
				l = m + 1;
			}
		}
		if (l < a.size()) {
			a[l] = x;
		} else {
			a.push_back(x);
		}
	}
	cout << a.size() << endl;
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>

using namespace std;

int main() {
	int s;
	cin >> s;
	cout << s / 3600 << ':' << (s % 3600) / 60 << ':' << (s % 3600) % 60 << endl;


}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int main() {
    int a,b,c;
    cin >> a >> b >> c;

    if(a+b == c || b+c == a || c+a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  
  vector<int> num(n);
  
  for(int i = 0; i < n-1; i++){
    for(int j = i+1; j < n; j++){
      int a, b, c;
      a = abs(i-j);
      b = abs(i-x) + 1 + abs(j-y);
      c = abs(i-y) + 1 + abs(j-x);
      int mi = min(a, b);
      mi = min(mi, c);
      num[mi]++;
    }
  }
  
  for(int i = 1; i < n; i++){
    cout << num[i] << endl;
  }
  
  return 0;
}

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

string transform_int_to_k(int k, int x)
{
  if (x / k)
  {
    return transform_int_to_k(k, x / k) + to_string(x % k);
  }
  
  return to_string(x % k);
}

int main()
{
    int n, k;
    cin >> n >> k;
  
    string str;
    str = transform_int_to_k(k, n);
  
    cout << str.length() << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
 
    char A[50][50], B[50][50];
 
 
    for(int x = 0; x < N; ++x)
    {
        for(int y = 0; y < N; ++y)
        {
            cin >> A[x][y];
        }
    }
 
    for(int x = 0; x < M; ++x)
    {
        for(int y = 0; y < M; ++y)
        {
            cin >> B[x][y];
        }
    }
 
    bool exist = false;
 
    for(int lx = 0; lx < N; ++lx)
    {
        for(int ly = 0; ly < N; ++ly)
        {
            if(lx + M - 1 >= N or ly + M - 1 >= N)
                continue;
 
            bool match = true;
            for(int x = 0; x < M; ++x)
            {
                for(int y = 0; y < M; ++y)
                {
                    if(A[lx + x][ly + y] != B[x][y])
                        match = false;
                }
            }
            if(match)
                exist = true;
        }
    }
 
    if(exist)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { //Simply store all segment starts and ends 
		//in array list and iterate through all possibilities accordingly
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		long cnt = N/11; //5+6 alternating while N>=11
		cnt*=2;
		N%=11;
		while (N>0) {
			if (cnt%2==0) N-=6;
			else N-=5;
			cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23636
n = int(input())
p = list(map(int,input().split()))
#print(p[:3])
p_cut =[]
cnt = 0

for i in range(n-2):
    p_cut = p[i:i+3]
    #print(p_cut)
    if p_cut[1] != max(p_cut)and p_cut[1] != min(p_cut):
        cnt += 1
print(cnt)

Measured memory_bytes: 9000
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    for(int i=0;i<10000;i++){
        if(a==int (i*0.08) && b==int(i*0.1)){
            cout << i;
            return 0;
        }
    }
    cout << -1;
}

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

int main(){
	int i,n,sum,f;
	char s[1000010];
	scanf("%s",&s);
	n=strlen(s);
	sum=0;f=0;
	for(i=n-1;i>0;i--){
		if(s[i]>='5'){
			if(f==0&&s[i]=='5'){
				f=1;
				sum+=5;
			}
			else{
				if(f)s[i]++;
				sum+='0'+10-s[i];
				s[i-1]++;
				f=0;
			}
		}
		else if(s[i]<'5'){
			f=0;
			sum+=s[i]-'0';
		}
	}
	if(s[i]>='5'){
		if(f==0&&s[i]=='5'){
			f=1;
			sum+=5;
		}
		else{
			if(f)s[i]++;
			sum+='0'+11-s[i];
			f=0;
		}
	}
	else if(s[i]<'5'){
		f=0;
		sum+=s[i]-'0';
	}
	printf("%d",sum);
	return 0;
}


Measured memory_bytes: 1280
X, K, D = map(int, input().split())
X = abs(X)
if K * D < X:
    print(X - K * D)
else:
    if (K - X // D) % 2 == 0:
        print(X - (X // D) * D)
    else:
        print(D - (X - (X // D) * D))


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

int main() {
    int a, b, c;
    
    cin >> a >> b >> c;

    int count_5 = 0;
    int count_7 = 0;
        if(a == 5){
            count_5++;
        }
        if(a == 7){
            count_7++;
        }
        if(b == 5){
            count_5++;
        }
        if(b == 7){
            count_7++;
        }
       if(c == 5){
            count_5++;
        }
        if (c == 7){
            count_7++;
        }
        if(count_5 == 2 && count_7 == 1){
            cout << "YES" << endl; 
        }
        else{
            cout << "NO" << endl;
        }
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

map<char, int> janken;

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

    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;

    map<char, int> mp;
    mp['r'] = p;
    mp['s'] = r;
    mp['p'] = s;

    janken['r'] = 0;
    janken['s'] = 1;
    janken['p'] = 2;

    vector<vector<int>> dp(n+1, vector<int>(3, 0));
    rep(i, k) {
        for (int j = i; j < n; j += k) {
            if (j - k < 0) {
                dp[j][janken[t[j]]] += mp[t[j]];
            }
            else {
                dp[j][janken[t[j]]] += mp[t[j]] + max(dp[j - k][(janken[t[j]] + 1) % 3], dp[j - k][(janken[t[j]] + 2) % 3]);
                dp[j][(janken[t[j]] + 1) % 3] = max(dp[j - k][(janken[t[j]]) % 3], dp[j - k][(janken[t[j]] + 2) % 3]);
                dp[j][(janken[t[j]] + 2) % 3] = max(dp[j - k][(janken[t[j]]) % 3], dp[j - k][(janken[t[j]] + 1) % 3]);;
            }
        }
    }

    int res = 0;
    REP(i, n - k, n) {
        res += max({dp[i][0], dp[i][1], dp[i][2]});
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5840
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

void distance(vector<int> x, vector<int> y, int p)
{
	double sum = 0;
	int n = x.size();
	for(int i = 0; i < n; i++){
		sum += pow(abs(x[i] - y[i]), p);
	}
	sum = pow(sum, 1.0/p);
	cout << sum << endl;
}
void distanceX(vector<int> x, vector<int> y)
{
	double max = 0;
	int n = x.size();
	for(int i = 0; i < n; i++){
		if(abs(x[i] - y[i]) > max){
			max = abs(x[i] - y[i]);
		}
	}
	cout << max << endl;
}
int main(void)
{	
	cout << fixed << setprecision(5);//?¨????

	int n;
	cin >> n;
	
	vector<int> x(n);
	vector<int> y(n);
	
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	for(int i = 0; i < n; i++){
		cin >> y[i];
	}
	
	for(int i = 1; i <= 3; i++){
		int p = i;
		distance(x, y, p);
	}
	distanceX(x, y);

	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, A, B;
    ll count;
    cin >> N >> A >> B;
    count = (B * (N - 1) + A) - (A * (N - 1) + B) + 1;
    cout << max(0LL, count) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner teclado = new Scanner(System.in);
		int n = teclado.nextInt();
		int x = teclado.nextInt();
		int quant = 0;
		int v[] = new int[n];
		int r[] = new int[n+1];
		for (int y = 0; y < n; y++) {
			v[y] = teclado.nextInt();
		}
		
		r[0] = 0;
		
		for (int y = 1; y <= n; y++) {
			int z = y - 1;
			r[y] = r[z] + v[z];
		}
		
		for (int y = 0; y <= n; y++) {
			if (r[y] <= x) {
				quant = quant + 1;
			}
		}
		
		System.out.println(quant);
		
		teclado.close();
		
	}
}

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

int P[10010]; // 0から10000までの頂点を取り扱い可能
void inti(int N){ // 初期化　初めはすべての頂点ははバラバラ
  for(int i=0; i<N; i++){
    P[i] = i;
  }
}
int root(int a){ // root 親をたどる関数
  if(a==P[a]){
    return a;
  }
  else{
    return root(P[a]);
  }
}
bool is_same_set(int a,int b){ // aとbが同値類（同じグループ）か判定
  return root(a) == root(b);
}
void unite(int a, int b){ // aとbを同一グループにまとめる
  P[root(a)] = root(b);
}

int main(){
  int n, q, x, y, z;
  cin >> n >> q;
  inti(10010);
  for(int i=0; i<q; i++){
    cin >> z >> x >> y;
    if(z == 0){
      unite(x, y);
    }
    else{
      cout << is_same_set(x, y) << endl;
    }

  }
  return 0;
}


Measured memory_bytes: 3128
a, b = map(int,input().split())
i = 0
ans = -1
while True:
    if int(i*0.080) == a and int(i*0.10) == b:
        ans = i
        break
    elif int(i*0.080) > a or int(i*0.10) > b:
        break
    i += 1
print(ans)


Measured memory_bytes: 2940
N = int(input())
F = [int(input().replace(" ", ''), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

maxv = -2<<100
for i in range(1, 1<<10):
    maxv = max(maxv, sum(p[bin(f&i).count('1')] for f, p in zip(F, P)))
print(maxv)


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

typedef long long int ll;
ll a, b, c, d;

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

    cin >> a >> b >> c >> d;
    if((a < 0 && b < 0 && c > 0 && d > 0) || (a > 0 && b > 0 && c < 0 && d < 0)) cout << min(abs(a), abs(b)) * min(abs(c), abs(d)) * -1 << '\n';
    else cout << max(max(a * c, a * d), max(b * c, b * d)) << '\n';

    return 0;
}

Measured memory_bytes: 3652