akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
long long int PredictTheWinner(long long int A[], int n){
        
       long long int dp[n][n];
       long long int sum[n][n];
        sum[0][0] = A[0];
        dp[0][0] = A[0];
 
        for (int i = 1; i < n; ++i) {
            sum[0][i] = sum[0][i - 1] + A[i];
            sum[i][i] = A[i];
            dp[i][i] = A[i];
            for (int j = i - 1; j >= 0; --j) {
                sum[j][i] = sum[0][i] - (j == 0 ? 0 : sum[0][j - 1]);
                dp[j][i] = max(sum[j][i] - dp[j + 1][i],  sum[j][i] - dp[j][i - 1]);
            }
        }
        return dp[0][n-1]-(sum[0][n - 1]-dp[0][n - 1]);
    }
int main() {
	// your code goes here
   std::ios::sync_with_stdio(false);cin.tie(NULL);
	int n;
	cin>>n;
	long long int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	cout<<PredictTheWinner(a,n);
	return 0;
}

Measured memory_bytes: 140928
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  
  int A;
  vector<tuple<string, int, int>> a(N);
  for (int i = 0; i < N; i++) {
   cin >> get<0>(a.at(i)) >> A;
   get<1>(a.at(i)) = A * (-1);
   get<2>(a.at(i)) = i + 1;
  }
  
  sort(a.begin(), a.end());
  
  for (int j = 0; j < N; j++) {
    cout << get<2>(a.at(j)) << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u)
{
    for (int v = nt[u]; v < n; v++)
    {
        nt[u] = v + 1;
        if (M[u][v] > 0) return v;
    }
    return -1;
}

