akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

const int INF = 1 << 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, L;
    cin >> N >> L;
    int aji = 0;
    for (int i = 1; i <= N; i++) {
        aji += L + i - 1;
    }
    int min_aji = INF;
    for (int i = 1; i <= N; i++) {
        int now_aji = 0;
        for (int j = 1; j <= N; j++) {
            if (i == j) continue;
            now_aji += L + j - 1;
        }
        if (abs(min_aji - aji) > abs(now_aji - aji)) {
            min_aji = now_aji;
        }
    }
    cout << min_aji << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    long long a[200005],i,n,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    a[0]=0;
    for(i=1;i<=n;i++)
    {
        if(a[i]-a[i-1]!=1)
        {
            s++;
            a[i]=a[i-1];
        }
    }
    if(s==n)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 5164
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
struct node
{
    int up,down,len;
};
vector<vector<int> >G;
vector<bool>vis;
stack<int>s;
node dfs(int root)
{
    vis[root]=true;
    for(int i=0;i<G[root].size();i++)
    {
        if(!vis[G[root][i]])
        {
            dfs(G[root][i]);
        }
    }
    s.push(root);
}
int main()
{
    int n,m,i,j,k;
    cin>>n>>m;
    G.resize(n+1);
    vis.resize(n+1);
    for(i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
    }
    for(i=1;i<=n;i++)
        if(!vis[i]) dfs(i);
    vector<int>topo(n);
    for(i=0;i<n;i++)
    {
        topo[i]=s.top();
        s.pop();
    }
    vector<int>dp(n+1);
    dp[topo[n-1]]=0;
    for(i=n-2;i>=0;i--)
    {
        int vert=topo[i];
        dp[vert]=0;
        for(j=0;j<G[vert].size();j++)
        {
            int child=G[vert][j];
            dp[vert]=max(dp[vert],1+dp[child]);
        }
    }
    int ans=0;
    for(i=1;i<=n;i++) ans=max(ans,dp[i]);
    cout<<ans;
}


Measured memory_bytes: 9552
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
L = [LIST() for i in range(M)]

graph = defaultdict(list)
# E = defaultdict(list)
rinsetsu = [[0] * N for i in range(N)]

for a, b in L:
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    rinsetsu[a-1][b-1] = 1
    rinsetsu[b-1][a-1] = 1

per = list(permutations([n for n in range(1, N)]))
# print(permu)
permu = []
for p_list in per:
    p_list = [0] + list(p_list)
    permu.append(p_list)

ans = 0

for p in permu:
    for i in range(N-1):
        # print(p[i], p[i+1])
        if rinsetsu[p[i]][p[i+1]] != 1:
            break
    else:
        ans += 1
print(ans)
    


