akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);


int main(){
  int N, Q; cin >> N >> Q;
  string S; cin >> S;

  vector <char> T(Q), D(Q);
  for (int i = 0; i < Q; i++){
    cin >> T[i] >> D[i];
  }

  bool flagL = false, flagR = false;

  int num = N - 1;
  for (int i = 0; i < Q; i++){
    if (S[num] == T[i]){
      if (D[i] == 'L') num--;
      else num++;
    }
    if (num >= N){
      flagR = true; break;
    }else if (num < 0){
      cout << 0 << endl;
      return 0;
    }
  }
  num = 0;
  for (int i = 0; i < Q; i++){
    if (S[num] == T[i]){
      if (D[i] == 'L') num--;
      else num++;
    }
    if (num < 0) {
      flagL = true; break;
    }else if (num >= N){
      cout << 0 << endl;
      return 0;
    }
  }
  
  int ansL = 0, ansR = N;

  int L = 0, R = N - 1;
  while (flagL == true){
    const int start = (L + R) / 2;
    int now = start;
    bool flag = true;
    for (int i = 0; i < Q; i++){
      if (T[i] == S[now]){
        if (D[i] == 'L') now--;
        else now++;
      }
      if (now < 0){
        flag = false; break;
      }else if (now >= N){
        break;
      }
    }

    if (flag == true) R = start;
    else L = start;

    if (start == (L + R) / 2){
      if (flagR == false){
        cout << N - R << endl;
        return 0;
      }
      ansL = R; break;
    }
  }

  L = 0, R = N - 1;
  while (flagR == true){
    const int start = (L + R) / 2;
    int now = start;
    bool flag = true;
    for (int i = 0; i < Q; i++){
      if (T[i] == S[now]){
        if (D[i] == 'L') now--;
        else now++;
      }
      if (now < 0){
        break;
      }else if (now >= N){
        flag = false; break;
      }
    }

    if (flag == true) L = start;
    else R = start;

    if (start == (L + R) / 2){
      if (flagL == false){
        cout << L + 1 << endl;
        return 0;
      }
      
      ansR = L; break;
    }
  }
  cout << ansR - ansL + 1 << endl;

  return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;


int main() {

  long long int n, k;
  cin >> n >> k;

  long double ans = 0;

  for ( long long int i = 1; i <= n; i++ ) {

    long long int cnt = 1;
    long long int p = i;
    while ( p < k ) {
      cnt *= 2;
      p *= 2;
    }

    ans += 1.00L / cnt;

  }

  ans /= n;
  cout << fixed << setprecision(15) << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
const int mod=(int)1e9+7;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); 
   	string s,w;
   	cin>>s;
   	for(int x=0;x<s.length();x+=2) w=w+s[x];
   		cout<<w;
}

Measured memory_bytes: 656
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
 
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
int main(){
    int n,m;
    int s[2005]={};
    int t[2005]={};
    scanf("%d%d",&n,&m);
    REP(i,n)scanf("%d",&s[i]);
    REP(i,m)scanf("%d",&t[i]);
    long long int dp[2005][2005]={};
    REP(i,2005){
        dp[0][i]=1;
        dp[i][0]=1;
    }
    for(int y=1;y<=m;y++){
        for(int x=1;x<=n;x++){
            dp[y][x]=dp[y][x-1]+dp[y-1][x]-dp[y-1][x-1]+1000000007;
            if(s[x-1]==t[y-1]){
                dp[y][x]+=dp[y-1][x-1];
            }
            dp[y][x]%=1000000007;
        }
    }
    printf("%lld\n",dp[m][n]);
    return 0;
}

Measured memory_bytes: 31616
n = int(input())
apple = list(map(int, input().split()))
if 0 in apple:
    print(0)
else:
    cat = 1
    for i in apple:
        cat *= i
        if cat > 10**18:
            break
        else:
            pass
    print(cat if cat <= 10**18 else -1)
    

Measured memory_bytes: 87816
s = int(input())

cnt = 1
li = [s]

