akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    ll n;
    cin >> n;
    ll tot=0;
    rep2(i,n){
        if(i%3!=0&&i%5!=0){
            tot+=i;
        }
    }
    cout<<tot<<endl;
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <queue>
#include <vector>
using namespace std;

vector<int> ans;
int vis[10010] = {0};
int cc[10010];
vector<int> r[10010];

class priority {
  public:
    bool operator() (const pair<int,int> &x, const pair<int,int> &y) const {
      return x.second > y.second;
    }
};

void topo(int n) {
  priority_queue<pair<int,int>, vector<pair<int,int> >, priority> pq;
  for (int i = 0; i < n; i++) { 
    pq.push(make_pair(i, cc[i]));
  }
  while (!pq.empty()) {
    pair<int,int> now = pq.top();
    pq.pop();
    int no = now.first;
    int count = now.second;
    if (count != 0) break;
    if (vis[no]) continue;
    vis[no] = 1;
    ans.push_back(no);
    for (int i = 0; i < r[no].size(); i++) {
      int t = r[no][i];
      pq.push(make_pair(t, --cc[t]));
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    r[x].push_back(y);
    cc[y]++;
  }
  topo(n);
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4164
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Ord
import Data.Maybe
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  (n,k) <- getIntPair
  edges <- replicateM (n-1) getIntPair
  let adj = accumArray (flip (:)) [] (1,n) $ edges ++ map swap edges
  -- print adj
  let mt p v = Node v $ map (mt v) $ delete p (adj!v)
  -- print $ mt 0 1
  let ans = if even k
            then
              maximum [cntD (k`div`2) $ mt 0 v | v <- [1..n]]
            else
              maximum [(cntD (k`div`2) $ mt w v) + (cntD (k`div`2) $ mt v w) | (v,w) <- edges]
  print (n - ans)


cntD 0 (Node _ cs) = 1
cntD n (Node _ cs) = 1 + sum [cntD (n-1) c | c <- cs]

type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 1788
fn search(li: &[i32], t: i32) -> usize {
    let mut left = 0;
    let mut right = li.len();
    while right - left > 1 {
        let mid = (right + left) / 2;
        if li[mid] < t {
            right = mid
        } else {
            left = mid
        }
    }
    left
}

fn main() {
    let n: u32 = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned().parse().unwrap()
    };

    let l: Vec<i32> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut ws = s.trim_right().split_whitespace();
        let mut l:Vec<i32> = vec![];
        while let Some(n) = ws.next() {
            l.push(n.parse().unwrap())
        }
        l.sort();
        l.reverse();
        l
    };

    let mut res = 0;
    for i in 0..(n as usize) {
        for j in (i+1)..((n-1) as usize) {
            let t = l[i] - l[j] + 1;
            if t > l[j+1] { continue }
            let cnt = search(&l[j+1..], t);
            res += (cnt+1)
        }
    }
    println!("{}", res)
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair
#define r0 return 0

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

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int k;
    vector<int> v(5);
    rep(i, 5)
    {
        cin >> v[i];
    }
    cin >> k;
    if (v[4] - v[0] <= k)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>
 
#define str string
 
#define pb(a) push_back(a)
#define mp make_pair
 
 
int main(){
  LCIN(x,y);
  if(x<2)EN(Brown);
  if(abs(x-y)<2)EN(Brown);
  EN(Alice);
 
  return 0;
}

Measured memory_bytes: 256
//This Code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<time.h>
// #include<windows.h>
#define int long long
#define PI 3.14159265358979323
#define INF 0x3fffffffffffffff
using namespace std;
string s,t;
int ans=INF,tmp;
signed main()
{
    ios::sync_with_stdio(false);
    cin>>s>>t;
    for(int i=0;i+(int)t.length()-1<(int)s.length();++i)
    {
        tmp=0;
        for(int j=0;j<(int)t.length();++j)
        {
            if(s[i+j]!=t[j])
            {
                ++tmp;
            }
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(){

    int n;
    scanf("%d",&n);
    int a[n],b[n],c[n-1];
    int sum=0;
    for(int i=0;i<n;i++){
    
        scanf("%d",&a[i]);
    
    
    }
    for(int i=0;i<n;i++){
    
        scanf("%d",&b[i]);
    
    }
    for(int i=0;i<n-1;i++){
    
        scanf("%d",&c[i]);
    
    
    }
    int ant=1;
    sum=0;
    for(int i=0;i<n;i++){
        int j = a[i];
        
        
        sum+=b[j-1];
        if(j==ant+1 && i!=0)
            sum+=c[j-2];
        ant=j;
    }
    printf("%d",sum);
    return 0;
    
}


Measured memory_bytes: 128
n = int(input())
l = 0
r = float("INF")
LR = [list(map(int,input().split())) for i in range(n)]
w = 0
for i,j in LR:
    l = max(l,i)
    r = min(r,j)
    w = max(w,j-i+1)
ans = max(r-l+1,0)+w
LR.sort()
rm = [float("INF")]*(n+1)
for i in range(n):
    rm[-2-i] = min(rm[-1-i],LR[-1-i][1])
for k in range(n-1):
    i,j = LR[k]
    a = max(r-i+1,0)
    b = max(rm[k+1]+1-l,0)
    ans = max(ans,a+b)
print(ans)

Measured memory_bytes: 27792
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
  int x,y,l=0;
  cin>>x>>y;
  if(x<=3){l+=400000-100000*x;}
  if(y<=3){l+=400000-100000*y;}
  if(x==1&&y==1){l+=400000;}
  cout<<l<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

char mp[1005][1005];
int vis[1005][1005];
int w, h, n;

int dirs[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int ans = 0, sx, sy;
int blood = 1;

struct Node{
	int x,y;
	Node(int _x, int _y){
		x = _x, y = _y;
	}
}; 
typedef struct Node Node; 

queue<Node> que;

void bfs(char t){
//	cout<<"sx = "<<sx<<", sy = "<<sy<<endl;
	que.push(Node(sx, sy));
	ans = 0;
	bool flag = true;
	while(!que.empty()){
//		cout<<"ans = "<<ans<<"n = "<<n<<endl;
		int size = que.size();
		for(int i = 0; i < size; i++){
			Node node = que.front();
			que.pop();
			int x = node.x, y = node.y;
//			cout<<"x = "<<x<<", y = "<<y<<endl;
			for(int i = 0; i < 4; i++){
				int tx = x + dirs[i][0], ty = y + dirs[i][1];
				if(tx >= 0 && tx < h && ty >= 0 && ty < w && vis[tx][ty] == 0 && mp[tx][ty] == t){
					sx = tx, sy = ty;
					ans++;
					flag = false;
					return;
				}else if(tx >= 0 && tx < h && ty >= 0 && ty < w && vis[tx][ty] == 0 &&  mp[tx][ty] != 'X'){
//					cout<<"tx = "<<tx<<", ty = "<<ty<<endl;
					que.push(Node(tx, ty));
					vis[tx][ty] = 1;
				}
			} 
		}
		ans++;
	}
	if(flag) ans = 0;
}

int main(){
	cin>>h>>w>>n;
	for(int i = 0; i < h; i++){
		scanf(" %s", mp[i]);
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(mp[i][j] == 'S'){
				sx = i, sy = j;
			}
		}
	}
	int res = 0;
	for(int i = 1; i <= n; i++){
		bfs(i + '0');
		for(int m = 0; m < h; m++)
			for(int k = 0; k < w; k++)
				vis[m][k] = 0;
		while(!que.empty())que.pop();
		res += ans;
	}
	cout<<res<<endl;
	return 0;
}

/**
331
S..
...
..1
*/


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


int main() {

    int n, m;
    cin >> n >> m;
    vector<int> cnt(m, 0);
    for (int i = 0; i < n; ++i) {
        int k; cin >> k;
        for (int j = 0; j < k; ++j) {
            int a; cin >> a;
            --a;
            ++cnt[a];
        }
    }
    int ans = 0;
    rep(i,m) {
        if (cnt[i] == n) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	string s;
	cin>>s;

	int t=0;
	rep(i,s.size()){
		if(s[i]=='x')t++;
	}
	if(15-t>=8)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		int i = scanner.nextInt();
		int j = scanner.nextInt();
		scanner.close();
		int measure = i*j;
		int circuit = i*2 + j*2;
		System.out.println(measure + " "+ circuit);
	}
}

Measured memory_bytes: 17160
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a;i < b; i++)

int main() {

	int n;
	cin >> n;

	vector<int> p(n);
	vector<int> q(n);

	rep(i, 0, n) {
		cin >> p[i];
		q[i] = p[i];
	}

	sort(q.begin(), q.end());

	int count = 0;

	rep(i, 0, n) {
		if (p[i] != q[i]) count++;
	}

	if (count > 2) cout << "NO" << endl;
	else cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (N,M,X,Y) = readLine()!!.split(" ").map{it.toInt()}
  val xn = readLine()!!.split(" ").map{it.toInt()}
  val ym = readLine()!!.split(" ").map{it.toInt()}

  if(judge(X,Y,xn,ym)){
    println("No War")
    return
  }
    println("War")
}

fun judge(X: Int, Y: Int, listX: List<Int>, listY: List<Int>): Boolean {
  return (X+1..Y).any{index ->
    listX.all{
      it < index
    } && listY.all{
      it >= index
    }
  }
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    unordered_set <string> a;
    for(int i  =0;i< n;i++){
        string temp;
        cin>>temp;
        a.insert(temp);
    }
    
    cout<<a.size()<<endl;
}

Measured memory_bytes: 17692
(n, a, b) = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
res = 0
for i in range(n - 1):
    at = (arr[i + 1] - arr[i]) * a
    if at > b:
        res += b
    else:
        res += at
print(res)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n, m, a, b;
  cin >> n >> m;
  vector<int> ans(n);
  rep(i, m) {
    cin >> a >> b;
    ans[a-1] += 1;
    ans[b-1] += 1;
  }
  rep(i, n) cout << ans[i] << endl;
}



Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}

int main(){
	int x, a, b;
	cin>>x>>a>>b;
	
	if(b<=a) cout<<"delicious"<<endl;
	else if(x>=b-a) cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
	return 0;
}




Measured memory_bytes: 256
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
dp=[[0]*(t) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(t):
        if j-l[i-1][0]>=0:
            dp[i][j]=max(dp[i-1][j-l[i-1][0]]+l[i-1][1],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
ans=[]
for i in range(n):
    ans.append(dp[i][-1]+l[i][1])
print(max(ans))

Measured memory_bytes: 116568
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll S,W;
    cin >> S >> W;
    if (S <= W){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
   return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n >> m;
	cout << n*(n-1)/2+m*(m-1)/2 << 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);
    	
        int N = sc.nextInt();
        int[] d = new int[N];
        int hp = 0;

        for (int i = 0; i < N; i++)
            d[i] = sc.nextInt();

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i != j) 
                    hp += d[i] * d[j];
            }
        }
        System.out.println(hp/2);
   	}
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
int n, a[26], ans=1;
string s;
signed main() {
	cin >> n >> s;
	rep(i, n)a[s[i] - 'a']++;
	rep(i, 26) {
		a[i]++;
		ans *= a[i];
		ans %= MOD;
	}
	ans--;
	cout << ans << endl;
	END;
}


