akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define openfile freopen("input.txt", "r" ,stdin); freopen("output.txt", "w", stdout); 
#define FOR(n) for(int i(0);i<n;++i)
#define ASC(i,a,b) for(int i(a); i <=b; ++i)
#define DESC(i,a,b) for(int i(a);i>=b;i--)
#define WL(t) while(t--)
#define SZ(a) int((a).size())
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define BB begin()
#define EE end()
#define all(c) c.BB, c.EE
#define present(container, element) (container.find(element) != container.end())
// ^^for set,map etc
#define cpresent(container, element) (find(all(container), element) != container.end())
// for vector,array etc
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;
const float INF = numeric_limits<float>::infinity();
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
const LL big=998244353;

#ifdef _DEBUG
freopen(input.txt,"r",stdin);
freopen(output.txt,"w",stdout);
#endif


int countDigit(long long n) 
{ 
    return floor(log10(n) + 1); 
} 

int main(){
	fast
	int n,a=0;
	cin >> n;
	for(int i(1);i<=n;++i){
		if(countDigit(i)&1) a++;
	}
	cout << a;

}

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

using namespace std;

using ll = long long;

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define all(v) v.begin(), v.end()

struct node {
  int x, y, z;
  ll v;
  node(int a, int b, int c, ll d) : x(a), y(b), z(c), v(d) {}
  bool operator<(const node a) const {
    if (v == a.v) {
      if (x == a.x) {
        if (y == a.y) {
          if (z == a.z) {
            return false;
          }
          return z < a.z;
        }
        return y < a.y;
      }
      return x < a.x;
    }
    return v < a.v;
  }
  bool operator>(const node b) const {
    return b < (*this);
  }
};

vector<ll> a, b, c;

node calc(int x, int y, int z)
{
  if (x < a.size() && y < b.size() && z < c.size()) {
    node n(x, y, z, a[x] + b[y] + c[z]);
    return n;
  }
  node n(x, y, z, 0);
  return n;
}

int main()
{
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  a.resize(x);
  b.resize(y);
  c.resize(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  sort(all(a), greater<ll>());
  sort(all(b), greater<ll>());
  sort(all(c), greater<ll>());
  priority_queue<node> q;
  q.push(calc(0, 0, 0));
  set<node> s;
  s.insert(calc(0, 0, 0));
  while (1) {
    if (k == 0) break;
    auto a = q.top();
    q.pop();
    cout << a.v << endl;
    node t = calc(a.x+1, a.y, a.z);
    if (s.count(t) == 0) {
      q.push(t);
      s.insert(t);
    }
    t = calc(a.x, a.y+1, a.z);
    if (s.count(t) == 0) {
      q.push(t);
      s.insert(t);
    }
    t = calc(a.x, a.y, a.z+1);
    if (s.count(t) == 0) {
      q.push(t);
      s.insert(t);
    }    
    k--;
  }
}



Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

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

    ll t = 0;
    ll a = 0;
    Rep (i, N) {
        ll rate = 0;
        if (i == 0) {
            t = T[i];
            a = A[i];
        } else {
            rate = max((t+T[i]-1)/T[i], (a+A[i]-1)/A[i]);
            t = rate * T[i];
            a = rate * A[i];
        }
        // cout << "t=" << t << ":a=" << a << "\n";
    }

    cout << t + a << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b; // Be careful not to overflow
}

int main() {

    int N, K;
    cin >> N >> K;
    
    int ma = 0;
    vector<int> A(N);
    REP(i, N) {
        cin >> A[i];
        maxs(ma, A[i]);
    }
    ll g = A[0];
    RREP(i, 1, N) {
        g = gcd(g, A[i]);
    }

    cout << (K % g == 0 && K <= ma ? "POSSIBLE" : "IMPOSSIBLE") << endl;



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

Measured memory_bytes: 640
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN4(a,b,c,d);
  x = c - a;
  y = d - b;
  cout << c-y << " " << d+x << " " << a-y << " " << b+x << endl;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
n = int(input())
ans = 0
for i in range(1,n+1,2):
    c = make_divisors(i)
    if len(c) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a[10],i,b=0,c=0;
    for(i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]==5)
            b++;
        if(a[i]==7)
            c++;
    }
    if(b==2&&c==1)
        printf("YES\n");
    else
        printf("NO\n");
