akhauriyash/Code-Regression huggingface dataset:
__Author__ = 'Anomino'
# coding:UTF-8


def AskUser(number) : 
    player_A, player_B = [], []
    for value in range(0, number) : 
        answer = raw_input()
        answer = answer.split( )
        player_A.append(int(answer[0]))
        player_B.append(int(answer[1]))

    return player_A, player_B
    
def CalcScore(player_A, player_B) : 
    score_A, score_B = 0, 0

    for value in range(0, len(player_A)) : 
        if player_A[value] < player_B[value] : 
            score_B = score_B + player_A[value] + player_B[value]
        elif player_A[value] > player_B[value] : 
            score_A = score_A + player_A[value] + player_B[value]
        else : 
            score_A = score_A + player_A[value]
            score_B = score_B + player_B[value]

    return score_A, score_B

if __name__ == '__main__' : 
    total_A, total_B = [], []
    number = int(raw_input())

    while number != 0 :
        player_A, player_B = AskUser(number)
        score_A, score_B = CalcScore(player_A, player_B)
        total_A.append(score_A)
        total_B.append(score_B)
        number = int(raw_input())

    for value in range(0, len(total_A)) : 
        print total_A[value], total_B[value]

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

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

long long MOD = 10000000000 + 7;
// modint
const ll mod = 1e9+7;
template< int mod >
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
      return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
    
  ModInt inv() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  
  static int get_mod() { return mod; }
};
 
using mint = ModInt<mod>;

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  vector<mint> A(N);

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

  for(int i = 0; i < N; i++){
    ans -= A[i] * A[i];
  }
  mint tmp2 = 2;
  ans = ans * tmp2.inv();

  cout << ans << endl;

}


Measured memory_bytes: 3980
#include <cstdio>
#include <algorithm>
 
const int N = 110;
 
int a[N], n, m;
 
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	std::sort(a+1, a+n+1);
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (m >= a[i]) {
			m -= a[i];
			ans++;
		} else {
			break;
		}
	}
	if (m != 0 && ans == n) ans--;
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int solve(int );

int main(void){
  int N;

  while(1) {
    cin>>N;
    if(N==0) return 0;
    else solve(N);
  }
  return 0;
}

int solve(int N){
  vector<int> score(N);
  FOR(i,0,N){
    cin>>score[i];
  }
  sort( score.begin(),score.end() );

  int sum;
  FOR(i,1,N-1){
    sum += score[i];
  }
  int ans = sum/(N-2);
  cout<<ans<<endl;
  sum=0;
}



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

int n, m;
bool visited[50];
bool graph[50][50];

void dfs(int i) {
    visited[i] = 1;
    rep(j, n) {
        if (!graph[i][j] || visited[j]) continue;
        dfs(j);
    }
}

int main() {
    cin >> n >> m;
    int a[50], b[50];
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = 1;
    }

    int ans = 0;
    rep(i, m) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = 0;

        rep(j, n) visited[j] = 0;
        dfs(0);
        bool bridge = false;
        rep(j, n) if (!visited[j]) bridge = true;
        if (bridge) ans++;

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = 1;
    }

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


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

constexpr int LEN = 1005;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
char m[LEN][LEN];
ll v[LEN][LEN];

