akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
    int H, W; cin >> H >> W;
    int dot = 0;
    vector< vector < char > > m;
    for(int i = 0; i < H; i++){
        vector<char> v;
        for(int j = 0; j < W; j++){
            char aux; cin >> aux;
            v.push_back(aux);
            if(aux == '.'){
                dot++;
            }
        }
        m.push_back(v);
    }

    vector< vector < char > > visited;
    for(int i = 0; i < H; i++){
        vector<char> v;
        for(int j = 0; j < W; j++){
            v.push_back('n');
        }
        visited.push_back(v);
    }

    visited[0][0] = 's';
    deque< pair < pair < int, int >, int > > q;
    pair<pair < int, int >, int> pairaux;
    pairaux.first.first = 0;
    pairaux.first.second = 0;
    pairaux.second = 1;
    q.push_back(pairaux);

    //int aaaaa = 0;
    while(!q.empty()){
        //aaaaa++;
        //cout << aaaaa << endl;
        auto p = q.front();
        visited[p.first.first][p.first.second] = 's';
        // ######
        // cout << p.first << " " << p.second << endl;
        // ######
        if(p.first.first == H-1 && p.first.second == W-1){
            cout << dot - p.second << endl;
            return 0;
        }
        // para os que p alcanca
        pair <int, int> ps[4];
        ps[0] = p.first; ps[0].first++;
        ps[1] = p.first; ps[1].first--;
        ps[2] = p.first; ps[2].second++;
        ps[3] = p.first; ps[3].second--;
        // se e valido
        for(int i = 0; i < 4; i++){
            if(ps[i].first >=0 && ps[i].first < H &&
               ps[i].second >= 0 && ps[i].second < W){
                   if(visited[ps[i].first][ps[i].second] == 'n' && m[ps[i].first][ps[i].second] == '.'){
                       pair <pair<int,int>, int> fds;
                       fds.first=ps[i];
                       fds.second=p.second+1;
                       visited[ps[i].first][ps[i].second] = 's';
                       q.push_back(fds);
                   }
            }
        }
        q.pop_front();
    }

    cout << "-1" << endl;
    

    return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    let mut x: usize;
    input! {x: usize};

    let five_handred_count = x / 500;
    let five_count = (x - five_handred_count * 500) / 5;

    println!("{}", five_handred_count * 1000 + five_count * 5);
}


Measured memory_bytes: 2156
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    out.println(Math.max(0, C - (A-B) ) );
  }
}

Measured memory_bytes: 22868
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	cout<<a[n-1]-a[0]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100005;
const int MAXM = 11;

int n, m, q;
int bio[MAXM][MAXM][MAXN];

vector <int> v[MAXN];

int p[MAXN], d[MAXN], start[MAXN];
int ans[MAXN];

void bfs(int st, int kr, int kve) {
	queue <int> q;
	if (bio[0][kr][st]) return;
	bio[0][kr][st] = 1;
	q.push(st);
	q.push(0);
	
	int cvor, dst, kraj;
	while (!q.empty()) {
		cvor = q.front();
		q.pop();
		dst = q.front();
		q.pop();
		
		ans[cvor] = max(ans[cvor], kve);
		bio[dst][kr][cvor] = 1;

		if (dst == kr) continue;

		REP(i, (int)v[cvor].size()) {
			int ncvor = v[cvor][i];
			if (bio[dst + 1][kr][ncvor]) continue;
			q.push(ncvor);
			q.push(dst + 1);
			bio[dst + 1][kr][ncvor] = 1;
		}
	}
}