//    for(i=0;i<2;i++)
//        for(j=0;j<2-i;j++)
//            if(a[j]>a[j+1])
//            {
//                t=a[j];a[j]=a[j+1];a[j+1]=t;
//            }
//    if(a[0]==5&&a[1]==7&&a[2]==5)
//        printf("YES\n");
//    else
//        printf("NO\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<pair<int,int>,string> item;
main(){
	int n,i,w,s,S;
	string f;
	for(;cin>>n,n;){
		vector<item> items,result;
		for(i=0;i<n;i++)cin>>f>>w>>s,items.push_back(make_pair(make_pair(w,s),f));
		sort(items.begin(),items.end());
		S=99999;
		do{
			for(s=w=i=0;i<n;i++){
				if(items[i].first.second<w)break;
				w+=items[i].first.first;
				s+=(n-i)*items[i].first.first;
			}
			if(i==n&&s<S)S=s,result=items;
		}while(next_permutation(items.begin(),items.end()));
		reverse(result.begin(),result.end());
		for(i=0;i<n;i++)cout<<result[i].second<<endl;
	}
}

Measured memory_bytes: 1216
while True:
    cnt = 0
    n, x = map(int, input().split())
    if n == x == 0: break
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if x == i+j+k:
                    cnt+=1
    print(cnt)


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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

int N;
vector<bool> v;

void init()
{
	string s;
	cin >> s;
	N = s.length();
	v.resize(N+1);
	rep(i, N) v[i+1] = s[i] == '1';
	v[0] = false;
}

bool check()
{
	if (!v[1]) return false;
	rep(i, N+1) {
		if (v[i] != v[N-i]) return false;
	}
	rep(i, N+1) {
		if (v[i] && i != N - i) {
			v[N-i] = false;
		}
	}
	return true;
}

void solve()
{
	if (!check()) {
		cout << -1 << endl;
		return;
	}
	int root = N-1;
	cout << N << " " << N - 1 << endl;
	int tyo = N - 2;
	reps(i, 2, N) {
		cout << root << " " << tyo << endl;
		if (v[i]) {
			root = tyo;
		}
		tyo--;
	}
}

Measured memory_bytes: 1576
#include<iostream>

using namespace std;

