akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        String s=sc.next();
        int ans=0;
        
        if(s.length()<2||s.length()%2!=0){
            System.out.println("No");
        }
        else{
            for(int i=0; i<s.length(); i+=2){
                if(s.charAt(i)=='h'&&s.charAt(i+1)=='i'){
                    ans++;
                }
            }
            if(ans==s.length()/2){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        }
        sc.close();
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

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

    ll i,j,n;
    cin>>n;
    vector<ll> a(12);
    a[0] = 0;
    for(i=1;i<12;i++) a[i] = a[i-1] + pow(26,i);
    // for(auto k: a) cout<<k<<" ";
    i = 1;
    while(a[i] < n) i++;
    ll diff = n-a[i-1]-1;
    vector<ll> r;
    while(diff)
    {
        r.pb(diff%26);
        diff/=26;
    }
    if(r.empty()) 
    {
        for(j=0;j<i;j++) cout<<'a';
        return 0;
    }
    reverse(all(r));
    vector<char> ch;
    for(auto e: r)
    {
        ch.pb(char('a'+e));
    }
    ll rem = i-sz(ch);
    for(j=0;j<rem;j++) cout<<'a';
    for(auto s: ch) cout<<s;
}

Measured memory_bytes: 4064
#include<cstdio>
#include<algorithm>
using namespace std;
int n, m, res;
int w[101000], UF[101000];
int Find(int a) {
	if (a == UF[a])return a;
	return UF[a] = Find(UF[a]);
}
int main() {
	int i, a, b;
	scanf("%d%d", &n,&m);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		UF[i] = i;
	}
	for (i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		a = Find(a), b = Find(b);
		if (a != b)UF[a] = b;
	}
	for (i = 1; i <= n; i++) {
		if (Find(w[i]) == Find(i))res++;
	}
	printf("%d\n", res);
}

