akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

int main(void){
    int n;
    unsigned long long mod = 1000000007;
    unsigned long long ans = 1;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        ans *= (unsigned long long)i;
        ans %= mod;
    }
    printf("%d\n", ans);
    


}


Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template<class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main() {
    string s;
    int n;
    cin>>n;
    cin>>s;
    rep(i,s.size()){
        int a = s[i]-'A';
        a+=n;
        a%=26;
        s[i]=char(a+'A');
    }
    cout<<s<<endl;

    return 0;
}


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

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int k;

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

  scanf("%d", &k);
  int cur = 0;
  map < int , bool > vis;
  for(int i = 1 ; ; ++i){
    cur = (cur*10)+7;
    cur %= k;
    if(vis.find(cur) != vis.end())
      return puts("-1") , 0;
    if(cur == 0)
      return printf("%d\n" , i) , 0;
    vis[cur] = 1;
  }


  return 0;
}


Measured memory_bytes: 50628
def main():
    N, x = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0] * N
    ans = float('inf')
    for k in range(N):
        can = k * x
        for i in range(N):
            if k == 0:
                B[i] = A[i]
            else:
                B[i] = min(B[i],A[i-k])
            can += B[i]
        ans = min(ans, can)

    print(ans)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 41836
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct Node
{
    int key;
    Node *p,*l,*r;
};
Node *root,*NIL;
Node *tree1(Node*x)
{
    while(x->l!=NIL)x=x->l;
    return x;
}
Node *find(Node *u,int k)
{
    while(u!=NIL&&k!=u->key)
    {
        if(k<u->key)
        {
            u=u->l;
        }
        else
            u=u->r;
    }
    return u;
}
Node *tree2(Node *x)
{
    if(x->l!=NIL)
        return tree1(x->r);
    Node *y=x->p;
    while(y!=NIL&&x==y->r)
    {
        x=y;
        y=y->p;
    }
    return y;
}
Node* De(Node *z)
{
    Node *y;
    Node *x;
    if(z->l==NIL||z->r==NIL)
    {
        y=z;
    }
    else
    {
        y=tree2(z);
    }
    if(y->l!=NIL)
    {
        x=y->l;
    }
    else{
        x=y->r;
    }
    if(x!=NIL)
    {
        x->p=y->p;
    }
    if(y->p==NIL)
    {
        root=x;
    }
    else{
        if(y==y->p->l)
        {
            y->p->l=x;
        }else
        {
            y->p->r=x;
        }
    }
    if(y!=z)
    {
        z->key=y->key;
    }
    free(y);
}
void insert(int k)
{
    Node *y=NIL;
    Node *x=root;
    Node *z;
    z=(Node*)malloc(sizeof(Node));
    z->key=k;
    z->l=NIL;
    z->r=NIL;
    while(x!=NIL)
    {
        y=x;
        if(z->key<x->key)
            x=x->l;
        else
            x=x->r;
    }
    z->p=y;
    if(y==NIL)
    {
        root=z;
    }
    else
    {
        if(z->key<y->key)
        {
            y->l=z;
        }
        else
        {
            y->r=z;
        }
    }
}
void zx(Node *u)
{
    if(u==NIL)return;
    zx(u->l);
    printf(" %d",u->key);
    zx(u->r);
}
void qx(Node *u)
{
    if(u==NIL)return;
    printf(" %d",u->key);
    qx(u->l);
    qx(u->r);

}

int main()
{
    int n,x;
    scanf("%d",&n);
    string c;
    for(int i=1;i<=n;i++)
    {
        cin>>c;
        if(c=="find")
        {
            scanf("%d",&x);
            Node *t=find(root,x);
            if(t!=NIL)cout<<"yes"<<endl;
            else
                cout<<"no"<<endl;
        }
        else if(c=="insert")
        {
            scanf("%d",&x);
            insert(x);
        }
        else if(c=="print")
        {
            zx(root);
            printf("\n");
            qx(root);
            printf("\n");
        }
        else if(c=="delete")
        {
            scanf("%d",&x);
            De(find(root,x));
        }
    }
    return 0;
}

Measured memory_bytes: 22044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		int A = Integer.parseInt(scn.next());
		int B = Integer.parseInt(scn.next());
		int C = Integer.parseInt(scn.next());
		int D = Integer.parseInt(scn.next());
 
		int a = A * B;
		int b = C * D;
		if (a > b) {
			System.out.println(a);
		} else {
			System.out.println(b);
		}

	}

}


