akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

bool isPrime(Int n){
  if(n == 0 || n == 1) return 0;
  for(Int i = 2; i * i <= n; i++) if( n % i == 0 ) return 0;
  return 1;
}

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n;
  cin>>n;

  Int ans = 0;
  while(n--){
    Int num;
    cin>>num;
    ans += isPrime(num);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3208
# -*- coding: utf-8 -*-
import math

#入力
A, B, C = map(str, input().split())

if (len(A) == 1) :
  Aend = A
else :
  Aend = A[len(A)-1:len(A)]

if (len(B) == 1) :
  Bstart = B
  Bend = B
else :
  Bstart = B[0:1]
  Bend = B[len(B)-1:len(B)]

Cstart = C[0:1]

if Aend == Bstart and Bend == Cstart :
  print ("YES")
else :
  print ("NO")


Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

const int DEBUG = 0;

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 701;
VI g[N];
int sigma[N][N];

int col[N];
bool vis[N];
PI dfs(int v, int c) {
  if (vis[v]) {
    if (col[v] != c) {
      return PI(-1, -1);
    }
    return PI(0, 0);
  }
  vis[v] = 1;
  col[v] = c;
  int tap = 1, ris = 0;
  for (int w: g[v]) {
    PI sub = dfs(w, 1 - c);
    if (sub.first == -1) return sub;
    tap += sub.second;
    ris += sub.first;
  }
  return PI(tap, ris);
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  REP(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    sigma[a][b] = 1;
    sigma[b][a] = 1;
  }
  REP(i, 0, n) REP(j, 0, n) {
    if (i != j) sigma[i][j] = 1 - sigma[i][j];
  }
  // complement
  REP(i, 0, n) {
    REP(j, 0, n) {
      if (sigma[i][j]) {
        g[i].push_back(j);
      }
    }
  }
  vector<PI> yuki;
  REP(i, 0, n) {
    if (not vis[i]) {
      PI res = dfs(i, 0);
      if (res.first == -1) {
        cout << -1 << endl;
        return 0;
      }
      yuki.push_back(res);
    }
  }
  if (DEBUG) {
    for (PI y: yuki) cerr << " " << y.first << "," << y.second;
    cerr << endl;
  }
  typedef bitset<N> bs;
  bs resha;
  resha[0] = 1;
  for (PI y: yuki) {
    bs tmp = resha << y.first;
    tmp |= resha << y.second;
    resha = tmp;
  }
  int ma = 1e8;
  REP(i, 0, N) {
    if (resha[i]) {
      ma = min(ma, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
    }
  }
  cout << ma << endl;
}


Measured memory_bytes: 4992
import sys
N = int(input())
A = list(map(int,input().split()))

MAX = [1]
for i in range(N):
  #print(MAX[-1],A[i+1])
  MAX.append((MAX[-1]-A[i])*2)
#print(MAX)

ans = A[-1]
mae = A[-1]

if N == 0 and A[0] >= 2:
  print("-1")
  sys.exit()


for i in range(N):
  #print(mae)
  if mae%2 == 0:
    tmin = mae//2
  else:
    tmin = mae//2+1
  if tmin + A[-i-2] > MAX[-i-2]:
    print("-1")
    sys.exit()
  tmax = mae+A[-i-2]
  #print(tmax,MAX[-i-2])
  mae = min(tmax,MAX[-i-2])
  ans += mae
print(ans)
  

Measured memory_bytes: 674488
#include<iostream>
#include<stdio.h>
#include<vector>
#include <map>
#include<cstring>
#include<algorithm>
#include<list>

using namespace std;

short node[10001];
short state_before[10001];
short map_before[10001];

//std::vector< tuple< int,int,int> > points;

map<int,list<pair<int,int>>> points;



void read_points(int tate){
    memcpy(map_before,node,sizeof node);
    memset(node,0,sizeof(node));    
    for(auto tmp:points[tate]){
        node[tmp.first]+=tmp.second;
    }
}
int main(){
    
    int n,r;
    
    int S=0;
    int L=0;

  
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;
        
        points.clear();
        int x1,y1,x2,y2;
        int max_x=0,min_x=10000,max_y=0,min_y=10000;
        for(int i=0;i<n;i++){
            cin>>x1>>y1>>x2>>y2;
            tuple<int,int,int> tl=make_tuple(y1,x1,1);
            tuple<int,int,int> tr=make_tuple(y1,x2,-1);
            tuple<int,int,int> bl=make_tuple(y2,x1,-1);
            tuple<int,int,int> br=make_tuple(y2,x2,1);
            
            if(points.find(y1)==points.end()){
                list<pair<int,int> > tmp;
                points[y1]=tmp;
            }
            if(points.find(y2)==points.end()){
                list<pair<int,int> > tmp;
                points[y2]=tmp;
            }
            points[y1].push_back(make_pair(x1,1));
            points[y1].push_back(make_pair(x2,-1));
            points[y2].push_back(make_pair(x1,-1));
            points[y2].push_back(make_pair(x2,1));
            /*points.push_back(tl);
            points.push_back(tr);
            points.push_back(bl);
            points.push_back(br);
            */

            if(max_x<x2)max_x=x2;
            if(max_y<y2)max_y=y2;
            if(min_x>x1)min_x=x1;
            if(min_y>y1)min_y=y1;
            
            //min_x=0,max_x=11;
            //min_y=0,max_y=11;
            
        }
        
        
        S=0;
        L=0;
        for(int h=min_y;h<=max_y;h++){
            
            read_points(h);
            int yoko_state=0;
            for(int w=min_x;w<=max_x;w++){
                
                //printf("%2d ",node[w]);
                
                yoko_state+=node[w];
                node[w]=yoko_state;
                if(h!=0){
                    node[w]+=state_before[w];
                }
                state_before[w]=node[w];
                //printf("%2d ",node[w]);
                if(node[w]>0){
                   S++;
                   if(w==0)L+=2;
                   else if(node[w-1]==0)L+=2;
                   if(h==0)L+=2;
                   else if(map_before[w]==0)L+=2;
                }
                
                
            }
            //cout<<endl;
            
        }


        cout<<S<<endl;
        if(r==2){
            cout<<L<<endl;
        }
        
        

    }

    

}

Measured memory_bytes: 3148
import sys

def main():
    X, Y = map(int, sys.stdin.readline().split())
    if X == Y:
        print(-1)
        return
    R = 1
    while True:
        R *= X
        if R >= 10**18:
            print(-1)
            return
        if R % Y != 0:
            print(R)
            return

main()

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

#define int long long

string readA,readB,readC;
char idx;
char ans;
//int idxA,idxB,idxC;


signed main(){
    cin >> readA >> readB >> readC;

    idx = readA[0];
    readA.erase(readA.begin());
    while(1){
        if(idx == 'a'){
            ans = 'A';
            if(readA.empty())break;
            idx = readA[0];
            readA.erase(readA.begin());
        }
        else if(idx == 'b'){
            ans = 'B';
            if(readB.empty())break;
            idx = readB[0];
            readB.erase(readB.begin());
        }
        else if(idx == 'c'){
            ans = 'C';
            if(readC.empty())break;
            idx = readC[0];
            readC.erase(readC.begin());
        }
    }

    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define emp emplace
#define fi first
#define se second
#define INF 0x3f3f3f3f
typedef long long ll;
typedef pair<int, int> ii;

int main(void) {
	ios_base::sync_with_stdio(false);

	int n, a; cin >> n >> a;

	n %= 500;

	if (n <= a) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 101
int n,color[N],i,time,d[N],f[N],G[N][N] = {};
 void dfs(void);
void visit(int);
int main(){
  int i,j,k,u,v;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++) {
    scanf("%d%d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      G[u][v] = 1;
     }
  }
   for(u=1;u<=n;u++) color[u] = WHITE;
  dfs();
  
  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}
 void dfs(){
      int u;

  for(u=1;u<=n;u++) if(color[u] == WHITE) visit(u);
  }

void visit(int u){
 int v;
  color[u] = GRAY;
  d[u] = ++time;
  
  for(v=1;v<=n;v++) {
    if(color[v] == WHITE && G[u][v]) visit(v);
  }
  color[u] = BLACK;
  f[u] = ++time;
}


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

long long int N, a[100101], b;

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i){
        scanf("%lld", a + i);
    }
    sort(a, a + N);
    b = (lower_bound(a, a + N - 1, a[N - 1] / 2) - a);
    if(b == 0){
        b = *a;
    }else if(b == N - 1) {
        b = a[N - 2];
    }else{
        b = a[(a[b] + a[b - 1] > a[N - 1]) ? (b - 1) : b];
    }
    printf("%lld %lld\n", a[N - 1], b);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long int
using namespace std;

int n,x;
std::vector<int> v;

int main(int argc, char const *argv[])
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		v.pb(x);
	}
	sort(v.begin(),v.end());
	double ans = (double)(v[0]+v[1])/2.0;
	// cout<<ans<<endl;
	for(int i=2;i<v.size();i++) ans=(ans+(double)v[i])/2.0;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int N; cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int maxi = 0, preMaxi = 0;
	vector<int>checkMax = A;
	sort(checkMax.begin(), checkMax.end());
	maxi = checkMax[N - 1];
	preMaxi = checkMax[N - 2];
	for (int i = 0; i < N; i++) {
		if (A[i] != maxi)cout << maxi << endl;
		else cout << preMaxi << endl;
	}

	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,n) for(int i = (a); i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define debug_v(v,N) for(int i=0;i<N;i++) { cout << v[i] << " "; } cout << endl;
#define debug_vv(v,H,W) for(int i=0;i<H;i++) { for(int j=0;j<W;j++) { cout << v[i][j] << " "; } cout << endl; }

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int five = 2;
	int seven = 1;
	rep(i, 3) {
		int tmp; cin >> tmp;
		if (tmp == 5) five--;
		if (tmp == 7) seven--;
	}
	if (five == 0 && seven == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
using namespace std;
string a[10001],b[10001];
int n;

int s2n(string str){
  int num=0;
  int c = 0;
  
  for(int j=0;j<str.size();j++) {
    if(j == 2) {
      c += num*60*60;
      num = 0;
      continue;
    }
    if(j == 5) {
      c += num*60;
      num = 0;
      continue;
    }
    num *= 10;
    num += str[j]-'0';
    
  }
  c += num;
  return c;
  
}
int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    int time[86401]={};
    int c ,d;
    for(int i=0;i<n;i++) {
      cin >> a[i] >> b[i];
      c = s2n(a[i]);
      d = s2n(b[i]);
      //  cout << c << " "<<d <<endl;
      time[c]++;
      time[d]--;
    }
    int ans=-1;
    for(int i=1;i<=86400;i++){
      time[i] += time[i-1];
      if(time[i] > ans) ans = time[i];
    }
    cout << ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 2648
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define MAXC 1000000000LL

bool chmin(ll& a, ll b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n, m; cin >> n >> m;
  vector<int> a(m), b(m);
  vector<ll> c(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--; c[i] *= -1;
  }

  vector<ll> dist(n, MAXC * (n-1));
  dist[0] = 0;
  for (int i = 0; i < n-1; i++) {
    for (int j = 0; j < m; j++) {
      chmin(dist[b[j]], dist[a[j]] + c[j]);
    }
  }

  vector<bool> negative(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (chmin(dist[b[j]], dist[a[j]] + c[j]) || negative[a[j]]) {
        negative[b[j]] = true;
      }
    }
  }

  if (negative[n-1])
    cout << "inf" << endl;
  else
    cout << -dist[n-1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin>>n;
    vector<ll> a(100005);
    ll sum=0;
    for(int i=0;i<n;i++){
        int ai;
        cin>>ai;
        a[ai]++;
        sum+=ai;
    }
    int q;
    cin>>q;
    vector<ll>b(q),c(q);
    for(int i=0;i<q;i++){
        cin>>b[i]>>c[i];    
    }
    for(int i=0;i<q;i++){
        ll num=a[b[i]];
        sum-=a[b[i]]*b[i];
        sum+=a[b[i]]*c[i];
        cout<<sum<<endl;
        a[b[i]]=0;
        a[c[i]]+=num;
    }
    return 0;
}

Measured memory_bytes: 5592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        System.out.println(solve(A, B));
    }
    public static String solve(int A, int B) {
        if (8 < A) {
            return ":(";
        }
        if (8 < B) {
            return ":(";
        }
        return "Yay!";
    }
}


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

