akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
namespace io{
    const int l=1<<20;
    char buf[l],*s,*t,c;
    inline void gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            c=s==t?EOF:*s++;
        }else c=*s++;
    }
    template<class IT>inline void gi(IT &x){
        x=0;gc();while(c<'0'||c>'9')gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
    }
    char buf0[20];int a;
    template<class IT>inline void pi(IT x){
        if(x<0){putchar('-');x=-x;}
        do buf0[++a]=x%10+48;while(x/=10);
        while(a)putchar(buf0[a--]);
        putchar('\n');
    }
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
typedef vector<int> vi;
typedef vector<ll > vl;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=3005;
const ll p=1000000007ll;
ll d[N][N];int x[N];
inline void mean(ll &a,ll &b){
	ll c=(a+b)*500000004ll%p;
	a=b=c;
}
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,q,i,j,k;ll s=0ll,t=1ll;
    scanf("%d%d",&n,&q);
    rep(i,1,n)scanf("%d",&x[i]);
	rep(i,1,n)rep(j,1,n)if(x[i]<x[j])d[i][j]=1ll;
	//rep(i,1,n){rep(j,1,n)printf("%lld ",d[i][j]);puts("");}puts("");
	while(q--){
		if((t<<=1)>=p)t-=p;
		scanf("%d%d",&i,&j);
		mean(d[i][j],d[j][i]);
		rep(k,1,n)if(k!=i&&k!=j)mean(d[i][k],d[j][k]);//printf("%d %d %d %d\n",i,k,j,k);
		rep(k,1,n)if(k!=i&&k!=j)mean(d[k][i],d[k][j]);//printf("%d %d %d %d\n",k,i,k,j);
		//rep(i,1,n){rep(j,1,n)printf("%lld ",d[i][j]*t%p);puts("");}puts("");
	}
	rep(i,2,n)REP(j,1,i)s+=d[i][j];
	printf("%lld",(s%p)*t%p);
    return 0;
}

Measured memory_bytes: 70656
n, k = map(int,input().split())
yokolist = list(map(int, input().split()))

expect_list = [((1+yokolist[i])/2) for i in range(n)]

#print(expect_list)

answer = 0
l = expect_list[0:k]
p = sum(l)
for j in range(n-k+1):
    if p > answer:
       answer = p
    if j != n-k:
        p = p - expect_list[j] + expect_list[k+j]

print(answer)

Measured memory_bytes: 24548
def main():
    n, w = tuple([int(e) for e in input().split()])
    items = []
    for i in range(n):
        items.append(tuple([int(e) for e in input().split()]))
    
    t = [[0] * (n + 1) for _ in range(w + 1)]
    for i in range(1, w + 1):
        for j in range(1, n + 1):
            if i - items[j - 1][0] >= 0:
                t[i][j] = t[i - items[j - 1][0]][j - 1] + items[j - 1][1]
            t[i][j] = max(t[i][j], t[i][j - 1], t[i - 1][j], t[i - 1][j - 1])
    print(t[w][n])
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 130652
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vec{
    double x, y;
};
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;
}
template<class T>
T min(T a, T b)
{
    if (a < b) return a;
    return b;
}
template<class T>
T max(T a, T b)
{
    if (a > b) return a;
    return b;
}
using namespace std;
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    int N;
    cin >> N;
    cout << (1000 - N % 1000)%1000 << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()


int main(){
  ll N,m=0,ans=0;
  cin >> N;
  vec A(N);
  rep(i,N){
    cin >> A.at(i);
    if(m>A.at(i)){
      ans+=m-A.at(i);
    }
    m=max(m,A.at(i));
  }
  cout << ans << endl;
}

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