int main(){

	int a = 0;
	int b = 0;
	int c = 0;

	cin >> a >> b >> c;

	if (a < b&&b<c){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	

}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
#include <cctype>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)

const int mod = 1e9 + 7;
int32_t main() {
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n;
    cin >> s;
    vector<vector<int>>dp(n + 13, vector<int>(n + 13, 0));
    dp[1][0] = 1;
    for (int i = 2; i <= n; i++) {
        vector<int> sum(i);
        for (int j = 0; j < i - 1; j++) {
            sum[j + 1] = (sum[j] + dp[i - 1][j]) % mod;
        }
        for (int j = 0; j < i; j++) {
            if (s[i - 2] == '<') {
                dp[i][j] = sum[j];
            } else {
                dp[i][j] = (sum.back() - sum[j] + mod) % mod;
            }
        }
    }
    int ans = 0;
    for (int j = 0; j < n; j++) {
        ans += dp[n][j];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    ll dp[20005] = {};
    f1(20000){
        dp[i] = 1e18;
    }
    dp[0] = 0;
    f(k){
        int add1, add2;
        cin >> add1 >> add2;
        for(int i = 0 ; i < n ; i++){
            dp[i+add1] = min(dp[i+add1],dp[i] + add2);
        }
    }
    ll mi = 1e18;
    for(int i = n ; i <= 20000 ;i++ ){
        mi = min(mi,dp[i]);
    }
    cout << mi << '\n';
}

Measured memory_bytes: 384
N = int(input())
R = [0 for i in range(100003)]
for i in range(N):
    a, b = map(int, input().split())
    R[a] += 1
    R[b+1] -= 1
x = 1
y = 1
for i in range(100003):
    x += R[i]
    if x >= i:
        y = max(i, y)
print(y-1)


Measured memory_bytes: 6500
using System;
class Example
{
    static void Main()
    {
        string[] n = Console.ReadLine().Split(' ');
        double x1 = double.Parse(n[0]);
        double y1 = double.Parse(n[1]);
        double x2 = double.Parse(n[2]);
        double y2 = double.Parse(n[3]);
        double answer = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 9272
#include <stdio.h>
#include<iostream>
#include<string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <map>
#include <cstring>
using namespace std;
int n;
char s[200005];
int main() {
    int r=0,cnt1=0,cnt2=0;
    cin>>n;
    scanf("%s",s+1);
    for(int i=1;i<=n;i++) if(s[i]=='R') r++;
    for(int i=1;i<=r;i++) if(s[i]=='W') cnt1++;
    for(int i=r+1;i<=n;i++) if(s[i]=='R') cnt2++;
    printf("%d\n",max(cnt1,cnt2));
    return 0;
}

Measured memory_bytes: 3988
# AOJ 0205: Rock, Paper, Scissors
# Python3 2018.6.25 bal4u

h = [0]*5
while True:
	try:
		for i in range(5): h[i] = int(input())
	except: break
	if len(set(h)) == 1 or len(set(h)) == 3:
		print(*[3]*5, sep='\n')
		continue
	ans = [1]*5
	for i in range(5):
		if   h[i] == 1: ans[i] += (h.count(3) > 0)
		elif h[i] == 2: ans[i] += (h.count(1) > 0)
		else:           ans[i] += (h.count(2) > 0)
	print(*ans, sep='\n')


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

int table[1000];
int bisect_right(int x,int a[],int left,int right){
    int mid;
    right++;
    while (left < right) {
        mid = (left + right) / 2;
        if (a[mid] <= x) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    return left;
}


int counter(int i) {
    if (i == 0) {
        return 0;
    }
    return bisect_right(i,table,0,999) - 1;
    
}

void solve(long long N, int *ans ){
    int cnt = 0;
    while (N % 2 == 0) {
        cnt++;
        N /= 2;
    }
    *ans += counter(cnt);
    int now = 3;
    cnt = 0;
    while ((long long)now * now <= N) {
        while (N % now == 0) {
            cnt++;
            N /= now;
        }
        *ans += counter(cnt);
        cnt = 0;
        now += 2;
    }
    if (N != 1) {
        *ans += counter(1);
    }
}



int main(void){
    long long N;
    scanf("%lld", &N);
    for (int i = 0; i < 1000; i++) {
        table[i] = i * (i + 1) / 2;
    }
    int ans = 0;
    solve(N, &ans);
    printf("%d\n",ans);
    return 0;
}



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

int n;
vector<int> id;
string s, lst = "01+-*()";

int solve();
int dfs(int x);
int expression(int &x);
int term(int &x);
int number(int &x);
bool check();

int main() {
  cin >> s;
  n = s.size();
  cout << solve() << endl;
  return 0;
}

int solve() {
  for(int i = 0; i < n; ++i)
    if(s[i] == '.') id.push_back(i);
  return dfs(0);
}

int dfs(int x) {
  int res = -1;
  if(x == (int)id.size()) {
    if(!check()) return -1;
    x = 0;
    return expression(x);
  }
  for(int i = 0; i < 7; ++i) {
    s[id[x]] = lst[i];
    res = max(res, dfs(x + 1));
  }
  return res;
}

int expression(int &x) {
  int res = term(x);
  if(res < 0) return res;
  while(x < n) {
    if(s[x] == '+') {
      int righ = term(++x);
      if(righ < 0) return -1;
      res += righ;
    }
    else if(s[x] == '-') {
      int righ = term(++x);
      if(righ < 0) return -1;
      res -= righ;
    }
    else
      break;
    if(res < 0 || res >= (1 << 10)) return -1;
  }
  return res;
}

int term(int &x) {
  int res = number(x);
  if(res < 0) return res;
  while(x < n) {
    if(s[x] == '*') {
      int righ = number(++x);
      if(righ < 0) return -1;
      res *= righ;
    }
    else
      break;
    if(res < 0 || res >= (1 << 10)) return -1;
  }
  return res;
}

int number(int &x) {
  int res = 0;
  if(s[x] == '(') {
    res = expression(++x);
    if(res < 0) return res;
    assert(s[x] == ')');
    ++x;
    return res;
  }
  if(x == n || !isdigit(s[x])) return -1;
  while(x < n && isdigit(s[x])) {
    res <<= 1;
    res += s[x++] & 1;
    if(res >= 1 << 10) return -1;
  }
  return res;
}

bool check() {
  vector<bool> ch;
  for(int i = 0; i < n; ++i) {
    if(s[i] == '(')
      ch.push_back(0);
    else if(s[i] == ')') {
      if(ch.empty() || !ch.back()) return 0;
      ch.pop_back();
    }
    if(ch.size() &&
       (s[i] == '+' || s[i] == '-' || s[i] == '*'))
      ch.back() = 1;
    if(i != 0 && s[i - 1] == '(' && !isdigit(s[i]) &&
       s[i] != '(')
      return 0;
    if(i != 0 && s[i - 1] == ')' &&
       (isdigit(s[i]) || s[i] == '('))
      return 0;
    if(i != 0 &&
       (s[i - 1] == '+' || s[i - 1] == '-' ||
        s[i - 1] == '*') &&
       !isdigit(s[i]) && s[i] != '(')
      return 0;
    if(i != 0 && isdigit(s[i - 1]) && s[i] == '(') return 0;
  }
  return ch.empty();
}


Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	string S;
	cin >> N >> S;
	vector<vector<int>> list(10);
	for (auto i = 0; i < 10; ++i)
	{
		for (auto j = 0; j < (int)S.length(); ++j)
		{
			if (S[j] - '0' == i)
			{
				list[i].push_back(j);
			}
		}
	}

	auto ans = 0;
	for (auto i = 0; i < 1000; ++i)
	{
		auto first = i / 100;
		auto second = i / 10 % 10;
		auto third = i % 10;
		if (list[first].size() == 0
			|| list[second].size() == 0
			|| list[third].size() == 0)
		{
			continue;
		}

		auto left = *(list[first].begin());
		auto right = *(list[third].rbegin());
		auto iterLeft = upper_bound(list[second].begin(), list[second].end(), left);
		auto iterRight = lower_bound(list[second].begin(), list[second].end(), right);
		auto num = iterRight - iterLeft;
		if (num <= 0)
		{
			continue;
		}

		++ans;
	}

	cout << ans << endl;

	return 0;
}

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

  
int main()
{     int n,k;
      vector<int> h;
      cin>>n;
      cin>>k;
      h.push_back(0);
      for(int i=0;i<n;i++)
      { int x;
        cin>>x;
        h.push_back(x);
      } 
     int dp[n+1]={0};
     if(k<n)
     {
     for(int i=2;i<=k;i++){
        int ans=INT_MAX;
        for(int j=i-1;j>=1;j--)
         { ans=min(ans,dp[j]+abs(h[j]-h[i]));

         }
       dp[i]=ans;

       }
      
     for(int i=k+1;i<=n;i++){
        int ans=INT_MAX;
        for(int j=i-1;j>=i-k;j--)
         { ans=min(ans,dp[j]+abs(h[j]-h[i]));

         }
       dp[i]=ans;

       }
     }
     else{
   for(int i=2;i<=n;i++){
        int ans=INT_MAX;
        for(int j=i-1;j>=1;j--)
         { ans=min(ans,dp[j]+abs(h[j]-h[i]));

         }
       dp[i]=ans;

       }

     }
      cout<<dp[n];

      return 0;
}

Measured memory_bytes: 4128
#include <stdio.h>

int main(){
  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  if (a<=b && b<=c){
    printf("%d %d %d\n", a, b, c);
  } else if (a<=c && c<=b){
    printf("%d %d %d\n", a, c, b);
  } else if (b<=a && a<=c){
    printf("%d %d %d\n", b, a, c);
  } else if (b<=c && c<=a){
    printf("%d %d %d\n", b, c, a);
  } else if (c<=a && a<=b){
    printf("%d %d %d\n", c, a, b);
  } else if (c<=b && b<=a){
    printf("%d %d %d\n", c, b, a);
  }
  return 0;
}

Measured memory_bytes: 1828
#include<stdio.h>
int main(){
  long int n,i,j,k,A[300]={},a=0;
  char s[11],l[6]="MARCH";
  scanf("%ld",&n);
  for(i=0;i<n;i++){scanf("%s",s);A[s[0]]++;}
  for(i=0;i<5;i++)for(j=i+1;j<5;j++)for(k=j+1;k<5;k++)a+=A[l[i]]*A[l[j]]*A[l[k]];
  printf("%ld",a);
}


Measured memory_bytes: 1704
#include <iostream>
    #include <algorithm>
    #include <set>
    #include <functional>
    #include <list>
    #include <bitset>
    #include <numeric>
    #include <utility>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include<deque>
     
    #define INF 1e9
    #define MOD 1000000007
    #define ll long long
    using namespace std;
    int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
    typedef unsigned long long ull;
    typedef pair<ll, int> pr;
     
    ll a[100001];
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll n,k;
        cin>>n>>k;
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        ll bit[100];
        fill(bit,bit+100,0LL);
        for(ll i=0;i<n;i++){
            for(ll j=0;j<50;j++){
                ll x=a[i];
                if((x>>j)&1LL==1LL){
                    bit[j]++;
                }
            }
        }
        // for(ll i=0;i<4;i++){
        //     cout<<bit[i]<<" ";
        // }
    //    cout<<endl;
        ll ans=0LL;
        ll kk=0LL;
        for(ll i=50;i>=0;i--){
            if(kk+(1LL<<i)>k){
                ans+=(1LL<<i)*bit[i];
                continue;
            }
     
            if(bit[i]>=n-bit[i]){
                ans+=(1LL<<i)*bit[i];
            }
            else{
                kk+=(1LL<<i);
                ans+=(1LL<<i)*(n-bit[i]);
            }
        //    cout<<ans<<" a"<<endl;
        }
        cout<<ans<<endl;
        return 0;
    }

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int n,m;
	cin >> n >> m;
	syc(n,1,30);
	syc(m,1,30);
	int a[n][m];
	int b[n];
	int p[m];
	int count=0;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			a[i][j]=-1;
			b[n]=-1;
			if(p[j]!=0)p[j]=0;
		}
	}
	
	for(int i=0;i<n;i++){
		cin >> b[i];
		syc(b[i],1,m);
		for(int j=0;j<b[i];j++){
			cin >> a[i][j];
			syc(a[i][j],1,m);
			p[a[i][j]-1]++;
		}
	}
	
	for(int i=0;i<m;i++){
		if(p[i]==n)count++;
	}
	
	cout << count << endl;
	return 0;
}


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

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

	int sl = s.size();
	int ac, zc;
	ac = -1;
	zc = -1;
	for (int i = 0; i < sl; i++) {
		if (s.at(i) == 'A') {
			if (ac == -1) ac = i;
		}
		if (s.at(i) == 'Z') {
			zc = i;
		}
	}

	cout << zc - ac + 1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<char> c(n);
	for (int i = 0; i < n; i++) cin >> c[i];

	int counter = 0;
	vector<char>::iterator itr;
	int rnum = count(c.begin(), c.end(), 'R');
	itr = find(c.begin(), c.end(), 'R');
	while (itr!=c.end()) {
		if (distance(c.begin(),itr)>=rnum) {
			iter_swap(c.begin() + counter, itr);
			counter++;
		}
		itr = find(itr+1, c.end(), 'R');
	}
	cout << counter;
}

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