Measured memory_bytes: 6376
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main()
{
    int N,T,A;
    cin >> N >> T >> A;
    
    
    double H[1000] = {};
    
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    
    for(int i=0;i<N;i++){
        H[i] = fabs(A-(T-H[i]*0.006));
        
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        if(H[ans]>H[i]){
            ans = i;
        }
    }
    cout << ans+1 << endl;
    return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  if(a==0){
    cout << b/x+1 << endl;
  }else{

    cout << b/x+1 - ((a-1)/x+1) << endl;

  }




  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n,x,count;
	
	while(1)
	{
		cin >> n >> x;
		if(n == 0 && x == 0) break;
		
		count = 0;
		
		for(int i = 1; i <= n-2; i++)
		{
			for(int j = i+1; j <= n-1; j++)
			{
				for(int k = j+1; k <= n; k++)
				{
					if(i+j+k == x) count++;
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

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

int main() {
    int N,K,ans=0;
    cin >> N >> K;
    vector<int>v(N);
    for (int i = 0; i < N; i++){
        cin >> v.at(i);
        if (v.at(i) >= K){
            ans++;
        }
    }
    cout << ans << endl;
}

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


int main(){
	int n;
	cin>>n;
	int adj[n+1][n-1], inds[n+1] ={0};
	for (int i=1;i<n+1;i++){
		for (int j=0;j<n-1;j++){
			cin>>adj[i][j];
		}
	}
	int c = (n*(n-1))/2, d = 0, fl = 0, val;
	while(c){
		d++;
		// cout<<"Day "<<d<<" :- \n";
		fl=0;
		int vis[n+1] = {0};
		for (int i=1;i<n+1;i++){
			if (!vis[i] && inds[i] < n-1){
				vis[i] = 1;
				val = adj[i][inds[i]];
				if (!vis[val] && inds[val] < n-1 && adj[val][inds[val]] == i){
					inds[i]++;
					inds[val]++;
					vis[val] = 1;
					c--;
					fl = 1;
					// cout<<"\t MAtch "<<i<<" - "<<val<<"\n";
				}
			}
		}
		if (!fl){
			break;
		}
		// d++;
	}
	if (!fl){
		cout<<"-1";
	}
	else
		cout<<d;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

struct CumulativeSum2D {
  vector<vector<int>> data;

  CumulativeSum2D(int w, int h) : data(w+1, vector<int>(h+1, 0)) {}

  void add(int x, int y, int z){
    //++x; ++y; // 0-indexedの場合
    if(x >= data.size() || y >= data[0].size()) return;
    data[x][y] += z;
  }

  void build() {
    for(int i = 1; i < data.size(); i++){
      for(int j = 1; j < data[i].size(); j++){
        data[i][j] += data[i][j-1] + data[i-1][j] - data[i-1][j-1];
      }
    }
  }

  int query(int sx, int sy, int gx, int gy){
    return data[gx][gy] - data[sx-1][gy] - data[gx][sy-1]  + data[sx-1][sy-1];
  }
};

int main(){
  int N,M,Q;
  cin >> N >> M >> Q;

  CumulativeSum2D cs = CumulativeSum2D(N,N);

  REP(i,M){
    int l,r;
    scanf("%d %d", &l,&r);

    cs.add(l,r,1);
  }
  cs.build();

  REP(i,Q){
    int p,q;
    scanf("%d %d", &p,&q);
    cout << cs.query(p,p,q,q) << endl;
  }
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1e9+7
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) cc.begin(), c.end()
#define mini(a, b, c) min(c, min(a, b))
//#define mini(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

int32_t main(){
    fast
    
    // Fuck Ratings, I'm in Love with Experience. 
    // Once a Charas, Always a CHARAS.
    
  //  int t=1;
    //cin>>t;
    //while(t--){



int n,c=0,i;
cin>>n;
int a[n];
for(i=0;i<n;i++){
    cin>>a[i];
    if(i%2==0){
        if(a[i]%2!=0)
        c++;
    }
}
      cout<<c;
  
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < m; i++){
    int x, y;
    cin >> x >> y;
    x--; y--;
    a[x]++; a[y]++;
  }
  for (int i = 0; i < n; i++){
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 3632
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
/*
	Problem: Biscuits
	Source: AtCoder Grand Contest 017 A
	Author: fts2001 (the_silliest)
 */
using namespace std;
int n,p,a[55];
long long dp[55][2];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>p;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int k=i;k>=0;k--){
            for(int j=0;j<2;j++){
                dp[k+1][(j+a[i])%2]+=dp[k][j];
            }
        }
    }
    long long ans=0;
    for(int i=0;i<=n;i++){
        ans+=dp[i][p];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
t = list(map(int, input().split()))

X = 0
Time = 0

for i in range(N):

    if Time <= t[i] :
        X += T

    else:
        X += t[i] - t[i-1]

    Time = t[i] + T

print(X)

Measured memory_bytes: 26708
from collections import deque

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

# n!通りの全探索?

"""
- 頂点起点で見る
     - 全パターン書き出す
- 辺起点で見る
"""
ans = deque([[1]])

while ans:
    a = ans.popleft()
    for i in range(2, N + 1):
        if i not in a:
            ans.append(a + [i])
    if len(ans[0]) == N:
        break

cnt = 0

for a in ans:
    tmp_cnt = 0
    for i in range(len(a) - 1):
        if [a[i], a[i + 1]] in AB or [a[i + 1], a[i]] in AB:
            tmp_cnt += 1
            continue
        else:
            break
    if tmp_cnt == len(a) - 1:
        cnt += 1

print(cnt)

Measured memory_bytes: 44140
l,r = map(int,input().split())
r = min(r, l+2019)
# ある数を2019で割った時の余りの最大値(2018)でminを初期化
min = 2018
for i in range(l,r):
  for j in range(i+1,r+1):
    value = (i*j)%2019
    if min > value:
      min = value
print(min)

Measured memory_bytes: 3060
//In the name of allah// Bismillahir rahmanir rahim 
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a;
cin>>a;
if('A'<=a && a<='Z')
cout<<"A"<<endl;
else if ('a'<=a && a<='z')
cout<<"a"<<endl;

return 0;
}

Measured memory_bytes: 3592
import java.io.*;
import java.util.*;
import java.util.stream.*;
import java.math.*;
 
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int k = Integer.parseInt(sc.nextLine());
        int x = Integer.parseInt(sc.nextLine());
        int y = Integer.parseInt(sc.nextLine());
        
        int res=k*x + (n-k)*y;
        if(n<k){
            res=n*x;
        }
        

        System.out.println(res);
    }
}




Measured memory_bytes: 21844
#include <stdio.h>

#define N 8

int col[N],row[N],dpos[2*N],dneg[2*N],m[N][N];

void pri(void){
  
  int i,j;
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(m[i][j]==1 && row[i]!=j)return;
    }
  }
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }

}

