akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair < int , int >;
using i3 = pair < int , ii >;
using vi = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 2e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

int n;

ll a[N];

void solve(){
    scanf("%d" , &n);

    for(int i = 0 ; i <= n ; i ++){
        scanf("%lld" , &a[i]);
    }

    ll ans = 0;
    for(int i = 0 ; i < n ; i ++){
        ll b;
        scanf("%lld" , &b);

        if(b >= a[i]){
            ans += a[i];
            b -= a[i];
        }
        else {
            ans += b;
            a[i] -= b;
            b = 0;
        }

        if(b >= a[i+1]){
            ans += a[i+1];
            a[i+1] = 0;
        }
        else {
            ans += b;
            a[i+1] -= b;
        }
    }

    printf("%lld\n" , ans);


}

main(){

    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
        solve();
    }

    return 0;
}




Measured memory_bytes: 1024
#coding:utf-8
#A,Bの上からi桁目のビットの組み合わせの数を求める
L = input()
lenL = len(L)
dp1 = [0] * lenL  #i桁目まででL未満になることが確定済みの組み合わせの数
dp2 = [0] * lenL  #i桁目まででA+BがLと一致している組み合わせの数、dp1[i+1]を求めるためにも利用
dp1[0] = 1 #0... となる数,最初の1桁目は(0,0)
dp2[0] = 2 #1... 

mod = 10**9 + 7
for i in range(1,len(L)):
    
    dp1[i] = (dp1[i] + 3 * dp1[i-1]) % mod  #L未満であることは確定しているので(0,0),(1,0),(0,1)の3通り
    if L[i] == '1':
        dp2[i] = (dp2[i] + 2 * dp2[i-1]) % mod  #A+BをLと一致させるために(1,0),(0,1)の2通りをとる
        dp1[i] = (dp1[i] + dp2[i-1]) % mod  #Lのi桁目が1で(0,0)を選択した場合これ以降の桁(この桁を含む)でどんな組み合わせを選んでもL以下になることが確定
    else:
        dp2[i] = (dp2[i] + dp2[i-1]) % mod  #A+BをLと一致させるために(0,0)の1通り

print((dp1[-1] + dp2[-1]) % mod)

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

using namespace std;

typedef long long int llint;

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

//#define DEBUG

#ifdef DEBUG
#define dump(i) cout << "[*] " #i ": " << i << endl
#define line cout << "[*] --------- [*]" << endl
#else
#define dump(i)
#define line
#endif

int N;
int a[100001];

inline void input() {
	cin >> N;
	rep(i, N) {
		cin >> a[i];
	}
}

inline void solve() {
	int odd_num = 0;
	int twice_num = 0;
	int qua_num = 0;

	rep(i, N) {
		if (a[i] & 1) {
			odd_num++;
		} else if (a[i] % 4 == 0) {
			qua_num++;
		} else if (a[i] % 2 == 0) {
			twice_num++;
		}
	}

	dump(odd_num);
	dump(twice_num);
	dump(qua_num);

	if (odd_num == 0) {
		if (twice_num > 1) {
			cout << "Yes" << endl;
			return;
		}
		if (qua_num > 0) {
			cout << "Yes" << endl;
			return;
		}
	} else {
		if (qua_num == odd_num - 1 && twice_num == 0) {
			cout << "Yes" << endl;
			return;
		}
		if (qua_num >= odd_num) {
			cout << "Yes" << endl;
			return;
		}
	}

	cout << "No" << endl;
}

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


Measured memory_bytes: 640
input = gets
ary = input.split(" ")
ans=Array.new
ary[0].to_i.times{|n|
if (ary[0].to_i % (n+1) == 0 )and(ary[1].to_i % (n+1) == 0 )then
 ans.push(n+1)
end
}
print ans[ans.length-ary[2].to_i]

Measured memory_bytes: 1788
mod=2019
s=input()
s=s[::-1]
tmp=0
memo=[0]*2019
memo[0]=1

for i in range(len(s)):
    tmp+=int(s[i])*pow(10,i,mod)
    tmp%=mod
    memo[tmp]+=1

ans=0
for i in memo:
    if i>=2:
        ans+=i*(i-1)//2
print(ans)

