akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)

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

  vector<vector<int>> jobs(m + 1);
  priority_queue<int> q;

  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if(a > m)
      continue;

    jobs[a].push_back(b);
  }

  ll ans = 0;
  rep(i, m + 1) {
    if(i == 0)
      continue;

    rep(j, jobs[i].size()) { q.push(jobs[i][j]); }

    if(q.size() > 0) {
      ans += q.top();
      q.pop();
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
const int INF = 1e8;
int main() {
    int N;
    cin >> N;
    map<char, int> ans;
    for(int i = 0; i < N; i++) {
        map<char, int> tmp;
        string S;
        cin >> S;
        for(auto c : S) {
            if(!tmp.count(c)) tmp[c] = 0;
            tmp[c]++;
        }
        for(char c = 'a'; c <= 'z'; c++) {
            if (!tmp.count(c)) {
                ans[c] = 0;
            } else {
                if(!ans.count(c)) {
                    ans[c] = tmp[c];
                } else {
                    ans[c] = min(ans[c], tmp[c]);
                }
            }
        }
    }
    for(auto x : ans) {
        cout << string(x.second, x.first);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

// T have +-*/ and 0
template<class T> class bit {
public:
    vector<T> dat;
    ll N;

    bit(){}
    bit(ll N) : N(N) { dat.assign(N,0); }
    // sum [0,i)
    T sum(ll i){
        ll ret = 0;
        for(--i; i>=0; i=(i&(i+1))-1) ret += dat[i];
        return ret;
    }
    // sum [i,j)
    T sum(ll i, ll j) { return sum(j) - sum(i); }
    // add x to i
    void add(ll i, T x) { for(; i < N; i|=i+1) dat[i] += x; }
};


int main() {
    ll N, D, A;
    cin >> N >> D >> A;

    vector<P> v(N);
    REP(i, N) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end(), [](P& a, P& b){return a.first < b.first;});

    D = D*2;

    vector<ll> t(N);
    ll tmp = 0;
    REP(i, N){
        if (i == 0){
            t[i] = i;
            continue;
        }
        while(v[tmp].first < v[i].first - D) tmp++;
        t[i] = tmp;
    }
    bit<ll> tree = bit<ll>((ll)N);
    REP(i, N){
        ll res = v[i].second - tree.sum(t[i], i) * A;
        if (res <= 0) continue;
        res = res % A == 0 ? res / A : res / A + 1;
        tree.add(i, res);
    }

    cout << tree.sum(N) << endl;




    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

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

	bool ans = 0;
	for (int i = 0;i < N;i++) {
		if (A[i] % 2 == 0) {
			if (A[i] % 3 > 0 && A[i] % 5 > 0) {
				ans = 1;
			}
		}
	}
	if (ans)cout << "DENIED" << endl;
	else cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int N, f, r, temp;
  cin >> N;
  int ans = 0;
  map<pair<int, int>, int> m;
  for(int i = 1; i <= N; i++){
    temp = i;
    r = i % 10;
    while(temp >= 10) temp/=10;
    f = temp;
    if(r == 0 || f == 0) continue;
    pair<int, int> p(f, r);
    m[p]++;
  }
  
  for(int i = 1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      pair<int, int> p1(i, j);
      pair<int, int> p2(j, i);
      ans += m[p1] * m[p2];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
   public static void main(String[] args) {
	  Scanner sc =new Scanner(System.in);
	  
	  for(;;){
		  int time =sc.nextInt();
		  if(time==0)System.exit(0);
		  int n=sc.nextInt();
	 int study=0;	
	for(;n>0;n--){
			 int s=sc.nextInt();
			 int e=sc.nextInt();
		study+=e-s;
	  }
	if(time<=study) System.out.println("OK");
	else System.out.println(time - study);
	  }
   }
}

Measured memory_bytes: 23256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  ll n,k,cnt=0,a=0,b=0,ans=0;
  std::cin >> n >> k;

  if(k%2==1){
    for(int i=1; i<=n; i++){
      if(i%k==0)cnt++;
    }
    ans=cnt*cnt*cnt;
  }

  else{
    for (int i = 1; i <= n; i++)
    {
      if(i%k==0)
        a++;
      if(i%k==k/2)
        b++;
    }
      ans=a*a*a+b*b*b;
  }

  std::cout << ans << '\n';
  return 0;
}


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

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

typedef long long ll;

int main(void)
{
    const int MAX_V = 1000*100;
    int N, W;
    cin >> N >> W;

    int w[N];
    int v[N];
    
    rep(i,N) cin >> w[i] >> v[i];

    ll dp[N][MAX_V+1];
    rep(t,MAX_V+1){
        rep(s,N) {
            dp[s][t] = -1;
        }
    }
    
    rep(i,N) {
        if (i == 0) {
            rep(j, MAX_V+1) {
                if (j == v[i]) dp[i][j] = W-w[i];
                if (j > v[i]) dp[i][j] = -1;
            }
        } else {
            rep(j, MAX_V+1) {
                if (j-v[i] > MAX_V || j-v[i] < 0) {
                    dp[i][j] = dp[i-1][j]; 
                } else {
                    dp[i][j] = max(dp[i-1][j-v[i]]-w[i], dp[i-1][j]);
                    if (v[i] == j) {
                        dp[i][j] = max(dp[i][j], (ll)W-w[i]);
                    }
                }
            }
        }

        //cout << i << ", v:" << v[i] << ", w:" << w[i] << endl;
        //rep(t,MAX_V+1){
        //    cout << t << ":";
        //    rep(s,i+1) {
        //        cout << dp[s][t] << ",";
        //    }
        //    cout << endl;
        //}
        //cout << endl;
    }

    int ans = 0;
    for(ans = MAX_V; ans > 0; ans--){
        if(dp[N-1][ans] != -1) break;
    }

    cout << ans << endl;
}


Measured memory_bytes: 78336
a = [int(x) for x in  input().split()]

cnt = 0
if a[0] > a[1]:
    print(0)
else:
    cnt += 1
    tmp = a[0]
    while True:
        if tmp*2 <= a[1]:
            tmp = tmp*2
            cnt += 1
        else:
            break
print(cnt)



Measured memory_bytes: 2940
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <map>

using namespace::std;

int main()
{
	int N;
  	string A, B, C;
  	cin >> N;
  	cin >> A;
  	cin >> B;
  	cin >> C;
  	int count = 0;
	for(int i = 0; i < N; i++){
      	if(A[i] == B[i]){
          if(A[i] == C[i])
            continue;
          else
            count++;
        }
      	else{
          if(A[i] == C[i])
            count++;
          else if(B[i] == C[i])
            count++;
          else
            count += 2;
        } 
    }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  int n,h,w; cin >>n >>h >>w;
  cout <<(n-h+1) * (n-w+1) <<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int a,b,c;
		Scanner in = new Scanner(System.in);
		
		a = in.nextInt();
		b = in.nextInt();
		c = in.nextInt();
		
		if(a<b && b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17356
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <functional>
using namespace std;
using ll = long long;

int main() {
	int K, S;
	cin >> K >> S;
	int c = 0;
	for (int x = 0; x < K + 1; x++) {
		if (x > S) break;
		for (int y = 0; y < K + 1; y++) {
			if (x + y > S) break;
			int z = S - x - y;
			if ((0 <= z) && (z <= K))c++;
		}
	}
	cout << c << endl;
	cin >> K >> S;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split(' '))
h = [ num for num in map(int, input().split(' '))]

dp = [float('inf')] * n

# print(n, h, dp)

def chmin(arr, index_a, val):
  if arr[index_a] > val:
    arr[index_a] = val
    return True
  return False

def chmax(arr, index_a, val):
  if arr[index_a] < val:
    arr[index_a] = val
    return True
  return False

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(1, n):
  for j in range(1, k+1):
    if i - j < 0:
      break
    chmin(dp, i, dp[i-j] + abs(h[i] - h[i-j]))

print(dp[n-1])

Measured memory_bytes: 55044
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int n  = get<int>();
    vector<int> x(n), y(n), h(n);
    int k = -1;
    for (int i = 0; i < n; i++) {
        x[i] = get<int>(), y[i] = get<int>(), h[i] = get<int>();
        if (h[i] > 0)
            k = i;
    }
    assert(k != -1);

    int xx, yy, hh;
    for (xx = 0; xx <= 100; xx++) {
        for (yy = 0; yy <= 100; yy++) {
            hh = h[k] + abs(xx - x[k]) + abs(yy - y[k]);
            for (int i = 0; i < n; i++) {
                if (h[i] != max(0, hh - abs(xx - x[i]) - abs(yy - y[i])))
                    goto NextCandidate;
            }
            goto Found;
        NextCandidate:;
        }
    }
    cerr << "Error";
    exit(1);
Found:;
    cout << xx << " "
         << yy << " "
         << hh << endl;
    return 0;
}

Measured memory_bytes: 256
# S = input()
# N = int(input())
# a = list(map(int, input().split()))
# X = [int(input()) for _ in range(N)]

N,A,B = map(int, input().split())

ans = 0




print((str)(min(A,B)) + " " + (str)(max(A+B-N,0)))


Measured memory_bytes: 2940
n = int(input())
h = input().split()
h = [int(i) for i in h]

out = 0

def divide_list_into_zero(l):
  ret = []
  tmp = []
  for i in l:
    if i != 0:
      tmp.append(i)
    elif len(tmp) is not 0:
      ret.append(tmp)
      tmp = []
  if len(tmp) is not 0:
    ret.append(tmp)
  return ret

def substract(l):
  global out
  out += 1
  return [i-1 for i in l]

def watering(l):
  tmp_1 = substract(l)
  tmp_2 = divide_list_into_zero(tmp_1)
  for child in tmp_2:
    watering(child)

for l in divide_list_into_zero(h):
  watering(l)
print(out)

Measured memory_bytes: 3188
def main():
    ab, bc, ca = map(int, input().split())

    longest = max(ab, bc, ca)

    if longest == ab:
        print(bc * ca // 2)
    if longest == bc:
        print(ca * ab // 2)
    if longest == ca:
        print(ab * bc // 2)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <stdio.h>
int main() {
    long int n, i, k;
    long int prime[1000001] = {0};
    long int sum[1000002] = {0};
    for(i = 2; i <= 1000000; i++) {
        prime[i] = 1;
    }
    for(i = 2; i <= 1000000; i++) {
        if(prime[i]) {
            for(k = 2*i; k <= 1000000; k+=i) {
                prime[k] = 0;
            }
        }
    }
    for(i = 0; i < 1000001; i++) {
        sum[i+1] = sum[i] + prime[i];
    }
    while(scanf("%ld", &n) != EOF) {
        printf("%ld\n", sum[n+1]);
    }
    return 0;
}

Measured memory_bytes: 17360
#k=int(input())
n,m=map(int,input().split())
hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
for i in range(m):
    a,b=map(int,input().split())
    if hl[a-1] <= hl[b-1]:
        dic[a]=False
    if hl[b-1] <= hl[a-1]:
        dic[b]=False

print(n-len(dic))


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

res = 0

n.times do |i|
  k = [a[i], b[i]].min
  a[i] -= k
  b[i] -= k
  res += k
  
  k = [a[i+1], b[i]].min
  a[i+1] -= k
  b[i] -= k
  res += k
end

puts res

Measured memory_bytes: 19596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define fs first
#define sc second
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

const static int INF = 1e8;
const static D EPS = 1e-8;

void Yes(bool a){
  cout << (a ? "YES" : "NO") << endl;
}

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == 7){
    Yes(b==5 and c==5);
  }else{
    Yes( min(b,c)==5 and max(b,c)==7 );
  }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
//		int N = sc.nextInt();
		
		String str1 = sc.nextLine();
		String str2 = sc.nextLine();
//		System.out.println(str1);
//		System.out.println(str2);
		
		int N = Integer.parseInt(str1);
		String[] num = str2.split(" ", 0);
		
		int[] a = new int[num.length];
		
		for(int i=0;i<num.length; i++){
			a[i]= Integer.parseInt(num[i]);
		}
		Arrays.sort(a);
		
//		System.out.println(Arrays.toString(a));
		
		int j=0;
		for(int i = 0; i<a.length; i=i+2){
			j = j+a[i];
		}
		
		System.out.println(j);
		
		
		
		
//		System.out.println(num[0]);


	}
}


Measured memory_bytes: 9936
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    vector<int> p(N);

    rep(i, N) {
        int a;
        cin >> a;
        if (a == i + 1) {
            p[i] = 1;
        }
        else {
            p[i] = 0;
        }
    }

    rep(i, N - 1) {
        if (p[i] == 1 && p[i + 1] == 1) p[i + 1] = 0;
    }

    int ans = 0;
    rep(i, N) {
        ans += p[i];
    }

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


Measured memory_bytes: 640
#include <iostream>
    #include <map>
    using namespace std;
     
    int main()
    {
        long long n, sum, ans;
        cin >> n;
        map<long long, long long> m;
        
        for(int i =0; i<n; i++){
            int t;
            cin >> t;
            sum = i==0? t: sum+t;
            m[sum]++;
            //cout << sum << " : " << m[sum] << endl;
        }
        ans =0;
        for(auto p: m){
            //cout << p.first << ":" << p.second <<endl;
            ans += p.second*(p.second -1)/2;
            if(p.first == 0) ans += p.second;
        }
        
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define si set<int>
#define sll set<ll>
#define ins insert
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define mod 1000000007
using namespace std;
/*lli power(lli a,lli n)
{lli ans=0;
   while(n>0)
   {
      if(n%2)
       {
         ans=ans*a;
         n--; 
       }
      else
        {
         a=a*a;
         n=n/2; 
        }
  }
return ans;
 }*/
/*ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}*/ 
/*int is_prime[1000001];
void sieve(){
    int maxN=1000000;
    for(int i=1;i<=maxN;i++)
    is_prime[i]=1;
    is_prime[0]=is_prime[1]=0;
    for(int i=2;i*i<=maxN;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=maxN;j+=i)
            is_prime[j]=0;
        }
    }
}*/
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
       int n,k;
       cin>>n>>k;
       int a[n];
       for(int i=0;i<n;i++)
       cin>>a[i];
      int dp[n];
       dp[0]=0;
       for(int i=1;i<n;i++)
       {
       	 int l;
       	 if(i>=k)
       	 l=i-k;
       	 else
       	 l=0;
       	 dp[i]=INT_MAX;
       	 for(int j=i;j>=l;j--)
       	 {
       	 	dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
       	 }
       }
       cout<<dp[n-1];
return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {

    long long n, a, b, ans, cal;

    scanf("%ld %ld %ld", &n, &a, &b);

    ans = n / (a + b) * a;
    cal = n % (a + b);

    if(cal >= a) {
        ans = ans + a;
    }
    else {
        ans = ans + cal;
    }

    printf("%ld\n", ans);

    return 0;
}

Measured memory_bytes: 128
A, B = map(int, input().split())

Xbmin = 10 * B
Xbmax = 10 * B + 10
ans = -1

for x in range(Xbmin, Xbmax):
    if 100 * A <= x * 8 and x * 8 < 100 * (A + 1):
        ans = x
        break
    
print(ans)

Measured memory_bytes: 8984
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()
S = list(input())
 
r = S.count("R")
g = S.count("G")
b = S.count("B")
 
 
A = list(range(len(S)))
cnt = 0
for x, y in combinations(A, 2):
	if (x+y)//2 == (x+y)/2:
		z = (x+y)//2
		if S[x] != S[y] and S[x] != S[z] and S[y] != S[z]:
			cnt += 1
 
print(r*g*b-cnt)

Measured memory_bytes: 73672
N=int(input())
X=list(map(int,input().split()))
for i in range(1,101):
  if i == 1:
    x=sum([(i-a)**2 for a in X])
  else:
    _x=sum([(i-a)**2 for a in X])
    if x<_x:
      break
    else:
      x=_x
print(x)
  

Measured memory_bytes: 2940
# Your code here!

K = gets.to_i
counter = 0

for i in 1..K
    for j in i..K
        if (i % 2 == 0 && j % 2 != 0) || (i % 2 != 0 && j % 2 == 0)
            counter += 1
        end
    end
end
puts counter

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

struct TXY{
    int t;
    int x;
    int y;
};

int distance(const struct TXY& lhs, const struct TXY& rhs){
    int dx = abs(lhs.x - rhs.x);
    int dy = abs(lhs.y - rhs.y);
    return dx + dy;
}

int main(){
    int N; cin >> N; N++;
    vector<struct TXY> vecTxy(N);
    vecTxy[0].t = 0;
    vecTxy[0].x = 0;
    vecTxy[0].y = 0;
    for(int i=1; i<vecTxy.size(); ++i){
        cin >> vecTxy[i].t;
        cin >> vecTxy[i].x;
        cin >> vecTxy[i].y;
    }
    
    for(int i=1; i<vecTxy.size(); ++i){
        int t = vecTxy[i].t - vecTxy[i-1].t;
        int d = distance(vecTxy[i-1], vecTxy[i]);
        if(t%d!=0){
//        if((t+d)&1 || t<d){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    
    return 0;
}

Measured memory_bytes: 1408
# YYMM or MMYY
S = int(input())

A = S // 100
B = S - (A* 100)
# YY確認
if 1 <= A <= 12:
    if 13 <= B <= 99 or B == 0:
        print('MMYY')
    else:  #1 <= B <= 12
        print('AMBIGUOUS')
elif 1 <= B <= 12:
    if 13 <= A <=99 or A == 0:
        print('YYMM')
    else: #1 <= B <= 12
        print('AMBIGUOUS')
else:
    print("NA")


Measured memory_bytes: 2940
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

char A[105];
int finalAns[100005];
int cnt;
int N;

int main()
{
	cnt = 0;
	scanf("%d", &N);
	for(int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	for(int i = 0; i < N; i++)
	{
		finalAns[A[i]]++;
	}

	for(int  i = 0; i < 10000; i++)
	{
		if(finalAns[i] != 0)
		{
			cnt++;
		}
	}

	if(cnt == 4)
	{
		printf("Four\n");
	}
	else
	{
		printf("Three\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  string a,b;
  cin >> a >> b;
  if(a.size() > b.size()){
    cout << "GREATER" << endl;
  }
  else if(a.size() < b.size()){
    cout << "LESS" << endl;
  }
  else{
    if(a > b) cout << "GREATER" << endl;
    else if (a < b) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
  }


  return 0;
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S, T;
  cin >> S >> T;
  
  VI R(27,-1),Q(27,-1);
  
  int N = SZ(S);
  
  REP(i,N){
    
    int a = S.at(i)-'a'  ,b = T.at(i)-'a';
    
    if(R.at(a) == -1){
      R.at(a) = b;
    }else{
      if(R.at(a) != b){
        
        cout << "No" << endl;
        return 0;
      }
    }
  }
  REP(i,N){
    
    int b = S.at(i)-'a'  ,a = T.at(i)-'a';
    
    if(Q.at(a) == -1){
      Q.at(a) = b;
    }else{
      if(Q.at(a) != b){
        
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 916
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    string s;

    cin >>n>>s;
    ll cnt(0);
    rep(i,0,s.size()-2)
    {
        if (s.substr(i,3)=="ABC")
            cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define N 3010

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int n;
ll a[N];
ll dp[N][N];
ll tmp[N][N];
ll s;

ll mul(ll x, ll y){
    return (x * y) % mod;
}

ll power(ll x, ll y){
    if(y == 0)return 1;
    ll pola = power(x, y/2);
    pola = mul(pola, pola);
    if(y%2)pola = mul(pola, x);
    return pola;
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> s;
    ll sum = 0;
    ff(i,1,n){
        cin >> a[i];
        sum += a[i];
    }
    ll inv2 = power(2, mod - 2);
    dp[0][0] = power(2, n);
    ll sta = power(2, n - 1);
    ff(i,1,n){
        ff(j,0,s){
            bool da = 0;
            if(j - a[i] >= 0)da = 1;
            if(da){
                if(j - a[i] > 0)dp[i][j] = (inv2 * dp[i - 1][j - a[i]])%mod;
                else dp[i][j] = sta;
            }
            dp[i][j] = (dp[i][j] + dp[i - 1][j])%mod;
        }
    }
    cout << dp[n][s] << "\n";
    return 0;
}


Measured memory_bytes: 74192
D,G = map(int,input().split())
P = []
C = []
for _ in range(D):
    p,c = map(int,input().split())
    P.append(p)
    C.append(c)

ans = 10**18

for i in range(2**D):
    problem = 0
    score = 0
    comp = []
    noncomp = []
    
    for j in range(D):
        if i>>j & 1:
            comp.append(j)
        else:
            noncomp.append(j)
            
    for j in comp:
        problem += P[j]
        score += C[j]+100*(j+1)*P[j]
        
    flag = False
    if score >= G:
        flag = True
        
    if not flag:
        for j in noncomp[::-1]:
            for k in range(P[j]-1):
                problem += 1
                score += 100*(j+1)
                if score >= G:
                    flag = True
                    break
                    
            if flag:
                break
                
    if flag:
        ans = min(ans,problem)

print(ans)

Measured memory_bytes: 42096
// Seealso: https://atcoder.jp/contests/abc061/tasks/abc061_a
fun main(args: Array<String>) {
    val list: List<Int> = readLine()!!.split(" ").map { it.toInt() }

    val ans: String
    if (list[2] >= list[0] && list[2] <= list[1]) {
        ans = "Yes"
    } else {
        ans = "No"
    }
    println(ans)
}


Measured memory_bytes: 35952
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;

typedef struct cond {
  i32 l, r, c;
} node;

int cmp (const void *a, const void *b) {
  i32 d = ((node *)a)->r - ((node *)b)->r;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

#define POS(i, j, k) ((((i) & 1) * n + (j)) * n + (k))

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  node *p = (node *) calloc (m, sizeof (node));
  for (i32 i = 0; i < m; ++i) {
    i32 l, r, c;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &r, &c);
    p[i] = (node) {l, r, c};
  }
  qsort (p, m, sizeof (node), cmp);
  const i32 mod = 1000000007;
  i32 *dp = (i32 *) calloc (2 * n * n, sizeof (i32));
  dp[POS(0, 0, 0)] = 1;
  for (i32 i = 1, q = 0; i <= n; ++i) {
    memset (dp + POS(i, 0, 0), 0, sizeof (i32) * n * n);
    for (i32 j = 0; j < i; ++j) {
      for (i32 k = 0; k <= j; ++k) {
        dp[POS(i, j, k)] = (dp[POS(i, j, k)] + dp[POS(i - 1, j, k)]) % mod;
        dp[POS(i, i - 1, k)] = (dp[POS(i, i - 1, k)] + dp[POS(i - 1, j, k)]) % mod;
        dp[POS(i, i - 1, j)] = (dp[POS(i, i - 1, j)] + dp[POS(i - 1, j, k)]) % mod;
      }
    }
    for (; q < m && p[q].r == i; ++q) {
      for (i32 j = 0; j < i; ++j) {
        for (i32 k = 0; k <= j; ++k) {
          i32 c = 1 + (j >= p[q].l ? 1 : 0) + (k >= p[q].l ? 1 : 0);
          if (c != p[q].c) dp[POS(i, j, k)] = 0;
        }
      }
    }
  }
  i32 ans = 0;
  for (i32 i = 0; i < n; ++i) {
    for (i32 j = 0; j <= i; ++j) {
      ans = (ans + dp[POS(n, i, j)]) % mod;
    }
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)

int32_t main(){
  
    fast;
    int a,b,h; cin >> a >> b >> h;
    cout << ((a+b)*h)/2;
 
 
    return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int b,c,d=-1,e=0;
  int a,i;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d %d",&b,&c);
    if(c>d){
      d=c;
      e=b;
    }else if(c==d&&b<e)e=b;
  }
  printf("%d %d\n",e,d);
  return 0;
}


Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;


int main(void) {
	int n, h;
	int w;
	int p = -1;
	int max = 0;
	int b[100001];
	long long int total = 0;
	long long int count = 0;

	cin >> n >> h;
	FOR(i, 1, n) {
		int a;
		cin >> a >> b[i];
		if (max < a) {
			max = a;
		}
	}
	sort(b, b + n+1);
	FOR(i, 1, n) {
		if (b[i] > max) {
			p = i;
			break;
		}
	}
	w = h;

	if (p == -1) {
		if (h%max == 0) {
			count = h / max;
		}
		else {
			count = h / max;
			count++;
		}
	}
	else {
		RFOR(i, n, p) {
			w -= b[i];
			total += b[i];
			count++;
			if (w <= 0) {
				break;
			}
		}
		if (w > 0) {
			if ((h-total)%max == 0) {
				count += (h-total) / max;
			}
			else {
				count += (h-total) / max;
				count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

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

inline int gcd(int a, int b) { return (a%b == 0) ? b : gcd(b, a%b); }
inline int fac(int n) { return (n==0) ? 1 : n * fac(n - 1); }

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

    int cnt = 0;
    for (int i = s.length() - 1; i >= 1; i--)
    {
        string str = s.substr(0, i);
        int l = str.length();
        if (l % 2 == 0) {
            string a = str.substr(0, l / 2);
            string b = str.substr(l / 2, l /2);
            if (a == b) {
                cnt = l;
                break;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3600
n, m = map(int, input().split())
chk = []
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    chk.append((u,v))
chk = tuple(chk)

def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def size(x):
    return -par[find(x)]

ans = 0
for i in range(m):
  par = [-1]*n
  for j in range(m):
    if i == j:
      continue
    else:
      unite(chk[j][0],chk[j][1])
  if size(0) != n:
    ans += 1
    
print(ans) 

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
    string s; cin>>s;
    int n=s.size();
    int flag=true;
    if(s[0]=='0'||s[n-1]=='1') flag=false;
    FOR(i,0,n-1){
        if(s[i]!=s[n-2-i]) flag=false;
    }
    int a=1,b=n;
    if(!flag){
        co(-1);
        return 0;
    }
    FOR(i,0,n/2){
        if(s[i]=='0'){
            printf("%d %d\n",a,b);
            b--;
        }else{
            printf("%d %d\n",a,a+1);
            a++;
        }
    }
    while(a<b) printf("%d %d\n",a,b--);
}


Measured memory_bytes: 1664
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
inline int read()
{
	int x=0,t=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*t;
}
ll n;
int main()
{
	cin>>n;
	for(ll i=sqrt(n);i>=1;i--)
	{
		if(n%i==0)
		{
			ll ans=i+(n/i)-2;
			cout<<ans<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)

h,w = map(int,input().split())
si = [input() for i in range(h)]

check = [-1]*(h*w)

#print(check,check==-1)
#exit()

vx = [0,1,0,-1]
vy = [1,0,-1,0]

def dfs(num,clr):
    #print(min(check))
    #if min(check) > -1:
    #    return
    
    y = num//w
    x = num%w
    for j in range(4):
        ny = y + vy[j]
        nx = x + vx[j]
        if ny >= 0 and ny < h and nx >= 0 and nx < w:
            new_num = ny*w+nx
            if check[new_num] != -1:
                continue
            #print(new_num,num,clr,si[ny][nx])
            if clr == '#':
                #print(ny,nx)
                if si[ny][nx] == '.':
                    check[new_num] = check[num]
                    dfs(new_num,'.')
            else:
                    
                if si[ny][nx] == '#':
                    check[new_num] = check[num]
                    dfs(new_num,'#')
            #print(check)

for i in range(h*w):
    #print(i)
    y = i//w
    x = i%w
    if si[y][x] == '#':
        if check[i] != -1:
            continue
        check[i] = i
        dfs(i,'#')
        #print(check)
        #exit()

ans = 0

li = [0]*(h*w+1)

for i in range(h):
    for j in range(w):
        if si[i][j] == '.':
            li[check[i*w+j]] += 1

#print(li)

for i in range(h):
    for j in range(w):
        if si[i][j] == '#':
            ans += li[check[i*w+j]]
            
print(ans)

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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b)) * b;
}


int main(){

  char c; cin >> c;
  if(c == 'A')
    pr("T");

  if(c == 'T')
    pr("A");
  
  if(c == 'G')
    pr("C");
  
  if(c == 'C')
    pr("G");

  return 0;
}


Measured memory_bytes: 256
S = input()

for i in range(1, len(S)):
    if len(S[:-i]) % 2 == 1:
        continue
    if S[:int(len(S[:-i])/2)] == S[int(len(S[:-i])/2):-i]:
        ans = len(S[:int(len(S[:-i]))])
        break
print(ans)

Measured memory_bytes: 3060
line = input().split(" ")
w = int(line[0])
h = int(line[1])
n = int(line[2])
area = [[0 for wx in range(w)] for hy in range(h)]
c = 0

for i in range(n):
    line = input().split(" ")
    x = int(line[0])
    y = int(line[1])
    a = int(line[2])
    if a == 1:
        for xi in range(h):
            for yi in range(x):
                area[xi][yi] = 1
    elif a == 2:
        for xi in range(h):
            for yi in range(w-x):
                area[xi][yi+x] = 1
    elif a == 3:
        for yi in range(w):
            for xi in range(y):
                area[xi][yi] = 1
    elif a == 4:
        for yi in range(w):
            for xi in range(h-y):
                area[xi+y][yi] = 1

for i in range(h):
    c = area[i].count(0) + c
print(c)

Measured memory_bytes: 3188
let id x = x
let (n,a,b) = Scanf.scanf "%d %d %d\n" (fun n a b -> (n,a,b))
 
let ans = if b-a < 0 || (b-a > 0 && n=1) then 0
    else if a=b then 1
    else (b-a) * (n-2) +1

let () =
  Printf.printf "%d\n" ans

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

const int N = 200005;

int n, m, a[N];

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m;
	for (int i = 0; i < 2 * n; ++i) std::cin >> a[i];
	std::sort(a, a + 2 * n);
	int l = 0, r = n, ans;
	auto check = [&] (int x) -> bool {
		for (int l = 2 * x, r = 2 * n - 1; l < r; ++l, --r)
			if (a[l] + a[r] < m) return 0;
		return 1;
	};
	while (l <= r) {
		int mid = l + r >> 1;
		if (check(mid)) ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	ans *= 2; int max = 0;
	for (int l = 0, r = ans - 1; l < r; ++l, --r)
		max = std::max(max, a[l] + a[r]);
	for (int l = ans, r = 2 * n - 1; l < r; ++l, --r)
		max = std::max(max, a[l] + a[r] - m);
	std::cout << max << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <queue>
#include <string.h>

int main(int argc, char *argv[])
{
	string st;
	int q;

	cin>>st>>q;
	
	char s[500000];
	strcpy(s+200000,st.c_str());
	char *l=s+200000,*r=s+200000+st.length();

	int rev=1;
	for (int i=0;i<q;i++)
	{
		int t,f;
		char c;
		cin>>t;
		if (t==1)
		{
			rev*=-1;
		}
		else
		{
			cin>>f>>c;
			if ((f==1) ^ (rev<0)) *--l=c; else *r++=c;
		}
		//cerr<<l<<endl;
	}
	*r=0;

	st=string(l);
	//cerr<<st<<endl;
	if (rev<0)
	{
		int l=st.length();
		string tmp=st;
		for(int i=0;i<l;i++)
		{
			st[i]=tmp[l-1-i];
		}
	}
	cout<<st<<endl;
	return 0;
}


Measured memory_bytes: 1308
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)

using namespace std;

vector<int> vec;

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

int main(void) {
	int a;
	int b;
	int c;

	long long ans;

	ans = 0;

	cin >> a;

	int temp = 0;

	for (int i = 1; i <= a; i++) {

		for (int k = 1; k <= a; k++) {

			for (int n = 1; n <= a; n++) {
				temp = gcd(i, k);
				temp = gcd(temp, n);
				ans += temp;
			}

		}

	}

	cout << ans;


}




Measured memory_bytes: 3636
n = int(input())
a = [int(i) for i in input().split()]
s = a[0]
c,j = 0,0
for i in a[1:]:
 
  if j ==0:
    if i-s > 0:
      j =1
      s = i
      continue
    elif i-s < 0:
      j = -1
      s = i
      continue
  elif i-s > 0 and j ==-1:
    j = 0
    c+=1
    
  if i-s < 0 and j==1:
    j = 0
    c+=1
  s = i
  
print(c+1)

Measured memory_bytes: 14252
n, m, x = map(int, input().split())
#n,m,x,i,j,l,money,k,o
books = []
for i in range(n):
    books.append(list(map(int, input().split())))
books = sorted(books, reverse=False)
#print(books)#

ans = 10 ** 10000
import itertools
for i in range(n+1):
    for j in itertools.combinations(books, i):#j:組み合わせ
#        print(j)#
        l = [0] * m #理解度
        money = 0
        for k in j:#k:組み合わせの中の１冊
#            print(k)#
            money += k[0]  #費用
#            print(money)#
            for o in range(1, m + 1):
                l[o-1] += k[o]  #lが理解度、kが本
#        print(money,l)#
        if all(a >=x for a in l):
            if money < ans:
                ans = money

if ans == 10 ** 10000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 74332
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#define pb push_back
typedef long long LL;
using namespace std;
typedef pair<int, int> Pii;
typedef pair<LL, LL> PLL;
const int maxn = 1E5 + 5;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m;
	int N, M;
	cin >> N >> M;
	cin >> n >> m;
	int sum = N * M;
	sum = sum - n * M - m * (N - n);
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
x = 0
for j in range(1,listA[0][0]+1):
    for i in range(1,n):
        listB = []
        for k in range(1,listA[i][0]+1):
          listB.append(listA[i][k])
        if listA[0][j] not in listB:
          break
    else:
    	x += 1
print(x)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;
typedef long long ll;
#define anyfill(n,s) setw(n) << setfill(s)
int N,M;
int P[100000],Y[100000];
vector<int> yd[100001];
int main(){
  cin>>N>>M;
  for(int i = 0; M > i; i++){
    cin >> P[i] >> Y[i];
    yd[P[i]].push_back(Y[i]);
  }
  for(int i = 1; N >= i; i++){
    sort(yd[i].begin(),yd[i].end());
  }
  for(int i = 0; M > i; i++){
  cout << anyfill(6,'0') << P[i];
  int b = lower_bound(yd[P[i]].begin(),yd[P[i]].end(),Y[i])-yd[P[i]].begin()+1;
  cout << anyfill(6,'0') << b << endl;
  }
}

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


int main(void)
{
  int N, M;
  long long K;
  std::cin >> N >> M >> K;

  std::vector<long long> as;
  for(int i=0; i<N; i++)
  {
	long long x;
    std::cin >> x;
    as.push_back(x);
  }
 
  std::vector<long long> bs;
  for(int i=0; i<M; i++)
  {
	long long x;
    std::cin >> x;
    bs.push_back(x);
  }
 
  std::vector<long long> ta(1,0);
  for( const auto& e : as )
  {
    auto x = ta.back() + e;
    if( K < x ) { break; }
    ta.push_back(x);
  }
  
  std::vector<long long> tb(1,0);
  for( const auto& e : bs )
  {
    auto x = tb.back() + e;
    if( K < x ) { break; }
    tb.push_back(x);
  }
  
  int up=0;
  int nb= tb.size()-1;
  for(int i=0; i<ta.size(); i++)
  {
    while( K < tb[nb] + ta[i] ) { nb-=1; }
    up = std::max(up, nb + i);
  }
  
  std::cout << up << std::endl;
  return 0;
}

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


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            var ans = s.OrderBy(x => x).ToList();
            if (s[1] < s[2] || s[0] > s[3])
            {
                WriteLine(0);
            }
            else WriteLine(ans[2] - ans[1]);
        }

        
    }
}


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

using namespace std;

int main()
{
	int n, a[100002] = {};
	long long s = 0;
	cin >> n;
	
	for (int i = 1; i <= n; i++)
		cin >> a[i];
		
	for (int i = 0; i < n+1; i++)
		s += abs(a[i]-a[i+1]);
		
	for (int i = 1; i <= n; i++)
		cout << s-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]) << endl;
}

Measured memory_bytes: 1664
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt();
		System.out.println(((n>k ? k : n)*x)+(((n-k>0) ? n-k : 0) *y));
		sc.close();
	}

	public static void main(String args[]) {
		solve();
	}

}


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

int main(){
	int a,b,count=0;
  	cin>>a>>b;
  	for(int i=a;i<=b;++i){
    	if(i/10000==i%10&&i/1000%10==i/10%10)++count;
    }cout<<count<<endl;
  	return 0;
}

Measured memory_bytes: 256