while True:
    cnt += 1
    if s%2 == 0:
        s /= 2
        if s in li:
            print(cnt)
            break
    else:
        s = s*3 + 1
        if s in li:
            print(cnt)
            break
    li.append(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,c;
cin>>a>>b>>c;
if((a+b)>=c)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
while 1:
    try:
        l=map(str,raw_input().split())
        s=[]
        for i in l:
            if i=='+':
                s.append(s.pop(-2)+s.pop(-1))
            elif i=='-':
                s.append(s.pop(-2)-s.pop(-1))
            elif i=='*':
                s.append(s.pop(-2)*s.pop(-1))
            elif i=='/':
                s.append(s.pop(-2)/s.pop(-1))
            else:
                s.append(float(i))
        print s[0]
    except:
        break
exit()

Measured memory_bytes: 6396
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(s: str):
    from collections import Counter
    c = Counter(s)

    N = len(s)
    ans = INF


    for k in c.keys():
        c = 0
        sc = s
        for j in range(N):
            ls = []
            for i in range(len(sc)-1):
                if sc[i] == k or sc[i+1] == k:
                    ls.append(k)
                else:
                    ls.append(sc[i])
            c += 1
            
            if all([j == k for j in sc]):
                break

            sc = ''.join(ls)
        ans = min(ans, c-1)

    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>

#define OK 0;
using namespace std;


int main(void) {
    unsigned int a;
    unsigned int b;

    //scanf
    cin >> a >> b;

//    printf(即qqqq = %d即, a * b);
    //printf
    cout << a * b << " " << 2 * (a + b) << endl;
//    cout << 2 * (a + b) << endl;

    return OK;
}

Measured memory_bytes: 1156
from collections import Counter
n = int(input())
inp =  list(input())
d = dict(Counter(inp))

for _ in range(n-1):
  inp =  list(input())
  dic = dict(Counter(inp))
  for st,cnt in dic.items():
    try:
      if d[st] > cnt:
        d[st] = cnt
    except KeyError:
      continue
     
  remove = []
  for k in d.keys():
    if not k in dic:
      remove.append(k)
      
  for r in remove:
    d.pop(r)
      
sort_d = sorted(d.items(),key=lambda x : x[0])
#print(sort_d)

ans = ""
for so in sort_d:
  ans += so[0]*so[1]
print(ans)



Measured memory_bytes: 3316
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if(H==0&&W==0) break;
			
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if((i+j)%2==0){
						System.out.print("#");
					}else{
						System.out.print(".");
					}
					
				}
				
				System.out.println("");
			}
			System.out.println("");
		}
	}

}



Measured memory_bytes: 34272
//�򵹻ƺ�˴��������!!// 
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int>v[100003];
int dp[100003];
int dfs(int x){
	if(dp[x])return dp[x];
	for(int i=0;i<v[x].size();i++)dp[x]=max(dfs(v[x][i])+1,dp[x]);
	return dp[x];
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		v[a].push_back(b);
	}
	int ans=0;
	for(int i=0;i<n;i++)ans=max(ans,dfs(i));
	cout<<ans;
}
//�򵹻ƺ�˴��������!!//


Measured memory_bytes: 8192
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

COIN = [25,10,5,1]

N = int(input())

ans = 0

for i in range(len(COIN)):
    ans += N//COIN[i]
    N %= COIN[i]

print("%d"%(ans))


Measured memory_bytes: 6360
h, w = map(int, input().split())
board = []

for _ in range(h):
    board.append(input())

dx = [0, 0, 1, 1, 1, -1, -1, -1]
dy = [1, -1, -1, 0, 1, -1, 0, 1]

for i in range(h):
    for j in range(w):
        if board[i][j] == "#":
            continue
        cnt = 0

        for d in range(8):
            ni = i + dy[d]
            nj = j + dx[d]

            if (ni < 0 or ni >= h) or (nj < 0 or nj >= w):
                continue
            if board[ni][nj] == "#":
                cnt += 1

        temp_board = list(board[i])
        temp_board[j] = str(cnt)
        board[i] = "".join(temp_board)

for i in range(h):
    print(board[i])

Measured memory_bytes: 73776
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#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>
#include <initializer_list>
#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;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  int cnt1=0,cnt2=0;

  string S;
  cin>>S;

  
  FOR(i,0,S.length() ){
    if(i%2==0){
      if(S[i]=='0'){
        cnt1++;
        // cerr<<"S[i]: "<<S[i]<<"   i:"<<i<<"  cnt1:"<<cnt1<<endl;
      }else{
        // cerr<<"S[i]: "<<S[i]<<"   i:"<<i<<"  cnt1:"<<cnt1<<endl;
      }
    }else{
      if(S[i]=='1'){
        cnt1++;
        // cerr<<"S[i]: "<<S[i]<<"   i:"<<i<<"  cnt1:"<<cnt1<<endl;
      }else{
        // cerr<<"S[i]: "<<S[i]<<"   i:"<<i<<"  cnt1:"<<cnt1<<endl;
      }
    }
  }
  // cerr<<"cnt1: "<<cnt1<<endl;
  
  FOR(i,0,S.length() ){
    if(i%2==1){
      if(S[i]=='0'){
        cnt2++;
      }
    }else{
      if(S[i]=='1'){
        cnt2++;
      }
    }
  }
  // cerr<<"cnt2: "<<cnt2<<endl;
  cout<<min(cnt1,cnt2)<<endl;
  return 0;
}



Measured memory_bytes: 512
n = int(input())
c = list(input())
ans = 0
cntW, cntR = 0, 0
flg = True
for i in range(n-1, -1, -1):
    if c[i] == 'W':
        cntW += 1
    else:
        cntR += 1
    if flg:
        if c[i] == 'R':
            flg = False
    else:
        if c[i] == 'W':
            ans += 1
ans = min(ans, cntW, cntR)
cnt = 0
for i in range(n-1, -1+cntR, -1):
    if c[i] == 'R':
        cnt += 1
ans = min(ans, cnt)
print(ans)

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
      
  long long num,fin=0;
  string str;
  char a=str[0];
  cin >> num >> str;
  for (int i=0; i<num; i++) {
      char b=str[i];
      if (a!=b){
          fin++;}
      a=b;}
    cout << fin;}

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

