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

int main(){
    int A, B, C, N, M ,K;
    int sum = 0;
    int t = 0;
    string s, s1;
    //cin >> A >> B;
    vector<int> X(5);
    for(int i = 0; i < 5; i++){
        cin >> X.at(i);
    } 

    for(int i = 0; i < 5; i++){
        int j = 0;
        while(j != 4){
            if(X.at(i)%10 < X.at(j)%10) swap(X.at(i), X.at(j));
            j++;
        }
    }

    for(int i = 0; i < 5; i++){
        if(X.at(i)%10 == 0){
            sum += X.at(i);
            t++;
        }
    }

    for(int i = 0; i < 5; i++){
        if(i == t) sum += X.at(i);
        else if(X.at(i)%10 != 0) sum += (X.at(i) + 10 - X.at(i)%10);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
#define BLACK 0
#define WHITE 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll N, H, W;
    cin >> N >> H >> W;
    ll i;
    ll a[1100], b[1100];
    ll ans=0;
    for(i=0; i<N; i++) {
        cin >> a[i] >> b[i];
        if(a[i]>=H && b[i]>=W) {
            ans++;
        }
    }
    
    pr(ans);
    
    
    
    
}


















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,x,n) for(int i=x;i<n;++i)
#define ar array
void func(int n){
    for(int i=0;i<=n;++i)
        cout<<i<<" ";
    for(int i=n-1;i>=0;--i)
        cout<<i<<" ";
    cout<<endl;
}
int32_t main()
{
  int n,a,b; cin>>n>>a>>b;
  int t=a+b;
  int x=n/t;
  int ans=x*a;
  int r=n%t;
  ans+=min(r,a);
  cout<<ans;
    return 0;
}


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

//????¨???????????¶????????????¨???????????????
class CAL{
private:
  string m_str;
  size_t m_cur;
  int digit();
  int number();
  int term();
  int factor();
public:
  CAL(string str);
  int expression();
};

//?????????????????????
CAL::CAL(string str):
  m_str(str),m_cur(0)
{
  m_str.resize(m_str.size() - 1);
}

//??????????????°????????°????????????
int CAL::digit()
{
  assert(isdigit(m_str[m_cur]));
  int n = m_str[m_cur++] - '0';
  return n;
}

//??°??????????????¨?????¨???????????°?????¨????????????
int CAL::number()
{
  int n = digit();
  while(m_cur < m_str.size() && isdigit(m_str[m_cur]))
    n = n*10 + digit();
  return n;
}

//???????????¨?????????????°???\
int CAL::term()
{
  int a = factor();
  while(m_cur < m_str.size() && (m_str[m_cur] == '*' || m_str[m_cur] == '/')){
    char op = m_str[m_cur++];
    int b = factor();
    if(op == '*') a *= b; else if(op == '/') a /= b;
  }
  return a;
}

//??¬??§???????????????????????°?????¨?????????????????????number()??????????????????
int CAL::factor()
{
  if(m_str[m_cur] != '(') return number();
  m_cur += 1;
  int n = expression();
  assert(m_str[m_cur] == ')');
  m_cur += 1;
  return n;
}

//??????????¨?
int CAL::expression()
{
  int a = term();
  while(m_cur < m_str.size() && (m_str[m_cur] == '+' || m_str[m_cur] == '-')){
    char op = m_str[m_cur++];
    int b = term();
    if(op == '+') a += b; else if(op == '-') a -= b;
  }
  return a;
}

int main()
{
  int N;
  cin >> N;//???????????°
  queue<int> answer;//???????????\?????????
  string str;
  for(int i = 0; i < N; ++i){
    cin >> str;//????????£??\
    CAL a(str);
    answer.push(a.expression());
  }
  while(!answer.empty()){
    cout << answer.front() << endl;
    answer.pop();
  }
}

Measured memory_bytes: 1216
n=gets.to_i

sam1=Array.new(n)
sam2=Array.new(n)
sam1=gets.split.map!(&:to_i)
sam2=gets.split.map!(&:to_i)

kot1=1
kot2=1
kazu1=n
kazu2=n
for i in 0..n-2
  ans1=1
  for j in 1..kazu1
    ans1=ans1*j
  end
  kot1+=ans1/kazu1*(sam1[i]-1)
  kazu1-=1
  for k in 0..n-1
    if sam1[k]>sam1[i]
      sam1[k]=sam1[k]-1
    end
  end
end
for i in 0..n-2
  ans2=1
  for j in 1..kazu2
    ans2=ans2*j
  end
  kot2+=ans2/kazu2*(sam2[i]-1)
  kazu2-=1
  for j in 0..n-1
    if sam2[j]>sam2[i]
      sam2[j]-=1
    end
  end
end
puts (kot1-kot2).abs


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

// マクロ //
#define rep(i,N) for(int i = 1; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint comb(int n, int m) {
    return perm(n) / (perm(n - m) * perm(m));
}

// End of Template //