void queen(int i){

  int j,k;

  if(i==N){
    pri();
    return;
  }
  /*
  for(k=0;k<N;k++){
    for(j=0;j<N;j++){
      if(m[k][j]==1)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
  printf("\n");

  */
  
  for(j=0;j<N;j++){
    //  printf("i:%d row:%d col:%d pos:%d neg:%d\n",i,row[i],col[j],dpos[i+j],dneg[i-j+N-1]);
    if(col[j]==1 || dpos[i+j]==1 || dneg[i-j+N-1]==1)continue; 

    row[i]=j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = 1;
    queen(i+1);
    row[i]=col[j] = dpos[i+j] = dneg[i-j+N-1] = 0;
    
  }
 
}


int main(){

  int n,i,j,r,c;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    m[r][c]=1;
  }
  /*
    for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    m[r][c]=1;
    row[r] = c;
    col[c]= dpos[r+c] = dneg[r-c+N-1] = 1;
    }
  */

  
  queen(0);
  
 
  return 0;
}



Measured memory_bytes: 2112
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
H = LI()
pre = H[0]
for i in range(N):
    if pre < H[i]:
        pre = H[i] - 1
    elif pre > H[i]:
        print("No")
        exit()
print("Yes")


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

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

  int minv = a.at(0);
  int ans  = -2000000000;
  for (int i = 1; i < n; i ++) {
    ans  = max(ans, a.at(i) - minv);
    minv = min(minv, a.at(i));
  }

  cout << ans << endl;
}



Measured memory_bytes: 3540
#include<stdio.h>
#include<string.h>

int max(int a, int b, int c) {
	if (a >= b && a >= c)return a;
	else if (b > a&&b >= c)return b;
	else return c;
}

int mid(int a, int b, int c) {
	if (a >= b && a >= c) {
		if (b >= c)return b;
		else return c;
	}
	else if (b > a&&b >= c) {
		if (a >= c)return a;
		else return c;
	}
	else {
		if (a >= b)return a;
		else return b;
	}
}

int min(int a, int b, int c) {
	if (a <= b && a <= c)return a;
	else if (b < a&&b <= c)return b;
	else return c;
}


int main() {
	int a, b, c;
	int max1, mid1, min1;
	int out[4] = { 0,0,0,0 };
	while (1) {
		scanf("%d %d %d", &a, &b, &c);
		max1 = max(a, b, c);
		mid1 = mid(a, b, c);
		min1 = min(a, b, c);
		if (max1 >= mid1 + min1) {
			break;
		}
		out[0] += 1;
		if (max1*max1 == mid1 * mid1 + min1 * min1) {
			out[1] += 1;
		}
		else if (max1*max1 < mid1*mid1 + min1 * min1) {
			out[2] += 1;
		}
		else out[3] += 1;
	}
	printf("%d %d %d %d\n", out[0], out[1], out[2], out[3]);

	return 0;
}


Measured memory_bytes: 2724
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int ta, tb, W; cin >> W >> ta >> tb;
	int a = min(ta, tb), b = max(ta, tb);
	cout << max(0, (b - a - W)) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int k = scan.nextInt();
		int p[] = new int[n];
		
		for(int i=0;i<n;i++) {
			p[i] = scan.nextInt();
		}
		
		Arrays.sort(p);
		
		int ans = 0;
		
		for(int i=0;i<k;i++) {
			ans += p[i];
		}
		
		System.out.println(ans);
	}
}
 


Measured memory_bytes: 38948
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


int main() {
	ll A, B, C;
	cin >> A >> B >> C;
	if (A == B)cout << C;
	if (A == C)cout << B;
	if (C == B)cout << A;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import math

while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(int,input().split()))
    
    sum = 0
    for i in range(len(s)):
        sum += s[i]
    m = sum/len(s)
    
    a = 0
    for i in range(len(s)):
        a += s[i]*s[i]
    a = a/len(s)
    
    print("{0:.8f}".format(math.sqrt(a-m*m)))


