akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;

namespace at_coder
{
#if TEST
    [TestClass]
#endif
    public class Test_169_b
    {
        // いまいち 実装がきれいではない・・
        // mod int を使う方が良かったかも・・
        // 実行結果NG だったので別の方法を利用する

        // 10^18 を 「超える」 の実装誤り ＝ は 超えていない。

#if TEST
        public static void Test_Main()
#else
        public static void Main()
#endif
        {
            int n = ReadInt();
            long[] ar = ReadLongArray();

            // 10^18 を 超えた数字;
            long limit = 1_000_00000_00000_00000L;

            bool over = false;
            long l = 1;
            for(int i=0;i<ar.Length;i++)
            {
                long l_next = 0;
                try
                {
                    checked
                    {
                        l_next = l * ar[i];
                    }
                }
                catch
                {
                    // オーバーフローした
                    l_next = 1;
                    over = true;
                }
                if (l_next == 0)
                {
                    // 0 は終了
                    l = 0;
                    break;
                }

                if (l_next > limit)
                {
                    // 10^18 を超えた (= は含まない）
                    over = true;
                    l_next = 1;
                }

                l = l_next;
            }

            if (over & l > 0)
            {
                l = -1;
            }

            Write($"{l}");
        }


        private static void Write(string s)
        {
            Console.WriteLine(s);
        }

        private static long[] ReadLongArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            long[] ar = new long[ss.Length];
            for (int i = 0; i < ss.Length; i++)
            {
                ar[i] = long.Parse(ss[i], CultureInfo.InvariantCulture);
            }
            return ar;
        }
        private static int ReadInt()
        {
            return int.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
        }
        private static void ReadInt(out long a, out long b)
        {
            var ar = ReadLongArray();
            a = ar[0];
            b = ar[1];
        }

        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            return ss;
        }
#if !TEST
    }
}
#endif