Measured memory_bytes: 9340
#include <iostream>
#include <cstdlib>
using namespace std;
struct val {
    long long int X, ans;
    int index;
};
int Xcmp(const void *p, const void *q) {
    return ((val*)p)->X - ((val*)q)->X;
}
int Icmp(const void *p, const void *q) {
    return ((val*)p)->index - ((val*)q)->index;
}
int main() {
    int N;
    val v[200000];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> v[i].X;
        v[i].index = i;
        v[i].ans = 0;
    }
    qsort(v, N, sizeof(val), Xcmp);
    int p = N / 2 + 1;
    for (int i = 0; i < p - 1; i++) v[i].ans = v[p-1].X;
    for (int i = 0; i < N - p + 1; i++) v[p+i-1].ans = v[p-2].X;
    qsort(v, N, sizeof(val), Icmp);
    for (int i = 0; i < N; i++) cout << v[i].ans << endl;
}

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

int main(){
    int n , x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    int res=0, cnt=0;
    while(x>0){
        if(cnt<=n-1){
            if(x >= a.at(cnt)){
                x = x - a.at(cnt);
                res++; cnt++;
            }else{
                break;
            }   
        }else{
            break;
        }
    }
    if(res == n && x==0)
        cout << res << endl;
    else if(res == n && x!=0)
        cout << (res-1) << endl;
    else
        cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

const int MOD = 1e9 + 7;
int D[302][302][302];
int N, M;

int dfs(int a, int b, int c){
	if(D[a][b][c] != -1)return D[a][b][c];
	int &res = D[a][b][c]; res = 0;
	if(a == 0){
		if(b == 0 && c == N)res = 1;
		else res = 0;
	}
	else{
		if(b > 0)res = (b * (ll)dfs(a-1, b-1, c)) % MOD;
		if(N-b-c > 0)res = (res + (ll)(N-b-c) * dfs(a-1, b, c)) % MOD;
		res = (res + (ll)c * dfs(a-1, b, N-b)) % MOD;
	}
	return res;
}

void solve(){
	scanf("%d%d", &N, &M);
	memset(D, -1, sizeof D);
	printf("%d", dfs(M, N-1, 1));
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 107904
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


int main(){
	
		int a,p;
		cin >> a >> p;
		cout << (3*a+p)/2 <<endl;
	return 0;
}


Measured memory_bytes: 256
// ABC 117 B

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N;
  int lmax = 0;
  int sum = 0;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int l;
    cin >> l;
    lmax = max(lmax, l);
    sum += l;
  }
  if (2 * lmax < sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import heapq
from math import ceil


def main():
    N, M = map(int, input().split())

    # As heapq.heappop returns the mininum value of the sequence,
    # we need to multiply -1 in order to attain the maximum
    # value of the sequence.
    A = list(map(lambda x: (-1) * int(x), input().split()))
    heapq.heapify(A)
    for i in range(M):
        heapq.heappush(A, ceil(heapq.heappop(A) / 2))

    print(-sum(A))


if __name__ == '__main__':
    main()

Measured memory_bytes: 14536
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[]ss = S.toCharArray();

        int cou = 0;
        for(int i=0; i<S.length(); i++) {
        	if(ss[i] != ss[S.length() -1 - i]){ 	
        		cou++;
        	}
        }
       for(int i=0; i<(S.length()-1)/2; i++) {
            if(ss[i] != ss[(S.length()-1)/2 -1 - i]){ 	
                cou++;	
            }	
        }
       for(int i=(S.length()+5)/2-1; i<S.length(); i++) {
       	if(ss[i] != ss[S.length()-1 - i]){ 	
       		cou++;
       	}
       }
       
        if(cou == 0){
            System.out.println("Yes");    
        }else{
            System.out.println("No");
    }
}
}


Measured memory_bytes: 35624
#!/usr/bin/env python3
# Submit as pypy2


from __future__ import print_function, division, unicode_literals

__metaclass__ = type

try:
    input = raw_input
    range = xrange
except NameError:
    pass


import sys


# Test code requires python3
# from hypothesis import given
# from hypothesis import strategies as st
#
#
# def debug(*args, **kwargs):
#     print(*args, *('{}={}'.format(k, v) for k, v in kwargs.items()),
#           sep='; ', file=sys.stderr)


def f(k):
    return k // 2


def rle(S):
    res = []
    last = None
    for i, c in enumerate(S):
        if c == last:
            res[-1] = (last, res[-1][1] + 1)
        else:
            res.append((c, 1))
            last = c
    return res


def solve(S, K):
    N = len(S)
    x = S[0]
    i = 0
    j = N
    while i < N and S[i] == x:
        i += 1
    if i == N:
        return f(N * K)
    while j > 0 and S[j - 1] == x:
        j -= 1
    if j == N or K == 1:
        res = rle(S)
        return K * sum(f(k) for _, k in rle(S))
    res = rle(S)
    return f(i) + f(N - j) + (K - 1) * f(i + N - j)\
        + K * sum(f(k) for _, k in res[1:-1])