using namespace std;

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

	vector<int> d(n);
	for(int i = 0; i < n; i++)
		cin >> d[i];

	int counter = 0;

	for(int i = 0; i < n; i++)
	{
		if(d[i] == d[i+1])
		{
			counter++;
			i++;
		}
	}
	cout << counter << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#define LEN 100
#define BASE 25

using namespace std;

int maps[LEN][LEN];
int off[LEN][LEN];

int checker[4];
int ncheck[4];

map<int, int> points[LEN];

class State {
public:
	char where;
	int enemy;
	int budget;
	int check[4];
	State() {}
	State(char w, int e, int b ) {
		where = w;
		enemy = e;
		budget = b; 
		check[0] = ncheck[0];
		check[1] = ncheck[1];
		check[2] = ncheck[2];
		check[3] = ncheck[3];
	}
};


inline bool operator< ( const State& a, const State& b) {
/*
	if( a.enemy == b.enemy )
		return a.budget > b.budget;
		*/
	return a.enemy < b.enemy;
}

inline bool operator> ( const State& a, const State& b) {
/*
	if ( a.enemy == b.enemy )
		return a.budget < b.budget;
		*/
	return a.enemy > b.enemy;
}

priority_queue<State, vector<State>, greater<State> > status;

inline void copy ( State now ) {
	checker[0] = now.check[0];
	checker[1] = now.check[1];
	checker[2] = now.check[2];
	checker[3] = now.check[3];
}

inline void ncopy ( ) {
	ncheck[0] = checker[0];
	ncheck[1] = checker[1];
	ncheck[2] = checker[2];
	ncheck[3] = checker[3];
}

inline bool check ( int i ) {
	return 0 == ((1<<(i%25)) & checker[i/BASE]);
}

inline void add ( int i ) {
	ncheck[i/BASE] = ((1<<(i%25)) | checker[i/BASE]);
}

inline void insert ( int i, int e, int b ) {
	
	map<int,int>::iterator itr = points[i].find(e);
	if ( itr == points[i].end() ) {
		points[i][e] = b;
		status.push(State(i,e,b));
	} else if ( (*itr).second < b ) {
		(*itr).second = b;
		status.push(State(i,e,b));
		int min = b;
		while ( itr != points[i].end() ) {
			if ( (*itr).second > min ) {
				min = (*itr).second;
			} else {
				(*itr).second = min;
			}
			itr++;
		}
	}
}

int main () {

	while ( true ) {
		int n,m,l;
		cin >> n >> m >> l;

		if ( n == 0 )
			break;

		for ( int i=0; i<n; i++ ) {
			for ( int j=0; j<n; j++ ) {
				maps[i][j] = -1;
				off[i][j] = 0;
			}
			points[i].clear();
		}

		for ( int i=0; i<m; i++ ) {
			int a,b,d,e;
			cin >> a >> b >> d >> e;

			maps[a-1][b-1] = maps[b-1][a-1] = d;
			off[a-1][b-1] = off[b-1][a-1] = e;
		}
		
		for ( int i=0; i<4; i++ ) {
			ncheck[i] = 0;
			checker[i] = 0;
		}

		priority_queue<State, vector<State>, greater<State> > empty;
		status = empty;

		ncheck[0] = 1;
		status.push(State(0,0,l));
		
		while(!status.empty()) {
			State now = status.top();
			status.pop();
			if ( now.where == n-1 ) {
				cout << now.enemy << endl;
				break;
			}

			copy(now);

			for ( int i=0; i<n; i++ ) {
				if ( maps[now.where][i] > 0 ) {

					if ( check( i ) ) {
						ncopy();
						add(i);
						
						int e, b;
						if ( off[now.where][i] == 0 ) {
							e = now.enemy;
							b = now.budget;
							insert(i,e,b);
						} else {
							if ( now.budget - maps[now.where][i] >= 0 ) {
								e = now.enemy;
								b = now.budget - maps[now.where][i];
								insert(i,e,b);
							}
							e = now.enemy + off[now.where][i];
							b = now.budget;
							insert(i,e,b);
						}
					}
				}
			}
		}
	}
}

		

Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
struct edge
{
	int x;
	int l;
}e[N];
bool cmp(edge a,edge b)
{
	return a.x + a.l < b.x + b.l;
}
int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
		scanf("%d%d",&e[i].x,&e[i].l);
	sort(e + 1,e + n + 1,cmp);
	int tp = 0,maxlen;
	tp ++;
	maxlen = e[1].x + e[1].l;
	for(int i = 2;i <= n;i++)
	{
		if(e[i].x - e[i].l >= maxlen)tp++,maxlen = e[i].x + e[i].l;
	}
	printf("%d",tp);
	return 0;
}

Measured memory_bytes: 1024
//Code by 27.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const int MOD=1000000007;
const long long LMOD=1000000007;
long long h[1000005];
long long n;
long long k;
long long f[1000005];
long long mx;
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		mx=BIGEST;
		scanf("%lld",&h[i]);
		for(int j=max(1ll,i-k);j<=i-1;j++)if(f[j]+abs(h[i]-h[j])<mx)mx=f[j]+abs(h[i]-h[j]);
		if(i==1)f[i]=0;
		else f[i]=mx;
		//while(f[q.front()]>f[i])q.pop_front();
		//while(q.back()-i>k)q.pop_back();
		//q.push_front(i); 
		//cout<<f[i]<<endl;
	}
	cout<<f[n];
	return 0;
}