Measured memory_bytes: 51176
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int N,L[210]={},ans=0;
    cin >> N;

    for(int i=0;i<(2*N);i++){
        cin >> L[i];
    }

    sort(L,L+(2*N));

    for(int i=0;i<(2*N);i++){
        if(i%2==0)ans+=L[i];
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int n2 = n * n;
		int[] p = new int[n2];
		sa = br.readLine().split(" ");
		for (int i = 0; i < n2; i++) {
			p[i] = Integer.parseInt(sa[i]) - 1;
		}
		br.close();

		int[][] a = new int[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(a[i], 1);
		}
		int[][] b = new int[n][n];
		for (int i = 1; i < n - 1; i++) {
			for (int j = 1; j < n - 1; j++) {
				int ni = n - 1 - i;
				int nj = n - 1 - j;
				b[i][j] = Math.min(i, j);
				b[i][j] = Math.min(b[i][j], ni);
				b[i][j] = Math.min(b[i][j], nj);
			}
		}

		int[] dx = {-1, 1, 0, 0};
		int[] dy = {0, 0, -1, 1};
		int ans = 0;
		for (int i = 0; i < n2; i++) {
//			System.out.println(p[i]);
//			for (int j = 0; j < n; j++) {
//				for (int j2 = 0; j2 < n; j2++) {
//					System.out.print(b[j][j2] + "\t");
//				}
//				System.out.println();
//			}

			int x = p[i] / n;
			int y = p[i] % n;
			ans += b[x][y];
			a[x][y] = 0;
			Queue<Integer> que = new ArrayDeque<>();
			que.add(p[i]);
			while (!que.isEmpty()) {
				int cur = que.poll();
				int cx = cur / n;
				int cy = cur % n;
				for (int k = 0; k < 4; k++) {
					int nx = cx + dx[k];
					int ny = cy + dy[k];
					int alt = b[cx][cy] + a[cx][cy];
					if (0 <= nx && nx < n && 0 <= ny && ny < n
							&& alt < b[nx][ny]) {
						que.add(nx * n + ny);
						b[nx][ny] = alt;
					}
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 68208
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define PII pair<ll,ll>
#define VI  vector<ll>
#define VB  vector<bool>
#define VVI vector<vector<ll>>
#define VS  vector<string>
#define VP  vector<PII>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
#define lr(i,a,b) for(ll i=a;i>=b;i--)
#define lfl(i,v) for(ll i=0;i<v.size();i++)
#define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--)
#define chk2(a,b) cout<<"check :  "<<a<<" "<<b<<endl
#define chk3(a,b,c) cout<<"check :  "<<a<<" "<<b<<" "<<c<<endl
#define chk4(a,b,c,d) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define chk5(a,b,c,d,e) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
#define lb(v,k)  lower_bound(v.begin(),v.end(),k)-v.begin()
#define ub(v,k)  upper_bound(v.begin(),v.end(),k)-v.begin()
#define mod 1000000007
#define pb push_back
#define pf push_front
#define m_p make_pair
#define fi first
#define se second
#define sz size()
#define sort(v) sort(v.begin(),v.end())
ll n,k;
VI wt;
VI vals;
ll dp[105][100005]; 
ll fun(ll ind,ll rem)
    {   if(ind>n)
            return 0;
        if(dp[ind][rem]!=-1)
            return dp[ind][rem];
        ll maxi=0;
        if(wt[ind]<=rem)
        {   maxi=max(maxi,vals[ind]+fun(ind+1,rem-wt[ind]));
        }
        maxi=max(maxi,fun(ind+1,rem));
        return dp[ind][rem]=maxi;
    }
int main()
{   cin>>n;
    ll W;cin>>W;
    wt=VI(n+1);
    vals=VI(n+1);
    lf(i,1,n)
    {   cin>>wt[i];
        cin>>vals[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<fun(1,W)<<endl; 
}

Measured memory_bytes: 82432
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
G = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]
L = [G[k][0] for k in range(M)]
R = [G[k][1] for k in range(M)]
L.sort(reverse=True)
R.sort()
print(max(R[0] - L[0] + 1, 0))


Measured memory_bytes: 23228
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  int n;
  cin >> n;
  int colors[9] = {0};
  REP(i, n) {
    int a;
    cin >> a;
    if (a / 400 >= 8) {
      colors[8] += 1;
    } else {
      if (colors[a / 400] == 0) {
        colors[a / 400] = 1;
      }
    }
  }
  int count = 0;
  REP(i, 8) { count += colors[i]; }

  cout << max(count, 1) << " " << count + colors[8] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int A,B,C,K;
  scanf("%d%d%d%d", &A,&B,&C,&K);
  int max = A;
  if(A < B)max = B;
  if(max < C)max = C;

  int sum = A + B + C - max;
  for(int i = 1;i <= K;i++){
      max = max*2;
  }sum = sum + max;
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 128
n, *x = map(int, open(0).read().split())

mod = 10 ** 9 + 7

y = []
for i in range(n - 1):
    y.append(x[i + 1] - x[i])

fac = [1] * (n + 1)
for i in range(1, n):
    fac[i] = fac[i - 1] * i % mod

dp = [0] * n
ans = 0
p = 0

for i in range(n - 1):
    p = (p + pow(i + 1, mod - 2, mod))
    ans = (ans + p * y[i]) % mod

print(ans * fac[n - 1] % mod)


Measured memory_bytes: 21256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
vector<ll> h;
ll dp[100005],n;
ll solve(int i)
{
    if(i==n-1) return 0;
    if(~dp[i]) return dp[i];
    ll ans = abs(h[i]-h[i+1])+solve(i+1);
    if(i+2<n)
        ans=min(ans, abs(h[i]-h[i+2])+solve(i+2));
    return dp[i]=ans;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    ll x;
    cin>>n;
    while(n--)
    {
        cin>>x;
        h.push_back(x);
    }
    memset(dp, -1, sizeof dp);
    n=(int)h.size();
    cout<<solve(0)<<endl;
} 


Measured memory_bytes: 6644
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	if(n < 1000)
	{
		printf("ABC\n");
	}
	else if(n >= 1000&&n<=1998)
	{
		printf("ABD\n");
	}
	return 0;
 } 

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

#define int long long
const int MOD = 1000000007LL;

signed main(){

    int n; cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    vector<int> dp(n, MOD);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        if(i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + (int)abs(h[i + 1] - h[i]));
        if(i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + (int)abs(h[i + 2] - h[i]));
    }

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

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
int main() {
  int n, t, x, y, t1, x1, y1;
  t = x = y = 0;
  scanf("%d", &n);
  while (n--) {
    scanf("%d%d%d", &t1, &x1, &y1);
    int d = std::abs(x - x1) + std::abs(y - y1);
    if (d > t1 - t || (d + t1 - t) % 2) return puts("No") & 0;
  }
  return puts("Yes") & 0;
}

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

#define int long long
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
ifstream ifs("in.txt");
ofstream ofs("out.txt");
#define cin ifs
#define cout ofs
//*/

int X;
signed main() {
    cin >> X;
    int ans = 1;
    for (int b = 1; b <= X; b++) {
        int a = b;
        for (int p = 2; p <= 100; p++) {
            a *= b;
            if (a > X) break;
            ans = max(ans, a);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int n, x, y, d1, d2, a[2000] = {};
    cin >> n >> x >> y;
    for (int i = 1; i <= n-1; i++) {
        for (int j = i + 1;j <= n;j++) {
            d1 = abs(x - i) + abs(j - y) + 1;
            d2 = j - i;
            a[min(d1, d2)]++;
        }
    }
    for (int i = 1; i <= n - 1;i++) {
        cout << a[i] << endl;
    }
}


    
    

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

c = Counter(A)
sort_A = sorted(c.items(), key=lambda x: x[0], reverse=True)
if sort_A[0][1] > 1:
    for _ in range(N):
        print(sort_A[0][0])
else:
    for i in range(N):
        if A[i] != sort_A[0][0]:
            print(sort_A[0][0])
        else:
            print(sort_A[1][0])


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

if (X <= 599):
    print('8')
elif (X <= 799):
    print('7')
elif (X <= 999):
    print('6')
elif (X <= 1199):
    print('5')
elif (X <= 1399):
    print('4')
elif (X <= 1599):
    print('3')
elif (X <= 1799):
    print('2')
elif (X <= 1999):
    print('1')

Measured memory_bytes: 9184
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	int N;
	scanf("%d", &N);
	int f[101] = { 0 };
	int cnt = 0;
	int ans = 0;
	int max = -1;
	for (int num = N; num >= 1; num--) {
		int tmp = num;
		cnt = 0;
		while (tmp % 2 == 0 && tmp != 0) {
			tmp = tmp / 2;
			cnt++;
		}
		if (max < cnt) {
			ans = num;
			max = cnt;
		}
		
	}
	
	printf("%d\n", ans);


#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] A = new int[N];
        HashMap<Integer, Integer> map = new HashMap<>();

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            if(map.containsKey(A[i])){
                map.put(A[i], map.get(A[i]) + 1);
            }
            else{
                map.put(A[i], 1);
            }
        }
        int l = map.size();
        if(l%2==0){
            System.out.println(l - 1);
        }
        else{
            System.out.println(l);
        }
    }
}

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

using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));

#define debug(x) std::cout << #x << ": " << x << endl
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n;
string s;

//check T
void solve()
{
	cin >> s;
	int ca = 0, cb = 0;
	rep(i, 0, 3) if(s[i] == 'A') ca++;
	cout << ((ca==0 || ca==3) ? "No" : "Yes" )<< endl;
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

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

  int five = 0,sev = 0;

  if(A == 5){
    five++;
  } else if(A == 7){
    sev++;
  }
  if(B == 5){
    five++;
  } else if(B == 7){
    sev++;
  }
  if(C == 5){
    five++;
  } else if(C == 7){
    sev++;
  }
  if(five == 2 && sev == 1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}



Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010;
int n,a[N];
vi V;

int main(){
    scanf("%d",&n);
    rep(i,0,n) scanf("%d",a + i) , V.pb(a[i]);
    sort(all(V));
    rep(i,0,n) a[i] = lower_bound(all(V),a[i]) - V.begin();
    int ans = 0;
    rep(i,0,n) ans += (a[i]&1) != (i&1);
    ans >>= 1;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1148
#include<iostream>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	A = (A + 11) % 13;
	B = (B + 11) % 13;
	if (A > B)cout << "Alice" << endl;
	else if (A < B)cout << "Bob" << endl;
	else cout << "Draw" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,s,x,y,w=0;
  cin>>k>>s;
  for(x=0;x<=k;x++) for(y=0;y<=min(k,s-x);y++) if(s-x-y<=k) w++;
  cout<<w<<endl;
}

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

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

    bool T1[10] = {};
    bool T2[100] = {};
    bool T3[1000] = {};
    for (char s: S)
    {
        s -= '0';
        for (int i=0; i<100; i++)
            if (T2[i])
                T3[i*10+s] = true;
        for (int i=0; i<10; i++)
            if (T1[i])
                T2[i*10+s] = true;
        T1[s] = true;
    }
    int ans = 0;
    for (bool t: T3)
        if (t)
            ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 888
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int A, B, C, D;

int main()
{
	in >> A >> B >> C >> D;

	if ((B < C) || (D < A))
	{
		out << 0 << std::endl;
	}
	else if (A <= C&&D <= B)
	{
		out << D - C << std::endl;
	}
	else if (C <= A&&B <= D)
	{
		out << B - A << std::endl;
	}
	else if (A <= C&&B <= D)
	{
		out << B - C << std::endl;
	}
	else if (C <= A&&D <= B)
	{
		out << D - A << std::endl;
	}
	return 0;
}

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

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

const ll INF = 1LL << 60;

int main(){
  int n,k;
  cin >> n >> k;
  int h[n+5];
  for(int i = 0;i<n;++i) cin >> h[i];
  ll dp[n+k+5];
  for(int i = 0;i<n+k+5;++i) dp[i] = INF; //初期化
  dp[0] = 0; //初期値
  //ループ
  for(int i = 0;i<n;++i){
    for(int j = 1;j<k+1;++j){
      chmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout << dp[n-1];//出力
}

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

using namespace std;
typedef long long ll;

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




int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, k, l, counter;
    cin >> n >> k;
    ll s, ans, a[n], a_sum[n+1], m, p;
    vector<ll> number, new_number;
    s = 0;
    a_sum[0] = 0;
    rep(i, n){
        cin >> a[i];
        s += a[i];
        a_sum[i+1] = s;
    }
    rep(i, n)
        rep2(j, i, n){
            number.push_back(a_sum[j+1] - a_sum[i]);
        }
    l = 0;
    m = a_sum[n];

    while (m){
        l++;
        m /= 2;
    }

    ans = 0;
    rep(i, l){
        p = pow(2, l-i-1);
        counter = 0;
        for (auto x : number){
            if (x & p){
                counter++;
                new_number.push_back(x);
            }
        }
        if (counter >= k){
            ans += p;
            number = new_number;
        }
        new_number.clear();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int N;

vector<bool> build(v(bool) &A) {
  v(bool) balls(N,false);
  drep(x,N) {
    int k = (x+1) * 2 - 1;
    bool even = true;
    while(true) {
      if(k >= N) break;
      if(balls[k]) {
        even = !even;
      }
      k += (x+1);
    }
    if(even) {
      if(A[x]) {
        balls[x] = true;
      }else {
        balls[x] = false;
      }
    } else {
      if(A[x]) {
        balls[x] = false;
      } else {
        balls[x] = true;
      }
    }
  }
  return balls;
}
  
int main() {
  
  cin >> N;
  v(bool) A(N);
  rep(i,N) {
    int x;
    cin >> x;
    if(x == 1) A[i] = true;
    else A[i] = false;
  }
  v(bool) balls = build(A);
  int m = count(rng(balls),true);
  cout << m << endl;
  bool f = true;
  rep(i,N) {
    if(balls[i]) {
      if(!f) cout << " ";
      cout << i+1;
      f = false;
    }
  }
  if(m >0) cout << endl;
  return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i, N) { cin >> X[i]; }
    int mi = 1e9;
    for (int p = 1; p <= 100; p++) {
        int sum = 0;
        rep(i, N) { sum += pow(p - X[i], 2); }
        mi = min(mi, sum);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
//template
int ans[530][530];
int N,k=1;
int line(int u,int v,int level){
  u%=k;v%=k;
  if(u>v)swap(u,v);
  if(ans[u][v])return -1;
  ans[u][v]=level;return 0;
}
void f(int s,int M,int d,int cnt){
  if(M==1)return;
  for(int j=1;j<=M/2;j+=2)
    for(int i=0;i<k;i+=d)
      if(line(s+i,s+i+j*d,cnt)<0)return;
  f(s,M/2,d*2,cnt+1);
  f(s+d,M/2,d*2,cnt+1);
}
//main
signed main(){
  cin>>N;
  while(k<N)k<<=1;
  f(0,k,1,1);
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++)cout<<ans[i][j]<<" ";cout<<endl;
  }
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        x = Math.abs(x);
        if (x > 0 && (x * 1.0 / k >= d)) {
            System.out.println(x - k * d);
            return;
        }
        if (x > 0) {
            long num = (long)Math.ceil(x * 1.0 / d);
            long xx = x - ((num - 1) * d);
            if ((k - (num - 1)) % 2 == 0) {
                System.out.println(xx);
            } else {
                System.out.println(Math.abs(xx - d));
            }
        } else {
            if (k % 2 == 0) {
                System.out.println(0);
            } else {
                System.out.println(d);
            }
        }
    }
}

Measured memory_bytes: 35324
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

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

  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      ans = max(ans, abs(a[i] - a[j]));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 範囲が A+iC-jD ~ A+iD-jC の形で進む

N,A,B,C,D = LI()

for i in range(N):
    if A+i*C-(N-1-i)*D <= B <= A+i*D-(N-1-i)*C:
        print('YES')
        exit()

print('NO') 

Measured memory_bytes: 39024
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  int n;
  cin >> n;
  v a(n, 0);
  rep(i, n) cin >> a[i];

  v memo(n, 0);
  rep(i, n - 1) {
    if (a[i] < a[i + 1]) {
      memo[i] = -1;
    }
  }
  rep(i, n - 1) {
    if (a[i] > a[i + 1]) {
      memo[i] = 1;
    }
  }
  memo[n - 1] = a[n - 1] < a[n - 2] ? -1 :  1;

  ll money = 1000;
  ll kabu = 0;
  rep(i, n - 1) {
    if(memo[i] == -1) {
      //buy
      ll tmp = money / a[i];
      kabu += tmp;
      money -= tmp * a[i];
    }
    if(memo[i] == 1) {
      //sell
      money += kabu * a[i];
      kabu = 0;
    }
  } 
  if (memo[n - 1] == 1) {
      money += kabu * a[n - 1];
      kabu = 0;
  }
  cout << money << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

int n, m;
int a[81][81], b[81][81];
const int ZERO = 80 * 80 + 1;
bitset<ZERO + ZERO - 1> dp[81][81];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> b[i][j];
        }
    }
    dp[0][0][a[0][0] - b[0][0] + ZERO] = 1;
    dp[0][0][b[0][0] - a[0][0] + ZERO] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            int a1 = abs(a[i][j] - b[i][j]);
            //cout << i << " " << j << " " << a1 << endl;
            if (i - 1 >= 0)
            {
                dp[i][j] |= dp[i - 1][j] << a1;
                dp[i][j] |= dp[i - 1][j] >> a1;
            }
            if (j - 1 >= 0)
            {
                dp[i][j] |= dp[i][j - 1] << a1;
                dp[i][j] |= dp[i][j - 1] >> a1;
            }
            //cout << dp[i][j].count() << endl;
        }
    }
    int ans = 1e9;
    for (int i = 0; i < 2 * ZERO - 1; i++)
    {
        if (dp[n - 1][m - 1][i]) ans = min(ans, abs(i - ZERO));
    }
    cout << ans;
}