Measured memory_bytes: 760
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  bool f[128]{};
  string s; cin >> s;
  for (int c : s) f[c] = true;

  for (int i = 'a'; i <= 'z'; ++i) {
    if (!f[i]) {
      cout << (char)i << endl;
      return 0;
    }
  }

  cout << "None" << endl;

  return 0;
}



Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    long long int x,y;
    scanf("%lld %lld",&x,&y);
    while (x!=0 &&y!=0){
        if(x>=y){
            x=x-y;
        }else{
            y=y-x;
        }
    }
    if(x==0){
        printf("%lld\n",y);
    }else{
        printf("%lld\n",x);
    }
    
    
    return 0;
}

Measured memory_bytes: 596
from collections import deque
import sys

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**9
    h,w,k=MI()
    x1,y1,x2,y2=MI1()
    aa=[[0 if c=="@" else inf for c in SI()] for _ in range(h)]
    #p2D(aa)

    aa[x1][y1]=0
    q=deque()
    q.append((x1,y1,0))
    while q:
        x,y,d=q.popleft()
        for nx in range(x+1,min(x+k+1,h)):
            if aa[nx][y] == d + 1:continue
            if aa[nx][y]<d+1:break
            aa[nx][y]=d+1
            q.append((nx,y,d+1))
        for nx in range(x-1,max(x-k-1,-1),-1):
            if aa[nx][y] == d + 1:continue
            if aa[nx][y]<d+1:break
            aa[nx][y]=d+1
            q.append((nx,y,d+1))
        for ny in range(y+1,min(y+k+1,w)):
            if aa[x][ny] == d + 1:continue
            if aa[x][ny]<d+1:break
            aa[x][ny]=d+1
            q.append((x,ny,d+1))
        for ny in range(y-1,max(y-k-1,-1),-1):
            if aa[x][ny] == d + 1:continue
            if aa[x][ny]<d+1:break
            aa[x][ny]=d+1
            q.append((x,ny,d+1))
        #p2D(aa)
        #print()

    ans=aa[x2][y2]
    if ans==inf:print(-1)
    else:print(ans)