Measured memory_bytes: 5120
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Trim();

        var r = s.Count(x => x == 'R');
        Console.WriteLine(r > n - r ? "Yes" : "No");
    }
}


Measured memory_bytes: 11220
from collections import Counter
N=int(input())
fac=[]
for n in range(2, N+1):
	for x in range(2, int(n**0.5)+2):
		while n % x == 0:
			fac.append(x)
			n //= x
	if n > 1:
		fac.append(n)
c=Counter(fac)
cn=[len(list(filter(lambda x: x >= i, c.values()))) for i in range(75)]
print(cn[74] + cn[24] * (cn[2] - 1) + cn[14] * (cn[4] - 1) + cn[4] * (cn[4] - 1) * (cn[2] - 2) // 2)


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

void swap(int x[],int l,int r){
	int t;
	t=x[l];
	x[l]=x[r];
	x[r]=t;
}

void qsort(int x[],int l,int r){
	int i,j,p;
	i=l;
	j=r;
	p=x[(i+j)/2];
	while(1){
		while(x[i]<p)i++;
		while(x[j]>p)j--;
		if(i>=j)break;
		swap(x,i,j);
		i++;
		j--;
	}
	if(i-l>0)qsort(x,l,i-1);
	if(r-j>0)qsort(x,j+1,r);
}

int main(){
	int h[5];
	int same,s,p,p1,p2;
	int i,j,k;
	char c[7][12]={"four card","full house","straight","three card","two pair","one pair","null"};
	int yaku[7];
	int b;
	char str[12];
	while(scanf("%d,%d,%d,%d,%d",&h[0],&h[1],&h[2],&h[3],&h[4])!=EOF){
		qsort(h,0,4);
		// for(i=0; i<5; i++){
		// 	printf("%2d ",h[i]);
		// }
		// printf("\n");
		for(i=0; i<7; i++){
			yaku[i]=0;
		}
		same=0;
		s=0;
		p=0;
		p1=0;
		p2=0;
		for(i=0; i<5; i++){
			s=0;
			for(j=i; j<5; j++){
				if(h[i]==h[j]){
					s++;
					if(p==0&&i!=j){
						p1=h[i];
						p++;
					}
					else if(p==1&&i!=j){
						if(h[i]!=p1){
							p2=i;
							p++;
						}
					}
				}
			}
			if(s>same)same=s;
		}
		if(same==4)yaku[0]=1;
		if(same==3){
			if(p==2)yaku[1]=1;
			yaku[3]=1;
		}
		if(same==2)yaku[5]=1;
		if(p==2)yaku[4]=1;
		for(i=0; i<5; i++){
			if(h[i]!=h[0]+i)break;
			if(i==4)yaku[2]=1;
		}
		if(h[0]==1&&h[1]==10&&h[2]==11&&h[3]==12&&h[4]==13){
			yaku[2]=1;
		}
		//("same:%d p:%d\n", same,p);
		yaku[6]=1;
		b=1;
		for(i=0; i<7; i++){
			if(yaku[i]){
				b=0;
				printf("%s\n", c[i]);
			}
			if(!b)break;
		}

	}

	return 0;
}

Measured memory_bytes: 580
N=int(input())
an=list(map(int,input().split()))
s=sum(an)
b = an[0]

l=[]
a = abs(s-2*b)
for i in range(1,N-1):
    b = b + an[i]
    a=min(a,abs(s-2*b))
print(a)

Measured memory_bytes: 24832
let () =
  let rec read () =
    let n = read_int () in
    if n != 0 then
      let rec loop max sum = function
          0 -> if sum > max then sum else max
        | i -> let m = read_int() in
               if sum < 0 && m > sum then
                 loop max m (i-1)
               else if m < 0 && sum > max then
                 loop sum (sum+m) (i-1)
               else
                 loop max (sum+m) (i-1)
      in Printf.printf "%d\n" (loop (-100000) (read_int ()) (n-1));read ()
  in read ();;

Measured memory_bytes: 2524
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

vector<int> graph[100];
int dist[100]={0};
int main(){
  int n;
  cin >> n;

  for(int i=0;i<n;++i){
    int u,k;
    cin >> u >> k;
    for(int i=0;i<k;++i){
      int v;
      cin >> v;
      graph[u-1].push_back(v-1);
    }
    dist[i] = -1;
  }

  queue<int> q;
  q.push(0);
  dist[0] = 0;
  while(!q.empty()){
    auto v = q.front();q.pop();
    for(auto next_v:graph[v]){
      if(dist[next_v]==-1){
        dist[next_v] = dist[v]+1;
        q.push(next_v);
      }
    }
  }
  for(int i=0;i<n;++i){
    cout << i+1 << " " << dist[i] << endl;
  }
}

Measured memory_bytes: 3112
n, m = map(int, input().split())
AB = [[] for _ in range(n)]
for i in range(m):
    a, b = map(lambda x:int(x)-1, input().split())
    AB[a].append(b)
    AB[b].append(a)
for i in range(n):
    print(len(AB[i]))


Measured memory_bytes: 9084
import time
N = int(input())
A = list(map(int, input().split()))

left = 0
right = left + 1
money = 1000

while left < N - 1:

    if A[left] >= A[left+1]:
        left += 1
        right = left
        continue

    if right <= N-2:
        if A[right] <= A[right+1]:
            right += 1
            continue

    money += (money//A[left]) * (A[right]-A[left])
    left = right

print(money)


Measured memory_bytes: 9056
import java.util.*

fun main() {
    val reader = System.`in`.bufferedReader()
    var tokenizer: StringTokenizer = StringTokenizer("")

    fun next(): String {
        while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
        return tokenizer.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextDouble() = next().toDouble()
    fun nextLine() = reader.readLine()

    fun solve() {
        var n = nextInt()
        var k = nextInt()

        var arr = nextLine().split(" ").map { it.toInt() }.sorted()


        var sum = 0
        for (i in 0..k-1)sum+=arr[i]

        println(sum)



    }

    solve()


}




Measured memory_bytes: 39512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1e9+7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, 62) {
    ll cnt[2] = {};
    rep(j, n) cnt[a[j]>>i & 1]++;
    ll num = cnt[0]*cnt[1]%MOD;
    (ans += (1LL<<i)%MOD*num%MOD) %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <iostream> 
#include <string> 
#define lli long long int
#define deb1(x) cout<<#x<<" :: "<<x<<"\n";
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define deb(v) for(lli i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }
#define all(a) a.begin(),a.end()
#define ll long long
using namespace std;
#define f first
#define sd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(x) (ll)x.size()
#define vl vector<lli>
#define pii pair<lli,lli>
lli mod=1e9+7;
using namespace std;
lli t,n,u,x,y,k;
const lli N = 100001;
int main(){
    fast
     t=1;
//    cin>>t;
    while(t--){
        cin>>n;
        lli ans=0;
        for(int i=1;i<=n;++i){
            x=n/i;
            if(n%i==0)--x;
            ans+=x;
//            deb2(x,i)
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3656
#include<iostream>

using namespace std;

int main()
{
  string s;
  cin >> s;
  
  int n = s.length();
  
  long long sum = 0;
  
  for(int i=0;i<n;i++) sum += s[i] - '0';
  
  string ans = sum % 9 == 0 ? "Yes":"No";
  cout << ans << endl;
  return 0;
}

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

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

    int count = 1; 

    for (int i = 1; i < n; ++i) 
    {
        if (s[i] != s[i-1]){
            count++; 
        }
    }
    cout << count << endl; 
    return 0; 
}

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

int main(){
    int n, m; cin >> n >> m;
    int A[n][m], B[m];

    int c;

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> c;
            A[i][j] = c;
        }
    }

    for(int i=0; i<m; i++){
        cin >> c;
        B[i] = c;
    }

    int ans=0;

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            ans += A[i][j] * B[j];
        }
        cout << ans << endl;
        ans=0;
    }

    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

vector<pair<string,pair<ll,pair<ll,ll>>>> Ans;

void add(ll i,ll j,ll k){
    Ans.push_back({"+",{i,{j,k}}});
}

void leq(ll i,ll j,ll k){
    Ans.push_back({"<",{i,{j,k}}});
}

void output(void){
    cout << Ans.size() << endl;
    REP(i,Ans.size()){
        cout << Ans[i].first << " " << Ans[i].second.first << " ";
        cout << Ans[i].second.second.first << " " ;
        cout << Ans[i].second.second.second << endl;
    }
}

int main(void){
    
    //a[0]=A
    //a[1]=B
    //a[3]=A+B
    //a[4]=1
    //a[5]=0
    add(0,1,3);
    leq(2,3,4);
    
    //2^iを用意していく
    
    //a[6]=1,a[7]=2,...,a[65]=2^60
    add(4,5,6);
    REP(i,60-1){
        add(6+i,6+i,7+i);
    }
    
    //AとBを各bitに分解していく
    
    //a[66]=A+1 a[67]=B+1
    //68~70 なんかいい感じのやつ
    add(0,4,66);
    add(1,4,67);
    
    //71~100 Aをbit分解
    //a[71]=Aの最下位ビット a[72]=Aの2番目bit a[100]=Aの30番目bit
    //101~130 Aをbit分解
    //a[101]=Bの最下位ビット a[102]=Bの2番目bit a[130]=Bの30番目bit
    for(ll i=29;i>=0;i--){
        add(68,6+i,69);
        leq(69,66,71+i);
        add(5,71+i,70);
        REP(j,i){add(70,70,70);}
        add(68,70,68);
    }
    
    add(5,5,68);
    
    for(ll i=29;i>=0;i--){
        add(68,6+i,69);
        leq(69,67,101+i);
        add(5,101+i,70);
        REP(j,i){add(70,70,70);}
        add(68,70,68);
    }
    
    //131~150 空
    
    
    
    //bitどうしの掛け算はわりと簡潔に表現できていく
    //そしてそれを足し合わせれば結果になっていく
    
    //151~1050 各bitの掛け算の結果(30桁*30桁=900個)
    //そしてそれを2^(i+j)倍したもの
    
    //a[2]=A*B
    
    REP(i,30){
        REP(j,30){
            add(71+i,101+j,151+i*30+j);
            leq(4,151+i*30+j,151+i*30+j);
            REP(k,i+j){
                add(151+i*30+j,151+i*30+j,151+i*30+j);
            }
            add(151+i*30+j,2,2);
        }
    }
    
    //オワオワリ
    output();
    return 0;
}



Measured memory_bytes: 5108
N = int(input())
first_line = input().split()
second_line = input().split()

bef_sum = 0
sum = 0

for i in range(N):
  for j in range(N):
    if j < i:
      sum += int(first_line[j])
    elif j == i:
      sum += int(first_line[j])
      sum += int(second_line[i])
    else:
      sum += int(second_line[j])
  if bef_sum < sum:
    bef_sum = sum
  sum = 0

print(bef_sum)
  

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
int n,m;
  scanf("%d%d",&n,&m);
  int l[m],r[m];
  int min=100001,max=0;
  for(int i=0;i<m;i++){
		scanf("%d%d",&l[i],&r[i]);
    if(l[i]>max)max=l[i];
    if(r[i]<min)min=r[i];
  }
  //printf("%d %d\n",max,min);
 if(min<max)printf("0");
  else printf("%d",min-max+1);
  
  return 0;
}

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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=2e5+5;
int L,n;s64 ans,x[N];
s64 s[N];

void solve()
{
	rep(i,2,n)s[i]=s[i-1]+s64(x[i]-x[i-1])*i;
	rep(i,1,n)
	{
		s64 sum=x[i];
		sum+=s64(x[i]+L-x[n])*(n-i);
		if((n-i)%2==0)
		{
			int m=(n+i)/2;
			if(i+1<=m)sum+=s64(2*m+1)*(x[m]-x[i])-2*(s[m]-s[i]);
			if(m+2<=n)sum+=2*(s[n]-s[m+1])-2LL*(m+1)*(x[n]-x[m+1]);
		}
		else
		{
			int m=(n+i)/2;
			if(i+1<=m)sum+=-2*(s[m]-s[i])+2LL*(m+1)*(x[m]-x[i]);
			if(m+2<=n)sum+=2*(s[n]-s[m+1])-(2LL*(m+1)+1)*(x[n]-x[m+1]);
		}
		chmax(ans,sum);
	}
}

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	cin>>L>>n;
	rep(i,1,n)x[i]=read();
	solve();
	rep(i,1,n)x[i]=L-x[i];
	reverse(x+1,x+n+1);
	solve();
	cout<<ans;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
#define ford(i,a,b) for(int i=(a);i>=(b);--i)
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define swap(x,y) ((x)^=(y),(y)^=(x),(x)^=(y))
const int maxn=1e5;
typedef long long ll;
const int inf=1<<25;

inline char getch(){
    static char buf[inf],*p1=buf,*p2=buf;
    return p1==p2 && (p2=(p1=buf)+fread(buf,1,inf,stdin),p1==p2) ? EOF : *p1++;
}
int read(){
    int s=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1; c=getchar();}
    while(c>='0' && c<='9') {s=s*10+c-48;c=getchar();}
    return s*f;
}
void write(int x){
    if(x<0) {putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+48);
}

