akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    cin >> s;
    int left = 0, right = s.size()-1;
    int ans = 0;
    while(left < right){
        if (s[left++] != s[right--]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop() {
  top--;
  return S[top+1];
}

int main()
{
  int a, b;
  top = 0;
  char s[100];

  while(scanf("%s", s) != EOF) {
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a+b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a-b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a*b);
    } else {
      push(atoi(s));
    }
  }

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


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
    
    int n, x, c, i, j, k;
    while (cin >> n >> x, n or x) {
		c = 0;
		for (i = 1; i < n; i++) {
			for (j = i + 1; j < n; j++) {
				k = x - (i + j);
				if (k <= n and k > j) c++;
			}
		}
		cout << c << "\n";
	}
    
    return 0;
}



Measured memory_bytes: 3128
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
lisA = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)

print(lisA.index(0)+1)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9152
N,K = map(int,input().split())
n = [i for i in range(N+1)]
M,m = sum(n[-K:]),sum(n[:K])
c = M-m+1
for i in range(K+1,N+2):
  M += n[-i]
  m += n[i-1]
  c += (M-m+1)
print(c%(10**9+7))

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

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b;
    c = a + b;
    if(c % 2 != 0)
    cout << (c / 2) + 1 << endl;
    else cout << c / 2 << endl;
}



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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s)
    ret += to_string(x);
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N;
  cin >> N;
  printf("%.10f\n", N % 2 == 0 ? 0.5 : (N / 2 + 1) / (double)N);
  return 0;
}

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

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

    long long a, b;
    int ans = 1;
    cin >> a >> b;
    if (a > b)
        swap(a, b);

    for (long long i = 2; i * i <= a; i++) {
        if (a % i == 0) {
            ans += (b % i == 0);
            while (a % i == 0)
                a /= i;
        }
    }
    ans += (a > 1 && b % a == 0);
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>

auto main () -> int
{
    int index = 1;
    int w;
    while (std::cin >> w && w)
    {
        int n;
        std::cin >> n;
        int dp [n + 1] [w + 1];
        int values [n];
        int weights [n];
        for (auto i = 0; i < n; ++ i)
        {
            std::scanf ("%d,%d" , values + i , weights + i);
        }
        
        for (auto j = 0; j <= w; ++ j)
        {
            dp [0] [j] = 0;
        }
        for (auto i = 1; i <= n; ++ i)
        {
            for (auto j = w; j >= 0; -- j)
            {
                dp [i] [j] = std::max (dp [i - 1] [j] , j + weights [i - 1] <= w ? dp [i - 1] [j + weights [i - 1]] + values [i - 1] : 0);
            }
        }
        auto res = std::make_pair (0 , 0);
        for (int j = 0; j <= w; ++ j)
        {
            if (res.first < dp [n] [j] || (res.first == dp [n] [j] && res.second > w - j))
            {
                res.first = dp [n] [j];
                res.second = w - j;
            }
        }
        
        std::cout << "Case " << index ++ << ":" << std::endl;
        std::cout << res.first << std::endl << res.second << std::endl;
    }
}

Measured memory_bytes: 7032
from collections import defaultdict

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    l = defaultdict(int)
    r = defaultdict(int)

    for i in range(n):
        l[i + a[i]] += 1
        r[i - a[i]] += 1

    ans = 0
    for i in l:
        ans += l[i] * r[i]

    print(ans)