int main(){
  int n; cin >>n;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  sort(a.rbegin(), a.rend());
  int t = n-1;
  ll ans = 0;
  rep(i,n){
    int lim = 2;
    if(i==0) lim = 1;
    rep(j,lim){
      if(t>0){
        ans += a[i];
        t--;
      }
    }
  }
  cout << ans << endl;
  return 0; 
}

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

using namespace __gnu_pbds;  
using namespace std;

typedef long long ll;

typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
os;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

const int N = 55;

int g[N][N];
int dp[N][N][2];
int n, m;

int get(int x, int y) {
  return x == 0 and y == 1;
}

int go(int x, int y, int last) {
  if(x == n - 1 and y == m - 1) {
    return get(last, g[x][y]);
  }
  if(dp[x][y][last] != -1) return dp[x][y][last];
  int gettis = get(last, g[x][y]);
  int cur = 1e9;
  if(x + 1 < n) cur = min(cur, gettis + go(x + 1, y, g[x][y]));
  if(y + 1 < m) cur = min(cur, gettis + go(x, y + 1, g[x][y]));
  return dp[x][y][last] = cur;
}

int main() {
  int n = 3, m = 3;
  int g[3][3];
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cin >> g[i][j];
    }
  }
  int a[3], b[3];
  for(int i = 0; i < 3; i++) {
    b[i] = g[0][i];
    a[i] = g[i][0] - b[0];
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      if(a[i] + b[j] != g[i][j]) {
        print("No");
        return 0;
      }
    }
  }
  print("Yes");
}