int a[maxn+7];
int n;
struct node
{
    int id,w;
}cnt[maxn+7],cnt2[maxn+7];
int cmp(node a,node b){
    return a.w>b.w;
}
int ans,tot,tot2;
int main(int argc, char const *argv[])
{
    n=read();
    fors(i,1,n) a[i]=read();
    for(int i=1;i<=n;i+=2)
        cnt[a[i]].w+=1,cnt[a[i]].id=a[i],tot+=1;

    for(int i=2;i<=n;i+=2)
        cnt2[a[i]].w+=1,cnt2[a[i]].id=a[i],tot2+=1;

    sort(cnt2+1,cnt2+maxn,cmp);
    sort(cnt+1,cnt+maxn,cmp);

    int ans=0;
    if(cnt[1].id == cnt2[1].id){
        ans+=((tot-cnt[2].w) < (tot2-cnt2[2].w) ? (tot-cnt[2].w+tot2-cnt2[1].w) : (tot2-cnt2[2].w+tot-cnt[1].w));
    }
    else ans+=n-cnt[1].w-cnt2[1].w;
    write(ans),putchar(10);
    
    return 0;
}

Measured memory_bytes: 2176
# -*= coding: utf-8 -*-
from collections import deque

S = input()
Q = int(input())
query = list()
for i in range(Q):
  query.append(list(map(str, input().split())))