Measured memory_bytes: 74044
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
int main(){
    string s;
    cin >> s;
    bool n=0;
    bool w=0;
    bool so=0;
    bool e=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='S'){
            so=1;
          //  cout<<"ha"<<endl;
        }
        if(s[i]=='E'){
            e=1;
        }
        if(s[i]=='N'){
            n=1;
        }
        if(s[i]=='W'){
            w=1;
        }
    }
    if((n!=so)||(w!=e)){
        cout<<"No"<<endl;
    }else{
    //    cout<<n<<endl;
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool c = false, f = false;
    rep(i,s.size()){
        if(s[i] == 'C') c = true;
        if(c){
            if(s[i] == 'F') f = true;
        }
    }
    if(c && f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
using System;
using System.ComponentModel.DataAnnotations;
using System.IO.Pipes;
using System.Linq;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int N = cin.NextInt();
            string[] S = cin.ArrayNext(N);
            int[] a = new int[4];
            Array.Sort(S);

            for(int i = 0; i < N; i++)
            {
                if (S[i][0] == 'A') a[0]++;
                if (S[i][0] == 'W') a[1]++;
                if (S[i][0] == 'T') a[2]++;
                if (S[i][0] == 'R') a[3]++;
            }

            Console.WriteLine("AC x {0}\nWA x {1}\nTLE x {2}\nRE x {3}", a[0], a[1], a[2], a[3]);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 34644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long H,N;
  cin >> H;
  cin >> N;
  vector<long long> vec(N);
  for (int i=0;i<N;i++) {
   cin >> vec.at(i);
   H=H-vec.at(i);
  }  
if (H<1) {cout << "Yes" << endl;}
else {cout << "No" << endl;} 
}

Measured memory_bytes: 1024
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;

bool ar[35];
void ng(){
  puts("-1");
  exit(0);
}

int main(){
  cin>>n;
  int sum=0;
  REP(i,n){
    int a;scanf("%d",&a);
    sum^=a;
    int d=30;
    for(int j=29;j>=0;--j) if(a>>j&1) d=j;
    ar[d]=1;
  }

  int cur=0,res=0;
  for(int i=29;i>=0;--i) if((sum>>i&1)!=cur){
    if(!ar[i]) ng();
    ++res;
    cur^=1;
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 256
import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
if n<=k:
    print(0)
    sys.exit()
else:
    for i in range(k):
        h[-i-1]=0
ans=0
for i in h:
    ans+=i
print(ans)


Measured memory_bytes: 26024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define max(a,b) (a>b?a:b)
using namespace std;
double d[1010],map[1010][1010];
double x[1010],y[1010],r[1010];
bool v[1010];
double tx,ty;
int n;
int main(){
    cin>>x[0]>>y[0]>>tx>>ty>>n;
    x[n+1]=tx,y[n+1]=ty;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i]>>r[i];
    for(int i=0;i<=n+1;i++)
        for(int j=0;j<=n+1;j++){
            if(i==j) continue;
            double ls=(sqrt((double) (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-(r[i]+r[j]));
            map[i][j]=max(ls,0);
        }
    for(int i=1;i<=n+1;i++) d[i]=(double) 1e10;
    int now=0;
    double mini;
    while(!v[now]){
        v[now]=true;
        for(int i=0;i<=n+1;i++){
            if(now==i) continue;
            if(!v[i]&&d[now]+map[now][i]<d[i])
                d[i]=d[now]+map[now][i];
        }
        mini=(double) 1e10;
        for(int i=0;i<=n+1;i++)
            if(!v[i]&&d[i]<mini) now=i,mini=d[i];
    }
    printf("%.10lf\n",d[n+1]);
    return 0;
}

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

bool isover(const vector<ll>& A, ll center, ll range) {
	const ll N = A.size();
	auto itrl = lower_bound(A.begin(), A.end(), center - range);
	auto itrr = upper_bound(A.begin(), A.end(), center + range);
	//if (itrr == A.begin())return false;// bug注意
	ll l = itrl - A.begin();
	ll r = (ll)(itrr - A.begin()) - 1;

	ll aoki = r - l + 1;
	ll takahasi = N - (r + 1);
	return aoki >= takahasi - 1; // ?
}


int main()
{
	ll N, Q;
	cin >> N >> Q;
	vector<ll> A(N), X(Q), imos, cross(N);
	rep(i, N)cin >> A[i];
	rep(i, Q)cin >> X[i];
	imos = A;
	rep(i, N - 1)imos[i + 1] += imos[i];

	rep(i, N) {
		if (N % 2 == 0) {
			if (i % 2 == 1)cross[i] += A[i];
		}
		else {
			if (i % 2 == 0)cross[i] += A[i];
		}
	}
	rep(i, N - 1)cross[i + 1] += cross[i];

	for (auto x : X) {
		ll xl = -1, xr = A.back();
		while (xr - xl > 1) {
			ll mid = (xl + xr) / 2;
			(isover(A, x, mid) ? xr : xl) = mid;
		}
		ll l = lower_bound(A.begin(), A.end(), x - xr) - A.begin();
		ll r = (ll)(upper_bound(A.begin(), A.end(), x + xr) - A.begin()) - 1;

		if (r - l == N - 1 - r)r--;
		ll res = l == 0 ? 0 : cross[l - 1];
		res += imos.back() - imos[r];
		cout << res << endl;
	}


	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

//#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


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

    int ans;
    int cnt = 0;

        for(int i = min(a, b); i > 0; i--){

        if(a%i == 0 && b%i == 0){

            cnt++;
            if(cnt == k){
                ans = i;
                break;
            }

        }

    }

    cout << ans << endl;
}

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

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

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

    string div[4] = {"dream", "dreamer", "erase", "eraser"};

    reverse(s.begin(), s.end());
    REP(i, 4)   reverse(div[i].begin(), div[i].end());

    bool can, ans = true;

    for (int i = 0; i < s.size(); ) {
        can = false;

        for (int j = 0; j < 4; ++j) {
            string d = div[j];

            if (d == s.substr(i, d.size())) {
                i += d.size();
                can = true;
                break;
            }
        }

        if (!can) {
            ans = false;
            break;
        }
    }

    if (ans)    cout << "YES" << endl;
    else        cout << "NO" << endl;
}

Measured memory_bytes: 512
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
n=int(raw_input())
l=[[0 for jc in range(n)] for _ in range(n)]
for a in range(n):
    jk=map(int, raw_input().split())
    for x in range(jk[1]):
        l[jk[0]-1][jk[x+2]-1]=1
 
for i in l:
    print ' '.join(map(str, i))

Measured memory_bytes: 4664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int a,b; cin >>a>>b;
    string t; cin >> t;
    string s = "1234567890";
    for (int i = 0; i < a; i++) {
        bool flag = false;
        for (int j = 0; j < 10; j++) {
            if (t[i] == s[j]) {
                flag = true;
            } 
        }
        if (!flag) {
            cout << "No" << endl;
            return 0;
        } 
    }
    if (t[a] != '-') {
        cout << "No" << endl;
        return 0;
    } 
    for (int i = a+1; i <= a+b; i++) {
        bool flag2 = false;
        for (int j = 0; j < 10; j++) {
            if (t[i] == s[j]) {
                flag2 = true;
            } 
        }
        if (!flag2) {
            cout << "No" << endl;
            return 0;
        } 
    }
    
    cout << "Yes" << endl; 
    return 0;
}



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


struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main(){

string s;
cin >>s;
int N=s.size();
int gg=0;
int pp = 0;
rep(i,N){
    if(s[i]=='g'){
        gg++;
    }
    else{
        pp++;
    }
}

    cout<<-1*pp+N/2<<endl;


return 0;
}

Measured memory_bytes: 512
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var c = new Array(2);
    for (var i = 0; i < c.length; i++) {
        c[i] = input[i];
    }

    var ans = true;
    for (var i = 0; i < c[0].length; i++) {
        if (c[0].charAt(i) != c[1].charAt(c[1].length - i - 1)) {
            ans = false;
            break;
        }
    }

    if (ans) {
        console.log('YES');
    }
    else {
        console.log('NO');
    }

    return 0;
}


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

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

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

  int n;
  cin >> n;
  vector<int> nums(n);
  rep(i, n) { cin >> nums.at(i); }

  vector<int> sorted_nums(nums);
  sort(sorted_nums.begin(), sorted_nums.end(), greater<int>());

  rep(i, n) {
    if (nums.at(i) == sorted_nums.at(0)) {
      cout << sorted_nums.at(1) << endl;
    } else {
      cout << sorted_nums.at(0) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3200
#include <string.h>
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    int a[n],ans=0;
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(int i=0;i<n;i++){
        if(a[a[i]-1]==i+1){ans++;
        //printf("incre %d\n",i);
        }
    }
    printf("%d",ans/2);
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

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

	if(b >= c){
		cout << "delicious" << endl;
	}else if(b + a >= c){
		cout << "safe" << endl;
	}else{
		cout << "dangerous" << endl;
	}
	return 0;
}

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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int INF = 123456789;//INFの入力忘れない
int cost[10][10];//cost[u][v] は　u -> v のコスト
int d[10];//頂点sからの最短距離
bool used[10];//すでに使われたかのフラグ
int V=10;//頂点数

void dijkstra(int s){
    fill(d,d+V,INF);
    fill(used,used+V,false);
    d[s] = 0;

    while(true){
        int v = -1;
        for(int u = 0;u< V;u++){
            if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
        }
        if(v == -1) break;
        used[v]  = true;
        for(int u=0;u<V;u++){
            d[u] = min(d[u],d[v] + cost[v][u]);
        }
    }
}
 
int main(){
    int h,w;
    ll ans = 0;
    cin >> h >> w;
    REP(i,10)REP(j,10) cin >>cost[j][i];

    dijkstra(1);

    REP(i,h)REP(j,w){
        int a;
        cin >> a;
        if(a*a != 1){
            ans += d[a];
        }
    }

    cout << ans;

}

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

using ll = long long;

int main(){
	int n;
	cin >> n;
	string s;
	 
	map<string,int>mp;
	for(int i=0;i<n;i++){
		cin >> s;
		mp[s]+=1; 
	}
	
	int max=0;
	for(auto x:mp){
		int v = x.second;
		if(v>max){
			max = v;
		}
	}

	for(auto it = mp.begin() ; it!=mp.end() ; it++){
		if(it->second == max){
			cout << it->first << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int dice[6] = {1, 5, 3, 2, 4, 6};

void init() {
	dice[0] = 1;
	dice[1] = 5;
	dice[2] = 3;
	dice[3] = 2;
	dice[4] = 4;
	dice[5] = 6;
}

void rright() {
	int north = dice[1];
	int east = dice[2];
	int south = dice[3];
	int west = dice[4];
	dice[1] = west;
	dice[2] = north;
	dice[3] = east;
	dice[4] = south;
}

void rleft() {
	rright();
	rright();
	rright();
}

void rnorth() {
	int top = dice[0];
	int north = dice[1];
	int south = dice[3];
	int floor = dice[5];
	dice[0] = south;
	dice[1] = top;
	dice[3] = floor;
	dice[5] = north;
}

void rsouth() {
	rnorth();
	rnorth();
	rnorth();
}

void reast() {
	int top = dice[0];
	int east = dice[2];
	int floor = dice[5];
	int west = dice[4];
	dice[0] = west;
	dice[2] = top;
	dice[5] = east;
	dice[4] = floor;
}

void rwest() {
	reast();
	reast();
	reast();
}

int main() {
	while(1) {
	  int n;
	  cin >> n;
	  if(n == 0) break;
	  init();
	  int sum = 1;
	  rep(i, n) {
		  string s;
		  cin >> s;
		  if(s == "North") rnorth();
		  else if(s == "East") reast();
		  else if(s == "West") rwest();
		  else if(s == "South") rsouth();
		  else if(s == "Right") rright();
		  else if(s == "Left") rleft();
		  else cout << "Error!" << endl;
		  sum += dice[0];
	  }
	  cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0];
		var A = (uint)I[1];
		var B = (uint)I[2];
		if (BitCount(A ^ B) % 2 == 0) { WriteLine("NO"); return; }
		WriteLine("YES");
		var l = Generate(N, A, B);
		WriteLine(string.Join(" ", l));
	}
	bool Check(List<uint> l)
	{
		if (new HashSet<uint>(l).Count != l.Count) return false;
		for (var i = 1; i < l.Count; i++) if (BitCount(l[i] ^ l[i - 1]) != 1) return false;
		return true;
	}
	List<uint> Generate(int N, uint A, uint B)
	{
		if (N == 1) return new List<uint> { A, B };

		if (N == 2)
		{
			if ((B ^ A) == 1) return new List<uint> { A, A ^ 2, A ^ 3, A ^ 1 };
			else return new List<uint> { A, A ^ 1, A ^ 3, A ^ 2 };
		}
		B ^= A;
		var cnt = BitCount(B);
		var perm = new int[N];
		var one = N - 1;
		var zero = 0;
		for (var i = 0; i < N; i++) perm[i] = (B & (1u << i)) != 0 ? one-- : zero++;
		var iperm = new int[N];
		for (var i = 0; i < N; i++) iperm[perm[i]] = i;
		B = ((1u << cnt) - 1) << (N - cnt);
		var ans = new List<uint>();
		var lim = 1u << (N - 1);
		for (var i = 0u; i < lim; i++) ans.Add(i ^ (i >> 1));
		foreach (var i in Generate(N - 1, 1u << (N - 2), B ^ lim)) ans.Add(i ^ lim);
		for (var i = 0; i < ans.Count; i++)
		{
			var s = 0u;
			for (var j = 0; j < N; j++) if ((ans[i] & (1u << j)) != 0) s |= 1u << iperm[j];
			ans[i] = s ^ A;
		}
		return ans;
	}
	public static int MSB(uint n)
	{
		n |= (n >> 1);
		n |= (n >> 2);
		n |= (n >> 4);
		n |= (n >> 8);
		n |= (n >> 16);
		return BitCount(n) - 1;
	}
	public static int BitCount(uint n)
	{
		n = (n & 0x55555555) + ((n >> 1) & 0x55555555);
		n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
		n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f);
		n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff);
		return (int)((n & 0x0000ffff) + ((n >> 16) & 0x0000ffff));
	}
}


Measured memory_bytes: 24924
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define all(a) begin(a),end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": "  << a << ENDL
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;

const int MAXN = 1e5 + 5;

lli dp[2][MAXN];

lli MOD = 1e9 + 7;

vector<vector<lli>> graph;

lli n;

lli dfs(int u, int pr, int color) {
    lli &ans = dp[color][u];
    if(ans != -1) return ans;
    ans = 1;
    for(auto it : graph[u]) {
        if(it == pr) continue;
        lli cur = dfs(it, u, 0);
        if(color == 0) cur = (cur + dfs(it, u, 1)) % MOD;
        ans = (ans * cur) % MOD;
    }
    return ans;
}

int main()
{   _
    fore(i, 0, 2) fore(j, 0, MAXN) dp[i][j] = -1;
    lli u, v; cin >> n;
    graph.resize(n);
    fore(i, 1, n) {
        cin >> u >> v;
        graph[u - 1].pb(v - 1);
        graph[v - 1].pb(u - 1);
    }
    cout << (dfs(0, -1, 0) + dfs(0, -1, 1)) % MOD << ENDL;
    return 0;
}


Measured memory_bytes: 20016
(* O(N log N (N = max n m)) *)
Scanf.scanf "%d %d" @@ fun n m ->
  let cards = Array.init (n + m) @@ fun i ->
    if i < n then Scanf.scanf " %d" @@ fun a -> 1, a
    else Scanf.scanf " %d %d" @@ fun b c -> b, c in
  let cmp (b, c) (b1, c1) = c1 - c in
  Array.sort cmp cards;
  let rec loop ans i rest =
    if rest <= 0 then Printf.printf "%d\n" ans
    else
      let b, c = cards.(i) in
      let m = min b rest in
      loop (ans + m * c) (i + 1) (rest - m) in
  loop 0 0 n

Measured memory_bytes: 9600
/* HARE KRSNA HARE KRSNA KRSNA KRSNA HARE HARE
    HARE RAMA HARE RAMA RAMA RAMA HARE HARE  */

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

#define nl "\n"
#define ff first
#define ss second
#define pp pop_back
#define pf pop_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define b_s binary_search
#define all(x) x.begin(),x.end()
#define test ll t; cin>>t; while(t--)
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define rloop(i,s,n) for(ll i=s;i>=n;i--)
#define fill(a,value) memset(a,value,sizeof(a))

#define debug2(a)  for(auto x : a)  cout<<x<<" ";  cout<<nl;
#define debug4(a)  for(auto x : a)  cout<<x.ff<<" "<<x.ss<<nl;
#define debug1(a,n) loop(i,0,n)  cout<<a[i]<<" ";  cout<<nl;
#define debug3(a,n,m)  loop(i,0,n){ loop(j,0,m)	cout<<a[i][j]<<" ";	cout<<nl; }

typedef long long ll;
typedef long double ld;

typedef stack<ll> sll;
typedef queue<ll> qll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<ll, pll> ppll;
typedef vector<vector<ll>> vvll;
typedef priority_queue<ll> pqll;

const ll mod = 1000000007;	//998244353;
const ld pi =  acos((ld) - 1);	//3.1415926535;

ll num_generator()		{   return rand() % 1000;	}
void array_generator(ll a[], ll n)		{   loop(i, 0, n)	a[i] = rand() % 100;	}

char a[100][100];
ll ans, cnt;
ll n, m, k;
set<string> S1, S2;

void row(string s, ll i)
{
	if (i >= n)
	{
		if (s.size() == n)		S1.insert(s);
		return;
	}

	row(s + '0', i + 1);
	row(s + '1', i + 1);
}

void col(string s, ll i)
{
	if (i >= m)
	{
		if (s.size() == m)		S2.insert(s);
		return;
	}

	col(s + '0', i + 1);
	col(s + '1', i + 1);
}

void solve()
{
	cin >> n >> m >> k;
	loop(i, 0, n)		loop(j, 0, m)		cin >> a[i][j];

	row("", 0);
	col("", 0);
	// debug2(S1);
	// debug2(S2);

	for (auto x : S1)
	{
		cnt = 0;

		for (auto y : S2)
		{
			cnt = 0;
			loop(i, 0, n)
			{
				if (x[i] == '0')
				{
					loop(j, 0, m)
					{
						if (y[j] == '0')
						{
							if (a[i][j] == '#')
							{
								cnt++;
							}
						}
					}
				}
			}
			if (cnt == k)
			{
				ans++;
				// cout << x << " " << y << nl;
			}
		}
	}
	cout << ans << nl;
}

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

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();
	return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};


struct Edge{
	int a,b,c;
	Edge(int a,int b,int c) : a(a) , b(b) , c(c) {}
};

bool operator < (const Edge &a,const Edge &b){
	return a.c < b.c;
}
int main(){
	int n;
	scanf("%d",&n);
	vector<Edge> edge;
	for(int i = 0 ; i < n-1 ; i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		edge.push_back(Edge(a,b,c));
	}
	sort(edge.begin(),edge.end());
	UnionFind uf(n);
	long long ans = 0;
	for(int i = 0 ; i < edge.size() ; i++){
		long long as = uf.size(edge[i].a);
		long long bs = uf.size(edge[i].b);
		long long cst = edge[i].c;
		ans += as * bs * cst;
		uf.unionSet(edge[i].a,edge[i].b);
	}
	cout << ans << endl;
	
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

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

    ll sup = (N-1) * (N-2) / 2;
    if(K > sup){
        cout << -1 << endl;
        return 0;
    }

    set<pair<ll, ll>> del;
    for(int v = 1; v < N; v++){
        for(int n = v+1; n < N; n++){
            if(K == 0) goto fin;
            auto p = make_pair(v, n);
            del.insert(p);
            K--;
        }
    }

fin:
    ll M = (N * (N-1) / 2) - del.size();
    cout << M << endl;
    for(int n = 1; n < N; n++){
        printf("%d %d\n", 1, n+1);
    }

    for(int v = 1; v < N; v++){
        for(int n = v+1; n < N; n++){
            auto p = make_pair(v, n);
            if(del.find(p) == del.end())
                printf("%d %d\n", v+1, n+1);
        }
    }

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
const int maxn = 100 + 5;
const int inf = 1e9;


int main(){
	int n, m;
	cin >> n >> m;
	m /= 1000;

		for(int i = 0 ; i <= n ; i++){
		for(int j = 0 ; j <= n-i ; j++){
			int k = n - i - j;
			if(k >= 0 && 10*i + 5*j + k == m){
				cout << i << " " << j <<  " " << k;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" ;


}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n-1);
  rep(i, n-1) cin >> v[i];
  ll res = 0;
  vector<int> a(n);
  a[0] = v[0];
  a[n-1] = v[n-2];
  for (int i = 1; i < n-1; i++) {
    a[i] = min(v[i], v[i-1]);
  }
  rep(i, n) res += a[i];

  cout << res << endl;
}


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

int main() {
  int n;
  cin >> n;
  int r = 0;
  for (int m = n; m > 0; m /= 10) {
    r = r * 10 + m % 10;
  }
  cout << ((r == n) ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<functional>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  string s;
  i64 k;
  cin >> s >> k;
  if(k == 1) cout << s[0] << endl;
  else if(s.size() == 1) cout << s << endl;
  else if(s[0] == '1') {
    int i = 1;
    while(s[i - 1] == '1' && i < s.size()) i++;
    if(i > k) cout << s[k - 1] << endl;
    else cout << s[i - 1] << endl;
  }
  else cout << s[0] << endl;
}


Measured memory_bytes: 256
n=int(input())
R=list()
for i in range(n):
    R.append(int(input()))

minv=R[0]
maxv=R[1]-R[0]
for i in range(1,n):
    if maxv<R[i]-minv:
        maxv=R[i]-minv
    if minv>R[i]:
        minv=R[i]
print(maxv)


Measured memory_bytes: 13584
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  string SA, SB, SC;
  cin >> SA >> SB >> SC;

  ll na = SA.size(), nb = SB.size(), nc = SC.size();
  ll ca = 0, cb = 0, cc = 0;
  ll turn = 0;

  while(true){
    if(turn == 0){
      if(ca == na){
		cout << 'A' << endl;
		return 0;
      }
      turn = SA[ca] - 'a';
      ca++;
    } else if(turn == 1){
      if(cb == nb){
        cout << 'B' << endl;
        return 0;
      }
      turn = SB[cb] - 'a';
      cb++;
    } else{
      if(cc ==nc){
      	cout << 'C' << endl;
      	return 0;
      }
      turn = SC[cc] - 'a';
      cc++;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int INFTY = int.MaxValue;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] table = new int[n, n];

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int u = int.Parse(input[0]);
                int k = int.Parse(input[1]);

                for (int j = 0; j < k; j++)
                {
                    int v = int.Parse(input[2 + j * 2]);
                    int c = int.Parse(input[3 + j * 2]);

                    table[u, v] = c;
                }
            }

            Dijkstra(table, n);
        }

        static void Dijkstra(int[,] table, int n)
        {
            int i, minCost;
            int[] minCostArr = Enumerable.Repeat(INFTY, n).ToArray();
            bool[] isVisit = new bool[n];

            minCostArr[0] = 0;

            while (true)
            {
                minCost = INFTY;
                int u = -1;

                for (i = 0; i < n; i++)
                {
                    if (!isVisit[i] && minCost > minCostArr[i])
                    {
                        u = i;
                        minCost = minCostArr[i];
                    }
                }

                if (u == -1) break;

                isVisit[u] = true;

                for (i = 0; i < n; i++)
                {
                    int w = table[u, i];

                    if (w > 0)
                    {
                        int c = minCostArr[u] + w;

                        if (c < minCostArr[i])
                        {
                            minCostArr[i] = c;
                        }
                    }
                }
            }

            StringBuilder sb = new StringBuilder();
            for (i = 0; i < n; i++)
            {
                int temp = minCostArr[i] == INFTY ? -1 : minCostArr[i];
                sb.AppendLine(i + " " + temp);
            }
            Console.Write(sb);
        }
    }
}

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

#define rep(i,x,y) for(ll i=(ll)(x);i<(ll)(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(ll)(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(std::string a, std::string b, std::string c){
    vector<bool> ab(10000,false), bc(10000,false), ac(10000,false);
    rep(i,-4000,4001) {
        bool ok = true;
        rep(j,0,a.size()) {
            int k = j - i;
            if (k < 0 || k >= b.size()) continue;
            if (a[j] != b[k] && a[j] != '?' && b[k] != '?') {
                ok = false;
                break;
            }
        }
        if (ok) {
            ab[i+5000] = true;
        }
    }
    rep(i,-4000,4001) {
        bool ok = true;
        rep(j,0,b.size()) {
            int k = j - i;
            if (k < 0 || k >= c.size()) continue;
            if (b[j] != c[k] && b[j] != '?' && c[k] != '?') {
                ok = false;
                break;
            }
        }
        if (ok) {
            bc[i+5000] = true;
        }
    }
    rep(i,-4000,4001) {
        bool ok = true;
        rep(j,0,a.size()) {
            int k = j - i;
            if (k < 0 || k >= c.size()) continue;
            if (a[j] != c[k] && a[j] != '?' && c[k] != '?') {
                ok = false;
                break;
            }
        }
        if (ok) {
            ac[i+5000] = true;
        }
    }
    int answer = a.size() + b.size() + c.size();
    rep(abi,-4000,4001) {
        if (!ab[abi+5000]) continue;
        rep(bci,-4000,4001) {
            if (!bc[bci+5000] || abs(abi + bci) > 4000) continue;
            if (ac[abi+bci + 5000]) {
                int left = min(min<ll>(abi, 0), abi+bci);
                int right = max<ll>(max<ll>((ll)b.size() + abi, (ll)a.size()), (ll)c.size() + abi+bci);
                answer = min(answer, right - left);
            }
        }
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    std::string a;
    std::cin >> a;
    std::string b;
    std::cin >> b;
    std::string c;
    std::cin >> c;
    solve(a, b, c);
    return 0;
}


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

int main() {

  int K, A, B;
  cin >> K >> A >> B;

  int i = A;
  bool result = false;
  while (true) {
    if (i % K == 0) {
      result = true;
      break;
    }
    if (i == B) break;

    i++;
  }

  if (result) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3636
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		
		int res = 0;
		for(int a=0; a<=A; a++){
			for(int b=0; b<=B; b++){
				int c = (X-a*500 -b * 100)/50;
				if(c >= 0 && c <= C)
					res++;
			}
		}
		
		System.out.println(res);
	}
}