int main(){
    memset(v, 0, sizeof(v));
    int h, w; cin >> h >> w;
    queue<P> q;
    rep(i, h)rep(j, w){
        char c; cin >> c;
        m[i][j] = c;
        if(c == '#') {
            q.push({i, j});
        }
    }

    while(q.size()){
        P now = q.front(); q.pop();
        int i = now.first, j = now.second;
        rep(k, 4){
            int ni = i + di[k], nj = j + dj[k];
            if(0 <= ni && ni < h && 0 <= nj && nj < w && m[ni][nj] != '#'){
                v[ni][nj] = v[i][j] + 1;
                m[ni][nj] = '#';
                q.push({ni, nj});
            }
        }
    }

    ll ans = -1;
    rep(i, h)rep(j, w) ans = max<ll>(ans, v[i][j]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 17296
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	double n;
	cin >> n;
	double cnt = 0;
	rep(i, n) {
		if ((i + 1) % 2 == 1) {
			cnt++;
		}
	}
	printf("%.12lf\n", cnt / n);

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
A - AtCoDeerくんとペンキ / AtCoDeer and Paint Cans
https://abc046.contest.atcoder.jp/tasks/abc046_a

"""
import sys


def solve(colors):
    return len(set(colors))


def main(args):
    colors = input().split()
    ans = solve(colors)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  double A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  sort(A,A+N);
  int i = 0;
  while (i < N){
  if (A[i]==A[i+1]){
      cout << "NO" << endl;
      exit(0);
  }else{
      i=i+1;
  }
  } 
  cout << "YES" << endl;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
int n, x, d;
map<int, vector<H>>m;
int solve(int s, int t) {
	if (s > t) return 0;
	return (s + t) * (t - s + 1) / 2;
}
signed main() {
	cin >> n >> x >> d;
	if (d == 0) {
		if (x == 0) cout << 1 << endl;
		else cout << n + 1 << endl;
		return 0;
	}
	if (d < 0) {
		d *= -1, x *= -1;
	}
	for (int i = 0; i <= n; i++) {
		int off = (i * x % d + d) % d;
		if (m.find(off) == m.end()) m[off] = vector<H>();
		m[off].push_back(H{ i * x / d + solve(0, i - 1), i * x / d + solve(n - i, n - 1) });
	}//高橋君がi個とる
	//この時、i*x+j*dの値が全て取れるから、modDの値でどこからどこまで取れるかを考えればよい
	int ans = 0;
	for (auto g : m) {
		sort(all(m[g.fs]));
		int s = m[g.fs][0].fs, e = m[g.fs][0].sc;
		for (int i = 1; i < m[g.fs].size(); i++) {
			if (m[g.fs][i].fs > e) {
				ans += e - s + 1;
				s = m[g.fs][i].fs;
				e = m[g.fs][i].sc;
			}
			e = max(e, m[g.fs][i].sc);
		}
		ans += e - s + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 22144
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		IsitATriangle();
	}
	
	public static void IsitATriangle(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[]triangle = new int[3];
		
		for(int i=0;i<n;i++){
			for(int j=0;j<3;j++)triangle[j]=scan.nextInt();
			Arrays.sort(triangle);
			if(triangle[0]*triangle[0]+triangle[1]*triangle[1]==triangle[2]*triangle[2])
				System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 33124
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 1505, inf = 0x3f3f3f3f;
int n,l[N][N],r[N][N],dfn[N][N],pos[N][N];char s[N][N];
ll f[N][N],res;
int main() {
	memset(s,'#',sizeof(s));read(n);rep(i,1,n)scanf("%s",s[i]+1);
	memset(l,inf,sizeof(l));
	per(i,n,1){
		rep(j,1,n){
			if(s[i][j]!='#')l[i][j]=r[i][j]=j;else l[i][j]=inf,r[i][j]=0;
			l[i+1][j]=inf,r[i+1][j]=0;
		}
		per(j,i,1)per(k,n,1)
		if(s[j][k]=='#')l[j][k]=inf,r[j][k]=0;
		else{
			if(j<i){r[j][k]=max(r[j][k+1],r[j+1][k]);l[j][k]=min(l[j][k+1],l[j+1][k]);}
			else{umax(r[j][k],r[j][k+1]);umin(l[j][k],l[j][k+1]);}
		//	if(s[j][k]!='#'&&s[j][k+1]!='#'&&s[j+1][k]!='#'){
				if(dfn[j][k]==i+1&&r[j+1][k]<pos[j][k])f[j][k]-=f[i+1][pos[j][k]];
				if(r[j+1][k]>=l[j][k+1])dfn[j][k]=i,pos[j][k]=l[j][k+1];
		//	}
			//printf("%d %d -- %d %d\n",j,k,l[j][k],r[j][k]);
		}
		per(j,n,1)if(s[i][j]!='#'){
		//	printf("%d %d:%lld %lld\n",i,j,f[i][j],f[i+1][j]+f[i][j+1]+f[i][j]);
			f[i][j]+=f[i+1][j]+f[i][j+1];ll c=s[i][j]-'0';
			res+=c*f[i][j];f[i][j]+=c;
		}
	}
	cout<<res;return 0;
}


Measured memory_bytes: 32384
def parse():
  N, K = map(int, input().split(" "))
  A = []
  for a in input().split(" "):
    A.append(int(a) - 1)
  return N, K, A

def fast_pow(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

def fast_mod(x, N):
  # return x % N
  if N % 2 == 0:
    return x & (N - 1)
  else:
    return x % N

def main():
  N, K, A = parse()
  # print(N, K, A)

  # 移動
  town = 0
  route = [0]
  loop_start_index = None
  i = 0
  visited = [False for i in range(N)]
  visited[0] = True
  for i in range(K):
    # 次の町に移動
    town = A[town]

    if visited[town]:
      # ループ検出
      loop_start_index = route.index(town)
      break

    visited[town] = True
    route.append(town)

  if loop_start_index == None:
    print(town + 1)
  else:
    loop_route = route[loop_start_index:]
    # print(loop_route, K, i)
    print(loop_route[(K - (i + 1)) % len(loop_route)] + 1)
    # print(loop_route[])
  # print(town)
  exit(0)

  # 経路の計算
  route = []
  next_town = A[0]
  town = 0
  while not (next_town in route):  # 既出の町に行く場合
    route.append(town)
    next_town = A[town]
    town = next_town
  once_route = route[:route.index(next_town)]
  loop_route = route[route.index(next_town):]
  # print("once_route:", once_route)
  # print("loop_route:", loop_route)
  
  

  # print([town + 1 for town in route])
  # print("K %% len(loop_route):", K % len(loop_route))
  # print(route[K % len(loop_route) + len(once_route)] + 1)
  if K >= len(route) and len(once_route) > 0:
    # print("loop")
    loop_K = K - len(route)
    print(loop_route[fast_mod(loop_K, len(loop_route))] + 1)
    # print(loop_route[loop_K % len(loop_route)] + 1)
  else:
    # print("normal")
    # print(route[fast_mod(K, len(loop_route))] + 1)
    # print("K:", K)
    # print("K %% len(route):", K % len(route))
    print(route[fast_mod(K, len(route))] + 1)
    # print(route[K % len(route)] + 1)

if __name__ == "__main__":
  main()


Measured memory_bytes: 32288
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

int main() {
	optimizar_io
	string s;

	cin >> s;
	if (s == "RRR")
		cout << 3 << "\n";
	else if (s == "RRS" or s == "SRR")
		cout << 2 << "\n";
	else if (s == "RSS" or s == "SRS" or s == "SSR" or s == "RSR")
		cout << 1 << "\n";
	else 
		cout << 0 << "\n";
	return 0;
}

Measured memory_bytes: 3612
#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(){


    ll n,x,m;
    cin>>n>>x>>m;
    set<ll> s;
    ll a = x;
    s.insert(a);
    vector<ll> v;
    v.push_back(a);
    ll i=1;
    ll sum = a;

    while(true){
        if(i==n){
            cout<<sum<<endl;
            return 0;
        }


         a = ((a%m)*(a%m))%m;


         if(s.find(a)!=s.end()){break;}
         else{
           //  cout<<a<<" ";
             v.push_back(a);
             s.insert(a);
             sum+=a;
         }
         i++;
    }
//    cout<<endl;
//    cout<<a<<endl;


    n-=v.size();
    ll ans = sum;


    ll loop = 0;
    while(v[loop]!=a){
        loop++;
    }

    ll loopc = v.size()-loop;

    ll csum = 0;
    for(int i=loop;i<v.size();i++){
        csum+=v[i];
    }



    ans += (n/loopc)*csum;
    n%=loopc;

    for(int i=0;i<n;i++){
        ans+=v[loop+i];
    }

    cout<<ans<<endl;
//    cout<<sum<<endl;
//    cout<<v.size()<<endl;
//    cout<<csum<<" "<<loopc<<" "<<loop<<" "<<endl;
























return 0;
}


Measured memory_bytes: 5888
N = int(input())
A = list(map(int, input().split()))
ans =[]

for _ in range(N):
  ans.append(-1)

for i in range(N,0,-1):
  C = i*2
  BALL = A[i-1]
  while C <= N:
    BALL = BALL ^ ans[C-1]
    C += i
  ans[i-1] = BALL 

print(ans.count(1))
ans2 = []
for i in range(N):
  if ans[i] == 1:
    ans2.append(i+1)

L=[str(a) for a in ans2]
L=" ".join(L)
print(L)


Measured memory_bytes: 19892
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using std::cin;
using std::max;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
const int INF=1e+9;
const ll INFLL=1e+17;
int N;
ll L;
ll X[200010];
void solve(){
  ll res1=X[N-1],dis=X[N-1];
  int j=N-1;
  rep(i,N-1){
    if(i%2==0){
      dis+=L-2*X[j]+2*X[N-2-i];
      res1=max(res1,dis);
    }
    else{
      dis+=L-X[j]-X[j-1]+2*X[N-2-i];
      res1=max(res1,dis);
      j--;
    }
    //    prin(dis);
  }
  rep(i,N) X[i]=L-X[i];
  ll res2=X[0];
  dis=X[0];j=0;
  rep(i,N-1){
    if(i%2==0){
      dis+=L-2*X[j]+2*X[i+1];
      res2=max(res2,dis);
    }
    else{
      dis+=L-X[j]-X[j+1]+2*X[i+1];
      res2=max(res2,dis);
      j++;
    }
    //    prin(dis);
  }
  //  prin2(res1,res2);
  prin(max(res1,res2));
}
int main(){
  cin>>L>>N;
  rep(i,N) cin>>X[i];
  solve();
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

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

    ll ans=1;

    FOR(i,1,N+1){
        ans*=i;
        ans%=MOD;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;

#define NUM 11000

int main(){
	int table[NUM],limit,numTable[10001] = {0};

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;
	table[1] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int index = 0,primeTable[1230];

	for(int i = 2; i <= 9997; i++){
		if(table[i] == 1)primeTable[index++] = i;	//?´???°????¨????
	}

	int sum;
	for(int left = 0; left <= index-1; left++){ //??????????????????
		for(int div = 0; left + div <= index-1; div++){ //?????????????¶?????´???°????????°????????????
			sum = 0;
			for(int p = 0; p <= div; p++){
				sum += primeTable[left+p];
			}
			if(sum <= 10000)numTable[sum]++;
		}
	}

	int n;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		printf("%d\n",numTable[n]);
	}
	return 0;
}

Measured memory_bytes: 3280
#n = gets.chomp.to_i
@d = false
require 'set'
n, m, P = gets.chomp.split().map(&:to_i)
edges = readlines.map{|m| m.chomp.split.map(&:to_i)}

edges.map!{|a,b,c| [a,b,(c-P)*-1]}
p edges if @d

def visit_check(edge_map, start)
  q = [start]
  visited = Set.new([start])
  until q.empty?
    cur = q.shift # bfs
    next if edge_map[cur].empty?
    edge_map[cur].each do |v|
      next if visited.include?(v)
      visited.add v
      q.push v
    end
  end
  p visited if @d
  visited
end
edge_map = Array.new(n+1){Set.new}
edge_map2 = Array.new(n+1){Set.new}
edges.each do |a,b,c|
  edge_map[a].add b
  edge_map2[b].add a
end
visited = visit_check(edge_map, 1)
edges.select!{|a,b,c| visited.include?(a) && visited.include?(b)}
p ['edges', edges] if @d

visited = visit_check(edge_map2, n)
edges.select!{|a,b,c| visited.include?(a) && visited.include?(b)}
p ['edges', edges] if @d

# v_num :: Voltex数
# edges :: [[from, to, cost], [from, to, cost], ...]
# s :: start
def shortest_path(v_num, edges, s)
  d = Array.new(v_num, Float::INFINITY)
  d[s - 1] = 0
  count = 0

  while true
    update = false

    edges.each do |from, to, cost|
      dfromcost = d[from - 1] + cost
      if d[to - 1] > dfromcost
        d[to - 1] = dfromcost
        update = true
      end
    end
    break if !update

    count += 1
    if count == v_num
      puts -1
      exit
    end
  end
  d
end

paths = shortest_path(n, edges, 1)
puts [paths.last * -1, 0].max


Measured memory_bytes: 7588
#include<iostream>
using namespace std;
 
int main()
{
    // get a integer
    char a[13];
    cin >> a;
    char str[14];
    for(int i=0; i<4; ++i) {
    	str[i]=a[i];
    }
    str[4]=' ';
    for(int i=5; i<14; ++i) {
    	str[i] = a[i-1];
    }
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
//change null_type here for map/set
typedef tree<int,null_type,less<int>,rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;
typedef long long int  ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define F first
#define S second

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    x*=sgn; return ~c;
}
///START HERE
///indexed_set pbd;
//pbd.insert()
//auto x = pbd.find_by_order(2);
//int od=pbd.order_of_key(7)
///rope<int> rp;
//rp.push_back()
//RandomAccess like vector
//mutable_begin, mutable_end()

int main(){
    ///read()+printf
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //fast;
    ll n;
    cin>>n;
    ll ar[n];
    ll ans=0;
    for(ll i=0;i<n;i++){
        cin>>ar[i];
    }
    ll lst=ar[0];
    for(ll i=1;i<n;i++){
        if(ar[i]>lst){
            lst=ar[i];
        }
        else{
            ans+=lst-ar[i];
        }
    }
    cout<<ans;




    return 0;
}


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

double dp[N][N],ar[N];
int n;
double solve(int i , int k){
    if(i == n)
        return k > n/2;
    double &ret = dp[i][k];
    if(ret == ret)return ret;
    double c1 = solve(i+1,k) * (1-ar[i]);
    double c2 = solve(i+1,k+1) * ar[i];
    return ret = c1+c2;
}

int main() {

    scanf("%d",&n);
    for(int i=0; i<n; ++i) {
        scanf("%lf",&ar[i]);
    }
    memset(dp , -1,sizeof dp);
    printf("%.12f",solve(0,0));

    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll X; cin >> X;
  ll ans = 0;
  ll sum = 0;

  int i = 0;
  while(sum < X) {
    sum += i;
    i++;
  }
  cout << i - 1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define M 10000000
#define R 1579
char s[M/2];
int main(){
int i,j,k,n;
    for(i=0;i<M/2;i++)s[i]=1;
    for(i=0;i<R;i++)if(s[i])for(k=i+i+3,j=k*(i+1)+i;j<=M/2;j+=k)s[j]=0;
    while(scanf("%d",&n),n>0){for(i=(n-3)/2;!(s[i-4]&&s[i-3]&&s[i-1]&&s[i]);i--);printf("%d\n",i*2+3);}
    return 0;
}

Measured memory_bytes: 5480
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
long long int a[100000];
int main()
{
    long long int n,OK=0,i;
    cin>>n;
    long long int c=0,d=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=n-1;i>0;i--)
    {
        if(a[i]==a[i-1]&&OK==0)
        {c=a[i];OK=1;i--;continue;}
        if(a[i]==a[i-1])
        {d=a[i];break;}
    }
    if(d==0)
    printf("0\n");
    else
    printf("%lld",c*d);
}

Measured memory_bytes: 1024
void main() {
	(a => (a[0] * a[1]) & 1 ? "Odd" : "Even")(readAs!(int[])).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from functools import reduce
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def func(n, i):
        a = set(S[:i])
        b = set(S[i:])
        return max( n, len(a & b) )

    N = int(lines.pop(0))
    S = lines.pop(0)

    print( reduce( func, range(1,N), 0 ) )

#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

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

int main(){
  int a[3];
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }
  sort(a, a+3);
  if(a[2] == a[0] + a[1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#define ll long long
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define vali 1000000000000000000
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    vector<int>c1(26,0),c2(26,0);
    vector<int>cnt[26];
    for(int i=0;i<s1.size();i++)
    {
        cnt[s1[i]-97].push_back(i);
        c1[s1[i]-97]++;
    }
    for(int i=0;i<s2.size();i++)
    c2[s2[i]-97]++;
    ll f=0;
    for(int i=0;i<26;i++)
    {
        if(c2[i]!=0)
        {
            if(c1[i]==0)
            {
                f=1;
                break;
            }
        }
    }
    if(f==1)
    cout<<"-1"<<endl;
    else
    {

        ll curr=-1,turn=0;
        for(int i=0;i<s2.size();i++)
        {
            auto lw=lower_bound(cnt[s2[i]-97].begin(),cnt[s2[i]-97].end(),curr+1);
          //  cout<<"hi "<<*lw<<endl;
            if(lw==cnt[s2[i]-97].end())
            {
                turn++;
                curr=cnt[s2[i]-97][0];
            //    cout<<"hi 2"<<curr<<endl;
            }
            else
            {
                curr=*lw;
            }
        }
        cout<<turn*s1.size()+curr+1<<endl;
    }
}


Measured memory_bytes: 1216
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

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

L.sort()
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        a = L[i]
        b = L[j]
        add = a+b
        sub = abs(a-b)
        head = bisect_right(L, sub)
        tail = bisect_left(L, add)
        ex = 0
        if a > sub:
            ex += 1
        if b > sub:
            ex += 1
        ans += (tail - head - ex)

print(ans//3)


Measured memory_bytes: 49884
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    ll n,a,b;
    cin>>n>>a>>b;


    ll x=(b-1);

    ll y=n-a;

    ll ans=min(x,y);

    if((b-a)%2==0)
    {
        x=(b-a)/2;

        ans=min(ans,x);
    }


    x=((a-1)*2)+(b-a)+((n-b)*2);
    if(x%2==0)
    {
        ans=min(ans,x/2);
    }
    else
        ans=min(ans,(x+1)/2);




    x=(b-a)+((n-b)*2);
    if(x%2==0)
    {
        ans=min(ans,x/2);
    }
    else
        ans=min(ans,(x+1)/2);




    x=((a-1)*2)+(b-a);
    if(x%2==0)
    {
        ans=min(ans,x/2);
    }
    else
        ans=min(ans,(x+1)/2);






    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int c[100];
long long q[51];
int main(){
	long long n,p;cin>>n>>p;
	long long a=0,b=0;
	long long cnt=1;
	for(int i=0;i<51;i++){
		q[i]=cnt;
		cnt*=2;
	}
	for(long long i=0;i<n;i++){
		cin>>c[i];
		if(c[i]%2==0)b++;
		else a++;
	}
	if(p==0){
		if(a==0)cout<<q[n]<<endl;
		else cout<<q[n-1]<<endl;
	}
	else{
		if(a==0)cout<<"0"<<endl;
		else cout<<q[n-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int n, l, x = 1000, s;
	cin >> n >> l;
	for (int i = 0; i < n; i++) {
		if (abs(l+i)<abs(x)){
			x = l + i;
		}
	}
	s = n * l + (n * (n - 1)) / 2 - x;
	cout << endl << s << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class name
{
    static void Main()
    {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int sum = 0;
        for(int i = a[0]; i < a[1] + 1; i++)
        {
            if (i % a[2] == 0)
            {
                sum++;
            }
        }
        Console.WriteLine(sum);





    }
}

Measured memory_bytes: 28008
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{n:usize, a:[i64;n]};
    println!("{}", if a.iter().filter(|&x| *x%2!=0).count() % 2 != 0 {"NO"} else {"YES"});
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if (a + b < 2 * c) {
        int cost = a * x + b * y;

        cout << cost << endl;
    } else {
        int mm = min(x, y);
        int cost = mm * 2 * c;
        x -= mm;
        y -= mm;

        if (x == 0) {
            cost += min(y * 2 * c, y * b);
        } else {
            cost += min(x * 2 * c, x * a);
        }
        cout << cost << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int h1,h2,k1,k2;cin>>h1>>h2>>k1>>k2;
    int a,b,c,d;cin>>a>>b>>c>>d;
    int h = h1*a+h2*b+(h1/10*c)+(h2/20*d);
    int k = k1*a+k2*b+(k1/10*c)+(k2/20*d);
    if(k < h)cout << "hiroshi" << endl;
    else if(k > h) cout << "kenjiro" << endl;
    else cout << "even" << endl;
}


Measured memory_bytes: 3088
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int count(int N)
{
        int cnt = 0;
        while (N % 2 == 0)
        {
                cnt++;
                N /= 2;
        }
        return cnt;
}

int main()
{
        int A, B, C, X;
        int ans = 0;

        cin >> A >> B >> C >> X;
        rep(i, A + 1)
        {
                rep(j, B + 1)
                {

                        if (0 <= X / 50 - 10 * i - 2 * j && X / 50 - 10 * i - 2 * j <= C)
                        {
                                ans++;
                        }
                }
        }
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);
//a=atoi(S.c_str());
//S=to_string(a);
int main(){
  int N,ans=1;
  string S;
  cin>>N>>S;
  
  REP(i,N-1){
    if(S[i+1]!=S[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
def resolve():
    N = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    ans = 0
    t = N-1
    for i in range(N):
        lim = 2
        if i == 0:
            lim = 1
        for l in range(lim):
            if t > 0:
                ans += A[i]
                t -= 1
    print(ans)

if __name__ == "__main__":
    resolve()

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string s;
  cin >> s;
  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  int n = s.size();
  int c_index = -1;
  int c_cnt = 0;
  for (int i = 1; i < n; ++i) {
    if (s[i] == 'C') {
      c_index = i;
      c_cnt++;
    } else {
      if (isupper(s[i])) {
        cout << "WA" << endl;
        return 0;
      }
    }
  }
  if (c_cnt != 1) {
    cout << "WA" << endl;
    return 0;
  }
  if (2 <= c_index && c_index <= n - 2) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# ABC 159 D
# https://atcoder.jp/contests/abc159/tasks/abc159_d

n = gets.to_i
a = gets.split(/ /).map(&:to_i)

a_uniq_size = a.uniq.size

class Pattern
  def initialize(i)
    @i = i
    @count = 0
  end

  attr_reader :count

  def increment
    @count = count + 1
  end

  def calc
    @calc ||= count * (count - 1) / 2
  end
end

h = {}

a.each do |ai|
  h[ai] ||= Pattern.new(ai)
  h[ai].increment
end

base = h.values.map { |value| value.calc }.reduce(0) { |acc, i| acc + i }

h2 = {}

a.each_with_index do |ai, i|
  if h2[ai].nil?
    pattern = h[ai]
    result = base - (pattern.count - 1)
    h2[ai] = result
  else
    result = h2[ai]
  end
  puts result
end


Measured memory_bytes: 47524
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

int N,M;
int s[100005];
ll cum[100005];

int main(){
  scanf("%d%d",&N,&M);
  for(int i=0;i<N-1;i++) scanf("%d", s+i);
  cum[0] = 0;
  for(int i=1;i<N;i++) cum[i] = s[i-1] + cum[i-1];
  int cur = 0;
  ll res = 0;
  for(int m = 0;m<M;m++){
    int a;
    scanf("%d",&a);
    int tar = cur+a;
    res = (res+abs(cum[cur]-cum[tar]))%100000;
    cur = tar;
  }

  printf("%lld\n", res%100000);
}

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

struct node{long long a,b;};
bool comp(const node& e1,const node& e2){
    return e1.b > e2.b;
}
int main() {
	long long N,num,con=0;
	long long H,ans=0,amax=0;
	bool flag = true;
	cin >> N >> H;
	node x[N];
	long long i,j;
	for(i=0;i<N;i++){
	    cin >> x[i].a >> x[i].b;
	    if(amax<x[i].a){
	        amax = x[i].a;
	        num = i;
	    }
	}
	sort(x,x+N,comp);
	for(i=0;i<N;i++){
	    if(amax < x[i].b){
	            ans+=x[i].b;
	            con++;
	    }
	    if(ans>=H){
	        cout << con << endl;
	        return 0;
	    }
	}
    while(ans<H){
        ans+=amax;
        con++;
    }
    cout << con << endl;
	return 0;
}


Measured memory_bytes: 1792
/*input
hi

*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;

int main()
{
  ifalse;
  string s;
  cin >> s;
  bool flag = 0;
  for(int i = 0; i < s.length(); i ++) {
    if(i & 1 and s[i] != 'i') {
      flag = 1;
    }
    if(i % 2 == 0 and s[i] != 'h') {
      flag = 1;
    }
  }
  int n = s.length();
  if(flag or (n & 1)) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(){
  int i,wlen,tlen,cnt=0;
  char W[10]={0};
  char T[1000]={0};
  scanf("%s",W);
  wlen=strlen(W);
  for(i=0;i<wlen;i++){
    if(65<=W[i]&&W[i]<=90){
      W[i]=W[i]+32;
    }
  }
  while(1){
    scanf("%s",T);
    if(strcmp(T,"END_OF_TEXT")==0)break;
    tlen=strlen(T);
    for(i=0;i<tlen;i++){
      if(65<=T[i]&&T[i]<=90){
        T[i]=T[i]+32;
      }
    }
    if(strcmp(W,T)==0){
      cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 2692
import java.util.Scanner;

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

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

    int[][] cost = new int[3][C + 1];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        for (int k = 1; k <= C; k++) {
          cost[(i + j + 2) % 3][k] += D[c[i][j] - 1][k - 1];
        }
      }
    }

    int min = Integer.MAX_VALUE;
    for (int ia = 1; ia <= C; ia++) {
      for (int ib = 1; ib <= C; ib++) {
        if (ia == ib) continue;
        for (int ic = 1; ic <= C; ic++) {
          if (ia == ic || ib == ic) continue;
          int t = cost[0][ia] + cost[1][ib] + cost[2][ic];
          if (t < min) min = t;
        }
      }
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 92624
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;
int prime[100002]={};//100000以下の素数:9592個
int Er_N=100001;
void Er(){//Eratosthenes  1:PRIME  0:NOT PRIME
	for(int i = 2; i < Er_N; i++){
		prime[i] = 1;
	}
	int limit_Er_roop=sqrt(Er_N);
	for(int i = 2; i < limit_Er_roop; i++){
		if(prime[i]){
			for(int j = 0; i * (j + 2) < Er_N; j++){
				prime[i *(j + 2)] = 0;
			}
		}
	}
}
int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	Er();
	int n;
	cin>>n;
	int cnt[101]={},tt=0;
	FORQ(i,2,n){
		if(prime[i]){
			FORQ(j,1,n){
				int t=j;
				while(t%i==0&&t!=0){
					cnt[i]++;
					t/=i;
				}
			}
		}
	}
	int ans=0;
	FOR(i,1,6){
		ans+=(cnt[i]>73);
	}
	FORQ(i,1,n){
		if(cnt[i]<2)continue;
		FORQ(j,1,n){
			if(i==j)continue;
			if(cnt[j]<24)continue;
			ans++;
		}
	}
	cerr<<ans<<endl;
	FORQ(i,1,n){
		if(cnt[i]<4)continue;
		FORQ(j,1,n){
			if(i==j)continue;
			if(cnt[j]<14)continue;
			ans++;
		}
	}
	cerr<<ans<<endl;

	FORQ(i,1,n){
		if(cnt[i]<2)continue;
		FORQ(j,1,n){
			if(i==j)continue;
			if(cnt[j]<4)continue;
			FORQ(k,j+1,n){
				if(i==k)continue;
				if(cnt[k]<4)continue;
				ans++;
			}
		}
	}


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


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll A, B, X;
	cin >> A >> B >> X;
	if (X >= A && A + B >= X) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	

	return 0;


}

Measured memory_bytes: 256