Measured memory_bytes: 256
# MAX = 3234566667

# def lunlun?(x)
#   x.to_s.chars.map(&:to_i).each_cons(2).all? do |i,j|
#     (i-j).abs <= 1
#   end
# end

def up!(a,d)
  if a[d+1].nil? #最上位桁
    if a[d] <= 8
      a[d] += 1
    else
      a[d] = 0
      a << 1
    end
  else
    if a[d] <= 8
      if a[d+1] < a[d] # 繰り上がり
        x = up!(a,d+1)
        a[d] = [x-1,0].max
      else
        a[d] += 1
      end
    else # a[d] == 9
      x = up!(a,d+1)
      a[d] = [x-1,0].max
    end
  end
  a[d]
end

k = gets.to_i
a = [0]
k.times do
  up!(a,0)
end

puts a.reverse!.join


Measured memory_bytes: 3836
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,x,y,f[55];
bool b[55][55];
inline int gf(int t){return f[t]==t?t:f[t]=gf(f[t]);}
int main(){
    scanf("%d%d",&n,&m);
    while(m--) scanf("%d%d",&x,&y),b[min(x,y)][max(x,y)]=true;
    for(register int i=1;i<=n;i++)
    for(register int j=i+1;j<=n;j++){
        if(!b[i][j]) continue;
        b[i][j]=false;
        for(register int k=1;k<=n;k++) f[k]=k;
        for(register int k=1;k<=n;k++)
        for(register int p=k+1;p<=n;p++)
        if(b[k][p]) f[gf(k)]=gf(p);
        for(register int k=2;k<=n;k++)
        if(gf(k)!=gf(k-1)){ans++;break;}
        b[i][j]=true;
    }
    printf("%d\n",ans);
    return 0;
}

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

