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

using namespace std;

int main() {
  string s;
  cin >> s;
  int l = s.size();
  int f[2] = {-1, -1};
  for (int i = 0; i < l - 1; i++) {
    if (s[i] == s[i+1]) {
      f[0] = i+1;
      f[1] = i+2;
      break;
    }
    if (i != l-2 && s[i] == s[i+2]){
      f[0] = i+1;
      f[1] = i+3;
      break;
    }
  }
  cout << f[0] << " " << f[1] << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int mo2 = 998244353;
constexpr int  mod = mo;
constexpr int inf = 1<<30;

int main(){
    int a;
    string s;
    cin>>a>>s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}



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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//------------------------------------------------------------------

int main(void){
  int n;
  cin >> n;
  v2(d, n, 2, 0);
  rep(i,n){
    cin >> d[i][0] >> d[i][1];
  }
  bool ok=false;
  rep(i,n-2){
    if(d[i][0]==d[i][1] && d[i+1][0]==d[i+1][1] && d[i+2][0]==d[i+2][1]){
      ok=true;
    }
  }

  prt(ok ? "Yes" : "No");
}


Measured memory_bytes: 3636
a,b=map(int,input().split())
c = []
for i in range(a):
    c.append(list(map(int,list(input().split()))))
    c[i].append(sum(c[i]))
e=[]
for i in range(b):
    total=0
    for j in range(a):
        total+=c[j][i]
    e.append(total)
e.append(sum(e))
c.append(e)
"""
for i in range(a+1):
    for j in range(b+1):
        print(c[i][j],end=" ")
    print()
"""
for row in range(0,a+1):
    print("%d"%(c[row][0]),end="")
    for col in range(1,b+1):
        print(" %d"%(c[row][col]),end ="")
    print()


Measured memory_bytes: 6240
import java.util.*;

class Main {
	
	public static boolean BinarySearch (ArrayList<Integer> list, int p) {
		
		int low = 0;
		int high = list.size() - 1;
		int middle = (low + high) / 2;
		
		while (low <= high) {
			if (list.get(middle) == p) {
				return true;
			} else if (list.get(middle) < p) {
				low = middle + 1;
			} else {
				high = middle - 1;
			}
			middle = (low + high) / 2;
		}
		
		return false;
		
	}
	
	public static ArrayList<Integer> sieve (int n) {
		
		ArrayList<Integer> ret = new ArrayList<Integer>();
		boolean[] isPrime = new boolean[n + 1];
		
		Arrays.fill(isPrime, true);
		
		for (int i = 4; i < n; i += 2)
			isPrime[i] = false;
		
		for (int i = 3; i * i <= n; i += 2) {
			for (int j = 3; i * j < n; j += 2)
				isPrime[i * j] = false;
		}
		for (int i = 2; i < n; i++) {
			if (isPrime[i]) ret.add(i);
		}
		return ret;
		
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while (true) {		
			int num = sc.nextInt();
			if (num == 0) break;
			ArrayList<Integer> primes = sieve(num);
			int cnt = 0;
			for (int p : primes)
				if (BinarySearch(primes,num - p)) {
					cnt++;
				}
			cnt /= 2;
			if (BinarySearch(primes,num / 2)) cnt++;
			System.out.println(cnt);
		}
		
	}
	
}

Measured memory_bytes: 17000
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        a=max(a,c);
        b=min(b,d);
        d=b-a;
        if(d<0) printf("0\n");
        else printf("%d\n",d);
    }
    return 0;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

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


void solve(){
  string S;
  cin >> S;

  int count[100000 + 5] = {};
  char pre = 'R';
  int L = 0;
  int R = 0;
  int pos = 0;
  rep(i, S.size()){
    if(S[i] == 'R') R++;
    else L++;

    if(pre == S[i]) continue;

    if(S[i] == 'L'){
      pos = i;
      count[pos] += R / 2;
      count[pos - 1] += R / 2 + R % 2;
      R = 0;
      pre = 'L';
    }else{
      count[pos] += L / 2 + L % 2;
      count[pos - 1] += L / 2;
      L = 0;
      pre = 'R';
    }
  }
  count[pos] += L / 2 + L % 2;
  count[pos - 1] += L / 2;

  rep(i, S.size() - 1){
    cout << count[i] << " ";
  }
  cout << count[S.size() - 1] << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;	cin >> n;
  vector<int>	p(n);
  for(int i=0;i<n;i++)	cin >> p[i];
  
  vector<int>	q=p;
  sort(q.begin(),q.end());
  
  int cnt=0;
  for(int i=0;i<n;i++){
    if(p[i]!=q[i])	cnt++;
  }
  if(cnt==2||cnt==0)	cout << "YES";
  else	cout << "NO";
}

Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
string a,b;
int main()
{
    cin>>a;
    for(int i=a.size()-1;i>=0;i--){
        if(a[i]=='p') b+='q';
        else if(a[i]=='q') b+='p';
        else if(a[i]=='b') b+='d';
        else b+='b';
    }
    if(a==b) printf("Yes");
    else printf("No");
    return 0;
}


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