int main() {
	scanf("%d %d",&n,&m);
	REP(i, m) {
		int a, b;
		scanf("%d %d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}

	scanf("%d",&q);
	FOR(i, 1, q + 1) scanf("%d %d %d",&start[i],&d[i],&p[i]);

	for (int i = q; i > 0; i--) bfs(start[i], d[i], i);

	FOR(i, 1, n + 1) printf("%d\n",p[ans[i]]);
	return 0;
}

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

int main(){
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
long long n,p,q,br=0; double d; cin>>n>>d;
for(;n!=0;n--){
    cin>>p>>q;
    if(sqrt(p*p+q*q)<=d) br++;
}
cout<<br<<'\n';
return 0;
}


Measured memory_bytes: 3760
#include <iostream>

int main() {
  int32_t n;
  std::cin >> n;

  std::string c;
  std::cin >> c;

  if (c.find('W') == std::string::npos) {
    std::cout << 0 << std::endl;
    return 0;
  }

  int32_t count = 0;
  for (;;) {
    auto r = c.find_last_of('R');
    auto w = c.find('W');
    if (r + 1 == w) {
      break;
    }
    auto tmp = c.at(w);
    c.at(w) = c.at(r);
    c.at(r) = tmp;
    ++count;
  }

  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  string S;
  cin >> S;
  vvll dp(5005, vll(5005, 0));
  for(int i = N-1; i >= 0; i--){
    for(int j = N-1; j >= 0; j--){
      if(S.at(i) != S.at(j)) dp.at(i).at(j) = 0;
      else dp.at(i).at(j) = dp.at(i+1).at(j+1) + 1;
    }
  }
  ll ans = 0LL;
  for(ll i = 0; i < N-1; i++){
    for(ll j = i+1; j < N; j++){
      ll res = min(dp.at(i).at(j), j-i);
      chmax(ans, res);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 196224
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF INT_MAX>>1 //要climits#includ

typedef long long ll;

using namespace std;

int main(void){
	int a, b; cin >> a >> b;
	if(a<=5)cout << 0 << endl;
	else if(a<=12) cout << b/2 << endl;
	else cout << b << endl;
	return 0;
}

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

int main() {
	int h, w; cin >> h >> w;
	vector<vector<char>> c(h + 2, vector<char>(w + 2));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cout << c[i][j];
		}
		cout << endl;
		for (int j = 1; j <= w; j++) {
			cout << c[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var: ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        c: i64,
        b: [i64; m],
        a: [[i64;m]; n],
    }
    let ans = a
        .into_iter()
        .filter(|a_| {
            a_.into_iter()
                .zip(b.iter())
                .map(|(a_, &b_)| a_ * b_)
                .sum::<i64>()
                + c
                > 0
        })
        .count();
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {

    int n;
    cin>>n;
    vll v(n);
    rep(i,n)cin>>v[i];
    rep(i,n){
        if(v[i]<=i)continue;
        fin(-1);
        return 0;
    }
    ll ans=0;
    rep(i,n-1){
        if(v[i]+1<v[i+1]){
            fin(-1);
            return 0;
        }
        if(v[i]+1==v[i+1]){
            ans++;
        }
        if(v[i]>=v[i+1]){
            ans+=v[i+1];
        }
    }
    fin(ans);
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){

	int a, b;
	int ans=0;

	// input
	scanf("%d %d", &a, &b);

	if(a < 1 || a > 10000 || b < 1 || b > 10000){
		return 1;
	}

	ans = a * b;

	if(ans %2 == 0){
		printf("Even\n");
	}else{
		printf("Odd\n");
	}

	return 0;

}

Measured memory_bytes: 128
#include<stdio.h>

int main (void){
	char op;
	int a,b,c,i;
	for(i=0;;i++){
		scanf("%d %c %d",&a,&op,&b);
		if(!(op=='?')){
			
			if(op=='+'){
				c=a+b;
			}
			if(op=='-'){
				c=a-b;
			}
			if(op=='*'){
				c=a*b;
			}
			if(op=='/'){
				c=a/b;
			}
			printf("%d\n",c);
		}
		else{
			break;
		}	
	}
	return 0;
}

Measured memory_bytes: 600
H, W=map(int, input().split())
a=[list(input()) for _ in range(H)]
b=[[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    if '#' in a[i]:
        for j in range(W):
            b[i][j]+=1
for j in range(W):
    if any(a[i][j]=='#' for i in range(H)):
        for k in range(H):
            b[k][j]+=1
for i in range(H):
    for j in range(W):
        if b[i][j]==2:
            print(a[i][j], end='')
    if 2 in b[i]:
        print('')


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 998244353;
Int dp1[2][90001], dp2[2][45001];
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (auto& a : A) cin >> a;
    int sum = accumulate(begin(A), end(A), 0);
    dp1[1][0] = 1;
    for (int i = 0; i < N; i++) {
        int a = A[i];
        bool b = i % 2;
        memset(dp1[b], 0, sizeof(dp1[0]));
        for (int j = 0; j <= 90000; j++) {
            if (j+a <= 90000) (dp1[b][j+a] += dp1[!b][j]) %= MOD;
            (dp1[b][j] += dp1[!b][j] * 2) %= MOD;
        }
    }
    dp2[1][0] = 1;
    for (int i = 0; i < N; i++) {
        int a = A[i];
        bool b = i % 2;
        memset(dp2[b], 0, sizeof(dp2[0]));
        for (int j = 0; j <= 45000; j++) {
            if (j+a <= 45000) (dp2[b][j+a] += dp2[!b][j]) %= MOD;
            (dp2[b][j] += dp2[!b][j]) %= MOD;
        }
    }
    Int ans = 1;
    for (int i = 0; i < N; i++) (ans *= 3) %= MOD;
    bool b = (N-1)%2;
    for (int i = (sum+1)/2; i <= sum; i++) {
        (ans += (MOD - dp1[b][i]) * 3) %= MOD;
    }
    if (sum % 2 == 0) (ans += dp2[b][sum/2] * 3) %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2304
program MSOLUTIONSC
    implicit none
    integer(8)::N,K,i,l,r
    integer(8),allocatable,dimension(:)::A
    read*,N,K
    allocate(A(N))
    read*,A

    l=A(1)
    do i=2,N-K+1
        if(A(i+K-1)>l)then
            print'(A)',"Yes"
        else
            print'(A)',"No"
        end if
        l=A(i)
    end do
end program MSOLUTIONSC

Measured memory_bytes: 4636
s=input()
c=0
if 0<int(s[0])*10+int(s[1])<13:c+=1
if 0<int(s[2])*10+int(s[3])<13:c+=2
print("AMBIGUOUS" if c==3 else "YYMM" if c==2 else "MMYY" if c==1 else "NA")

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int n,dmax;
int m[300];
bool visited[300], isVisit[300], isGoal;
void dfs(int p){
  if(visited[p])return ;
  visited[p] = true;
  isVisit[p] = true;
  if(p == n+1){
    isGoal = true;
    return;
  }
  for(int i = 1; i <= dmax && p+i <= n+1; i++){
    int np = p+i;
    np = np + m[np];
    if(np > n + 1)np = n + 1;
    if(np < 0) np = 0;  
    dfs(np);
  }
}
void solve(){
  fill(isVisit, isVisit+(n+2), false);
  isVisit[0] = true;
  for(int i = 0 ; i <= n; i++){
    if(!isVisit[i])continue;
    isGoal = false;
    fill(visited, visited+(n+2), false);
    dfs(i);
    if(!isGoal)break;    
  }
  cout << (isGoal?"OK":"NG") << endl;
}
int main(){
  while( cin >> dmax, dmax ){
    cin >> n;
    fill(m, m+(n+2), 0);
    for(int i = 0 ; i < n ;i++){
      cin >> m[i+1];
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000];
int main()
{
	long long m,n,x,z,i;
	cin>>m>>n;
	string ans;
	ans="";
	char y;
	x=min(m,n);
	z=max(m,n);
	y=char(x+48);
	for (i=0;i<z;i++)
	{
		ans=ans+y;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(int(1e6))

def search(x, num):
    nodes.remove(x)
    for y in edge[x]:
        edge[y].discard(x)
    for y in list(edge[x]):
        if y in nodes:
            num = search(y, num)
    return num + 1

(n,m),*d  = [list(map(int, s.split())) for s in open(0)]

edge = [set() for _ in range(n+1)]
for x in d:
    edge[x[0]].add(x[1])
    edge[x[1]].add(x[0])

nodes = set(range(1,n+1))
ans = 1
for x in list(nodes):
    if x in nodes:
        ans = max(ans, search(x, 0))
print(ans)

Measured memory_bytes: 291236
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        s: String,
    }

    let vs: Vec<char> = s.chars().collect();
    let mut ans = 0;
    let mut current = 0;
    for i in &vs {
        if *i == 'A' || *i == 'C' || *i == 'G' || *i == 'T' {
            current += 1;
        } else {
            ans = ans.max(current);
            current = 0;
        }
    }
    ans = ans.max(current);
    println!("{}", ans);
}


Measured memory_bytes: 2132
#include<cstdio>
const int K=38,N=38*(38-1)+1;
int i,j,k,cnt=1,f[K+3][K+3];
int main(){
	printf("%d %d\n",N,K);
	for(i=1;i<=K;i++){
		for(j=1;j<=K;j++){
			if(j==1)f[i][j]=1;
			else f[i][j]=++cnt;
			printf("%d ",f[i][j]);
		}
		printf("\n");
	}
	for(i=2;i<=K;i++)
		for(j=0;j+1<K;j++){
			printf("%d ",i);
			for(k=2;k<=K;k++)
				printf("%d ",f[k][2+(j+(k-2)*(i-2))%(K-1)]);
			printf("\n");
		}
	//while(1);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100, maxk = 303;
long long dp[maxk][maxn], a[maxn];
long long dq[maxn];
int pl, pr;
void clear(){
	pl = 0;
	pr = -1;
}
void add(long long v){
	while(pl <= pr && dq[pr] < v) pr--;
	dq[++pr] = v;
}
void del(long long v){
	if(dq[pl] == v) pl++;
}
long long best(){
	assert(pl <= pr);
	return dq[pl];
}
int main(){
	int n, m, k; cin >> n >> m >> k;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) dp[1][i] = a[i];
	for(int i = 2; i <= k; i++){
		clear();
		add(dp[i - 1][i - 2]);
		for(int j = i - 1; j < n; j++){
			if(j - m - 1 >= i - 2) del(dp[i - 1][j - m - 1]);
			dp[i][j] = best() + i * a[j];
			add(dp[i - 1][j]);
		}
	}
	long long ans = 0;
	for(int i = 0; i < n; i++) ans = max(ans, dp[k][i]);
	cout << ans << endl;
	return 0;
}


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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;

#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

int main()
{
    char a;
    cin >> a;
    cout << char(a+1) << endl;
}

Measured memory_bytes: 3584
def factorize(n):
    n_list = []
    for i in range(n):
        x = i + 1
        if n % x == 0:
            n_list.append(x)
    return n_list


if __name__ == '__main__':
    A, B, C = input().split()
    a_list = factorize(int(A))
    b_list = factorize(int(B))
    and_list = list(set(a_list) & set(b_list))
    and_list.sort(reverse=True)
    print(and_list[int(C) - 1])

Measured memory_bytes: 3064
def gcd(a, b):
    if(a < b):
        a, b = b, a
    if(b == 0):
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

N = int(input())
A = list(map(int, input().split()))
l = A[0]
for a in A:
    l = lcm(l, a)
ans = 0
mod = 10**9+7
for a in A:
    ans += (l * pow(a, mod-2, mod))%mod
    ans %= mod
print(ans)


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

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

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C) {
    set<int> X;
    X.insert(A);
    X.insert(B);
    X.insert(C);
    if( X.size() == 2) cout << YES << endl;
    else cout << NO << endl;

}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  solve(A, B, C);
  return 0;
}


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

using namespace std;

#define ll long long
#define fi first
#define se second

void test_case(){
	int h,a;
	scanf("%d%d",&h,&a);
	int r=h/a;
	if(h%a!=0)
		r++;
	printf("%d\n",r);

}

int main(){
	int t=1;
	//scanf("%d",&t);
	
	while(t--)
		test_case();

}


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

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

	int a[10];
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a, a + 10);
	reverse(a, a + 10);
	for (int i = 0; i < 3; i++) {
		cout << a[i] << endl;
	}
}

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

int main() {
  int n,c;
  c = 0;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i = 0; i < n - 1; i++) {
    if(a.at(i) == a.at(i + 1)) {
      c++;
    }
  }
  cout << n - c << endl;
}


Measured memory_bytes: 3568
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

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

int gcd(int a,int b){
  int r=a%b;
  while(r>0){
    a=b;b=r;r=a%b;
  }
  return b;
}

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  int *a=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int g=a[0];
  for(i=1;i<n;i++){
    g=gcd(g,a[i]);
  }
  for(i=0;i<n;i++){
    if(a[i]>=k && (a[i]-k)%g==0){
      printf("POSSIBLE\n");
      return;
    }
  }
  printf("IMPOSSIBLE\n");
  return;
}

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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 gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	string o,e; cin>>o>>e;

	int i;
	for(i=0; i<e.length(); i++) {
		cout<<o.at(i)<<e.at(i);
	}
	if(o.length()!=e.length()) cout<<o.at(i);

}


Measured memory_bytes: 256
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    int N= n + 1000;
    int chn = N / 1000;
    chn *= 1000;
    
    int ans = chn - n;
    if(ans % 1000 == 0)
        ans = 0;
    cout << ans;
    
    
    

}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> a(M);
  vector<int> b(M);
  rep(i, M){
    cin >> a.at(i) >> b.at(i);
  }
  
  vector<int> ans(N);
  for(int j=1; j<N+1; j++){
    rep(i, M){
      if(a.at(i)==j) ans.at(j-1)++;
      if(b.at(i)==j) ans.at(j-1)++;
    }
  }
  
  rep(j, N){
    cout << ans.at(j) << endl;
  }
}

Measured memory_bytes: 256
def main():
    N = int(input())
    V = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    ans = 0
    for v, c in zip(V, C):
        if v - c > 0:
            ans += v - c
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
package main

import "fmt"

func main() {
	var A, B, C, D int
	fmt.Scan(&A, &B, &C, &D)
	ans := max(A*B, C*D)
	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
const ll MOD=1e9+7;
ll mypow(int x){
	ll res=1,ans=2;
	while (x>0){
		if (x%2==1){
			x--;
			res*=ans;
			res%=MOD; 
			continue;
		}
		ans*=ans;
		ans%=MOD;
		x/=2;
	}
	return res;
}
int n,a[103];
ll dp[103][103],ans=0;
vector<int>v;
map <int,int> vis;
map <int,int> mp;
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
		if (vis[a[i]]) continue;
		v.push_back(a[i]);
		vis[a[i]]=1;
	}
	v.push_back(0);
	sort (v.begin(),v.end());
	for (int i=0;i<v.size();i++)
		mp[v[i]]=i;
	dp[1][0]=(mypow(v[1]-v[0])-2)%MOD*mypow(a[1]-v[1])%MOD;
	for (int i=1;i<mp[a[1]];i++) dp[1][i]=2*(mypow(v[i+1]-v[i])-1)%MOD*mypow(a[1]-v[i+1])%MOD;
	dp[1][mp[a[1]]]=2;
	for (int i=2;i<=n;i++){
		if (a[i-1]>=a[i]){
			for (int j=0;j<=mp[a[i]];j++) dp[i][j]=dp[i-1][j];
			for (int j=mp[a[i]]+1;j<=mp[a[i-1]];j++) dp[i][mp[a[i]]]+=dp[i-1][j];
			dp[i][mp[a[i]]]=dp[i][mp[a[i]]]*2%MOD;
		}else{
			for (int j=0;j<mp[a[i-1]];j++) dp[i][j]=dp[i-1][j]*mypow(a[i]-a[i-1])%MOD;
			dp[i][mp[a[i-1]]]=2*dp[i-1][mp[a[i-1]]]*(mypow(v[mp[a[i-1]]+1]-a[i-1])-1)%MOD*mypow(a[i]-v[mp[a[i-1]]+1])%MOD;
			for (int j=mp[a[i-1]]+1;j<mp[a[i]];j++) dp[i][j]=dp[i-1][mp[a[i-1]]]*2%MOD*(mypow(v[j+1]-v[j])-1)%MOD*mypow(a[i]-v[j+1])%MOD;
			dp[i][mp[a[i]]]=dp[i-1][mp[a[i-1]]]*2%MOD;
		}
	}
	for (int i=0;i<=mp[a[n]];i++) ans+=dp[n][i];
	cout<<ans%MOD;
}