main()

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d){
        cout << "Left";
    }else if(a+b<c+d){
        cout << "Right";
    }else{
        cout << "Balanced";
    }
    return 0;
}

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

using namespace std;

class Solution {
  public:
    bool Solve(int N) {
        for (int i = 0; i <= 100 / 7; i++) {
            for (int j = 0; j < 100 / 4; j++) {
                if (7 * i + 4 * j == N)
                    return true;
            }
        }
        return false;
    }
};

int main() {
    int n;
    cin >> n;
    Solution s;
    if (s.Solve(n))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 30
#define NIL -1

typedef struct Node{
  int parent;
  int left;
  int right;
}Node;

typedef struct node{
  int sibling;
  int degree;
  int depth;
  int height;
}Depth;

Node gNode[MAX];
Depth gDepth[MAX];

void print(int, int);
void rec(int, int);
void height(int, int);

int main(){
  int n,i,j,nodeP,left,right,root;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    gNode[i].parent = NIL;
    gNode[i].left = NIL;
    gNode[i].right = NIL;
    gDepth[i].height = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d%d",&nodeP,&left,&right);
    gNode[nodeP].left = left;
    gNode[nodeP].right = right;
    if(left != NIL) gNode[left].parent = nodeP;
    if(right != NIL) gNode[right].parent = nodeP;
  }
   for(i = 0; i < n; i++){
    if(gNode[i].parent == NIL){
      root = i;
    }
  }
   gDepth[root].sibling = NIL;
   
   for(i = 0; i < n; i++){
     if(i != root){
       if(i != gNode[gNode[i].parent].left) gDepth[i].sibling = gNode[gNode[i].parent].left;
       else if(i != gNode[gNode[i].parent].right) gDepth[i].sibling = gNode[gNode[i].parent].right;
     }
     if(gNode[i].right != NIL && gNode[i].left != NIL) gDepth[i].degree = 2;
     else if(gNode[i].right != NIL || gNode[i].left != NIL) gDepth[i].degree = 1;
     else{
       gDepth[i].degree = 0;
       gDepth[i].height = 0;
     }
     if(gDepth[i].height == 0) height(i,0);
   }


   rec(root,0);

   for(i = 0; i < n; i++){
     print(i,n);
  }
  return 0;

}