Measured memory_bytes: 25044
#include <iostream>

using namespace std;

int p[101];

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

    for (int i = 0; i < 101; ++i)
    {
        p[i] = 0;
    }
    int cur;

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

    for (int i = 0; i < 101; ++i)
    {
        if (x-i < 1 || x-i > 100 || p[x-i] == 0)
        {
            cout << x-i << "\n";
            break;
        }

        if (x+i < 1 || x+i > 100 || p[x+i] == 0)
        {
            cout << x+i << "\n";
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
	const int M = 8;
	int N, a;
	bool is_contains[M];
	int min, max;
	min = max = 0;
	cin >> N;

	for (int i = 0; i < M; i++)
		is_contains[i] = false;

	for (int i = 0; i < N; i++)
	{
		cin >> a;

		if (a >= 3200)
			max++;
		else
		{
			if (!is_contains[a / 400])
			{
				min++;
				max++;
				is_contains[a / 400] = true;
			}
		}
	}

	cout << (min == 0 ? 1 : min) << " " << max << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	int tefud[11];
	int hito;
	int ba;
	int i;
	char yama[101];
	
	while(1){
		
		cin>>n;
		
		if(n==0) break;
		
		for(i=1;i<=n;i++) tefud[i]=0;
		
		cin>>yama;
		
		hito=1; ba=0;
		for(i=0;i<100;i++){
			if(hito>n) hito=1;
			if(yama[i]=='M') tefud[hito]++;
			else if(yama[i]=='S'){
				ba+=tefud[hito]+1;
				tefud[hito]=0;
			}
			else if(yama[i]=='L'){
				tefud[hito]+=ba+1;
				ba=0;
			}
			hito++;
		}
		
		sort(tefud+1,tefud+n+1);
		
		for(i=1;i<=n;i++) cout<<tefud[i]<<" ";
		cout<<ba<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 3176
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
#include <cassert>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

string s, t;
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios::sync_with_stdio(false); cin.tie(0);
    cin >> s >> t;
    if (SZ(s) + 1 == SZ(t) && s == t.substr(0, SZ(t) - 1)) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    set<int> pos;
    rep(i, 0, N) {
        if (S[i] == 'R') {
            pos.insert(i);
        }
    }
    int ans = 0;
    rep(i, 0, N) {
        if (S[i] == 'W' && !pos.empty()) {
            swap(S[i], S[*pos.rbegin()]);
            pos.erase(*pos.rbegin());
            ++ans;
        } else if (S[i] == 'R' && pos.count(i)) {
            pos.erase(i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12984
#include<iostream>

using namespace std;

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

	int A = X / 500;
	int AA = X % 500;

	//int Ans = 0;
	//Ans += A * 1000;
	int AAA = AA / 5;
	//Ans += AAA * 5;
	int Ans = (A * 1000) + (AAA * 5);

	cout << Ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main(){
  int A,B;
  cin >> A >> B ;
  if(A*B%2==0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

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

#define ll long long int

#define pi 2*acos(0.0)
#define mod 1000000007

#define fast   ios_base::sync_with_stdio(false);cin.tie(NULL);

#define pii pair<ll,ll>

#define pb push_back

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

//ll Big_Mod(ll v1, ll p, ll md)  { ll res=1; v1=v1%md; while (p > 0){if (p & 1)res = (res * v1) % md; p =p>>1; v1 = (v1 * v1) % md;}return res;}
ll ar[500009],br[500009],cr[500009],tr[500009];
map<ll,ll>mp;
vector<ll>v;
string s;

struct evan
{
    ll l,r,pos;
}st[500009];
bool com(evan i1,evan i2)
{
    return (i1.r < i2.r);
}

int main()
{
    ll a,b,c,d,e,i,j,k,x,y,z,f,g,h,n,m;
    cin>>a;
    x=0;
    for(i=0;i<a;i++)
    {
        cin>>ar[i];
        x=x^ar[i];
    }
    for(i=0;i<a;i++)
    {
        cout<<(x^ar[i])<<" ";
    }
    cout<<endl;
}






Measured memory_bytes: 5092
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

Int gcd(Int x, Int y) {
    return y == 0 ? x : gcd(y, x % y);
}
Int mul_gcd(Int a, Int b, Int c) {
    return gcd(a,gcd(b,c));
}
int main(void) {
    Int K;
    cin>>K;
    Int sum = 0;

    for(Int i = 1;i <= K;i++) {
        for(Int j = 1;j <= K;j++) {
            for(Int k = 1;k <= K;k++) {
                sum += mul_gcd(i,j,k);
            }
        }
    }

    cout<<sum<<endl;

    return 0;
}





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

int main(){
  ll h, n;
  cin >> h >> n;
  vector<int> a(n);
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  cout << (sum >= h ? "Yes" : "No");
  
  return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
    while (true) {
      int H = sc.nextInt();
      int W = sc.nextInt();
      if (H == 0 && W == 0) {
        break;
      } else {
        for (int h = 0; h < H; h++) {
          for (int w = 0; w < W; w++) {
            if (h == 0 || h == H -1  || w == 0 || w == W - 1)
              System.out.print("#");
            else
              System.out.print(".");
          }
          System.out.println();
        }
        System.out.println();
      }
    }
    sc.close();
  }
}


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

using ll=long long;

int main() {
  vector<char> N(4);
  rep(i,0,4) {
    cin >>N[i];
  }
  sort(N.begin(),N.end());
  string ans="";
  rep(i,0,4) {
    ans+=N[i];
  }
  cout <<(ans=="1479" ? "YES":"NO") <<endl;
  return 0;
}


Measured memory_bytes: 3632
solve :: Int -> Int -> Int
solve a b =
  let c = round(fromIntegral a/3)
      d = a - c
      e = b `div` 2
      f = b - e
      g = d `div` 2
      h = d - g
      ls1 = [ c*b, e*d, f*d ]
      ls2 = [ c*b, g*b, h*b ]
  in min (maximum ls1 - minimum ls1) (maximum ls2 - minimum ls2)

main = do
  [h, w] <- map read.words <$> getLine :: IO [Int]
  if h`mod`3 == 0 || w`mod`3 == 3
    then print 0
    else print $ min (solve h w) (solve w h)


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n,k;
    cin>>n>>k;
    vector<int> pos,neg;
    int ans = 1,z = 0;
    for(int i=0;i<n;i++)
    {
      int foo;
      cin>>foo;
       if(foo<=0)
        neg.push_back(foo);
      else
        pos.push_back(foo);
    }
    sort(pos.begin(),pos.end());  // 1 2 3 4 5
    sort(neg.rbegin(),neg.rend()); // -1 -2 -3 -4 -5
    if(k%2){
      if(!pos.empty()){
        if(pos.size()-1 + (neg.size()/2)*2>=k-1)
         ans = pos.back(),pos.pop_back();
        else
          ans = pos[0],pos.erase(pos.begin());
      } else
        ans =*neg.begin(),neg.erase(neg.begin());
    }
    bool ok = 1;
    if(ans<0)
      ok = 0;
    ans = (ans+mod)%mod;
    k -= k%2;
    
    if(pos.size() + (neg.size()/2)*2<k)
      ok = 0;

    for(int i=1;i<=k;i+=2){
      int maxm = 0;
      if(neg.size()>=2){
      if(ok)
        maxm = neg.back() * neg[neg.size()-2];
      else
        maxm = neg[0] * neg[1];
      }
      if(pos.size()>=2){
        if((ok && maxm < pos.back() * pos[pos.size()-2]) || (!ok && maxm > pos[0]*pos[1]) || neg.size()<2) {
          if(ok){
            maxm = pos.back();
            pos.pop_back();
            maxm = maxm * pos.back();
            pos.pop_back();
          }else{
            maxm = pos[0]*pos[1];
            pos.erase(pos.begin());
            pos.erase(pos.begin());
          }
        }else{
          if(ok){
            neg.pop_back();
            neg.pop_back();
          }else{
            neg.erase(neg.begin());
            neg.erase(neg.begin());
          }
        }
      }
      else{
        if(neg.size()>=2){
         if(ok){
            neg.pop_back();
            neg.pop_back();
          }else{
            neg.erase(neg.begin());
            neg.erase(neg.begin());
          }
        }else{
          assert(!neg.empty()&&!pos.empty());
          maxm = (*neg.begin()) * pos.back();
          pos.pop_back();
          neg.erase(neg.begin());
        }
      }
      maxm = (maxm + mod*(int)1e9)%mod;
      ans =((ans%mod * maxm%mod)%mod + mod)%mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5664
#include <iostream>
using namespace std;
int main(){

  int n;
  cin >> n;
  for(int i = 1; i <= n; i++){
    if((int)(i * 1.08) == n){
    cout << i << endl;
    return 0;
    }
    
   //cout<< i << " " << num  << " "<< nun << endl;
  }
  
  cout << ":(" << endl;
  

  return 0;
}



Measured memory_bytes: 256
#TLE解答
'''
N = int(input())
A = list(map(int,input().split()))
ans = []
for X in range(min(A),max(A)+1):
    count = 0
    for i in A:
        if(abs(i-X) <= 1):
            count += 1
    ans.append(count)
print(max(ans))
'''

#解説を見て
import collections
N = int(input())
A = list(map(int,input().split()))
list_A = []
for i in  range(N):
    list_A.append(A[i])
    list_A.append(A[i]+1)
    list_A.append(A[i]-1)
print(collections.Counter(list_A).most_common()[0][1])


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

char buf[4];

int main (void) {
	gets(buf);
	if (!strcmp("SUN", buf)) puts("7");
	else if (!strcmp("MON", buf)) puts("6");
	else if (!strcmp("TUE", buf)) puts("5");
	else if (!strcmp("WED", buf)) puts("4");
	else if (!strcmp("THU", buf)) puts("3");
	else if (!strcmp("FRI", buf)) puts("2");
	else puts("1");
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* UnionFind */

struct UnionFind{
  vector<int> data;
  vector<ll> sum, sum2, sum3;
  vector<priority_queue<pair<int,pair<int,int> > > > pqs;

  UnionFind(int s):data(s, -1), sum(s, 0), sum2(s), sum3(s), pqs(s) {}

  int root(int x){
    if(data[x] < 0) return x;
    return data[x] = root(data[x]);
  }

  bool set(int x, int y){
    x = root(x); y = root(y);
    if(x == y) return false;
    if (pqs[x].size() < pqs[y].size()) swap(x, y);
    
    data[x] += data[y];
    sum[x] += sum[y];
    sum2[x] += sum2[y];
    sum3[x] += sum3[y];

    while(pqs[y].size()) {
      pqs[x].push(pqs[y].top());
      pqs[y].pop();
    }

    data[y] = x;
    sum[y] = sum2[y] = 0;
    return true;
  }

  bool check(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return -data[root(x)];
  }
};



int main(){
  int n, m;
  int x[SIZE];
  vector<pair<int,pair<int,int> > > vec;

  scanf("%d%d", &n, &m);

  UnionFind uf(n);

  for(int i=0;i<n;i++){
    scanf("%d", x+i);
    uf.sum[i] = x[i];
  }

  for(int i=0;i<m;i++){
    int a, b, y;
    scanf("%d%d%d", &a, &b, &y);
    vec.push_back({y, {a-1, b-1}});
  }

  sort(vec.begin(), vec.end());

  int ans = 0;

  for(int i=0;i<m;i++){
    int a = vec[i].second.first;
    int b = vec[i].second.second;
    int y = vec[i].first;

    uf.set(a, b);

    int r = uf.root(a);

    auto &pq = uf.pqs[r];
    uf.sum3[r]++;

    pq.push({-y, {a, b}});

    while(pq.size()){
      if(uf.sum[r] >= -pq.top().first)
        pq.pop();
      else
        break;
    }

    if(pq.size() == 0) {
      ans += uf.sum3[r] - uf.sum2[r];
      debug(uf.sum2[r]);
      debug(uf.sum3[r]);
      uf.sum2[r] = uf.sum3[r];
    }

  }

  cout << m - ans << endl;


  return 0;
}


Measured memory_bytes: 14068
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 5e3+5;

string s;
int z[N];

void buildZ(string a){
    int n = a.size();
    memset(z , 0 , sizeof z);
    int x = 0 , y = 0;
    for(int i = 1; i < n; i++){
        z[i] = max(0 , min(z[i - x] , y - i + 1));
        while(i + z[i] < n && a[i + z[i]] == a[z[i]]){
            x = i;
            y = i + z[i];
            z[i]++;
        }
    }
}

int main(){
    int sz;
    cin >> sz;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < sz; i++){
        string trial = "";
        for(int j = i; j < sz; j++){
            trial += s[j];
        }
        buildZ(trial);
        for(int j = 0; j < trial.size(); j++){
            ans = max(ans , min(z[j] , j));
        }
    }
    cout << ans << endl;
}


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


int max(std::vector<int> num, int key, int n, int k){
    int sum_max = 0;
    num[key] *= 2;
    if(n==k){
        sum_max = num[0] + num[1] + num[2];
    }else{
        for(int i = 0; i<3; i++){
            int buff = max(num,i,n+1,k);
            if(buff>sum_max) sum_max = buff;
        }
    }
    return sum_max;
}

int max(std::vector<int> num, int k){
    int sum_max = 0;
    for(int i = 0; i<3; i++){
        int buff = max(num,i,1,k);
        if(buff>sum_max) sum_max = buff;
    }
    return sum_max;
}

int main(){
    std::vector<int> num(3);
    int k;
    std::cin >> num[0] >> num[1] >> num[2];
    std::cin >> k;

    std::cout << max(num,k) << std::endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
t = len(s)

x = []
y = 0

while 10 ** y % 2019 not in x:
    x.append(10 ** y % 2019)
    y += 1

z = len(x)

m = [0 for i in range(2019)]
m[0] = 1
a = 0
for i in reversed(range(0, t)):
    a += x[(t-i-1) % z] * (int(s[i]) % 2019)
    a = a % 2019
    m[a] += 1

def triangle(n):
    if n > 1:
        return n * (n-1) // 2
    else:
        return 0

p = list(map(triangle, m))
# print(p)
print(sum(p))


Measured memory_bytes: 9304
#include <iostream>
 
using ll = long long;
 
ll n, c;
ll a[400],b[400];
ll dp[401];
 
ll MOD = 1000000007;
 
int main()
{
	std::cin >> n >> c;
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		std::cin >> b[i];
	}
	for (int j = 0; j <= c; ++j)
	{
		dp[j] = 0;
	}
	dp[0] = 1;
	for (int i = 0; i < n; ++i)
	{
		ll newdp[401] = {};
		for (ll t = a[i]; t <= b[i]; ++t)
		{
			ll tas[401] = { dp[0] };
			for (int j = 0; j <= c; ++j)
			{
				if(j != 0)tas[j] = (tas[j - 1] * t + dp[j]) % MOD;
				newdp[j] += tas[j];
				newdp[j] %= MOD;
			}
		}
		for (int j = 0; j <= c; ++j)
		{
			dp[j] = newdp[j] % MOD;
		}
	}
	std::cout << dp[c] << std::endl;
	return 0;
}

Measured memory_bytes: 384
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

cnt = 0
for i in range(n):
    a = list(map(int, input().split()))

    socre = 0
    for j in range(m):
        socre += a[j] * b[j]
    if socre + c > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,Max=0,T;
	cin>>n>>T;
	for(int i=1;i<=T;i++)
	{
		int x; cin>>x;
		Max=max(Max,x);
	}
	cout<<max(Max-1-(n-Max),0);
	return 0;
} 

Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = ll(1e9+7);

int main(){
  ll h, w;cin>>h>>w;
  ll ans=LINF;
  if(h>=3LL){
    ans=min(ans, ll(h%3!=0LL)*w);
  }
  if(w>=3LL){
    ans=min(ans, ll(w%3!=0LL)*h);
  }
  if(h%2==0LL){
    ans=min(ans, h/2*ll(w%3!=0));
  }else{
    repb(w_, 1, w){
      ll s1=h*w_,
         s2=h/2*(w-w_),
         s3=(h+1)/2*(w-w_);
      ans=min(ans, max(s1, s3)-min(s1, s2));
    }
  }
  if(w%2==0LL){
    ans=min(ans, w/2*ll(h%3!=0));
  }else{
    repb(h_, 1, h){
      ll s1=w*h_,
         s2=w/2*(h-h_),
         s3=(w+1)/2*(h-h_);
      ans=min(ans, max(s1, s3)-min(s1, s2));
    }
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        System.out.println((A-1) * (B-1));
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    int x,a;
    cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<int,vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;


ve<ve<char>> s;
int H,W;

bool check(int a,int b){
    if(a-1 >= 0) if(s[a-1][b] == '#') return true;
    if(b-1 >= 0) if(s[a][b-1] == '#') return true;
    if(a+1 < H) if(s[a+1][b] == '#') return true;
    if(b+1 < W) if(s[a][b+1] == '#') return true;
    return false;
}

int main()
{
    cin >> H >> W;
    s.assign(H,ve<char>(W,'.'));
    rep(i,H) rep(j,W) cin >> s[i][j];
    
    rep(i,H) rep(j,W){
        if(s[i][j] == '#'){
            if(check(i,j)) continue;
            else {
                out("No");
                return 0;
            }
        }
    }

    out("Yes");
    return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, int> pli;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MX = 100010;

vi vl[MX];

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

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		vl[b].pb(a);
	}

	int ret = 0;
	int la = -1;
	rep(i, n) {
		if (vl[i].size()) {
			int u = *max_element(ALL(vl[i]));
			if (u > la) {
				la = i-1;
				++ret;
			}
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 4864
#include<stdio.h>
#define MAX 500000
#define INFTY 1000000000
int L[MAX], R[MAX];
int count;
void merge(int*, int, int, int);
void mergeSort(int*, int, int);
int main(){
  int i;
  int A[MAX], n; 
  count = 0;    
  scanf("%d", &n);
  for (i=0; i<n; i++){
    scanf("%d", &A[i]);
    if (A[i] >= INFTY ){
      return 1;
    }
  }
   
  mergeSort(A, 0, n);
 
  for (i=0; i<n; i++){
    if ( i ) printf(" ");
    printf("%d", A[i]);
    }
  printf("\n"); 
  printf("%d\n", count);
  return 0;
}
 
void merge(int A[], int left, int mid, int right){  
  int i,j,k,n1,n2;
   n1 = mid - left;
   n2 = right - mid;
   for(i=0; i<n1; i++){
     L[i] = A[left + i];
   }    
   for (i=0; i<n2; i++){
     R[i] = A[mid + i];
   }  
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
   
  for (k=left; k<=right-1; k++){    
    count++;   
    if ( L[i] <= R[j] ){
      A[k] = L[i];
      i = i + 1;
    }
    else {
      A[k] = R[j];
      j=j+1;
    }
  }
}
 
void mergeSort(int A[], int left, int right ){
  int mid;  
  if (left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

Measured memory_bytes: 4512
import java.util.*;

public class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc=new Scanner(System.in);
		while(true){
			int score[]=new int[sc.nextInt()];
			if(score.length==0)break;
			float sum=0;

			for(int i=0; i<score.length; i++)
				score[i]=sc.nextInt();
			Arrays.sort(score);
			for(int i=1; i<score.length-1; i++)
				sum+=score[i];
			sum/=score.length-2;
			System.out.println((int)sum);
		}
		sc.close();
	}
}

Measured memory_bytes: 20924
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        // 整数の入力
        int N = int.Parse(Console.ReadLine());
        string A = Console.ReadLine();
        string B = Console.ReadLine();
        string C = Console.ReadLine();


        int cnt = 0;

        // Aにそろえる
        for (int i = 0; i < N; i++)
        {
            //AとBとCが一致する
            if(A[i].Equals(B[i]) && A[i].Equals(C[i]))
            {
            }
            //AとBが一致する、Cが一致しない
            else if (A[i].Equals(B[i]) && !A[i].Equals(C[i]))
            {
                cnt++;
            }
            //AとCが一致する、Bが一致しない
            else if (A[i].Equals(C[i]) && !A[i].Equals(B[i]))
            {
                cnt++;
            }
            //BとCが一致する、Aが一致しない
            else if (B[i].Equals(C[i]) && !B[i].Equals(A[i]))
            {
                cnt++;
            }
            else
            {
                cnt += 2;
            }
        }

        //出力
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 11092
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1e9;
#define MOD 1e9+7;
#define INF64 1e18;

#define F first
#define S second


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 ans = 0;

	cin >> N;

	vector<SINT32> DATA(N);
	
	rep(i,0,N) {
		cin >> DATA[i];
	}
	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());

	rep(i,0,N) {
		if ((i % 2) == 0) {
			ans += DATA[i];
		} else {
			ans -= DATA[i];
		}
	}

	cout << ans << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N, K; cin >> N >> K;
        string s; cin >> s;
        s[K - 1] = tolower(s[K - 1]);
        cout << s << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - (a - b)) << endl;
	return 0;
}

Measured memory_bytes: 256
w=input()
l=len(w)

dic={}

for i in range(l):
    if w[i] not in dic:
        dic[w[i]]=1
    else:
        dic[w[i]]+=1

flag=1
for val in dic.values():
    if val%2==1:
        flag=0

if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n,m; cin>>n>>m;
	vector<vector<int>> array(m,vector<int>());
	rep(i,m){
		int k; cin>>k;
		vint e(k);
		rep(j,k){cin>>e[j]; e[j]--;}
		array[i] = e;
	}
	vector<int> cond(m);
	rep(i,m)cin>>cond[i];
	int ans = 0;
	for(int bit = 0; bit<(1<<n); ++bit){
		vector<bool> onof(m,false);
		for(int i = 0; i<n; ++i){
			if(bit & (1<<i)){
				onof[i] = true;
			}
		}
		bool ok = true;
		rep(i,m){
			int cnt = 0;
			rep(j,array[i].size()){
				if(onof[array[i][j]])cnt++;
			}
			if(cnt%2==cond[i]);
			else{ ok = false; break;}
		}
		if(ok)ans++;
	}
	cout<<ans<<endl; return 0;
	return 0;
}

Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#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;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int a,b,c,k;
  cin >> a >> b >> c;
  cin >> k;
  while(b<=a && k){
    b*=2;
    k--;
  }
  while(c<=b && k){
    c*=2;
    k--;
  }
  if(b>a && c>b){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }



return 0;
}
///....


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

int main(){
    int N,M;
    cin >> N >> M;
    if (M == 1 || N >= M){
        cout << "0" << "\n";
        return 0;
    }
    vector<int>v(M);
    for (int i = 0; i < M; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    vector<int>sa(M-1);
    for (int i = 1; i < M; i++){
        sa.at(i-1) = v.at(i) - v.at(i-1);
    }
    sort(sa.begin(), sa.end());
    reverse(sa.begin(), sa.end());
    int soukyori = v.at(M-1) - v.at(0);
    int yaranai = 0;
    for (int i = 0; i < N-1; i++){
        yaranai += sa.at(i);
    }
    cout << soukyori - yaranai << "\n";
}

Measured memory_bytes: 1024
import numpy as np


s = input()
t = input()


trans = {}

flag = True
for i in range(len(s)):
    if s[i] in trans:
        temp = trans[s[i]]
        if temp == t[i]:
            continue
        else:
            flag = False
            break
    else:
        if t[i] not in trans.values():
           trans[s[i]] = t[i]
        else:
            flag = False
            break


if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 21356
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static char[][] c;
	static int H, W;
	static List<Point> p;
	static long ans = 0;
	static boolean[][] m;
	static int[][] g;
	static long cnt1 = 0;
	static long cnt2 = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		H = sc.nextInt();
		W = sc.nextInt();
		String[] S = new String[H];
		for(int i = 0; i < H; i++) {
			S[i] = sc.next();
		}
		sc.close();
		c = new char[H][W];
		m = new boolean[H][W];
		g = new int[H][W];

		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				m[i][j] = true;
			}
		}
		p = new ArrayList<Point>();
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				c[i][j] = S[i].charAt(j);
				if(c[i][j] == '#') {
					p.add(new Point(j, i));
				}
			}
		}
		for(int i = 0; i < p.size(); i++) {
			int x = p.get(i).x;
			int y = p.get(i).y;
			//System.out.println(y + " " + x);
			if(!m[y][x]) {
				continue;
			}
			g[y][x] = 1;
			m[y][x] = false;
			cnt1 = 0;
			cnt2 = 1;
			rec('#', x, y);
			//System.out.println(cnt1 +" " + cnt2);
			ans += cnt1 * cnt2;

		}
		System.out.println(ans);
	}
	static void rec(char color, int x, int y) {
		int[] dx = {1, -1, 0, 0};
		int[] dy = {0, 0, 1, -1};
		for(int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx >= 0 && nx < W && ny >= 0 && ny < H) {
				if(color == '#' && m[ny][nx] && c[ny][nx] == '.') {
					m[ny][nx] = false;
					cnt1++;
					rec('.', nx, ny);
				}else if(color == '.' && m[ny][nx] && c[ny][nx] == '#') {
					g[ny][nx] = 1;
					m[ny][nx] = false;
					cnt2++;
					rec('#', nx, ny);
				}
			}
		}
	}
}

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

