akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ff first
#define ss second
#define M 1000000007
#define mp(a, b) make_pair(a, b)
#define pb push_back


using namespace std;

int main() {

//    ifstream cin("input.in");
//    ofstream cout("output.out");
//    cin.tie(0);

    int n, h[100009], m[100009], i;
    cin>>n;
    for(i=0;i<n; i++)   cin>>h[i];
    m[1]=0;
    m[2]=abs(h[1]-h[0]);

    for(i=3; i<=n; i++) {
        m[i]=min(m[i-2]+abs(h[i-1]-h[i-3]), m[i-1]+abs(h[i-1]-h[i-2]));
    }

    cout<<m[n];

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

#define W 1
#define G 2
#define B 3
#define NIL -1
#define MaxWeight 2001
#define N 1000

int main(){

  int n, i, j, k, l, min, sum = 0;
  int g[N][N], c[N], d[N];

  scanf("%d", &n);

  for( i = 1; i <= n; i++){
    c[i] = W;
    d[i] = N;
    for( j = 1; j <= n; j++){

      scanf("%d", &g[i][j]);
  
    }
  }
  d[1] = 0;

  for( i = 1; i < n; i++){

    min = N;

    for( j = 1; j <= n; j++){

      if( d[j] < min && c[j] == W){
	min = d[j];
	k = j;
      }

    }

    c[k] = B;
  
    for( l = 1; l <= n; l++){

      if(g[k][l] < d[l] && g[k][l] != NIL && c[l] == W){
	d[l] = g[k][l];
      }

    }
  }

  for( i = 1; i <= n; i++){

    sum += d[i];

  }

  printf("%d\n", sum);

  return 0;

}

Measured memory_bytes: 1000
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<ll> A;
  ll ret = 0;
  ll ret_sub = 0;
  ll start = 0;
  ll end = 0;
  bool ok = true;
  for(int i=0; i<N; i++){
    ll in;
    cin >> in;
    A.push_back(in);
    ret += in;

    if((i == 0 && in != 0) ||
       (i != 0 && A[i-1] + 1 < in))
      ok = false;

    if(ok){
      if(in == end + 1){
        end = in;
      } else {
        ret_sub += (start + end - 1) * (end - start) / 2;
        start = end = in;
      }

      if(i == N-1){
        ret_sub += (start + end - 1) * (end - start) / 2;
        start = end = in;
      }
    }
  }

  if(ok)
    cout << ret - ret_sub << endl;
  else
    cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3444
/*************************************************************************
    > File Name: D.cpp
    > Author: PumpkinYing
    > Created Time: 2018/11/9 15:51:37
 ************************************************************************/

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define prii pair<int,int>
#define prdd pair<double,double>
#define rep(i,l,r) for(int i = l;i < r;i++)
#define rep_(i,l,r) for(int i = l;i <= r;i++)
typedef long long ll;

const int maxn = 1000010;
map<ll,int> mp;
int sz[maxn];

struct Node {
	ll d;
	int id;
	void read(int i) {
		id = i;
		scanf("%lld",&d);
	}
	bool operator < (const Node& b) const {
		return d > b.d;
	}
}ns[maxn];

int fa[maxn],vis[maxn];

int main() {
	int n;
	scanf("%d",&n);
	rep_(i,1,n) {
		ns[i].read(i);
		mp[ns[i].d] = i;
		sz[i] = 1;
	}
	sort(ns+1,ns+1+n);
	int ok = 1;
	ll tot = 0;
	rep_(i,1,n-1) {
		int id = ns[i].id;
		vis[id] = 1;
		ll val = ns[i].d+sz[id]-(n-sz[id]);
		if(mp[val] == 0 || vis[mp[val]]) {
			ok = 0;
			break;
		}
		else {
			fa[id] = mp[val];
			sz[mp[val]] += sz[id];
			tot += sz[id];
		}
	}
	int root;
	rep_(i,1,n) if(fa[ns[i].id] == 0) root = i;
	if(ok == 0 || ns[root].d != tot) printf("-1\n");
	else rep_(i,1,n) if(fa[i] != 0) printf("%d %d\n",i,fa[i]);
    return 0;
}


Measured memory_bytes: 18304
//q5.cpp

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;

using namespace std;

long long h,w,ans,flag=0;
char m[1020][1020];
int md[1020][1020];
bool mc[1020][1020];
queue<pair<int,int> > s,s1,che;
pair<int,int> p;

int check(int y,int x){
    int c=0;
    
    for(int i=-1;i<=1;i++)
        for(int j=-1;j<=1;j++)
            if(m[y+i][x+j]=='.') c++;
    
    if((int)(m[y][x]-'0')<=c &&  !mc[y][x]){
        mc[y][x]=true;
        che.push(make_pair(y,x));
        s1.push(make_pair(y,x));
        return 1;
    }
    
    return 0;
}

int main(){
    scanf("%lld%lld",&h,&w);
    
    for(int i=0;i<h;i++)
        scanf("%s",m[i]);
    
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            if(m[i][j]=='.')
                md[i][j]=0;
            else
                md[i][j]=m[i][j]-'0';
    
    
    //1
    flag=0;
    
    for(int i=1;i<h-1;i++)
        for(int j=1;j<w-1;j++)
            if(m[i][j]!='.') flag+=check(i,j);
    
    while(!che.empty()){
        p=che.front();
        che.pop();
        m[p.first][p.second]='.';
    }
    
    
    if(flag)
        ans++;
    else{
        puts("0");
        return 0;
    }
    
    //2-
    do{
        s=s1;
        
        while(!s1.empty())
            s1.pop();
        
        flag=0;
        
        for(int i=0;!s.empty();i++){
            p=s.front();
            s.pop();
            
            for(int j=-1;j<=1;j++)
                for(int k=-1;k<=1;k++)
                    if(m[p.first+j][p.second+k]!='.' && !mc[p.first+j][p.second+k]) flag+=check(p.first+j,p.second+k);
            
        }
        
        while(!che.empty()){
            p=che.front();
            che.pop();
            m[p.first][p.second]='.';
        }
        
        if(flag) ans++;
        
        
    }while(flag);
    
    printf("%lld\n",ans);
    
    return 0;
}

Measured memory_bytes: 7220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), ans(n);
    rep(i,n) cin >> a[i];
    rep(i,n) ans[a[i]-1] = i;
    rep(i,n) {
        if (i) cout << " ";
        cout << ans[i]+1;
    }
    cout << endl;
}

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

