akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<utility>
#include<vector>

#define INF 1000000007

using ll = long long;
using namespace std;

int main(void){

    int n;
    cin >> n;

    int oddNum = 0;
    int evenNum = 0;
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        if(a%2==0)evenNum++;
    }
    oddNum = n - evenNum;

    evenNum += oddNum/2;
    oddNum %= 2;

    while(evenNum>1){
        evenNum = evenNum%2 + evenNum/2;
    }

//cout << "#" << oddNum+evenNum << endl;
    if(oddNum+(evenNum%2)==1)cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(void){
	long long a,b,n,x;
	cin>>a>>b>>n;
	if(n>=b) x=b-1ll;
	else x=n;
	cout<<a*x/b-a*(x/b)<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b; cin >> a >> b;

    ll ans = 0;
    if(b - a > 8){
        reps(i, a, (a/4+1)*4){
            ans ^= i;
        }

        reps(i, b/4*4, b+1){
            ans ^= i;
        }
    }
    else{
        reps(i, a, b+1){
            ans ^= i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  vi h(n);
  int mx = 0;
  rep(i, n){
    cin >> h[i];
    mx = max(mx, h[i]);
  }
  int left = 0, right = mx;
  while(left < right - 1){
    int middle = (right + left) / 2;
    ll tot = 0, num = middle * b;
    rep(i, n){
      tot += ceil(max(double(0), (double)(h[i] - num) / (a - b)));
    }
    if(tot <= middle) right = middle;
    else left = middle;
  }
  cout << left + 1 << endl;
}

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

// 数字の各桁の和を返す
int sumDigits (int n) {
    int s;
    while (n > 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

// 最大公約数を返す
int gcd (int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main () {
  string c1, c2; cin >> c1 >> c2;
  reverse(c2.begin(), c2.end());
  
  if (c1 == c2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long 
int n;
int dp[100000];
 

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//memset(dp,0, sizeof dp);
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	dp[0] = 0;
	dp[1] = abs(arr[0] - arr[1]);
	for(int i = 2; i < n; i++){
		dp[i] = min(dp[i - 1] + abs(arr[i - 1] - arr[i]), dp[i - 2] + abs(arr[i - 2] - arr[i]));
	}
	cout << dp[n - 1];
	
}


Measured memory_bytes: 4420
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    X = list(mi())

    if all(x%2==1 for x in X):
        print(min(X[0]*X[1], X[1]*X[2], X[2]*X[0]))
    else:
        print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9984
//----------ACCIDENTAL COMPETITIVE PROGRAMMER---------------------

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
using namespace std;

#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair


const LL MOD = (1e9) + 7 ;
const LD EPS = 0.0000001 ;

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

    LL a, b; cin >> a >> b;
    if (a <= 5) {
    	cout << 0 << endl;
    } else if (a >= 13){
    	cout << b << endl;
    } else
    	cout << b / 2; 

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int city,road;
    cin >> city >> road;
    map<int,int>mp;
    for(int i=0; i<road; i++){
        int a,b;
        cin >> a >>b;
        mp[a]++;
        mp[b]++;
    }
    for(int i=1; i<=city; i++){
        cout << mp[i] <<endl;
    }
}

Measured memory_bytes: 3580
N, M = map(int, input().split())
mod = 10 ** 9 + 7
A = [True] * (N+1)
for _ in range(M):
    a = int(input())
    A[a] = False
dp = [0] * (N+1)
dp[:2] = 1, 1 if A[1] else 0
for i in range(2, N+1):
    if A[i]:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= mod
print(dp[N])

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

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

int minTime(vector<int> &arr) {
  int time = 24;
  vector<int> c;
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] >= 1) c.push_back(i);
  }
  for (int i = 0; i < c.size() - 1; i++) time = min(time, c[i + 1] - c[i]);
  time = min(time, 24 - c.back());
  return time;
}

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

  vector<int> D(N);
  for (int i = 0; i < N; i++) cin >> D[i];

  map<int, int> M;
  for (int i = 0; i < N; i++) {
    if (D[i] >= 13) D[i] = 24 - D[i];
    M[D[i]]++;
  }


  for (auto x : M) {
    if ((x.first == 0 && x.second >= 1) || (x.first == 12 && x.second >= 2) ||
        (x.first != 0 && x.first != 12 && x.second >= 3)) {
      cout << 0 << endl;
      return 0;
    }
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << 11); bit++) {
    vector<int> time(24, 0);
    time[0] = 1;
    if (M.count(12)) time[12] = 1;
    bool good = true;
    for (int i = 0; i < 11; i++) {
      //置いてあげる
      if (bit & (1 << i)) {
        if (M[(i + 1)] == 2) {
          time[(i + 1)] = 1;
          time[(24 - (i + 1))] = 1;
        }
        if (M[(i + 1)] == 1) {
          time[(i + 1)] = 1;
        }
      } else {
        if (M[(i + 1)] == 2) {
          good = false;
        }
        if (M[(i + 1)] == 1) {
          time[24 - (i + 1)] = 1;
        }
      }
    }
    if (!good) continue;
    int t = minTime(time);
    ans = max(ans, t);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

		String[] a = A.split("");
		String[] b = B.split("");

		if (a[0].equals(b[2]) && a[2].equals(b[0])){
			if(a[1].equals(b[1])){
				System.out.println("YES");
			}
            else{
                System.out.println("NO");
            }
		}
		else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define el cout<<endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    int x, y;
    cin >> x >> y;
    
    int ans = a * x + b * y;

    if (x < y) {
        int tmp = 2 * x * c;
        tmp += (y - x) * b;
        ans = min(ans, tmp);
    }
    else {
        int tmp = 2 * y * c;
        tmp += (x - y) * a;
        ans = min(ans, tmp);
    }
    
    ans = min(ans, 2 * max(x, y) * c);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

ll sum[55], pcnt[55], bcnt[55];
ll rec (ll x, int i) {
    if (x == 0) return 0;
    if (x == 1) {
        if (i == 0) return 1;
        else {
            return 0;
        }
    }
    if (x > sum[i]) {
        return pcnt[i] + 1;
    } else if (x == sum[i]) {
        return pcnt[i];
    } else if (x > sum[i - 1] + 1) {
        return pcnt[i - 1] + rec (x - sum[i - 1] - 2, i - 1) + 1;
    } else {
        return rec (x - 1, i - 1);
    }
}

int main() {
    int n;
    ll x;
    cin >> n >> x;
    ll ans = 0;
    rep (i, 0, n + 1) {
        pcnt[i] = 0;
        bcnt[i] = 0;
        sum[i] = 0;
    }
    pcnt[0] = 1, sum[0] = 1;
    rep (i, 0, n) {
        bcnt[i + 1] = bcnt[i] * 2 + 2;
        pcnt[i + 1] = pcnt[i] * 2 + 1;
        sum[i + 1] = pcnt[i + 1] + bcnt[i + 1];
    }
    cout << rec (x, n) << "\n";
}


Measured memory_bytes: 256
cnt = 0
INFTY=10**10
def merge_sort(a,left,right):
	if left+1<right:
		mid=(left+right)//2
		merge_sort(a,left,mid)
		merge_sort(a,mid,right)
		merge(a,left,mid,right)

def merge(a,left,mid,right):
	L=a[left:mid]
	R=a[mid:right]
	L.append(INFTY)
	R.append(INFTY)
	global cnt
	i=0
	j=0
	for k in range(left,right):
		cnt+=1
		if L[i] <= R[j]:
			a[k]=L[i]
			i+=1
		else:
			a[k]=R[j]
			j+=1
			
	
n=int(input())
cnt=0
a=list(map(int,input().split()))
merge_sort(a,0,len(a))
print(*a)
print(cnt)


Measured memory_bytes: 61648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  int n;
  
  cin >> n;
  
  int a;
  bool i = true;
  rep(k, 0, n) {
    cin >> a;
    if(a%2==1) continue;
    else if(a%5!=0 and a%3!=0) i = false;
  }
  
  cout << (i ?"APPROVED" :"DENIED") << "\n";

}


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

int main() {
  long n;int  k;
  cin >> n >> k;
  int res = 0;
  while (n > 0) {
    n /= k;
    res++;
  }
  cout << res << endl;
  return 0;
}



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

int main(){
    int A,B;
    cin >> A >> B;
    if(A>=13)cout << B << endl;
    else if(A>=6&&A<=12)cout << B/2 << endl;
    else if(A<=5)cout << 0 <<endl;
    return 0;
}

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

using namespace std;

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

    int w = a + b - c - d;
    if (w > 0) {
        cout << "Left" << endl;
    } else if (w < 0) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, m;
  cin >> n >> m;
  if (abs(n - m) > 1) {
    P(0);
    return 0;
  }
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    ans = (ans * i) % mod;
  }
  for (int i = 1; i <= m; i++) {
    ans = (ans * i) % mod;
  }

  if (n == m) ans = ans * 2 % mod;
  P(ans);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