Measured memory_bytes: 10496
N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
    print(0)
else:
    D.sort()

    if D[1] == 0:
        print(0)
    else:
        mod = 998244353
        ans = 1
        distance = 0
        prev = 1
        now = 0

        for i in range(N):
            if D[i] == distance:
                now += 1
            elif D[i] == distance + 1:
                ans = (ans % mod) * (prev ** now % mod) % mod
                prev = now+0
                now = 1
                distance += 1
            else:
                ans = 0
                break
        else:
            ans = (ans % mod) * (prev ** now % mod) % mod
        
        print(ans)

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


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


int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];


  vector<pair<ll, ll>> b;
  rep(i, n){
    b.push_back({a[i], i+1});
  }

  sort(all(b));

  string pt = "";
  rep(i, n){
    cout << pt << b[i].second;
    pt = " ";
  }
  cout << endl;


  return 0;
}


Measured memory_bytes: 3312
n = gets.to_i
a = gets.split.map(&:to_i)

max = a.index(a.max)
min = a.index(a.min)

c = 0
ans = []
if a[max] + a[min] > 0
    n.times do |i| 
        if a[i] < 0
            a[i] += a[max] 
            c += 1
            ans << "#{max+1} #{i+1}"
        end
    end

    0.upto(n-2) do |i|
        max = i if a[max] < a[i]

        while a[i] > a[i+1]
            a[i+1] += a[max]
            c += 1
            ans << "#{max+1} #{i+2}"
        end
    end