Measured memory_bytes: 5696
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define f first
#define s second
using namespace std;

//
int main(){
    int n, m;scanf("%d%d", &n, &m);
    int flecha[n + 1] = {0};
    vector<int> unidos[100005];
    int a,b;
    for(int i = 0; i < m; i++){
        scanf("%d%d", &a, &b);
        unidos[a].pb(b); unidos[b].pb(a);
    }
    int cnt = 1; flecha[1] = 1000;
    queue<int> fase; fase.push(1);
    while(fase.size()){
        int room = fase.front();
        fase.pop();
        for(int j = 0; j < unidos[room].size(); j++){
            if(flecha[unidos[room][j]] == 0){
                flecha[unidos[room][j]] = room;
                fase.push(unidos[room][j]);
                cnt++;
            }
        }   
    }
    if(cnt >= n){
        printf("Yes\n");
        for(int i = 2; i < n + 1; i++){
            printf("%d\n", flecha[i]);
        }
    }
    else printf("No\n"); 
}


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

int main(){
  int N,a[110];
  cin>>N;
  for(int t=0;t<N;t++){
    cin>>a[t];
  }

  int cont=0;
  for(int t=0;t<N-1;t++){
    if(a[t]==a[t+1]){
      a[t+1]=-1;
      cont++;
    }
  }

  cout<<cont<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  string s;
  int n, k;
  
  cin >> n >> s >> k;
  
  for (int x = 0; x<n; x++)
  {
    if (s[x] != s[k-1]) s[x] = '*';
  }
  
  cout << s;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n,a,b;
	int t[1002];
	scanf("%d%d%d",&n,&a,&b);
	rep(i,n)scanf("%d",&t[i]);
	
	int ret = 0;
	rep(i,n){
		if(t[i] < a || b <= t[i])ret ++;
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
/*Templates are for weak. -invictus_123*/
#include <bits/stdc++.h>
using namespace std;
int main() {
 	string s, t;
 	cin >> s >> t;
 	int r = s.length() + 1, c = t.length() + 1;
 	vector <vector <int>> dp(r, vector <int> (c, 0));
 	for(int i = 1; i < r; i ++) {
 		for(int j = 1; j < c; j ++) {
 			if(s[i - 1] == t[j - 1]) {
 				dp[i][j] = dp[i - 1][j - 1] + 1;
 			}	
 			else {
 				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
 			}
 		}
 	}
 	r --;
 	c --;
 	string ans;
 	int idx = 0;
 	while(r > 0 && c > 0) {
 		if(dp[r][c] == dp[r - 1][c]) {
 			r --;
 		}
 		else if(dp[r][c] == dp[r][c - 1]) {
 			c --;
 		}
 		else {
 			ans[idx ++] = s[r - 1];
 			r --;
 			c --;
 		}
 	}
 	for(int i = idx - 1; i >= 0; i --) {
 		cout << ans[i];
 	}
    return 0;
}

Measured memory_bytes: 35584
import sys

def main():
    N = int(input())

    B = list(map(int, input().split()))


    A = []
    A.append(B[0])

    for x in range(N-2):
        A.append(min(B[x],B[x+1]))

    A.append(B[N-2])

    print(sum(A))

main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200000+5];
int b[200000+5];


int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(&a[1],&a[1+n]);


    int k=n/2,q,p;
    for(i=1; i<=n; i++)
    {
        if(b[i]<=a[k])
            printf("%d\n",a[k+1]);
        else

            printf("%d\n",a[k]);


    }
}


Measured memory_bytes: 3712
N = int(input())
A = list(map(int, input().split()))