int main() {
  int a,b,x;
  cin >> a >> b >> x;
  if(a <= x && a + b >= x) puts("YES");
  else puts("NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, __start, __end) for(ll i_=(ll)__start; i_<(ll)__end; i_++)
#define print(_a) cout << _a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");


int main(){
    ll n, ans=1000000000001;
    cin >> n;

    for(ll i=1; i*i <= n; i++){
      if(n % i == 0){
        ans = min(ans, i + n/i - 2);
      }
    }
    print(ans);
    
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(f.readLine());
        HashMap<Integer, Integer> nums = new HashMap<Integer, Integer>();
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        long sum = 0;
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(tokenizer.nextToken());
            sum += num;
            if (!nums.containsKey(num)) {
                nums.put(num, 0);
            }
            nums.put(num, nums.get(num) + 1);
        }

        int q = Integer.parseInt(f.readLine());
        for (int q1 = 0; q1 < q; q1++) {
            tokenizer = new StringTokenizer(f.readLine());
            int b = Integer.parseInt(tokenizer.nextToken());
            int c = Integer.parseInt(tokenizer.nextToken());

            Integer numOf = nums.get(b);
            if (numOf == null) numOf = 0;
            sum += (long) numOf * c;
            sum -= (long) numOf * b;
            nums.put(b, 0);
            if (!nums.containsKey(c)) {
                nums.put(c, 0);
            }
            nums.put(c, nums.get(c) + numOf);

            out.println(sum);
        }


        out.close();
    }
}


Measured memory_bytes: 62968
#include <cstdio>

using namespace std;

int main()
{
    int n,r=0,l=0,i,x=0,y=0;
    char a[105];
    scanf("%d",&n);
    getchar();
    for(i=0;i<n;i++)
        scanf("%c",&a[i]);
    for(i=0;i<n;i++)
    {
        if(a[i]==')')
        {
            if(r!=0) r--;
            else x++;
        }
        if(a[i]=='(') r++;
    }
    for(i=0;i<x;i++)
         printf("(");
    for(i=0;i<n;i++)
        printf("%c",a[i]);
    for(i=0;i<r;i++)
         printf(")");
    return 0;
}


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