Measured memory_bytes: 384
n=int(input())
t,x,y=0,0,0
for i in range(n):
     t_,x_,y_=map(int,input().split())
     l=abs(x-x_)+abs(y-y_)
     if l<=t_-t and (t_-t-l)%2==0:
          t,x,y=t_,x_,y_
     else:
          print('No')
          break
else:
     print('Yes')

Measured memory_bytes: 46952
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const int INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}

int main(){
    int n,m;
    cin>>n>>m;
    int r[55]={0};
    int a,b;
    for(int i=0;i<m;++i){
        cin>>a>>b;
        r[a]++;
        r[b]++;
    }
    for(int i=1;i<=n;++i){
        cout<<r[i]<<endl;
    }
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Point {
	double x, y, z;
	Point(): x(0), y(0), z(0) {}
	Point(double x, double y, double z): x(x), y(y), z(z) {}
	const Point operator+(const Point& p) const { return Point(x + p.x, y + p.y, z + p.z); }
	const Point operator-(const Point& p) const { return *this + (-p); }
	const Point operator-() const { return Point(-x, -y, -z); }
	const Point operator*(const double d) const { return Point(d * x, d * y, d * z); }
	const Point operator/(const double d) const { return *this * (1 / d); }
	const double norm2() const { return x * x + y * y + z * z; }
};

double mindist(Point p1, Point p2, Point t) {
	for (int i = 0; i < 100; i++) {
		//cout << fixed << setprecision(3) << p1.x << " " << p1.y << " " << p1.z << " " << p2.x << " " << p2.y << " " << p2.z << endl;
		
		Point pl = (p1 * 2 + p2) / 3;
		Point pr = (p1 + p2 * 2) / 3;
		
		double distl = (pl - t).norm2();
		double distr = (pr - t).norm2();

		if (distl < distr) {
			p2 = pr;
		} else {
			p1 = pl;
		}
	}

	return sqrt((p1 - t).norm2());
}

int main() {
	int n, q; cin >> n >> q;
	
	vector<Point> p(n);
	vector<double> r(n);
	vector<ll> l(n);

	for (int i = 0; i < n; i++)
		cin >> p[i].x >> p[i].y >> p[i].z >> r[i] >> l[i];

	const double eps = 1e-8;

	for (int i = 0; i < q; i++) {
		Point p1, p2;
		cin >> p1.x >> p1.y >> p1.z >> p2.x >> p2.y >> p2.z;
		
		ll score = 0;

		for (int j = 0; j < n; j++) {
			double d;
			if ((d = mindist(p1, p2, p[j])) <= r[j] + eps) {
				score += l[j];
			}
			//cout << fixed << setprecision(10) << d << " " << l[j] << endl;
		}
		cout << score << endl;
	}
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int dp[2005][2005];
int solve(int i,int sum){
  if(sum==0)return 1;
  if(dp[i][sum]!=-1)return dp[i][sum];
  int ans=0;
  rep(j,3,sum+1){
      ans+=solve(i+1,sum-j);
      ans%=mod;
  }
  dp[i][sum]=ans;
  return ans;
}
int32_t main(){
    clr(dp,-1);
    int n; cin>>n;
    cout<<solve(0,n);
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


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

int main() {
    int N, K;
    int cnt = 0;
    cin >> N >> K;
    int array[N];
    for(int i = 0; i < N; i++)
        array[i] = 0;
    for(int i = 0; i < K; i++)
    {
        int n = 0;
        cin >> n;
        int a;
        for(int j = 0; j < n; j++)
        {
            cin >> a;
            array[a - 1]++;
        }
    }
    for(int i = 0; i < N; i++)
    {
        if(array[i] == 0)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

int n;
vector<int> a(100100);

int main(){
    cin>>n;
    int cnt1=0;
    int cnt2=0;
    rep(i,0,n){
        cin>>a[i];
        if(a[i]%2==1) cnt1++;
        if(a[i]%4==0) cnt2++;
    }
    if(cnt1<=cnt2) cout<<"Yes"<<"\n";
    else if(cnt1+cnt2==n && abs(cnt1-cnt2)==1) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define M 1000010


int main(){
	IOS;
	tihs;
	
	
	ll a[M]={0};
	rep(i,1,M){
		if(i%3==0 and i%5==0)continue;
		else if(i%3==0)continue;
		else if(i%5==0)continue;
		else a[i]=i;
	}
	rep(i,1,M)a[i]+=a[i-1];
	ll m;cin>>m;
	cout<<a[m];

	return 0;
}

Measured memory_bytes: 11468
n = input()
l = input().split()
m = []
for a in l:
    a = int(a)
    c = 0
    while a % 2 == 0:
        a = a / 2
        c = c + 1
    m.append(c)
d = m[0]
for b in m:
    if b < d:
        d = b
    else:
        pass
print(d)

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

int main() {
  string s;
  cin >> s;
  bool ac = true;
  if(s[0] != 'A') {
    ac = false;
  }

  int numC = 0;
  for(int i=1;i < s.size();i++) {
    if(i >= 2 && i <= s.size()-2) {
      if(s[i] == 'C') {
        numC++;
        continue;
      }
    }
    if((s[i] < 'a') || (s[i] > 'z')) {
      ac = false;
      break;
    }
  }

  if(numC != 1) {
    ac = false;
  }

  if(ac) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	aa := make([]int, n)
	pp := make(pairs, m)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	for i := 0; i < m; i++ {
		pp[i][0] = getNextInt(scanner)
		pp[i][1] = getNextInt(scanner)
	}
	var ans int64
	sort.Ints(aa)
	sort.Sort(pp)
	j := 0
	for i := 0; i < n; i++ {
		if j < m && aa[i] < pp[j][1] {
			ans += int64(pp[j][1])
			pp[j][0]--
			if pp[j][0] == 0 {
				j++
			}
			continue
		}
		ans += int64(aa[i])
	}
	fmt.Fprintln(writer, ans)
}

func newPair(b, c int) pair {
	return pair{
		b, c,
	}
}

type pair [2]int
type pairs []pair

func (a pairs) Len() int           { return len(a) }
func (a pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a pairs) Less(i, j int) bool { return a[i][1] > a[j][1] }


Measured memory_bytes: 6784
package main

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

// IO struct
type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func newIO() *IO {
	return &IO{
		scanner: bufio.NewScanner(os.Stdin),
		writer:  bufio.NewWriter(os.Stdout),
	}
}

func (IO *IO) nextLine() string {
	IO.scanner.Scan()
	return IO.scanner.Text()
}

func (IO *IO) nextInt() int {
	i, e := strconv.Atoi(IO.nextLine())
	if e != nil {
		panic(e)
	}
	return i
}

func (IO *IO) nextInt64() int64 {
	a, _ := strconv.ParseInt(IO.nextLine(), 10, 64)
	return a
}

func (IO *IO) scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = IO.nextInt()
		nums = append(nums, num)
	}
	return
}

func (IO *IO) printLn(a ...interface{}) {
	fmt.Fprintln(IO.writer, a...)
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func sumSlice(nums []int) int {
	sum := 0
	for _, n := range nums {
		sum += n
	}
	return sum
}

func binarySearch(target int, list []int) int {
	left := 0
	right := len(list) - 1
	mid := (left + right) / 2

	for {
		if list[mid] < target {
			left = mid + 1
		} else {
			right = mid
		}
		mid = (left + right) / 2
		if left >= right {
			break
		}
	}
	return mid
}

// <<<<<<< functions for 2D array
type array2D [][]int

func (a array2D) Len() int {
	return len(a)
}

func (a array2D) Less(i, j int) bool {
	// return a[i][0] < a[j][0] // sort by 1st arg
	return a[i][1] < a[j][1] // sort by 2nd arg
}

func (a array2D) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a array2D) sort() {
	sort.Sort(a)
}

// >>>>>>> functions for 2D array

var io = newIO()

func main() {
	io.scanner.Split(bufio.ScanWords)       // switch to separating by space
	io.scanner.Buffer([]byte{}, 1000000009) // switch to read large size input
	defer io.writer.Flush()

	N := io.nextInt()
	robots := array2D{}

	for i := 0; i < N; i++ {
		x := io.nextInt()
		arm := io.nextInt()
		robot := []int{x, x + arm}
		robots = append(robots, robot)
	}

	robots.sort()
	count := 0
	lastR := int(-1e10)
	for _, robot := range robots {
		x := robot[0]
		r := robot[1]
		l := x - (r - x)
		if l < lastR {
			count++
		} else {
			lastR = r
		}
	}
	io.printLn(N - count)
}


Measured memory_bytes: 11264
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int m;
  cin>>m;
  vector<int> a(m);
  for(int i=0; i<m; i++){
    cin>>a.at(i);
    n-=a.at(i);
  }
  if(n<0){
    n=-1;
  }
  cout<<n<<endl;
}

Measured memory_bytes: 3640
n,m = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i).sort
ops = m.times.map{gets.chomp.split.map(&:to_i)}.sort_by(&:last).reverse
flag = false
current = 0
ops.each do |b,c|
  (current..current+b-1).each do |i|
    if i < n && as[i] < c
      as[i] = c
    else
      flag = true
      break
    end
  end
  if flag
    break
  else
    current += b
  end
end
puts as.inject(:+)


Measured memory_bytes: 20448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String S = scan.next();
		String T = scan.next();
		int A = scan.nextInt();
		int B = scan.nextInt();
		String U = scan.next();

		if(S.equals(U)) {
			A-=1;
		}else {
			B-=1;
		}

		System.out.println(A+ " " +B);
	}
}