int main(int argc, char const *argv[]) {
  vector<long long int> l(87);
  l.at(0) = 2;
  l.at(1) = 1;
  for(int i = 2;i <= 86;i++) {
    l.at(i) = l.at(i - 1) + l.at(i - 2);
  }
  int n;
  cin >> n;
  cout << l.at(n)<< endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
*l, = map(int,input().split())
pro = 0
amature = set()
for i in l:
  j = i//400
  if j >=8:
    pro+=1
  else:
    amature.add(j)
minans = max([1,len(amature)])
maxans = len(amature) + pro
print(minans, maxans)

Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

struct edge{
	int to,cap,rev;
};

int n,m;
vector<vector<edge> > g;

void add_edge(int u,int v){
	g[u].push_back({v,1,(int)g[v].size()});
	g[v].push_back({u,1,(int)g[u].size()-1});
}

int dfs(int v,vi& used){
	used[v]=1;
	for(int i=0;i<g[v].size();i++){
		edge &e=g[v][i];
		if(e.cap==1||e.cap==2&&!used[e.to]&&dfs(e.to,used)){
			e.cap=0;
			g[e.to][e.rev].cap=2;
			return 1;
		}
	}
	return 0;
}

int main(){
	while(1){
		cin>>n>>m;
		if(!n) break;
		g=vector<vector<edge> >(n);
		for(int i=0;i<m;i++){
			int u,v;
			cin>>u>>v;
			u--;v--;
			add_edge(u,v);
		}
		vi a(n);
		for(int i=0;i<n;i++) for(int j=0;j<n;j++){
			vi used(n);
			a[j]+=dfs(j,used);
		}
		int mn=inf,mx=0;
		for(int i=0;i<n;i++){
			mn=min(mn,a[i]);
			mx=max(mx,a[i]);
		}
		cout<<mn<<' '<<mx<<endl;
	}
}

Measured memory_bytes: 3212
program sample
    implicit none
    character(200000)::s
    integer(8) :: i,j,m,n,a,b,c,d
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)s
    c=1
    d=n
    m=0
    do 
    do i=c,n
        if(s(i:i) .eq. 'W')then
            a=i
            exit
        elseif(i==n)then
            a=n+1
            exit
        end if
    end do
    do i=d,1,-1
        if(s(i:i) .eq. 'R')then
            b=i
            exit
        elseif(i==1)then
            b=0
            exit
        end if
    end do
    if(a<b)then
        m=m+1
        c=a+1
        d=b-1
    else
        exit
    end if
    end do
    
    write(*,*) m
  
    stop
end program sample
  



Measured memory_bytes: 3304
#include <iostream>
#include <vector>
#include <algorithm>

#define INF (1 << 27)

using namespace std;

vector<int> unchi[100005];

int main()
{
    int ans = INF;
    int h, w, n;
    int x, y;
    int maxv[100005] = {};

    cin >> w >> h >> n;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        unchi[y].push_back(x);
    }

    for (int i = h - 1; i >= 0; i--) {
        int mv = 0;

        for (int j = 0; j < unchi[i + 1].size(); j++) {
            mv = max(mv, unchi[i + 1][j]);
        }

        maxv[i] = max(maxv[i + 1], mv);
    }

    for (int i = 0; i < h; i++) {
        ans = min(i + maxv[i], ans);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 8948
n, a, b = map(int,input().split())
x = list(map(int,input().split()))
md = b//a
ans = 0
for i in range(n-1):
    if x[i+1]-x[i] <= md:
        ans += a*(x[i+1]-x[i])
    else:
        ans += b

print(ans)


Measured memory_bytes: 14228
#include <iostream>

using namespace std;

int main()
{
long long d[2000001],a[2000001],i,n;
  cin>>n;
  for(int i=2;i<=n;i++)
  {
      cin>>a[i];
      d[a[i]]++;
  }
  for(int i=1;i<=n;i++)
    cout<<d[i]<<"\n";
  return 0;
}


Measured memory_bytes: 6748
a1,a2,a4=0,0,0

for i in range(1):
    # Start Input code ---------------------------------------
    n=int(input())
    y=map(int,input().split())
    for x in y:
        
        if x%4==0:
            a4+=1
        elif x%2==0:
            a2=1
        else:
            a1+=1
ans='Yes' if a1+a2<=a4+1 else 'No'
print(ans)


Measured memory_bytes: 62704
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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;
}