string s;
string dm = "dream", ee = "erase", dr = "dreamer", er = "eraser";
bool flag;

int main()
{
    cin >> s;
    s += "---";
    int n = s.size();
    for(int i = 0; i < n; i++){
        if(n - i - 3 < 5){
            printf("NO\n");
            return 0;
        }
        if(s.substr(i, 7) == dr && (s[i + 7] == 'e' || s[i + 7] == 'd' || s[i + 7] == '-')){
            i += 6;
            if(n - 4 == i){
                printf("YES\n");return 0;
            }
        }
        else if(s.substr(i, 6) == er && (s[i + 6] == 'e' || s[i + 6] == 'd' || s[i + 6] == '-')){
            i += 5;
            if(n - 4 == i){
                printf("YES\n");return 0;
            }
        }
        else if((s.substr(i, 5) == dm || s.substr(i, 5) == ee) && (s[i + 5] == 'e' || s[i + 5] == 'd' || s[i + 5] == '-')){
            i += 4;
            if(n - 4 == i){
                printf("YES\n");return 0;
            }
        }
        else {
            printf("NO\n");
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
#define max1 1000001

//long long int mod=1e18 ;


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


}
	
	
	
	





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

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

    int input[m][2];
    for(int i=0; i<m; i++) cin>>input[i][0]>>input[i][1];

    int final[n];
    for(int i=0; i<n; i++) final[i]=-1;

    bool flag = true;
    for(int i=0; i<m; i++) {
        if(final[input[i][0]-1]!=-1 && final[input[i][0]-1]!=input[i][1]) {
            flag=false;
            break;
        }
        else final[input[i][0]-1] = input[i][1];
    }
    if(n!=1 && final[0]==0) flag=false;

    if(!flag) {
        cout<<-1<<endl;
        return 0;
    }

    int ans = 0;
    for(int i=0; i<n; i++) {
        if(final[i]!=-1) ans += final[i]*pow(10, n-1-i);
    }    

    if(n!=1 && final[0]==-1) ans += pow(10, n-1);

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */
int powz(int v,int k) { int r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> x(n);
	rep(i,n) std::cin >> x[i];
	int L;
	std::cin >> L;

	// left to right index to the max in one day
	std::vector<int> ltor(n);
	{
		int r;
		r=0;
		for(int l=0;l<n;l++) {
			while(r<n && x[r]-x[l]<=L) r++;
			ltor[l] = r-1;
		}
	}
	std::vector<std::vector<int> > ltord(20,std::vector<int>(n) );
	ltord[0] = ltor;
	for( int d=0;d<19;d++) {
		rep(i,n) ltord[d+1][i] = ltord[d][ltord[d][i]];
	}

	std::reverse(all(x));

	std::vector<int> rtol(n);
	{
		int r;
		r=0;
		for(int l=0;l<n;l++) {
			while(r<n && x[l]-x[r]<=L) r++;
			rtol[l] = r-1;
		}
	}
	std::vector<std::vector<int> > rtold(20,std::vector<int>(n) );
	rtold[0] = rtol;
	for( int d=0;d<19;d++) {
		rep(i,n) rtold[d+1][i] = rtold[d][rtold[d][i]];
	}

	int q;
	std::cin >> q;
	rep(z,q) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		if(a>b) {
			a=n-1-a;b=n-1-b;
			int days = 0;
			int current = a;
			while(current!=b) {
				int minv = 20;
				for(int v=19;v>=0;v--) {
					if(rtold[v][current]<=b) {
						minv = v;
						if(b!=n-1) break;
					}
				}
				if(minv==20) {
					days+=1;
					current = b;
				}
				else {
					days+=powz(2,minv);
					current = rtold[minv][current];
				}
			}
			print(days);
		}
		else {
			int days = 0;
			int current = a;
			while(current!=b) {
				int minv = 20;
				for(int v=19;v>=0;v--) {
					if(ltord[v][current]<=b) {
						minv = v;
						if(b!=n-1) break;
					}
				}
				if(minv==20) {
					days+=1;
					current = b;
				}
				else {
					days+=powz(2,minv);
					current = ltord[minv][current];
				}
			}
			print(days);
		}
	}

	return 0;
}


Measured memory_bytes: 36720