Measured memory_bytes: 21840
#include <bits/stdc++.h> 
#include <iostream>
#include<set>
#include<utility>
using namespace std;
#include<algorithm>
#define ll  long long 
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll int dp[100001];
int main() {
 ll int n;
 cin>>n;
 ll int h[n];
 for(ll int i=0;i<n;i++){
   cin>>h[i];
 }
 dp[2]=abs(h[1]-h[0]);
 dp[1]=0;
 for(ll int i=3;i<=n;i++){
    dp[i]=min(dp[i-1]+abs(h[i-1]-h[i-2]),dp[i-2]+abs(h[i-1]-h[i-3]));
 }
 cout<<dp[n]<<endl;
 
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int x, a, b; cin >> x >> a >> b;
	x -= a;
	while (x - b >= 0) x -= b;
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100005],t[100005];
int gcd(int a,int b){
	int t=b;
	while(t!=0){
		t=a%b;
		a=b;
		b=t;
	}
	return a;
}
int main(){
	int n,m,flag;
	scanf("%d%d",&n,&m);
	scanf("%s",s);
	scanf("%s",t);
	if(s[0]==t[0]){
		if(n!=m){
			int x=gcd(m,n);
			flag=0;
			if(x!=1){
				for(int i=0,j=0;i<m;i+=m/x,j+=n/x){
					if(t[i]==s[j]){
						
					}else{
						cout<<-1<<endl;
						flag=1;
						break;
					}
				}
				if(!flag){
					long long sum=(long long)n*(long long)m/gcd(n,m);
					cout<<sum<<endl;
				}
			}else{
				long long sum=(long long)n*(long long)m/gcd(n,m);
				cout<<sum<<endl;
			}
		}else{
			if(strcmp(s,t)==0){
				cout<<n<<endl;
			}else{
				cout<<-1<<endl;
			}
		}
	}else{
		cout<<-1<<endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
struct pp
{
    int x ,y;
};
int main()
{
    const pp p[]= {{-1,0},{0,1},{1,0},{0,-1}};
    int m ,n ,i ,j ,k ,x ,y;
    scanf("%d%d",&m,&n);
    char a[m][n+2];
    for(i = 0 ; i < m ; i++)
        scanf("%s",a[i]);
    for(i = 0; i < m ; i++)
    {
        for(j = 0 ; j < n; j++)
        {
            if(a[i][j] == '#')
            {
                for(k = 0; k < 4; k++)
                {
                    x = i+p[k].x;
                    y = j+p[k].y;
                    if(x>=0 && x<m && y>=0 && y<n)
                    {
                        if(a[x][y] == '#')
                            break;
                    }
                }
                if(k == 4)
                {
                    printf("No");
                    return 0;
                }
            }
        }
    }
    printf("Yes");
    return 0;
}


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

int main(){
  int N,W;
  cin >> N >> W;
  int v[N],w[N];
  for(int i=1; i<=N; ++i){
    cin >> v[i] >> w[i];
  }

  int V[N+1][W+1] = {};
  for(int i=1; i<=N; ++i){
    V[i][0]=0; // c = w[i]?????´????????????
    for(int c=1; c<=W; ++c){
      V[0][c]=0; // i = 1?????´????????????
      // V[i-1][c-w[i]]?????????????????????????????????c<w[i]??§???i?????°????????????????????§????????????
      if(c-w[i] < 0){
        V[i][c] = V[i-1][c];
        continue;
      }
      V[i][c] = max(V[i-1][c-w[i]]+v[i],V[i-1][c]);
    }
  }

  int ans = 0;
  for(int c=0; c<=W; ++c){
    ans = max(ans, V[N][c]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 7036
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

f = np.array(F)
ans = float('-inf')
for n in range(1, 2**10):
    a = np.array([int(x) for x in bin(n)[2:].rjust(10, '0')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)

Measured memory_bytes: 14460
#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(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;

int main() {
	int N;
	priority_queue<int, vector<int>, greater<int> > pq;
	
	cin >> N;
	REP(i, N) {
		int a, b;
		scanf("%d %d", &a, &b);
		pq.push(a + b);
	}
	
	vector<int> ans;
	while (pq.size() > 1) {
		int a = pq.top(); pq.pop();
		int b = pq.top(); pq.pop();
		
		if (a == b) pq.push(a + 1);
		else {
			pq.push(b);
			ans.push_back(a);
		}
	}
	if (pq.size() > 0) ans.push_back(pq.top());
	
	REP(i, ans.size()) printf("%d 0\n", ans[i], i == ans.size() - 1 ? '\n' : ' ');
	
	return 0;
}

Measured memory_bytes: 3544