void dfs_visit(int r)
{
    for (int i = 0; i < n; i++) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while ( !S.empty() )
    {
        int u = S.top();
        int v = next(u);
        if (v != -1)
        {
            if ( color[v] == WHITE)
            {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else
        {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs()
{
    for (int i = 0; i < n; i++)
    {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    for (int u = 0; u < n; u++)
    {
        if ( color[u] == WHITE) dfs_visit(u);
    }
    for (int i = 0; i < n; i++)
    {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main()
{
    int u, k, v;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}


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

int main(){
    int n;  cin >> n;
    vector<int>a(n);
    rep(i, n)	cin >> a[i];
    //solve
    bool ok=false;
    int next=0;
    int count=0;
    rep(i, n){
	count++;
	next=a[next]-1;
	if(next==1){
	    ok=true;
	    break;
	}
    }
    if(ok){
	cout << count << endl;
    }else{
	cout << -1 << endl;
    }
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_126
{
    class E
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            UnionFind unionFind = new UnionFind(n);
            for(int i = 0; i < m; i++)
            {
                int[] xyz = ReadInts();
                unionFind.Unite(xyz[0] - 1, xyz[1] - 1);
            }

            int cnt = 0;
            for(int i = 0; i < n; i++)
            {
                if (i == unionFind.Root(i)) cnt++;
            }

            WriteLine(cnt);
        }

        class UnionFind
        {
            int[] tree;
            int[] size;

            public UnionFind(int length)
            {
                tree = new int[length];
                size = new int[length];
                for (int i = 0; i < length; i++)
                {
                    tree[i] = i;
                    size[i] = 0;
                }
            }

            public int Root(int x)
            {
                int rx = x;
                while (tree[rx] != rx)
                {
                    rx = tree[rx];
                }
                tree[x] = rx;
                return rx;
            }

            public bool IsSame(int x, int y)
            {
                return Root(x) == Root(y);
            }

            public void Unite(int x, int y)
            {
                int rx = Root(x);
                int ry = Root(y);
                if (rx == ry) return;

                if (rx > ry)
                {
                    int temp = rx;
                    rx = ry;
                    ry = temp;
                }
                tree[ry] = rx;
                size[rx] += size[ry];
            }

            public int GetSize(int x)
            {
                return size[Root(x)];
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 15808
'use strict'
function main(input) {
  input = input.trim().split('\n')
  let max = 0
  let count = 0
  input[1].split(' ').forEach(height => {
    if (Number(height) >= max) {
      count++;
      max = Number(height)
    }
  })
  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
n = 0

def format_input(filename = None):
	global n
	if filename == None:
		n = int(input())

	elif filename == '__random__':
		from random import randint as rng
		n = rng(1, 999)
		print(n)

def get_answer():
	answer = ''
	digit = n % 10
	if digit == 3:
		answer = 'bon'
	elif digit in [0, 1, 6, 8]:
		answer = 'pon'
	else:
		answer = 'hon'

	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int B[26]={0};
void check(string S){
    long L=S.size();
    for(long i=0;i<L;i++)
        B[S[i]-'a']++;
}
int main()
{
   // ifstream cin("input.in");
   // ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long N;
    string S,P;
    cin>>N>>S;
    N--;
    check(S);
    while(N--)
    {
        cin>>P;
        int C[26]={0};
        long L=P.size();
        for(long i=0;i<L;i++)
            C[P[i]-'a']++;
        for(long i=0;i<26;i++)
            B[i]=min(B[i],C[i]);
    }
    S="";
    //for(long i=0;i<26;i++)
    //    cout<<B[i]<<"\n";
    for(long i=0;i<26;i++)
        while(B[i]--)
            S+=char('a'+i);
    cout<<S;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;



int main(){
    
    string S;
    string T;
    cin >> S >> T;
    string Sd = S;
    int n = S.length();
    rep(i,n){
        if (S[i] == '?' || S[i] == T[0]) {
            int a = 0;
            for (int j = 0; j < T.length(); j++) {
                if (S[i+j] == '?' || S[i+j] == T[j]) {
                    a++;
                }
            }
            
            if (a == T.length()) {
                string SS = S;
                for (int j = 0; j < T.length(); j++) {
                    SS[i+j] = T[j];
                }
                rep(k,n){
                    if (SS[k]=='?') {
                        SS[k] = 'a';
                    }
                }
                if (Sd == S) {
                    
                    Sd = SS;
                    
                }else{
                    if (Sd > SS) {
                        Sd = SS;
                    }
                }
            }
        }
    }
    
    
    
    for (int i = 0; i<n; i++) {
        if (Sd[i] == '?') {
            cout << "UNRESTORABLE" << endl;
            return 0;
        }
    }
    
    cout << Sd << endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

from collections import Counter
Answer = Counter(A)

for i in range(1,N+1) :
    if K-Q+Answer[i] > 0 :
        print("Yes")
    else :
        print("No")


Measured memory_bytes: 11924
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int k = scanner.nextInt();
        if (b - a + 1 <= 2 * k) {
            for (int i = a; i <= b; i++) {
                System.out.println(i);
            }
        } else {
            for (int i = a; i < k + a; i++) {
                System.out.println(i);
            }
            for (int j = b - k + 1; j <= b; j++) {
                System.out.println(j);
            }
        }
    }
}

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

int n, m;

int solve() {
  scanf("%d %d", &n, &m);
  printf("%d\n", n*(n-1)/2 + m*(m-1)/2);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}


int main(){
    ll N, a;
    cin >> N;
    vector<ll> A;
    rep(i,N){
        cin >> a;
        A.push_back(a);
    }
    ll min_sum = INF;
    for(ll i=-100; i<=100; i++){
        ll sum = 0;
        rep(j,N){
            sum += ((A[j]-i)*(A[j]-i));
        }
        if (sum < min_sum) min_sum = sum;
    }
    cout << min_sum << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    if (Math.abs(x-a) < Math.abs(x-b)) {
      System.out.println("A");
    } else {
      System.out.println("B");
    }
  }
}


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

const int N = 2e5 + 77;

int n,p[N];
pair<int,int> a[N];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        a[i].first = p[i];
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);

    int mx = 0, c = 1;
    for (int i = 2; i <= n; i++) {
        if (a[i].second > a[i - 1].second) c++;
        else mx = max(mx, c), c = 1;
    }
    mx = max(mx, c);
    cout << n - mx << endl;
    return 0;
}

Measured memory_bytes: 2560
N,U,V=map(int,input().split())
if U==V:
    print(0)
    exit()

G=[[]*N for _ in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)


from collections import deque
def calc(s):
    que=deque()
    que.append(s-1)
    visited=[-1]*N
    visited[s-1]=0
    while que:
        v=que.pop()
        for u in G[v]:
            if visited[u]==-1:
                que.appendleft(u)
                visited[u]=visited[v]+1
    return visited
taka=calc(U)
aoki=calc(V)
#print(taka)
#print(aoki)
ans=0
for i in range(N):
    if taka[i]<=aoki[i]:
        ans=max(ans,aoki[i])

print(ans-1)


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

int main(){
    int n;
    cin>>n;
    if(n%10==2 ||n%10==4 ||n%10==5 ||n%10==7 ||n%10==9){
        cout<<"hon"<<endl;
    }else if(n%10==0 ||n%10==1 ||n%10==6 ||n%10==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"bon"<<endl;
    }

}


Measured memory_bytes: 3596
#include <iostream>
#include <string>

using namespace std;

int main(){
    int s, p, n;
    cin >> s;
    p = s / 100;
    n = s - p * 100;

    if(p >0 && p < 13){
        if(n > 0 && n < 13){
            cout << "AMBIGUOUS" << endl;
            return 0;
        }
        cout << "MMYY" << endl;
        return 0;
    }
    if(n >0 && n < 13){
        cout << "YYMM" << endl;
        return 0;
    }
    cout << "NA" << endl;
    return 0;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
struct s
{
  int c1;
  int t1;
};
bool operator <(s x,s y)
{
    if(x.t1!=x.t1)
    {
        return x.t1>y.t1;
    }
    else
        return x.c1<y.c1;
}
int  main()
{
    int n,t;
    cin>>n>>t;
    s a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].c1>>a[i].t1;
    }
    sort(a,a+n);
    int ck=0;
    //cout<<endl;
    for(int i=0;i<n;i++)
    {
        //cout<<a[i].c1<<" "<<a[i].t1<<endl;
        if(t>=a[i].t1)
        {
            cout<<a[i].c1<<endl;
            ck=1;
            break;
        }
    }
    if(ck==0)
    {
        cout<<"TLE"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
def main():
    R, G, B, N = map(int, input().split())

    cnt = 0
    for r in range(N//R+1):
        for g in range(N//G+1):
            res = N - (r*R+g*G)
            if res >= 0 and res % B == 0:
                cnt += 1
    print(cnt)

main()

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

int main()
{
  int d;
  while (cin >> d, d){
    int n, m;
    cin >> n >> m;

    vector<int> a;
    a.push_back(0);
    for (int i = 1; i < n; i++){
      int x;
      cin >> x;
      a.push_back(x);
    }
    a.push_back(d);

    sort(a.begin(), a.end());

    int ans = 0;
    while (m--){
      int q;
      cin >> q;

      int l = 0, r = n + 1;
      while (r - l > 1){
        int mid = (l + r) / 2;
        if (a[l] <= q && q <= a[mid]) {
          r = mid;
        } else {
          l = mid;
        }
      }

      ans += min(a[r] - q, q - a[l]);
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 3412
import collections
N = int(input())

num=0

li = [i+1 for i in range(N)]

l4 = list(map(lambda x: str(x)[0]+str(x)[-1], li))
ll = set(l4)
l5 = list(map(lambda x: str(x)[-1]+str(x)[0], li))
c4 = collections.Counter(l4)
c5 = collections.Counter(l5)

for l in ll:
  num += c4[l] * c5[l]
print(num)





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

using namespace std;

int N;
long long int x;
vector<long long int>a;

int main(void) {

	cin >> N;
	cin >> x;
	long long int tmp;
	for (int i = 1; i <= N;i++) {
		cin >> tmp;
		a.push_back(tmp);
	}

	//cout << "check" << endl;

	sort(a.begin(), a.end());

	int count = 0;
	for (int i = 0; i < N-1; i++) {
		if (a[i] <= x) { count++; x -= a[i]; }
	}

	if (a[N - 1] == x) { count++; }

	cout << count << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
//看题解了，部分和那里，背下来，重做 
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
 
const int NN = 330;
struct rec1{
	int x, y;
}a[NN*NN];
int h, w, d, x, q, l, r, n, sum[NN*NN];

int dis(int p, int q){
	return abs(a[p].x - a[q].x) + abs(a[p].y - a[q].y);
}

int main(){
	scanf("%d%d%d", &h, &w, &d);
	for (int i=1; i<=h; i++){
		for (int j=1; j<=w; j++){
			scanf("%d", &x);
			a[x].x = i;
			a[x].y = j;
		}
	}
	
	n = h * w;
	memset(sum, 0, sizeof(sum)); 
	for (int i=1; i<=d; i++){
		for (int j=i+d; j<=n; j+=d) sum[j] = sum[j-d] + dis(j, j-d); 
	}
	
	//for (int i=1; i<=n; i++) printf("%d ", sum[i]);
	
	scanf("%d", &q);
	while (q--){
		scanf("%d%d", &l, &r);
		printf("%d\n", sum[r] - sum[l]);
	}
	
	return 0;
}
 

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

    int a,b;

    cin >> a >> b; 

    string aa,bb;

    for(int i= 0; i < b; ++i){
        aa += to_string(a);
    }
    for(int i = 0; i < a; ++i){
        bb += to_string(b);
    }

    if(aa > bb)cout << bb << endl;
    else cout << aa << endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;

bitset<92> map[92];
int W,H;
int ans;
int dx[] = {1,-1,0,0}, dy[] = {0,0,-1,1};

void saiki(int x , int y , int step)
{
	
	for(int i = 0; i < 4; i++){
		int nx = x+dx[i], ny = y+dy[i];

		if(map[ny][nx]){
			map[ny][nx] = 0;
			saiki(nx,ny,step+1);
			map[ny][nx] = 1;
		}
	}
	
	ans = max(ans,step);
}


int main(void)
{

	while(cin >> W >> H, W|H){
		int in;
		ans = 0;

		for(int i = 1; i <= H; i++){
			map[i] = 0;
			for(int j = 1; j <= W; j++){
				cin >> in;
				map[i][j] = in == 1;
			}
		}

		for(int i = 1; i <= H; i++){
			for(int j = 1; j <= W; j++){
				if(map[i][j]){
					saiki(j,i,0);
				}
			}
		}

		cout <<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

lli n, k, ar[N], pospre[N], possuf[N], pre[N], ans;

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);

	cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> ar[i];
		pre[i] = pre[i - 1] + ar[i];
		pospre[i] = pospre[i - 1];
		if(ar[i] > 0)
			pospre[i] += ar[i];
	}

	for(int i = n; i >= 1; i--) {
		possuf[i] = possuf[i + 1];
		if(ar[i] > 0)
			possuf[i] = possuf[i + 1] + ar[i];
	}

	for(int i = 1; i <= n - k + 1; i++) {
		lli add = pre[i + k - 1] - pre[i - 1];
		if(add < 0)
			add = 0;
		ans = max(ans, pospre[i - 1] + possuf[i + k] + add);
	}
	cout << ans;
}

Measured memory_bytes: 11264
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <unordered_map>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#define int long long 
#define lli unsigned long long int
#define pb push_back
#define ins emplace
#define mod 1e9+7
#define fi(i,n) for(int i=1; i<=n;i++)
#define INF 10000000000
#define unm  unordered_map<int , int>
#define vvi  vector<vector<int>>
#define sortall(v) sort(v.begin(),v.end())
#define deb(x)     cout << #x << "=" << x << endl
#define deb2(x,y)  cout << #x << "=" << x << "," << #y << "=" << y << endl
#define mp make_pair
#define F  first
#define S second
#define itr(it,a) for(auto it = a.begin(); it!=a.end();it++)
#define vi  vector<int>
#define pii pair<int ,int>
#define vii vector<vi>
#define in1(x) int x; cin >> x
#define in2(x,y) int x,y; cin >> x >> y;
#define in3(x,y,z) int x,y,z; cin >> x >> y >> z

using namespace std;

int32_t main(){
	int n; cin >> n;
	int ans = 0;
	vi v(n); 
	for(auto &i : v) cin >> i;

	for(int i=1; i<n;i++){
		if(v[i] < v[i-1]){
			ans+=v[i-1]-v[i];
			v[i]+=(v[i-1]-v[i]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4436
from sys import stdin
N = int(stdin.readline())
A = sorted([int(stdin.readline()) for i in range(N)])

a = [0] * N
b = [0] * N
j = 1

for i in range(N-1):
    a[i] += -j
    a[i+1] += j
    b[i] += j
    b[i+1] += -j
    j = -j

a.sort()
b.sort()
s1 = s2 = 0
for i in range(N):
    s1 += a[i] * A[i]
    s2 += b[i] * A[i]
print(max(s1, s2))

Measured memory_bytes: 46428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
int main (){
    int N , K;
    cin >> N >> K;
    long long cost[100001];
    long long h[100001];
    h[0] = 0;
    for(int i=1;i<=N;i++){
        cin >> h[i] ;
    }
    for(int i=0;i<=N;i++){
        cost[i] = INF;
    }
    cost[0]=0;
    cost[1]=0;
    if(N >= K){
        if(K>1){
            for(int i=2;i<=K;i++){
                for(int j=1;j<i;j++){
                    cost[i] = min( cost[i], cost[i-j] + abs(h[i]-h[i-j]) );
                }
            }
            for(int i=K+1;i<=N;i++){
                for(int j=1;j<=K;j++){
                    cost[i] = min( cost[i] , cost[i-j] + abs(h[i]-h[i-j]) ) ;
                }
            }
        }
        else if(K==1){
            for(int i=2;i<=N;i++){
                cost[i] = min( cost[i], cost[i-1] + abs(h[i] - h[i-1]));
            }
        }
    }
    else{
        for(int i=2;i<=N;i++){
            for(int j=0;j<=N-1;j++){
                cost[i] = min ( cost[i], cost[i-j] + abs(h[i] - h[i-j]));   
            }
        }
    }
    
    cout << cost[N] << endl;

}

Measured memory_bytes: 5188
n = int(input())
ans_list = [0,0,0,0]

for i in range(n):
    s = input()
    if s == 'AC':
        ans_list[0] += 1
    elif s == 'WA':
        ans_list[1] += 1
    elif s == 'TLE':
        ans_list[2] += 1
    else:
        ans_list[3] += 1

for i in range(len(ans_list)):
    if i == 0:
        print('AC x ' + str(ans_list[i]))
    elif i == 1:
        print('WA x ' + str(ans_list[i]))
    elif i == 2:
        print('TLE x ' + str(ans_list[i]))
    else:
        print('RE x ' + str(ans_list[i]))


Measured memory_bytes: 9184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int x=sc.nextInt();
		int[] array=new int[n];
		int f=0,count=1;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}

		for(int i=0;i<n;i++) {
			f=f+array[i];
			if(f>x) {
				break;
			}
			count++;
		}
		System.out.println(count);


	}
}
/*
 6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
 */

//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));




Measured memory_bytes: 21844
import java.util.Scanner;

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

		int n = sc.nextInt();
		int[] a = new int[n + 1];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int m = sc.nextInt();
		int[] b = new int[m];
		for (int i = 0; i < m; i++) {
			b[i] = Integer.parseInt(sc.next());
		}

		int count = 0;

		for (int i = 0; i < m; i++) {
			int c = 0;
			a[n] = b[i];
			while (a[c] != a[n]) {
				c++;
			}
			if (c != n) {
				count++;
			}
		}
		System.out.println(count);

	}
}


Measured memory_bytes: 38248
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#define L l,m,rt<<1
#define R m+1,r,rt<<1|1
#define LL long long 
using namespace std;
LL n;
LL l,r,ans,maxx,mid;
LL f[5000100];
LL s[5000100];
LL sum[16000010];
LL read()
{
	LL _=0,__=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')__=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){_=_*10+ch-'0';ch=getchar();}
	return _*__;
}
void pushup(LL rt){sum[rt]=sum[rt<<1]+sum[rt<<1|1];}
void build(LL l,LL r,LL rt)
{
	sum[rt]=0;
	if(l==r)
	{
	return ;
    }
	LL m=(l+r)>>1;
	build(L);
	build(R);
	pushup(rt);
}
void update(LL x,LL l,LL r,LL rt)
{
	if(l==r)
	{
		sum[rt]+=1;
		return ;
	}
 	LL m=(l+r)>>1;
	if(x<=m) update(x,L);
	else update(x,R);
	pushup(rt); 
}
LL query(LL x,LL y,LL l,LL r,LL rt)
{
	if(x>y) return 0;
	if(x<=l&&y>=r)
	{
		return sum[rt];
	}
	LL set=0;
	LL m=(l+r)>>1;
	if(x<=m)set+=query(x,y,L);
	if(y>m) set+=query(x,y,R);
	return set; 
}
LL check(LL x)
{
	memset(sum,0,sizeof(sum));
	ans=0;maxx=-1;
	 for(int i=1;i<=n;i++)
	 {
	 	if(f[i]>x)
	 	s[i]=-1;
	 	else 
	 	s[i]=1;
	 	s[i]+=s[i-1];
	 }
	 for(int i=0;i<=n;i++)
	 s[i]+=n+1,maxx=max(maxx,s[i]);
	 build(1,maxx+5000,1);
	 for(int i=0;i<=n;i++)
	 {
	 	ans+=query(1,s[i]-1,1,maxx+5000,1);
	 	update(s[i],1,maxx+5000,1);
	 }
	 if(ans>=(1ll*n*(n+1)/4+1)) return 1;
	 else return 0;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		f[i]=read();
		r=max(r,f[i]); 
	}
//	if(n==1)
//	{
//		printf("%lld",f[1]);
//		return 0;
//	}
	r=r+1;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(check(mid))
        {
            r=mid;
        }
        else
        {
            l=mid+1;
        }
        if(r-l<=1) 
        {
            mid=check(l)?l:r;
            break;
        }
    }
    printf("%lld\n",mid);
//	printf("%lld",r);
//	cout<<endl;
//	printf("%d",r);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for(int i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  
  vector<int> count(1000005);
  for(int i = 0; i < n; i++) {
    int x = A.at(i);
    if (count.at(x) != 0) {
      count.at(x) = 2;
      continue;
    }
    for (int j = x; j < 1000005; j += x) {
      count.at(j)++;
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(count.at(A.at(i)) == 1) {
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7912
<?php
# 数値の入力
fscanf(STDIN, "%d", $data1);
$data2 = fgets(STDIN);
$integer = explode(" ", $data2);

$anser = 0;
for($i=0; $i<$data1; $i++){
    $anser += 1/$integer[$i];
#    echo $anser."\n";
}
$anser = 1/$anser;
echo $anser."\n";
?>

Measured memory_bytes: 3956
#include <stdio.h>
 
int main(void) {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x >= r && y >= r && (H - r) >= y && (W - r) >= x) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

 

 




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

#define IOS std::cin.tie(0);std::ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>;

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
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__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
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(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 1e6+1;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    double money=100;
    LCIN(X);
    ll count=0;
    while(1){
        money=floor(money*1.01);count++;
        if(X<=money)break;
    }
    COUT(count);


    return 0;
}

Measured memory_bytes: 3632
X=int(input())

if X >= 400 and X <=599:
    print("8")
elif X >= 600 and X <=799:
    print("7")
elif X >= 800 and X <=999:
    print("6")
elif X >= 1000 and X <=1199:
    print("5")
elif X >= 1200 and X <=1399:
    print("4")
elif X >= 1400 and X <=1599:
    print("3")
elif X >= 1600 and X <=1799:
    print("2")
elif X >= 1800 and X <=1999:
    print("1")

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

int main()
{
    int a,b , c;
    cin>>a>>b>>c;
    
    int c1 = 0;
    int c2 = 0;
    if(a==5)
    c1++;
    else if(a==7)
    c2++;
    
     if(b==5)
    c1++;
    else if(b==7)
    c2++;
    
     if(c==5)
    c1++;
    else if(c==7)
    c2++;
    
    if(c1 == 2 && c2 == 1)
    std::cout << "YES" << std::endl;
    else
    cout<<"NO"<<"\n";
        
    return  0;
}	

Measured memory_bytes: 3468
import math
N,M=map(int,input().split())
if abs(N-M)>1:
    print(0)
elif abs(N-M)==1:
    print((math.factorial(N)*math.factorial(M))%(1000000007))
else:
    print((math.factorial(N)*math.factorial(M)*2)%(1000000007))

Measured memory_bytes: 55152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 65010


void calc(int n){
  int p,sump=0;
  int joi[SIZE];

  for(int i=0;i<n;i++){
    scanf("%d",&p);
    sump += p;
  }

  for(int i=0;i<n-1;i++){
    scanf("%d",joi+i);
  }

  sort(joi,joi+n-1);

  ll ans = (ll)sump * n;
  
  for(int i=n-2;i>=0;i--){
    sump += joi[i];

    ans = max(ans,(ll)sump * (i+1));
  }

  printf("%lld\n",ans);
}
  

int main(){

  int n;

  while(scanf("%d",&n)!=EOF){
    if(n==0) break;
    calc(n);
  }
  
  return 0;
}

Measured memory_bytes: 1460
if __name__ == "__main__":
    inp = input()
    a = []
    ans = []
    total = 0
    for i in range(len(inp)):
        if inp[i] == "\\":
            a.append(i)
        elif inp[i] == "/":
            if len(a) != 0:
                x = a.pop()
                d = i - x
                total += d
                while len(ans) != 0 and ans[-1][0] > x:
                    d += ans[-1][1]
                    ans.pop()
                ans.append([x, d])
    print(total)
    if total == 0:
        print(0)
    else:
        print(str(len(ans))+" "+(" ".join(map(str, [x[1] for x in ans]))))

Measured memory_bytes: 8012
#include <iostream>
#include <stdio.h>
#include <ctype.h>
using namespace std;


int main()
{

    char k , j  ;
    cin >> k>> j ;
     k = toupper(k) , j = toupper(j);
    int x = k-55 ;
    int y = j -55 ;
    if (y > x )
    cout << "<";
    else if (y < x )
    cout << ">";
    else
     cout << "=";
    return 0;

}


Measured memory_bytes: 256
import sys
import numpy as np
sys.setrecursionlimit(100000)
n = int(input())

edges=[[] for i in range(n+1)]
d=[-1 for i in range(n+1)]
for i in range(1,n):
	a, b=[int(i) for i in input().split()]
	edges[a].append([b,1])
	edges[b].append([a,1])
def kyori(u):
	for v,w in edges[u]:
		if d[v]==-1:
			d[v]=d[u]+w
			kyori(v)

d[1]=0
kyori(1)

D = list(map(int, input().split()))
D.sort(reverse=True)

ans_lst = [0] * n
ans = sum(D[1:])

ans_lst[0] = D[0]
now_kyori = 1
idx = 1
m = 1
idx_lst = [i for i in range(n)]

d.pop(0)

lst = np.array([d, idx_lst]).T.tolist()
lst.sort()
d = np.array(lst).T.tolist()[0]
idx_lst = np.array(lst).T.tolist()[1]

for i in range(n):
    ans_lst[idx_lst[i]] = D[i]

ans_lst = list(map(str, ans_lst))
mojiretu = ' '.join(ans_lst)
print(ans)
print(mojiretu)

Measured memory_bytes: 25964
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <typeinfo>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
set<ll> ans;
void dfs(string s){
  ll k=stol(s);
  if(k>1e9) return ;
  ans.insert(k);
  string s1=s+'3';
  string s2=s+'5';
  string s3=s+'7';
  dfs(s1);
  dfs(s2);
  dfs(s3);
  return ;
}
int main(){
  ll n;
  cin>>n;
  dfs("3");
  dfs("5");
  dfs("7");
  ll cu=0;
  for(auto p:ans){
    set<char> j;
    string d=to_string(p);
    rep(i,sz(d)) j.insert(d[i]);
    if(p<=n&&sz(j)==3)cu++;
  }
  COUT(cu);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

signed main() {
	ll n = 0, k = 0, cnt = 1, sum = 1, ans = 0;
	cin >> n; vector<ll>t(n), u(n); map<ll, map<ll, ll>> m;
	rep(h, n) { cin >> t[h] >> u[h]; }
	rep(h, n) {
		for (int i = h + 1; i < n; i++) {
			ll a = t[h] - t[i], b = u[h] - u[i];
			m[a][b]++; m[0 - a][0 - b]++;
			ans = max(ans, max(m[a][b], m[0 - a][0 - b]));
		}
	}
	cout << n - ans << endl;
	return 0;
}

Measured memory_bytes: 3916
//const int N = 2e5+5;
//Factorial f(N);
//ll movement(int r, int c){
//    return f.comb(r+c,r);
//}
//int h,w,a,b;
//ll get(int r, int c){
//    ll p1 = movement(r-1,c-1);
//    ll p2 = movement(h-r,w-c);
//    return p1*p2%MOD;
//}
//void _(){
//    cin >> h >> w >> a >> b;
//    ll ans = 0;
//    for(int row = h-a; row >= 1; --row){
//        int col = b+1 + (h-a - row);
//        if(col > w) break;
//        ans += get(row,col);
//    }
//    print(ans%MOD);
//}
//
#include <iomanip>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
const ll MOD = 1e9 + 7;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 void print(T x, string end = "\n"){
    cout << x << end;
}
T1 T ext_euclid(T a, T b, T c, T d){
    if(c == T(0))
        return b;
    return ext_euclid(c, d, a % c, b - a / c * d);
}
T1 T mod_inverse(T x, T mod = T(MOD)){
    return (ext_euclid(mod, T(0), x, T(1)) + mod) % mod;
}
ll mod_inverse(int x, ll mod = MOD){
    return mod_inverse<ll>(x,mod);
}
struct Factorial{
    vl fact,ifact;
    ll comb(ll n, ll m){
        assert(n >= m);
        assert(n < sz(fact));
        return fact[n]*ifact[m]%MOD*ifact[n-m]%MOD;
    }
    Factorial(int n){
        fact.resize(n+1);
        ifact.resize(n+1);
        fact[0] = 1;
        for(int i = 1; i <= n; ++i)
            fact[i] = fact[i-1]*i%MOD;
        ifact[n] = mod_inverse(fact[n]);
        for(int i = n-1; i >= 0; --i)
            ifact[i] = (i+1)*ifact[i+1]%MOD;
    }
};
const int N = 2e5+5;
Factorial f(N);
ll movement(int r, int c){
    return f.comb(r+c,r);
}
int h,w,a,b;
ll get(int r, int c){
    ll p1 = movement(r-1,c-1);
    ll p2 = movement(h-r,w-c);
    return p1*p2%MOD;
}
void _(){
    cin >> h >> w >> a >> b;
    ll ans = 0;
    for(int row = h-a; row >= 1; --row){
        int col = b+1 + (h-a - row);
        if(col > w) break;
        ans += get(row,col);
    }
    print(ans%MOD);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        _();
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  string s;
  cin >> s;
  
  for(int i=0; i<4; i++){
    int ssum=0;
    for(int j=0; j<4; j++){
      if(s[i]==s[j]){
        ssum++;
      }
    }
    if(ssum!=2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	ini(n);
	int a[10000];
	FOR(i,0,n){cin>>a[i];}
	FOR(i,0,n){
		if(a[i] % 2 == 0){
			if(a[i] % 3 == 0){continue;}
			else{
				if(a[i] % 5 == 0){continue;}
				else{
					out("DENIED");
					return 0;
				}
			}
		}
	}
	out("APPROVED");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		String[] m =new String[x];
		String tmp ="";
		for (int i=0;i<m.length;i++){
			m[i] = sc.next();
		}
		for (int i=0;i<x+2;i++){
			if(i>0&&i<x+1){
				tmp = m[i-1];
			}
			for (int j=0;j<y+2;j++){
				if(i==0||i==x+1){
					System.out.print("#");
				}
				else if (j==0||j==y+1){
					System.out.print("#");
				}
				else System.out.print(tmp.charAt(j-1));
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 27196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(long long i=I;i<A;i+=B)
#define rep(I,A,B) for(long long j=I;j<=A;j+=B)
#define repp(I,A,B) for(long long j=I;j>=A;j-=B)
#define str(A) for(long long k=0;A[k]!='\0';k++)
#define pb push_back
#define mp make_pair
#define pii pair<long long,long long>
vector <int> adj[100001];
bool visit[100001];
const int mod = 1000000007;
string s,t;
int dp[3010][3010];
int func(int i,int j)
{
	if(i<0 || j<0)
		return 0;
	if(dp[i][j]==-1)
	{
		if(s[i]==t[j])
			dp[i][j]=max(dp[i][j],1+func(i-1,j-1));
		else
			dp[i][j]=max(func(i,j-1),func(i-1,j));
	}
	return dp[i][j];
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n1,n2;
	cin>>s>>t;
	FOR(0,3001,1)
		rep(0,3000,1)
			dp[i][j]=-1;
	n1=s.length(),n2=t.length();
	func(n1-1,n2-1);
	int i=n1-1,j=n2-1;
  	stack<char> st;
	while(i>=0 && j>=0)
	{
        if(s[i]==t[j])
			st.push(t[j]),i--,j--;
		else
		{
          if(i>0 && j>0)
          {
			if(dp[i][j-1]>dp[i-1][j])
				j--;
			else
				i--;
		  }
          else
          {
            if(i==0 && j>0)
              j--;
            else if(j==0 && i>0)
              i--;
            else
              i--,j--;
          }
        }
	}
  	while(!st.empty())
    {
		cout<<st.top();
      	st.pop();
    }
	return 0;
}

Measured memory_bytes: 38400
#include <iostream>
int main(){
	char a,b,c;
	int x[3]={1,0,0};
	while (std::cin>>a>>c>>b){
		int i=a-'A', j=b-'A', k = x[i];
		x[i] = x[j];
		x[j] = k;
	}
	for (int i=0; i<3;i++)
		if (x[i]==1) std::cout<<char(i+'A')<<std::endl;
}

Measured memory_bytes: 1132
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int a=scan.nextInt();
    String b=scan.next();
    int Ans=0;
    String in[]=new String[a];
    in=b.split("");
    for(int x=0; x<a-2; x++){
      if(in[x].equals("A") && in[x+1].equals("B") && in[x+2].equals("C")){
        Ans++;
      }
    }
    System.out.println(Ans);
  }
}

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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int ans=0;
    rep(i, 0, n){
        if(s[i]!=t[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, X;
  cin>>N>>M>>X;
  vector<int> gates(N);
  for(int i=0; i<N; i++){
    int a;
    cin>>a;
    gates.at(a)=1; //料金所があれば1
  }
  int sum1=0;
  int sum2=0;
  for(int i=1; i<X; i++){
    sum1+=gates.at(i);
  }
  for(int i=X+1; i<N; i++){
    sum2+=gates.at(i);
  }
  cout << min(sum1, sum2) <<endl;
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main extends App {
  val n = readInt
  var ans = 0

  for (_ <- 1 to n) {
    val num = readInt
    if (isPrime(num)) ans += 1
  }

  println(ans)

  def isPrime(x: Int): Boolean = {
    if (x == 2) true
    else if (x < 2 || x % 2 == 0) false
    else {
      var i = 3
      while (i <= Math.sqrt(x)) {
        if (x % i == 0) return false
        i = i + 2
      }
      true
    }
  }
}


Measured memory_bytes: 49168
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

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

  ll base = 1;
  string ans = "";
  while(n){
    if(n % 2 == 0) ans = "0" + ans;
    else{
      n--;
      ans = "1" + ans;
    }
    n /= -2;
  }
  if(ans == "") ans = "0";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;

signed main(){
  int d,n;
  cin>>d>>n;
  if(d==0){
    if(n==100)cout<<101<<endl;
    else cout<<n<<endl;
    return 0;
  }else if(d==1){
    if(n==100){
      cout<<10100<<endl;
    }else{
      cout<<n*100<<endl;
    }
  }else{
    if(n==100)cout<<1010000<<endl;
    else cout<<n*10000<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
using namespace std;
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes";
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No";
            return 0;
        }
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>

typedef long long ll;
using namespace std;

//class Node{
//public:
//    ll value;
//    Node* parent;
//    Node* leftChild;
//    Node* rightChild;
//    int left;
//    int right;
//    Node(int value,){
//
//    }
//};


bool isPrime(int n){
    if(n < 2){
        return 0;
    }
    if(n%2 == 0){
        return n==2;
    }
    for(int i=3;i*i<=n;i++){
        if(n%i == 0) return 0;
    }
    return 1;
}


int main() {
    string s[] = {"AC", "WA", "TLE",  "RE"};
    int n;
    cin>>n;
    map<string,int> m;
    while(n--){
        string h;
        cin>>h;
        m[h]++;
    }
    for(int i=0;i<4;i++){
        cout<<s[i]<<" x "<<m[s[i]]<<endl;
    }



    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    cin >> k;
    ll ans = 0;
    REP(i,1,k+1)
    {
      REP(j,1,k+1)
      {
        REP(l,1,k+1)
        {
          ans += gcd(i,gcd(j,l));
        }
      }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
a = int(input())
b = int(input())
c = int(input())
d = int(input())
if a>=b and c>=d:
    print(b+d)
elif a>b and c<d:
    print(b+c)
elif a<b and c>d:
    print(a+d)
else:
    print(a+c)

Measured memory_bytes: 3060