def main():
    S = input()
    K = int(input())
    print(solve(S, K))


if __name__ == "__main__":
    main()


Measured memory_bytes: 28652
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public static void Solve()
    {
        int N = NextInt();
        NX mod = 998244353;
        NX[] D = LineLong();
        if (D[0] != 0) { Console.WriteLine(0); return; }
        var d = D.OrderBy(x => x).ToList();
        if (N > 1 && d[1] == 0) { Console.WriteLine(0); return; }
        int counter = 0;
        for (int i = 0; i < N; i++)
        {
            if (counter != d[i])
            {
                if (d[i] - counter == 1) { counter++; continue; }
                else { Console.WriteLine(0); return; }
            }
        }
        Dictionary<NX, NX> dic = new Dictionary<NX, NX>();
        for (int i = 0; i < N; i++)
        {
            if (!dic.ContainsKey(d[i])) dic[d[i]] = 0;
            dic[d[i]]++;
        }
        bool f = true;
        NX before = 0;
        NX ans = 1;
        foreach (var e in dic)
        {
            if (f) { f = false; before = e.Value; continue; }
            ans *= RepPow(before, e.Value, mod) % mod;
            ans %= mod;
            before = e.Value;
        }
        Console.WriteLine(ans % mod);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        return;
    }
    public static long RepPow(long x, long p, long m = 1000000007)
    {
        if (p == 1) return x % m;
        long b = RepPow(x, p / 2, m) % m;
        if (p % 2 == 0) { return (b * b) % m; }
        else { return (x * ((b * b) % m)) % m; }
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using namespace std;


int main (void) 
{

  /* Variable_Proclamation */
  string S;    // input
  char ans;  // output

  int i;    // subscript
  char char_cnt;
  int count;


  /* Input, Array_Proclamation */
  cin >> S;
  // vector<int> A(N);


  // for(i=0; i<N; i++)
  // {
  //   cin >> A.at(i);
  // }


  /* Initialize */
  ans = ' ';
  count = 0;


  /* Calculation */
  for(char_cnt = 'a';  char_cnt <= 'z';  char_cnt++)
  {

    for(i=0; i<S.size(); i++)
    {
      if( S.at(i) == char_cnt)
      {
        break;
      }
      else
      {
        count = i;
      }
    }

    if( count == S.size() -1 )
    {
      ans = char_cnt;
      break;
    }

  }
  

  /* Output */
  if(ans != ' ')
  {
    cout << ans << endl;
  }
  else
  {
    cout << "None" << endl;
  }
  


  return 0;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main(){
    ll a, c;
    double b;
    cin >> a >> b;
  	c = (double)b * 100.0 + 0.5;
    cout << (a*c)/100;
    return 0;
}

Measured memory_bytes: 3732
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S()
if len(s) % 2:
    print("No")
    exit()
for i in range(len(s) // 2):
    if s[i * 2:i * 2 + 2] != 'hi':
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 81368
import java.io.*;
        import java.math.BigInteger;
        import java.util.Arrays;
        import java.util.Scanner;
public class Main {
    public static int gcd(int a,int b){
        if(b==0)
            return a;
        int v=a%b;
        return gcd(b,v);
    }
    public static StreamTokenizer in;
    static {
        try{
            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in))));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static int nextInt() throws IOException{ in.nextToken(); return (int)in.nval; }
    public static void main(String[] args) throws IOException{
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        int a=nextInt();
        int b=nextInt();
        int c=nextInt();
        int k=nextInt();
        long all=0;
        if(k<a)
            all=k;
        else{
            all+=a;
            k-=a;
            if(k>b)
                all-=(k-b);
        }
        System.out.print(all);
    }
}


Measured memory_bytes: 35764
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    VI a(n), b(m);
    REP(i,0,n) cin >> a[i];
    REP(i,0,m) cin >> b[i];
    sort(all(a));
    sort(all(b));
    if (a[n-1] < b[0] && x < b[0] && y > a[n-1]) cout << "No War" << endl;
    else cout << "War" << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
 
int t;
 
void solve(){
	ll n, k;
	cin >> n >> k;
	if(k == 1){
		cout << 0;
		return ;
	}
	n %= k;
	if(k-1 == n) {
		cout << 1;
		return ;
	}
	cout << min(n, k-n);
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	t = 1;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
p = list(map(lambda x:int(x)-1,input().split()))
par = [i for i in range(n)]
rank = [0]*n

def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x, y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
    if rank[x] == rank[y]:
        rank[x] += 1

def same(x, y):
    return find(x) == find(y)

for i in range(m):
    x,y = map(int,input().split())
    unite(x-1,y-1)

ans = 0
for i in range(n):
    if same(i,p[i]):
        ans += 1
print(ans)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){fastio
    ll x;cin>>x;
    ll c=0;
    ll n=100;
    while(true){
        if(n>=x){
            cout<<c<<endl;
            return 0;
        }else{
            n=n*1.01;
            c++;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
int main(){
  int a, b, result;
  scanf("%d%d",&a,&b);
  result=a-b;

  if(result == 0 ){
    printf("a == b\n");
  } else if(result < 0 ){
    printf("a < b\n");
  } else if(result > 0 ){
    printf("a > b\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
const int N=410;

int a[N],res;
void search1(int l,int r)
{
	if(l>r)return ;
	while(a[l]==0)
	{
		l++;
		if(l>r)return ;
	}
	while(a[r]==0){
		r--;
		if(l>r)return ;
	}

	int mid,min1=1000;
	for(int i=l;i<=r;i++)
	{
		if(a[i]<=min1)
		{
			min1=a[i];
			mid=i;
		}
	}
	res+=a[mid];
	for(int i=l;i<=r;i++){a[i]=a[i]-min1;}


	search1(l,mid-1),search1(mid+1,r);

}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	search1(0,n-1);
	cout<<res;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,jumps=1,sum=0;
    scanf("%d %d",&n,&x);
    int l[n],i,d[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&l[i]);
        sum+=l[i];
        if(sum<=x)
            jumps++;
    }
    /*d[0]=0;
    for(i=1;i<n;i++)
    {
        d[i]=d[i-1]+l[i-1];
        sum+=l[i];
        if(sum<=x)
        {
            jumps++;
        }
    }*/
    printf("%d",jumps);
    return 0;
}


Measured memory_bytes: 256
n = int(input())

d = dict()

for i in range(n):
  s = "".join(sorted(list(input())))
  d[s] = d.get(s, 0) + 1

count = 0

for i in d.items():
  count += (i[1] * (i[1] - 1)) // 2

print(count)

Measured memory_bytes: 62168
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


ll maxNum=55560;
vector<bool> isPrime(maxNum,true);
void sieve(ll n){
    isPrime[0]=false;
    isPrime[1]=false;

    for(ll i=2;i<n;i++){
        if(!isPrime[i]) continue;
        for(int j=i*2;j<=n;j+=i)    isPrime[j]=false;
    }
}

int main(){
    sieve(55556);
    vector<ll> ans;
    for(ll i=2;i<55555;i++){
        if(isPrime[i]&&(i%5==1)) ans.push_back(i);
    }
    ll n;
    cin>>n;
    rep(i,n-1){
        cout<<ans[i]<<' ';
    }
    cout<<ans[n-1]<<endl;
    return 0;
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

int const LOG = 19;
int const MAX = (1 << LOG) + 41;

int n, m;
int a[MAX];
pii d[LOG][MAX];
int ans[MAX];

bool bit(int m, int i) {
	return (1 & (m >> i));
}

pii const EMP = mp(-1, -1);                 

bool leq(int x, int y) {
	if (x == -1) return true;
	if (y == -1) return false;
	return (a[x] < a[y]);
}

void relax(pii &x) {
	if (leq(x.first, x.second)) {
		swap(x.first, x.second);
	}
}

pii combine(pii x, pii y) {
	if (leq(x.second, y.first)) {
		swap(x.second, y.first);
		relax(x);		
		relax(y);
	}	
	if (leq(x.second, y.first)) {
		swap(x.second, y.first);
		relax(x);		
//		relax(y);
	}	
	return x;
}

pii dp[2][MAX];

int const INF = 1e9 + 41;

int getvalue(pii a) {
	if (a.first == -1 || a.second == -1) return -INF;
	if (a.first == a.second) return -INF;
	return ::a[a.first] + ::a[a.second];
}

void solve() {
	fo(0, n) {
		fi(0, m) {
			dp[0][i] = dp[1][i] = EMP;
			if (!bit(i, o)) {
				dp[0][i] = mp(i, -1);
			}
		}
		fi(0, n) {
			for (int mask = 0; mask <= m; mask++) {
				dp[1][mask] = dp[0][mask];
				if (!bit(mask, i)) continue;
				dp[1][mask] = combine(dp[0][mask], dp[0][(mask ^ (1 << i))]);
			}
			memcpy(dp[0], dp[1], sizeof(dp[0]));
		}						
		memcpy(d[o], dp[0], sizeof(d[o]));
	}	

	for (int mask = 1; mask <= m; mask++) {
		int res = getvalue(d[n][mask]);
		int mask1 = 0;
		fdi(n - 1, 0) {
			if (!bit(mask, i)) continue;
			int mask2 = mask1;
			mask2 |= (1 << i);
			mask2--;

			res = max(res, getvalue(d[i][mask2]));

			mask1 |= (1 << i);	
		}
		ans[mask] = res;	
	}

	fi(1, m) {
		printf("%d\n", ans[i]);		
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  scanf("%d", &n);
  m = (1 << n) - 1;
	fi(0, m) {
		scanf("%d", &a[i]);
	}
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 93184
N, M = map(int, input().split())
heights = list(map(int, input().split()))
 
greatest = [0] * N
for m in range(0, M):
  A, B = [int(s)-1 for s in input().split()]
  greatest[A] = max(greatest[A], heights[B])
  greatest[B] = max(greatest[B], heights[A])
    
count = 0
for i in range(0, N):
    count += heights[i] > greatest[i]
    
print(count)


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

// #define MULTI_TEST
#ifdef LOCAL
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
    out << '[' << p.first << ", " << p.second << ']';
    return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
    while (*name == ',' || *name == ' ')
        name++;
    std::cerr << name << " { ";
    for (const auto &v : arg)
        cerr << v << ' ';
    cerr << " }\n";
}
template <typename Arg1, typename... Args>
void PC(const char *names, Arg1 &&arg1, Args &&... args)
{
    while (*names == ',' || *names == ' ')
        names++;
    const char *comma = strchr(names, ',');
    std::cerr.write(names, comma - names) << " { ";
    for (const auto &v : arg1)
        cerr << v << ' ';
    cerr << " }\n";
    PC(comma, args...);
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
    std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

void solveCase(int caseNo)
{
    int n;
    cin >> n;
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = i + 1; j < n; j++)
        {
            int k = 0;
            int x = i ^ j;
            while (x)
            {
                x /= 2;
                k++;
            }
            cout << k << ' ';
        }
        cout << '\n';
    }
}

int main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    for (int i = 1; i <= t; ++i)
    {
        solveCase(i);
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	string s; cin >> s;
	bool ans = false;
	if(s[0] == '7' || s[1] == '7' || s[2] == '7'){
		ans = true;
	}
	print((ans)? "Yes" : "No")
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#define Max zhi5968
typedef long long ll;
using namespace std;

string s,t;

int find(int tt)
{
	int i;
	for(i=0;i<t.length();i++)
	{
		if(s[i+tt]!=t[i]&&s[i+tt]!='?')
			return 0;
	}
	return 1;
}

int v(int tt)
{
	for(int i=0;i<t.length();i++)
		s[i+tt]=t[i];
	return 0;
}

int main ()
{
	cin>>s;
	cin>>t;
	int i,bj=0;
	for(i=s.length()-t.length();i>=0;i--)
	{
	//	cout<<i<<endl;
		if(find(i))
			bj++;
		if(bj!=0)
		{
			v(i);
			break;
		}
	}
//	cout<<bj<<endl;
	if(bj==0)
	{
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	for(i=0;i<s.length();i++)
	{
		if(s[i]=='?')
			cout<<"a";
		else
			cout<<s[i];
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		if(N==1){
			System.out.println("Hello World");
		}else{
			int A = sc.nextInt();
			int B = sc.nextInt();
			System.out.println(A+B);
		}


   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

void chmax(ll& a, ll b) { a = max(a, b); }
void chmin(ll& a, ll b) { a = min(a, b); }

int n,m,q;
vector<int> a,b,c,d;

int dfs(vector<int> now, int next) {
    if(next != -1) now.push_back(next);
    if(now.size() == n) {
        // チェック処理
        int ret = 0;
        rep(i, q) {
            if(now[b[i]-1] - now[a[i]-1] == c[i]) {
                ret += d[i];
            }
        }
        return ret;
    } else {
        int ans = 0;
        for(int i=now.back(); i <= m; i++) {
            ans = max(ans, dfs(now, i));
        }
        return ans;
    }
}

int main() {
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    vector<int> now(1, 1);

    cout << dfs(now, -1) << endl;


    return 0;
}


Measured memory_bytes: 3648
from itertools import accumulate

def binary_search(a, left, right, base):
    l,r = left, right
    while l + 1 < r:
        mid = (l+r)//2
        # print(acc[right] - base, )
        if acc[right] - base < (acc[mid] - base) * 2:
            r = mid
        else:
            l = mid
    if abs(acc[right] - base - (acc[r] - base) * 2) < abs(acc[right] - base - (acc[l] - base) * 2):
        return r
    else:
        return l

n = int(input())
a = [0] + list(map(int, input().split()))
acc = list(accumulate(a))
ans = float('INF')
for i in range(2,n-1):
    # print(i, i+1, a[i+1])
    s = binary_search(a, 1,i, 0)
    t = binary_search(a, i+1,n, acc[i])
    o,p,q,r = acc[s], acc[i]-acc[s], acc[-1]-acc[t], acc[t] - acc[i]
    # print(s,i,t, o,p,q,r)
    if max(q,p,r,o) - min(p,q,r,o) < ans:
        ans = max(p,q,r,o) - min(p,q,r,o)
print(ans)


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

int main(){
    int n;
    cin >> n;
    vector<int> ary(n);
    map<int, ll> mp;
    rep(i, n){
        cin >> ary[i];
        mp[ary[i]]++;
    }
    ll ans = 0;
    for(auto x : mp){
        ans += x.second * (x.second-1) / 2;
    }
    rep(i, n){
        ll tmp = ans;
        ll x = mp[ary[i]];
        tmp -= x * (x-1) / 2;
        tmp += (x-1) * (x-2) / 2;
        cout << tmp << endl;
    }
    return 0;
}

Measured memory_bytes: 12032
N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
cnt = 0

A.append(0)
A.append(0)

ai = A[0]
ai2 = A[1]

for i in range(N):

  bi = B[i]
  
  if ai <= bi:
    cnt += ai
    
    if ai2 <= (bi - ai):
      cnt += ai2
      ai = max(0, ai2-(bi - ai))
      ai2 = A[i+2]
    else:
      cnt += (bi - ai)
      ai = max(0, ai2-(bi - ai))
      ai2 = A[i+2]
      
  else:
    cnt += bi
    ai = A[i+1]
    ai2 = A[i+2]
  
print(int(cnt))


Measured memory_bytes: 18624
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int H; int W;
	while(~scanf("%d%d", &H, &W)) {
		rep(i, H) rep(j, W) {
			char buf[101];
			scanf("%s", buf);
			if(strcmp(buf, "snuke") == 0)
				printf("%c%d\n", 'A' + j, i + 1);
		}
	}
	return 0;
}


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

const long N = 4;
const long N2 = 16;
const long LIMIT = 100;
const long dx[4] = {0, -1, 0, 1};
const long dy[4] = {1, 0, -1, 0};
const char dir[4] = {'r', 'u', 'l', 'd'};
long MDT[N2][N2];

struct Puzzle {long f[N2], space, MD;};

Puzzle state;
long limit;
long path[LIMIT];

long getAllMD(Puzzle pz){
	long sum = 0;
	for (long i = 0; i < N2; i++){
		if (pz.f[i] == N2) continue;
		sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}

bool isSolved(){
	for (long i = 0; i < N2; i++){
		if (state.f[i] != i + 1) return false;
	}
	return true;
}

bool dfs(long depth, long prev){
	if (state.MD == 0) return true;
	if (depth + state.MD > limit) return false;

	long sx = state.space / N;
	long sy = state.space % N;
	Puzzle tmp;

	for (long r = 0; r < 4; r++){
		long tx = sx + dx[r];
		long ty = sy + dy[r];
		if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
		if (max(prev, r) - min(prev, r) == 2) continue;
		tmp = state;

		state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
		state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
		swap(state.f[tx * N + ty], state.f[sx * N + sy]);
		state.space = tx * N + ty;
		if (dfs(depth + 1, r)){
			path[depth] = r;
			return true;
		}
		state = tmp;
	}
	return false;
}

string iterative_deepening(Puzzle in){
	in.MD = getAllMD(in);

	for (limit = in.MD; limit <= LIMIT; limit++){
		state = in;
		if (dfs(0, -100)){
			string ans = "";
			for (long i = 0; i < limit; i++) ans += dir[path[i]];
			return ans;
		}
	}
	return "unsolvable";
}

int main(){
	for (long i = 0; i < N2; i++){
		for (long j = 0; j < N2; j++){
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
			Puzzle in;
		}
	}
	Puzzle in;
	for (long i = 0; i < N2; i++){
		cin >> in.f[i];
		if (in.f[i] == 0){
			in.f[i] = N2;
			in.space = i;
		}
	}
	string ans = iterative_deepening(in);
	cout << ans.size() << endl;

	return 0;
}



Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int K = Integer.parseInt(sc.next());
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());

    long ans = 0;
    if (A + 1 < B && A < K) {
      int times = (K - (A - 1)) / 2;
      ans = A + (long)(B - A) * times + (K - (A - 1)) % 2;
    } else {
      ans = K + 1;
    }

    System.out.println(ans);
  }

}

Measured memory_bytes: 22740
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define debug(x) cout<<#x<<": "<<x<<" "
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main()
{
    IO;
    int n;
    ll d;
    cin>>n>>d;
    int res=0;
    while(n--)
    {
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d) res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=1e17+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<int>&ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<int>&ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	//可能かどうかでdp
	int n,i,j,k;cin>>n;
	vector<int>a(n);for(i=0;i<n;i++){cin>>a[i];}
	vector<int>b(n);for(i=0;i<n;i++){cin>>b[i];}
	llint dp[51][51];
	//n=1 cost dp[a][b]
	for(i=0;i<=50;i++){
		for(j=0;j<=50;j++){dp[i][j]=big;}
		dp[i][i]=0;
	}
	for(k=1;k<=50;k++){
		for(i=k;i<=50;i++){
			for(j=0;j<=i%k;j++){
				mineq(dp[i][j],dp[i%k][j]+(1LL<<k));
			}
		}
	}
	for(i=0;i<n;i++){if(dp[a[i]][b[i]]>=big){cout<<-1<<endl;return 0;}}
	vector<array<bool,51>>can(n);
	for(i=0;i<n;i++){can[i][a[i]]=true;}
	llint ans=0;
	for(int h=50;h>0;h--){
		bool use=false;
		/*for(i=0;i<n;i++){
			for(j=0;j<=50;j++){cerr<<can[i][j];}
			cerr<<endl;
		}*/
		for(i=0;i<n;i++){
			bool need=true;
			for(j=0;j<=50;j++){
				if(!can[i][j]){continue;}
				if(dp[j][b[i]]<(1LL<<h)){need=false;break;}
			}
			if(need){use=true;break;}
		}
		if(use){
			ans+=(1LL<<h);
			for(i=0;i<n;i++){
				for(j=0;j<=50;j++){
					if(!can[i][j]){continue;}
					can[i][j%h]=true;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
 int N;
 int A;

cin >> N;
cin >> A;
if (N >= 1 && N <= 10000){
	if(A >= 0 && A <= 1000){
		if ((N % 500) <= A){
			cout << "Yes" << endl;
		} else { 
      		cout << "No" << endl;
    	}
	}else{
		cout << "No" << endl;
    }
}else{
	cout << "No" << endl;
}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int x, y;

    scanf("%d %d", &x, &y);

    int ans = 0;
    for(int i = 0; i <= x; ++i){
        if((2 * i + 4 * (x - i)) == y){
            ans = 1;
            break;
        }else{
            ans = 0;
        }
    }

    if(ans) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 1656
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> v[20];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		int b,c;
		scanf("%d%d",&b,&c);
		v[i]=make_pair(-c,b);
	}std::sort(v,v+a);
	printf("%d %d\n",v[0].second,-v[0].first);
}

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

typedef long long int lli;

int main() {
    lli a, b, c, x, y, ret = 0;

    cin >> a >> b >> c >> x >> y;

    if(a + b >= 2 * c) {
        lli z = min(x, y);
        ret += 2 * c * z;
        x -= z, y -= z;
    }

    a = min(a, 2 * c);
    b = min(b, 2 * c);

    ret += a * x + b * y;

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>

using namespace std;

int main(void) {

	int N;
	string S;

	cin >> N >> S;

	int ans=0;

	for (int i = 0; i <= N - 3; i++) {
		if (S.substr(i, 3) == "ABC") {ans++; }
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,k,a[100000];

    scanf("%d %d",&n,&k);
    int i,j;
    for (i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
    }
    
    int min = 0;
    for (i = 0; i < n; i++)
    {
        if(a[min] == 1){min = i;break;}
    }
    int ans;    
    if(min > k - 1)
    {
        ans = (min + k - 2) / (k - 1);
    }
    else
    {
        ans = 1;
        min = k - 1;
    }

    ans += (n - 1 - min + k - 2) / (k - 1);

    printf("%d",ans);
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(c>=a && c<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
class Bitset
    attr_reader :int

    def initialize(int)
        @int = int
    end

    def &(other); Bitset.new(@int & other.int); end
    def |(other); Bitset.new(@int | other.int); end
    def ^(other); Bitset.new(@int ^ other.int); end
    def <<(n); Bitset.new(@int << n); end
    def >>(n); Bitset.new(@int >> n); end
    
    def length; @int.bit_length; end
    def to_s; @int.to_s(2).reverse; end
    def to_i; @int; end

    def [](n); (@int >> n) & 1; end
    def []=(n, bit)
        if bit == 1
            @int |= 1 << n
        elsif bit == 0
            @int &= (1 << n) ^ -1
        else
            raise 'invalid argument of Bitset'
        end
        self
    end
end

def partial_sum_dp(items, sum)
    n_items = items.length
    mask = Bitset.new((1 << sum) - 1)
    dp = []
    dp[0] = Bitset.new(1)
    dp[0] |= Bitset.new(1 << items[0]) if items[0] < sum
    (1...n_items).each do |i|
        dp[i] = dp[i - 1]
        dp[i] |= (dp[i - 1] << items[i]) & mask if items[i] < sum
    end
    return dp
end



N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i).sort
#N, K = 5000, 5000
#as = N.times.map{|i| rand(10**6)}

dp_normal = partial_sum_dp(as, K)
asr = as.reverse
dp_reverse = partial_sum_dp(asr, K).reverse

need_min = N.times.to_a.bsearch do |i|
    a = as[i]
    sum1_cand = i > 0 ? dp_normal[i - 1] : Bitset.new(1)
    sum2_cand = i < N - 1 ? dp_reverse[i + 1] : Bitset.new(1)
    lower = [K - a, 0].max
    upper = K - 1

    flag = false

    sum2_accum = Array.new(upper + 1, 0)
    sum2_accum[0] = 1
    (0..upper).each do |i|
        sum2_accum[i + 1] = sum2_accum[i] + (sum2_cand[i + 1] == 1 ? 1 : 0)
    end

   (0...K).each do |sum1|
        next if sum1_cand[sum1] == 0
        next if upper < sum1
        sum2_accum_lower = lower - 1 < sum1 ? 0 : sum2_accum[lower - sum1 - 1]
        sum2_accum_upper = sum2_accum[upper - sum1]
        if sum2_accum_lower != sum2_accum_upper
            flag = true
            break
        end
    end

    flag
end

puts need_min || N



Measured memory_bytes: 19960
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int ret = 0;
  if(k <= a){
    ret = k;
  }
  else {
    ret = a;
    k -= a;
    if( k <= b ){
    }
    else {
      k -= b;
      if( k <= c ) {
        ret -= k;
      }
      else {
        ret -= c;
      }
    }
  }
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <vector>
using namespace std;
 
int main(void)
{
  int N = 0, X = 0;
  cin >> N >> X;
  
  vector<int> L(N, 0);
  for(int i = 0; i < N; i++)
  {
    cin >> L[i];
  }
  
  int i = 0, pos = 0, count = 1;
  while(i < N)
  {
    pos = pos + L[i];
    if(pos <= X)
    {
      count++;
      i++;
    }
    else
    {
      break;
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#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
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}




int main() {
	ll N, X;
	cin >> N >> X;
	cout << 3 * (N - gcd(N, X)) << endl;
}

Measured memory_bytes: 256
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include <iomanip>
#include<cmath>
#include<stack>
#include <algorithm>
#include<cstdio>
#include <cstring>
#include <iostream>
#define inf 0n7fffffff
using namespace std;
int main ()
{
    int n;
    int a[110];
    int i,j;
    int sum=0;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    double m;
    m=sum*1.0/n;
    int p=m;
    int q=m+1;
    int s1=0;
    int s2=0;
    for(i=0; i<n; i++)
    {
        s1=s1+(a[i]-p)*(a[i]-p);
        s2=s2+(a[i]-q)*(a[i]-q);
    }
    printf("%d",min(s1,s2));
    return 0;
}


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

int main(){
	int i,n,c,d,e,f;
	cin >> n;
	int a[n];
	long long ans;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	f = 0;
	for(i=0;i<n;i++){
		f = max(a[i],f);
	}
	if(f==0){
		cout << 0 << endl;
		return 0;
	}
		
	for(i=0;i<n;i++){
		if(a[i]>i){
			cout << -1 << endl;
			return 0;
		}
	}
	for(i=0;i<n-1;i++){
		if(a[i+1]-a[i]>1){
			cout << -1 << endl;
			return 0;
		}
	}
	ans = 0;
	for(i=0;i<n-1;i++){
		if(a[i]<a[i+1]){
			c = a[i+1];
		}else{
			ans += c;
			c = a[i+1];
		}
	}
	ans += c;
	if(n==1){
		cout << 0 << endl;
	}else{
	cout << ans << endl;
}
}
		
		
	

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(int, char**)
{
    int n, m;

    cin >> n >> m;
    int tmp;
    for (int i = 0; i < m; i++) { cin >> tmp; n -= tmp; }

    if (n < 0) n = -1;
    cout << n << endl;

    return 0;
}

Measured memory_bytes: 3624