int main(){
    ll N;cin>>N;
    vector<ll>A(N+1);
    rep(i,N+1){
        cin>>A.at(i);
    }
    vector<ll>Ans(N+1);
    vector<ll>B(N+1);
    B.at(N)=A.at(N);
    for(int i=N-1;i>=0;i--){
        B.at(i)=B.at(i+1)+A.at(i);
    }
    ll sum=1;
    bool flag=true;
    Ans[0]=1;
    rep(i,N){
        Ans[i+1]=min((Ans[i]-A[i])*2,B[i+1]);
        if(Ans[i+1]<=0){
            flag=false;
        }
    }
    rep(i,N){
        if(Ans[i+1]<Ans[i]-A[i]){
            flag=false;
        }
        if(Ans[i+1]<A[i+1]){
            flag=false;
        }
    }
    if(Ans[N]!=A[N]){
        flag=false;
    }
    rep(i,N){
        sum+=Ans[i+1];
    }
    if(flag){
        cout<<sum<<endl;
    }
    else{
        cout<<-1<<endl;
    }
}

    

Measured memory_bytes: 5636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

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

char inp[10][10];
int ok[10][10];

int main()
{
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		cin >> inp[i];
	}
	ok[0][0] = 1;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (inp[i][j] == '#' &&
					i + 1 < H && inp[i + 1][j] == '#' &&
					j + 1 < W && inp[i][j + 1] == '#'
			   ) {
				cout << "Impossible" << endl;
				return 0;
			} else if (inp[i][j] == '#' && !ok[i][j]) {
				cout << "Impossible" << endl;
				return 0;
			} else if (inp[i][j] == '#') {
				ok[i + 1][j] = 1;
				ok[i][j + 1] = 1;
			}
		}
	}
	cout << "Possible" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		String ans = "";

		if ( S.compareTo( "2019/04/30" ) <= 0) {
			ans = "Heisei";
		} else {
			ans = "TBD";
		}

		System.out.println( ans );
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count = 0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='p'&&i%2==0) count -= 1;
    if(s[i]=='g'&&i%2==1) count += 1;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
	}

	ans := int(10e8)
	for i := 0; i <= n-k; i++ {
		cost := min(abs(x[i])+abs(x[i+k-1]-x[i]), abs(x[i+k-1])+abs(x[i]-x[i+k-1]))
		if cost < ans {
			ans = cost
		}
	}
	fmt.Println(ans)
}

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

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

Measured memory_bytes: 6272
import static java.lang.Long.parseLong;

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = parseLong(sc.next()) - 1;
    StringBuilder sb = new StringBuilder();
    while (n >= 26) {
      sb.insert(0, (char) ('a' + n % 26));
      n /= 26;
      n--;
    }
    sb.insert(0, (char) ('a' + n));
    System.out.println(sb);
  }
}

Measured memory_bytes: 27028
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>

using namespace std;
int main(void){
    // Your code here!
long long int N,K;
cin >> N >> K;
long long int l;
l = pow(K-1,N-1) * K;
cout << l << endl;
}


Measured memory_bytes: 512
N = int(input())
a = list(map(int, input().split()))
a.sort()
rui = [0] * (N + 1)
for i in range(1, N + 1):
    rui[i] = rui[i - 1] + a[i - 1]

cnt = 1
for i in reversed(range(1, N)):
    if 2 * (rui[i]) >= a[i]:
        cnt += 1
    else:
        break

print(cnt)

Measured memory_bytes: 14224
#include <iostream>
#include <vector>
#include <numeric>

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long x; cin >> x;

    long long num_a = (x / 11) * 2;

    if (x % 11 == 0) {
    }
    else if (x % 11 > 6) {
        num_a += 2;
    }
    else {
        num_a += 1;
    }

    cout << num_a << endl;
}

Measured memory_bytes: 256
/* Jay Solanki */

#include <ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
typedef long long int ll;
#define pii pair<ll, ll>
#define pb push_back
#define pf push_front
#define F first
#define S second
#define mp make_pair
#define For(i,a,b) for(ll i=a;i<b;i++)
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll mode = 1e9 + 7;

int modInverse(int a, int m)
{

    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

ll power(ll x,ll y){
    ll res = 1;
    x = x % mode;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mode;
        y = y>>1;
        x = (x*x) % mode;
    }
    return res;
}

int main()
{
    FAST;
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n,c=0,k=1,y=0,x=0,z=0;
        cin>>n;
        // string s;
        // cin>>s;
        vector<ll> v(n),ans(n);
        For(i,0,n) cin>>v[i];
        ans[0]=0;
        for(int i=1;i<n;i++)
        {
            if(i==1) ans[i]=abs(v[i-1]-v[i]);
            else
                ans[i]=min(ans[i-1]+abs(v[i]-v[i-1]),ans[i-2]+abs(v[i]-v[i-2]));
        }
        cout<<ans[n-1];
    }
    return 0;
}

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