#define ll long long
#define N (ll)(4*1e6)
#define EPS (double)(1e-12)
#define M (ll)(1e9+7)

using namespace std;

const ll maxN = 1e5+1;

vector<ll> adj[maxN];

void addEdge(ll u, ll v) {
    adj[u].push_back(v);
}
ll mat[maxN][4];

ll bfs(ll s, ll t) {
    queue<pair<ll, ll>> fila;

    // node / distance
    fila.push({s, 0});

    while(!fila.empty()) {
        int no = fila.front().first;
        int dist = fila.front().second;

        fila.pop();

        if(mat[no][dist%3])
            continue;
        mat[no][dist%3] = true;

        if(no == t && dist%3 == 0)
            return dist/3;
        
        for(auto a : adj[no])
            fila.push({a, dist+1});
    }
    return -1;
}

int main() {
    // 189 algorithm design manual
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n, m, s, t, u, v;

    cin >> n >> m;

    for(ll i = 0; i < m; i++) {
        cin >> u >> v;
        addEdge(u, v);
    }
    cin >> s >> t;

    cout << bfs(s, t) << endl;


    return 0;
}

Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {

    public static void main (String [] args){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char [][] board = new char[H][W];

        for(int i=0;i<H;i++){
            String tmp = sc.next();
            for(int j=0;j<W;j++){
                board[i][j] = tmp.charAt(j);
            }
        }
        int [] dx ={1,1,0,-1,-1,-1,0,1};
        int [] dy ={0,1,1,1,0,-1,-1,-1};
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(board[i][j] =='#'){
                    System.out.print("#");
                }else{
                    int sum =0;
                    for(int k=0;k<8;k++){
                        int x = j+dx[k];
                        int y = i+dy[k];
                        if(0>x || x>W-1){
                            continue;
                        }
                        if(0>y || y>H-1){
                            continue;
                        }
                        if(board[y][x]=='#'){
                            sum++;
                        }
                    }
                    System.out.print(sum);
                }
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

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

    cout << n-i+1 << endl;
}

Measured memory_bytes: 256
from itertools import accumulate

L, N, *X = map(int, open(0).read().split())

Y = [L - x for x in reversed(X)]

Sx = [0] + list(accumulate(X))
Sy = [0] + list(accumulate(Y))

ans = 0
for i in range(N):
    j = N - i - 1
    mi = min(i, j)

    x = X[i] + 2 * (Sx[i] - Sx[i - mi]) + 2 * (Sy[j] - Sy[j - mi - int(i < j)])
    y = Y[j] + 2 * (Sx[i] - Sx[i - mi - int(i > j)]) + 2 * (Sy[j] - Sy[j - mi])
    ans = max(ans, x, y)

print(ans)

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

char judge(int pm, int pe, int pj)
{
    if(pm == 100 || pe == 100 || pj == 100 || pm + pe >= 180 || pm + pe + pj >= 240) return 'A';
    else if(pm + pe + pj >= 210 || pm + pe + pj >= 150 && (pm >= 80 || pe >= 80)) return 'B';
    return 'C';
}

int main()
{
    int n, pm, pe, pj;
    while(cin >> n, n){
        for(int i = 0; i < n; ++i){
            cin >> pm >> pe >> pj;
            cout << judge(pm,pe,pj) << endl;
        }
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
const int iINF=1e9;
int main(){
    int a,b,c,d;
    string s;
    cin>>a>>s;
    if(a>=3200)cout<<s<<endl;
    else cout<<"red"<<endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc082/tasks/abc082_b
# Ruby 2nd Try
yes = "Yes"
no = "No"
s = gets.chomp
t = gets.chomp
eachS = s.chars
eachT = t.chars
smallS = eachS.sort.join
largeT = eachT.sort.reverse.join
# checkStr = smallS + '<' + largeT
# puts(checkStr)
(smallS < largeT) ? ( puts(yes) ):( puts(no) )


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

int main() {

  int N, K;
  cin >> N >> K;

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

  for(int i = K; i < N; i++){
    if(A[i] > A[i - K]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4052
// Let Go Your Earthly Tether , Enter The Void , Empty And Become Wind

#include<bits/stdc++.h>

#define all(x) x.begin() , x.end()

#define PB push_back
#define F first
#define S second
#define _sz(x) (int)x.size()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pll = pair<ll , ll> ;

const int MAXN = 100 * 1000 + 19 ;

ll h , n , a[MAXN] , sum = 0 ;

int main() {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
        cin >> h >> n ;
        for (int i = 0 ; i < n ; i ++)
                cin >> a[i] , sum += a[i] ;
        cout << (sum >= h ? "Yes" : "No") ;
        return (0) ;
}


Measured memory_bytes: 1024
#include<stdio.h>
  
#define N 100000

int Partition(int *,int,int);

int main(){
  int n,i,p,r;
  int A[N];

  scanf("%d", &n);
 for(i = 0; i < n; i++) {
  scanf("%d", &A[i]);
 }
  
  r = Partition(A,p,n-1);

  for(i=0; i<n; i++){
    if(i != 0)
      printf(" ");
    if(r == i)
      printf("[%d]",A[i]);
    else
      printf("%d",A[i]);
  }
  printf("\n");
  
  return 0;
}

int Partition(int *A,int p,int r){
  int i,j,s,t;
  s=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=s){
      i++;
      t=A[i];     
      A[i]=A[j];
      A[j]=t;
    }

  }

  t=A[i+1];       
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

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

/*----------------------------- DEFINES ------------------------------*/

#define eps 1e-9
#define mod 1000000007
#define ump unordered_map // operations take less time compared to map
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define mp make_pair
#define ps(x) push(x) // for stack and queue
#define T top() //  for stack
#define FR front()// for queue
#define BA back()// for queue
#define PP pop()// for queue and stack
#define B begin()
#define E end()
#define F first
#define S second
#define tostr(x) to_string(x)
#define SZ(x) ((int)x.size())
#define ins insert
#define MAE max_element
#define MIE min_element
#define cnt(x) count(x)
#define lb(x) lower_bound(x) // returns an it ptng to the element >=x if no such returns end
#define ub(x) upper_bound(x) // returns an it ptng to the element >x if no such returns end
#define rep(i,x,y) for(int i=x;i<y;i++)
#define per(i,x,y) for(int i=x;i>y;i--)
#define repi(i,x,y) for(int i=x;i<=y;i++)
#define peri(i,x,y) for(int i=x;i>=y;i--)
#define reps(i,x,y,k) for(int i=x;i<y;i+=k)
#define sper(i,x,y,k) for(int i=x;i>y;i-=k) 
#define all(x) ((x.B),(x.E))
#define inf (ll)LLONG_MAX
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x) // easy method to iterate through a ds
#define sq(a) (a)*(a)
#define fib(n) ceil(pow((1+sqrt(5),n)-pow((1-sqrt(5),n)/(float)(pow(2,n)*sqrt(5)// compute fib(n) in O(1)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}// fast i/o
#define dig(n) (int)(log10(n)+1) // num of digits
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define f(x) find(x)
#define set(x,k) memset(x,k,sizeof x)

/*------------------------------ TYPEDEFS-----------------------------*/

typedef long long ll;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef ump<int,int> umpii;

/*-----------------------------START FROM HERE -----------------------*/

int main(){
	FIO
	
	int k,s;cin>>k>>s;
  	int ans=0;
  	rep(i,0,k+1){
      rep(j,0,k+1){
        if(s-(i+j)>=0 && s-(i+j)<=k)ans++;
      }
    }
  	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

string w[100];

signed main()
{
    int N; cin>>N;
    REP(i,N) cin>>w[i];

    bool ok=true;

    set<string> st;
    REP(i,N){
        if(st.count(w[i])==1)
            ok=false;
        st.insert(w[i]);
    }
    REP(i,N-1){
        if(w[i][w[i].size()-1]!=w[i+1][0])
            ok=false;
    }
    cout<<(ok? "Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

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

char ch;
cin>>ch;
char c=ch+1;
cout<<c;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> a(n);
    int cnt = 0; //minus
    ll sum = 0;
    int mi = INF;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        mi = min(mi, abs(a[i]));
        sum += abs(a[i]);
        if(a[i] < 0) ++cnt;
    }
    if(cnt % 2 == 0) cout << sum << "\n";
    else cout << sum - 2 * mi << "\n";
    return 0;
}

Measured memory_bytes: 640
/*
	树, 我首先指定根
	每一个点的值由它下面点的值确定 (一个区间)
	当然, 奇偶性也得确定
	下面没点, 由上面的值确定
*/
#include <bits/stdc++.h>
#define N 100005

using namespace std;

int n, m;
int fa[N];
int head[N], nex[N << 1], to[N << 1], te;
int l[N], r[N], isOdd[N], val[N];

inline void read(int &x) {
	x = 0; bool sgn = false; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (sgn = true), ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	if(sgn) x = -x;
}
inline void ade(int u, int v) {
	nex[++te] = head[u], head[u] = te, to[te] = v;
}

void dfs_1(int u) {
	if(~isOdd[u]) {
		l[u] = r[u] = val[u];
	} else {
		l[u] = -1e9, r[u] = 1e9;
	}
	
	for(int i = head[u], ll, rr; i; i = nex[i]) {
		int v = to[i];
		if(v == fa[u]) continue;
		fa[v] = u, dfs_1(v);
		if(~isOdd[v]) {
			ll = l[v] - 1, rr = r[v] + 1;
			if(isOdd[v] == isOdd[u] || l[u] > rr || r[u] < ll) {
				puts("No");
				exit(0);
			}
			if(!~isOdd[u]) isOdd[u] = isOdd[v] xor 1;
			l[u] = max(l[u], ll), r[u] = min(r[u], rr);
		}
	}
	return;
}

inline bool check(int u, int v) {
	return !~isOdd[u] ||
		   isOdd[u] == (v & 1) && 
		   l[u] <= v && v <= r[u];
}
void dfs_2(int u) {
	if(!val[u]) {
		if(check(u, val[fa[u]] + 1)) {
			val[u] = val[fa[u]] + 1;
		} else if(check(u, val[fa[u]] - 1)) {
			val[u] = val[fa[u]] - 1;
		} else {
			puts("No");
			exit(0);
		}
	}
	for(int i = head[u]; i; i = nex[i]) {
		int v = to[i];
		if(v == fa[u]) continue;
		dfs_2(v);
	}
	return;
}

int main() {
	read(n);
	for(int i = 1, u, v; i < n; ++i) {
		read(u), read(v);
		ade(u, v), ade(v, u);
	}
	read(m);
	memset(isOdd, -1, sizeof isOdd);
	for(int i = 1, u; i <= m; ++i) {
		read(u), read(val[u]);
		isOdd[u] = val[u] & 1;
	}
	dfs_1(1);
	
//	for(int i = 1; i <= n; ++i)
//		printf("%d : %d %d\n", i, l[i], r[i]);
	
	val[0] = l[1] - ((l[1] & 1) == isOdd[1]);
	
	dfs_2(1);
	puts("Yes");
	for(int i = 1; i <= n; ++i)
		printf("%d\n", val[i]);
	return 0;
}

Measured memory_bytes: 9472
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

// ミンコフスキー距離
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	x := make([]float64, n)
	y := make([]float64, n)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " ") {
		num, _ := strconv.ParseFloat(v, 64)
		x[i] = num
	}
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " ") {
		num, _ := strconv.ParseFloat(v, 64)
		y[i] = num
	}
	s := ""
	for i := 1; i <= 3; i++ {
		p := float64(i)
		var D float64
		for j := 0; j < n; j++ {
			D += math.Pow(math.Abs(x[j]-y[j]), p)
		}
		s += fmt.Sprintf("%f\n", math.Pow(D, 1/p))
	}
	var D float64
	for i := 0; i < n; i++ {
		D = math.Max(D, math.Abs(x[i]-y[i]))
	}
	s += fmt.Sprintf("%f\n", D)
	fmt.Print(s)
}



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

int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> A;
    rep(i, n)
    {
        int a;
        cin >> a;
        A.push(a);
    }
    vector<pair<int, int>> CB;
    rep(i, m)
    {
        int b, c;
        cin >> b >> c;
        CB.emplace_back(c, b);
    }
    sort(CB.begin(), CB.end(), greater<pair<int, int>>());

    for (auto p : CB)
    {
        rep(i, p.second)
        {
            int top = A.top();
            A.pop();
            if (top < p.first)
                A.push(p.first);
            else
            {
                A.push(top);
                goto end;
            }
        }
    }

end:

    ll ans = 0;
    rep(i, n)
    {
        ans += A.top();
        A.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 1784
n = gets.to_i
names = []
n.times do
  names << gets.chomp
end

name_tally = Hash.new { 0 }

names.each_with_object(name_tally) do |name, tally|
  next unless name.start_with?(/M|A|R|C|H/)
  tally[name[0]] += 1
end

answer = 0

%w(M A R C H).combination(3) { |a, b, c|
  answer += name_tally[a] * name_tally[b] * name_tally[c]
}

puts answer


Measured memory_bytes: 21916
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;



int a[1006];
int main() {
  int N,M;cin>>N>>M;
  int count=0;
  int sum=0;
  rep(i,N) {cin>>a[i]; sum+=a[i];}
  rep (i,N) {
    double cond = (double) sum/(4*M);
    if (a[i]>= cond) count++;
}
  puts(count>=M? "Yes":"No");


  return 0;
}

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

#define MAX 2000000

int H;
int A[MAX + 1];


// int left(int i) { return i * 2; }                                            
//int right(int i) { return i * 2 + 1; }                                        

void maxHeapify(int i) {
  int largest;
  int l = 2 * i;      // left(i);                                               
  int r = 2 * i + 1;  // right(i);                                              

  if ( l <= H && A[l] > A[i] ) {
    largest = l;
  } else {
    largest = i;
  }

  if ( r <= H && A[r] > A[largest] ) {
    largest = r;
  }

  if ( largest != i ) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

void buildMaxHeap() {
  for ( int i = H / 2; i >= 1; i-- ) {
    maxHeapify(i);
  }
}

int main() {
  cin >> H;
  for ( int i = 1; i <= H; i++ ) {
    cin >> A[i];
  }

  buildMaxHeap();

  for ( int i = 1; i <= H; i++ ) {
    cout << " " << A[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 5024
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	ll n;
	cin >> n;
	pair<ll,ll> ba[n];
	for(ll i=0; i<n; i++){
		cin >> ba[i].second >> ba[i].first;
	}
	sort(ba,ba+n);
	ll cost=0;
	for(ll i=0; i<n; i++){
		cost+=ba[i].second;
		if(cost>ba[i].first){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(gcd(a, b));
        sc.close();
    }
    static int gcd(int a, int b){
        int tmp;
        while((tmp = a%b)!=0){
            a = b;
            b = tmp;
        }
        return b;
    }
}


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

vector<int> num;

void dfs(long n)
{
  if (1000000000 < n)
  {
    return;
  }
  num.push_back(n);
  dfs(n * 10 + 7);
  dfs(n * 10 + 5);
  dfs(n * 10 + 3);
}

int main()
{
  long N;
  cin >> N;
  dfs(0);
  int ans = 0;
  for (int i = 0; i < num.size(); i++)
  {
    string val = to_string(num.at(i));
    if (val.find("7") != -1 && val.find("5") != -1 && val.find("3") != -1 && num.at(i) <= N)
    {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 99999999

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef map<int,Edges> Graph;

void shortestPath(Graph &g, int s,
    map<int,Weight> &dist, map<int,int> &prev) {
  int n = g.size();
  for(auto &f:g)dist[f.first]=INF; dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev.find(e.dst) != prev.end()) continue;
    prev[e.dst] = e.src;
    for(auto &f:g[e.dst]) {
      if (dist[f.dst] > e.weight+f.weight) {
        dist[f.dst] = e.weight+f.weight;
        Q.push(Edge(f.src, f.dst, e.weight+f.weight));
      }
    }
  }
}

char buf[101];
int W;
int coor(int x,int y){return (y)*(W*2+2)+x;}
int main(){
	int H,N,X1,Y1,X2,Y2;
	scanf("%d%d%d%d%d%d%d",&W,&H,&N,&X1,&Y1,&X2,&Y2);
	X1=coor(X1*2,Y1*2),X2=coor(X2*2,Y2*2);
	vector<vector<int> >m(H*2+1);
	for(auto &&e:m)e.resize(W*2+1);
	for(int i=0;i<N;i++){
		int x,y,t,l;
		scanf("%d%d%d%s",&x,&y,&t,buf);
		l=strlen(buf);
		x=2*x+1,y=2*y+1;
		for(int j=0;j<t;j++){
			for(int k=0;k<l;k++){
				int c=buf[k];
				if(c=='L'&&1<x)m[y][x-1]++,x-=2;
				if(c=='U'&&1<y)m[y-1][x]++,y-=2;
				if(c=='R'&&x<W*2-1)m[y][x+1]++,x+=2;
				if(c=='D'&&y<H*2-1)m[y+1][x]++,y+=2;
			}
		}
	}
	Graph g;
	for(int h=0;h<=H*2;h+=2)for(int w=0;w<=W*2;w+=2){
		int a=coor(w,h),b;
		if(h<H*2)b=coor(w,h+2),g[a].push_back(Edge(a,b,m[h+1][w])),g[b].push_back(Edge(b,a,m[h+1][w]));
		if(w<W*2)b=coor(w+2,h),g[a].push_back(Edge(a,b,m[h][w+1])),g[b].push_back(Edge(b,a,m[h][w+1]));
	}
	map<int,Weight> dist;
	map<int,int> prev;
	shortestPath(g,X1,dist,prev);
	printf("%d\n",dist[X2]);
}

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

int main() {
    int n;cin>>n;
    vector<long long> vec={2,1};
    if(n==0) cout<<"2"<<endl;
    else if(n==1) cout<<"1"<<endl;
    else{
        for(int i=0;i<n-1;i++){
            vec.push_back(vec.at(i)+vec.at(i+1));

        }
        cout<<vec.at(n)<<endl;
    }

}

Measured memory_bytes: 256
import kotlin.math.min

fun main(args: Array<String>) {
    val s = readString()

    var ans = Int.MAX_VALUE
    for (c in 'a'..'z') {
        if (!s.contains(c)) continue
        ans = min(ans, s.split(c).maxBy { it.length }!!.length)
    }
    println(ans)
}

// read
fun readString() = readLine()!!

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

namespace ABC146_E___Rem_of_Sum_is_Num
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NK[0]; var K = NK[1];
            if (K == 1) return 0;

            var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var minus1A = A.Select(n => n - 1).ToArray();
            var accumA = new long[N + 1];
            accumA[0] = 0;
            for (int i = 1; i < N + 1; i++) accumA[i] = accumA[i - 1] + minus1A[i - 1];
            accumA = accumA.Select(n => n % K).ToArray();

            var dic = new ElementCounter<long>();
            for (int i = 1; i < Math.Min(K, N + 1); i++) dic.Add(accumA[i]);

            var result = 0L;
            result += dic[0];
            for (int i = 1; i < N + 1; i++)
            {
                dic.Remove(accumA[i]);
                if (N >= i + K - 1) dic.Add(accumA[i + K - 1]);

                result += dic[accumA[i]];
            }
            return result;
        }

    }
    class ElementCounter<T>
    {
        public Dictionary<T, long> Dic;

        public ElementCounter()
        {
            Dic = new Dictionary<T, long>();
        }
        public long this[T key]
        {
            get
            {
                if (Dic.ContainsKey(key))
                {
                    return Dic[key];
                }
                else
                {
                    return 0;
                }
            }
            set
            {
                if (Dic.ContainsKey(key))
                {
                    Dic[key] = value;
                }
                else
                {
                    Dic.Add(key, value);
                }
            }
        }
        public void Add(T item)
        {
            if (Dic.ContainsKey(item))
            {
                Dic[item] += 1;
            }
            else
            {
                Dic.Add(item, 1);
            }
        }
        public void Remove(T item)
        {
            if (Dic.ContainsKey(item))
            {
                Dic[item] = Dic[item] != 0 ? Dic[item] - 1 : 0;
            }
        }
    }
}


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

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

    vector<int> store;
    vector<int> wht;

    wht.push_back(0);
    store.push_back(0);

    int cnt = 0, tmp;
    for (int i = 1; i <= N; i++) {
        scanf("%d", &tmp);
        store.push_back(tmp);

        int ttt = abs(store[i] - store[i-1]);
        wht.push_back(ttt);
        cnt += ttt;
    }
    store.push_back(0);
    int ttt = abs(store[N+1] - store[N]);
    wht.push_back(ttt);
    cnt += ttt;


    for (int i = 1; i <= N; i++) {
        int ii = abs(store[i+1] - store[i-1]); /// 5 - 0     /// 5
        int ans = ii + cnt - (wht[i] + wht[i+1]); /// 12 - (3+2)    /// 12 -
        //cout << wht[i] << ' ' << wht[i+1] << endl;
        printf("%d\n", ans);
    }

}


Measured memory_bytes: 2292
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <cstring>

using namespace std;

int main() {
    string str; cin>>str; int k; cin>>k;
    
    int n = str.size();
    for(int i=0; i<n-1; i++) {
        int s = str[i] - 'a' + 1;
        if(str[i]=='a') continue;
        else {
            int cnt = 27 - s;
            if(cnt <= k) {
                str[i] = 'a';
                k-=cnt;
            } else {
                continue;
            }
        }
    }
    
    if(k>0) {
        int cnt = ((str[n-1] - 'a' + 1) + k)%26; if(cnt==0) cnt = 26;
        str[n-1] = cnt + 'a' - 1;
    }
    cout<<str<<endl;
    
    return 0;
}


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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  const int dx=tx-sx;
  const int dy=ty-sy;
  cout << string(dy,'U') << string(dx,'R') << flush;
  cout << string(dy,'D') << string(dx,'L') << flush;
  cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D' << flush;
  cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U' << flush;
  cout << endl;
  return 0;
}


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

int INF = 1e9;
vector<int> dx = {0,1,0,-1},dy = {1,0,-1,0};

int main(){
    int h,w; cin >> h >> w;
    vector<string> s(h);
    queue<P> que;
    vector<vector<int>> d(h,vector<int> (w,INF));
    rep(i,h) cin >> s[i];
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '#') continue;
            rep(a,h)rep(b,w) d[a][b] = INF;
            int dmax = 0;
            d[i][j] = 0;
            que.push(P(i,j));
            while(que.size()){
                P p = que.front();que.pop();
                int x = p.first,y = p.second;
                rep(k,4){
                    int nx = x + dx[k],ny = y + dy[k];
                    if(0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.' && d[nx][ny] == INF){
                        d[nx][ny] = d[x][y] + 1;
                        que.push(P(nx,ny));
                        dmax = d[nx][ny];
                    }
                }
            }
            ans = max(dmax,ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
	scanf("%d", &n);
	while( n > 10 ){
		if( n%10 == 9 ) m = 1;
		n /= 10;
	}
	if( n == 9 ) m = 1;
	puts(m?"Yes":"No");
} 

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int x, a;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> x >> a;
	if (x < a) cout << 0  << endl;
	else cout << 10 << endl;
	
	return 0;
}


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

int main(int argc, char const *argv[])
{
  int n,l; cin >> n >> l;
  // l - l+n-1
  int z = (2*l+n-1)*n/2;
  if(l>0) z-=l;
  else if(l+n-1<0) z-=l+n-1;
  cout << z << endl;
  return 0;
}



Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var hs = new HashSet<string>();
        for (int i = 0; i < n; i++) hs.Add(Console.ReadLine().Trim());
        var m = int.Parse(Console.ReadLine().Trim());
        var mes = "Closed by ";
        for (int i = 0; i < m; i++)
        {
            var s = Console.ReadLine().Trim();
            if (!hs.Contains(s)) { Console.WriteLine("Unknown " + s); goto next; }
            else if (mes == "Closed by ") mes = "Opened by ";
            else mes = "Closed by ";
            Console.WriteLine(mes + s);
            next:;
        }
    }
}


Measured memory_bytes: 20340
import collections

N, Q = map(int, input().split())
S = input()

new_S = S.replace("AC", "12")


count_one_list = [0] * len(S)
for i in range(len(S)-1):
    if new_S[i] == '1' and i == 0:
        count_one_list[i+1] += 1
    elif new_S[i] == '1':
        count_one_list[i+1] = count_one_list[i] + 1
    else:
        count_one_list[i+1] = count_one_list[i]
# count_one_list = [new_S[:i].count('1') for i in range(len(S))]
# print(count_one_list)

for i in range(Q):
    left, right = map(int, input().split())
    count_one = count_one_list[right-1] - count_one_list[left-1]
    print(count_one)

Measured memory_bytes: 51160
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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 dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
// Union Find

template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	vector<T> sizes;
	UnionFind(T n):par(n),rank(n,0),sizes(n,1){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}

	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  sizes[x]=sizes[x]+sizes[y];
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
	T size(T x){
	  return sizes[root(x)];
	}
};