void rec(int node, int depth){
  gDepth[node].depth = depth;
  if(gNode[node].left != NIL) rec(gNode[node].left,depth+1);
  if(gNode[node].right != NIL) rec(gNode[node].right,depth+1);
}

void height(int node, int hei){
  if(gDepth[node].height < hei) gDepth[node].height = hei;
  if(gNode[node].parent != NIL) height(gNode[node].parent,hei+1);
}

void print(int node, int n){
  printf("node %d: parent = %d, sibling = %d, ",node,gNode[node].parent,gDepth[node].sibling);
  printf("degree = %d, depth = %d, height = %d, ",gDepth[node].degree,gDepth[node].depth,gDepth[node].height);
  if(gNode[node].parent == NIL) printf("root\n");
  else if(gNode[node].left == NIL && gNode[node].right == NIL) printf("leaf\n");
  else printf("internal node\n");
}



Measured memory_bytes: 2048
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,Q,*m = map(int, read().split())
    AB = m[:2*(N-1)]
    PX = m[2*(N-1):]

    E = [[] for _ in range(N+1)]
    for a, b in zip(*[iter(AB)]*2):
        E[a].append(b)
        E[b].append(a)

    cost = [0] * (N+1)
    for p, x in zip(*[iter(PX)]*2):
        cost[p] += x

    seen = [-1] * (N+1)
    seen[1] = cost[1]
    stack = [1]
    while stack:
        v = stack.pop()
        for e in E[v]:
            if seen[e] == -1:
                seen[e] = seen[v] + cost[e]
                stack.append(e)

    print(*seen[1:])
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 94828
input_line = int(input())
keta = len(str(input_line))

suji = []
suji_2 = []
mojiretu = ''
mojire = ''
flug = 0

if keta%2 == 0:
    for i in range(keta-1):
        if i%2 == 0:
            suji.append('9')
        else:
            suji.append('0')