class Line_container {
public:
	Line_container(const int &w = 0) :line{new std::vector<int>(w + 1, 0) } {};
	~Line_container() { delete line; };
	int &at(const int &i) const {
		return line->at(i + 1);
	}
	int &at(const int &i) {
		return line->at(i + 1);
	}
	void swap(Line_container &other) {
		auto temp = line;
		line = other.line; other.line = temp;
	}
private:
	std::vector<int> *line;
};
template <class F>
F min(const F &num) {
	return num;
}
template <class F, class... Args>
F min(const F &num, const Args&... args) {
	return (num < min(args...) ? num : min(args...));
}
int main() {
	int h, w;
	std::scanf("%d %d", &h, &w);
	Line_container prev_line(w);
	Line_container line(w);
	int max = 0;
	for (auto i = 0; i < h; ++i) {
		for (auto j = 0; j < w; ++j) {
			int cell;
			std::scanf("%d", &cell);
			if (cell == 1) {
				line.at(j) = 0;
			}
			else {
				line.at(j) = min(prev_line.at(j - 1), prev_line.at(j), line.at(j - 1)) + 1;
				if (max < line.at(j)) {
					max = line.at(j);
				}
			}
		}
		line.swap(prev_line);
	}
	std::printf("%d\n", max * max);
	return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

struct before_main {
  before_main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} before_main;

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

typedef bitset<42> BS;

int N;
map<string, int> id;
bool adjacent[41][41];
int weight[41];
int weight_sum[41];
int ans;

void dfs(BS& bs, int wsum, int curr) {

  if (curr == N) {
    ans = max(ans, wsum);
    return;
  }

  if (wsum + weight_sum[N-1] - (curr ? weight_sum[curr - 1] : 0) <= ans)
    return;

  dfs(bs, wsum, curr + 1);

  rep(k, curr) {
    if (adjacent[curr][k] && bs[k]) {
      return;
    }
  }

  bs.set(curr);
  dfs(bs, wsum + weight[curr], curr + 1);
  bs.reset(curr);
}

int main() {

  while (cin >> N && N) {
    rep(i, 41) rep(j, 41) adjacent[i][j] = 0;
    id.clear();
    int v = 0;

    rep(_, N) {
      string s;
      cin >> s;
      if (id.find(s) == id.end())
        id[s] = v++;
      cin >> weight[id[s]];
      int n;
      cin >> n;
      rep(_, n) {
        string t;
        cin >> t;
        if (id.find(t) == id.end())
          id[t] = v++;
        adjacent[id[s]][id[t]] = 1;
      }
    }

    rep(i, N) weight_sum[i] = weight[i] + (i ? weight_sum[i-1] : 0);

    ans = 0;
    BS bs;
    bs.set(0);
    dfs(bs, weight[0], 1);
    cout << ans << endl;
  }

  return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n;
li a[2020];

PI aa[2020];

// dp[i][j] : でかいほうからi番目までみたときにj個左側に寄せたときの最大値
li dp[2020][2020];

int main() {
    cin >> n;
    rin{
        cin >> a[i];
        aa[i] = {a[i], i};
    }
    sort(aa, aa + n);
    reverse(aa, aa + n);

    rep(i, 2020) {
        rep(j, 2020) {
            dp[i][j] = -INF;
        }
    }
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, i + 1) {
            // 既にj個左端にある

            // 右に寄せた
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + abs(n - 1 - (i - j) - aa[i].S) * aa[i].F);
            // 左に寄せた
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + abs(aa[i].S - j) * aa[i].F);
        }
        //puts("--");
        //rep(j, i + 2)cout << dp[i + 1][j] << " "; cout << endl;
    }

    li res = -INF;
    rep(i, n + 1) {
        res = max(res, dp[n][i]);
    }
    cout << res << endl;


    return 0;
}