else
    n.times do |i|
        if a[i] > 0
            a[i] += a[min] 
            c += 1
            ans << "#{min+1} #{i+1}"
        end
    end

    (n-1).downto(1) do |i|
        min = i if a[min] > a[i]

        while a[i-1] > a[i]
            a[i-1] += a[min]
            c += 1
            ans << "#{min+1} #{i}"
        end
    end
end

#p a
puts c,ans

Measured memory_bytes: 1788
M = 3501
N = int(input())
for h in range(1, M):
    for w in range(1, M):
        u = 4*h*w-N*w-N*h
        d = N*h*w
        if u <= 0:
            continue
        if d % u == 0:
            print(h, w, d//u)
            exit()


Measured memory_bytes: 40556
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int n, a, b, c;
vector<int> l;

int mergeCost(int v) {
	return v == 0 ? 0 : 10;
}

int solve(int idx, int al, int bl, int cl) {
	if (idx == n) {
		if (al == 0 || bl == 0 || cl == 0) {
			return 1e8;
		}

		return abs(a - al) + abs(b - bl) + abs(c - cl);
	}

	int res = 0;
	res = solve(idx + 1, al, bl, cl);

	res = min(res, solve(idx + 1, al + l[idx], bl, cl) + mergeCost(al));
	res = min(res, solve(idx + 1, al, bl + l[idx], cl) + mergeCost(bl));
	res = min(res, solve(idx + 1, al, bl, cl + l[idx]) + mergeCost(cl));

	return res;
}

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

	cin >> n >> a >> b >> c;

	l.resize(n);
	for (auto &v : l) {
		cin >> v;
	}

	cout << solve(0, 0, 0, 0) << endl;
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
data = [[0,1] for i in range(n)]
data[0] = [1,1]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    data[b][1] += 1
    data[a][1] -= 1
    if data[a][0] == 1:
        data[b][0] = 1
    if data[a][1] == 0:
        data[a][0] = 0
else:
    ans = 0
    for i in data:
        if i[0] == 1:
            ans += 1
    else:
        print(ans)
        
       
        

Measured memory_bytes: 14964
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
int main(){
  double N,temp,ans=0.0;
  std::cin>>N;
  std::vector<double>arr;
  for (int i=0;i<N;i++){
    std::cin>>temp;
    arr.push_back(temp);
  }
  std::sort(arr.begin(),arr.end());
  ans+=arr[0]/(std::pow(2,N-1));
  for (int i=1;i<N;i++){
    ans+=arr[i]/(std::pow(2,N-i));
  }
  std::cout<<ans<<std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int w, n;
int ans[20];

void swap(int *x, int *y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

int main() {
    int i = 0;

    scanf("%d", &w);
    scanf("%d", &n);

    for(i = 0; i<w; ++i) {
        ans[i] = i;
    }
    for(i = 0; i <n; ++i) {
        int a, c, b;
        scanf("%d%c%d", &a, &c, &b);
        --a, --b;
        swap(&ans[a], &ans[b]);
    }
    for(i = 0; i<w; ++i) {
        printf("%d\n", ans[i] + 1);
    }
}


Measured memory_bytes: 2008
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
long long n,a[10001],ans;
int main()
{
	cin>>n;
	n*=2;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i+=2) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

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

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
        
    string N;
    cin >> N;
    bool flag = false;
    rep(i, 3) {
        if (N[i] == '7') {
            flag = true;
        }
    }
    flag ? y() : n();
    


}


Measured memory_bytes: 3676
// https://atcoder.jp/contests/abc166/tasks/abc166_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC\n";
    } else {
        cout << "ABC\n";
    }

    return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int a = ni();
		int b = ni();
		int t = ni();

		out(t / a * b);

	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

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

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

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

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

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

	static long lcm(long m, long n) {

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

	static int lcm(int m, int n) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

public class Main {
    private FastScanner in;
    private PrintWriter out;

    long getAns(long h, long w) {
        long res = Long.MAX_VALUE;
        if (h >= 3) {
            res = (h + 2) / 3 * w - h / 3 * w;
        }
        for (int h1 = 1; h1 + 1 <= h; h1++) {
            long s1 = h1 * 1L * w;
            long s2 = (h - h1) * 1L * (w / 2);
            long s3 = (h - h1) * 1L * ((w+1)/2);
            long sMax = Math.max(s1, s3);
            long sMin = Math.min(s1, s2);
            res = Math.min(res, sMax - sMin);
        }
        return res;
    }

    private void solve() {

        int h = in.nextInt();
        int w = in.nextInt();
        out.println(Math.min(getAns(h, w), getAns(w, h)));
    }

    private void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void runIO() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

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

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
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; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

ll BellmanFord(vector<vector<pair<ll,ll>>> &graph) {
    int n=sz(graph);
    vector<ll> dist(n,LINF);
    dist[0]=0;
    rep(i,n-1) {
        rep(from,n) {
            for(auto p:graph[from]) {
                int to=p.first;
                ll cost=p.second;
                chmin(dist[to],dist[from]+cost);
            }
        }
    }
    
    rep(i,n) {
        rep(from,n) {
            for(auto p:graph[from]) {
                int to=p.first;
                ll cost=p.second;
                if(dist[to]>dist[from]+cost) {
                    dist[to]=-LINF;
                }
            }
        }
    }
    
    return dist[n-1];
}

int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<pair<ll,ll>>> graph(n);
    while(m--) {
        int a,b;
        ll c;
        cin>>a>>b>>c;
        a--;b--;
        graph[a].emplace_back(b,-c);
    }
    
    ll ans=BellmanFord(graph);
    if(ans==-LINF) cout<<"inf"<<endl;
    else cout<<-ans<<endl;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String o = in.nextLine();
            String e = in.nextLine();
            String password = "";

            int size = Math.max(o.length(), e.length());

            for (int i = 0; i < size; ++i) {
                if (i < o.length()) {
                    password += String.valueOf(o.charAt(i));
                }

                if (i < e.length()) {
                    password += String.valueOf(e.charAt(i));
                }
            }

            out.println(password);
        }

    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ac=0,re=0,wa=0,tl=0;
    cin>>n;
    while(n--)
    {
        string ar;
        cin>>ar;
        if(ar=="AC")
        {
          ac++;
        }
        if(ar=="WA")
        {
            wa++;
        }
        if(ar=="TLE")
        {
            tl++;
        }
        if(ar=="RE")
        {
            re++;
        }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tl<<endl;
    cout<<"RE x "<<re<<endl;
}


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

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

    if(S[2]==S[3] && S[4]==S[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

int main(){
    int n; cin >> n;
    vector <int> a(n), sorted(n);
    for(int i = 0; i < n; i++){
        cin >> a[i]; sorted[i] = a[i];
    }
    sort(sorted.begin(), sorted.end());
    for(int i = 0; i < n; i++){
        cout << ((a[i]==sorted[n-1]) ? sorted[n-2] : sorted[n-1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
/*
2020-04-26
atcoder ABC
B - Battle
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

int main() {
    int a, b, c, d, taka_time, aoki_time ;
    cin >> a >> b >> c >> d;
    taka_time = (c + b - 1) / b;
    aoki_time = (a + d - 1) / d;
    if (taka_time <= aoki_time) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3624