else:
    if keta == 1:
        print(input_line)
        exit()
    else:
        for i in range(keta-2):
            if i%2 == 0:
                suji.append('9')
            else:
                suji.append('0')
        flug = 1

for x in suji:
    mojiretu += x

for y in range(keta-1):
    suji_2.append('9')

for x in suji_2:
    mojire += x


if flug == 0:
    print(mojiretu)
else:
    input_line = input_line - int(mojire)
    print(int(mojiretu) + input_line)



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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();

			for (int i = 0; i <= n/4+1; i++) {
				for (int j = 0; j <= n/7+1; j++) {
					int sum = 4*i + 7*j;
					if (sum == n) {
						out.println("Yes");
						return;
					}
				}
			}

			out.println("No");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


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

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

  bool takahashi=false; //false=lose
  while(1){
    c-=b;
    if(c<=0){
      takahashi=true;
      break;
    }
    a-=d;
    if(a<=0){
      takahashi=false;
      break;
    }
  }
  if(takahashi){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, a = 0;
    scanf("%d", &n);
    vector<int> b(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &b[i]);
        a += b[i];
    }
    if (a % 10)
    {
        printf("%d\n", a);
        return 0;
    }
    else
    {
        sort(b.begin(), b.end());
        for (int i = 0; i < n; i++)
        {
            if (b[i] % 10)
            {
                printf("%d\n", a - b[i]);
                return 0;
            }
        }
    }
    printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
using namespace std;
char in[110][1100];
map<string,int>m;
string rev[110];
vector<int>g[110];
int mod=1000000007;
int v[310];
int sz[310];
int cur;
int solve(int a){
	if(~sz[a])return sz[a];
	int ret=0;
	for(int i=0;i<g[a].size();i++){
		if(g[a][i]<0)ret=min(210,ret+1);
		else ret=min(210,ret+solve(g[a][i]));
	}
	return sz[a]=ret;
}
void dfs(int a){
	for(int i=0;i<g[a].size();i++){
		if(g[a][i]<0){
			v[cur++]=-g[a][i];
		}else dfs(g[a][i]);
	}
}
int dp[51][51][51][51];
int main(){
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	gets(in[0]);
	for(int i=0;i<e;i++)gets(in[i]);
	for(int i=e-1;i>=0;i--){
		string tmp="";
		int j=0;
		for(;in[i][j];j++){
			if(in[i][j]==':'){
				break;
			}
			tmp+=in[i][j];
		}
		m[tmp]=i;
		rev[i]=tmp;
		j+=2;
		while(in[i][j]){
			if(in[i][j]=='['){
				int now=0;
				while(in[i][j]!=']'){
					if(in[i][j]=='A')now-=1;
					if(in[i][j]=='T')now-=2;
					if(in[i][j]=='G')now-=4;
					if(in[i][j]=='C')now-=8;
					j++;
				}
				g[i].push_back(now);
				j++;
			}else{
				string now="";
				while(in[i][j]!=' '&&in[i][j]){
					now+=in[i][j];
					j++;
				}
				g[i].push_back(m[now]);
			}
			j++;
		}
	}
	for(int i=0;i<e;i++)sz[i]=-1;
	int t=solve(0);
	if(t!=a+b+c+d){
		printf("0\n");return 0;
	}
	dfs(0);
	dp[0][0][0][0]=1;
	for(int i=0;i<t;i++){
		for(int j=max(0,i-b-c-d);j<=min(i,a);j++){
			for(int k=max(0,i-j-c-d);k<=min(i-j,b);k++){
				for(int l=max(0,i-j-k-d);l<=min(i-j-k,c);l++){
					if((v[i]&1)&&j<a)dp[j+1][k][l][i-j-k-l]=(dp[j+1][k][l][i-j-k-l]+dp[j][k][l][i-j-k-l])%mod;
					if((v[i]&2)&&k<b)dp[j][k+1][l][i-j-k-l]=(dp[j][k+1][l][i-j-k-l]+dp[j][k][l][i-j-k-l])%mod;
					if((v[i]&4)&&l<c)dp[j][k][l+1][i-j-k-l]=(dp[j][k][l+1][i-j-k-l]+dp[j][k][l][i-j-k-l])%mod;
					if((v[i]&8)&&i-j-k-l<d)dp[j][k][l][i-j-k-l+1]=(dp[j][k][l][i-j-k-l+1]+dp[j][k][l][i-j-k-l])%mod;
				}
			}
		}
	}
	printf("%d\n",dp[a][b][c][d]);
}

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

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int C = 5556;
vector<ii> getlines(string s, bool ext=1)
{
	vector<ii> vec; int n=s.length();
	for(int i=0;i<C;i++)
	{
		if(i<C-1&&!ext) continue;
		vec.pb(mp(s[0]-'0',0));
		if(i%2==0) vec.back().fi^=1;
	}
	for(int i=0;i+1<n;i++)
	{
		if(s[i]!=s[i+1])
		{
			vec.pb(mp(s[i+1]-'0',i+1));
		}
	}
	for(int i=0;i<C;i++)
	{
		if(i>0&&!ext) break;
		vec.pb(mp(s[n-1]-'0',n));
		if(i%2==0) vec.back().fi^=1;
	}
	return vec;
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	//freopen("less-than-3.txt","r",stdin);
	int n; cin>>n;
	string s,t;
	cin>>s>>t;
	vector<ii> a = getlines(s);
	vector<ii> b = getlines(t,0);
	/*
	for(ii x:a)
	{
		cerr<<x.fi<<' '<<x.se<<'\n';
	}
	cerr<<'\n';
	for(ii x:b)
	{
		cerr<<x.fi<<' '<<x.se<<'\n';
	}
	*/
	int ans = int(1e9);
	for(int i=0;i<a.size();i++)
	{
		if(a[i].fi==b[0].fi&&i+int(b.size())-1<int(a.size()))
		{
			int res=0;
			if(a[i].se>0)
			{
				for(int j=0;j<i;j++) res+=a[j].se;
			}
			//cerr<<res<<'\n';
			for(int j=0;j<b.size();j++)
			{
				res+=abs(b[j].se-a[i+j].se);
				//cerr<<b[j].se<<' '<<a[i+j].se<<' '<<abs(b[j].se-a[i+j].se)<<'\n';
			}
			if(a[i+int(b.size())-1].se<n)
			{
				for(int j=i+int(b.size());j<a.size();j++) res+=n-a[j].se;
			}
			//cerr<<res<<'\n';
			//cerr<<'\n';
			ans=min(ans,res);
		}
	}
	cout<<ans<<'\n';
}	


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