int main(){
  ll n,k;
  cin>>n>>k;
  vll a(n);
  rep(i,n){
    cin>>a[i];
  }
  UnionFind<ll> uf(n-k+1);
  ll r=0;
  ll ma=-INF;
  vll o(0);
  ll l=0;
  while(r<n){
    while(r<n){
      if(a[l]>a[r]) break;
      if(r-l+1>=k) {
        o.pb(r-k+1);
      }
      if(r<n-1&&a[r]<a[r+1]){
        r++;
      }
      else{
        break;
      }
    }
    l=r+1;
    r++;
  }
  rep(i,sz(o)-1){
    uf.unite(o[i],o[i+1]);
  }
  set<ll> s;
  rep(i,k){
    s.insert(a[i]);
  }
  rep(i,n-k){
    s.insert(a[i+k]);
    if(*begin(s)==a[i]&&*rbegin(s)==a[i+k]){
      uf.unite(i,i+1);
    }
    s.erase(a[i]);
  }
  set<ll> ans;
  rep(i,n-k+1){
    ans.insert(uf.root(i));
  }
  COUT(sz(ans));
}

Measured memory_bytes: 15872
#include<stdio.h>
int main()
{
    long long int a,b,s=0;
    scanf("%lld",&a);
    long long int i;
    for(i=0;i<a;i++)
    {
        scanf("%lld",&b);
        s+=b;
    }
    printf("%lld\n",s-a);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
#define sqr(x) ((x)*(x))
#define pb push_back
const int N=1000002,M=998244353;
int pw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%M)if(y&1)z=1ll*z*x%M;return z;}
void inc(int &x,int y){x+=y;if(x>=M)x-=M;}void dec(int &x,int y){x-=y;if(x<0)x+=M;}
void Max(int &x,int y){if(y>x)x=y;}void Min(int &x,int y){if(y<x)x=y;}
//struct node{int to,ne;}e[];
//void add(int x,int y){e[++tot]=(node){y,h[x]},h[x]=tot;}
signed main(){
	int n,m;
	scanf("%d%d",&n,&m);
	printf("%d",max(n-m*2,0));
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;

template< typename T >
T mod_pow(T x, T n, const T &p) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

int main() {
    int n, s;
    vector<int> a;
    cin >> n >> s;
    for (int i=0;i<n;i++) {
        int aa;
        cin >> aa;
        a.push_back(aa);
    }
    map<int, long long> ff;
    ff[0]++;
    for (int i=0;i<n;i++) {
        map<int, long long> fff;
        for (auto v: ff) {
            fff[v.first] = (fff[v.first] + v.second*2) % M;
            if (v.first + a[i] > s) {
                continue;
            }
            fff[v.first + a[i]] = (fff[v.first + a[i]] + v.second) % M;
        }
        ff = fff;
    }
    cout << (ff[s]) % M << endl;
}

Measured memory_bytes: 3984
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
int ceil(int a,int b){// a以上でｂの倍数の最小値を出力//
    return (a+b-1)/b*b;
}
int stoii(string s){ //stoi関数の代用//
    return atoi(s.c_str());
}
int main(void){
    int n,m;
    cin>>n>>m;
    vector<int> a(n,0),b(n,0);
    vector<int> c(m,0),d(m,0);
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,m) cin>>c[i]>>d[i];
    rep(i,n){
        ll f=INF;
        ll min=INF;
        rep(j,m){
            if(abs(c[j]-a[i])+abs(d[j]-b[i])<min){
                f=j+1;
                min=abs(c[j]-a[i])+abs(d[j]-b[i]);
            }           
        }
        cout<<f<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
N = int(sys.stdin.readline().strip())
As = list(map(int, sys.stdin.readline().strip().split()))

ans = 0
num_negative = 0
min_num = float('inf')
for A in As:
    ans += abs(A)
    min_num = min(min_num, abs(A))
    if A < 0:
        num_negative += 1
if num_negative % 2 == 1:
    ans -= 2 * min_num
print(ans)


Measured memory_bytes: 14252
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    A = kwargs["A"]
    res = 0

    for i, a in enumerate(A):
        if (i + 1) * A[i] % 2 == 1:
            res += 1

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]
    cin = input().split()
    kwargs["A"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31192
I = float('inf')
N = int(input())
XYD = [input().split() for _ in range(N)]
xL = set()
xR = set()
xS = set()
yD = set()
yU = set()
yS = set()
for xyd in XYD:
    x, y, d = xyd
    x = int(x)
    y = int(y)
    if d == 'L':
        xL.add(x)
        yS.add(y)
    elif d == 'R':
        xR.add(x)
        yS.add(y)
    elif d == 'U':
        yU.add(y)
        xS.add(x)
    else:
        yD.add(y)
        xS.add(x)
#xmin
xRmin = min(xR | {I})
xLmin = min(xL | {I})
xSmin = min(xS | {I})
#xmax
xRmax = max(xR | {-I})
xLmax = max(xL | {-I})
xSmax = max(xS | {-I})

x2m = xLmax - xRmin
x1m = max(xSmax - xRmin, xLmax - xSmin)
x0 = max(xRmax - xRmin, xLmax - xLmin, xSmax - xSmin)
x1 = max(xSmax - xLmin, xRmax - xSmin)
x2 = xRmax - xLmin
#ymin
yUmin = min(yU | {I})
yDmin = min(yD | {I})
ySmin = min(yS | {I})
#ymax
yUmax = max(yU | {-I})
yDmax = max(yD | {-I})
ySmax = max(yS | {-I})

y2m = yDmax - yUmin
y1m = max(ySmax - yUmin, yDmax - ySmin)
y0 = max(yUmax - yUmin, yDmax - yDmin, ySmax - ySmin)
y1 = max(ySmax - yDmin, yUmax - ySmin)
y2 = yUmax - yDmin


def dd(t):
    if 0 <= t < I:
        return max(x2m - 2 * t, x1m - t, x0, x1 + t, x2 + 2 * t) * max(
            y2m - 2 * t, y1m - t, y0, y1 + t, y2 + 2 * t)
    else:
        return I


t = [0, x2m / 2, x1m, y2m / 2, y1m]
t += [x2m - x1m, x1m - x0, x0 - x1, x1 - x2]
t += [(x2m - x0) / 2, (x1m - x1) / 2, (x0 - x2) / 2]
t += [(x2m - x1) / 3, (x1m - x2) / 3]
t += [(x2m - x2) / 4]
t += [y2m - y1m, y1m - y0, y0 - y1, y1 - y2]
t += [(y2m - y0) / 2, (y1m - y1) / 2, (y0 - y2) / 2]
t += [(y2m - y1) / 3, (y1m - y2) / 3]
t += [(y2m - y2) / 4]
t += [(x2m + y2m) / 4, (x2 + y2) / 4]
t += [(x2m + 2 * y1m) / 4, (y1m + 2 * x2m) / 4, (x2 + 2 * y1) / 4,
      (y1 + 2 * x2) / 4]
t += [(x1m + y1m) / 2, (x1 + y1) / 2]

print(min([dd(time) for time in t]))


Measured memory_bytes: 53420
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }


int main() {
    string s[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string t;
    cin >> t;
    REP(i,7){
        if (s[i] == t){
            cout << 7 - i << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define inf INT_MAX
#define ninf INT_MIN
#define W(x) cout<<x<<endl
#define WW(x,y) cout<<x<<' '<<y<<endl;
#define in(x) cin>>x
#define int long long
const ll mod = 998244353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 
template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}
struct Node{
    int first;int second;
    Node(int x,int y){
        this->first = x;
        this->second = y;
    }
};
struct comparator{
    bool operator()(const Node &a,const Node &b){
        int lena = a.second-a.first+1;
        int lenb = b.second-b.first+1;
        if(lena == lenb)return a.first<b.first;
        else return lena>lenb;
    }
};
ll power(ll x,ll y,ll mod){
    ll res = 1;
    x%=mod;
    while(y>0){
        if(y&1)res = (res*x)%mod;
        y>>=1;
        x = (x*x)%mod;
    }
    return res;
}

signed main() {
	int n;
	cin>>n;
	vector<long long> a(n);
	bool flag0 = false;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		if(a[i]==0)
			flag0=true;
	}
    sort(all(a));
	long long prod = 1;
	long long maxp = 1e18;
	for(int i=0;i<n;i++) {

		if(flag0) {
			prod=0;
			break;
		} else if(maxp/prod< a[i]) {
			prod = -1;
			break;
		} else if(maxp/prod==a[i] && maxp%prod!=0) {
			prod = -1;
			break;
		} else {
			prod *= a[i];
		}

	}
	cout<<prod;
	return 0;
}

Measured memory_bytes: 4052
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	int n;
  scanf("%d", &n);
  int A[n], B[n], C[n];
  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
  for ( int i = 0; i < n; i++ ) B[i] = A[i];
  sort(B, B+n);
  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      if (A[i] == B[j]) {
        C[i] = j;
        break;
      }
    }
  }
  int k = 0, count = 0, min = B[0], count1 = 0, count2 = 0;
  while ( k < n ) {
    int i, j;
    for (i = 0; i < n; i++) if (C[i] == k) break;
    for (j = 0; j < n; j++) if (C[j] == i) break;
    if (C[k] == k) {
			if (count1 > count2+2*(min+B[k])) {
				count += count2+2*(min+B[k]);
			} else {
				count += count1;
			}
			count1 = 0;
			count2 = 0;
      k++;
    } else {
      count1 += A[i]+A[j];
			count2 += min+A[j];
      swap(A[i], A[j]);
      swap(C[i], C[j]);
    }
  }

  printf("%d\n", count);

  return 0;
}



Measured memory_bytes: 2772