void trace(vector<int> A, int N){
    for(int i = 0; i < N; i++ ){
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(vector<int> A, int N){
    int v, j;

    for (int i = 1; i < N; i++){
        v = A[i];
        j = i -1;

        while (j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        
        }
        A[j + 1] = v;
        trace(A, N);

    }
}

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

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

    trace(A, N);
    insertionSort(A, N);

    
}


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

int main(int argc, char const *argv[])
{
  double a, b, C;
  cin >> a >> b >> C;
  double S, L, h;
  S = a*b/2*sin(C*M_PI/180);
  L = a + b + sqrt(a*a+b*b-2*a*b*cos(C*M_PI/180));
  h = 2*S/a;
  cout << fixed << setprecision(10) << S << endl
       << L << endl
       << h << endl;
  return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

int main(){
	int n;cin>>n;
	int now=1e9;
	int ans=0;
	for(int i=0;i<n;i++){
		int a;cin>>a;
		if(a<now){
			ans++;
			now=a;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, A: "List[int]"):
    while len(A) != 1:
        A.sort(reverse=True)
        while A[-1] == 0:
            A.pop()
        for i in range(len(A) - 1):
            A[i] %= A[-1]
    return A[0]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, A)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 17872
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    k, n = map(int, readline().rstrip().split())
    A = sorted(list(map(int, readline().rstrip().split())))
    maxA = k + A[0] - A[n-1]
    for i in range(n-1):
        a = abs(A[i+1] - A[i])
        maxA = max(maxA, a)
    print(k - maxA)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33912
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    s = list(input()[:-1].decode())
    pre_si = s[0]
    s2 = [pre_si]
    for i in range(1, n):
        if s[i] != pre_si:
            s2.append(s[i])
            pre_si = s[i]

    print(len(s2))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 49520
N,A,B,C = map(int, input().split())
l = [0]*N
for i in range(N):
    l[i] = int(input())
def dfs(i,a,b,c):
    if i == N:
        if a==0 or b==0 or c==0:
            return 100000
        else:
            return abs(A-a)+abs(B-b)+abs(C-c)-30
    else:
         return min(dfs(i+1,a+l[i],b,c)+10, dfs(i+1,a,b+l[i],c)+10, dfs(i+1,a,b,c+l[i])+10, dfs(i+1,a,b,c))

print(dfs(0,0,0,0))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;

int main()
{
	int n;
	cin>>n;
	multiset<int> all;
	for(int i=0,tmp;i<n;i++)
	{
		cin>>tmp;
		all.insert(tmp);
	}
	int ans=0;
	while(all.size())
	{
		auto cur=all.rbegin();
		int val=*cur;
		all.erase(all.find(*cur));
		for(int i=0;i<31;i++)
		{
			if((1<<i)<=val) continue;
			if(all.count((1<<i)-val))
			{
				all.erase(all.find((1<<i)-val));
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 9600
//解説AC
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;

vector<string> split(const string& s, char d=' ')
{
    vector<string> vs;
	//string::size_type stringの要素のインデックスを指す専門のやつ
    string::size_type l = 0;
    for (string::size_type i = 0; i < s.size(); i++) {
        if (s[i] == d) {
            string now = s.substr(l,i-l);
				if(now.size()!=0)
					vs.push_back(now);
            l = i + 1;
        }
    }
	if(s.substr(l,s.size()-l).size()!=0)
    	vs.push_back(s.substr(l, s.size()-l));
    return vs;
}

int main(){
	int n;
	int nf=0; //2の倍数を除く4の倍数の数
	int nt=0; //2の倍数の数
	int ne=0; //2の倍数でも4の倍数でもない数
	bool can = false; //可能か
	cin >> n;
	rep(i,n){
		int input;
		cin >> input;
		if(input%4==0) nf++;
		else if(input%2==0) nt++;
		else ne++;
	}
	if(nt==0){
		if(ne-1<=nf){
			can = true;
		}
	}
	else{
		ne++;
		if(ne-1<=nf){
			can = true;
		}
	}
	if(can){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int A,B,C,D,E,sum=0;

	scanf("%d %d %d %d %d",&A,&B,&C,&D,&E);

	if(A<0){
		sum=C*(0-A)+D;
		A=0;
	}

	sum+=(B-A)*E;

	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1748
#!/usr/bin/env python3
import sys


def solve(S: int):
    def divisor(n): #nの約数を全て求める

        i = 1
        while i * i <= n:
            if n%i == 0:
                if 0<= i <= 10**9 and 0 <= n//i <=10**9:
                    return i
            i += 1
    # 0 0 a b c d

    if int(S**(1/2))**2 == S:
        half  =int(S**(1/2))
        b = c = 0
    else:
        half = int(S**(1/2))+1
        res = half**2-S
        num = divisor(res)
        b = num
        c = res//num

    a = d = half 

    print(0,0,a,b,c,d)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n,a,b=map(int,input().split())
x=list(map(int,input().split()))

xx=[]
ans=0
for i in range(n-1):
    xx.append(a*(x[i+1]-x[i]))


for i in range(len(xx)):
    if xx[i]<b:
        ans+=xx[i]
    else:
        ans+=b
print(ans)

Measured memory_bytes: 20000
#include <bits/stdc++.h>
using namespace std;
 
//#define READ_NUMBER(i) scanf("%d",i)
 
int main(){
	int n;
	int count = 1;
	cin >> n;
	if(n == 4 || n == 2 || n == 1){
		
	}else{
		while(true){
			if(n % 2 == 0){
				n = n / 2;
			}else{
				n = n * 3 + 1;
			}
			count++;
			if(n == 4){
				break;
			}
		}
	}
	cout << count + 3 << endl;
}

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

int main() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  if (n*2 < m) {
    long long remain_c = m - n*2;
    printf("%lld\n", n + (remain_c / 4));
  } else {
    printf("%lld\n", min(n, m/2));
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;

typedef long long ll;

int main(){
	int n;

	char s[5];
	scanf(" %s", s);

	if(s[0] == s[1] && s[1] == s[2]) printf("No\n");
	else printf("Yes\n");

	return 0;
}

Measured memory_bytes: 256
def m_d(a, b)
  (a[0] - b[0]).abs + (a[1] - b[1]).abs
end

N, M = gets.split(" ").first(2).map(&:to_i)
Students = N.times.map{
  gets.split(" ").first(2).map(&:to_i)
}
Checkpoints = M.times.map{
  gets.split(" ").first(2).map(&:to_i)
}

Students.each{|st|
  # チェックポイントとの距離一覧
  m_ds = Checkpoints.map{|ch|
    m_d(ch, st)
  }
  # 番号の最も小さいチェックポイント
  puts m_ds.index(m_ds.min)+1
}


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

map<pair<int,int>, int> m1;
pair<int,int> mp;

int main(){
	int st1[205][2],st2[1005][2];
	int n,m;
	int i,j,k;
	
	while(cin>>m && m!=0){
		for(i=0;i<m;i++){
			cin>>st1[i][0]>>st1[i][1];
		}
		cin>>n;
		for(i=0;i<n;i++){
			cin>>st2[i][0]>>st2[i][1];
		}
		for(i=0;i<m;i++){
			for(j=0;j<n;j++){
				m1[make_pair(st2[j][0]-st1[i][0],st2[j][1]-st1[i][1])]++;
			}
		}
		for(map<pair<int,int>,int>::iterator itr=m1.begin();itr!=m1.end();itr++){
			if(itr->second==m){
				cout<<(itr->first.first)<<" "<<(itr->first.second)<<endl;
				break;
			}
		}
		m1.clear();
	}
	return 0;
}

Measured memory_bytes: 15548
h,w=map(int,input().split())
s=[list(input())for i in range(h)]
dx=[1,1,0,-1,-1,-1,0,1]
dy=[0,1,1,1,0,-1,-1,-1]
for i in range(h):
    for j in range(w):
        cnt=0
        if s[i][j]==".":
            for k in range(8):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x and x<h and 0<=y and y<w and s[x][y]=="#":
                    cnt+=1
            s[i][j]=str(cnt)
for i in s:
    print(*i,sep="")

Measured memory_bytes: 3572
n = gets.to_i

robot = []
n.times {robot << gets.split.map(&:to_i)}
robot.sort_by!{|x, l| x + l}

pre = robot[0][0] - robot[0][1]
ans = 0

robot.each do |x, l|
    if pre <= x - l
        ans += 1
        pre = x + l
    end
end

puts ans

Measured memory_bytes: 12664
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int jumpLength = sc.nextInt();
        int[] highs = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            highs[i] = sc.nextInt();
        }
        int[] leastCostAt = new int[n + 1];
        leastCostAt[1] = 0;
        leastCostAt[2] = Math.abs(highs[2] - highs[1]);
        for (int i = 3; i <= n; i++) {
            int[] costOfPlan = new int[jumpLength];
            Arrays.fill(costOfPlan,99999999);
            for (int j = 0; j < jumpLength; j++) {
                if (i - 1 - j == 0) break;
                costOfPlan[j] = leastCostAt[i - 1 - j] + Math.abs(highs[i] - highs[i - 1 - j]);
            }
            
            Arrays.sort(costOfPlan);
            leastCostAt[i] = costOfPlan[0];
        }
        System.out.println(leastCostAt[n]);
    }
}

Measured memory_bytes: 63016
import numpy as np
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N=int(input())
b=[]
for i in range(0,N):
    d=int(input())
    b.append(d)
c1=[False,False,False]
c2=[False,False,False]
c3=[False,False,False]

for j in range(0,N):
    for k in range(0,3):
        if A1[k]==b[j]:
            c1[k]=True
        if A2[k]==b[j]:
            c2[k]=True
        if A3[k]==b[j]:
            c3[k]=True
if c1[0]==True and c1[1]==True and c1[2]==True:
    print("Yes")
elif c2[0]==True and c2[1]==True and c2[2]==True:
    print("Yes")
elif c3[0]==True and c3[1]==True and c3[2]==True:
    print("Yes")
elif c1[0]==True and c2[0]==True and c3[0]==True:
    print("Yes")
elif c1[1]==True and c2[1]==True and c3[1]==True:
    print("Yes")
elif c1[2]==True and c2[2]==True and c3[2]==True:
    print("Yes")
elif c1[0]==True and c2[1]==True and c3[2]==True:
    print("Yes")
elif c3[0]==True and c2[1]==True and c1[2]==True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 21284
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"

const int N = 2e5;

int n, h[N], dp[N];

int main () {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> h[i];
	}		
	dp[2] = abs(h[2] - h[1]);
	for(int i = 3; i <= n; ++i) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    long N=sc.nextLong();
    int m=1000000007;
    long ans=1;
    int i=1;
    while(i<=N) {
      ans=(i*ans) %m;
      i++;
    }
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ul=unsigned long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
template<class C>
struct rev{
    C &c;
    explicit rev(C &x):c(x){}
    auto begin(){return c.rbegin();}
    auto end(){return c.rend();}
};

void solve(){
    int n;
    cin>>n;
    vector<ul> a(n);
    set<ul> base;
    for(auto&i:a) cin>>i;
    string s;
    cin>>s;
    ifr(i,n){
        for(auto&v:rev(base)) chmin(a[i],a[i]^v);
        if(a[i]){
            if(s[i]=='0') base.insert(a[i]);
            else{
                cout<<1<<'\n';
                return;
            }
        }
    }
    cout<<0<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    fr(i,t) solve();
}


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

#define int long long

using namespace std;

const int N = 2e5 + 10, INF = 1e18;

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    int h, w, k, x1, x2, y1, y2;
    cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
    --x1, --x2, --y1, --y2;
    int d[h][w][4];
    char c[h][w];
    for (int i = 0; i < h; ++i)
    {
        cin >> c[i];
        for (int j = 0; j < w; ++j)
        {
            for (int w = 0; w < 4; ++w)
            {
                d[i][j][w] = 1e18;
            }
        }
    }
    int u[] = {0, 0, 1, -1};
    int v[] = {1, -1, 0, 0};
    queue<pair<int, pair<pair<int, int>, pair<int, int>>>> q;
    for (int i = 0; i < 4; ++i) 
    {
        d[x1][y1][i] = 0;
    }
    q.push({0, {{-1, 0}, {x1, y1}}});
    while (!q.empty())
    {
        auto z = q.front();
        q.pop();
        int dis = z.second.first.second;
        int dir = z.second.first.first;
        int x = z.second.second.first;
        int y = z.second.second.second;
        if (dir != -1 && d[x][y][dir] < z.first) continue;
        for (int idx = 0; idx < 4; ++idx)
        {
            int i = x + u[idx];
            int j = y + v[idx];
            if (!(i >= h || j >= w || i < 0 || j < 0 || c[i][j] == '@')) 
            {
                int cur = dis;
                if (dir == -1 || dir != idx) cur  = ((cur + k - 1) / k) * k;
                if (d[i][j][idx] > cur + 1) 
                {
                    d[i][j][idx] = cur + 1;
                    q.push({d[i][j][idx], {{idx, cur + 1}, {i, j}}});
                }
            }
        }
    }
    int ans = 1e18;
    for (int i = 0; i < 4; ++i)
    {
        ans = min(ans, d[x2][y2][i]);
    }
    if (ans == INF) cout << -1;
    else cout << (ans + k - 1) / k;
    return 0;
}

Measured memory_bytes: 35984
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M;
struct Edge{ll to,cost;};
vector<Edge> edgeList[100010];
ll d[100010];
int main(){
    cin>>N>>M;
	for(ll i=0;i<M;i++){
		ll l,r,c;cin>>l>>r>>c;
		l--;r--;
		edgeList[l].push_back(Edge{r,c});
	}
	for(ll i=1;i<N;i++){
		edgeList[i].push_back(Edge{i-1,0});
		d[i]=INF;
	}
	d[0]=0;	
	priority_queue<P,vector<P>,greater<P>> pq;
	pq.push(P(0,0));
	while(!pq.empty()){
		ll now=pq.top().second;
		ll nowC=pq.top().first;pq.pop();
		if(nowC>d[now])continue;
		for(auto e:edgeList[now]){
			ll newC=nowC+e.cost;
			if(d[e.to]>newC){
				d[e.to]=newC;
				pq.push(P(newC,e.to));
			}
		}
	}
	cout<<((d[N-1]==INF)?(-1):d[N-1]);
    return 0;
}

Measured memory_bytes: 9340
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();
		int M = scan.nextInt();
		int X = scan.nextInt();

		int[][] A = new int[N][M];
		int[] C = new int[N];

		for (int i = 0; i < N; i++) {
			C[i] = scan.nextInt();
			for (int j = 0; j < M; j++) {
				A[i][j] = scan.nextInt();
			}
		}

		//WK変数
		int result = -1;

		//演算
		l1: for (int i = 0; i < Math.pow(2, N); i++) {
			int sum = 0;
			int price = 0;
			for (int j = 0; j < M; j++) {
				sum = 0;
				price = 0;
				for (int i1 = 0; i1 < N; i1++) {
					sum += A[i1][j] * ((int) (i % Math.pow(2, i1 + 1)) / (int) Math.pow(2, i1));
					price += C[i1] * ((int) (i % Math.pow(2, i1 + 1)) / (int) Math.pow(2, i1));
				}

				if (sum < X) {
					continue l1;
				}
			}

			if (price != 0 && (result == -1|| result > price)) {
				result = price;
			}
		}

		//結果出力
		System.out.println(result);
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> s(n);
  rep(i,n) cin >> s[i];
  sort(s.rbegin(),s.rend());
  int a = 0;
  int b = 0;
  rep(i,n){
    if(i % 2 == 0){
      a += s[i];
    }
    else b += s[i];
  }
  cout << a-b << endl;
  return 0;
}


Measured memory_bytes: 256