using namespace std;

const int MOD = 1e9 + 7;

typedef long long ll;

int mul(int a, int b) {
	ll res = (ll)a * b;
	return res % MOD;
}

int add(int a, int b) {
	ll res = (ll)a + b;
	return res % MOD;
}

int sub(int a, int b) {
	ll res = (ll)a - b;
	res %= MOD;
	res += MOD;
	return res % MOD;
}

const int MAXN = 104;
const int CNT = 4;
int dp[MAXN][CNT][CNT][CNT];

bool ok(vector<int> a) {
	auto ch = [](vector<int> a) {
		for (int i = 0; i + 3 <= (int)(a.size()); i++) {
			if (a[i] == 0 && a[i + 1] == 1 && a[i + 2] == 2) {
				return false;
			}
		}
		return true;
	};
	if (!ch(a)) return false;
	for (int i = 0; i + 1 < (int)a.size(); i++) {
		swap(a[i], a[i + 1]);
		if (!ch(a)) return false;
		swap(a[i], a[i + 1]);
	}
	return true;
}
               
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef LOCAL
	assert(freopen("input.txt", "r", stdin));
	#endif

	int n;
	cin >> n;
	for (int a = 0; a < 4; a++) {
		for (int b = 0; b < 4; b++) {
			for (int c = 0; c < 4; c++) {
				vector<int> tmp = {a, b, c};
				if (ok(tmp)) {
					//cerr << a << ' ' << b << ' ' << c << endl;
					dp[3][a][b][c] = 1;
				}
			}
		}
	}
	for (int i = 3; i + 1 <= n; i++) {
		for (int a = 0; a < 4; a++) {
			for (int b = 0; b < 4; b++) {
				for (int c = 0; c < 4; c++) {
					for (int d = 0; d < 4; d++) {
						vector<int> cr = {a, b, c, d};
						if (ok(cr)) {
							dp[i + 1][b][c][d] = add(dp[i + 1][b][c][d], dp[i][a][b][c]);
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int a = 0; a < 4; a++) {
		for (int b = 0; b < 4; b++) {
			for (int c = 0; c < 4; c++) {
				ans = add(ans, dp[n][a][b][c]);
			}
		}
	}
	cout << ans << endl;
	//vector<int> a = {0, 1, 2};
	//cout << ok(a) << endl;	
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

ll n, a, b;
int h[100010];

bool isOK(ll x){
    ll cnt = 0;
    REP(i,0,n){
        ll rest = h[i] - x * b;
        if (rest <= 0) continue;
        cnt += (rest + a - b - 1) / (a - b);
    }
    return cnt <= x;
}

int main(){
    cin >> n >> a >> b;
    REP(i,0,n){
        cin >> h[i];
    }

    ll ng = 0, ok = MOD;
    while(abs(ok - ng) > 1){
        ll mid = (ng + ok) / 2;
        if (isOK(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;   
    
    return 0;
}

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

using namespace std;
#define int long long
const int N = 3333;
int dp[N][N][6];
/*dp(i,j,k)：当前位于 第 i 行,第 j 列,且当行已经取了第  k 个的最大值 */
int mp[N][N]={0};
int R,C,K;
int mc[N];
signed main(){
	cin>>R>>C>>K;
	int r,c,v;
	for(int i=1;i<=K;i++){
		cin>>r>>c>>v;
		mp[r][c]=v;
	}
	for(int i=1;i<=R;i++){
		for(int j=1;j<=C;j++){
			int sum=0;
			for(int k=0;k<=3;k++){
				sum=max(sum,dp[i-1][j][k]);
			}
			for(int k=1;k<=3;k++){
				dp[i][j][k]=max(max(dp[i][j-1][k],dp[i][j-1][k-1]+mp[i][j]),sum+mp[i][j]);	
			}
		}
	}
	
	int ans=0;
	for(int i=0;i<=3;i++){
		ans=max(ans,dp[R][C][i]);
	}  
	cout<<ans;
	return 0;
}

Measured memory_bytes: 515144
s,t=input(),input()
ans='z'*len(s)
for i in range(len(s)-len(t)+1):
    pre=s[:i].replace("?",'a')
    
    for x,y in zip(list(s[i:]),list(t)):
        if x!="?"and x!=y:break
        pre+=y
    else:
        pre+=s[i+len(t):].replace("?",'a')
        ans=min(ans,pre)
print(ans if ans!='z'*len(s) else 'UNRESTORABLE')

Measured memory_bytes: 9084
s = input()

if s[0] == 'R' and s[1] == 'R' and s[2] == 'R':
    print(3)
elif (s[0] == 'R' and s[1] == 'R') or (s[1] == 'R' and s[2] == 'R') : 
    print(2)
elif s[0] == 'R' or s[1] == 'R' or s[2] == 'R':
    print(1)
else:
    print(0)

Measured memory_bytes: 9052
/**
		Author : Avi J Patel
		University : DA-IICT
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define large 10000000000000001
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int main()
{
	string s;
	cin>>s;
	if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
	{
		cout<<"Bad";
	}
	else
	cout<<"Good";
	return 0;
}








Measured memory_bytes: 256
number = int(input())
lower = list(map(int, input().split()))

time = 0
max = 0

def down(i):
    global time
    for j in range(i, number-1):
        if lower[j] >= lower[j+1]:
            time += 1
        else:
            return j+1

    return 0

now = 0
for i in range(len(lower)):

    if now > i:
        continue

    if max > (number-i+1):
        break

    now = down(i)

    if max < time:
        max = time
    time = 0



print(max)


Measured memory_bytes: 14224
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10*5
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 main():
    n = INT()
    a = LIST()

    a1 = a[:2*n]
    a2 = a[n:]
    a2.reverse()
    for i in range(2*n):
        a2[i] = a2[i]*-1

    def searchmax(a):
        maxl = [0]*(n+1)
        left = a[:n]
        center = a[n:]
        heapq.heapify(left)
        maxl[0] = sum(left)
        for i in range(1,n+1):
            poped = heapq.heappushpop(left, center[i-1])
            maxl[i] = max(maxl[i-1], maxl[i-1]-poped+center[i-1])
        return maxl

    maxll = searchmax(a1)
    minrr = searchmax(a2)
    minrr.reverse()

    res = [INF *-1]*(n+1)
    for i in range(n+1):
        res[i] = maxll[i] + minrr[i]

    print(max(res)) 

if __name__ == '__main__':
    main()
    



Measured memory_bytes: 119788
#include <stdio.h>

int main(void)
{
    int r, c;
    int cell[101][101] = {};
    int i, j;
    scanf("%d %d", &r, &c);
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d", &cell[i][j]);
            cell[i][c] += cell[i][j];
            cell[r][j] += cell[i][j];
            cell[r][c] += cell[i][j];
        }
    }
    
    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            printf("%d", cell[i][j]);
            if(j==c){
                printf("\n");
            }
            else{
                printf(" ");
            }
        }
    }
        
    return 0; 
}
    

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

int main()
{
  int64_t N, negfst = 0, posfst = 0, plus = 0;
  cin >> N;
  vector<int64_t> A(N), S(N + 1, 0);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    S.at(i + 1) = S.at(i) + A.at(i);
  }
  // 1番目が正の場合
  for (int i = 1; i <= N; i++)
  {
    if (i % 2 == 1 && S.at(i) + plus <= 0) // 奇数番目が負の場合
    {
      posfst += abs(S.at(i) + plus) + 1; // 足して+1にする
      plus += abs(S.at(i) + plus) + 1;   // 足した分を加味する
    }
    else if (i % 2 == 0 && S.at(i) + plus >= 0)
    {
      posfst += abs(S.at(i) + plus) + 1; // 引いて-1にする
      plus -= abs(S.at(i) + plus) + 1;   // 引いた分を加味する
    }
  }
  // 1番目が負の場合
  plus = 0;
  for (int i = 1; i <= N; i++)
  {
    if (i % 2 == 1 && S.at(i) + plus >= 0) // 奇数番目が正の場合
    {
      negfst += abs(S.at(i) + plus) + 1;
      plus -= abs(S.at(i) + plus) + 1;
    }
    else if (i % 2 == 0 && S.at(i) + plus <= 0)
    {
      negfst += abs(S.at(i) + plus) + 1;
      plus += abs(S.at(i) + plus) + 1;
    }
  }
  cout << (posfst <= negfst ? posfst : negfst) << endl;
}

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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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

vi memo(100, 0);

int fib(int n)
{
    if(memo[n] != 0) return memo[n];
    return memo[n] = fib(n-1)+fib(n-2);
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, W; cin >> N >> W;
    vi v(N), w(N); REP(i, N) cin >> v[i] >> w[i];
    vvi dp(N+1, vi(W+1, 0));
    REP(i, N)
    {
        REP(j, W+1)
        {
            chmax(dp[i+1][j], dp[i][j]);
            if(j >= w[i]) chmax(dp[i+1][j], dp[i][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,a[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int t=1,ans=0;
    for(int i=2;i<=n;i++)
        if(a[i]==a[i-1]) t++;
    else ans+=t/2,t=1;
    ans+=t/2;
    printf("%d\n",ans);
}


Measured memory_bytes: 256
n, m = map(int, input().split())
l = [False] * n
res = [0] * n

ac = 0
wa = 0

for i in range(m):
    p,s = input().split()
    p = int(p)

    if(l[p-1]):
        continue
    
    if(s=="AC"):
        l[p-1] = True
        ac += 1
        wa += res[p-1]
        continue

    res[p-1] += 1


print(ac, wa)

Measured memory_bytes: 4596
import std;

auto input()
{
    return readln().chomp();
}

alias sread = () => readln.chomp();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long n, m;
    scan(n, m);
    auto ACしたか = new bool[](n + 1);
    // ACしたか[n] = false;
    // writeln(ACしたか);
    auto 何回WAしたか = new long[](n + 1);
    long ans1 = 0;
    long ans2 = 0;

    foreach (_; 0 .. m)
    {
        long p;
        string s;
        scan(p, s);
        // writeln(p, s);
        if ((ACしたか[p] == false) && (s == "WA"))
        {
            何回WAしたか[p] += 1;
        }
        if (s == "AC")
        {
            ACしたか[p] = true;
        }
    }
    foreach (i; 0 .. n + 1)
    {
        if (ACしたか[i] == true)
            ans1 += 何回WAしたか[i];
    }
    foreach (i; 0 .. n + 1)
    {
        if (ACしたか[i] == true)
        {
            ans2 += 1;
        }
    }
    writeln(ans2, ' ', ans1);

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


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

using namespace std;
typedef long long ll;
const int INF = (1<<30);

bool check[1000001];

int main(){
    char c;
    int cnt1=0,cnt2=0,cnt3=0;
    while(cin >> c){
        cnt1++;
        if(c=='S')cnt2++;
        if(c=='T'&&cnt2>=1){
            cnt2--;
            cnt3++;
        }
    }
    cout << cnt1 - cnt3*2 << endl;
    return 0;
}

Measured memory_bytes: 256