Measured memory_bytes: 896
"use strict"
function Main(input) {
    if (!input.match(/([\n])/)){
        input = input.split(" ");
    } else {
        input = input.split("\n");
        for (var i = 0; i < input.length; i++){
            input[i] = input[i].split(" ");
        }
    }
    //中身↓
    let end = "D";
    if(input[0]<=999){
        end = "C";
    }
    console.log("AB"+end);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
template<typename T>
struct edge {
  int to, from;T cost;
  edge(int to) : from(-1), to(to), cost(-1) {}
  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template<typename T>
using edges = vector<edge<T>>;
template<typename T>
using graph = vector<edges<T>>;
template<typename T>
using matrix = vector<vector<T>>;

template<typename T>
bool compByCost(const edge<T>& left, const edge<T>& right){
  return left.cost < right.cost; 
}

template<typename T>
vector<vector<T>> warshall(matrix<T> &g){
  vector<vector<T>> dist(g.size());
  rep(i,g.size()){
    dist[i].resize(g.size());
    rep(j,g.size())dist[i][j] = (i == j ? 0 : g[i][j]);
  }
  rep(k,g.size()){
    rep(i,g.size()){
      rep(j,g.size()){
        if(dist[i][k] == INF || dist[k][j] == INF)continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return dist;
}

#define warshall warshall<int>// matの初期化でINFを詰めておく



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

int h,w,d,q,a[310][310], l[110000], r[110000];
P ax[310*310];
int dist[310*310];
signed main(){
  cin>>h>>w>>d;
  rep(i,h)rep(j,w){
    cin>>a[i][j];
    ax[a[i][j]] = P(i, j);
  }
  cin>>q;
  rep(i,q)cin>>l[i]>>r[i];
  repd(i,1,w*h+1){
    if(i <= d)dist[i] = 0;
    else{
      P p = ax[i], q = ax[i-d];
      dist[i] = dist[i-d] + abs(p.first - q.first) + abs(p.second - q.second);
    }
  }
  rep(i,q){
    cout << dist[r[i]] - dist[l[i]] << endl;;
  }
}


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

int const N = 1234567;

long long c[N];
int a[N], b[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", a + i, b + i);
  for (int i = 0; i < n; i++) c[i] = a[i];
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    c[i] += ans;
    long long need = (c[i] + b[i] - 1) / b[i] * b[i];
    ans += need - c[i];
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 1792
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn main() {
    input! {
    x1: i64,
    y1: i64,
    x2: i64,
    y2: i64
    }
    let x3 = x2 + y1 - y2;
    let y3 = x2 + y2 - x1;
    let x4 = x1 + y1 - y2;
    let y4 = y1 + x2 - x1;
    println!("{} {} {} {}", x3, y3, x4, y4);
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,k;
  cin>>n>>k;
  int mx = (n-1)*(n-2)/2;
  if(k>mx){
    cout<<"-1"<<endl;
    return 0;
  }
  vp uv;
  int cnt =0;
  rep(i,n-1){
    uv.emplace_back(i+1,n);
  }
  rep(i,n-1){
    rep(j,i){
      if(cnt>=mx-k)continue;
      uv.emplace_back(i+1,j+1);
      cnt++;
    }
  }

  cout<<sz(uv)<<endl;
  for(auto it: uv){
    cout<<it.fi<<" "<<it.se<<endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define T tuple<int, int, int>
int X, Y, Z, K;
ll A[1010], B[1010], C[1010];

struct edge{
    int x, y, z;

    ll culc() const {
        return A[x] + B[y] + C[z];
    }
    
    void output(){
        cout << x << " " << y << " " << z << endl;
    }

    bool operator < (const edge& e) const {
        return culc() < e.culc();
    }
};

void input(){
    cin >> X >> Y >> Z >> K;

    for(int i = 0; i < X; i++){
        cin >> A[i];
    }
    for(int i = 0; i < Y; i++){
        cin >> B[i];
    }
    for(int i = 0; i < X; i++){
        cin >> C[i];
    }
}


void solve(){
    sort(A, A + X);
    sort(B, B + Y);
    sort(C, C + Z);
    X--, Y--, Z--;
    
    priority_queue<edge> q;
    set<T> st;
    q.push(edge{X, Y, Z});
    st.insert(T{X, Y, Z});
    for(int i = 0; i < K; i++){
        edge e = q.top();
        q.pop();

        cout << e.culc() << endl;

        if(e.x != 0){
            edge f = {e.x - 1, e.y, e. z};

            if(st.find(T{e.x - 1, e.y, e.z}) == st.end()){
                st.insert(T{e.x - 1, e.y, e.z});
                q.push(f);
            }
        }

        if(e.y != 0){
            edge f = {e.x, e.y - 1, e. z};

            if(st.find(T{e.x, e.y - 1, e.z}) == st.end()){
            
                st.insert(T{e.x, e.y - 1, e.z});
                q.push(f);
            }        
        }

        if(e.z != 0){
            edge f = {e.x, e.y, e.z - 1};

            if(st.find(T{e.x, e.y, e.z - 1}) == st.end()){
                st.insert(T{e.x, e.y, e.z - 1});
                q.push(f);
            }
        }
    }
}

int main(){
    input();
    solve();
    return 0;
}

Measured memory_bytes: 768
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
#from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


h,w,m=mdata()
bombh=[0]*h
bombw=[0]*w
s=set()
for i in range(m):
    x,y=mdata()
    x-=1
    y-=1
    s.add((x,y))
    bombh[x]+=1
    bombw[y]+=1
cnt=0
mh=max(bombh)
mw=max(bombw)
for (i,j) in s:
    if bombh[i]==mh and bombw[j]==mw:
        cnt+=1
k=0
for i in range(h):
    if bombh[i]==mh:
        k+=1
for i in range(w):
    if bombw[i]==mw:
        cnt-=k
if cnt==0:
    out(mh+mw-1)
else:
    out(mh+mw)

Measured memory_bytes: 130880
n = int(input())
A = list(map(int, input().split()))

A.sort()

if len(A) == 2:
    print(A[1], A[0])
else:
    a = A[-1]
    k = a / 2
    B = [a for a in A if a <  k]
    C = [a for a in A if a >= k]

    if k - B[-1] > C[0] - k:
        print(a, C[0])
    else:
        print(a, B[-1])


Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define rep(i,b) for(ll i=0;i<b;i++)
#define all(v) (v).begin(),(v).end()

int main() {
    ll n,q,b,l,r;
    cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    cin>>q;
    rep(i,q){
        cin>>b>>l>>r;
        vl B=a;
        sort(B.begin()+l,B.begin()+r);
        if(b==0)cout<<B[l]<<endl;
        else cout<<B[r-1]<<endl;
    }
}


Measured memory_bytes: 3164
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1e5+5;

int n;
LL a[maxn],sum[maxn];

int main()
{
	scanf("%d",&n);
	memset(sum,0,sizeof(sum));
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int mx = 0;
	for(int i = 1;i < n;i++)
	{
		if(2*sum[i] < a[i+1]) mx = max(mx,i);
	}
	printf("%d\n",n-mx);
	return 0;
}


Measured memory_bytes: 1792
H,W,N=map(int,input().split())
ans=H
Y=[0]*H
ob=[float("inf")]*H
for i in range(N):
  x,y=map(int,input().split())
  ob[x-1]=min(ob[x-1],y-1)
for i in range(1,H):
  if ob[i]==Y[i-1]+1:
    Y[i]=Y[i-1]
  else:
    Y[i]=Y[i-1]+1
for i in range(1,H):
  if ob[i]<=Y[i]:
    ans=min(ans,i)
print(ans)


Measured memory_bytes: 56144
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
	
}

int main()
{
	int a,b,c;
	string S,T;
	cin>>a>>b;
	cout<<(a*500>=b?"Yes":"No");
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int flag;
	int i;
	int n;
	int num[3] = {0,0,0};
	
	
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d %d %d",&num[0], &num[1], &num[2]);
		
			do{
				int  j, temp=0;
				flag=0;
				for(j=0; j<2; j++){
					if(num[j+1]<num[j]){
						temp = num[j+1];
						num[j+1] = num[j];
						num[j] = temp;
						flag = 1;
					}
					
				}
				
			}while(flag==1);
		
		//printf("%d %d %d\n",num[0], num[1], num[2]);
		
		if(((num[0]*num[0])+(num[1]*num[1]))==(num[2]*num[2])) printf("YES\n");
		else printf("NO\n");
	
	}

	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int H, W;
    cin >> H >> W;
    vector<vector<char>> grid(H + 2, vector<char>(W + 2));
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> grid.at(i).at(j);
        }
    }
    
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (grid.at(i).at(j) == '#' && grid.at(i - 1).at(j) != '#' && grid.at(i + 1).at(j) != '#'
                && grid.at(i).at(j - 1) != '#' && grid.at(i).at(j + 1) != '#') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}


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




int main(){ 
      ll n,m;
      cin >> n >>m;
      vector<ll> a(n);
      vector<pair<ll,ll>> cb(m) ;
      for(int i=0;i<n;i++){
            cin >> a[i];
      }
      for(int i=0;i<m;i++){
            cin >> cb[i].second >> cb[i].first;
      }
      sort(cb.begin(),cb.end(),greater<>()); //降順
      sort(a.begin(),a.end()); //昇順
      int golgi = -1;
      int ed = 0;
      for(int j=0;j<m;j++){
            if(ed == 1) break;
            for(int k=0;k<cb[j].second;k++){
                  if(a[golgi+1+k]>cb[j].first){
                        ed = 1;
                        break;
                  }
                  a[golgi+1+k] = cb[j].first;
                  
            }
            golgi += cb[j].second;
      }
      ll ans=0;
      for(int i=0;i<n;i++){
            ans += a[i];
      }
      cout << ans << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//互除法
ll GCD(ll a, ll b){
  return b ? GCD(b,a%b) : a;
}

ll LCM(ll a, ll b){
  return (a / GCD(a,b))*b;
}

int main()
{
  //方針
  //最大公約数を素因数分解して素因数の種類+1を求める。
  
  //input
  ll a, b;
  cin >> a >> b;
  
  //main
  int ans = 0;
  ll g = GCD(a,b);
  
  if(g%2 == 0){
    while(g%2 == 0){
      g /= 2; 
    }
    ans ++;
  }
  
  for(ll i=3; i*i<=g; i+=2){//1と2は別に扱っても問題ない。
    if(i != 3 && i%3 == 0) continue;
    if(g%i == 0){
      while(g%i == 0){
        g /= i; 
      }
      ans ++;
    }
  }
  if(g != 1){//自身が素数の時
    ans ++; 
  }
  
  // output
  output(ans+1);//1の分
    
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>

using namespace std;
int a, b;

int main() {
  cin >> a >> b;

  char ans = 'x';
  if (a*b == 15) {
    ans = '*';
  }
  if (a+b == 15) {
    ans = '+';
  }
  cout << ans << endl;
}


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

int main(){
	int n[6];
	int c[4]={};
	for(int i=0;i<6;i++)
	{
		cin>>n[i];
		c[n[i]-1]++;
	}
	sort(c,c+4);
	if(c[0]==1&&c[1]==1&&c[2]==2&&c[3]==2)cout<<"YES";
	else cout<<"NO";
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int b[20], p[20];
  int ones = 0;
  for (auto i=0; i<N; i++) {
    cin >> b[i];
    ones += b[i];
  }
  /* for (auto j=0; j<N; j++) {
    cerr << b[j];
  }
  cerr << endl; */
  for (auto j=0; j<M; j++) {
    cin >> p[j];
  }
  int ans = 100000000;
  for (int i=0; i<2; i++) {
    int q[20];
    int cur = 0;
    int onesq = 0;
    for (int j=0; j<M; j++) {
      for (int k=0; k<p[j]; k++) {
	q[cur+k] = (j+i)%2;
	onesq += q[cur+k];
      }
      cur += p[j];
    }
    /* for (auto j=0; j<N; j++) {
      cerr << q[j];
    }
    cerr << endl; */
    if (ones == onesq) {
      int tans = 0;
      for (int j=0; j<N; j++) {
	if (q[j] != b[j]) {
	  for (int k=j+1; ; k++) {
	    assert(k < N);
	    if (q[k] == b[j]) {
	      swap(q[k], q[j]);
	      // cerr << "swap at " << k << " and " << j << endl;
	      tans += k-j;
	      break;
	    }
	  }
	}
      }
      if (ans > tans) ans = tans;
    }
  }
  assert(ans < 100000000);
  cout << ans << endl;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main()
{
    int a , b , c ,d , ar1=0 , ar2=0 ;
    cin >> a >> b >> c >> d  ;
    ar1 = a*b ;
    ar2 = c*d ;
    if ( ar1 > ar2 )
        cout << ar1 << endl ;
    else if ( ar1 < ar2 )
        cout << ar2 << endl ;
    else
        cout << ar1 << endl ;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
	// write your code here
        int n = Integer.parseInt(br.readLine().trim());
        List<Integer> tmp = new ArrayList<Integer>();
        for (int i=0; i<n; i++){
            int d = Integer.parseInt(br.readLine().trim());
            tmp.add(d);
        }
        List<Integer> dl = new ArrayList<Integer>(new HashSet<>(tmp));
        System.out.println(dl.size());
    }

}



Measured memory_bytes: 23252
N,K = map(int,input().split())
ab = []
#for i in range(N):
#    ab.append(list(map(int,input().split())))

ab = sorted(list(map(int,input().split())) for i in range(N))

s = 0
for l in ab:
    s += l[1]
    if s >= K:
        print(l[0])
        break


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

using namespace std;

int main(){
    vector<int> N;
    for(int i=0; i<3; i++){
        int n; cin >> n;
        N.push_back(n); 
    }

    sort(N.begin(),N.end());
    int a = N.at(0);
    int b = N.at(1);
    int c = N.at(2);
    int ans;

    if(a%2 == b%2){
        ans = (b-a)/2 + c-b;
    }else{
        ans = c-b + (b-a+1)/2 + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
	int n,a[3],x,i,j;
	scanf("%d", &n);
	for(i=1; i<=n; i++)
	scanf("%d", &a[i]);
	for(i=1; i<n; i++)
	{
		for(j=n-1; j>=i+1; j--)
		{
			if(a[j]<a[j-1])
			{
				x=a[j];
				a[j]=a[j-1];
				a[j-1]=x;
			}
		}
	}
	for(i=1; i<=a[1]; i++)
	{
		for(j=1; j<=n; j++)
		{
			if(a[j]%i!=0)
			break;
			else if(j==n)
			printf("%d\n", i);
		}
	}
	
	return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
using namespace std;

int n,a[100009];
int gcd(int x,int y){ return y?gcd(y,x%y):x; }
int main(){
	scanf("%d",&n);
	int i;
	for (i=1; i<=n; i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int ans=a[1];
	for (i=2; i<=n; i++) ans=(ll)ans*gcd(i-1,a[i])%998244353;
	printf("%d\n",ans);
	return 0;	
}

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

int main() {
  string S;
  cin >> S;

  // YYMM
  // MMYY
  // AMBIGUOUS
  // NA
  int s = atoi(S.c_str());

  int before = s / 100;
  // 13以上: YY
  // 12以下: MM

  int after = s % 100;

  // a

  if (0 < before && before <= 12) {
    if (0 < after && after <= 12) {
      printf("AMBIGUOUS");
    } else {
      printf("MMYY");
    }
  } else {
    if (0 < after && after <= 12) {
      printf("YYMM");
    } else {
      printf("NA");
    }
  }

  return 0;
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
ans=''
#1
for i in range(c-a):
    ans +='R'
for i in range(d-b):
    ans +='U'
for i in range(c-a):
    ans +='L'
for i in range(d-b+1):
    ans +='D'
for i in range(c-a+1):
    ans +='R'
for i in range(d-b+1):
    ans +='U'
ans +='L'
ans +='U'
for i in range(c-a+1):
    ans +='L'
for i in range(d-b+1):
    ans +='D'
ans+='R'
print(ans)

Measured memory_bytes: 3064
def solve(N: int):
    coins = set()
    coins.add(1)
    i = 1
    while 6**i <= N:
        coins.add(6**i)
        i += 1
    i = 1
    while 9**i <= N:
        coins.add(9**i)
        i += 1
         

    dp = [float('inf')] * (N + 1)
    dp[0] = 0
    
    for n in range(1, N + 1):
        for coin in coins:
            if n - coin >= 0:
                dp[n] = min(dp[n - coin] + 1, dp[n])
                
    return dp[N]
N = int(input())
print(solve(N))

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

int c[3][3];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    bool flag = true;
    rep(i, 3) if (c[i][1]-c[i][0]!=c[0][1]-c[0][0]) flag = false;
    rep(i, 3) if (c[i][2]-c[i][1]!=c[0][2]-c[0][1]) flag = false;
    rep(i, 3) if (c[1][i]-c[0][i]!=c[1][0]-c[0][0]) flag = false;
    rep(i, 3) if (c[2][i]-c[1][i]!=c[2][0]-c[1][0]) flag = false;
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	
	int s, i , count;
	
	scanf("%d", &s);
	count = 0;
	for( i = 0; i < 3; i++ ){
		if( s % 10 == 1 ) count++;
		s /= 10;
	}
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var (
		a, b int
		s    string
	)

	fmt.Scan(&a, &b, &s)

	var ans string
	if a+b+1 == len(s) {
		prefix := s[0:a]
		hyphen := s[a : a+1]
		suffix := s[a+1:]

		_, a_err := strconv.Atoi(prefix)
		_, b_err := strconv.Atoi(suffix)

		if a_err != nil || b_err != nil || hyphen != "-" {
			ans = "No"
		} else {
			ans = "Yes"
		}

	} else {
		ans = "No"
	}
	fmt.Println(ans)
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  ll now = n;
  map<ll, ll> mp;
  for (ll i = 2; i * i <= n; i++) {
    while (now % i == 0) {
      mp[i]++;
      now /= i;
    }
  }
  if (now > 1) mp[now]++;
  
  ll ans = 0;
  for (auto i : mp) {
    ll keep = i.second;
    for (int j = 1; j < 100; j++) {
      if (keep < j) break;
      ans++;
      keep -= j;
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 3624
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, i;
		int[] x = new int[100], y = new int[100];
		double[] dist = new double[4];
		
		for(i = 0; i < 4; i++){
			dist[i] = 0;
		}
		
		n = sc.nextInt();
		
		for(i = 0; i < n; i++){
			x[i] = sc.nextInt();
		}
		for(i = 0; i < n; i++){
			y[i] = sc.nextInt();
		}
		
		for(i = 0; i < n; i++){
			dist[0] += Math.abs(x[i] - y[i]);
			dist[1] += Math.pow(x[i] - y[i], 2);
			dist[2] += Math.pow(Math.abs(x[i] - y[i]), 3);
			dist[3] = Math.max(dist[3], Math.abs(x[i] - y[i]));
		}
		
		dist[1] = Math.abs(Math.sqrt(dist[1]));
		dist[2] = Math.pow(dist[2], 0.3333333333);
		
		for(double d : dist){
			System.out.println(d);
		}
	}
}

Measured memory_bytes: 26516
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {

       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        int i = 1;
        while (true) {
            int n = Integer.parseInt(br.readLine());
            if (n == 0) {
                break;
            }
            sb.append("Case ").append(i).append(": ").append(n).append("\n");
            i++;
        }
        System.out.print(sb);
    }

}

Measured memory_bytes: 30732
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define dec(i,j,k) for(re int i=j;i>=k;i--)
#define lc o<<1
#define rc o<<1|1
const int N=5e5+5; 
using namespace std;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,k,p[N],maxx[N<<2],ans[N];
int gmax(int a,int b){return p[a]>p[b]?a:b;}
priority_queue<int> q;
bool in[N];
void build(int o,int l,int r){
	if(l==r) return maxx[o]=l,void();
	int mid=(l+r)>>1;
	build(lc,l,mid),build(rc,mid+1,r);
	maxx[o]=gmax(maxx[lc],maxx[rc]);
}
void del(int o,int l,int r,int x){
	if(l==r){p[l]=0;return;}
	int mid=(l+r)>>1;
	if(x<=mid) del(lc,l,mid,x);
	else del(rc,mid+1,r,x);
	maxx[o]=gmax(maxx[lc],maxx[rc]);
}
int query(int o,int l,int r,int x,int y){
	if(y<l||r<x) return 0;
	if(x<=l&&r<=y) return maxx[o];
	int mid=(l+r)>>1,res=0;
	if(x<=mid) res=gmax(res,query(lc,l,mid,x,y));
	if(mid<y) res=gmax(res,query(rc,mid+1,r,x,y));
	return res;
}
void putin(int x){
	if(in[x]) return;
	if(query(1,1,n,x-k+1,x+k-1)==x) q.push(x),in[x]=1;
}
int main(){
	n=read(),k=read();
	inc(i,1,n) p[i]=read();
	in[0]=1;build(1,1,n);
	inc(i,1,n) putin(i);
	dec(i,n,1){
		int u=q.top();q.pop();
		ans[u]=i;
		del(1,1,n,u);
		putin(query(1,1,n,u-k+1,u-1));
		putin(query(1,1,n,u+1,u+k-1));
	}
	inc(i,1,n) printf("%d\n",ans[i]);
}

Measured memory_bytes: 15728
#!/usr/bin/env python3

import numpy as np

def main():
    h, w = map(int, input().split())
    s = [list(input()) for i in range(h)]
    s = np.array(s)

    flag = True
    for i in range(h):
        for j in range(w):
            if s[i, j] == "#":
                if not adj(s, h, w, i, j):
                    flag = False
    print("Yes" if flag else "No")

def adj(s, h, w, i, j):
    up = s[i - 1, j] if i > 0 else "."
    down = s[i + 1, j] if i < h - 1 else "."
    left = s[i, j - 1] if j > 0 else "."
    right = s[i, j + 1] if j < w - 1 else "."
    return ("#" in [up, down, left, right])

main()



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

int main() {
  map<int, int> m;
  m[1] = 300000;
  m[2] = 200000;
  m[3] = 100000;
  int x, y;
  cin >> x >> y;
  cout << m[x] + m[y] + (x == 1 && y == 1 ? 400000 : 0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll a[110];
ll dp[110];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        dp[i] = max(1000LL, dp[i]);
        if (i != 0)
            dp[i] = max(dp[i], dp[i-1]);
        for (int j = i + 1; j < n; j++) {
            dp[j] = max(dp[j], (dp[i] / a[i]) * a[j] + dp[i] - (dp[i]/a[i]) * a[i]);
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n, m, d;
	cin >> n >> m >> d;

	double ans = (double)(n - d) * (double)(m - 1) / (double)(n * n);
	if (d != 0) ans *= 2;
	cout << fixed << setprecision(12);
	cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct node
{
	ll s,w,v;
};
node bl[1010];
ll n,f[20010],ans;
bool cmp(node a1,node b1)
{
	return a1.s+a1.w<b1.s+b1.w;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>bl[i].w>>bl[i].s>>bl[i].v;
	sort(bl+1,bl+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		for(int j=20010;j>=bl[i].w;j--)
		{
			if(bl[i].s+bl[i].w>=j)
				f[j]=max(f[j],f[j-bl[i].w]+bl[i].v);
			ans=max(ans,f[j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3


def main():
    N, x, *A = map(int, open(0).read().split())
    A.sort()
    for i in range(N):
        x -= A[i]
        if x == 0:
            print(i + 1)
            break
        elif x < 0:
            print(i)
            break
    else:
        # ちょうどN個もらわないと喜べない悲しい子どもたち
        print(N - 1)


main()


Measured memory_bytes: 9132
#include <iostream>
#include <stdio.h>
using namespace std;

int getMinIndex(int* arr,int l,int r){
    if(arr[l] < arr[r]){
        return l;
    }
    // 値が同じ場合は便宜上末端を返すようにする
    else{
        return r;
    }
}

int main() {
    int n,partLength,minIndex = -1;
    //cin >> n >> partLength;
    scanf("%d %d",&n,&partLength);
    int a[n];
    for(int i = 0;i < n;++i){
        //cin >> a[i];
        scanf("%d",&a[i]);
    }
    
    for(int i = 0;i + partLength - 1 < n;++i){
        // 最小値のindexが範囲外になった場合
        if(minIndex < i){
            minIndex = i;
            // 範囲内から最小のindexを探し出す奥の値を返すようにすればいいじゃねぇか
            for(int j = i + 1;j < i + partLength;++j){
                if(a[minIndex] >= a[j]){
                    minIndex = j;
                }
            }
        }
        else{
            // 最小値の値と末端の値を比べる
            minIndex = getMinIndex(a,minIndex,i + partLength - 1);
        }
        if(i){
            //cout << " ";
            printf(" ");
        }
        //cout << a[minIndex];
        printf("%d",a[minIndex]);
    }
    //cout << endl;
    printf("\n");
}



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

int main() {
  string S;
  cin>>S;
  stack<char> p;
  p.push('T');
  for(int i=0;i<S.size();i++){
    if(S[i]=='S') p.push('S');
    else if(S[i]=='T'&&p.top()=='S') p.pop();
    else p.push('T');
  }
  cout<<p.size()-1<<endl;
}
    

Measured memory_bytes: 644
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int nValue; // 1 <= N
        int kValue; //<= 100
//        int checkN;
        Scanner scanner = new Scanner(System.in);
//
//        System.out.println("1 以上 N 以下の異なる整数を、差が 1 の整数をともに選ばないように K 個選びます");
//        System.out.println("NとKをそれぞれ半角空白で区切って入力してください");
//        System.out.println("例: input ->10 90");
//        System.out.println("input >>");

        String N = scanner.next();
        String K = scanner.next();

        try {
        nValue = Integer.parseInt(N);

        } catch (NumberFormatException e) {
//            System.out.println();
            return;
        }
        try {
        kValue = Integer.parseInt(K);

        } catch (NumberFormatException e) {
            return;
        }


//        if (100 < kValue || kValue < 1) {
////            System.out.println("Kの値は1以上100以下の整数を入力してください。終了します。");
//            return;
//        }
//        if (nValue < 2) {
////            System.out.println("Nの値は1以上の整数を入力してください。終了します。");
//            return;
//        }


        if (nValue % 2 == 1) {
            nValue = nValue + 1;
        }
//        else {
//            checkN = nValue;
//        }

        if ((nValue  /  2) >= kValue ) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
        scanner.close();
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[100001] = {};
ll s[100001] = {};
map<ll, ll> mp;
int main()
{
	ll n, m; cin >> n >> m;

	repe(i, 1, n) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
		mp[s[i] % m]++;
	}

	ll cnt = mp[0];
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second >= 2) {
			cnt += it->second* (it->second - 1) / 2;
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>

bool isPrime(int x)
{
  if (x < 2)
  {
    return false;
  }
  else if (x == 2)
  {
    return true;
  }
  if (x % 2 == 0)
  {
    return false;
  }

  for (int i = 3; i * i <= x; i += 2)
  {
    if (x % i == 0)
    {
      return false;
    }
  }

  return true;
}

int main()
{
  int n, x;
  int count = 0;

  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &x);
    if (isPrime(x))
    {
      count++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 2628
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))

L = R = 0
for k, v in c.items():
    if 4 <= v:
        L = max(L, k)
        R = max(R, k)
    elif 2 <= v:
        if R < L:
            L, R = R, L
        L = max(L, k)

print(L*R)


Measured memory_bytes: 28196
n = int(input())
s = map(int, input().split())
s = list(s)
num = 0
ASC, DES, EQ, UND = 0, 1, 2, 3
state = UND
if len(s) <= 2:
    print(1)
    exit()
i = s[0]
for j in s[1:]:
    if state == UND:
        if i > j:
            state = DES
        elif i < j:
            state = ASC
        else:
            state = EQ
        num += 1
    elif state == EQ:
        if i > j:
            state = DES
        elif i < j:
            state = ASC
    elif state == DES:
        if i >= j:
            pass
        else:
            state = UND
    else:
        if i <= j:
            pass
        else:
            state = UND
    i = j
if state == UND:
    num += 1

print(num)


Measured memory_bytes: 14480
from operator import itemgetter

lst=[]
n=int(input())
for _ in range(n):
    lst.append(list(map(int,input().split())))
lst.sort(key=itemgetter(1))

t=0
for a,b in lst:
    t +=a
    if t>b:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 89688
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#include<regex>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }
const LL MOD = 1e9 + 7;
const LL LLINF = 1LL << 60;
const int INF = 1 << 30;

int main(void) {
	string S;
	cin >> S;

	string T;
	int i = 0;
	while (i < S.size()) {
		if (S[i] == 'B' and S[i + 1] == 'C') {
			T.push_back('D');
			i += 2;
		}
		else {
			T.push_back(S[i]);
			i++;
		}
	}

	LL ans = 0;
	LL a_count = 0;
	for (i = 0; i < T.size(); i++) {
		if (T[i] == 'A') a_count++;
		else if (T[i] == 'D') ans += a_count;
		else a_count = 0;
	}

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

Measured memory_bytes: 776
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = Data.List.map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = Data.List.map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	board  <- replicateM 3 readInts
	n <- readInt
	as <- replicateM n readInt
	putStrLn $ if solve board as
		then "Yes"
		else "No"
	
solve board as = runST $ do
	res <- newArray ( 0, 7 ) True :: ST s ( STUArray s Int Bool )
	forM_ [ 0 .. 2 ] $ \i -> do
		forM_ [ 0 .. 2 ] $ \j -> do
			modifyArray res i $ (&&) $
				( board !! i !! j ) `elem` as
			modifyArray res ( 3 + j ) $ (&&) $
				( board !! i !! j ) `elem` as

		modifyArray res 6 $ (&&) $
			( board !! i !! i ) `elem` as
		modifyArray res 7 $ (&&) $
			( board !! i !! ( 2 - i ) ) `elem` as
	or <$> getElems res

Measured memory_bytes: 508
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  string tmp=to_string(n);
  bool flag=true;
  rep(i,tmp.size()-1){
    if(tmp[i+1]!='9') flag=false; 
  }
  if(flag) cout<<Sint(n)<<endl;
  else cout<<9*(tmp.size()-1)+(n/(ll)pow(10,tmp.size()-1)-1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 2e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

vector<int>pos[MAXN];
int n;

int main() 
{
    fastio();

    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        pos[x].pb(i);
    }

    int st = -1;
    int ptr = 1;
    while( 1 )
    {
        int lb = lower_bound( pos[ptr].begin(), pos[ptr].end(), st) - pos[ptr].begin();
        if( lb == pos[ptr].size() )
            break;
        st = pos[ptr][lb];
        ptr++;
    }

    if( st == -1 )
    {
        cout<<-1,nl;
        return 0;
    }
    cout<<n-ptr+1;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 11264
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		long[]A = new long[N];
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str[i]);
		}
		long[,]D = new long[N+1,2];
      	D[1,0] = D[0,0]+A[0];
      	D[1,1] = D[0,0]-A[0];
		for(var i=1;i<N-1;i++){
			D[i+1,0] = Math.Max(D[i,0]+A[i],D[i,1]-A[i]);
			D[i+1,1] = Math.Max(D[i,0]-A[i],D[i,1]+A[i]);
		}
      	D[N,0] = Math.Max(D[N-1,0]+A[N-1],D[N-1,1]-A[N-1]);
		Console.WriteLine(D[N,0]);
	}
}

Measured memory_bytes: 31324
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#define ll long long 
#define fr(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define inf (1<<31)
#define xx first
#define yy second

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	string s,t;
    int f=1;
    cin>>s;
    int l=s.length()-1;
    while(f && l>=0){
        f=0;
        if(l>=6 && s[l]=='r' && s[l-1]=='e' && s[l-2]=='m' && s[l-3]=='a' && s[l-4]=='e' && s[l-5]=='r' && s[l-6]=='d'){
            l-=7;
            f=1;
            
        }
        else if(l>=4 && s[l]=='m' && s[l-1]=='a' && s[l-2]=='e' && s[l-3]=='r' && s[l-4]=='d'){
            l-=5;
            f=1;
        }   
        else if(l>=4 && s[l]=='e' && s[l-1]=='s' && s[l-2]=='a' && s[l-3]=='r' && s[l-4]=='e'){
            l-=5;
            f=1;
        }   
        else if(l>=5 && s[l]=='r' && s[l-1]=='e' && s[l-2]=='s' && s[l-3]=='a' && s[l-4]=='r' && s[l-5]=='e'){
            l-=6;
            f=1;
        } 
    }
    if(l==-1)
        cout<<"YES";
    else
        cout<<"NO";

	
	return 0;
}

Measured memory_bytes: 512
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

void rsort_u32(void *base, const int count){
	typedef uint32_t rsort_t;
	rsort_t *a=base;
	rsort_t *b=malloc(count*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}

int b[100001];
int main(void){
	int n=nextint();
	int m=nextint();
	int a=0;
	for(int i=1; i<=n; i++){
		a=(a+nextint())%m;
		b[i]=a;
	}
	rsort_u32(b, n+1);
	long ans=0;
	int s=1;
	for(int i=1; i<=n; i++){
		if(b[i]==b[i-1]){
			ans+=s;
			s++;
		}else{
			s=1;
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 896
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  long long int m,n;
  long long int totalVotes=0;
  long long int picked=0;
  cin>>n>>m;
  vector<int> v(n);
  for(auto & x:v){
    cin>>x;
    totalVotes+=x;
  }
  sort(v.begin(),v.end(),greater<int>{});
  for(int i=1;i<=m;i++){
    if(v[i-1]*(4*m)>=totalVotes){
      picked++;
    }
    else{
      break;
    }
  }
  if(picked==m){
    cout<<"Yes"<<"\n";  
  }
  else{
    cout<<"No"<<"\n";  
  }
  
  return 0;
}

Measured memory_bytes: 256