akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = list(input())
left = [0] * n
right = [0] * n

for i in range(1, n):
    left[i] = left[i - 1]
    if s[i - 1] == 'W':
        left[i] += 1

for i in range(1, n):
    right[n - i - 1] = right[n - i]
    if s[n - i] == 'E':
        right[n - i - 1] += 1

total = [x + y for x, y in zip(left, right)]
ans = min(total)
print(ans)

Measured memory_bytes: 31772
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int N,M,X,Y;
	cin>>N>>M>>X>>Y;
	int x=-INF,y=INF;
	rep(i,0,N)x=max(x,read());
	rep(i,0,M)y=min(y,read());
	puts((Y>x) && (x<y) && (X<Y) && (X<y)?"No War":"War");
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc135/tasks/abc135_b

n = int(input())
p = list(map(int, input().strip().split()))

count = 0
for i in range(n):
    if p[i] != i + 1:
        count += 1

if count > 2:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 9028
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B,C,K;
	while(cin>>A>>B>>C>>K) {
		ll a=min(K, A);
		K-=a;
		ll b=min(K, B);
		K-=b;
		ll c=min(K, C);
		ll ans=a-c;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3168
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
	int N, a[100005];
	int Nfore, Ntwo, None;
	Nfore = Ntwo = None = 0;
	cin >> N;
	REP(i, N) {
		cin >> a[i];
		if (a[i] % 2 == 1) None++;
		else if (a[i] % 4 == 0) Nfore++;
		else Ntwo++;
	}

	if (None == 0) {
		cout << "Yes" << endl;
	}
	else if (Ntwo == 0) {
		if (None - 1 <= Nfore) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	else if (Ntwo != 0) {
		if (None <= Nfore) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        cout << n << " ";  
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
    int t;
   // cin>>t;
   t=1;
    while(t--)
    {
   long long int i,j;
 //long long int b[1000000];
 //set<long long int >s;
       long long int f=0,p=0,z,o=0;
       double pie=3.141592653589793238;
    long long int n,m,l=0,k,min1=10000000000000,max2=-100;
 // char c;
  cin>>n>>k;
  long long int a[n];
  for(i=0;i<n;i++)
  cin>>a[i];
  sort(a,a+n);
  for(i=0;i<k;i++)
  {
      p=p+a[i];
  }
  cout<<p;
    }
 return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
int main(){
    int x,y,tmp;
    while(scanf("%d %d",&x,&y)){
        if(x==0 && y==0) break;
        if(x>y){
            tmp=x;
            x=y;
            y=tmp;
        }
        printf("%d %d\n",x,y);
    }
        return 0;
}
   

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif




int main(){
	ll n, k;
	cin >> n >> k;
	
	vector<ll> a(n);
	rep(i,n)
		cin >> a[i];
	
	
	for ( int i = 0; i < n-k; i++ ){
		cout << (a[i] < a[i+k]  ? "Yes" : "No" ) << endl;
	}
	
	
	return 0;
}




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

#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;

signed main()
{
    int N; cin >> N;
    vector<int> A(N);
    int numNegative = 0;
    rep(i, N){ 
        cin >> A[i]; 
        if(A[i] < 0) ++numNegative;
        A[i] = abs(A[i]);
    }

    ll ans = 0L;
    rep(i, N) ans += A[i];

    if (numNegative & 1){
        sort(A.begin(), A.end());
        ans -= A[0] * 2;
    }

    cout << ans << endl;

    return 0;
}


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

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

  string S; cin >> S;
  string ans = "No";
  if (S[0] == S[1] && S[2] == S[3] && S[0] != S[3]) ans = "Yes";
  if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ans = "Yes";
  if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) ans = "Yes";
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

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

  ll num = 0;
  for (ll i=1; i*i<=N; i++) {
    if (N%i==0) num = N/i;
  }
  int result = to_string(num).length();
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int>v;
string s;
int ary[100005] = {0};
int main(){
  int N;
  string ans ="ABC";

  cin >>N;
  if(1000 <= N){
    ans = "ABD";
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    bool flag = false;
    for( int i = 0; i < s.size() - 1; ++i ) {
        if( s[i] == 'A' && s[i + 1] == 'C' ) flag = true;
    }

    if( flag ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N, M, Q;
long long int a[50], b[50], c[50], d[50];
int A[10];

long long int dfs(int n, int value){
  A[n] = value;
  if(n == N-1){
    long long int ans=0;
    for(int i=0; i<Q; i++){
      if(A[b[i]-1]-A[a[i]-1] == c[i]) ans += d[i];
    }
    return ans;
  }
  long long int ans, tmp;
  if(M == value) return dfs(n+1, value);
  ans = dfs(n+1, value);
  for(int i=1; i+value<=M; i++){
    tmp = dfs(n+1, value+i);
    if(tmp > ans) ans = tmp;
  }
  return ans;
}

int main(){
  cin >> N >> M >> Q;
  for(int i=0; i<Q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  long long int ans, tmp;
  ans = dfs(0, 1);
  for(int i=2; i<=M; i++){
    tmp = dfs(0, i);
    if(tmp > ans) ans = tmp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    int[] x = readln.split.to!(int[]);
    x.sort!"a < b";
    int[] diff = new int[m-1];
    foreach (i; 0 .. m-1) {
        diff[i] = x[i+1] - x[i];
    }
    diff.sort!"a < b";
    writeln(n < m ? diff[0..m-n].sum : 0);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
ll ans=10000000000000000;
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}
int main(void){
	ll n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-1;i++){
		ans=min(ans,gcd(a[i],a[i+1]));
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Collections;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace _1_A
//{
class Program
{
    static void Main(string[] args)
    {
        ArrayList harray = new ArrayList();
        ArrayList warray = new ArrayList();
        int dat = 0, hid = 0, mig = 0;
        int[] iarray = new int[2];
        string inp = Console.ReadLine();
        string[] oup = inp.Split(' ');
        iarray[0] = int.Parse(oup[0]);
        iarray[1] = int.Parse(oup[1]);

        while (dat < 300)
        {
            if (iarray[0] == 0 && iarray[1] == 0)
                break;
            harray.Add(iarray[0]);
            warray.Add(iarray[1]);
            dat++;
            inp = Console.ReadLine();
            oup = inp.Split(' ');
            iarray[0] = int.Parse(oup[0]);
            iarray[1] = int.Parse(oup[1]);
        }

        int cnt = 0;
        for (; cnt < dat; ++cnt)
        {
            hid = Convert.ToInt32(harray[cnt]);
            mig = Convert.ToInt32(warray[cnt]);
            for (int i = 0; i < hid; i++)
            {
                for (int j = 0; j < mig; j++)
                {
                    if (i == 0 || i == (hid - 1) || i >= 1 && j == 0 || i <= (hid - 1) && j == 0 || i >= 1 && j == (mig - 1) || i <= (hid - 1) && j == (mig - 1))
                        Console.Write("#");
                    else
                        Console.Write(".");
                        
                }
                Console.WriteLine();
            }
            Console.WriteLine();

        }

        //Console.Read();
    }
}
//}

Measured memory_bytes: 8804
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

k = int(sys.stdin.buffer.readline())
if k % 2 == 0:
    ans = ( k // 2 ) ** 2

else:
    ans = k // 2 * (k // 2 + 1)
print(ans)


Measured memory_bytes: 13336
#include <iostream> // cout, endl, cin
#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> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0; i<n; ++i){
    cin >>a[i];
  }
  vector<long long> b(2);
  int w=0;
  sort(a.begin(),a.end());
  for(int i=n-2; i>=0; --i){
    if(a[i+1]==a[i]){
      b[w]=a[i];
      w++;
      if(i==1 || w==2) break;
      else{
        i--;
      }
    }
  }
  if(w==2){
    cout << b[0]*b[1] << endl;
  }
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

int main() {
    stack<int> s;
    int i;
    while(cin >> i) {
        if (i == 0) {cout << s.top() << endl; s.pop();}
        else s.push(i);
    }
    return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll l, r;
    cin >> l >> r;

    if(r-l>2019){
        cout << 0 << endl;
        return 0;
    }

    ll res = 2019;
    ll MOD = 2019;
    for (ll i = l; i <= r-1; ++i){
        for(ll j = i+1; j <= r; ++j){
            res = min(res, (i*j)%MOD);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let mut xs = read_vec_i64();
    xs.sort();
    let res = xs[2] - xs[0];
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
#ABC89 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7


h,w,d = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
q = int(input())
s = [None for _ in range(h*w+1)]
for i in range(h):
    for j in range(w):
        s[a[i][j]] = [i+1,j+1]
D = [[0]*((h*w+1)//d+1) for _ in range(d)]
for i in range(d+1,h*w+1):
    X,Y = s[i]
    Z,W = s[i-d]
    x = abs(X - Z) + abs(Y - W)
    D[i%d][i//d] = x + D[i%d][i//d-1]
for _ in range(q):
    l,r = map(int,input().split())
    x = D[l%d]
    print(x[r//d] - x[l//d])


Measured memory_bytes: 69116
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

set<int> divisor(int a)
{
  set<int> st;
  for (int i = 1; i*i <= a; ++i)
  {
    if(a%i==0) 
    {
      st.insert(i);
      st.insert(a/i);
    }
  }
  return st;
}

int main()
{
  int n;
  cin>>n;
  multiset<int> a;
  set<int> b;
  for (int i = 0; i < n; ++i)
  {
    int j;
    cin>>j;
    a.insert(j);
    b.insert(j);
  }
  int ans=0;
  for(const auto& e: b) 
  {
    set<int> div=divisor(e);
    a.erase(a.find(e));
    bool flag=true;
    for(const auto& f: div) 
    {
      if(a.find(f)!=a.end())
      {
        flag=false;
        break;
      }
    }
    if(flag) ans++;
    a.insert(e);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 22364
N,K = map(int,input().split(' '))
S = input()
previous_idx = 0
if S[0] == 'L':
    search_s = 'R'
    non_search_s = 'L'
else:
    search_s = 'L'
    non_search_s = 'R'

flag  = False
i = 0
count_s = 0
new_S = ''
previous_s = S[0]
while K != 0 and i != N:
    if previous_s != S[i]:
        if previous_s == search_s:
            #new_S += non_search_s*count_s
            K -= 1
        #else:
            #new_S += non_search_s*count_s
        previous_s = S[i]
        #count_s = 1
        #count_s += 1
        #if i+1 == N:
        #    flag =True
            #new_S += non_search_s*count_s
        
    i += 1
if K > 0:
    print(N-1)
else:
    new_S += non_search_s*(i-1)
    if not flag:
        new_S += S[i-1:N]
    #print(new_S)
    count_s = 0
    previous_s = new_S[0]
    for i in range(1,N):
        if previous_s == new_S[i]:
            count_s +=1
        else:
            previous_s = new_S[i]
    print(count_s)


Measured memory_bytes: 40816
N = int(input())
l = list(map(int, input().split()))

l_ = []
l__ = []
for n in range(N):
    if l[n] % 2 == 0:
        l_.append(n)

if len(l_) == 0:
    print('APPROVED')
    
if len(l_) != 0:
    for n in l_:
        if l[n] % 3 == 0 or l[n] % 5 == 0:
            l__.append(n)
            
    if len(l__) == len(l_):
        print('APPROVED')
    else :
        print('DENIED')

Measured memory_bytes: 3064
import re
S=input()
T=input()
position=-100
ans=''
for i in range(len(S)-len(T)+1):
	#SをTの長さだけスライス。後ろから順に試す
	if i==0:
		regexp=r'%s' % S[-(len(T)):].replace('?','\w')
	else:
		regexp=r'%s' % S[-(i+len(T)):-i].replace('?','\w')
	if len(re.compile(regexp).findall(T))==1:
		position=i
		break
if position==-100:
	ans='UNRESTORABLE'
elif position==0:
	ans = S[:-(len(T))].replace('?','a') + T
else:
	ans=S[:-(position+len(T))].replace('?','a') + T + S[-(position):].replace('?','a')
print(ans)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    string s;
    string t;
    cin >>s>>t;
    reverse(all(s));
    if(s==t)puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

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

    if(n/100 == n%10) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
using ll =long long;

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

 ll LCM(ll a, ll b) {
	 ll g = GCD(a, b);
	 return a / g *b ;
}

int main() {
	int n;
	cin >> n;
	ll ans = 1;
	for (int i = 0;i < n;i++) {
		ll a;
		cin >> a;
		ans = LCM(a, ans);
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
int n, s, p = -1;
ll a[maxn + 10], w[maxn + 10], ans;
int main() {
	scanf("%d%d", &n, &s);
	for (int i = 1; i <= n; ++i) scanf("%lld%lld", &a[i], &w[i]);
	for (int l = 1, r = n; ; ) {
		if (a[l] >= s) {
			ans += p == -1 ? a[r] - s : a[r] - p + a[r] - s;
			break;
		}
		if (a[r] <= s) {
			ans += p == -1 ? s - a[l] : p - a[l] + s - a[l];
			break;
		}
		if (w[l] >= w[r]) {
			ans += p == -1 ? a[r] - a[l] : p - a[l];
			w[l] += w[r]; p = a[l]; --r;
		} else {
			ans += p == -1 ? a[r] - a[l] : a[r] - p;
			w[r] += w[l]; p = a[r]; ++l;
		}
	}
	printf("%lld", ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 200000 + 1000;
const int MOD = 1000000000 + 7;
const int INF = 0x3f3f3f3f;

int lowbit(int x)
{
	return x & (-x);
}

struct BinaryIndexedTree
{
	int n, s[MAXN];
	void init(int _n)
	{
		n = _n;
		memset(s, 0, sizeof(s));
	}
	void add(int p, int v)
	{
		for(int i = p; i <= n; i += lowbit(i))
			s[i] = (s[i] + v) % MOD;
	}
	int query(int p)
	{
		int ret = 0;
		for(int i = p; i >= 1; i -= lowbit(i))
			ret = (ret + s[i]) % MOD;
		return ret;
	}
	int query(int l, int r)
	{
		return (query(r) - query(l - 1) + MOD) % MOD;
	}
}
bit;

int n;
pair<int, int> a[MAXN];
int id[MAXN], rk[MAXN], l[MAXN], r[MAXN];

bool cmp(int x, int y)
{
	return a[x].second < a[y].second;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i].first >> a[i].second;
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++)
		id[i] = i;
	sort(id + 1, id + n + 1, cmp);
	for(int i = 1; i <= n; i++)
		rk[id[i]] = i;
	l[1] = 1, r[n] = n;
	for(int i = 2; i <= n; i++)
		l[i] = (a[l[i - 1]].second > a[i].second ? l[i - 1] : i);
	for(int i = n - 1; i >= 1; i--)
		r[i] = (a[r[i + 1]].second < a[i].second ? r[i + 1] : i);
	for(int i = 1; i <= n; i++)
		l[i] = rk[l[i]], r[i] = rk[r[i]], swap(l[i], r[i]);
	// for(int i = 1; i <= n; i++)
	// 	cerr << a[i].first << ' ' << a[i].second << ' ' << l[i] << ' ' << r[i] << endl;
	bit.init(n);
	for(int i = 1; i <= n; i++)
	{
		bit.add(r[i], l[i] == 1 ? 1 + bit.query(r[i]) : bit.query(l[i] - 1, r[i]));
	}
	int ans = bit.query(n, n);
	cout << ans << endl;

	return 0;
}


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

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

    cin  >> a >> b >> c;

    if(0 <= a && a <= 100 && 0 <= b && b <= 100 && 0 <= c && c <= 100)
    {
        if(a < b && b < c)
            cout << "Yes" << endl;

        else
            cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3108
import sys
input = sys.stdin.readline
def solve():
  a = [list(int(i) for i in input().split()) for _ in range(3)]
  n = int(input())
  b = [int(input()) for _ in range(n)]
  query = [[False]*3 for _ in range(3)]
  for number in b:
    for i in range(3):
      for j in range(3):
        if a[i][j] == number:
          query[i][j] = True
  ans = "No"
  for i in range(3):
    if query[i][0] and query[i][1] and query[i][2]:
      ans = "Yes"
  for i in range(3):
    if query[0][i] and query[1][i] and query[2][i]:
      ans = "Yes"
  if query[0][0] and query[1][1] and query[2][2]:
    ans = "Yes"
  if query[0][2] and query[1][1] and query[2][0]:
    ans = "Yes"
  print(ans)
                                                
  
solve()

Measured memory_bytes: 3064
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    F = [int(f) for f in input().split()]
    A.sort(reverse = True)
    F.sort()
    low, high = -1, 10 ** 13
    while high - low > 1:
        mid = (low + high) // 2
        count = 0
        for i in range(N):
            counterF = mid // F[i] 
            if counterF < A[i]: count += A[i] - counterF
        if count <= K: high = mid
        else: low = mid
    print(high)
         
    return 0

if __name__ == "__main__":
    solve()

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

WHITE = '.'
BLACK = '#'

K = 50

grid = [[BLACK for _ in range(2*K)] for _ in range(2*K)]
for y in range(K, 2*K):
    for x in range(2*K):
        grid[y][x] = WHITE

A -= 1
B -= 1

for y in range(0, K-1, 2):
    for i in range(K):
        if A > 0:
            grid[y][2*i] = WHITE
            A -= 1
        else:
            break

for y in range(0, K-1, 2):
    for i in range(K):
        if B > 0:
            grid[y+K+1][2*i] = BLACK
            B -= 1
        else:
            break

print("{0} {1}".format(2*K, 2*K))
for g in grid:
    print("".join(g))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <bitset>
#include <fstream>

#define ll long long
#define scani(x) scanf("%i", &x)
#define scanll(x) scanf("%I64d", &x)
#define scanfl(x) scanf("%f", &x)
#define scanch(x) scanf("%c", &x)
#define scans(x) scanf("%s", x);
#define printi(x) printf("%i", x);
#define printll(x) printf("%I64d", x);
#define printfl(x) printf("%f", x);
#define printch(x) printf("%c", x);
#define prints(x) printf("%s", x);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define INFI (1 << 29)
#define INFL (1LL << 62)
#define sz(x) int(x.size())
#define fi first
#define se second
#define forn(i, n) for(ll i = 0; i < n; i++)
#define for1(i, n) for(ll i = 1; i <= n; i++)
#define ford(i, n) for(ll i = (n - 1); i >= 0; i--)
#define fori(i, n) for(ll i = n; i >= 1; i--)
#define fore(i, l, r) for(ll i = l; i <= r; i++)
#define get_bit(mask, x) (bool)(mask & (1LL << x))
#define set_bit(mask, x) (mask |= (1LL << x))
#define reset_bit(mask, x) (mask &= ~(1LL << x))
#define toggle_bit(mask, x) (mask ^= (1LL << x))

using namespace std;

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

    ll a, b, c = 0, r = 0;

    cin >> a >> b;

    while(c < b)
    {
        c += (a - 1);

        r++;
    }

    if(((c - (a - 1)) + 1) >= b)
        c = ((c - (a - 1)) + 1), r--;

    cout << r << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
int k,n;
std::vector<int>A[555];
int main(){
    scanf("%d",&k);
    if(k<=500){
        printf("%d\n",k);
        for(int i=1;i<=k;++i)
        for(int j=1;j<=k;++j)
        printf("%d%c",i," \n"[j==k]);
    }else{
        n=k+1>>1;
        if(n&1)++n;
        for(int i=1;i<=n;++i)
        A[0].push_back(i);
        for(int i=n+2;i<=2*n;++i)
        A[1].push_back(i);
        A[1].push_back(n+1);
        for(int i=2;i<n;++i){
            A[i]=A[i-2];
            A[i].push_back(A[i][0]),A[i].push_back(A[i][1]);
            A[i].erase(A[i].begin());
            A[i].erase(A[i].begin());
        }
        for(int i=0;i<n*2-k;++i){
            for(int x=0;x<n;++x)
            for(int y=0;y<n;++y)
            if(A[x][y]==2*n-i)A[x][y]-=n;
        }
        printf("%d\n",n);
        for(int i=0;i<n;++i){
            for(int j:A[i])printf("%d ",j);
            putchar('\n');
        }
    }
    return 0;
}

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

int main(){
  int y,m,d;
  char a,b;
  cin >> y >> a >> m >> b >> d;
  
  if(y>=2019 && m>4){cout << "TBD" << endl;}
  else{cout << "Heisei" << endl;}
  
  return 0;
}

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

int main()
{
	vector<int> A(3);
	for (int i = 0; i < A.size(); i++)
		cin >> A[i];
	sort(A.begin(), A.end());
	int ans = (A[2] - A[1]) + (A[1]-A[0]+1) / 2 + (A[1] - A[0]) % 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            HashMap<Character, Integer> hm
                = new HashMap<Character, Integer>();

            for (int i = 0; i < s.length(); i++) {
                char at = s.charAt(i);
                if (!hm.containsKey(at)) hm.put(at, 0);
                hm.put(at, hm.get(at) + 1);
            }

            boolean flg = true;

            for (char c : hm.keySet()) {
                if (hm.get(c) % 2 == 1) {
                    flg = false;
                    break;
                }
            }

            System.out.println(flg ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pis = pair<int,string>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int n;
    cin >> n;
    if(n == 1){
        cout << "a" << endl;
        return 0;
    }
    //priority_queue<string,vector<string>,greater<string>> S;
    priority_queue<string,vector<string>,greater<string>> ans;
    priority_queue<pis,vector<pis>,greater<pis>> S;
    //priority_queue<pis,vector<pis>,greater<pis>> ans;
    S.push(pis(1,"a"));
  //S.push("a");
    while(S.size()){
      pis P = S.top();
        string s = P.second;
        S.pop();
        if(s.size() == n){
            ans.push(s);
            continue;
        }
        //int num = unique(s.begin(), s.end()) - s.begin();
      int num = P.first;
      //cout << s << " " << num << endl;
      //cout << "start" << endl;
        rep(i,num+1){  
            s.push_back('a' + i);
          //cout << s << endl;
            S.push(pis( num + (i == num) ,s));
            s.pop_back();
        }
      //cout << "end" << endl;
    }
    //cout << ans.size() << endl;
    while(ans.size()){
        cout << ans.top() << endl;
        ans.pop();
    }
}

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

# define fori(i,n)          for(int i=0;i<n;i++)
# define forl(i,n)          for (ll i=0;i<n;i++)
# define pb                 push_back
# define mp                 make_pair
# define X                  first
# define Y                  second
# define all(v)             v.begin(),v.end()
# define in_ar_int(arr,n)   int arr[n]; fori(i,n) cin >> arr[i];
# define in_ar_ll(arr,n)    ll arr[n]; fori(i,n) cin >> arr[i];
# define endl               "\n"
# define R0                 return 0
# define mod                1000000007
# define pi                 3.1415926536

typedef long long ll;
typedef string str;
typedef unsigned long long ull; 
typedef pair<int, int> pii; 
typedef vector<pii> vpii;
typedef vector<int> vi;

void solve(){
    int n;
    int w;
    cin >>n >> w;
    ll x,y;
    vector <ll> dp(w+1,0);
    for (int i=0;i<n;i++){
        cin >> x >> y;
        for(int j=w-x;j>=0;--j){
            dp[j+x]=max(dp[j+x],dp[j]+y);
        }
    }
    ll ans=0 ;
    for (int i=0;i<w+1;i++) ans=max(ans,dp[i]);
    cout << ans << "\n";
}     

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int chill=1;
    // cin >> chill;
    while(chill--){
    solve();
    }
}



Measured memory_bytes: 3984
program mixing_experiment
  implicit none
  integer :: n, ma, mb, a, b, c, dp(0:400,0:400)
  integer :: i, ia, ib, m
  integer, parameter :: infty = 10000000
  dp = infty
  read(*,*) n, ma, mb
  dp(0,0) = 0
  do i = 1, n
    read(*,*) a, b, c
    do ia = 400, a, -1
      do ib = 400, b, -1
        dp(ia,ib) = min(dp(ia,ib),dp(ia-a,ib-b)+c)
      end do
    end do
  end do
  m = infty
  do i = 1, 400/ma
    ia = i*ma
    ib = i*mb
    if (ib.gt.400) exit
    m = min(dp(ia,ib),m)
  end do
  if (m.eq.infty) then
    write(*,'(i0)') -1
  else
    write(*,'(i0)') m
  end if
  stop
end program mixing_experiment

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair



int main() {
  int n, m;
  cin >> n >> m;
  vi p(m), y(m);
  vector<map<int, int> > mp(n);
  rep (i, m) {
    cin >> p[i] >> y[i];
    p[i]--;
    mp[p[i]][y[i]] = i;
  }
  vector<pii> ans(m);
  rep (i, n) {
    int cnt = 0;
    for (auto itr = mp[i].begin(); itr != mp[i].end(); itr++) {
      int j = itr->second;
      cnt++;
      ans[j] = pii(i + 1, cnt);
    }
  }
  rep (i, m) {
    printf("%06d%06d\n", ans[i].first, ans[i].second);
  }
}
    
  
  


Measured memory_bytes: 12416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(),k = scanner.nextInt(),x = scanner.nextInt(),y = scanner.nextInt();
		int sum = 0;
		for(int i=0;i<n;i++){
			if(i < k){
				sum += x;
			}else{
				sum += y;
			}
		}
		System.out.println(sum);

	}

}


Measured memory_bytes: 20820
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
template<class T,class U>constexpr bool bit(const T n,const U k){return (n>>k)&1;}

//デバッグ
template<class T>
void Vout(vector<T> &V){
    cout<<"start"<<endl;
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i]<<'\n';
    }
    cout<<"end"<<endl;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;

//__builtin_popcount(S);
//#define int ll
//vector<vector<int>> data(3, vector<int>(4));
//vector.resize(a,vector<int>(b,-1));
//vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));



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

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

    int N,K;
    cin>>N>>K;
    vector<vector<ll>> V(N+1, vector<ll>(0));
    for(int i=0;i<N;i++){
        int t;
        ll d;
        cin>>t>>d;
        V[t].push_back(d);
    }
    for(int i=0;i<=N;i++){
        sort(V[i].rbegin(),V[i].rend());
    }
    vector<ll> ne,ol;
    for(int i=0;i<=N;i++){
        for(int j=0;j<(int)V[i].size();j++){
            if(j==0) ne.push_back(V[i][j]);
            else ol.push_back(V[i][j]);
        }
    }
    sort(ne.rbegin(),ne.rend());
    sort(ol.rbegin(),ol.rend());

    for(int i=1;i<(int)ne.size();i++) ne[i]+=ne[i-1];
    for(int i=1;i<(int)ol.size();i++) ol[i]+=ol[i-1];
    ll ans=0;
    for(int i=1;i<=K;i++){
        if(ne.size()<i) break;
        ll x=ne[i-1];
        if(i!=K && (int)ol.size()>0) x+=ol[min(K-i-1,(int)ol.size()-1)];
        chmax(ans,x+(ll)i*i);
    }
    cout<<ans<<endl;
}

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

int main() {
	string c,d;
    cin >> c >> d;
    if(c.at(0)==d.at(2) && c.at(1)==d.at(1) && c.at(2)==d.at(0)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int N, M;
vector<vector<int> > A;

void func(vector<int> a){
  if(a.size() == N){
    A.push_back(a);
    return;
  }
  int num = 1;
  if(a.size() != 0){
    num = a.back();
  }
  for(int i = num; i <= M; i++){
    a.push_back(i);
    func(a);
    a.pop_back();
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int Q; cin >> N >> M >> Q;
  vector<int> a;  // 関数に渡す空の配列を用意
  func(a);
  int n = A.size();
  vector<int> res(n, 0);
  REP(i, Q){
    int a, b, c, d; cin >> a >> b >> c >> d; a--; b--;
    REP(j, n){
      if(A[j][b]-A[j][a] == c) res[j] += d;
    }
  }
  int ans = 0;
  REP(i, n){
    ans = max(ans, res[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 10080
#include <iostream>
#include <vector>
#include <queue>
#define NMAX 102

using namespace std;
int main(){
	int N,A[2][NMAX],dp[2][NMAX] = {};
	cin >> N;
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			cin >> A[i][j];
			dp[i][j] = A[i][j];
		}
	}
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			if(i != 0 && j != 0){
				dp[i][j] += max(dp[i-1][j],dp[i][j-1]);
			}else if(i == 0 && j != 0){
				dp[i][j] += dp[i][j-1];
			}else if(i != 0 && j == 0){
				dp[i][j] += dp[i-1][j];
			}
		}
	}
	cout << dp[1][N-1] << endl;
	return 0;
}

Measured memory_bytes: 892
x = int(input())

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


Measured memory_bytes: 9180
n, m  = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb = []
for i in range(m):
  b, c = map(int, input().split())
  cb.append([c,b])
cb.sort(reverse=True)

j = 0
for i in range(m):
  k = 0
  while k<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
    a[k+j] = cb[i][0]
    k += 1
  j += k
  if j == n:
    break
    
print(sum(a))

Measured memory_bytes: 28196
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


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

	sort(a.begin(), a.end(), greater<int>());
	double half = a[0]/2;

	int diff = MOD, index = -1;
	for (int i = 1; i < n; i++){
		if (diff > abs(a[i] - half)){
			diff = abs(a[i] - half);
			index = i;
		}
	}
	cout << a[0] << " " << a[index] << endl;
	return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
struct mint {
    long long x;
    mint(long long _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(long long t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& a){
        os << a.x;
        return os;
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int> C(N);
    rep(i,N){
        cin >> C[i];
    }
    sort(all(C));
    print(C);
    mint sum = 0;
    //0000...0について
    if(N == 1){
        mint ans = 2 * C[0];
        cout << ans << endl;
        return 0;
    }
    rep(i,N){
        mint cnt = mint(2).modpow(N-2) * (2 + N - i - 1);
        sum += mint(C[i]) * cnt;
    }
    sum *= mint(2).modpow(N);
    cout << sum <<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    double W,H,x,y;
    cin>>W>>H>>x>>y;
    cout<<W*H/2<<endl;
    if(x==W/2 && y==H/2){cout<<1<<endl;}
    else{cout<<0<<endl;}
}

Measured memory_bytes: 256