d = deque()
for s in S:
  d.append(s) # 右からsを追加
is_reverse = False

for q in query:
  if len(q) == 1:
    # Tiが1の場合
    
    is_reverse = not is_reverse
    
  else:
    # Tiが2の場合
    
    if q[1] == '1':
      # Fiが1の場合
      
      if is_reverse == False:
        d.appendleft(q[2])
      else:
        d.append(q[2])
      
    else:
      # Fiが2の場合
      
      if is_reverse == False:
        d.append(q[2])
      else:
        d.appendleft(q[2])

ans = ''
if is_reverse == True:
  d.reverse()
ans = ''.join(d)
print(ans)

Measured memory_bytes: 140428
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a;
  long long ans=0;
  vector<int>v(a);
  for(int i=0;i<a;i++)
    cin>>v[i];
  for(int i=0;i<a;i++)
  {
    for(int j=i+1;j<a;j++)
    {
       ans+=(v[i]*v[j]);
    }
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    ll sum=0;
    rp(i,n){
        int a;
        cin >> a;
        sum+=a;
    }
    sum-=n;
    print(sum);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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


bool is375(int n){
  string str = to_string(n);
  int n1= str.find("1");
  int n2 = str.find("2");
  int n3 = str.find("3");
  int n4 = str.find("4");
  int n5 = str.find("5");
  int n6 = str.find("6");
  int n7 = str.find("7");
  int n8 = str.find("8");
  int n9 = str.find("9");
  int n0 = str.find("0");
  if(n3 != -1&& n5 != -1 && n7 != -1){
    if (n1 == -1 && n2 == -1 && n4 == -1 && n6 == -1 && n8 == -1 && n9 == -1 && n0 == -1 ){
      return true;
    }
  }
  return false;
}

ll dfs(ll n, ll i = 0, bool jud3 =false, bool jud5=false, bool jud7=false){
  if(n<i) return 0;
  ll ret = 0;
  if(jud3&&jud5&&jud7){
    //cout << i << endl;
    ret++;
  }
  ret+=dfs(n, i*10+3, true, jud5, jud7);
  ret+=dfs(n, i*10+5, jud3, true, jud7);
  ret+=dfs(n, i*10+7, jud3, jud5, true);
  return ret;
}

int n;
int main()
{
  // int cnt = 0;
  cin >> n;
  // dfs(n);
  cout << dfs(n) << endl;
  //cout << cnt << endl;
}


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

int main() {
    int N; cin >> N;
    int x = N / 1.08;
    if (int(x * 1.08) == N) {
        cout << x << endl;
        return 0;
    }
    while (x * 1.08 <= N) {
        x++;
        if (int(x * 1.08) == N) {
            cout << x << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
n,s=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*6007
ans=0
for i in range(n):
  for j in range(s,0,-1):dp[a[i]+j]+=dp[j]
  dp[a[i]]+=i+1
  ans+=dp[s]
print(ans%998244353)

Measured memory_bytes: 66652
s = set(input())
ls = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
k = 0

for i in range(26):
    alp = ls[i]
    if alp not in s:
        k = 1
        break

if k == 1:
    print(alp)
else:
    print("None")

Measured memory_bytes: 9088
n = int(input())
a = [int(input()) if(i) else 0 for i in range(n+1)]
distance = [None] * (n+1)
queue = [(1, 0)]
while(len(queue)):
    p, d = queue.pop()
    if(p==2):
        print(d)
        break
    if(distance[p]!=None or d==100001):
        print(-1)
        break
    distance[p] == d
    nextp = a[p]
    queue.append((nextp, d+1))


Measured memory_bytes: 7852
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  long long N, A, B;
  cin >> N >> A >> B;
  long long ans = (B * (N - 1) + A) - (A * (N - 1) + B);
  if (ans < 0)
    cout << 0 << endl;
  else
    cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 200006
#define ll long long int
using namespace std;
int arr[M],n,last=1,circle=0;
ll m;
struct node{   //s是传到哪，t记录访问的次数
	int s,t;
}p[M];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;++i)  
	{
		cin>>arr[i];
	}
	p[1].s=1;
	p[1].t=0;
	for(int i=1;i<=n;++i)
	{
		p[arr[last]].s+=1;
		if(i==m){cout<<arr[last];return 0;}
		if(p[arr[last]].s==2){
			circle=i-p[arr[last]].t;
			m-=p[arr[last]].t;
			break;
		}
		p[arr[last]].t=i;
		last=arr[last];
	}
	m%=circle;
	if(m==0){cout<<arr[last];return 0;}
	last=arr[last];
	for(int i=1;i<=m;++i)
	{
		last=arr[last];
	}
	cout<<last;
}

Measured memory_bytes: 5960
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define LL long long 
#define LD long double
LL n,a,b,ans=0x3f3f3f3f3f3f3f3f;
int main()
{
	cin>>n>>a>>b;
	ans=min(ans,min(max(a-1,b-1),max(n-a,n-b)));
	if((a+b)%2==0)ans=min(ans,(a+b)/2-min(a,b));
	else 
	{
		if(a>b)swap(a,b);
		LL sum=0;
		LL c=1,d=b-a+1;sum=a-1;
		if((c+d)%2==0)ans=min(sum+(c+d)/2-1,ans);
		else ans=min(sum+(c+d-1)/2,ans);
		c=a+(n-b),d=n;sum=n-b;
		if((c+d)%2==0)ans=min(sum+(c+d)/2-1,ans);
		else ans=min(sum+n-(c+d-1)/2,ans);
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    int n;
    cin>>n;
    int a[n+5];
    f(i,1,n)
    {
        cin>>a[i];
    }
    int ses=0;
    map<int,int>cnt;
    rf(i,n,1)
    {
        int val=a[i]+i;
        ses+=cnt[val];
        int nval=i-a[i];
        cnt[nval]++;
    }
    cout<<ses<<endl;

















    return 0;

}













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

int main(){
    
    int n,number;
    char egara;
    int s[14] = {0};
    int h[14] = {0};
    int c[14] = {0};
    int d[14] = {0};
    
    std::cin >> n;
    
    while(n > 0){
        std::cin >> egara >> number;
        switch (egara) {
            case 'S':
                s[number] = 1;
                break;
            case 'H':
                h[number] = 1;
                break;
            case 'C':
                c[number] = 1;
                break;
            case 'D':
                d[number] = 1;
                break;
        }
        n--;
    }
    //出力
    for(int i = 1; i <= 13; i++){
        //std::cout << s[i] << "\n";
        
       
        if(s[i] == 0){
            std::cout << "S" << " " << i << "\n";
        }
    }
    
    for(int i = 1; i <= 13; i++){
        if(h[i] == 0){
            std::cout << "H" << " " << i << "\n";
        }
    }
    
    for(int i = 1; i <= 13; i++){
        if(c[i] == 0){
            std::cout << "C" << " " << i << "\n";
        }
    }
    
    for(int i = 1; i <= 13; i++){
        if(d[i] == 0){
            std::cout << "D" << " " << i << "\n";
        }
    }
    
    return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define rep(i,a,b) for(ll i = a;i <= b;i++)
#define repv(i,a,b) for(ll i = a;i >= b;i--)
#define e endl
#define all(v) v.begin(), v.end()
typedef pair<ll,ll> pp;

int lcm(int a, int b)
{
    int lar = max(a, b);
    int small = min(a, b);
    for (int i = lar; ; i += lar) {
        if (i % small == 0)
            return i;
    }
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result
  
    x = x % p; // Update x if it is more than or
                // equal to p
   
    if (x == 0) return 0; // In case x is divisible by p;
  
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
  
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

bool isPowerOfTwo (ll x)
{
    return x && (!(x&(x-1)));
} //cout << h[i] << " " << cnt[i] << " " << good[i] << " " << bad[i] << e;


void solve(){
    string s; cin >> s;
    ll count = 0;
    if(s[1] == 'R'){
        if(s[0] == 'R' && s[2] == 'R') cout << 3 << endl;
        else if(s[0] == 'R' || s[2] == 'R') cout << 2 << endl;
        else cout << 1 << e;
    }
    else if(s[0] == 'R' || s[2] == 'R') cout << 1 << endl;
    else cout << 0 << e;
}
        
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    //ll t; cin >> t; while(t--)
        solve();
}


Measured memory_bytes: 3608
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
    var money = int.Parse(ReadLine());
    var x = money/500;
    var y = (money%500)/5;
    
    Write(x*1000 + y*5);
    
    
  }
}

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




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

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

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<int, int>;

/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}



const int INF = 1001001001;



int main() {
	string s, t;
	cin >> s >> t;
	rep(i, s.size()) {
		if (s == t) {
			cout << "Yes";
			return 0;
		}
		s = s.back() + s.substr(0, s.size() - 1);
	}
	cout << "No";
	
	return 0;
}













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

template <typename T,typename U>
struct compressor{
	vector<pair<T,U>> v;
	void add(T x,U y){
		v.emplace_back(x,y);
	}
	
	void compress(){
		sort(v.begin(),v.end());
		
		vector<pair<T,U>> t;
		rep(i,v.size()){
			if(t.size()!=0 && t.back().first == v[i].first){
				t.back().second = func(t.back().second,v[i].second);
			}
			else{
				t.push_back(v[i]);
			}
		}
		swap(v,t);
		
	}

	U func(U a,U b){
		return a+b;
	}

	int size(){
		return v.size();
	}
	
	U get(int p){
		return v[p].second;
	}
	
	U operator[] (T &x){
		return lower_bound(v.begin(),v.end(),x)->second;
	}
};

int main(){

	int N;
	cin>>N;
	
	compressor<string,int> C;
	
	for(int i=0;i<N;i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		C.add(s,1);
	}
	
	C.compress();
	
	long long ans = 0;
	
	rep(i,C.size()){
		long long t = C.get(i);
		ans += t * (t-1) / 2;
	}
	
	cout<<ans<<endl;

	return 0;
}



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int X = nextLong();
  int N = nextLong();

  set<int> P;
  REP(i, N) {
    int p = nextLong();
    P.insert(p);
  }


  int ans = -1000;
  for (int x = -1000; x <= 1000; x++) {
    if (P.count(x)) continue;
    if (abs(X - x) < abs(ans - X)) {
      ans = x;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3692
N, M = map(int, input().split())

WA = [0] * (N+1)
AC = [0] * (N+1)
for i in range(M):
    p, s = input().split()
    p = int(p)
    
    if s == "AC":
        AC[p] = 1
    elif AC[p] == 0:
        WA[p] += 1
            
print(sum(AC), sum(w if a > 0 else 0 for a, w in zip(AC, WA)))

Measured memory_bytes: 4596