int main(void){
    int n;
    int i;
    int card[4][13] = {{0}};
    cin >> n;
    char a;
    int b;
    for (i = 0; i < n; i++){
        cin >> a >> b;
        switch(a){
        case 'S':
            card[0][b - 1] = 1;
            break;
        case 'H':
            card[1][b - 1] = 1;
            break;
        case 'C':
            card[2][b - 1] = 1;
            break;
        case 'D':
            card[3][b - 1] = 1;
            break;
        }
    }
    for (i = 0; i < 4; i++){
        for ( int j = 0; j < 13; j++){
            if (card[i][j] == 0){
                switch(i){
                case 0:
                    cout << "S" << " " << j + 1 << endl;
                    break;
                case 1:
                    cout << "H" << " " << j + 1 << endl;
                    break;
                case 2:
                    cout << "C" << " " <<j + 1 << endl;
                    break;
                case 3:
                    cout << "D" << " " <<j + 1 << endl;
                    break;
                }
            }
        }
    }
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#include <boost/multiprecision/cpp_int.hpp> 
using boost::multiprecision::cpp_int; 
 
#define ff              first
#define ss              second
// #define ll 				long long int
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define modp            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
// void aks()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }


void solve()
{
	cpp_int a; double b;
	cin >> a >> b;
	b = ((b)*(1000.0000000000000000));
	cpp_int bb = (cpp_int)b;
	cpp_int aa = a;
	cpp_int aans = (aa*bb);
	cpp_int t = aans/1000;
	cout << t << endl;

}
 
int32_t main()
{
	FIO
    //aks();
    //w(t)
    {
    	solve();
    }
    return 0;
}
	

Measured memory_bytes: 3892
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string S, T;
  cin >> S >> T;
  int len = S.length();
  bool ans = false;
  for (int i = 0; i < len; i++) {
    int p;
    for (p = 0; p < len; p++) {
      if (S[p] != T[(p+i)%len]) break;
    }
    if (p == len) ans = true;
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,a;
  int kaisu = 0;
  int maekaisu = 0;
  
  cin >> N;
  
  for (int i=0; i<N; i++) {
    cin >> a;
    
    while (!(a % 2)) {
      if (!(a % 2)) {
         a = a / 2;
         kaisu++; 
      }
    }
    
    if (i==0 || kaisu < maekaisu) {
      maekaisu = kaisu;
    }
    
    kaisu = 0;
  }

  cout << maekaisu << endl;
    
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> ans = a;
    sort(ans.rbegin(), ans.rend());
    rep(i, n)
    {
        if (a[i] == ans[0])
        {
            cout << ans[1] << endl;
        }
        else
        {
            cout << ans[0] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int a, b;
  vector<int> v;
  cin >> a >> b;
  v.push_back(a+b);
  v.push_back(a-b);
  v.push_back(a*b);
  sort(v.begin(), v.end());
  cout << v[2] << endl;
  return 0;
}


Measured memory_bytes: 256
//Author:- S_Aditya

#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 tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;         
const int N=16;

//dp[mask] tells the maximum profit if the subsets of rabbits represented by mask
//are already grouped.

//profit[mask] tells the total profit we get if we put all the rabbits represented by
//mask in a single group

ll dp[1<<N],profit[1<<N];

void rec(int ind,vector<int> &not_taken,int mask,ll sum_till_now,int new_group)
{
    if(ind==(int)not_taken.size())
    {
        dp[mask]=max(dp[mask],sum_till_now+profit[new_group]);
        
        return;
    }
    
    //take the rabbit represented by ind in our new group
    rec(ind+1,not_taken,mask^(1<<not_taken[ind]),sum_till_now,
                                                  new_group^(1<<not_taken[ind]));
    
    //do not take this rabbit in the new group
    rec(ind+1,not_taken,mask,sum_till_now,new_group);
}

int main()                  
{
    int n;
    
    scn(n);
    
    int cost[n][n];
    
    rep(i,0,n)
    {
        rep(j,0,n)
        scn(cost[i][j]);
    }
    
    //I can keep all dp values initially 0 as we can get a profit of zero if we give
    //each rabbit a distinct group
    
    //preprocess the profit array
    for(int mask=0;mask<(1<<n);mask++)
    {
        for(int i=0;i<n;i++)
        if(mask&(1<<i))
        {
            for(int j=i+1;j<n;j++)
            if(mask&(1<<j))
            profit[mask]+=1LL*cost[i][j];
        }
    }
    
    //iterate over already taken masks
    for(int mask=0;mask<(1<<n);mask++)
    {
        vector<int> not_taken;
        
        for(int i=0;i<n;i++)
        if(!(mask&(1<<i)))
        not_taken.pb(i);
        
        //recurse over forming a new group of some subset
        //from those who are not already taken
        
        rec(0,not_taken,mask,dp[mask],0);
    }
    
    //ans will be in all bits set mask as we have to give each rabbit exactly one group
    printf("%lld ",dp[(1<<n)-1]);
} 

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define vi vector<int> 
#define pb push_back
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vii vector<pii>
#define MAX (int)(1e7+5)
#define int long long
using namespace std;

void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define see(x...)                 \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define see(x...)
#endif
const int MOD = (int)(1e9+7);
int I_fpow(int x,int y,int p = MOD){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;}

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

    vi a(n);
    int flg = 0;
    for(int i=0;i<n;i++) cin>>a[i], flg += (a[i] == 0);

    if((n%2 == 0 && flg) || (flg > 1)) return cout<<0 ,0;
    set<int> s;
    for(int i=0;i<n;i++) s.insert(a[i]);
    int g = n/2;
    if(n%2) g++;
    if(s.size() != g) return cout<<0,0;
    vi v;
    for(auto i : s) v.pb(i);
    int flag = 0;
    for(int i=0;i<v.size()-1;i++) {
        if(v[i+1]-v[i] != 2) flag = 1;
    }
    if(flag) return cout<<0,0;
    if(n%2 && v[0] == 0) cout<<I_fpow(2,n/2);
    else if(n%2 == 0 && v[0] == 1) cout<<I_fpow(2,n/2);
    else cout<<0;
    return 0; 
}

Measured memory_bytes: 3968
#include<stdio.h>

int n, k;
int x;

int main(void)
{
	int ans;
	
	scanf( "%d %d", &n, &k );
	
	ans = 0;
	while( n-- ) {
		scanf( "%d", &x );
		
		if ( k < x || k-x < x ) {
			if ( k < x ) {
				ans += x - k;
			}
			else {
				ans += k - x;
			}
		}
		else {
			ans += x;
		}
	}
	
	printf( "%d\n", ans * 2);
	
	return 0;
}

Measured memory_bytes: 128
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
best = 0
D = 100000
for i in range(N):
    t = T - H[i] * 0.006
    d = abs(A - t)
    if d < D:
        D = d
        best = i + 1

print(best)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PR;

int N, W, H;
int xx[100002], yy[100002];

int main()
{
	scanf("%d %d %d", &N, &W, &H);
	for (int i = 0; i < N; i++){
		int x, y, w;
		scanf("%d %d %d", &x, &y, &w);
		int sx = max(x - w, 0);
		int ex = min(x + w, W);
		int sy = max(y - w, 0);
		int ey = min(y + w, H);
		xx[sx]++;
		xx[ex]--;
		yy[sy]++;
		yy[ey]--;
	}
	for (int i = 0; i < W; i++){
		xx[i + 1] += xx[i];
	}
	for (int i = 0; i < H; i++){
		yy[i + 1] += yy[i];
	}
	bool resx = true;
	for (int i = 0; i < W; i++){
		resx &= !!xx[i];
		//printf("%d ", xx[i]);
	}
	//puts("");
	bool resy = true;
	for (int i = 0; i < H; i++){
		resy &= !!yy[i];
		//printf("%d ", yy[i]);
	}
	//puts("");
	puts(resx | resy ? "Yes" : "No");
}

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

int main() {
    int N, Q;
    cin >> N;
    long long sum = 0;
    vector<long long> bucket(110000, 0);
    for (int i = 0; i < N; ++i) {
        long long A; cin >> A;
        sum += A;
        bucket[A]++;
    }
        
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        long long B, C; cin >> B >> C;
        sum += (C - B) * bucket[B];
        bucket[C] += bucket[B];
        bucket[B] = 0;
        cout << sum << endl;
     }
     return 0;
}

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;

ll div_ceil(ll a, ll b){
	return (a+b-1)/b;
}

int main(){
	ll v[2][2];
	fr(cor,2) scanf("%lld%lld", v[cor],v[cor]+1);
	
	ll g1 = div_ceil(v[1][0],v[0][1]);
	ll g2 = div_ceil(v[0][0],v[1][1]);
	
	if(g1<=g2) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 3760
# -*- coding: utf-8 -*-
from operator import mul
from functools import reduce

def combination(n, r):
    if n < r:
        return 0
    else:
        r = min(n-r, r)
        if r == 0:
            return 1
        else:
            over = reduce(mul, range(n, n-r, -1))
            under = reduce(mul, range(1, r+1))
            return over // under

n = int(input())
s = {}
for i in range(n):
    str = ''.join(sorted(input()))
    if str in s.keys():
        s[str] += 1
    else:
        s[str] = 1
ans = 0
for i in s:
    ans += combination(s[i], 2)
print(ans)


Measured memory_bytes: 18340
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <cstdio>
#include <cstdint>
#include <cmath>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<ll> H;
    rep(i, N)
    {
        ll h;
        cin >> h;
        H.push_back(h);
    }
    vector<bool> h(N, true);
    rep(i, M)
    {
        ll a,b;
        cin >> a >> b;
        --a;
        --b;
        if (H[a] <= H[b]) h[a] = false;
        if (H[a] >= H[b]) h[b] = false;
    }
    ll ans = 0;
    rep(i, N)if (h[i]) ++ans;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3912
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

  ll n;cin >> n;

  vll a(n),b(n),c(n,0);

  rep(i,n) cin >> a[i] >> b[i];

  for(ll i = n-1; i >= 0; --i)
  {
    if(i == n - 1)
    {
      c[i] = kiriage(a[i],b[i]) * b[i] - a[i];
    }
    else
    {
      ll buf = kiriage(a[i] + c[i+1], b[i]) * b[i];
      c[i] = buf - a[i];
    }
  }

  cout << c[0] << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  u64 n;
  cin >> n;
  l64 a[n], b[n];
  for (u64 i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  l64 cnt = 0;
  for (l64 i = n-1; i>=0; --i) {
    if (a[i]+cnt == 0) continue;
    cnt+=((a[i]+cnt-1)/b[i]+1)*b[i]-(a[i]+cnt);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  int n;
  cin >> n;
  int tmp = n % 100;
  n /= 100;
  
  REP(i,0,n+1){
    REP(j,0,n+1){
      REP(k,0,n+1){
        REP(l,0,n+1){
          REP(m,0,n+1)REP(nn,0,n+1){
            if(nn * 0 + i * 1 + j * 2 + k * 3 + l * 4 + m * 5 == tmp && nn+i+j+k+l+m == n){
              cout << 1 << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
s = raw_input()
n = len(s)
if n == 1:
    print 1
    exit()
if not n & 1:
    l = n / 2 - 1
    r = n / 2
    res = n / 2
    while r < n and l >= 0 and s[l] == s[r]:
        l -= 1
        r += 1
        res += 1
    print res
else:
    l = n / 2 - 1
    r = n / 2 + 1
    res = n / 2 + 1
    if s[n / 2] != s[l] or s[n / 2] != s[r]:
        print res
    else:
        while r < n and l >= 0 and s[l] == s[r]:
            l -= 1
            r += 1
            res += 1
        print res


Measured memory_bytes: 2692
N, X, T = map(int, input().split())
count = 0
result = 0

if N < X:
  print(T)
else:
  if N % X == 0:
    count = N / X
    result = count * T
    print(int(result))
  else:
    count = (N // X) + 1
    result = count * T
    print(int(result))

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

int main(void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int ans = 0;
    int i;
    for(i = 0; i <= 100; i++){
        if(i >= a && i >= c && i < b && i < d){
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 100005;
const int MM = 1000000007;

struct UF{
	int t[MX], cnt[MX];
	int find(int x){ return t[x] ? t[x] = find(t[x]) : x; }
	int merge(int a, int b){
		a = find(a), b = find(b);
		if( a == b ) return 0;
		cnt[a] += cnt[b];
		return t[b] = a;
	}
}uf;

ll f(ll x){ return x * (x-1) / 2; }

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) uf.cnt[i] = 1;
	for(int i = 1; i <= M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		uf.merge(a, b);
	}
	int p = uf.cnt[uf.find(1)], q = uf.cnt[uf.find(2)];
	ll ans = max(f(p) + f(N-p), f(q) + f(N-q));
	printf("%lld\n", ans - M);
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	vector<int> c(h * w);
	int it = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		for (int j = 0; j < a; j++) {
			c[it] = i + 1;
			it++;
		}
	}

	vector<vector<int>> ans(h, vector<int>(w));
	it = 0;
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; j++) {
				ans[i][j] = c[it];
				it++;
			}
		} else {
			for (int j = w - 1; j >= 0; j--) {
				ans[i][j] = c[it];
				it++;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << ans[i][j] << (j == w - 1 ? "" : " ");
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,  int>;

const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
	int n, k;
	cin >> n >> k;
	cout << max(n-2* k, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define pii pair<int,int>
#define endl '\n'
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--)

int powe(int a, int b){
	int ans=1;
	while(b){
		b--;
		ans=ans*a;
	}
	return ans;
}

signed main() 
{	
	fast;
	int a;
	cin >> a;
	int cnt=0, t=0;
	while(a>=1){
		a=a/2;
		cnt++;
	}
	cout << powe(2,cnt)-1;
}


Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using ll = long long;
using namespace std;
struct cake{
  ll num;
  ll k;
  ll o;
  ll n;
};

bool comp(const cake &a,const cake &b){
  return ((a.k) + (a.o) + (a.n)) > ((b.k) + (b.o) + (b.n));
}

bool comp1(const cake &a,const cake &b){
  return ((a.k) + (a.o) + (a.n)) > ((b.k) + (b.o) + (b.n));
}

bool comp2(const cake &a,const cake &b){
  return (-(a.k) + (a.o) + (a.n)) > (-(b.k) + (b.o) + (b.n));
}

bool comp3(const cake &a,const cake &b){
  return ((a.k) - (a.o) + (a.n)) > ((b.k) - (b.o) + (b.n));
}

bool comp4(const cake &a,const cake &b){
  return (-(a.k) - (a.o) + (a.n)) > (-(b.k) - (b.o) + (b.n));
}

bool comp5(const cake &a,const cake &b){
  return ((a.k) + (a.o) - (a.n)) > ((b.k) + (b.o) - (b.n));
}

bool comp6(const cake &a,const cake &b){
  return (-(a.k) + (a.o) - (a.n)) > (-(b.k) + (b.o) - (b.n));
}

bool comp7(const cake &a,const cake &b){
  return ((a.k) - (a.o) - (a.n)) > ((b.k) - (b.o) - (b.n));
}

bool comp8(const cake &a,const cake &b){
  return (-(a.k) - (a.o) - (a.n)) > (-(b.k) - (b.o) - (b.n));
}


int main(){
  ll n,m,ii,jj;
  cin >> n >> m;
  vector<cake> c;
  vector<cake> ca[8];
  c.resize(n);

  for(ii=0;ii<n;ii++){
    c[ii].num = ii;
    cin >> c[ii].k >> c[ii].o >> c[ii].n;
  }
  for(ii=0;ii<8;ii++){
    ca[ii] = c;
  }

  sort(c.begin(),c.end(),comp);
  sort(ca[0].begin(),ca[0].end(),comp1);
  sort(ca[1].begin(),ca[1].end(),comp2);
  sort(ca[2].begin(),ca[2].end(),comp3);
  sort(ca[3].begin(),ca[3].end(),comp4);
  sort(ca[4].begin(),ca[4].end(),comp5);
  sort(ca[5].begin(),ca[5].end(),comp6);
  sort(ca[6].begin(),ca[6].end(),comp7);
  sort(ca[7].begin(),ca[7].end(),comp8);
  ll sum = 0,osum,ksum,nsum,max=0;
  for(jj=0;jj<8;jj++){
    sum = 0;
    osum = 0;
    ksum = 0;
    nsum = 0;
    for(ii=0;ii<m;ii++){
      //cout << c[ii].num + 1 << endl;
      //sum += (c[ii].o) + (c[ii].k) + (c[ii].n);
      osum += ca[jj][ii].o;
      ksum += ca[jj][ii].k;
      nsum += ca[jj][ii].n;
    }

    sum = abs(osum)+abs(ksum)+abs(nsum);
    if(sum > max){
      max = sum;
    }
  }
  cout << max << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int n;cin>>n;

  int ans=0;
  rep(i,1,n+1)ans+=i;

  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n, sum=0;
    cin >> n;
    vector<ll> a(n+2, 0);
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=0; i<=n; i++) sum += abs(a[i+1]-a[i]);
    for(int i=1; i<=n; i++){
        ll ans = sum - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4000
import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = read().decode().split()

dicts = Counter(S)
max_cnt = 0
ans_list = []
for v in dicts.values():
    max_cnt = max(max_cnt, v)
for k, v in dicts.items():
    if v == max_cnt:
        ans_list.append(k)

ans_list = sorted(ans_list)

for key in ans_list:
    print(key)


Measured memory_bytes: 38464
r = int(input())
A = list(map(int, input().split()))

cnt = 0
for i in range(r):
    min_j = i
    for j in range(i+1, r):
        if A[j] < A[min_j]:
            min_j = j
    if min_j > i:
        A[min_j], A[i] = A[i], A[min_j]
        cnt+=1
print(" ".join(map(str, A)))
print(cnt)


Measured memory_bytes: 5600
def solve():
    s = list(input())
    K = int(input())

    for i in range(len(s)):
        distToA = (ord('z')+1 - ord(s[i])) % 26
        if distToA <= K:
            s[i] = 'a'
            K -= distToA
    else:
        s[-1] = chr(ord(s[-1]) + K%26)
    
    print("".join(s))

if __name__ == '__main__':
    solve()

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

int n;
long long ans, INF = 1e18;
class UnionFind{
public:
	vector<int> Parent;
	vector<int> Rank;
	UnionFind(int n){
		++n;
		Parent.resize(n, 0);
		Rank.resize(n, 0);
		for(int i=0; i<n; ++i)
			Parent[i] = i;
	}

	int find(int x){
		if(Parent[x] == x) return x;
		return Parent[x] = find(Parent[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(Rank[x] < Rank[y]) Parent[x] = y;
		else{
			Parent[y] = x;
			if(Rank[x] == Rank[y]) ++Rank[x];
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};
class Edge{
public:
	long long cost;
	int from, to;
	Edge(long long c, int f, int t){
		cost = c;
		from = f;
		to = t;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
bool operator < (const Edge &e, const Edge &f){
	return e.cost != f.cost ? e.cost > f.cost : e.from != f.from ? e.from < f.from : e.to < f.to;
}
void dijkstra(int s, const Graph &g, vector<long long> &dist){
	int V = g.size();
	dist = vector<long long>(V, INF);
	dist[s] = 0;
	priority_queue<Edge> q;
	q.push(Edge(0, s, s));
	while(!q.empty()){
		Edge e = q.top();
		q.pop();
		if(dist[e.to] < e.cost) continue;
		for(int i=0; i<(int)g[e.to].size(); ++i){
			Edge f = g[e.to][i];
			if(dist[f.to] > dist[e.to] + f.cost){
				dist[f.to] = dist[e.to] + f.cost;
				q.push(Edge(dist[f.to], s, f.to));
			}
		}
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	UnionFind uf(n);
	Graph g(n);
	vector<Edge> w;
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j){
			int t;
			cin >> t;
			if(i <= j) continue;
			w.push_back(Edge(t, i, j));
		}
	sort(w.begin(), w.end());
	reverse(w.begin(), w.end());
	for(auto e:w){
		int i = e.from, j = e.to, t = e.cost;
		if(!uf.same(i, j)){
			uf.unite(i, j);
			ans += t;
			g[i].push_back(Edge(t, i, j));
			g[j].push_back(Edge(t, j, i));
		}else{
			vector<long long> d(n, INF);
			dijkstra(i, g, d);
			if(d[j] < t){
				cout << -1 << "\n";
				return 0;
			}else if(d[j] > t){
				ans += t;
				g[i].push_back(Edge(t, i, j));
				g[j].push_back(Edge(t, j, i));
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1404
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, a, b, c, ans = INF;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    int ma = 1;
    for(int i = 0; i < n; i++){
        ma *= 4;
    }
    for(int i = 0; i < ma; i++){
        int t = i, cnt = n, sum = 0, s1 = 0, s2 = 0, s3 = 0;
        for(int j = 0; j < n; j++){
            if(t % 4 == 0){
                cnt--;
            }else if(t % 4 == 1){
                s1 += l[j];
                if(s1 != l[j]) sum += 10;
            }else if(t % 4 == 2){
                s2 += l[j];
                if(s2 != l[j]) sum += 10;
            }else if(t % 4 == 3){
                s3 += l[j];
                if(s3 != l[j]) sum += 10;
            }
            t /= 4;
        }
        if(cnt < 3 || s1 == 0 || s2 == 0 || s3 == 0) continue;
        sum += abs(a - s1) + abs(b - s2) + abs(c - s3);
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5+1)
n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

Measured memory_bytes: 159576
n,x,y = (int(num) for num in input().split())
x -= 1
y -= 1

def d(i,j):
    return min(j-i,abs(j-x) + 1 + abs(i-y),abs(i-x) + 1 + abs(j-y))
dlist = [0] * n
for i in range(n-1):
    for j in range(i+1,n):
        #print(i+1,j+1,d(i,j))
        dlist[d(i,j)] += 1
        
for i in range(1,n):
    print(dlist[i])

Measured memory_bytes: 3444
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, M = mi()
    l = [[] for i in range(N)]
    for i in range(M):
        a, b = mi()
        l[a-1].append(b-1)
        l[b-1].append(a-1)

    for v in l[0]:
        if N-1 in l[v]:
            print('POSSIBLE')
            return
    print('IMPOSSIBLE')


if __name__ == '__main__':
    main()


Measured memory_bytes: 100316
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<pair<int,ll>> pos(N);
    REP(i,N){
        cin>>pos[i].first>>pos[i].second;
        pos[i].first-=pos[i].second;
        pos[i].second+=pos[i].second;
    }
    sort(All(pos),[](pair<int,ll> x,pair<int,ll>y){return x.first+x.second<y.first+y.second;});
    int ans=0,r=-1e9;
    REP(i,N){
        if(r<=pos[i].first){
            ans++;
            r=pos[i].first+pos[i].second;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
import math

N=int(input())
A=list(map(int,input().split()))

for i in range(N):
    A[i]-=i+1
A.sort()
a=N//2

def sad(A,a):
    sadness=0
    for i in range(N):
        sadness+=abs(A[i]-A[a])
    return sadness

if N%2==0:
    ans=min(sad(A,a),sad(A,a+1))
else:
    ans=sad(A,a)
print(ans)

Measured memory_bytes: 26832
import math 
a, b, h, m = map(int,input().split())


h_degree = h * 30 + 30 * m / 60
m_degree = m * 6

degree = abs(h_degree - m_degree)
cosc = math.cos(math.radians(degree))

c = a**2 + b**2 - 2*a*b*cosc

print(c**0.5)

Measured memory_bytes: 9480
from fractions import gcd
from itertools import count, chain, product

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

g = gcd(A, B)

divisors = []
for i in chain([2], range(3, int(g ** 0.5) + 1, 2)):
    firsttime = True
    while g % i == 0:
        g //= i
        if firsttime:
            divisors.append(i)
            firsttime = False
    if g == 1:
        break
if g != 1:
    divisors.append(-1)

print(len(divisors) + 1)



Measured memory_bytes: 5044
//ABC133C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int l, r;
	cin >> l >> r;
	int ans = 2019;
	for(int i=l;i<r;i++){
		for(int j=i+1;j<=r;j++){
			ans = min(ans,((i%2019)*(j%2019))%2019);
			if(ans == 0){
				cout << 0 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

last = -1
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] is T[j] or S[i+j] is '?':
            if j == len(T)-1:
                last = i
        else:
            break
if last != -1:
    S = S[:last] + T + S[last+len(T):]
    S = S.replace('?', 'a')
    print(S)
    exit()

print('UNRESTORABLE')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
  bool ans = true;
  int a[5];
  rep(i,5){
    cin>>a[i];
  }
  int k;
  cin>>k;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<5;j++){
      if(a[j]-a[i]>k){
        ans = false;
      }
    }
  }
  if(ans) cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <numeric>
#include <unordered_map>

using namespace std;
using ll = long long;

enum State
{
    LEFT,
    RIGHT,
    SURVIVE,
};

State go(int x, const string& s, const vector<char>& t, const vector<char>& d)
{
    int N = s.size();
    int Q = t.size();

    for (int i = 0; i < Q; ++i) {
        if (s[x] == t[i]) {
            if (d[i] == 'L') {
                --x;
            } else {
                ++x;
            }

            if (x < 0) {
                return LEFT;
            }

            if (x >= N) {
                return RIGHT;
            }
        }
    }

    return SURVIVE;
}

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

    string s;
    cin >> s;

    vector<char> t(Q);
    vector<char> d(Q);

    for (int i = 0; i < Q; ++i) {
        cin >> t[i] >> d[i];
    }

    int left = -1;
    int right = N;
    while (right - left > 1) {
        int middle = (left + right) / 2;

        if (go(middle, s, t, d) == LEFT) {
            left = middle;
        } else {
            right = middle;
        }
    }

    int survive_left_pos = right;

    left = -1;
    right = N;
    while (right - left > 1) {
        int middle = (left + right) / 2;

        if (go(middle, s, t, d) == RIGHT) { 
            right = middle;
        } else {
            left = middle;
        }
    }

    int survive_right_pos = left;

    cout << survive_right_pos - survive_left_pos + 1 << endl;

    return 0;
}


Measured memory_bytes: 900
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;
 
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
 
#define csh(a,n) memset(a,n,sizeof(a));
int arr[1001][1001];
int main(){
	int t,n,m;
	cin>>n;
	int sum=0;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		sum+=a-1;
	} 
	cout<<sum<<endl;
} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}

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

	int a, b;
	a = (s[0]-'0') * 10 + s[1] - '0';
	b = (s[2] - '0') * 10 + s[3] - '0';

	int f1 = 0, f2 = 0;
	if (a > 12 || a==0)f1 = 1;
	if (b > 12 || b==0)f2 = 1;

	if (f1&&f2) {
		puts("NA");
	}else if(f1) {
		puts("YYMM");
	}
	else if (f2) {
		puts("MMYY");
	}
	else {
		puts("AMBIGUOUS");
	}
}


Measured memory_bytes: 128
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});

reader.on("close", function() {
  // A_1,A_2,...
  var numbers: number[] = lines[1].split(" ").map(x => {
    return Number(x);
  });

  var tmpArray: number[] = new Array();
  numbers.forEach((x: number) => {
    tmpArray.push(x);
  });

  var baseSum: number = Math.abs(numbers[0]);
  for (var i: number = 1; i < numbers.length; i++) {
    baseSum = baseSum + Math.abs(numbers[i] - numbers[i - 1]);
  }
  baseSum = baseSum + Math.abs(numbers[numbers.length - 1]);

  for (var i: number = 0; i < numbers.length; i++) {
    if (i == 0) {
      console.log(
        baseSum -
          Math.abs(numbers[0]) -
          Math.abs(numbers[1] - numbers[0]) +
          Math.abs(numbers[1])
      );
    } else if (i == numbers.length - 1) {
      console.log(
        baseSum -
          Math.abs(numbers[numbers.length - 1]) -
          Math.abs(numbers[numbers.length - 1] - numbers[numbers.length - 2]) +
          Math.abs(numbers[numbers.length - 2])
      );
    } else {
      console.log(
        baseSum -
          Math.abs(numbers[i + 1] - numbers[i]) -
          Math.abs(numbers[i] - numbers[i - 1]) +
          Math.abs(numbers[i + 1] - numbers[i - 1])
      );
    }
  }
});


Measured memory_bytes: 36260