int main() {
	long long N, K;
	cin >> N >> K;
	if (K == 1 || N == K) {
		cout << "0" << endl;
		return 0;
	}
	long long ans;
	if (N > K) {
		long long tmp = N / K;
		tmp = N - K * tmp;
		ans = min(tmp, K - tmp);
	} else {
		ans = min(N, K - N);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,a,b,c,d;
  int A[100][100];
  scanf("%d", &a);

  for(i = 0; i < a; i++){
    for(j = 0; j < a; j++){
      A[i][j] = 0;
    }
  }

  for(i = 0; i < a; i++){
    scanf("%d%d", &b, &c);
    for(j = 0; j < c; j++){
      scanf("%d", &d);
      A[b-1][d-1] = 1;
    }
  }

  for(i = 0; i < a; i++){
    for(j = 0; j < a; j++){
      if(j>0) printf(" ");
      printf("%d", A[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2112
#include <stdio.h>

int main(){
    int a[3], k, max, maxi = 0, sum = 0;
    scanf("%d %d %d %d", a, a + 1, a + 2, &k);

    max = a[0];
    for(int i = 0; i < 3; i++){
        if(max < a[i]){
            max = a[i];
            maxi = i;
        }
    }

    max = max << k;

    a[maxi] = max;
    for(int i = 0; i < 3; i++){
        sum += a[i];
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const double pi = 3.141592653589793;

int main() { 
  int a, b, h, m;
  double ans;
  double c;
  cin >> a >> b >> h >> m;
  double a_angle = h * 30 + 0.5 * m;
  double b_angle = 6 * m;
  double angle = a_angle - b_angle;
  if (angle < 0) {
    angle = angle * (-1);
  }
  if (angle > 180) {
    angle = 360 - angle;
  }
  c = angle / 180.0;
  ans = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(pi * c));
  cout << fixed;
  cout << setprecision(20) << ans << endl;
  return 0;
}

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define INF 1e9
// constexpr ll INF = 1LL << 60;

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  REP(i, H){
    cin >> S[i];
  }   
  vector<vector<int>> c(H, vector<int>(W));
  int mans = 0;
  REP(y, H){
    REP(x, W){
      REP(i, H){
        REP(j, W){
          c[i][j] = S[i][j]-'0';
        }
      }
      c[y][x] = -1;
      REP(j, W){
        REPR(i, H-2){
          int h = i;
          if(c[i][j] == -1) continue;
          while(h+1 < H && c[h+1][j] ==-1){
            c[h+1][j] = c[h][j];
            c[h][j] = -1;
            h++;
          }
        }
      }
      int beki = 1;
      bool deleted = true;
      int ans = 0;
      while(deleted){
        deleted = false;
        int value = 0;
        REP(i, H){
          REP(j, W){
            if(c[i][j]==-1) continue;
            int left = j+1;
            while(left < W && c[i][j] == c[i][left]){
              left++;
            }
            if(left-j >= K){
              deleted = true;
              value += c[i][j]*(left-j);
              FOR(k, j, left){
                c[i][k] = -1;
              }
            }
          }
        }
        if(deleted){
          ans += value * beki;
          REP(j, W){
            REPR(i, H-2){
              int h = i;
              if(c[i][j] == -1) continue;
              while(h+1 < H && c[h+1][j] ==-1){
                c[h+1][j] = c[h][j];
                c[h][j] = -1;
                h++;
              }
            }
          }
        }
        beki *= 2;
      }
      mans = max(ans, mans);
    }
  }
  cout << mans << endl;
  return 0;
}



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

#define ft first
#define sd second
#define sz(x) ((int)x.size())

using namespace std;

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






int q;


int main() {
	cin >> q;
	int x, y;
	while (q--) {
		cin >> x >> y;
		ll z = (ll)x * y, f = (ll)ceil(sqrt(z)), ans;
		if (f * f >= z)
			f--;
		ans = 2 * f;
		if (f * (f + 1) >= z)
			ans--;
		cout << ans - 1 + (x == y) << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,y;
    cin>>n>>y;
    y/=1000;
    bool oto=true;
    bool aaa=true;
    for (int i = 0; i <= n; i++) {
	for (int j = 0; j <= n - i; j++) {
		if(aaa){for (int k = 0; k <= n - i - j; k++) {
			if (10 * i + 5 * j + k == y&&i+j+k==n) {
				cout << i << " " << j << " " << k;
				oto = false;
				aaa=false;
			}
		}
	}
	}
}
if (oto) cout << -1 << " " << -1 << " " << -1;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int Q; cin >> Q;
    string A, B;
    bool turn = false;
    while(Q--) {
        int q; cin >> q;
        if(q == 1) {
            turn = !turn;
            continue;
        }
        int F; char c;
        cin >> F >> c;
        if(F == 2 && !turn) B += c;
        if(F == 1 && !turn) A = c + A;
        if(F == 2 && turn) A = c + A;
        if(F == 1 && turn) B += c;
    }
    string K = A + S + B;
    if(turn) {
        reverse(K.begin(), K.end());
    }
    
    
    cout << K << endl;

    return 0;
}
// ASB

// BSA



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  string s; cin >> s;

  int cnt = 0, pre = 0;
  for (int i = 0; i < N; ++i) {
    if (s[i] == '(') { ++cnt; }
    else if (s[i] == ')') {
      if (cnt == 0) { ++pre; }
      else { --cnt; }
    }
  }
  string ans = string(pre, '(') + s + string(cnt, ')');
  printf("%s\n", ans.c_str());
  return 0;
}


Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Sat Mar 14 11:44:01 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n, a = nin(2)
print(n * n - a)

Measured memory_bytes: 3316
# https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_b

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    n, k = map(int, input().split())
    al = list(map(int, input().split()))
    down1 = 0
    for i in range(n-1):
        for j in range(i+1,n):
            if al[i] > al[j]:
                down1 += 1

    down2 = 0
    for i in range(n):
        for j in range(n):
            if al[i] > al[j]:
                down2 += 1

    mod = 10**9 + 7
    print((down1 * k + down2 * k * (k - 1) // 2) % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42092
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

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

	long double ans = 0;

	for (size_t i = 1; i <= n; i++)
	{
		long double tmp = 1;

		int score = i;
		int c = 0;
		for (; score < k; c++)
		{
			score <<= 1;
			tmp /= 2;
		}
		ans += tmp;
	}
	ans /= n;
	cout << std::setprecision(10) << ans << endl;
	return 0;
}


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

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

  if(c == "a" || c == "e" || c == "i" || c == "o" || c =="u") {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

struct Sugar {
  int a, b;
  double con;
};

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  Sugar s = {0, 0, 0};
  FOR(i, 0, 31) FOR(j, 0, 31) {
    int a = 100 * (A * i + B * j);
    if (a == 0) continue;
    FOR(k, 0, ceil((F - a) / C)) FOR(m, 0, ceil((F - a) / D)) {
      int b = C * k + D * m;
      double con = (double)b / (a + b) * 100.0;
      if (b > a / 100 * E || a + b > F) continue;
      if (con > s.con) s = {a, b, con};
    }
  }
  if (s.con == 0) s.a = 100 * A;

  cout << s.a + s.b << " " << s.b << endl;
}

Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]

    
def main():
    A, B, K = read_values()
    A2 = max(0, A - K)
    K -= A - A2
    B2 = max(0, B - K)

    print(A2, B2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int dp[100010];

int main() {

	int n; cin >> n;

	for (int i = 0; i < 100010; i++) {
		dp[i] = INF;
	}

	dp[0] = 0;

	//dp[i円払った]状態の最低枚数

	//コインは無限に使える。
	//更新の向きを気にしなくていい。

	
		//6べきを一つとってくる
		for (int power = 1; power <= n; power = power * 6) {
			for (int i = 0; i+power<=n; i++) {
				dp[i + power] = min(dp[i + power], dp[i] + 1);
			}
		}

		//9べきの遷移
		for (int power = 1; power <= n; power = power * 9) {
			for (int i = 0; i + power <= n; i++) {
				dp[i + power] = min(dp[i + power], dp[i] + 1);
			}
		}

		cout << dp[n] << endl;
	
	return 0;
}

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

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(  int.Parse(Console.ReadLine())<3200?"red" :Console.ReadLine());
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;
    if (K == 1) cout << 0 << endl;
    else cout << N - K << endl;
    return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

ll sm[MAX_N];

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

  CIN(N);
  vector< ll > A(N);
  REP(i, N) {
    cin >> A[i];
  }

  sort(ALL(A));

  REP(i, N) {
    sm[i] = A[i];
  }

  REP(i, N) {
    sm[i + 1] += sm[i];
  }
  
  int ans = N;
  RREP(i, N - 1) {
    
    if (2ll * sm[i] < A[i + 1]) {
      ans = min(N - i - 1, ans);
      break;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1792
// AOJ ALDS1_7_A Rooted Trees
// 2018.5.1 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) { pc('0'); return; }
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}

void sout(char *s) { while (*s) pc(*s++); }

typedef struct { int parent; int depth; int k; int *c; } TREE;
TREE tbl[100002];

void calc_depth(int node, int d)
{
	int i;
	tbl[node].depth = d;
	for (i = 0; i < tbl[node].k; i++) calc_depth(tbl[node].c[i], d+1);
}

int main()
{
	int n, i, j, k, id;
	int root;

	n = in();
	for (i = 0; i < n; i++) {
		id = in(), tbl[id].k = k = in();
		tbl[id].c = malloc(k << 2);
		for (j = 0; j < k; j++) {
			int _c = in();
			tbl[_c].parent = id+1;
			tbl[id].c[j] = _c;
		}
	}
	for (root = 0; root < n; root++) {
		if (tbl[root].parent == 0) break;
	}
	calc_depth(root, 0);

	for (i = 0; i < n; i++) {
		sout("node "), out(i);
		sout(": parent = ");
		if (i == root) sout("-1");
		else out(tbl[i].parent - 1);
		sout(", depth = "), out(tbl[i].depth);
		sout(", ");
		if (i == root)          sout("root");
		else if (tbl[i].k == 0) sout("leaf");
		else                    sout("internal node");
		sout(", [");
		if (tbl[i].k > 0) {
			out(tbl[i].c[0]);
			for (j = 1; j < tbl[i].k; j++) {
				pc(','), pc(' '), out(tbl[i].c[j]);
			}
		}
		sout("]\n");
	}
	return 0;
}


Measured memory_bytes: 7476
import sys

N, L = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))

for i in range(N-1):
    if A[i] + A[i+1] >= L:
        print("Possible")
        for j in range(1, i+1):
            print(j)
        for j in range(i+1, N)[::-1]:
            print(j)
        sys.exit()

print("Impossible")

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
const int N=200;
int tu[N][N];
int n,m,t;
int main()
{
    scanf("%d%d%d",&n,&m,&t);
    int x=1,y=1;
    for(int i=1,a;i<=t;i++){
        scanf("%d",&a);
        for(int j=1;j<=a;j++){
            if(x%2==0&&y==0){
                x=x+1,y=1;
                tu[x][y++]=i;
            }
            else if(x%2==1&&y==m+1){
                x=x+1,y=m;
                tu[x][y--]=i;
            }
            else{
                if(x%2==0)tu[x][y--]=i;
                else tu[x][y++]=i;
            }
        }
    }
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
        cout<<tu[i][j];
        if(j==m)cout<<endl;
        else cout<<" ";
    }
}


Measured memory_bytes: 384
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong();
        long r = sc.nextLong();
        long min = Long.MAX_VALUE;
        int cnt = 0;
//        if(r-l>=2018) {
//            System.out.println(0);
//            return;
//        }
        for(long i = l; i<Math.min(r,l+2018); i++) {
            cnt=0;
            for(long j = i+1; j<=r; j++) {
                cnt++;
                if(cnt>=2019) break;
                min = Math.min((i*j)%2019, min);
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		out(1110 - ni());

	}

	/*
	 * 以下メソッド集
	 */

	static int abcount(String str) {
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if ("AB".equals(str.substring(i, i + 2))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static double min(double d, double e) {
		return Math.min(d, e);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 21076
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            ArrayList<String> list = new ArrayList<String>();
            String[][] name = new String[n][10];
            for(int i=0; i<n; i++){
                String s = sc.next();                
                String[] line = s.split(":");
                list.add(line[0]);
                String[] line2 = line[1].substring(0,line[1].length()-1).split(",");
                for(int j=0; j<line2.length; j++) name[i][j] = line2[j];
            }

            HashSet<String> set1 = new HashSet<String>();
            HashSet<String> set2 = new HashSet<String>();
            Queue<String> q = new LinkedList<String>();
            for(int i=0; i<10; i++){
                if(name[0][i]!=null){
                    q.add(name[0][i]);
                }
            }

            while(q.size()>0){
                String po = q.poll();
                if(list.contains(po) && set2.add(po)){
                    for(int i=0; i<10; i++){
                        int idx = list.indexOf(po);
                        if(name[idx][i]!=null){
                            q.add(name[idx][i]);
                        }
                    }
                }else if(!list.contains(po)){
                    set1.add(po);
                }
            }

            System.out.println(set1.size());
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 38636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define FINISH cout<<"No"<<endl;return 0

int main(){
	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0;i < N;i++)cin >> H[i];
	int mn = INT32_MAX;
	for (int i = N - 1;i >= 0;i--) {
		if (mn > H[i])mn = H[i];
		else if (mn < H[i]) {
			if (H[i] - mn > 1) {
				FINISH;
			}
		}
	}
	cout << "Yes" << endl;
}

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

int main() {
	int n, a, b, temp; cin >> n >> a >> b; vector<int> ans;
	for (int i = 1; i < (a < b ? b : a); i++)
		if (a % i == 0 && b % i == 0) ans.push_back(i);
	if (n == 3) {
		cin >> temp;
		for (int i = 0; i < ans.size(); i++)
			if (temp % ans[i] != 0) ans.erase(ans.begin() + i);
	}
	for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<cstring>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

#define MAX_N 300000

int game[MAX_N][10], x[MAX_N][10][3];
int score[MAX_N][10];
int sum[MAX_N], cust[MAX_N];
int n, cnt, sum2;

pair<int, int>bowling[MAX_N];

int main() {
	while (true) {
		//memset.
		memset(game, 0, sizeof(game));
		memset(x, 0, sizeof(x));
		memset(score, 0, sizeof(score));
		memset(sum, 0, sizeof(sum));
		memset(cust, 0, sizeof(cust));
		memset(bowling, 0, sizeof(bowling));

		cin >> n;
		if (n == 0) {
			break;
		}

		for (int i = 0; i < n; i++) {
			cin >> cust[i];

			for (int j = 0; j < 10; j++) {
				//cin.
				cnt = 0;
				while (true) {
					cin >> x[i][j][cnt];

					//1-9 Frame.
					if (j < 9) {
						if (x[i][j][cnt] == 10) {
							goto Exit;
						}
						if (cnt == 1) {
							goto Exit;
						}
					}

					//10 Frame.
					else {
						if (cnt == 1) {
							if (x[i][j][0] != 10 && x[i][j][0] + x[i][j][1] != 10) {
								goto Exit;
							}
						}
						else if (cnt == 2) {
							goto Exit;
						}
					}

					//End Throw.
					cnt++;
				}
			Exit:;
				game[i][j] = cnt + 1;
			}
		}
		
		//check.
		for (int i = 0; i < n; i++) {

			//sum.
			for (int j = 0; j < 10; j++) {
				sum2 = 0;
				for (int k = 0; k < game[i][j]; k++) {
					sum2 += x[i][j][k];
				}

				//1-9 Frame.
				if (j < 9) {
					//Normal.
					if (sum2 < 10) {
						score[i][j] = sum2;
					}

					//Spair.
					else if (game[i][j] == 2) {
						score[i][j] = 10 + x[i][j + 1][0];
					}

					//Strike!!
					else {
						if (game[i][j + 1] == 1) {
							score[i][j] = 10 + x[i][j + 1][0] + x[i][j + 2][0];
						}
						else {
							score[i][j] = 10 + x[i][j + 1][0] + x[i][j + 1][1];
						}
					}
				}

				//10 Frame.
				else {
					score[i][j] = sum2;
				}
			}

			//Calc.
			for (int j = 0; j < 10; j++) {
				sum[i] += score[i][j];
			}
		}

		//pair-input.
		for (int i = 0; i < n; i++) {
			bowling[i] = make_pair(sum[i], 1000000000 - cust[i]);
		}

		//sort.
		sort(bowling, bowling + n, greater<pair<int, int> >());

		//print.
		for (int i = 0; i < n; i++) {
			cout << 1000000000 - bowling[i].second << ' ' << bowling[i].first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 64452
def f(s):
  lst = s.split()
  return lst[0], int(lst[1])

N = int(input())
S = []
T = []
for i in range(N):
  s, t = f(input())
  S.append(s)
  T.append(t)

X = str(input())

if X in S:
  index = S.index(X)
else:
  print(o)

sum = 0
for i in range(index+1, N):
  sum += int(T[i])

print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
  while (true) {
    std::map<char, char> table;
    int n, m;
    string s;

    cin >> n;

    if (n == 0) break;

    for (int i = 0; i < n; ++i) {
      char k, v;
      cin >> k;
      cin >> v;
      table.insert(make_pair(k, v));
    }

    cin >> m;

    for (int i = 0; i < m; ++i) {
      char c;
      cin >> c;
      std::map<char, char>::iterator it = table.find(c);

      if (it == table.end()) {
        s.push_back(c);
      } else {
        s.push_back(it->second);
      }
    }
  
    cout << s << endl;
  }

  return 0;
}



Measured memory_bytes: 3248
# -*- coding: utf-8 -*-
import sys

N,K,*A = map(int, sys.stdin.buffer.read().split())

for _ in range(K):
  Anext = [0 for _ in range(N+1)]
  for i in range(N):
    Anext[max(0,i-A[i])] += 1
    Anext[min(N,i+A[i]+1)] -= 1
  cumsum = 0
  for i in range(N):
    cumsum += Anext[i]
    A[i] = cumsum
  if min(A)==N:
    break

print(' '.join([str(a) for a in A]))

Measured memory_bytes: 172192
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>

using namespace std;

typedef pair<int, int> P;
#define FOR(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
#define P(p) cout<<(p)<<endl
#define _1 first
#define _2 second
#define pb push_back
#define bigmod 1000000007
#define INF 1050000000

const int maxn = 1e5 + 10;
vi G[maxn];
int n, m, u, v;
int a;

int main() {
	C(n);
	string s1, s2;
	C2(s1, s2);

	if (n == 1) {
		P(3);
		return 0;
	}
	
	int pre;
	ll ans;
	bool pass = true;
	if (s1[0] == s1[1]) pre = 0, ans = 6;
	else pre = 1, ans = 3, pass = false;

	FOR(i, 1, n) {
		if (pass) {
			pass = false;
			continue;
		}

		if (s1[i] == s1[i + 1] && pre == 0) //ヨコヨコ
		{
			pass = true;
			ans *= 3;
		}
		else if (s1[i] == s1[i + 1] && pre == 1) //タテヨコ
		{
			pre = 0;
			ans *= 2;
			pass = true;
		}
		else if (s1[i] != s1[i + 1] && pre == 0) //ヨコタテ
		{
			pre = 1;
		}
		else if (s1[i] != s1[i + 1] && pre == 1) //タテタテ
		{
			ans *= 2;
		}
		ans = ans % bigmod;		
		//P(ans);
	}

	P(ans);
	return 0;
}

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

int main(){
  int n,d,ans=0; cin>>n >>d;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>x[i][j];
    }
  }
  
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      int dis=0;
      for(int k=0;k<d;k++){
        dis+=abs(x[i][k]-x[j][k])*abs(x[i][k]-x[j][k]);
      }
      for(int i=1;i*i<=16000;i++){
        if(dis==i*i){
          ans++;
          break;
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define R register
#define ll long long
using namespace std;

ll base[40];
int D;
int ans=0;
int st[40];

inline void dfs(int now,int len,ll sum)
{
	if(now==len/2+1)
	{
		if(sum!=D) return;
		int tans=st[1]>=0?(9-st[1]):(9+st[1]);
		for(R int i=2;i<now;i++) tans=tans*(st[i]>=0?(10-st[i]):(10+st[i]));
		ans+=len&1?tans*10:tans;
		return ;
	}
	if(sum+10ll*(base[len-now]-base[now-1])<D) return ;
	if(sum-10ll*(base[len-now]-base[now-1])>D) return ;
	for(R int ss=(now==1?-8:-9);ss<=9;ss++)
	{
		st[now]=ss;
		dfs(now+1,len,sum+st[now]*(base[len-now]-base[now-1]));
	}
	return ;
}

int main()
{
	scanf("%d",&D);
	base[0]=1;
	for(R int i=1;i<=18;i++) base[i]=base[i-1]*10;
	for(R int i=1;i<=18;i++) dfs(1,i,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main(void){
    int n,asum=0;
    cin>>n;
    int a[n] = {};
    for(int i=0;i<n;i++){
        cin>>a[i];
        asum += a[i];
    }
    int y;
    if(asum>0) y = ( asum + n/2.0)/n;
    else y = ( asum - n/2)/n;
    int ans = 0;
    for(int i=0;i<n;i++) ans += (a[i]-y)*(a[i]-y);
    cout<<ans<<endl;
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned int uint;
typedef pair<int,int> pii;
//-------------------------------------------------------------------LYYY↓
namespace LYYY{
	int rd()
	{
		int s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	LL rdl()
	{
		LL s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	void wt(int x)
	{
		if(x>=10) wt(x/10);
		putchar(x%10+48);
	}
	void WT(int x)
	{
		if(x<0) x=-x,putchar(45);
		wt(x);
	}
	void wtl(LL x)
	{
		if(x>=10) wtl(x/10);
		putchar(x%10+48);
	}
	void WTL(LL x)
	{
		if(x<0) x=-x,putchar(45);
		wtl(x);
	}
}using namespace LYYY;
//-------------------------------------------------------------------bianliang↓
const int maxn=555555;
char ss[maxn];
int A[maxn],f[maxn];
//-------------------------------------------------------------------hanshu↓
//-------------------------------------------------------------------main()↓
int main()
{
	scanf("%s",ss+1);
	int N=strlen(ss+1);
	A[0]=0,ss[0]='<';
	for(int i=N;i;--i)if(ss[i]=='>') f[i]=f[i+1]+1;
	for(int i=1;i<=N;++i)
	{
		if(ss[i]=='<') A[i]=A[i-1]+1;
		else if(ss[i]=='>')
		{
			A[i]=f[i]-1;
			if(ss[i-1]=='<') A[i-1]=max(A[i-1],f[i]);
		}
	}
	LL ans=0;
	for(int i=0;i<=N;++i) ans+=A[i];
	WTL(ans);
	return 0;
}

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

#define ASORT(arr, n)          sort(arr,arr+n)
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for (int i=0; i<n; i++)
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI                  acos(-1.0)

using namespace std;

typedef long long              ll;
typedef unsigned long long     ull;
typedef vector<int>            vi;

const double eps = 1e-9;


int main()
{
  fastIO();
	ll k , a, b ;
	cin>>k>>a>>b;
	for(int i=a; i<=b; i++)
	{
		if(i%k==0)
		{
			cout<<"OK"<<'\n';
		//	break;
		return 0;
		}
	
	}
			cout<<"NG"<<'\n';
	


 return 0;
 }


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C;
  cin >> A>>B>>C;
  int min=1000000;

  //処理
  //123 132 213 231 312 321全部比較すればよい
  //ABC
  min=abs(B-A)+abs(C-B);
  
  //ACB
  if(abs(C-A)+abs(B-C)<min){
    min=abs(C-A)+abs(B-C);
  }
  //213
  if(abs(A-B)+abs(C-A)<min){
    min=abs(A-B)+abs(C-A);
  }
  //231
  if(abs(C-B)+abs(A-C)<min){
    min=abs(C-B)+abs(A-C);
  }
  //312
  if(abs(A-C)+abs(B-A)<min){
    min=abs(A-C)+abs(B-A);
  }
  //321
  if(abs(B-C)+abs(A-B)<min){
    min=abs(B-C)+abs(A-B);
  }
  
  cout<<min<<endl;
}


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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

class Seg {
public:
    int n;
    vector<ll> da, db;
    Seg(int _n) {
        n = 1;
        while (n < _n) n *= 2;
        da.resize(n*2-1, 0);
        db.resize(n*2-1, 0);
    }
    void add(int l, int r, ll x) {
        _add(l, r, 0, 0, n, x);
    }
    void _add(int l, int r, int k, int tl, int tr, ll x) {
        if (l <= tl && tr <= r) da[k] += x;
        else if (tl < r && l < tr) {
            db[k] += (min(r, tr) - max(l, tl)) * x;
            _add(l, r, k*2+1, tl, (tl+tr)/2, x);
            _add(l, r, k*2+2, (tl+tr)/2, tr, x);
        }
    }
    ll sum(int l, int r) {
        return _sum(l, r, 0, 0, n);
    }
    ll _sum(int l, int r, int k, int tl, int tr) {
        if (r <= tl || tr <= l) return 0;
        if (l <= tl && tr <= r) {
            return da[k] * (tr-tl) + db[k];
        }
        ll sl = _sum(l, r, k*2+1, tl, (tl+tr)/2);
        ll sr = _sum(l, r, k*2+2, (tl+tr)/2, tr);
        return (min(r, tr) - max(l, tl)) * da[k] + sl + sr;
    }
};

int main() {
    ll N, D, A;
    cin >> N >> D >> A;
    vector<pair<ll,ll>> fox;
    ll X, H;
    for (int i=0; i<N; ++i) {
        cin >> X >> H;
        fox.push_back(make_pair(X, H));
    }
    sort(fox.begin(), fox.end());

    Seg sg(N);
    ll res = 0;
    for (int l=0; l<N; ++l) {
        ll hp = max(0LL, fox[l].second - sg.sum(l, l+1));
        ll t = (hp+A-1) / A;
        if (0 < t) {
            res += t;
            auto it = lower_bound(fox.begin(), fox.end(), make_pair(fox[l].first+D*2+1, -LLONG_MAX));
            int r;
            if (it == fox.end()) {
                r = N;
            } else {
                r = it-fox.begin();
            }
            sg.add(l, r, A*t);
        }
    }
    cout << res << endl;

    return 0;
}

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

int main() {
  int N, Y; cin >> N >> Y;
  int x = -1, y = -1, z = -1;
  bool flag = false;
  rep2(i, 0, N+1) {
    rep2(j, 0, N+1-i) {
      if (Y - (10000 * i + 5000 * j) == 1000 * (N - i - j)) {
        x = i;
        y = j;
        z = N - i - j;
        flag = true;
        break;
      }
      if (flag) {
        break;
      }
    }
  }
  if (flag) {
    cout << x << " " << y << " " << z << endl;
  }
  else {
  cout << x << " " << y << " " << z << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func scanNums(len int) []int {
	var num int
	var nums []int
	for i:=0; i <len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return nums
}

func checker(n int, nums []int) string {
	v := float64(nums[1]) / float64(n)
	i := int(math.Floor(v))

	if nums[0] <= i*n && i*n <= nums[1] && i >= 1{
		return "OK"
	}
	return "NG"

}

func main() {
	var N int
	fmt.Scan(&N)
	nums:= scanNums(2)
	result := checker(N, nums)
	fmt.Println(result)
}

Measured memory_bytes: 1756
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int N,W,v[200000],w[200000],dp[101][10001];
    cin>>N>>W;
    for(int i=0;i<N;i++) cin>>v[i]>>w[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j>=w[i]) dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
            else dp[i+1][j]=dp[i][j];
        }
    }
    cout<<dp[N][W]<<endl;
}


Measured memory_bytes: 7008
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int dp[30];
Int fib(Int n,Int x,Int y,int z=1){
  if(n<0) return 0;
  if(n<=z) return 1;
  if(dp[n]<0) dp[n]=fib(n-x,x,y,z)+fib(n-y,x,y,z);
  return dp[n];
}
signed main(){
  Int h,w;
  while(cin>>h>>w,h){
    memset(dp,-1,sizeof(dp));
    if((h*w)&1){
      cout<<0<<endl;
      continue;
    }
    
    if(h>w) swap(h,w);
    if(h==1){
      cout<<1<<endl;
      continue;
    }
    if(h==2){
      cout<<fib(w,h-1,h+1)+fib(w-h,h-1,h+1)<<endl;
      continue;
    }
    if(h&1) cout<<2*fib(w/2,(h-1)/2,(h+1)/2,0)<<endl;
    else cout<<fib(w,h-1,h+1)+fib(w-(h-2),h-1,h+1)+fib(w-h,h-1,h+1)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
int main() {

	int A500, B100, C50, X,ans = 0;
	cin >> A500 >> B100 >> C50 >> X;



	for (int i = 0; i <= A500; i++)
	{
		for (int j = 0; j <= B100; j++)
		{
			for (int x = 0; x <= C50; x++)
			{
				if (X == i * 500 + j * 100 + x * 50) {
					++ans;
				}
			}
		}
	}

	cout << ans << endl;





}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author shengboxu
 */

public class Main {
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
    
        System.out.println(Stream.of(str.split(""))
                .map(e -> e.compareTo("9") == 0 ? "1" : "9")
                .collect(Collectors.joining("")));
    }
}


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

namespace Atc_0039
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            int X = int.Parse(S.Split(' ')[0]);
            int N = int.Parse(S.Split(' ')[1]);

            if (N == 0)
            {
                Console.WriteLine(X);
                return;
            }

            var Nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            int i = 0;

            while (i < Nums.Count)
            {
                if (Nums.Contains(X + i))
                {
                    i++;

                    continue;
                }
                else
                {
                    break;
                }

            }

            int ii = X + i;
            int ri = i;

            i = 0;
            while (i < Nums.Count)
            {
                if (Nums.Contains(X - i))
                {
                    i++;

                    continue;
                }
                else
                {
                    break;
                }

            }

            int ie = X - i;
            int re = i;

            if (re < ri)
            {
                Console.WriteLine(X - re);
            }
            else if (re ==ri)
            {
                Console.WriteLine(X - ri);
            }
            else
            {
                Console.WriteLine(X + ri);
            }

        }
    }
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s.size() == 2 && s[0] == s[1]) {
    cout << "1 2" << endl;
    return 0;
  }
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == s[i + 1] || s[i + 1] == s[i + 2] || s[i + 2] == s[i]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
  return 0;
}

Measured memory_bytes: 512