Measured memory_bytes: 20948
//                                                  '-.-'
   //                                         ()      __.'.__
   //                                      .-:--:-.  |_______|
   //                               ()      \____/    \=====/
   //                               /\      {====}     )___(
   //                    (\=,      //\      )__(     /_____\
   //    __    |'-'-'|  //  .\    (    )    /____\     |   |
   //   /  \   |_____| (( \_  \    )__(      |  |      |   |
   //   \__/    |===|   ))  `\_)  /____\     |  |      |   |
   //  /____\   |   |  (/     \    |  |      |  |      |   |
   //   |  |    |   |   | _.-'|    |  |      |  |      |   |
   //   |__|    )___(    )___(    /____\    /____\    /_____\
   //  (====)  (=====)  (=====)  (======)  (======)  (=======)
   //  }===={  }====={  }====={  }======{  }======{  }======={
   // (______)(_______)(_______)(________)(________)(_________)
   //
   // Credits :- Joan G. Stark
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
   //|                      AUTHOR - _P_VATSAL_                                     |
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
#include<bits/stdc++.h>
#include <iomanip>
#include <string>
using namespace std;
//************
//***CODER***
//PRANAV VATSAL
//************
typedef long long ll;
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define f first
#define s second
typedef vector<pli> vpli;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(),v.end() 
#define fr(i,n) for(i=0;i<n;i++)
#define frr(i,a,b) for(i=a;i<b;i++)
using ld=long double;
lli INF=1e18;
int inf=1e6;
#define endl '\n'


void solve()
{
	lli n;
	cin>>n;
  lli k;
  cin>>k;
	lli h[n+1];
	lli i;
	fr(i,n)
	{
		cin>>h[i+1];
	}
	if(n==1)
	{
		cout<<0;
		return ;
	}
	lli dp[n+1];//dp[i] is the min cost to reach i 
	dp[1]=0;

	frr(i,2,n+1)
	{
    lli j;
    dp[i]=INF;
    frr(j,1,k+1)
    {
      if((i-j)==0)
        break;
      dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
    }
	}
	cout<<dp[n];
}


int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int t;
  //cin>>t;
  //while(t--)
    solve();
  return 0;
}

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

int main()
{	
	int a,b;
	cin >> a >> b;
	if(a < b) swap(a,b);
	if((a + b) % 2 == 0) cout << (a + b) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;


ll sum(ll n) {
  ll m=0;
  FOR(i,0,12){
    m+=n%10;
    n/=10;
  }
  return m;
}


ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}


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


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/


signed main() {
  ll n;
  ci(n);
  vll A(n);
  FOR(i,0,n){
    ci(A[i])
  }
  SORT(A);
  co(A[n-1]-A[0])
}

Measured memory_bytes: 256