def abs_quiz(A):
    B = [a-i-1 for i, a in enumerate(A)]
    B.sort()
    ans = sum([abs(b - B[N//2]) for b in B])
    return ans

ans = abs_quiz(A)
print(ans)

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

int main()
{
	string A;
	cin >> A;
	ll ans = A.size() * (A.size() - 1) / 2;
	char c = 'a';
	rep(i,26)
	{
		ll cnt = 0;
		rep(j,A.size())
		{
			if (A[j] == c) cnt++;
		}
		if (cnt != 0) ans -= cnt * (cnt - 1) / 2;
		c++;
	}
	ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		// 計算
		int result = k;
		for(int i = 1; i < n; i++){
		    result *= k-1;
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

ll solve(ll h, ll w){
    ll ans = 1e15;
    ll num;
    if(h%2==0){
        FOR(k,1,w){
            num = max(h*k,(h/2)*(w-k)) - min(h*k,(h/2)*(w-k));
            ans = min(ans, num);
        }
    }else{
        FOR(k,1,w){
            num = max({h*k,(h/2)*(w-k), (h/2+1)*(w-k)}) 
                - min({h*k,(h/2)*(w-k), (h/2+1)*(w-k)});
            ans = min(ans, num);
        }
    }
    return ans;
}

int main() {
    ll H,W; cin >> H >> W;
    if(H%3==0 || W%3==0) cout << 0 << endl;
    else{
        cout << min({solve(H,W), solve(W,H), H, W}) << endl;
    }
    return 0;
}

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

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

inline int Pow(int a, int k) {
  int s = 1; 
  for(; k; k >>= 1) {
    k & 1 ? s = 1LL * s * a % MOD : 0;
    a = 1LL * a * a % MOD;
  }
  return s;
}

// Init variables here
const int N = 1e6 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);
}

void preprocess() {
}

void debug() {
  //  44gg
  if (true) {
  
  }
}


void solve() {
  preprocess();
  // 50gg
  int n, k;
  string s;
  cin >> n >> k >> s;
  char cur = '1';
  vec<int> v;
  int cnt = 0;
  FOR(i, 0, n) {
    if (s[i] != cur) {
      v.push_back(cnt);
      cnt = 1;
      cur = (cur == '1' ? '0' : '1');
    } else {
      cnt++;
    }
  }
  v.push_back(cnt);
  if (s.back() != '1') {v.push_back(0);}
  int m = v.size();
  //cerr << "m = " << m << endl;
  //FOR(i, 0, m) {cerr << v[i] << ' ';}
  //cerr << endl;
  int g = min(k + k + 1, m);
  //cerr << "g = " << g << endl;
  int sum[m + 1];
  sum[0] = 0;
  FOR(i, 0, m) {
    sum[i + 1] = sum[i] + v[i];
  }
  int res = 0;
  for (int i = g; i <= m; i += 2) {
    res = max(res, sum[i] - sum[i - g]);
  }
  cout << res << endl;
  //debug();
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

void output() {

}

#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--) 
  {
    input();
    solve();
    output();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
typedef long long ll;

int main(){
    fast_io();
    ll N; cin >> N;
    ll sum = 0;
    for(long long i = 1; i <= 1e6; i++){
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
        if(i == N) break;
    }
    cout << sum;
    return 0;
}


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

void main()
{
    auto N = readln.chomp.to!int;
    auto A = new long[][](N, N);
    foreach (i; 0..N) {
        foreach (j, a; readln.split.to!(long[])) {
            A[i][j] = a;
        }
    }

    foreach (k; 0..N) {
        foreach (i; 0..N) {
            foreach (j; 0..N) {
                if (A[i][j] > A[i][k] + A[k][j]) {
                    writeln("-1");
                    return;
                }
            }
        }
    }

    long r;
    foreach (i; 0..N) {
        foreach (j; 0..N) {
            foreach (k; 0..N) {
                if (k != i && k != j && A[i][j] == A[i][k] + A[k][j]) goto ng;
            }
            r += A[i][j];
            ng:
        }
    }
    writeln(r/2);
}

Measured memory_bytes: 5116
#include<iostream>
using namespace std;
int main() {
  int A,B;
  cin >> A;
  cin >> B;
  if(A+B == 3) {
    cout << 3 << endl;
  }else if(A+B == 4){
    cout << 2 << endl;
  }else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
while 1:
	n=input()
	if n==0:break
	p=[0]*n
	l=[[0]*31 for i in range(n)]
	a=sorted([raw_input().split() for i in range(n)])
	for j in range(n):
		for t in a[j][2:]:
			l[j][int(t)]=1
	for t in range(30):
		c=0
		for j in range(n):
			if l[j][t]:
				c+=1
		for j in range(n):
			if l[j][t]:
				p[j]+=n-c+1
	print min(p),a[p.index(min(p))][0]

Measured memory_bytes: 4248
main :: IO ()
main = do
  [x, y] <- (map convert . words) <$> getLine
  putStrLn $ if x < y then "<" else if x > y then ">" else "="

convert :: String -> Int
convert s =
  case s of
    "A" -> 10
    "B" -> 11
    "C" -> 12
    "D" -> 13
    "E" -> 14
    "F" -> 15


Measured memory_bytes: 380
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import collections
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    print((n-1)*n//2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

cnt, ans = 0, 0
candidates = []
for reversed_day in range(1, m + 1):
  while cnt < len(conditions) and conditions[cnt][0] <= reversed_day:
    heapq.heappush(candidates, -conditions[cnt][1])
    cnt += 1

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

print(ans)

Measured memory_bytes: 26468
#include <stdio.h>
 
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
 
typedef struct{
  short x,y;
  int cost;
  short ch;
}mouse;
const int MAX=(1<<14)-1;
mouse que[(1<<14)-1];
int s,num;
 
mouse t;
short cx,cy,nx,ny,ch,nch,h,w,n;
int cost;
 
main(){
  scanf("%d%d%d ",&h,&w,&n);
  short maxch[h][w];
  char ku[h][w];
  int i,j;
  
  for(i=0;i<h;i++)fread(ku[i],1,w+1,stdin);
 
 
  for(i=0;i<h;i++)for(j=0;j<w;j++){
    if(ku[i][j]=='S')cx=i,cy=j;
    maxch[i][j]=-1;
  }
 
 
  que[s+num++]=(mouse){cx,cy,0,0};
  maxch[cx][cy]=0;
 
  while(1){
    t=que[s++&MAX];
    num--;
    cx=t.x,cy=t.y,cost=t.cost;
    ch=t.ch;
 
    for(i=0;i<4;i++){
      nx=cx+dx[i],ny=cy+dy[i];
      if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
      if(ku[nx][ny]=='X')continue;
      nch=ch;
      if(ku[nx][ny]<='9' && ku[nx][ny]>='1' && ku[nx][ny]-'0'==t.ch+1){
        nch=ch+1;
      }
 
      if(maxch[nx][ny]>=nch)continue;
      if(nch==n){
        printf("%d\n",cost+1);
        return 0;
      }
      maxch[nx][ny]=nch;
      que[s+num++&MAX]=(mouse){nx,ny,cost+1,nch};
    }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int num[1000005];
int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    memset(num, 0, sizeof(num));
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= m; j++)
        {
            num[m*i-j*i+(n-i)*j] = 1;
//            cout << m*i-j*i+(n-i)*j << ' ';
        }
//        cout << endl;
    }
    if(num[k] == 1)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

typedef unsigned long long int uint64;
typedef long long int          int64;

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))


void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

int main()
{
  int cnt;
  int i;
  int64 r;

  get_N(&r);

  printf("%lld", (3*r*r));

  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll l,r;cin >> l >> r;
	if(r-l>=10000){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 2019;
	for(ll i=l;i<r;++i){
		for(ll j=i+1;j<=r;++j){
			ans = min(ans,i*j%2019);
		}
	}
	cout << ans << endl;
}


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

int main() {
    vector<int> X(5);
    for(int i = 0; i < 5; i++) {
        cin >> X[i];
    }
    for(int i = 0; i < 5; i++) {
        if(X[i] == 0) {
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
s = input();

if len(s) % 2 == 0:
  harf = int(len(s) / 2 - 1) + 1;
else:
  harf = int((len(s) - 1) / 2);

count = 0;
for i in range(harf):
    if s[i] != s[::-1][i]:
        count += 1;
    
print(count);

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    r = ii()
    print(r * r)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int n,a[100001],x,ans;//数组如果开到10亿，就超空间了
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x>n) ans++;//大于n的x删除，计数器加一
        else a[x]++;//不大于n的x的桶加一，计量x出现的次数
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0) continue;//桶为0，表示i从未出现
        if(a[i]<i) ans+=a[i];//i不超过装它的桶，全部删除
        else if(a[i]>i) ans+=a[i]-i;//i超过装它的桶，删除超过的部分
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
count = {}
S1 = list(input())
for s in S1:
  if s in count.keys():
    count[s] += 1
  else:
    count[s] = 1
for i in range(n-1):
  S = list(input())
  count1 = {}
  for s in S:
    if s in count1.keys():
      count1[s] += 1
    else:
      count1[s] = 1
  for k,v in count.items():
    if k in count1.keys():
      count[k] = min(v,count1[k])
    else:
      count[k] = 0
items = sorted(count.items())
ans = ""
for i in range(len(items)):
  ans += items[i][0]*items[i][1]
print(ans)

Measured memory_bytes: 3064
X = int(input())

number = X
flag = 0

if number == 2:
  	print(number)
elif number%2 == 0:
    number += 1
else:
    pass
  
if number != 2:
    while(True):
        for i in range(2, number):
            if number%i == 0:
                number += 2
                break

            elif i == (number-1):
                flag = 1
                print(number)
                break

            else:
                pass

        if flag == 1:
            break

else:
  pass

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

long long EulerTotientFunction(long long n){
    long long ret = n;
    for(long long i=2;i*i<=n;i++){
        if(n%i==0)ret = ret/i*(i-1);
        while(n%i==0) n/=i;
    }
    if(n>1)ret = ret/n*(n-1);
    return ret;
}

int main(){
    
    ll n; cin>>n;
    cout<<EulerTotientFunction(n)<<endl;
    
    return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		boolean submited[] = new boolean[30];
		for (int i = 0; i < 28; i++)
		{
			submited[sc.nextInt() - 1] = true;
		}
		for (int i = 0; i < 30; i++)
		{
			if (!submited[i])System.out.println(i+1);
		}
	}
}

Measured memory_bytes: 12000
import math
N,L=map(int,input().split())
T=[int(input()) for i in range(N)]
X=0
Y=0
for i in range(N):
    for j in range(i+1,N):
        angle=math.pi*(T[j]+T[i])/L
        #print(math.cos(angle),math.sin(angle))
        X+=math.cos(angle)*(N-2-(j-i-1)*2)
        Y+=math.sin(angle)*(N-2-(j-i-1)*2)
A=(N*(N-1)*(N-2))//6
print(X/A,Y/A)


Measured memory_bytes: 44264
#include<bits/stdc++.h>
 
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
using namespace std;
 
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
char a[N],b[N];
int F[N],f[N][33];
int vis[33];
int main(){
	ios::sync_with_stdio(false);
	cin>>a+1>>b+1;
	int L=strlen(a+1),R=strlen(b+1);
	for(int i=0;i<26;i++)f[L+1][i]=-1;
	for(int i=1;i<=L;i++)if(!F[a[i]-'a'])F[a[i]-'a']=i;
	for(int i=L;i>=1;i--){
		vis[a[i]-'a']=1;
		for(int j=0;j<26;j++){
			f[i][j]=f[i+1][j];
		}
		f[i][a[i]-'a']=i;
	}
	int now=0;
	LL ans=0;
	for(int i=1;i<=R;i++){
		if(!vis[b[i]-'a'])return cout<<-1,0;
		if(f[now+1][b[i]-'a']!=-1){
			ans+=f[now+1][b[i]-'a']-now;
			now=f[now+1][b[i]-'a'];
		}else{
			ans+=L-now;
			ans+=F[b[i]-'a'];
			now=F[b[i]-'a'];
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<ll, ll> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

struct P {
    int a, b, c;
    bool operator<(const P &rhs) const { return a - b < rhs.a - rhs.b; }
    bool operator>(const P &rhs) const { return a - b > rhs.a - rhs.b; }
};

int main()
{
    ios::sync_with_stdio(false);

    int X, Y, Z, N;
    cin >> X >> Y >> Z;
    N = X + Y + Z;

    vector<P> PS(N);
    rep(i, N) cin >> PS[i].a >> PS[i].b >> PS[i].c;

    sort(PS.begin(), PS.end(), greater<P>());

    priority_queue<PII, vector<PII>, greater<PII>> queue_gold, queue_silver;

    vector<PII> ans_gold(N+1), ans_silver(N+1);
    rep(i, X) {
        ans_gold[i+1].first = ans_gold[i].first + PS[i].a;
        queue_gold.emplace(PS[i].a - PS[i].c, i);
    }

    for (int i=X; i<N; i++) {
        queue_gold.emplace(PS[i].a - PS[i].c, i);
        PII remove = queue_gold.top(); queue_gold.pop();

        ans_gold[i+1].first  = ans_gold[i].first + PS[i].a - PS[remove.second].a;
        ans_gold[i+1].second = ans_gold[i].second + PS[remove.second].c;
    }

    reverse(PS.begin(), PS.end());

    rep(i, Y) {
        ans_silver[i+1].first = ans_silver[i].first + PS[i].b;
        queue_silver.emplace(PS[i].b - PS[i].c, i);
    }

    for (int i=Y; i<N; i++) {
        queue_silver.emplace(PS[i].b - PS[i].c, i);
        PII remove = queue_silver.top(); queue_silver.pop();

        ans_silver[i+1].first  = ans_silver[i].first + PS[i].b - PS[remove.second].b;
        ans_silver[i+1].second = ans_silver[i].second + PS[remove.second].c;
    }

    ll ans = 0;
    for (int i=X; i<=X+Z; i++) {
        ll tmp = ans_gold[i].first + ans_gold[i].second + ans_silver[N-i].first + ans_silver[N-i].second;

        // DUMP(i);
        // cerr << ans_gold[i].first << ", " << ans_gold[i].second << endl;
        // cerr << ans_silver[N-i].first << ", " << ans_silver[N-i].second << endl;
    
        ans = max(ans, tmp);
    }

    cout << ans << endl;
}

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

bool check(int t, int x0, int y0, int x1, int y1) {
  int d = abs(x0 - x1) + abs(y0 - y1);
  if ((d > t) || abs(d - t) % 2 == 1) {
    return false;
  }
  return true;
}

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

  int t[N], x[N], y[N];
  for (int i = 0; i < N; ++i) {
    cin >> t[i] >> x[i] >> y[i];
  }

  int t0 = 0;
  int x0 = 0;
  int y0 = 0;
  bool fail = false;
  for (int i = 0; i < N; ++i) {
    if (!check(t[i] - t0, x0, y0, x[i], y[i])) {
      fail = true;
      break;
    }
    t0 = t[i];
    x0 = x[i];
    y0 = y[i];
  }

  if (fail) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long int
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const ll maxn=1e18;
int main()
{
    int n;
    cin>>n;
    ll A[n];
    bool zero,over;
    zero=over=false;
    rep(i,n)
    {
        cin>>A[i];
        if(A[i]==0)
        {
            zero=true;
            break;
        }
    }
    if(zero)
    {
        cout<<0<<endl;
        return 0;
    }
    ll p=1;
    rep(i,n)
    {
        if(A[i]>maxn/p)
        {
            over=true;
            break;
        }
         p*=A[i];
    }
    if(over)
        cout<<-1<<endl;
    else
        cout<<p<<endl;
    return 0;
}


Measured memory_bytes: 4404
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

char s[4];
int a[4];
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		nextstr(s);
		int k=0;
		switch(s[0]){
			case 'R': k++;
			case 'T': k++;
			case 'W': k++;
		}
		a[k]++;
	}
	printf("AC x %d\n", a[0]);
	printf("WA x %d\n", a[1]);
	printf("TLE x %d\n", a[2]);
	printf("RE x %d\n", a[3]);
}


Measured memory_bytes: 1568
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    a, b = sl()
    if a == 'H':
        print(b)
    elif b == 'H':
        print('D')
    else:
        print('H')


if __name__ == '__main__':
    main()


Measured memory_bytes: 10020
#include <bits/stdc++.h>
using namespace std;
int arr_wield[100001],arr_throw[100001];
bool mycompare(const int & a,const int & b)
{
	return a>b;
}
int main()
{
	int N,H,i,count=0,ans=0,pos_t=0;
	scanf("%d %d",&N,&H);
	for(i=0;i<N;i++)
	{
		scanf("%d %d",&arr_wield[i],&arr_throw[i]);
	}
	sort(arr_wield,arr_wield+N,mycompare);
	sort(arr_throw,arr_throw+N,mycompare);
	while(H>0)
	{
		if(arr_throw[pos_t]>arr_wield[0])
		{
			H-=arr_throw[pos_t++];
			ans++;
		}
		else
		{
			ans+=H/arr_wield[0];
			ans+=H%arr_wield[0]==0?0:1;	
		    break;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll A,B;
    cin >> A >> B;
    ll D;
    D = __gcd(A, B);
    ll count = 1;
    for(ll i = 2; D >= i * i; i++){
        if(D%i  == 0){
            count++;
            while(D%i == 0){
                D = D/i;
            }
        }
    }
    if(D != 1) count++;
    printf("%lld\n", count);
}

Measured memory_bytes: 256
function main(_stdin) {
    const stdin = _stdin.split('\n');
    const len = Number(stdin.shift());
    const arr = stdin.shift().split(' ').filter(e => e.length).map(Number);

    let count = 0;

    for (let maxSortedIndex = 0, l = arr.length; maxSortedIndex < l; maxSortedIndex++) {
        let minNumIndex = maxSortedIndex;
        for (let j = maxSortedIndex, l = arr.length; j < l; j++) {
            if (arr[j] < arr[minNumIndex]) {
                minNumIndex = j;
            }
        }
        if (maxSortedIndex !== minNumIndex) {
            let temp = arr[maxSortedIndex];
            arr[maxSortedIndex] = arr[minNumIndex];
            arr[minNumIndex] = temp;
            count++;
        }
    }

    console.log(arr.join(' '));
    console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));






Measured memory_bytes: 15392