int main()
{
  int N,K,R,S,P;
  string T;
  cin>>N>>K;
  cin>>R>>S>>P;
  cin>>T;
  int ans=0;
  int A[100010]={0};
  for(int i=0;i<N;i++){
    if(i<K){
      if(T[i]=='r')A[i]=P;
      else if(T[i]=='s')A[i]=R;
      else A[i]=S;
    }
    else{
      if(T[i]!=T[i-K]){
        if(T[i]=='r')A[i]=P;
        else if(T[i]=='s')A[i]=R;
        else A[i]=S;
      }
      else if(A[i-K]==0){
        if(T[i]=='r')A[i]=P;
        else if(T[i]=='s')A[i]=R;
        else A[i]=S;
      }
    }
  }
  for(int i=0;i<N;i++){
    ans+=A[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 896
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####

def main():
	n,yen = LI()
	f = False
	for x in range(0,n+1):
		for y in range(0,n-x+1):
			z = n-x-y
			r = yen - 10000*x - 5000*y - 1000*z
			if r == 0:
				print(x,y,z)
				f = True
				break
		if f:
			break

	if f==False:
		print(-1,-1,-1)



if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
a = list(input())
b = []

for i in range(len(a)):
  if a[i] == "0":
    b.append("0")
  elif a[i] == "1":
    b.append("1")
  elif a[i] == "B" and len(b) != 0:
    b.pop()
  else:
    continue
    
print("".join(b))

Measured memory_bytes: 3060
N = int(input())

A = 0
W = 0
T = 0
R = 0

for i in range(N):
    S = input()
    if S == "AC":
        A+=1
    elif S == "WA":
        W+=1
    elif S == "TLE":
        T+=1
    elif S == "RE":
        R+=1

print("AC x " + str(A))
print("WA x " + str(W))
print("TLE x " + str(T))
print("RE x " + str(R))

Measured memory_bytes: 9204
#include <stdio.h>

int main(void){
  int H,W,i,j;
  while(1){
    scanf("%d%d",&H,&W);
    if(H == 0 && W == 0){
      break;
    }
    for(i = 1; i <= H; i++){
      for(j = 1; j <= W; j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0; 
}


Measured memory_bytes: 2104
///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl; 
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
// <=================================================================================================================================
// <=================================================================================================================================


void fun(){
    int a,b,c,k;cin>>a>>b>>c>>k;
    while(k--){
        if(b<=a){
            b*=2;
        }else if(c<=b){
            c*=2;
        }
    }
    if(c>b && b>a){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

signed  main() {
    lets_go

      int t;
      t=1;
// cin >> t;
    while (t--) {            
         fun();             
    }                        
                            
                            
    return 0;

}


Measured memory_bytes: 3648
from fractions import gcd
n=int(input())
T=[]
for i in range(n):
    t=int(input())
    T.append(t)
if n==1:
    print(T[0])
else:
    ts=T[0]*T[1]//gcd(T[0],T[1])
    for i in range(n-2):
        ts=ts*T[i+2]//gcd(ts,T[i+2])
    print(ts)

Measured memory_bytes: 5432
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
  	int n;
  int i;
  cin>>n;
  string str[n];
  map<string,int> map;
  for(i=0;i<n;i++)
  {
    	cin>>str[i];
    map[str[i]]++;
  }
  int l=map.size();
  cout<<l;
  return 0;
}

Measured memory_bytes: 25348
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        s: chars,
    }
    let mut sum: String = String::new();
    for i in 0..s.len() {
        if i % 2 == 0 {
            sum.push(s[i]);
        }
    }
    println!("{}", sum);
}

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

#define range(a, l, r) a >= l && r >= a

int main(){
	double x1, y1, x2, y2, x3, y3, xp, yp;
	double s, t;
	while(cin >> x1){
		cin >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp;
		s = ((xp-x1)*(y3-y1)-(yp-y1)*(x3-x1)) / ((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1));
		t = ((xp-x1)*(y2-y1)-(yp-y1)*(x2-x1)) / ((x3-x1)*(y2-y1)-(y3-y1)*(x2-x1));
		if(range(s, 0, 1) && range(t, 0, 1) && s+t <= 1) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 1220
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
  int katanaNum;
  int enemyHP;

  cin >> katanaNum >> enemyHP;
  vector<int> a(katanaNum);
  vector<int> d(katanaNum);
  int maxA = 0;

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

  sort(a.begin(), a.end(), greater<int>());
  maxA = a[0];
  sort(d.begin(), d.end(), greater<int>());

  int ans = enemyHP;
  for (int katanaIdx = 0; katanaIdx <= katanaNum; katanaIdx++) {
    if (enemyHP < 0) break;
    enemyHP -= d[katanaIdx];
    int count = 0;
    if(enemyHP > 0) {
    	count = (enemyHP + maxA -1) / maxA;
    }
    ans = min(ans, count + katanaIdx + 1);
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
const int N = 100005;
int n, a[N], c[2*N], s[N];
long long tot = 0;
int query(int x){
    int ans = 0;
    for(int i = x; i; i -= lowbit(i)) ans += c[i];
    return ans;
}
void add(int x){
    for(int i = x; i < 2*N; i += lowbit(i)) c[i] += 1;
}
long long sum = 0;
void Mergesort(int l, int r){
    if(l < r){
        int mid = (l + r) >> 1;
        int p = l, q = mid + 1;
        int x = l;
        Mergesort(l, mid);
        Mergesort(mid+1, r);
        while(p <= mid || q <= r){
            if(q > r || (p <= mid && s[p] < s[q])) c[x++] = s[p++];
            else{
                 sum += (p - l);
                 c[x++] = s[q++];
            }
        }
        for(int i = l; i <= r; ++i) s[i] = c[i];
    }
}
bool check(int x){
    s[0] = 0;
    for(int i = 1; i <= n; ++i){
        s[i] = s[i-1] + (a[i] <= x ? 1 : -1);
    }
   // for(int i = 1; i <= n; ++i) cout << s[i] << " ";
   // cout << endl;
    /*
    for(int i = 0; i <= n; ++i){
        sum += query(s[i] + N);
        add(s[i] + N);
    }
    */
    sum = 0;
    Mergesort(0, n);
    //cout << x << " " << sum << " " << tot/2+1 << endl;
    return sum >= (tot / 2 + 1);
}
int main(){
    int l = 1e9 + 7, r = 0, ans;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d", a+i);
        r = max(a[i], r);
        l = min(a[i], l);
        tot += i;
    }
    if(n == 1){
        return 0 * printf("%d\n", a[1]);
    }
    //cout << l << " " << r << endl;
    for(int i = 1; i <= 200; ++i){
        int mid = (l + r) >> 1;
        if(check(mid)){
            r = mid;
            ans = mid;
        }else l = mid + 1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1536
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
	int n,m;cin>>n>>m;
  int sm = 0;
  vector<int> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i];
    sm += A[i];
  }
  int z = sm/(4*m) + (sm%(4*m)?1:0);
  for(int i = 0; n > i; i++){
    if(A[i] >= z)m--;
  }
  cout << YesNo(m<=0) << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
table = []
for i in range(h):
    tmp = input()
    if tmp != '.' * w:
        table.append(tmp)
ans = []
for s in zip(*table):  # 転置
    if '#' in s:
        ans.append(s)
for a in zip(*ans):  # 転置し直す
    print(''.join(a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  rep(i, s.size()){
    if(s[i] == '?'){
      cout << 'D';
      
    }
    else 
      cout << s[i];
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 3744
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CSyntheticKadomatsu {
        int[] l;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();

            l = new int[n];
            for (int i = 0; i < n; i++) {
                l[i] = in.nextInt();
            }

            int answer = Integer.MAX_VALUE;

            for (int A = 1; A < (1 << n); A++) {
                for (int B = 1; B < (1 << n); B++) {
                    if ((A & B) != 0) {
                        continue;
                    }

                    for (int C = 1; C < (1 << n); C++) {
                        if ((A & C) != 0 || (B & C) != 0) {
                            continue;
                        }

                        int score = score(a, A) + score(b, B) + score(c, C);
                        answer = Math.min(answer, score);
                    }
                }
            }

            out.println(answer);
        }

        int score(int a, int comb) {
            for (int i = 0; i < l.length; i++) {
                if ((comb & (1 << i)) != 0) {
                    a -= l[i];
                }
            }

            return 10 * (Integer.bitCount(comb) - 1) + Math.abs(a);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

int main()
{
  int n,b,f,r,v,A[4][3][10];
  for(int i=0;i<4;i++)
    {
      for(int j=0;j<3;j++)
        {
          for(int k=0;k<10;k++)
            {
              A[i][j][k]=0;
            }
        }
    }
  cin >> n;
  for(int i=0;i<n;i++)
    {
      cin >> b >> f >> r >> v;
      A[b-1][f-1][r-1]+=v;
    }
  for(int i=0;i<4;i++)
    {
      for(int j=0;j<3;j++)
        {
          for(int k=0;k<10;k++)
            {
              cout << " " << A[i][j][k];
            }
          cout << endl;
        }
      if(i!=3)
        {
          for(int l=0;l<20;l++)
            {
              cout << "#";
            }
          cout << endl;
        }
    }
  return 0;
}

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

using namespace std;
 
const int MOD=1e9+7;

long long dp[3001][3001][4], gr[3001][3001];



//const int MOD=998244353;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int r,c,k;
    cin>>r>>c>>k;
    while(k--){
        int x,y;
        long long val;
        cin>>x>>y>>val;
        gr[x][y]=val;
    }
    
    for(int i=1; i<=r; i++){
        for(int j=1; j<=c; j++){
            dp[i][j][0]=dp[i][j-1][0];
            long long mav=0;
            for(int k=0; k<=3; k++){
                mav=max(mav,dp[i-1][j][k]);
                dp[i][j][k]=dp[i][j-1][k];
            }
            dp[i][j][0]=max(dp[i][j][0],mav);
            
            
            if(gr[i][j]){
                dp[i][j][1]=max(dp[i][j][1],mav+gr[i][j]);
                for(int k=1; k<=3; k++){
                    dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+gr[i][j]);
                }
            }
            
        }
    }
    
    long long ans=0;
    for(int k=0; k<=3; k++){
        ans=max(ans,dp[r][c][k]);
    }
    cout<<ans;
    
    
    return 0;
}

Measured memory_bytes: 355208
#include <stdio.h>
 int gcd(int x, int y){
 if(x%y == 0)
  return y;
 else
  return (gcd(y, x%y)); }

 int main(void){
 long long int x, y;
 while(scanf("%lld %lld", &x, &y)>0){
 long long int lcm=(x*y)/gcd(x, y);
 if(lcm == 0) break;
 printf("%lld %lld\n", gcd(x,y), lcm); }
 return 0;
} 


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

#define pb push_back

#define ll long long

#define ft first

#define sd second

using namespace std;

const int N = 5050 ;

bool used[N];

ll z , r , w ;

int main(){

    int n , m ;
    cin >> n >> m ;
    if( n == m ){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 131B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP  PIC X(60).
01 N    PIC 9(3).
01 L    PIC S9(3).
01 A    PIC S9(3).
01 AP   PIC 9(3).
01 TL   PIC S9(5).
01 I    PIC 9(3).
01 MIN  PIC 9(3).
01 MIS  PIC S9(3). 
01 OUT  PIC -(5)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N L.
*>
  MOVE 999 TO MIN.
  MOVE 0   TO TL.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    COMPUTE A =  L + I - 1
    MOVE A TO AP
    IF (AP < MIN)
      MOVE AP TO MIN
      MOVE A  TO MIS
    END-IF
*>
    ADD A  TO TL 
  END-PERFORM.
*>
  COMPUTE OUT = TL - MIS.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.


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

using namespace std;

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

    if (b == 1) {cout << 0; return 0;}

    int i = 1;

    int curr = a;

    while (curr < b)
    {
        curr = curr + a - 1;
        i++;
    }

    cout << i << '\n';
    return 0;
}


Measured memory_bytes: 3600
#!/usr/bin/env python3
import sys

from collections import Counter

def solve(N: int, A: "List[int]", Q: int, B: "List[int]", C: "List[int]"):
    c = Counter(A)
    s = sum(A)
    for i in range(Q):
        s += c[B[i]] * (C[i] - B[i])
        c[C[i]] += c[B[i]]
        c[B[i]] = 0
        print(s)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = int(next(tokens))  # type: int
    B = [int()] * (Q)  # type: "List[int]"
    C = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, A, Q, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30076
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll unsigned long long
using namespace std;
int n,ans;
ll Hash[5010],pow[5010];
char s[5010];
inline bool check(int len){
	for(register int i=0;i<=n-len*2+1;i++){
		for(register int j=i+len;j+len<=n+1;j++){
			if(Hash[i+len]-Hash[i]*pow[len]==Hash[j+len]-Hash[j]*pow[len])return true;
		}
	}
	return false;
}
inline void binary(int le,int ri){
	while(le<=ri){
		int mid=(le+ri)>>1;
		if(check(mid)){
			ans=mid;le=mid+1;
		}
		else{
			ri=mid-1;
		}
	}
}
int main(){
	cin>>n;scanf("%s",s+1);
	pow[0]=1;for(register int i=1;i<=5010;i++) pow[i]=pow[i-1]*19260817;
	for(register int i=1;i<=n;i++) Hash[i]=Hash[i-1]*19260817+s[i]-'a'+1;
	binary(0,n); 
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    char c[2][3];
    rep(i,0,1){
        rep(j,0,2){
            cin>>c[i][j];
        }
    }
    bool flag = true;
    rep(i,0,1){
        rep(j,0,2){
            if(c[i][j]!=c[1-i][2-j]){
                flag = false;
                break;
            }
        }
    }

    if(flag) printf("YES\n");
    else printf("NO\n");
    return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;

int main(){

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

    cout << (A-1)*(B-1) << endl;

    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d,t;
    scanf("%d %d %d %d",&a,&b,&c,&d);

    if(a>b && c>d)
        t=b+d;
    else if(a>b && d>c)
        t=b+c;
    else if(b>a && c>d)
        t=a+d;
    else if(b>a && d>c)
        t=a+c;
        else if(a==b && c>d)
            t=a+d;

        else if(a==b && d>c)
            t=a+c;

        else if(c==d && a>b)
            t=b+c;
            else if(c==d && b>a)
            t=a+c;
        else if(c==d && a==b)
            t=a+c;
    printf("%d\n",t);
    return 0;
}


Measured memory_bytes: 128
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let mut n: u64 = sc.read();
    let mut s = String::new();
    let v = vec!["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];

    while n > 0 {
        n = n - 1;
        let i = n % 26;
        let t =  v[i as usize];
        s = [t.to_string(), s].concat();
        n = n / 26;
    }

    println!("{}", s);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a*n,b) << endl;
  return 0;
}


Measured memory_bytes: 764