akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//#include <DEBUG.h>
#ifndef LL
#define LL long long
#endif
#ifndef uLL
#define uLL unsigned long long
#endif
#ifndef uL
#define uL unsigned int
#endif
#ifndef iL
#define iL int
#endif
#ifndef iS
#define iS short
#endif
#ifndef uS
#define uS unsigned short
#endif
#ifndef uC
#define uC unsigned char
#endif
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define abs(a) (((a)<0)?(-(a)):(a))
#define sgn(a) (((a)<0)?(1):(0))
#define movs(a,b,l) (memmove((a),(b),sizeof(*(b))*(l)))
#define stosb(a,b,l) (memset((a),(b),sizeof(*(a))*(l)))
LL num[1000000],num2[1000000];
char str[1000000];
int main()
{
	//freopen("in.in","r",stdin);
	char ch;
	LL i,j,k,a,b,c,d,n,m,iq,qq,ans,x,y,size;
	scanf("%s",str);
	memset(num,0,sizeof(*num)*1000000);
	for (i=0;str[i]>0;i++)
	{
		if (str[i]=='A') {num[i+1]=1;}
	}
	n=i;
	for (i=0;i<n-1;i++)
	{
		if ((str[i]=='B')&&(str[i+1]=='C')) {num[i+1]=2;num[i+2]=2;}
	}
	///
	size=0;n+=1;num[n]=0;ans=0;
	//print64(num+1,n);
	for (i=1,j=0;i<=n;i++)
	{
		if (num[i]>0)
		{
			num2[++j]=num[i];
			if (num[i]==2) {i++;}
		}
		else
		{
			//print64(num2+1,j);
			a=0;b=0;c=0;
			for (k=1;k<=j;k++)
			{
				if (num2[k]==1)
				{
					c+=j-k-a;
					a+=1;
				}
				else
				{
					c+=k-1-b;
					b+=1;
				}
			}
			ans+=c/2;
			j=0;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    int n; cin >> n;
    int h[n];

    for (int i=0;i<n;i++) {
        cin >> h[i];
    }

    int count = 1;
    int heighest = h[0];

    for (int i=1;i<n;i++) {
        if (heighest <= h[i]){
            heighest = h[i];
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
vector<int> a[MAXN];
int n,root;
pair<int,int> dfs(int x,int fa){
    int res=0,rs=0;
    int flag=0;
    for(int i=0;i<a[x].size();i++){
        if(a[x][i]==fa)
            continue;
        pair<int,int> t=dfs(a[x][i],x);
        int res1=t.first;
        if(a[x].size()+(root==x)==2)
            rs=t.second;
        if(res1==0&&flag==1)
            res++;
        if(res1==0&&flag==0)
            flag=1;
        res+=res1;
    }
    return make_pair(res,max(rs,flag));
}
int main(){
    SF("%d",&n);
    int u,v;
    for(int i=1;i<n;i++){
        SF("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
    }
    for(int i=0;i<n;i++)
        if(a[i].size()==1){
            root=i;
            break;
        }
    pair<int,int> ans=dfs(root,-1);
    PF("%d",ans.first+ans.second);
}


Measured memory_bytes: 13568
n, k = map(int, input().split(' '))
arr  = list(map(int, input().split(' ')))
count = [0 for _ in range(45)]
for i in arr:
    s = bin(i)[2:]
    # print(s)
    for idx, val in enumerate(reversed(s)):
        count[45 - idx - 1] += int(val)
        
ans  = 0
prev = 0
f = -1
# print(count)
for idx, val in enumerate(count):
    prev = ans
    if val > n // 2:
        ans |= (0 << 44 - idx)
    else:
        ans |= (1 << 44 - idx)
        
    # print(ans)
    if ans > k:
        ans = prev
        continue 


# print(ans)
rep = 0
for val in arr:
    rep += val ^ ans
    
print(rep)
        


Measured memory_bytes: 68188
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;
const int N = 1e5 + 5 , mod = 1e9 + 7;

ll A[N];

int main()
{
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n , k; cin >> n >> k;
    for (int i=0; i<n; i++)
        cin >> A[i];
    sort(A , A+n);
    ll mn = 1e17;
    for (int i=0; i+k-1 < n; i++)
        mn = min(mn , A[i+k-1] - A[i]);
    cout << mn;
}


Measured memory_bytes: 1024
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(X, T),
    Z is max(0, X - T),
    writeln(Z).


Measured memory_bytes: 8184
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll inf=1e18;
const ll maxs = 201;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define line() cout<<endl;
#define fr(i,b) for(ll i=0;i<b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll lcm(ll a,ll b)
{
    return a*b/__gcd(a,b);
}


int main()
{
    fastio();
    
     ll t=1;
     //cin>>t;
     while(t--)
     {
        ll n;
        cin>>n;
        ll a[n][3];
        for(ll i=0;i<n;i++)
            cin>>a[i][0]>>a[i][1]>>a[i][2];
        
        ll dp[n][3];
        dp[0][0] = a[0][0];
        dp[0][1] = a[0][1];
        dp[0][2] = a[0][2];
        for(ll i=1;i<n;i++)
        {
            dp[i][0] = a[i][0] + max(dp[i-1][1],dp[i-1][2]);
            dp[i][1] = a[i][1] + max(dp[i-1][0],dp[i-1][2]);
            dp[i][2] = a[i][2] + max(dp[i-1][1],dp[i-1][0]);
        }
         ll ans = dp[n-1][0];
         ans = max(ans,max(dp[n-1][1],dp[n-1][2]));
         cout<<ans;
         
     }
    return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    map <string, int> m;
    rep(i, n) {
        string s; cin >> s;
        if(m.count(s)) m[s]++;
        else m[s] = 1;
    }
    int max=0;
    for(auto i=m.begin(); i!=m.end(); i++) {
        chmax(max, i->second);
    }
    for(auto i=m.begin(); i!=m.end(); i++) {
        if(i->second == max) cout << i->first << endl;
    }
}

Measured memory_bytes: 25216
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass
{
    static void Main(string[] args)
    {
        var n = int.Parse(System.Console.ReadLine().Trim());
        var nodes = new List<List<int>>(n);
        foreach (var i in Enumerable.Range(0, n)) nodes.Add(new List<int>());
        foreach(var i in Enumerable.Range(0, n - 1))
        {
            var edge = System.Console.ReadLine().Trim().Split(' ').Select(s => int.Parse(s) - 1).ToArray();
            nodes[edge[0]].Add(edge[1]);
            nodes[edge[1]].Add(edge[0]);
        }
        var distanceFromZero = DistanceFrom(0, nodes);
        var maxA = Enumerable.Range(0, n).OrderByDescending(i => distanceFromZero[i]).First();
        var distanceFromEndA = DistanceFrom(maxA, nodes);
        var maxB = Enumerable.Range(0, n).OrderByDescending(i => distanceFromEndA[i]).First();
        var distanceFromEndB = DistanceFrom(maxB, nodes);
        foreach(var i in Enumerable.Range(0, n))
        {
            Console.WriteLine(2 * n - 2 - Math.Max(distanceFromEndA[i], distanceFromEndB[i]));
        }
    }
    static int[] DistanceFrom(int from, List<List<int>> nodes)
    {
        var distance = Enumerable.Repeat(-1, nodes.Count).ToArray(); distance[from] = 0;
        var queue = new Queue<int>(); queue.Enqueue(from);
        while(queue.Count > 0)
        {
            var current = queue.Dequeue();
            foreach(var next in nodes[current])
            {
                if (distance[next] == -1)
                {
                    distance[next] = distance[current] + 1;
                    queue.Enqueue(next);
                }
            }
        }
        return distance;
    }
}



Measured memory_bytes: 44388
import java.util.Scanner;

public class Main {


    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] points = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        }

        int ans = 0;
        for (int i = 0; i < N - 1; i++) {
            for (int j = i + 1; j < N; j++) {

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        }
        System.out.print(ans);
    }

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



Measured memory_bytes: 21844
def resolve():
    a = [input().split() for i in range(3)]
    n = int(input())
    b = [input() for i in range(n)]
    
    r=[[0] * 3 for i in range(3)]
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if b[i]==a[j][k]:
                    r[j][k] = 1
    # print(res)
    for i in range(3):
        if r[0][i] + r[1][i] + r[2][i] == 3:
            print("Yes")
            return
    for i in range(3):
        if r[i][0] + r[i][1] + r[i][2] == 3:
            print("Yes")
            return
    if r[0][0] + r[1][1] + r[2][2] == 3:
        print("Yes")
        return
    if r[0][2] + r[1][1] + r[2][0] == 3:
        print("Yes")
        return
    print("No")

resolve()

Measured memory_bytes: 3444
#include<iostream>
using namespace std;
long long mod=1e9+7;

long long power(long long a,long long b){
	long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res;
}

int main(){
	long long n,ans=1;
  
  	cin>>n;
  
  	ans = (power(10,n)%mod - 2*power(9,n)%mod + power(8,n)%mod + 2*mod)%mod;
  
  	cout<<ans;
    return 0;
}


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

int main(void) {
	using namespace std;
	const long long MOD = 1000000007;
	long long res = 1;
	int N;
	cin >> N;
	string S1, S2;
	cin >> S1;
	cin >> S2;
	enum Kind { VERT, HORIZ, NONE };
	Kind pre = NONE;
	for(int i = 0; i < N; ++i) {
		if(S1[i] == S2[i]) {
			switch(pre) {
				case NONE:
					res = res * 3 % MOD;
					break;
				case VERT:
					res = res * 2 % MOD;
					break;
				case HORIZ:
					break;
			}
			pre = VERT;
		} else {
			switch(pre) {
				case NONE:
					res = res * 6 % MOD;
					break;
				case VERT:
					res = res * 2 % MOD;
					break;
				case HORIZ:
					res = res * 3 % MOD;
					break;
			}
			pre = HORIZ;
			++i;
		}
	}
	cout << res << '\n';
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n){
		cin>>a[i];
	}
	sort(begin(a),end(a));
	ll ans=0;
	rep(i,n)FOR(j,i+1,n){
		ll cnt=lower_bound(begin(a)+j+1,end(a),a[i]+a[j])-upper_bound(begin(a)+j+1,end(a),a[j]-a[i]);
		ans+=cnt;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
Var s,x:ansistring;
    n,i:longint;
Begin
        readln(s);
        for i:=1 to length(s) do
        Begin
                if s[i] in ['C','F'] then
                Begin
                        x:=x+s[i];
                end;

                if pos('CF',x)<>0 then
                Begin
                        write('Yes');
                        halt;
                end;
        end;
        write('No');
end.

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
        int n, i, j, num_s, buffer;
        int *array;

        scanf("%d", &n);

        array = (int *)malloc(n * sizeof(int));

        for(i = 0 ; i < n; i++){
                scanf("%d", &array[i]);
        }

        for(j = 0 ; j < n ; j++){
                for(i = n - 1 ; i > j ; i--){
                        if(array[i] < array[i - 1]){
                                buffer = array[i];
                                array[i] = array[i - 1];
                                array[i - 1] = buffer;
                                num_s++;
                        }
                }
        }

        for(i = 0 ; i < n ; i++){
                printf("%d", array[i]);
                if(i + 1 != n)printf(" ");
        }
        printf("\n");

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

        return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 3010
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
   ll a,b;
   cin>>a>>b;
   ll x=__gcd(a,b);
   ll ans=1;
   map<ll,int> m;
   if(x!=1){
       for(int i=2;i<=sqrt(x)+1;i++){
           while(x%i==0){
               m[i]++;
               x/=i;
           }
       }
       if(x!=1)m[x]++;
       ans+=SZ(m);
   }

   OUT(ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      int N = sc.nextInt();
      int R = sc.nextInt();
      int A = 0;
       
      if(N < 10){
       A = 100 * (10 - N);
      }


      System.out.print(A + R);
   }
 }

Measured memory_bytes: 35504
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#define  go return 0
#define pb push_back
#include<utility>
#include <algorithm>
#include<iterator>
typedef long long ll;
typedef double db;
#define lp1(i, n)  for(int i=0; i<(int)(n); ++i)
#define lp2(i, n)  for(int i=1; i<=(int)(n); ++i)
#define lp3(j, m)  for(int j=0; j<(int)(m); ++j)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
typedef vector<int> vi;
const int N=1e5+5;
int arr[N];
int main(){

 int n,k,arr[N],sum=0,count=0;
 cin>>n>>k;
lp1(i,n){
cin>>arr[i];
if(arr[i]>=k)
    count++;
}
cout<<count;
go;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <deque>
#include <string>
#include <vector>
using namespace std;
typedef vector <string> svector;
typedef vector <int> ivector;
typedef deque <string> sdeque;

int split(svector &tokens, const string &text, char delim=' '){
	int start = 0, end = 0;
	for (int i=0; i<(int)text.size(); i++)
		if (text[i] == delim){
			end = i;
			tokens.push_back(text.substr(start, end - start));
			start = end + 1;
		}
	tokens.push_back(text.substr(start));
	return 0;
}

int sdeque_out(sdeque &A){
    int n=A.size();
    for (int i=0; i<n; i++){
        cout << A[i];
        if (i!= n-1) cout<<" ";
        else cout<<endl;
    }
    return 0;
}

int main(void){
	int n;
	string text = "";
	svector strs;
	sdeque que;
	sdeque::iterator pos;
	
	cin >> n;
	getline(cin, text);

	for (int i=0; i<n; i++){
		getline(cin, text);
		strs.clear();
		split(strs, text);

		if (strs[0]== "insert")
			que.push_front(strs[1]);
		else if (strs[0] == "delete"){
			pos = find( que.begin(), que.end(), strs[1] );
			if (pos != que.end()) que.erase(pos);
		}else if (strs[0] == "deleteFirst")
			que.pop_front();
		else if (strs[0] == "deleteLast")
			que.pop_back();
	}

	sdeque_out(que);
	return 0;
}

Measured memory_bytes: 56188
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define reg register
using namespace std;
const int N=2e5+5;
struct node
{
	int l,r;
	inline friend bool operator < (node a,node b)
	{
		return a.l==b.l?a.r>b.r:a.l<b.l;
	}
}q[N];
int n,m,a[N],cnt,tmin[N<<2];
inline int read()
{
	int x=0,w=1;
	char c=getchar();
	while (!isdigit(c)&&c!='-') c=getchar();
	if (c=='-') c=getchar(),w=-1;
	while (isdigit(c))
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*w;
}
inline void pushup(int now)
{
	tmin[now]=min(tmin[now<<1],tmin[now<<1|1]);
}
void build(int l,int r,int now)
{
	if (l==r) {tmin[now]=(l?N:0); return;}
	int mid=(l+r)>>1;
	build(l,mid,now<<1); build(mid+1,r,now<<1|1);
	pushup(now);
}
void change(int l,int r,int now,int x,int c)
{
	if (l==r) {tmin[now]=min(tmin[now],c); return;}
	int mid=(l+r)>>1;
	if (x<=mid) change(l,mid,now<<1,x,c);
	else change(mid+1,r,now<<1|1,x,c);
	pushup(now);
}
int query(int L,int R,int l,int r,int now)
{
	if (l>R||r<L) return N;
	if (l>=L&&r<=R) return tmin[now];
	int mid=(l+r)>>1;
	if (mid>=R) return query(L,R,l,mid,now<<1);
	if (mid<L) return query(L,R,mid+1,r,now<<1|1);
	return min(query(L,mid,l,mid,now<<1),query(mid+1,R,mid+1,r,now<<1|1));
}
int main()
{
	n=read();
	for (reg int i=1;i<=n;i++) cnt+=(1-(a[i]=read()));
	m=read();
	for (reg int i=1;i<=m;i++) q[i].l=read(),q[i].r=read();
	sort(q+1,q+m+1); build(0,n,1);
	for (reg int i=1,now=1;i<=n;i++)
	{
		while (q[now].l==i) change(0,n,1,q[now].r,query(i-1,q[now].r,0,n,1)),++now;
		change(0,n,1,i,query(i-1,i-1,0,n,1)+(a[i]<<1)-1);
	}
	printf("%d\n",cnt+query(n,n,0,n,1));
	return 0;
}

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

int main() {

    string s;

    cin >> s;

    set<char> char_set;

    for(int i=0; i<s.size(); i++){
        char_set.insert(s[i]);
    }

    if(char_set.size() != s.size()){
        cout << "no" << endl;
    }
    else{
        cout <<  "yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

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

int n;
vector<P> v;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    v.resize(n);
    REP(i, n) cin >> v[i].second >> v[i].first;
    sort(v.begin(), v.end());

    ll t = 0;
    bool ans = true;
    REP(i, n) {
        t += v[i].second;
        if (t > v[i].first) {
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
void dfs(string s, char mx) {
  if (s.size() == N) {cout << s << endl;}
  else {
    for (char c = 'a'; c <= mx; c++) {
      dfs(s+c, (c == mx? mx+1:mx));
    }
  }
}
int main() {cin >> N; dfs("", 'a');}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a,b,c,d;
char s[200005];
int main(){
	cin >> n >> a >> b >> c >> d;
	scanf("%s",s+1);
	if(c>d){
		for(int i=a+1;i<c-1;i++)
			if(s[i]=='#' and s[i+1]=='#'){
				cout << "No";
				return 0;
			}
		for(int i=b-1;i<d;i++)
			if(s[i]=='.' and s[i+1]=='.' and s[i+2]=='.'){
				cout << "Yes";
				return 0;
			}
		cout << "No";
	}
	else{
		for(int i=a+1;i<d-1;i++)
			if(s[i]=='#' and s[i+1]=='#'){
				cout << "No";
				return 0;
			}
		cout << "Yes";
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	   Scanner stdIn = new Scanner(System.in);
	   
	   int a = stdIn.nextInt();
	   int b = stdIn.nextInt();
	   int c = stdIn.nextInt();
	   
	   if (a == 5 && b == 7 && c == 5) {
		   System.out.println("YES");
	   } else if (a == 7 && b == 5 && c == 5) {
		   System.out.println("YES");
	   } else if (a == 5 && b == 5 && c == 7) {
		   System.out.println("YES");
	   } else {
		   System.out.println("NO");
	   }
	}
}

Measured memory_bytes: 21460
import collections

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

prime = collections.Counter(prime_factorize(n))

ans = 0
for cnt in prime.values():
    c = 0
    while cnt - c > 0:
        c += 1
        cnt -= c
    ans += c

print(ans)

Measured memory_bytes: 9488
n = int(input())
hs = list(map(int, input().split(' ')))

MAX = hs[0]
result = True
for i in range(n):
    if hs[i] > MAX:
        MAX = hs[i]
    else:
        if MAX - hs[i] >= 2:
            result = False

if result:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 15020
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecD = vector<double>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<vector<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

Vec1<ld> dp;

int main(void){
	ll n;
	cin >> n;
	VecD p(n);
	rep(i, n) cin >> p[i];
	dp.resize(n+1);

	dp[0] = 1;
	rep(i, n) repnr(j, n){
		dp[j] += dp[j-1]*p[i];
		dp[j-1] *= (1.0-p[i]);
	}

	ld ans = 0;
	REPNR(i, n, (n+1)/2) ans += dp[i];
	setp(10);
	co(ans);

	return 0;
}


Measured memory_bytes: 384
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
      
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
print(lcm_list(T))

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
vector<i64> A;

int main(){
  cin >> N;
  A.resize(N);
  int ans = 0;
  rep(i,0,N - 1){
    cin >> A[i];
    i64 a = A[i];
    int cnt = 0;
    while(a % 2 == 0){
      cnt++;
      a /= 2;
    }
    ans+= cnt;
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

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

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

/////////////////////////////////////////////////////////

void Main() {
  ll N, M; cin >> N >> M;
  priority_queue<ll> A;
  rep(i, 0, N){
    ll tmp; cin >> tmp;
    A.push(tmp);
  }
  while(M > 0){
    ll tmp = A.top();
    A.pop();
    tmp /= 2;
    A.push(tmp);
    M--;
  }
  ll res = 0;
  rep(i, 0, N){
    res += A.top();
    A.pop();
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

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

  Main();
}


Measured memory_bytes: 1400
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int task(int a, int b, int c) {
    int res = 0;

    res += abs(a - b);
    res += abs(b - c);

    return res;
}

int main()
{
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    int res = 0;

    res = task(a1, a2, a3);
    res = min(res, task(a1, a3, a2));
    res = min(res, task(a2, a1, a3));
    res = min(res, task(a2, a3, a1));
    res = min(res, task(a3, a1, a2));
    res = min(res, task(a3, a2, a1));

    cout << res << endl;

    return 0;
}


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

int main() {
	int n;
	string s;
	cin >> n >> s;

	int x = 0, ans = 0;
	
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I')x++;
		if (s[i] == 'D')x--;

		ans = max(ans, x);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
int main()
{
    string s;
    cin>>s;
    ll i,sum=0;
    for(i=0;i<s.length();i++)
    {
        sum+=s[i]-48;
    }
    if(sum%9)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


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

using namespace std;

#include <vector>
#include <iostream>

class DisjointSet
{
  private:
    std::vector<int> P;
    int root(int a);

  public:
    DisjointSet(int N);
    ~DisjointSet();
    void unite(int a, int b);
    bool is_same_set(int a, int b);

    void show_all(int a);
};

DisjointSet::DisjointSet(int N)
{
    for (int i = 0; i <= N; ++i)
    {
        P.push_back(i);
    }
}

int DisjointSet::root(int a)
{
    if (P[a] == a)
        return a;
    return (P[a] = root(P[a]));
}

void DisjointSet::unite(int a, int b)
{
    P[root(a)] = root(b);
    return;
}

bool DisjointSet::is_same_set(int a, int b)
{
    return root(a) == root(b);
}

void DisjointSet::show_all(int a)
{
    if (P[a] != a)
        show_all(P[a]);
    std::cout << "P[" << a << "] = " << P[a] << std::endl;
    return;
}

int main()
{
    int n, q;
    cin >> n >> q;

    // Union Find Tree
    DisjointSet *set = new DisjointSet(n);

    for (int i = 0; i < q; i++)
    {
        int com;
        int x, y;
        cin >> com >> x >> y;

        switch (com)
        {
        case 0:
            set->unite(x, y);
            break;
        case 1:
            cout << set->is_same_set(x, y) << endl;
            break;
        default:
            break;
        }
    }
}


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

 using namespace std ;
 #define task "data"

 const int maxn = 1e5 + 5 ;
 int dp[200][maxn] , n , W , w[maxn] , v[maxn] ;
 const int vc = 1e9 + 5;
 main()
 {
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
   //  #ifndef ONLINE_JUDGE
    // freopen(task".inp","r",stdin);
     //freopen(task".out","w",stdout);
 //    #endif // ONLINE_JUDGE

     cin >> n >> W ;

     for (int i = 1 ; i <= n ; i++) cin >> w[i] >> v[i] ;

     for (int i = 0 ; i <= n ; i++) for (int j = 0 ; j <= 1000 * n ; j++) dp[i][j] = vc ;
     dp[0][0] = 0 ;
     for (int i = 0 ; i <= n - 1 ; i++)
     for (int j = 0 ; j < 1000 * n ; j++)
     {
         dp[i + 1][j] = min(dp[i + 1][j] , dp[i][j]) ;
         dp[i + 1][j + v[i + 1]] = min(dp[i + 1][j + v[i + 1]] , dp[i][j] + w[i + 1]) ;
       //  cout << i << " " << j << " " << dp[i][j] << endl ;
     }

     for (int i = 1000 * n ; i >= 0 ; i--) if(dp[n][i] <= W) { cout << i ; break ; }

     return 0 ;
 }


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

string s,t;
int c=0;

int main(){
  cin >> s >> t;
  for (int i=0;i<s.length();i++){
    if (s[i] == t[i]){
      c += 1;
    }
  }
  cout << c;
  return 0;
}
    

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
nijo_list = []
for i in range(min(a), max(a)):
    nijo_sum = 0
    for j in range(len(a)):
        nijo = (a[j] - i)**2
        nijo_sum += nijo
    nijo_list.append(nijo_sum)
if nijo_list:
    print(min(nijo_list))
else:
    print(0)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();


		long sum = 0;

		if(K >= A) {
			K -= A;
			sum += A;
		}else {
			sum = K;
			System.out.println(sum);
			return;
		}

		if(K >= B) {
			K -= B;
		}else {
			System.out.println(sum);
			return;
		}

		if(K >= C) {
			K -= C;
			sum -= C;
		}else {
			sum -= K;
			System.out.println(sum);
			return;
		}

		System.out.println(sum);

	}

}


Measured memory_bytes: 35848
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

int n;
string s;
ll h[MAXN], p = 53, pp[MAXN];
ll h2[MAXN], p2 = 29, pp2[MAXN];
ll h3[MAXN], p3 = 59, pp3[MAXN];

ll getH(int l, int r) {
	ll H = h[r];
	if (l > 0) H = (H - h[l - 1] + mod) % mod;
	H = (H * pp[n - r - 1]) % mod;
	return H;
}

ll getH2(int l, int r) {
	ll H = h2[r];
	if (l > 0) H = (H - h2[l - 1] + mod) % mod;
	H = (H * pp2[n - r - 1]) % mod;
	return H;
}

ll getH3(int l, int r) {
	ll H = h3[r];
	if (l > 0) H = (H - h3[l - 1] + mod) % mod;
	H = (H * pp3[n - r - 1]) % mod;
	return H;
}


bool check(int len) {
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
		    if (i + len - 1 >= j) continue;
		    if (j + len - 1 >= n) continue;
			if (getH(i, i + len - 1) == getH(j, j + len - 1) && getH2(i, i + len - 1) == getH2(j, j + len - 1) && getH3(i, i + len - 1) == getH3(j, j + len - 1)) return 1;
		}
	}
	return 0;
}

int main() {
	//freopen(NAME".in", "r", stdin);
	//freopen(NAME".out", "w", stdout);
		
	cin >> n >> s;
	pp[0] = 1;
	pp2[0] = 1;
	pp3[0] = 1;
	for (int i = 1; i <= n; i++) {
		pp[i] = (pp[i - 1] * p) % mod;
	}
	h[0] = (s[0] - 'a' + 1);
	h3[0] = h2[0] = h[0];
	for (int i = 1; i < n; i++) {
		h[i] = (h[i - 1] + pp[i] * (s[i] - 'a' + 1)) % mod;
	}
	for (int i = 1; i <= n; i++) {
		pp2[i] = (pp2[i - 1] * p2) % mod;
	}
	for (int i = 1; i < n; i++) {
		h2[i] = (h2[i - 1] + pp2[i] * (s[i] - 'a' + 1)) % mod;
	}
	for (int i = 1; i <= n; i++) {
		pp3[i] = (pp3[i - 1] * p3) % mod;
	}
	for (int i = 1; i < n; i++) {
		h3[i] = (h3[i - 1] + pp3[i] * (s[i] - 'a' + 1)) % mod;
	}


	int l = 1, r = n, res = 0;
	while (l <= r) {
		int m = (l + r) >> 1;
		if (check(m)) {
			res = max(res, m);
			l = m + 1;
		}
		else r = m - 1;
	}
	cout << res;
	return 0;	
}

Measured memory_bytes: 10624
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int min = Integer.MAX_VALUE;
		int minidx = 0;
		int N = sc.nextInt();
		for(int i=0; i<N; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(min > b) {
				min = b;
				minidx = a;
			}
		}
		System.out.println(min+minidx);
	}
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
}


Measured memory_bytes: 65404
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    string n;
    cin >> n;
    cout << (((int)n.find("9") > -1) ? "Yes" : "No");
    cout << endl;

    return 0;
}



Measured memory_bytes: 760
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int N,v[101],i,x,nr=0;
    scanf ("%d %d",&N,&x);

    for (i=1; i<=N; i++)
    {
        scanf ("%d",&v[i]);
    }

    sort (v+1,v+N+1);

    for (i=1; i<=N; i++)
    {
        if (x-v[i]>=0)
        {
            x-=v[i];
            nr++;
        }
    }

    if (x>0&&nr==N)
    {
        printf ("%d\n",nr-1);
    }
    else
    {
        printf ("%d\n",nr);
    }

    return 0;
}

Measured memory_bytes: 128
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def max_diff(*A):
    return max(A)-min(A)


def _solve(H, W):
    # W is set
    min_diff = math.inf
    for h in range(1, H):
        min_diff = min(min_diff, max_diff(W*h, (W//2)*(H-h), (W-W//2)*(H-h)),
                                 max_diff(W*h, ((H-h)//2)*W, (H-h-(H-h)//2)*W))
    return min_diff


def solve():
    H, W = read_ints()
    return min(_solve(H, W), _solve(W, H))


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 68004
from itertools import permutations

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

for _ in range(M):
    fr, to = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].add(to)
    edges[to].add(fr)

def existsPath(path):
    for fr, to in zip(path, path[1:]):
        if not to in  edges[fr]:
            return False
    return True

ans = 0
for path in permutations(range(1, N), r=N-1):
    if existsPath((0,) + path):
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,k;
  cin >>n>>k;
  ll a,b;
  vector <pair<ll,ll>> p;
  for(ll i=0;i<n;i++){
    cin >>a>>b;
    p.push_back(make_pair(a,b));
  }
  sort(p.begin(),p.end());
  ll sum=0;
  for(ll i=0;i<n;i++){
   sum+=p[i].second;
   if(k<=sum) {
     cout <<p[i].first<<endl;
     return 0;
   }
  }
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int n, k;
    cin >> n >> k;
    ll x[n];
    rep(i, n) cin >> x[i];
    ll ans = LINF;
    rep(i, n - k + 1){
        ll mn = x[i];
        ll mx = x[i + k - 1];
        ll tmp = min(abs(mn), abs(mx)) + abs(mx - mn);
        ans = min(ans , tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int N;
  double x, ans = 0;
  string u;
  
  cin >> N;
  
  const double rate = 380000.0;
  for(int i = 0; i < N; i++){
    cin >> x >> u;
    if(u == "JPY") ans += x;
    else ans += x * rate;
  }
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N,T,ba,play[10];
	char H[100];
	while(1){
		ba = 0;
		cin >> N;
		for(int i=0;i<10;i++) play[i]=0;
		if(N==0) break;
		cin >> H;
		for(int i=0;i<100;i++){
			if(H[i] == 'M')
				play[i%N]++;
			else if(H[i] == 'S'){
				play[i%N]++;
				ba = ba + play[i%N];
				play[i%N] = 0;
			}
			else if(H[i] == 'L'){
				play[i%N]++;
				play[i%N] = play[i%N] + ba;
				ba = 0;
			}
		}
		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
				if(play[i] > play[j]){
					T = play[i];
					play[i] = play[j];
					play[j] = T;
				}
			}
		}
		for(int i=0;i<N;i++){
			cout << play[i] << " ";
		}
		cout << ba << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int H = 111;
int grid[H][H];
int n, h, w;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> n;
    int x = 1, y = 1;
    for(int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        while(a--) {
            grid[x][y] = i;
            if(x & 1) {
                if(y == w) {
                    x++;
                } else {
                    y++;
                }
            } else {
                if(y == 1) {
                    x++;
                } else {
                    y--;
                }
            }
        }
    }
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            cout << grid[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define LLINF (1LL<<60)
#define INF (1<<30)
#define F first
#define S second
int main(void){
    long long n,t;
    long long a[100005];
    long long uru[100005]={0};
    cin>>n>>t;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long maxs=a[n-1];
    for(int i=n-1;i>=0;i--){
        uru[i]=maxs-a[i];
        maxs=max(a[i],maxs);
    }
    sort(uru,uru+n,greater<long long>());
    long long ans=1;
    for(int i=1;i<n;i++){
        if(uru[0]==uru[i]) ans++;
        else break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	vector<bool>oks(30);
	for (int i = 0; i < 28; ++i) {
		int a; cin >> a; a--;
		oks[a] =true;
	}
	for (int i = 0; i < 30; ++i) {
		if (!oks[i]) {
			cout << i + 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int xx[100005];
int main()
{
    int n,v,c=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>v;
        if(v>100000)c++;
        else xx[v]++;
    }
    vector<int>vc,vc1;
    for(int i=1;i<=100005;i++)
    {
        if(xx[i]!=0)
        {
            if(xx[i]<i)c+=xx[i];
            else if(xx[i]>i)c+=xx[i]-i;
        }
    }
      cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int x,y,z;
  int ans;
  while(1){
    z = scanf("%d %d", &x, &y);
    if(z==EOF)break;
    ans=0;
    x = x + y;
    while(x > 0){
      x/=10;
      ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll n , p , m;

int main()
{
    _FastIO;

    cin >> n >> p >> m;
    vector<ll> used(m + 10 , 0);
    vector<ll> v(m + 10 , 0);
    vector<ll> ms(m + 10 , 0);
    used[p] = 1;
    v[1] = p;
    ms[1] = p;
    ll t = p;
    ll k = 0;
    ll tp = 0;
    ll s = 0;
    for(ll i = 2; i <= m + 5; i++){
        ll x = (t * t) % m;
        t = x;
        ms[i] = t;
        if(used[t]){
            k = i - used[t];
            tp = used[t] - 1;
            s = v[i - 1] - v[tp];
            break;
        }
        used[t] = i;
        v[i] = v[i - 1] + t;
    }
    ll ans = v[tp];
    if(n <= tp){
        cout << v[n] << endl;
        return 0;
    }
    n -= tp;
    ll kp = n / k;
    ll kq = n % k;
    ans += (kp * s);
    ans += (v[tp + kq] - v[tp]);
    cout << ans << endl;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    string a, b; cin >> a >> b;
    int x, y; cin >> x >> y;
    string k; cin >> k;
    if (k == a) cout << x - 1 << ' ' << y << endl;
    else cout << x << ' ' << y - 1 << endl;
}

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

int main() {
	int N;
	char s[100001];
	int loop = 0;
	int point = 0;
	scanf("%s", s);
	N = strlen(s);

	do {
		if (s[loop++] == 'p')point--;
		if (s[loop++] == 'g')point++;
	} while (loop < N);
	printf("%d\n", point);
	return 0;
}

Measured memory_bytes: 256