Measured memory_bytes: 35556
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m;
V z;
V &Me(const V &_x,const V &_y){
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m;
	return z;
}
V &Mx(const V &_x){
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_x[slice(j,n,n)]).sum()%m;
	return z;
}
void O(const V &r,const V &s){
	int i=0;
    for(;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
    printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i,a,b,c,t;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		V x(n*n);
		V e(n*n);
		z.resize(n*n);

		x[0]=b;
		x[1]=c;
		e[0]=1;
		for(i=1;i<n-1;i++){
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			x[i*n+i+1]=c;
			e[i*n+i]=1;
		}
		x[i*n+i-1]=a;
		x[i*n+i]=b;
		e[i*n+i]=1;
		for(;t;t>>=1){
			if(t&1)e=Me(e,x);
			x=Mx(x);
		}
		V s(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		O(e,s);
	}
}

Measured memory_bytes: 1084
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

S = collect(chomp(readline()))
N = length(S)
if N == 3
    println("Yes")
else
    if S[1:(N-1)÷2] == reverse(S[1:(N-1)÷2]) && S[(N+3)÷2:end] == reverse(S[(N+3)÷2:end]) && S == reverse(S)
        println("Yes")
    else
        println("No")
    end
end

Measured memory_bytes: 163088
<?php
fscanf(STDIN,"%d",$n);
$arr = explode(" ", trim(fgets(STDIN)));
$continous = 1;
$answer = 0;
$value = $arr[0];
for($i = 1;$i < $n;$i++)
{
   if($arr[$i] == $arr[$i-1])
        $continous++;
   else {
   	$answer += (int)($continous/2);
   	$continous = 1;
   }
}
$answer += (int)($continous/2);
printf("%d\n",$answer);

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

int main(){
    int n,q,j = 0, f = 0,count = 0;
    cin>>n;
    int S[n];
    for(int i=0;i<n;i++){
        cin>>S[i];
    }
    cin>>q;
    int T[q];
    for(int i=0;i<q;i++){
        cin>>T[i];
    }
    for(int i=0;i<q;i++){
        int left=0;
        int right=n;
        int mid;
        while(left<right){
            mid = (left +right)/2;
            if(S[mid]==T[i]){
                f=1;
                break;
            }
            else if(T[i]<S[mid]){
                right=mid;
            }
            else{
                left=mid+1;
            }
        }
        if(f==1){
            count++;
        }
        f=0;
         
    }
    cout<<count<<endl;
}


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

main() {
    int N,M; cin >> N >> M;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> p;
    rep(i,N) {
        int a,b; cin >> a >> b;
        p.push(make_pair(a,b));
    }
    ll ans=0;
    while(M>0){
        pair<int,int> NOW=p.top(); p.pop();
        if(M>NOW.second) {M-=NOW.second; ans+=NOW.second*NOW.first;}
        else {ans+=M*NOW.first; M=0;}
    }    
        cout << ans << endl;
    

    return 0;
}

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

ll H, W, A, B;

int main(void) {
  cin >> H >> W >> A >> B;

  if(A * B == 1) {
    cout << "No" << endl;
    return 0;
  }

  ll d = A * B - 1;
  ll u = (1000000000LL - 1) / d;
  ll m = u * d + 1;
  ll p = (H / A) * (W / B);
  ll s = (H * W - p) * u - p * m;

  if(s > 0) {
    cout << "Yes" << endl;
    REP(i, 0, H) REP(j, 0, W) cout << ((i + 1) % A == 0 && (j + 1) % B == 0 ? -m : u) << (j + 1 != W ? " " : "\n");
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <climits>
using namespace std;

vector<int> x,y;
vector<int> ux,uy;

short data[5002][5002];

int main(){
	int n,m;
	cin >> n >> m;
	for(int i = 0 ; i < n ; i++){
		int a,b;
		cin >> a >> b;
		x.push_back(a);
		y.push_back(b);
	}
	ux = x;
	uy = y;
	ux.push_back(INT_MAX);
	ux.push_back(INT_MIN);
	uy.push_back(INT_MAX);
	uy.push_back(INT_MIN);
	sort(ux.begin(),ux.end());
	sort(uy.begin(),uy.end());
	ux.erase(unique(ux.begin(),ux.end()),ux.end());
	uy.erase(unique(uy.begin(),uy.end()),uy.end());
	for(int i = 0 ; i < x.size() ; i++){
		x[i] = lower_bound(ux.begin(),ux.end(),x[i]) - ux.begin();
		y[i] = lower_bound(uy.begin(),uy.end(),y[i]) - uy.begin();
		data[y[i]][x[i]]++;
	}
	for(int i = 0 ; i < 5002 ; i++)
		for(int j = 1 ; j < 5002 ; j++)
			data[i][j] += data[i][j-1];
	for(int i = 1 ; i < 5002 ; i++)
		for(int j = 0 ; j < 5002 ; j++)
			data[i][j] += data[i-1][j];
	for(int i = 0 ; i < m ; i++){
		int a,b,c,d; 
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a = lower_bound(ux.begin(),ux.end(),a) - ux.begin();
		b = lower_bound(uy.begin(),uy.end(),b) - uy.begin();
		c = upper_bound(ux.begin(),ux.end(),c) - ux.begin() - 1;
		d = upper_bound(uy.begin(),uy.end(),d) - uy.begin() - 1;
		//cout << a << " " << b << " " << c << " " << d << endl;
		int answer = data[d][c] - data[d][a-1] - data[b-1][c] + data[b-1][a-1];
		printf("%d%c",answer,10);
	}
	
}

Measured memory_bytes: 50248
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

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

    cout<<max(0,A-B*2)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<limits.h>

using namespace std;
typedef long long ll;
ll lucas[87];

void init(){
	lucas[0] = 2;lucas[1] = 1;
	for(int i = 2;i <= 86;i++){
		lucas[i] = lucas[i-2] + lucas[i-1];
	}
}

int main(){
	init();
	int n;
	while(cin >> n){
		cout << lucas[n] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,m =na()
ls = 1
rs = n
for i in range(m):
    l, r = na()
    ls = max(ls, l)
    rs = min(rs, r)
if ls > rs:
    print(0)
else:
    print(rs - ls + 1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<pair<ll, ll> > v;
    rep(i, n)
    {
        ll a, b;
        cin >> a >> b;
        v.push_back({b, a});
    }
    sort(ALL(v));
    ll cur = 0;
    rep(i, n)
    {
        if (cur + v[i].second > v[i].first)
        {
            cout << "No" << endl;
            return 0;
        }
        else
        {
            cur += v[i].second;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 6256
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    if k <= 0 or s[i] == 'a':
        continue
    if 123 - ord(s[i]) <= k:
        k -= 123 - ord(s[i])
        s[i] = 'a'
# print(k)
# print(s)
k %= 26
# print(ord(s[-1])+k)
if ord(s[-1])+k > 122:
    s[-1] = chr(97+(122-ord(s[-1])+k))
else:
    s[-1] = chr(ord(s[-1])+k)
# print(k)
print(*s, sep='')


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

using namespace std;
using ll = long long;
using P = pair <int, int>;

int main(){
  char c;

  std::vector<char> upp = {'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'};
//  vector<char> low(26)={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};
  cin  >> c;
  //cout << c << endl;
  int n=26;
  bool uflag=false;
  rep(i,n){
    if(upp.at(i)==c){
      uflag=true;
      break;
    }
  }
  if(uflag){
    cout << "A"<<endl;
  }else{
    cout << "a"<< endl;
  }

  return 0;
}


Measured memory_bytes: 3624
"""
1.連続するRを探す(rf-re)
2.連続するLを探す(lf-le)
3.rf-leの間で偶奇をカウント、re、lfにその数を代入
"""

S = input()+"R"
N = len(S)
Rli = [0]*(N-1)

rf=re=lf=le=-1
rf = 0

for i in range(N):
  if re == -1:
    #R search
    if S[i] == "L":
      re = i-1
      lf = i
  else:
    #L search
    if S[i] == "R":
      le = i-1
      bet = le-rf+1
      if bet%2 == 0:
        Rli[re] = Rli[lf] = bet//2
      else:
        if rf%2 == 0:
          ki = (bet-1)//2
        else:
          ki = (bet+1)//2
        if re%2 == 0:
          Rli[re] = bet-ki
          Rli[lf] = ki
        else:
          Rli[re] = ki
          Rli[lf] = bet-ki
      rf=re=lf=le=-1
      rf = i
      
print(" ".join(map(str,Rli)))

Measured memory_bytes: 17316
N, Y = map(int, input().split())
result = [-1 , -1, -1]
for m in range(N + 1):
    
    for f in range(N + 1 - m):
        
        s = N - m - f
        
        if 10000*m + 5000*f + 1000*s == Y:
            result = [m, f, s]
            
            break
            
print(f'{result[0]} {result[1]} {result[2]}')

        

Measured memory_bytes: 9100
#B
ABCK = input().split(' ')
A = int(ABCK[0]) ; B = int(ABCK[1]) ; C = int(ABCK[2])
K = int(ABCK[3])
if K <= A:
    print(K)
elif K <= (A + B):
    print(A)
else:
    print(A - (K - A - B))

Measured memory_bytes: 9180
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int ans[100007];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    if(s[n]=='1'){
        cout<<-1;
        return 0;
    }
    int x=n;
    int flag=0;
    int cnt=0;
    while(1){
        flag=0;
        int r=max(0,x-m);
        for(int i=r;i<x;++i){
            if(s[i]=='0'){
                ans[++cnt]=x-i;
                x=i;
                flag=1;
                break;
            }
        }
        if(x==0||!flag)
            break;
    }
    if(flag)
        for(int i=cnt;i;--i)
            cout<<ans[i]<<" ";
    else
        cout<<-1;
    return 0;
}


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

int main() {
    int l,r;
    cin >> l >> r;
    const int mod=2019;

    if ((r-l) >= 2019) {
        cout << 0 << endl;
    } else {
        int ans = 2019;
        for (size_t i = l; i <= r; i++)
        {
            for(size_t j = i + 1; j<=r; j++)
            {
                int m = i * j % mod;
                ans = min(ans, m);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto l = readln.split.to!(int[]);
    auto H = l[0];
    auto W = l[1];
    auto A = l[2];
    auto B = l[3];

    char[][] R;
    R.length = H;

    foreach (h; 0..H) {
        foreach (w; 0..W) {
            bool x;
            if (h < B) x = !x;
            if (w < A) x = !x;
            R[h] ~= x ? '1' : '0';
        }
    }

    foreach (r; R) writeln(r);
}

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#define MAX1 2000001
#define MAX2 10000
int main(){
    unsigned short *A,*B;
    int C[MAX2+1];
    int a,b,c;
    scanf("%d",&a);
    A=malloc(sizeof(short)*a+1);
    B=malloc(sizeof(short)*a+1);
    for(b=0;b<=MAX2;b++){
        C[b]=0;
    }
    for(b=0;b<a;b++){
        scanf("%hu",&A[b+1]);
        C[A[b+1]]++;
    }
    for(b=1;b<=MAX2;b++){
        C[b]=C[b]+C[b-1];
    }
    for(c=1;c<=a;c++){
        B[C[A[c]]]=A[c];
        C[A[c]]--;
    }
    for(b=1;b<=a;b++){
        if(b>1) printf(" ");
        printf("%d",B[b]);
        }
        printf("\n");
        return 0;
    }


Measured memory_bytes: 9576
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, m;
ll a[100001];
ll sum[100001];
map<ll, ll> mp;
int main() {
    cin>>n>>m;
    REP(i, 0, n){
        cin>>a[i];
        sum[i+1]=(sum[i]+a[i])%m;
    }

    ll ans=0;
    REP(i, 0, n+1){
        ans+=mp[sum[i]];
        mp[sum[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, u, v, z[3] = {-1, -1, -1};
    cin >> n >> m;
    while (m--) {
        cin >> u >> v;
        u--;
        if (z[u] == -1) z[u] = v;
        else if (z[u] != v) {
            cout << -1;
            return 0;
        }
    }
    if (n > 1 && z[0] == 0) {
        cout << -1;
        return 0;
    }
    if (n > 1 && z[0] == -1) z[0] = 1;
    for (int i = 0; i < n; i++) {
        if (z[i] == -1) cout << 0;
        else cout << z[i];
    }
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;



const int MAX = 200000;
std::vector<int>o[MAX + 1];

int search(int* d, int t, int n) {
	if (d[0] == t)return 0;
	int r = 0;
	for (int i = 20; i >= 0; i--) {
		int c = r | (1 << i);
		if (c >= n)continue;
		if (d[c] == t)return c;
		if (d[c] < t)r = c;
	}
	return -1;
}

int main() {
	int N;
	long long K;
	scanf("%d %lld", &N, &K);
	int *A = new int[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", A + i);
		o[A[i]].push_back(i);
	}
	int s = 0;
	long long cnt = 1;
	while (1) {
		int c = search(o[A[s]].data(), s, o[A[s]].size());
		int sd = (o[A[s]][(c + 1) % o[A[s]].size()] + 1) % N;
		if ((c + 1) % o[A[s]].size() == 0)cnt++;
		s = sd;
		if (s == 0)break;
	}
	long long kd = K % cnt;
	if (kd == 0)return 0;
	s = 0;
	for (int q = 0; q < kd;) {
		int c = search(o[A[s]].data(), s, o[A[s]].size());
		int sd = (o[A[s]][(c + 1) % o[A[s]].size()] + 1) % N;
		if ((c + 1) % o[A[s]].size() == 0)q++;
		if (q < kd)s = sd;
	}
	for (int i = s; i < N; i++) {
		int c = search(o[A[i]].data(), i, o[A[i]].size());
		if (c == o[A[i]].size() - 1) {
			printf("%d ", A[i]);
		}
		else {
			i = o[A[i]][c + 1];
		}
	}
	return 0;
}

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

int main(){
    int h, w;

    while(1){
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++ ){
            cout << "#";
            for (int j = 0; j < w-2; j++){
                if (i == 0 || i == h-1){
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << "#" << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>

using namespace std;

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

  for(int i = a; i <= b; i++){
    if(i % k == 0){
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;

  return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Libra
            var n = ReadLine();

            int left = n[0] + n[1];
            int right = n[2] + n[3];

            if (left > right)
            {
                Console.WriteLine("Left");
            }
            else if (left < right)
            {
                Console.WriteLine("Right");
            }
            else
            {
                Console.WriteLine("Balanced");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
#codng utf-8
N,M=map(int,input().split())
B=[1]*(N+1)
F=[0]*(N+1)#0がある場所
F[1]=1


for i in range(M):
    a,b=map(int,input().split())
    if F[a]==1:
        if B[a]==1:
            F[a]=0
            F[b]=1
        else:
            F[b]=1
        B[a]-=1
        B[b]+=1
    else:
        B[a]-=1
        B[b]+=1


print(F.count(1))

Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;

int countdown[17];

int main() {
    memset(countdown, 0, sizeof countdown);
    vector<int> ans;
    queue<int> q;
    for (int m=0; (int)ans.size()<100; ++m) {
        if (m%5 == 0 && m/5 < 100) q.push(m/5);
        for (int i=0; i<17; ++i) {
            if (countdown[i]) --countdown[i];
        }
        while ( ! q.empty()) {
            bool change = false;
            int num = (q.front()%5 == 1 ? 5 : 2);
            for (int i=0; i+num-1<17; ++i) {
                bool ok = true;
                for (int j=i; j<=i+num-1; ++j) {
                    if (0 < countdown[j]) ok = false;
                }
                if (ok) {
                    change = true;
                    for (int j=i; j<=i+num-1; ++j) {
                        countdown[j] = 17*(q.front()%2) + 3*(q.front()%3) + 19;
                    }
                    ans.push_back(m - (5 * q.front()));
                    q.pop();
                    break;
                }
            }
            if ( ! change) break;
        }
    }
    int n;
    while (cin >> n) {
        cout << ans[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
from collections import deque

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
O = min(N, K)
for i in range(O+1):
    for j in range(O-i+1):
        if i + j > O:
            break
        DV = deque(V)
        S = 0
        nums = []
        for _ in range(i):
            nums.append(DV.popleft())
        for _ in range(j):
            nums.append(DV.pop())
        nums.sort()
        S = sum(nums)
        for n in range(min(K-i-j, len(nums))):
            if nums[n] >= 0:
                break
            S -= nums[n]
        ans = max(ans, S)
print(ans)

Measured memory_bytes: 3316
#include<stdio.h>

int main(){
	
	int mae,usiro,x,y;
	mae = 1;
	usiro = 1;
	x = 0;
	y = 0;

	while(y <= 80){

	

			printf("%dx%d=%d\n",mae,usiro,mae*usiro);
			usiro += 1;
			x += 1;
			y += 1;
			if(x == 9){

				x = 0;
				mae += 1;
				usiro = 1;

			}
	}


    return 0;
}

Measured memory_bytes: 524
#include <stdio.h>

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  char g[h][w+1];
  for (int i=0; i<h; i++) scanf("%s", g[i]);
  for (int i=0; i<h; i++) {
    int j=0;
    while (g[i][j] == '.' && j<w) j++;
    if (j==w) {
      for (int j=0; j<w; j++) g[i][j] = '0';
    }
  }
  for (int i=0; i<w; i++) {
    int j=0;
    while (g[j][i] != '#' && j<h) j++;
    if (j==h) {
      for (int j=0; j<h; j++) g[j][i] = '0';
    }
  }
  for (int i=0; i<h; i++) {
    int boo = 0;
    for (int j=0; j<w; j++) {
      if (g[i][j] != '0') {
        printf("%c", g[i][j]);
        boo = 1;
      }
    }
    if (boo) printf("\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
#include<unordered_map>
 
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8
 
#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
 
int main() {
	ios::sync_with_stdio(false);
	int x,a,b;
	cin>>x>>a>>b;
	if(abs(x-a)<abs(x-b)) cout<<"A"<<endl;
	else cout<<"B"<<endl;
}

Measured memory_bytes: 256
n = int(input())
works = []
for i in range(n):
    a, b = map(int, input().split())
    works.append([a, b])


works = sorted(works, key=lambda x : x[1])

flag = True
time = 0

for i in range(n):
    time += works[i][0]
    if works[i][1] < time:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 39692
#include<bits/stdc++.h>
using namespace std;
#define N 200003
#define LL long long
#define mod 998244353
#define P 31

int n;
int f[N][30];
char s[20];
struct Node{
	int tot,val1,val2;
	int g[11],h[11];
}w[N];
map<pair<int,pair<int,int> >,LL>mp;
LL ans;

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);
		for (int j=1;j<=10;j++)
		  f[i][s[j]-'a'+1]++;
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=26;j++)
		  	if (f[i][j]!=0){
				w[i].tot++;
				w[i].g[w[i].tot]=f[i][j];
				w[i].h[w[i].tot]=j;
		  	}
		int val1=0,val2=0;
		for (int j=1;j<=w[i].tot;j++){
			val1=(1ll*val1*P%mod+w[i].g[j])%mod;
			val2=(1ll*val2*P%mod+w[i].h[j])%mod;
		}
		w[i].val1=val1;
		w[i].val2=val2;
	}
	for (int i=1;i<=n;i++){
		ans+=mp[make_pair(w[i].tot,make_pair(w[i].val1,w[i].val2))];
		mp[make_pair(w[i].tot,make_pair(w[i].val1,w[i].val2))]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 31104
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a;
    long long b, c;
    cin >> a >> b >> c;
    if((a == 1 && c - b != 0) || b > c) {
        cout << 0;
        return 0;
    }
    long long small = (b * (a - 1)) + c, big = (c * (a - 1)) + b;
    //cout << small << " " << big << endl;
    cout << big - small + 1;
}

Measured memory_bytes: 3596
function main(input) {
  var N = input[0]-0;
  var ans = 0;
  for(var i=105;i<=N;i+=2){
    var cnt = 0;
    for(var j=1;j<=i;j++){
      if(i%j==0) cnt++;
      if(cnt>8) break;
    }
    if(cnt == 8) ans++;
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int L,R,d;
    int mul;
    int sum = 0;

    cin >> L >> R >> d;

    int i = L;

    for(i ; i <= R ; i++){
        mul = i % d;
        if(mul == 0){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3588
N = int(input())
A = list(map(int,input().split()))
l = [0 for i in range(N+1)]
r = [0 for i in range(N+1)]
candidate = []

def GCD(a,b):
    if a == 0 or b == 0: return max(a,b)
    else:
        gcd = 1
        while 1:
            if a%b == 0:
                gcd = b
                break
            else:
                r = a%b
                a = b
                b = r
        return gcd

for i in range(1, N+1):
    l[i] = GCD(A[i-1], l[i-1])
for i in range(N-1, -1, -1):
    r[i] = GCD(A[i], r[i+1])

candidate = [0 for i in range(N)]
for i in range(N):
    candidate[i] = GCD(l[i], r[i+1])
print(max(candidate))



Measured memory_bytes: 14524
S = input()

Y = int(S[:2])
M = int(S[2:])

if(Y <= 12 and M <= 12 and Y > 0 and M > 0):
    print('AMBIGUOUS')
elif(Y <= 12 and Y > 0):
    print('MMYY')
elif(M <= 12 and M > 0):
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 38256
/* 
 * Author: pawanmsr
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //
int n;
string s;
set<int> r;
set<int> g;
set<int> b;

// Functions //

// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    /* code */
    cin >> n >> s;
    for (int j=0; j<n; j++) {
        if (s[j]=='R') r.insert(j);
        else if (s[j]=='G') g.insert(j);
        else if (s[j]=='B') b.insert(j);
    }

    ll ans = 0;
    for (auto p:r) {
        for (auto q:g) {
            int ct = 0;
            int d = abs(p-q);
            if (min(p, q)-d>=0 && b.find(min(p, q)-d)!=b.end()) ct++;
            if (max(p,q)+d<n && b.find(max(p,q)+d)!=b.end()) ct++;
            if (d%2==0 && b.find(min(p,q)+d/2)!=b.end()) ct++;
            ans+=b.size() - ct;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  int lmin = L;
  int lmax = L + N -1;
  int leat;
  if (lmax <= 0) {
    leat = lmax;
  } else if (lmin >= 0) {
    leat = lmin;
  } else {
    leat = 0;
  }
  int lsum = ((lmin + lmax) * N / 2) - leat;
  cout << lsum << endl;
}


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

 
int main(void)
{
    int a, b, k, i, t = 0, ans;
    cin >> a >> b >> k;
    for(i = min(a, b); i > 0; i--) {
        if(a % i == 0 && b % i == 0) {
            ans = i;    t++;
        }

        if(t == k)
            break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
const ll INF=1LL<<60;
int n,k;
int main(){
  cin>>n>>k;
  vector<ll> h(n);
  rep(i,n)cin>>h[i];
  vector<ll> dp(n,INF);
  dp[0]=0;
  for(int i=1;i<n;i++){
    for(int j=1;j<=k;j++)if(i>=j)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1792