int main() {

    int N;
    cin >> N;

    if (N > 81) {
        n();
    }
    else {
        rep(i, sqrt(N) + 1) {
            if (N % i == 0 && i < 10 && N / i < 10) {
                y(), exit(0);
            }
        }
        n();
    }
}

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

int main(){
    int n;
    cin >> n;
    int k[n];
    for(int i = 0; i < n; i++){
        cin >> k[i];
    }
    for(int j = 0; j < n; j++){
        cout << k[n-1-j];
        if(j != n-1) cout << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx3[4] = {1, 0, -1, 0};
int dy3[4] = {0, 1, 0, -1};
int dx[8] = {1, 0, -1, -1, -1, 0, 1, 1};
int dy[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dx2[16] = {0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
int dy2[16] = {2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2};
struct state{
  int x, y, S;
  int c;
  state() {}
  state(int x, int y, int S, int c) : x(x), y(y), S(S), c(c) {}
  bool operator < (const state& s) const {
    return c > s.c; //rev
  }
};

int main(){
  int W, H;
  while(cin>>W>>H && (W||H)){
    vector<string> grid(H);
    REP(y, H) cin>>grid[y];
    int cnt = 0;
    REP(y, H)REP(x, W)if(grid[y][x] == 'M'){
      grid[y][x] = cnt + '0';
      cnt++;
    }
    const int goalS = (1<<cnt) - 1;
    int move[100][100] = {};
    REP(y, H)REP(x, W) move[y][x] = 1;
    REP(y, H)REP(x, W){
      if(grid[y][x] == '#'){
        REP(r, 8){
          int nx = x + dx[r], ny = y + dy[r];
          if(nx >= 0 && ny >= 0 && nx < W && ny < H){
            move[ny][nx] = 3;
          }
        }
        REP(r, 16){
          int nx = x + dx2[r], ny = y + dy2[r];
          if(nx >= 0 && ny >= 0 && nx < W && ny < H){
            move[ny][nx] = max(move[ny][nx], 2);
          }
        }
      }
    }
    int dist[1<<5][100][100];
    priority_queue<state> que;
    REP(y, H)REP(x, W)REP(i, 1<<5)dist[i][y][x] = INF;
    REP(y, H)REP(x, W)if(grid[y][x] == 'S'){
      dist[0][y][x] = 0;
      que.push(state(x, y, 0, 0));
    }
    int ans = INF;
    while(!que.empty()){
      state s = que.top(); que.pop();
      if(s.S == goalS && grid[s.y][s.x] == 'G'){
        ans = s.c;
        break;
      }
      REP(r, 4){
        int nx = s.x + dx3[r];
        int ny = s.y + dy3[r];
        if(!(nx >= 0 && ny >= 0 && nx < W && ny < H)) continue;
        if(grid[ny][nx] == '#') continue;
        int nc = s.c + move[s.y][s.x];
        int nS = s.S;
        if(grid[ny][nx] <= '5' && grid[ny][nx] >= '0'){
          nS = nS | (1<<(grid[ny][nx]-'0'));
        }
        if(dist[nS][ny][nx] > nc){
          dist[nS][ny][nx] = nc;
          que.push(state(nx, ny, nS, nc));
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2636
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let A = xs[1].trim().split(' ').map(v=>parseInt(v,10));
   let N = xs[0];
   const compare = (a, b) => {
   return a - b;
   }
   A.sort(compare);
   
   let count = 0;
   for(let i =0; i<A.length; i++){
       if(A[i]==A[i+1]){
       count += 1;
       }else{
       count +=0;
       }
   }
   if(count==0){
     console.log('YES');
   }else{
     console.log('NO');
   }
   
} 
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 34584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, s, t) for(int i = (s); i < (t); i++)

int N;
ll A[3005], DP[3005][3005];

ll sol = 0;

// 0 - Taro's turn
// 1 - Jiro's turn

ll rek(int l, int r, int turn) {
    if(l>r) return 0;
    if(l==r) {
        return DP[l][r] = A[l]*(1-turn);
    }
    if(DP[l][r] != 0) return DP[l][r];
    ll sol1 = rek(l+1, r, 1-turn) + A[l];
    ll sol2 = rek(l, r-1, 1-turn) + A[r];
    if(turn == 0) {
        DP[l][r] = max(sol1, sol2);
    }
    else {
        DP[l][r] = min(sol1 - A[l], sol2 - A[r]);
    }
    return DP[l][r];
}

int main()
{
    scanf("%d", &N);
    ll sum = 0;
    REP(i, 0, N) {
        scanf("%lld", &A[i]);
        sum += A[i];
    }

    ll x = rek(0, N-1, 0);
    printf("%lld\n", x-(sum-x));

    return 0;
}


Measured memory_bytes: 70272
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;


bool valid[10];
inline bool solve(int n)
{
  while (n)
    {
      if (!valid[n%10])
    return false;
      n /= 10;
    }
  return true;
}
int main()
{
  int n, k;
  scanf("%d %d", &n, &k);
  memset(valid, 1, sizeof(valid));
  for (int i = 0; i < k; ++i)
    {
      int x;
      scanf("%d", &x);
      valid[x] = false;
    }
  while (!solve(n))
    ++n;
  printf("%d\n", n);
}

Measured memory_bytes: 256
import java.util.Scanner;

//AtCoder Beginner Contest 140
//C	Maximal Value
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] bList = new int[N - 1];
		for (int i = 0; i < N - 1; i++) {
			bList[i] = Integer.parseInt(sc.next());
		}
		sc.close();

		int ans = 0;
		for (int i = N - 2; i >= 0; i--) {
			if (i == N - 2) {
				ans += bList[i];
			} else {
				if (bList[i] < bList[i + 1]) {
					ans += bList[i];
				} else {
					ans += bList[i + 1];
				}
			}
		}
		ans += bList[0];

		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
import itertools
N,M = map(int,input().split())
K =[list(map(int,input().split())) for _ in range(M)]
P = list(map(int,input().split()))

prod = list(itertools.product([0,1], repeat = N))
cnt = 0
for i in range(len(prod)):
  judge = True
  for j in range(M):
    temp = 0
    for k in range(K[j][0]):
      if prod[i][K[j][k+1]-1] == 1:
        temp += 1
    if temp % 2 != P[j]:
      judge = False
  if judge == True:
    cnt += 1

print(cnt) 

Measured memory_bytes: 3188
#include <iostream>
//#include <vector>
//#include <cstdlib>
//#include <algorithm>
//#include <cmath>
using namespace std;
 
int main() {
    string s;
    
    cin >> s;
    
    //cout << s.size();
   for(int i=0; i<s.size(); i = i + 2){
        cout << s.at(i);       
    }
    
    return 0;
}

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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  ld ret = 0;
  for(int i = 1; i <= N; ++i) {
    ld tmp = 1;
    while(tmp * i < K) {
      tmp *= 2;
    }
    ret += 1 / (tmp * N);
  }
  cout << fixed << setprecision(10) << ret << endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();
    long ans = 0;
    if(a == 0) {
      ans = b / x + 1;
    } else if(a == 1) {
      ans = b / x;
    } else { 
      ans = b / x - (a - 1) / x;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include<cstdio>
#include<algorithm>
int cnt[200005];
int a[200005];

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    std::sort(a+1,a+1+n);
    int p = 1, size = 0;
    while(p<=n){
        int np = p;
        while(np+1<=n && a[np+1]==a[p]) np++;
        cnt[++size] = np-p+1;
        p = np+1;
    }
    std::sort(cnt+1,cnt+1+size);
    int ans = 0;
    int left = size-k;
    for(int i = 1; i <= left; i++) ans += cnt[i];
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>

void swap(int *a, int *b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void merge_sort (int array[], int left, int right)
{
	int i, j, k, mid;
	int work[300000];

	if (left < right)
	{
		mid = (left + right) / 2;
		merge_sort(array, left, mid);
		merge_sort(array, mid+1, right);
		for (i = mid; i >= left; i--)
		{
			work[i] = array[i];
		}
		for (j = mid+1; j <= right; j++)
		{
			work[right-(j-(mid+1))] = array[j];
		}
		i = left; j = right;
		for (k = left; k <= right; k++)
		{
			if (work[i] > work[j])
			{
				array[k] = work[i++];
			}
			else
			{
				array[k] = work[j--];
			}
		}
	}
}

int main(void)
{
	int n;
	int a[300000];
	long long int ans = 0;
	int i;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	merge_sort(a, 0, n - 1);

	for (i = 0; i < (n + 1) / 2; i++)
	{
		ans += a[i];
	}
	ans *= 2;
	ans -= a[0];
	if (n % 2 == 1) ans -= a[n / 2];

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

	return 0;
}


Measured memory_bytes: 16672
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long

int main(){
  int a,b,c;cin>>a>>b>>c;
  int t=a+b+c,m=max(a,max(b,c));
  if((t-m)%2!=0){
    m=m+1;
  }
  cout<<(3*m-t)/2<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
void f(int*,int*);
int main(int argc, char *argv[])
{
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=1;i<=k;i++)
		if(i%2==1)
			f(&a,&b);
		else
			f(&b,&a);
	cout<<a<<" "<<b<<endl;
	return 0;
}
void f(int* x,int* y)
{
	if(*x%2==1)
		*x-=1; 
	*y=*y+*x/2;
	*x=*x/2;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	p := sc.nextIntSlice(N)
	sort.Ints(p)
	ans := p[N-1] / 2
	for i := 0; i < N-1; i++ {
		ans += p[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int length, breadth;		//Value a, b.
	int area, rectangle;		//answers.

	scanf("%d %d", &length, &breadth);
	area = length * breadth;
	rectangle = length * 2 + breadth * 2;

	printf("%d %d\n", area, rectangle);
	return (0);
}



Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  long x[n];
  int i;
  for(i=0;i<n;i++){
    cin >> x[i];
  }
  long dist[n-k+1];
  for(i=0;i<n-k+1;i++){
    if(x[i]<0&&x[i+k-1]>0)dist[i] = min(2*abs(x[i])+x[i+k-1],abs(x[i])+2*x[i+k-1]);
    else dist[i] = max(abs(x[i]),abs(x[i+k-1]));
  }
  long ans = dist[0];
  for(i=1;i<n-k+1;i++){
    if(ans > dist[i])ans = dist[i];
  }
  cout << ans;
}


Measured memory_bytes: 1408
#include <iostream>

int main () {
    int n, k;
    std::cin >> n >> k;
    int h[n], ans = 0;
    for(int i = 0; i < n; ++i) {
        std::cin >> h[i];
        if(h[i] >= k) ++ans;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 640
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;

int main()
{
    optimizeIO();

    int n;
    cin>>n;

    vector<LL>v(n);

    LL s = 0;

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

    sort(ALL(v));
    reverse(ALL(v));

    s += v[0];

    int lagbe = n-2;

    for(int i=1;i<n;i++)
    {
//        DBG(lagbe);

        if(lagbe>=2)
        {
            s += 2*v[i];
            lagbe -= 2;
        }
        else if(lagbe==1)
        {
            s += v[i];
            lagbe -= 1;
        }
        else if(lagbe==0)
            break;

    }

    cout<<s<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 4748
_n, k = gets.chomp.split(' ').map(&:to_i)
towns = gets.chomp.split(' ').map { |i| i.to_i - 1 }
visited = Hash.new(false)
current = 0
sequence = []
until visited[current] do
  visited[current] = true
  sequence << current
  current = towns[current]
end
close_start = sequence.find_index(current)
not_close = sequence[0, close_start]
close = sequence[close_start, sequence.length]
if not_close.length > k
  puts not_close[k] + 1
else
  length = k - not_close.length
  puts close[length % close.length] + 1
end

Measured memory_bytes: 39180
//#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

/*
ID: jamerz1
PROG: hidden
LANG: C++11
*/

using namespace std;

// TIMER
std::clock_t __start;
double __duration;
void start_timer() { __start = std::clock(); }
void print_timer() {
	__duration = (std::clock() - __start) / (double)CLOCKS_PER_SEC;
	std::cout << "Duration (msec): " << __duration * 1000 << '\n';
}
// END TIMER

//PI
#define M_PI		3.14159265358979323846
// fast input
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)

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

double EPS_ = 1e-16;
bool eq_(const double& lhs, const double &rhs) {
	return (fabs(lhs - rhs) < EPS_);
}

//#define F first
//#define S second

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef pair<int, int> ii;
typedef pair<double, double> dd;

typedef pair<ll, ll> llll;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<llll> vllll;
typedef vector<int> vi;
typedef vector<ull> vull;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;

const int INF = int(2e9);
const ll INF_LL = LLONG_MAX;
const ll MOD = 1e9 + 7;

bool mysort(ii lhs, ii rhs) {
	if (lhs.first == rhs.first) {
		return lhs.second < rhs.second;
	}
	else
		return lhs.first < rhs.first;
}

int main()  {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N, C;
	cin >> N >> C;
	int s, t, c;
	vector<vii> chans(C, vii());
	for (int i = 0; i < N; ++i) {
		cin >> s >> t >> c;
		chans[c - 1].push_back({ s, t });
	}
	for (int c = 0; c < C; ++c) {
		if (chans[c].size() < 2)
			continue;

		sort(chans[c].begin(), chans[c].end());
		vii new_chan;
		int start = chans[c][0].first;
		int idx = 1;
		while (idx < chans[c].size()) {
			if (chans[c][idx].first == chans[c][idx - 1].second) {
				++idx;
			}
			else {
				new_chan.push_back({ start, chans[c][idx - 1].second });
				start = chans[c][idx].first;
				++idx;
			}
		}
		new_chan.push_back({ start, chans[c][chans[c].size() - 1].second });
		chans[c] = new_chan;
	}

	vii times;
	for (int c = 0; c < C; ++c) {
		for (int i = 0; i < chans[c].size(); ++i) {
			times.push_back({ chans[c][i].first, 0 });
			times.push_back({ chans[c][i].second, 1 });

		}
	}
	sort(times.begin(), times.end(), mysort);
	int max_count = 0;
	int curr_count = 0;
	for (int i = 0; i < times.size(); ++i) {
		if (times[i].second == 0) {
			++curr_count;
			max_count = max(max_count, curr_count);
		}
		else {
			--curr_count;
		}
	}
	cout << max_count << '\n';
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <cstdlib>
#include <iterator>
#include <algorithm>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int ans = 1e9;
    for (int i = 0; i + m - 1 < n; i++)
    {
        int c = 0, cnt = 0;
        int ind1 = i;
        int ind2 = 0;
        while (cnt < m)
        {
            if (s[ind1++] != t[ind2++])
                c++;
            cnt++;
        }
        ans = min(ans, c);
    }
    cout << ans;
    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,m,ans=0;
    cin>>n>>m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    sort(all(a));
    reverse(all(a));

    vector<pll> p(m);
    for (int i = 0; i < m; i++)
    {
        ll b,c;
        cin>>b>>c;
        p[i]=make_pair(c,b);
    }
    sort(all(p));
    reverse(all(p));
    ll ai=0,pi=0,cnt=0;
    while(cnt<n)
    {
        if(a[ai]>=p[pi].first)
        {
            ans+=a[ai];
            cnt++;
            ai++;
        }
        else
        {
            ll ninzu = min(p[pi].second, n-cnt);
            ans+=p[pi].first * ninzu;
            cnt+=ninzu;
            pi++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int q;
	cin>>q;
	int flag=0;
	while(q--){
		int k;
		cin>>k;
		if(k==1)flag++;
		else{
			int f;
			char c;
			cin>>f>>c;
			if(f==1){
				if(flag%2==0)
				s.insert(s.begin(),c);
				else s.insert(s.end(),c);
				
			}
			else{
				if(flag%2==0)s.insert(s.end(),c);
				else s.insert(s.begin(),c);
			}
		}
	}
	if(flag%2)reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
typedef pair<ld, int> pdi;

int main()
{
	int h, w;
	cin >> h >> w;
	vs fld(h+2);
	fld[0] = fld[h + 1] = string(w+2, '.');
	REP(i, h)
	{
		string s; cin >> s;
		fld[i + 1] = "." + s + ".";
	}
	vector<pdi> v;
	FOR(i, 1, h + 2)FOR(j, 1, w + 2)
	{
		ld t;
		if (j != 1) t = (ld)(h + 1 - i) / (ld)(j-1);
		else t = INF;
		if (fld[i - 1][j - 1] == '.'&&fld[i - 1][j] == '.'&&fld[i][j - 1] == '.'&&fld[i][j] == '#')
		{
			v.emplace_back(t, -1);
		}
		if (fld[i - 1][j - 1] == '#'&&fld[i - 1][j] == '#'&&fld[i][j - 1] == '#'&&fld[i][j] == '.')
		{
			v.emplace_back(t, -1);
		}
		if (fld[i - 1][j - 1] == '#'&&fld[i - 1][j] == '.'&&fld[i][j - 1] == '.'&&fld[i][j] == '.')
		{
			v.emplace_back(t, 1);
		}
		if (fld[i - 1][j - 1] == '.'&&fld[i - 1][j] == '#'&&fld[i][j - 1] == '#'&&fld[i][j] == '#')
		{
			v.emplace_back(t, 1);
		}
	}
	sort(v.rbegin(),v.rend());
	int ans = -1, tmp = 1;
	REP(i, v.size())
	{
		tmp -= v[i].second;
		chmax(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

#define endl '\n'

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

    int n, m; cin >> n >> m;
    int a[n], soma=0; for (int i=0; i<n; i++){cin >> a[i]; soma+=a[i];}
    sort(a, a+n);

    int c=0, frac = (soma + 4*m - 1)/(4*m);
    for (int i=n-1; i>=0; i--){
        if (a[i] < frac) break;
        c++;
    }
    if (c < m) cout << "No\n";
    else cout << "Yes\n";
}


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

int main()
{
    int n,k;
    int result=1;
    cin>>n>>k;
    result*=k;
    for(int i=2;i<=n;i++){
        result*=(k-1);
    }
    printf("%d\n",result);
    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++)

int main()
{
  int n;
  cin >> n;
  vector<int> a(n), l(n+1), r(n+1);
  rep(i,n) cin >> a[i];
  
  a.push_back(0);
  exclusive_scan(a.begin(), a.end(), l.begin(), 0,
                [](int x, int y) {return gcd(x, y); });
  exclusive_scan(a.rbegin(), a.rend(), r.rbegin(), 0,
                [](int x, int y) {return gcd(x, y); });
  
  int ans = 0;
  rep(i,n+1)
    ans = max(ans, gcd(l[i], r[i]));
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4764
#include <iostream>
#include <stdio.h>
#include <vector>
#include <deque>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int main(){

    deque<string> s;
    string first_s;
    int n;
    cin >> first_s >> n;

    s.push_front(first_s);

    bool reverse_flag = true;

    int t, f;
    string c;
    REP(i, 0, n){
        cin >> t;
        if(t == 1){ reverse_flag = not reverse_flag;}
        else{
            cin >> f >> c;
            if(reverse_flag){
                if(f == 1){s.push_front(c);} //c + s
                else{s.push_back(c);}//s + c
            } else {
                if(f == 1){s.push_back(c);}
                else{s.push_front(c);}
            }
        }
    }

    string ans;
    REP(i, 0, s.size()){
        ans += s[i];
    }

    if(not reverse_flag){reverse(ans.begin(), ans.end());}


    p(ans);

    return 0;
}

Measured memory_bytes: 12128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

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

  int cnt = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (S[i] == S[i + 1]) ++cnt;
  }
  cout << min(cnt + K * 2, N - 1) << endl;
}


Measured memory_bytes: 3740
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int c = 0;

        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(int i=0;i<n-1;i++){
            for(int j=n-1;j>i;j--){
                if(a[j-1]>a[j]){
                    int b = a[j-1];
                    a[j-1] = a[j];
                    a[j] = b;
                    c++;
                }
            }
        }
        for(int i=0;i<n;i++){
            if(i==n-1) System.out.println(a[i]);
            else System.out.print(a[i]+" ");
        }
        System.out.println(c);
        sc.close();
    }
}


Measured memory_bytes: 26176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int w[] = new int[n];
		for(int i=0; i<n; i++) {
			w[i] = sc.nextInt();
		}
		int min = 1000000000;
		for(int i=0; i<n; i++) {
			int s1 = 0;
			int s2 = 0;
			for(int j = 0; j<=i; j++) {
				s1 += w[j];
			}
			for(int k = i+1; k<=n-1; k++) {
				s2 += w[k];
			}
			int minTemp = Math.abs(s1 - s2);
			if(minTemp < min) {
				min = minTemp;
			}
		}

		System.out.println(min);
	}
}

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

int main(){
    int n, A[201];
    string s;

    cin >> n;

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

    int cnt = 0;

    while(true){
        bool odd = false;
        for (int i = 0; i < n; ++i){
            if (A[i] % 2 != 0) odd = true;
        }

        if (odd) break;

        for (int i = 0; i < n; ++i){
            A[i] /= 2;
        }  
        ++cnt;       
    }
    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int a[50];

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        cin >> a[i];
    }

    int b = 1e6 + 1, u = -1e6 - 1;
    int bIdx, uIdx;
    rep(i, n)
    {
        if (b > a[i]) {
            b = a[i];
            bIdx = i;
        }
        if (u < a[i]) {
            u = a[i];
            uIdx = i;
        }
    }

    vector<pair<int, int>> ans;

    if ((int64_t)b * u <= 0) {
        if (u + b >= 0) {
            rep(i, n)
            {
                ans.push_back(make_pair(uIdx, i));
                a[i] += a[uIdx];
            }
        } else {
            rep(i, n)
            {
                ans.push_back(make_pair(bIdx, i));
                a[i] += a[bIdx];
            }
        }
    }

    if (a[0] >= 0) {
        rep(i, n)
        {
            if (i < n - 1) {
                ans.push_back(make_pair(i, i + 1));
                a[i + 1] += a[i];
            }
        }
    } else {
        rrep(i, n)
        {
            if (i > 0) {
                ans.push_back(make_pair(i, i - 1));
                a[i - 1] += a[i];
            }
        }
    }

    cout << ans.size() << endl;
    for (const auto& p : ans) {
        cout << p.first + 1 << " " << p.second + 1 << endl;
    }

    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin>>n;
  vector<int> diff(n);
  for(int i = 0; i < n; i++) {
    cin>>diff[i];
  }
  
  int count = 0;
  if(n%2 != 0) {
    cout<<count<<endl;
    return 0;
  }
  
  sort(diff.begin(), diff.end());
  int hi = diff[n/2];
  int lo = diff[(n/2) - 1];
  count = hi-lo;
  cout<<count<<endl;
  
  return 0;
}
  

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	string s;
	int m;
	int cnt=0;
	vector<string> ans;
	int c=0;
	bool f=false;
	
	cin>>s;
	cin>>m;
	for(int i=0;i<s.length();i++)
	{
		string t=s.substr(i,1);
		ans.push_back(t);
	}
	for(int i=1;i<s.length();i++)
	{
		string t=s.substr(i-1,2);
		ans.push_back(t);
	}
	for(int i=2;i<s.length();i++)
	{
		string t=s.substr(i-2,3);
		ans.push_back(t);
	}
	for(int i=3;i<s.length();i++)
	{
		string t=s.substr(i-3,4);
		ans.push_back(t);
	}
	for(int i=4;i<s.length();i++)
	{
		string t=s.substr(i-4,5);
		ans.push_back(t);
	}
	sort(ans.begin(),ans.end());
	int i=1;
	while(i<ans.size())
	{
		if(ans[i]==ans[i-1])
			ans.erase(ans.begin()+i-1);
		else
			i++;
	}
	cout<<ans[m-1]<<endl;
	return 0;
}

Measured memory_bytes: 1660
def stablesort(a)
   arr=Array.new(10){Array.new}
   a.each{|v|
     idx=v[1].to_i
     arr[idx].push(v[0])
   }
   res=Array.new
   arr.each_with_index{|x,i|
      if x!=nil then
         x.each{|y|
            res.push(y+i.to_s)
         }
      end
   }
   return res.join(" ")
end

def BubbleSort(a)
    n=a.length
    (0..n-1).each do |i|
        if i+1 > n-1 then next end
        (i+1..n-1).reverse_each do |j|
            if a[j][1] < a[j-1][1] then
               a[j],a[j-1]=a[j-1],a[j]
            end
        end
    end
    return a.join(" ")
end

def SelectionSort(a)
    n=a.length
    (0..n-1).each do |i|
        mini=i
        (i..n-1).each do |j|
            if a[j][1] < a[mini][1] then
               mini=j
            end
        end
        if mini!=i then
           a[i],a[mini]=a[mini],a[i]
        end
    end
    return a.join(" ")
end

def printst(r1,r2)
    if r1!=r2 then
       printf("Not stable\n")
    else
       printf("Stable\n")
    end
end

n=gets.to_i
indata1=gets.split(' ')
indata2=indata1.clone
indata3=indata1.clone
r1=stablesort(indata1)
r2=BubbleSort(indata2)
r3=SelectionSort(indata3)
printf("%s\n",r2)
printst(r1,r2)
printf("%s\n",r3)
printst(r1,r3)

Measured memory_bytes: 8800
n = int(input())
keta = len(str(n))

if keta <= 2:
    print(0)
else:
    # keta-1までのパターン
    ans = 0
    # for k in range(3, keta):
    #    ans = pow(3, k) - 3 - (3*(pow(2, k) + 2))

    from itertools import product
    for k in range(3, keta+1):
        for l in product(['3', '5', '7'], repeat=k):
            if not '3' in l or not '5' in l or not '7' in l:
                continue
            nn = int(''.join(l))
            if nn <= n:
                ans += 1

    print(ans)


Measured memory_bytes: 68420
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

LL fact[100005], ifact[100005];
const LL MOD = 1000000007;

LL bigmod(LL a, LL b) {
	if (b == 0) return 1;
	LL x = bigmod(a, b / 2);
	x = (x * x) % MOD;
	if (b & 1)  x = (x * a) % MOD;
	return x;
}

int num[100005], vis[100005];
LL ans[100005];

LL ncr(LL n, LL r) {
	if (n < r) return 0;
	LL x = fact[n];
	x *= ifact[n - r];
	x %= MOD;
	x *= ifact[r];
	x %= MOD;
	return x;
}

int main()
{
	fact[0] = ifact[0] = 1;
	for (int i = 1; i <= 100001; i++) {
		fact[i] = (i * fact[i - 1]) % MOD;
		ifact[i] = bigmod(fact[i], MOD - 2);
	}

	int n;
	scanf("%d", &n);
	int sp;
	for (int i = 1; i <= n + 1; i++) {
		scanf("%d", &num[i]);
		if (vis[num[i]]) sp = num[i];
		vis[num[i]] = 1;
	}

	VI V;
	for (int i = 1; i <= n + 1; i++) {
		if (num[i] == sp) {
			V.push_back(i);
		}
	}

	int a = V[0] - 1;
	int b = (n + 1) - V[1];
	for (int i = 1; i <= n + 1; i++) {
		ans[i] = ncr(n + 1, i);
		ans[i] -= ncr(a + b, i - 1);
		ans[i] += MOD;
		ans[i] %= MOD;
		printf("%lld\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 4352
/*
 *    author: Tran Minh Khoa
 *    created: 14.05.2019 08:01:48
 *    Ho Chi Minh University of Science
 */

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  cout.precision(10); 
  cout << fixed;
#ifdef KM777
  freopen("in", "r", stdin);
#endif
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << "\n";  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num), lower_bound(A, A+N, num)
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>		// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>			// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>		// push(x), front(), pop()
#include <deque>
#include <stack>		// push(x), top(), pop()
#include <map>			// M[key],  insert(key, val), erase(key), find(key), 
#include <set>			// insert(key), erase(key), find(key)

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

#define PI 3.141592653589793)
#define MOD 1000000007
#define REP(i, n) for(int i = 0; i < n; i++)

ll n;
long long a[200010];
ll ans;

void solve() {
	cin >> n;
	map<ll, ll> mp;
	mp[0]++;
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] == 0)ans++;
		a[i] += a[i - 1];
		mp[a[i]]++;
		if (a[i] == a[i - 1]) {
			ans += max(mp[a[i]] - 2, 0LL);
		}
		else {
			ans += max(mp[a[i]]-1, 0LL);
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 14336
n, k, *p_n = map(int, open(0).read().split())
p_n.insert(0, 0)
for i in range(n):
    p_n[i + 1] = ((p_n[i + 1] + 1) / 2) + p_n[i]

exp_sum = [0] * (n - k + 1)
for i in range(n - k + 1):
    exp_sum[i] = p_n[i + k] - p_n[i]
    
print(max(exp_sum))

Measured memory_bytes: 25036
const factorization = (n) => {
    let primes = []
    for(let i=2; i*i<=n; i++) {
        let e=0
        while(n%i===0) {
            e++
            n/=i
        }
        if(e) {
            primes.push(i)
        }
    }
    if(n>1) {
        primes.push(n)
    }
    return primes
}

const getGCD = (a,b) => {
    if(b===0)return a
    else if(a===0)return b
    return getGCD(b, a%b)
}

const main = (arg) => {
    const N = Number(arg.split("\n")[0])
    const a = arg.split("\n")[1].split(" ").map(Number)
    
    const MAX_A = 10**6+1
    
    //  check if p is in {a} (paircoprime)
    let set = [...new Array(MAX_A)].fill(0)
    isPairCoprime = true
    for(let i=0; i<N; i++) {
        //const factors = Object.keys(factorizationBySoE(a[i], primes))
  	    const factors = factorization(a[i])
        for(let j=0; j<factors.length; j++ ) {
            if(set[factors[j]] === 1) {
                isPairCoprime = false
            }
            set[factors[j]] = 1
        }
    }

  	if(isPairCoprime) {
        console.log("pairwise coprime")
        return
    }

  // setcoprime
    let gcd = 0
    for(let i=0; i<a.length; i++) {
        gcd = getGCD(gcd, a[i])
    }
    
    if(gcd===1) {
        console.log("setwise coprime")
        return
    }
    
    console.log("not coprime")
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 131948
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef priority_queue<int> Pr; typedef vector<int> Vi; typedef vector<Pi> Vp;
typedef map<int,int> MPi; typedef pair<Int,Int> Pl; typedef vector<Int> VI;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(nullptr); ios::sync_with_stdio(false);

    int n,k; cin>>n>>k; int c[n]={};
    for (int i = 0; i < k; i++){
        int a,b; cin>>a>>b;
        c[a-1]++; c[b-1]++;
    }
    for (int i = 0; i < n; i++)if(c[i]%2){cout<<"NO"<<'\n'; return 0;}
    cout<<"YES"<<'\n';
}

Measured memory_bytes: 640
// #pragma GCC optimize("O3", "unroll-loops")
  // #pragma GCC target("avx2")

  #include <bits/stdc++.h>
  using namespace std;

  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp> 
  using namespace __gnu_pbds;

  typedef long long int ll;
  #define endl '\n'
  #define ld long double
  #define all(a) a.begin(),a.end()
  #define int long long
  #define pb push_back
  #define pii pair <int, int>
  #define ff first
  #define ss second
  #define sz(v) (int)v.size() 
  #define UB upper_bound
  #define LB lower_bound
  #define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

  const int INF = 2e9 + 0;
  const int mod = 1e9 + 7;
  //const int mod = 998244353;

  void solve() {
    int n; cin >> n;
    set <string> st;
    while(n--) {
      string s; cin >> s;
      st.insert(s);
    }
    cout << sz(st) << '\n';
  }

  signed main() {
      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
      #endif
      int t = 1; //cin >> t;
      for(int i = 1; i <= t; i++) {
          solve();
      }
  }    


Measured memory_bytes: 19204
#include "bits/stdc++.h"

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;

int n,m,p,q,k,ans;
string s;
char ch;
vector<int> v;

vector<int> add_i_to_tenj[10];
int dp[2][2021];

void solve()
{
    for(int i=0;i<=9;i++){
        for(int j=0;j<2020;j++){
            if( (10*j + i)%2019 == 0)
                add_i_to_tenj[i].pb(j);
        }
    }

    cin>>s;

    int n = s.length();
    int x = s[0] - 48;
    int num;

    dp[0][x%2019] += 1;

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

        x = s[i] - 48;

        for(int j=0; j<(int)add_i_to_tenj[x].size();j++){
            num = add_i_to_tenj[x][j];
            ans += dp[0][num];
        }

        for(int j=0;j<=2018;j++){
            dp[1][(10*j + x)%2019] += dp[0][j];
        }

        dp[1][x] += 1;

        for(int j=0;j<=2019;j++)
        {
            dp[0][j] = dp[1][j];
            dp[1][j] = 0;
        }
    }
    cout<<ans;
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main()
{
	long n;
	cin >> n;
	string s;
	cin >> s;
	vector<long> stone;
	bool black = true;
	long t = 0;
	long kuronokazu = 0;
	long shironokazu = 0;
	long answer = 0;
	//左の黒石の数から計測を始める

	for (long i = 0; i < n; i++) {
		if (black){
			if (s.substr(i, 1) == "#") {
				t++;
			}
			else {
				if ( (stone.size() == 0)&&(t < 1)) continue;
				stone.push_back(t);
				t = 1;
				black = false;
			}
		} else {
			if (s.substr(i, 1) == ".") {
				t++;
			}
			else {
				stone.push_back(t);
				kuronokazu += t;
				t = 1;
				black = true;
			}
		}
	}
	if(!black) kuronokazu += t;
	stone.push_back(t);

	/*if (stone.size() <= 1) {
		cout << 0 << endl;
		return 0;
	}*/
	answer = kuronokazu;
	for (long i = 0; i < stone.size()-1; i+=2) {
		shironokazu += stone[i];
		kuronokazu -= stone[i+1];
		if (answer > shironokazu + kuronokazu) answer = shironokazu + kuronokazu;
	}
	cout << answer << endl;

    return 0;
}

Measured memory_bytes: 2680
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {

	int n;
	while(cin >> n, n) {
		int result = 0;
		for(int i = 1; i < n; ++i) {
			int tmp = 0;
			for(int j = i; tmp < n; ++j) {
				tmp += j;
				if(tmp == n) {
					result++;
					break;
				}
			}
		}

		cout << result << endl;
	}


	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){long long i,n,a;cin>>n;vector<long long> s(100010,0);for(i=0;i<n;i++){cin>>a;s[a]++;s[a+1]++;s[a+2]++;}cout<<*max_element(s.begin(),s.end());}

Measured memory_bytes: 1152