akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EDoubleFactorial solver = new EDoubleFactorial();
        solver.solve(1, in, out);
        out.close();
    }

    static class EDoubleFactorial {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            long n = s.nextLong();
            if (n % 2 != 0) {
                out.println(0);
            } else {
                out.println(findTrailingZeros(n / 2));
            }
        }

        long findTrailingZeros(long n) {
            // Initialize result
            long count = 0;

            // Keep dividing n by powers of
            // 5 and update count
            for (long i = 5; n / i >= 1; i *= 5)
                count += n / i;

            return count;
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21844
#include<stdio.h>
#define N 100
#define White 0
#define Black 2
#define Gray 1

int n, M[N][N];
int color[N];
int d[N];
int f[N];
int time;
void DfsVisit(int );
void Dfs();
int main(){
  int i,j,u,k,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)
      M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  Dfs();

  return 0;
}
void DfsVisit(int u){
  int v;
  color[u]=Gray;
  d[u]=++time;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==White){
      DfsVisit(v);
    }
  }
  color[u]=Black;
  f[u]=++time;
}
void Dfs(){
  int i;
  for(i=0;i<n;i++)color[i]=White;
  time=0;
  for(i=0;i<n;i++){
    if(color[i]==White)
	DfsVisit(i);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}
    
    

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

int main(){
	char maxc[33],maxl[33],ss[1001][33];
	int a,b,cmax,i,c,count;
	
	memset(ss,'\0',sizeof(ss));
	i=0;
	while(0<=scanf(" %s ",ss[i])){
		++i;
	}
	maxl[0]=maxc[0]='\0';
	cmax=0;
	a=i;
	for(b=0;b<=i;++b){
		if(strlen(maxl)<strlen(ss[b])){
			strcpy(maxl,ss[b]);
		}
		count=0;
		for(c=0;c<=i;c++){
			if(!strcmp(ss[b],ss[c]))++count;
		}
		if(count>cmax){
			cmax=count;
			strcpy(maxc,ss[b]);
		}
	}
	printf("%s %s\n",maxc,maxl);
	return 0;
}

Measured memory_bytes: 0
//https://www.youtube.com/watch?v=8LusJS5-AGo
//https://www.geeksforgeeks.org/0-1-knapsack-problem-dp-10/
#include<bits/stdc++.h>
#define int long long
#define scf(n) scanf("%lld",&n)
#define rep1(n) for(int i=1;i<=n;i++)
#define prf(n) printf("%lld",n)
#define sci(n) scanf("%lld",&n)
#define pri(n) printf("%lld",n)

#define nl printf("\n")
#define spc printf(" ")
#define file freopen("in.txt","rt",stdin)
#define pii pair<int,int>
#define piii pair<pii,int>
#define MOD 10000007
const int INF = 1e18L + 5;
using namespace std;

/*bool sortBySec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/
void faster(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
/******************************************/



int32_t main()
{
   string s,s1;
   cin>>s>>s1;
   int cnt = 0;

   for(int i=0;i<s.size();i++)
   {
       if(s[i]==s1[i])
        cnt++;
   }
   cout<<cnt<<endl;



    return 0;
}


Measured memory_bytes: 256
def solve(n,l):
    count = [0]*n
    ans = 0
    for i in range(1,n):
            if l[i] <= l[i-1]:
                count[i] = count[i-1] + 1
                ans = max(ans,count[i])
    return ans

if __name__ == '__main__':
    num = int(input())
    matriz = list(map(int,input().split()))
    print(solve(num,matriz))

Measured memory_bytes: 14252
import java.util.*;

public class Main {
    static Map<Integer,Integer> dp = new HashMap<>();
    static List<Integer> depos = new ArrayList<>();

    static void doDepo(int n){
        List<Integer> ans = new ArrayList();
        for(int v : depos){
            if(n == v){
                dp.put(n,1);
                return;
            }else if(n > v){
                ans.add(dp.get(n-v) + 1);
            }
        }
        int result = ans.stream().min((a, b) -> a.compareTo(b)).get();
        dp.put(n,result);
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int v = sc.nextInt();

        // 引出可能金額準備
        depos.add(1);
        int d = 6;
        while(d <= 100000){
            depos.add(d);
            d = d * 6;
        }
        d = 9;
        while(d <= 100000){
            depos.add(d);
            d = d * 9;
        }
        // dp準備
        for(int i = 1; i <= 100000; i++){
            doDepo(i);
        }
        // 回答
        System.out.println(dp.get(v));
    }
}

Measured memory_bytes: 56864
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int main(){
  int cnt = 0;
  string w, t;
  cin >> w;
  while (cin >> t){
    if (t == "END_OF_TEXT"){
      break;
    }
    for (int i = 0; i < t.size(); i++){
      if ('A' <= t[i] && t[i] <= 'Z'){
	t[i] += 32;
      }
    }
    if(t == w){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3176
// Aizu 2273: Shiritori
// 2017.9.22 bal4u@uu

#include <stdio.h>

char str[10];
int f[128];

int main()
{
	int  z;
	char q[5] = "aabz";

	z = 0;
	for (q[1] = 'a'; q[1] <= 'z'; q[1]++) for (q[2] = 'a'; q[2] <= 'z'; q[2]++) {
		printf("?%s\n", q);	fflush(stdout);	scanf("%s", str);
		if (*str != 'z') goto Done;
		if (str[1] == 0) { if (z) goto Done; else z = 1; *q = str[0]; }
		else             { if (f[str[1]]) goto Done; else f[str[1]] = 1; *q = str[1]; }
	}
Done:
	puts("!OUT");
	return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int a, b;
    cin >> a >> b;
    if(a+b==3){
        cout << 3 << endl;
    }
    else if(a+b==4){
        cout << 2 << endl;
    }
    else cout << 1 << endl;
}

Measured memory_bytes: 3568
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

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

#define INF 100000000
#define EPS 1e-9

#define MAX_W 50
#define MAX_H 50

int W, H;

vector<P> ans_list;

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, -1, 0, 1 };
bool black = false, white = false;
char maze_map[MAX_H][MAX_W];

int solve(int sx, int sy, bool maze[][MAX_W]){

	
	maze[sy][sx] = true;

	int ans = 1;

	for (int i = 0; i < 4; i++){
		int nx = sx + dx[i];
		int ny = sy + dy[i];
		if (nx >= 0 && nx < W && ny >= 0 && ny < H){
			if (maze_map[ny][nx] == 'W')
				white = true;
			else if (maze_map[ny][nx] == 'B')
				black = true;
			else if(!maze[ny][nx]){
				ans += solve(nx, ny, maze);
			}
		}

	}

	return ans;

}

int main(){

	while (true){
	
		cin >> W >> H;
		if (W == 0 && H == 0)
			break;

		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cin >> maze_map[i][j];
			}
		}

		int white_ans = 0;
		int black_ans = 0;
		bool maze[MAX_H][MAX_W];

		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				maze[i][j] = false;
			}
		}

		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				black = false, white = false;
				if (!maze[i][j] && maze_map[i][j] == '.'){
					int tmp = solve(j, i, maze);
					if (white && black)
						continue;
					else if (white)
						white_ans += tmp;
					else if (black)
						black_ans += tmp;
				}
			}
		}

		ans_list.push_back(P(black_ans, white_ans));
	
	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i].first << " " << ans_list[i].second << endl;
	}

	return 0;

}

Measured memory_bytes: 1316
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n, m;
	lint k;
	cin>>n>>m>>k;
	vector<lint> a(n+1), b(m+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=m;i++){
		cin>>b[i];
	}
	lint tot = 0;
	int i, j;
	for(i=1;i<=n;i++){
		assert(i <= n);
		if((tot + a[i]) <= k)tot += a[i];
		else{
			i--; break;
		}
	}
	if(i == n+1)i--;
	j=0;
	int ans = i+j;
	while(j<m){
		j++;
		assert(j <= m);
		tot += b[j];
		while(tot > k && i>=1){
			tot -= a[i];
			i--;
		}
		if(tot <= k){
		 	cerr<<i<<" "<<j<<" = "<<tot<<"\n";
		 ans = max(ans, i+j);
		 }
	}
	cout<<ans<<"\n";
	return 0;	
}


Measured memory_bytes: 8604
import std.functional,
       std.algorithm,
       std.container,
       std.typetuple,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

bool chmax(t)(ref t a, t b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}

double con(double w, double s) {
  return 100 * s / (w + s);
}

void main() {
  double[] ABCDEF = readln.chomp.split.to!(double[]);
  double A = ABCDEF[0],
         B = ABCDEF[1],
         C = ABCDEF[2],
         D = ABCDEF[3],
         E = ABCDEF[4],
         F = ABCDEF[5];

  bool ok(double w, double s) {
    double base = E / 100;
    double p = s / w;

    return base >= p;
  }

  double[] W, S;

  double max = -1;
  int ans1, ans2;

  for (int i; i <= F / 100*A; i++) {
    for (int j; j <= F / 100*B; j++) {
      double w1 = 100 * A * i,
             w2 = 100 * B * j;
      if (w1 + w2 <= F) {
        W ~= w1 + w2;
      }
    }
  }

  for (int i; i <= F / C; i++) {
    for (int j; j <= F / D; j++) {
      double s1 = C * i,
             s2 = D * j;
      if (s1 + s2 <= F) {
        S ~= s1 + s2;
      }
    }
  }

  foreach (w, s; cartesianProduct(W, S)) {
    if (ok(w, s) && w + s <= F) {
      if(chmax(max, con(w, s))) {
        ans1 = (w + s).to!int;
        ans2 = s.to!int;
      }
    }
  }

  writefln("%d %d", ans1, ans2);
}


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

const int N = 105;

int A[N], n;

int calc(int x) {
	return x / 2;
}

int main(void) {
	cin >> n;
	int len = 0;
	int ans = 0;
	for(int i = 1; i <= n; ++ i) {
		cin >> A[i];
		if(A[i] == A[i - 1]) {
			++ len;
		}
		else ans += calc(len), len = 1;
	}
	cout << ans + calc(len);
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <cstdlib>
#include<string>
using namespace std;
int main(){
  int n[3];
  int t;
  for (int i=0;i<3;i++){
    cin >> n[i];
  }
  for (int j=1;j<3;j++){
    if(n[0]>n[j]){
      t=n[0]; n[0]=n[j]; n[j]=t;
    }
  }
  if(n[1]>n[2]){
    t=n[1]; n[1]=n[2]; n[2]=t;
  }
  cout << n[0] << " " << n[1] << " " << n[2] << endl ;
  

}


Measured memory_bytes: 3084
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      ps: [usize; n],
    }
    let mut ans = 0;
    let mut cnt = 0;
    for i in 0..n {
        if i+1 == ps[i] {
            cnt += 1;
        } else {
            if cnt > 0 {
                ans += (cnt+1)/2;
                cnt = 0;
            }
        }
    }
    if cnt > 0 {
        ans += (cnt+1)/2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
	int a,b,c,d,val=0;
		cin>>a>>b>>c>>d;
		if(abs(a-c)<=d)
			val=1;
		else if(abs(a-b)<=d && abs(b-c)<=d)
			val=1;
		if(val==1)
			cout<<"Yes";
		else
			cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
/**
 *   author: bholuakku
**/

#include <bits/stdc++.h>
#define For(i,a,b) for(i=(a); i<(b); i++)
#define rep(i,n) for(i=0; i<(n); i++)
#define Nfor(i,a,b) for(i=(a)-1; i>=(b); i--)
#define dep(i,n) for(i=(n-1);i>=0; i--)
#define mp make_pair
#define pb push_back
#define Auto(a) for(auto &val : a)
#define X first
#define Y second
#define MOD 1000000007
#define MOD1 998244353
#define iterate(A, i) for(auto i = A.begin(); i!=A.end(); i++)
#define mset(A,val,n) memset(A, val, n*sizeof(int))
#define Endl cout<<"\n"
#define Test cout<<"Hello\n"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<bool> vb;
typedef vector<vector<bool> > vvb;
typedef pair<int, int> pii;
typedef vector<vector<pair<int, int> > > vvp;

int power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y>0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x)%p;} return res;}
int modInverse(ll n) {ll p = MOD;return power(n, p-2, p);}
int min(int a, int b, int c) { return min(a, min(b, c)); }
int max(int a, int b, int c) { return max(a, max(b, c)); }
inline void swap(int &a, int &b) { int t = a; a = b; b = t;}
bool cmp(int a, int b){return a>b;}
vi ans;
vvi g;
void dfs(int v){
    if(ans[v]!=-1) return;
    if(g[v].size()==0){
        ans[v] = 0;
        return;
    }
    int i;
    rep(i, g[v].size()){
        dfs(g[v][i]);
        ans[v] = max(ans[v], ans[g[v][i]]+1);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, i, j;
    cin>>n>>m;
    g.resize(n+1);
    while(m--){
        cin>>i>>j;
        g[i].pb(j);
    }
    ans.resize(n+1, -1);
    rep(i, n) dfs(i+1);
    j = -1;
    rep(i, n) j = max(j, ans[i+1]);
    cout<<j;
    return 0;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define INF 2e9
using namespace std;
const int N=1e6+1;
const int mod=1e9+7;
ll fastexp(ll base,ll exp){
	base%=mod;
	ll ans=1;
	while(exp>0){
		if(exp&1){
			ans*=base;
			ans%=mod;
		}
		base*=base;
		base%=mod;
		exp/=2;
	}
	return ans;
}
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}
int cnt[N];
int arr[N];
int main() {
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		sum += arr[i];
		cnt[arr[i]]++;

	}
	int k;
	cin >> k;
	while (k--){
		int f,l;
		cin >> f >> l;
		ll sumadd = 0;
		cnt[l]+=cnt[f];
		sumadd = cnt[f];
		sumadd *= (l-f);
		sum += sumadd;
		cout << sum << endl;
		cnt[f] = 0;
	}
	return 0;
}
   






   







Measured memory_bytes: 4392
N, M = gets.split.map(&:to_i)
As = gets.split.map(&:to_i)

as = As.sort.reverse
lb, ub = 2*as.last, 2*as.first
gs = as.each_with_object(Array.new(ub + 1, 0)){|a, ary| ary[a] += 1}
ub.downto(1){|i| gs[i - 1] += gs[i]}
g = ->(x){x > 0 ? gs[x] : N}
d = ub.downto(lb).to_a.bsearch{|x| as.inject(0){|s, a| s + g[x - a]} >= M}
ca = as.inject([0]){|ary, a| ary << ary.last + a}
res, m = 0, M
as.map{|a| [a, g[d - a]]}.reject{|a, n| n.zero?}.each do |a, n|
  res += a*n + ca[n]
  m -= n
end
puts res + d*m

Measured memory_bytes: 17644
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    A.sort()
    ans = N
    t = 0
    for i in range(N)[::-1]:
        if t+A[i] < K:
            t += A[i]
        else:
            ans = min(ans, i)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
    int q=0;char ch=' ';
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
    return q;
}
const int mod=1e9+7,N=100005;
int n,ans;
int a[N],du[N],cir[N],vis[N],footL[N],sum[N],f[N];
int qm(int x) {return x>=mod?x-mod:x;}
void workcir(int x) {
    int now=0,fr=0,ed=0,frL=0;
    //fr:第一个有脚的位置，ed:上一个找到的有脚的位置
    //frL:第一个脚的长度，now:当前节点是从x开始走环走到的第几个点
    while(cir[x]) {
        ++now,cir[x]=0;
        if(footL[x]) {
            if(!fr) ed=fr=now,frL=footL[x];
            else {//塞脚
                int kl=(footL[x]<now-ed)+(footL[x]<=now-ed);
                ans=1LL*ans*kl%mod,ed=now;
            }
        }
        x=a[x];
    }
    if(!fr) ++sum[now];//是简单环
    else {//考虑第一个脚
        int kl=(frL<now-ed+fr)+(frL<=now-ed+fr);
        ans=1LL*ans*kl%mod;
    }
}
void work() {
    for(RI i=1;i<=n;++i) {
        if(du[i]) continue;
        int x=i,len=0;while(!cir[x]) x=a[x],++len;
        footL[x]=len;//算挂在每个点上的脚长
    }
    ans=1;
    for(RI i=1;i<=n;++i) if(cir[i]) workcir(i);
    for(RI i=1;i<=n;++i) {//对每一种长度的简单环做DP
        if(!sum[i]) continue;
        f[0]=1;
        for(RI j=1;j<=sum[i];++j) {
            if(i>1&&(i&1)) f[j]=qm(f[j-1]+f[j-1]);//情况1,2
            else f[j]=f[j-1];//情况1
            if(j>1) f[j]=qm(f[j]+1LL*f[j-2]*(j-1)%mod*i%mod);//情况3
        }
        ans=1LL*ans*f[sum[i]]%mod;
    }
}
int main()
{
    n=read();
    for(RI i=1;i<=n;++i) a[i]=read(),++du[a[i]];
    for(RI i=1;i<=n;++i) {
        if(vis[i]) continue;
        int x=i;while(!vis[x]) vis[x]=i,x=a[x];
        if(vis[x]!=i) continue;//说明i在一个脚上
        while(!cir[x]) cir[x]=1,x=a[x];//给环打上是环标记
    }
    for(RI i=1;i<=n;++i)//判无解
        if((cir[i]&&du[i]>2)||(!cir[i]&&du[i]>1)) {puts("0");return 0;}
    work();
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <fstream>

using namespace std;

int main () {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long n;
    cin >> n;
    b = min(b, 2 * a);
    c = min(c, 2 * b);
    d = min(d, 2 * c);
    cout << d * (n/2) + c * (n % 2) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int N;cin>>N;
    vector<ll> A(N),B(N);
    ll ans=0,tmp=INT_MAX;
    REP(i,N){
        cin>>A[i]>>B[i];
        ans+=B[i];
        if(A[i]>B[i]) tmp=min(tmp,B[i]);
    }
    if(A==B){
        cout<<0<<endl;
        return 0;
    }
    ans-=tmp;
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

int main(void){
    int H,W;
    cin >> H >> W;
    int A[H][W];
    rep(i,H) rep(j,W) cin >> A[i][j];
    int N=0;
    int cnt=0;
    vector<int> res[4];
    for(int i=0;i<H;i++){
        if(i%2==0){
            for(int j=0;j<W;j++){
                cnt++;
                if(cnt==H*W) break;
                int nh=i,nw=j+1;
                if(nw==W) nh++,nw--;
                if(A[i][j]%2){
                    N++;
                    res[0].push_back(i);
                    res[1].push_back(j);
                    res[2].push_back(nh);
                    res[3].push_back(nw);
                    A[nh][nw]++;
                }
            }
        }
        else{
            for(int j=W-1;j>=0;j--){
                cnt++;
                if(cnt==H*W) break;
                int nh=i,nw=j-1;
                if(nw==-1) nh++,nw++;
                if(A[i][j]%2){
                    N++;
                    res[0].push_back(i);
                    res[1].push_back(j);
                    res[2].push_back(nh);
                    res[3].push_back(nw);
                    A[nh][nw]++;
                }
            }
        }
    }
    cout << N << endl;
    rep(i,N){
        rep(j,4) cout << res[j][i]+1 << (j==3?"\n":" ");
    }
}


Measured memory_bytes: 6296
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
module Main (main) where
import Control.Applicative
import Control.Monad
import qualified Data.ByteString as BS
import Data.ByteString.Char8 (readInt)
import qualified Data.IntSet as IS
import Data.Maybe (fromJust)
import qualified Data.Vector.Unboxed as VU



main :: IO ()
main = do
  n <- readLn
  as <- VU.replicateM n $ fst . fromJust . readInt <$> BS.getLine
  --as <- replicateM n $ read <$> getLine
  print $ solve as
{-# INLINE solve #-}
solve :: VU.Vector Int -> Int
solve as = IS.size $ VU.foldl' f IS.empty as
  where
    f s e = case IS.lookupGE e s of
      Just ix | e < ix     -> IS.insert e $ IS.delete ix s
              | otherwise -> s
      Nothing -> IS.insert e s

Measured memory_bytes: 11256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;

}

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

int main(){
  int n;
  cin >>n;
  double a,b,l;
  l=0;
  vector<int> x(n);
  vector<int> y(n);
  //入力
  for (int i=0;i<n;i++){
   cin >> x.at(i)>> y.at(i);
  }
  //全パターン出す
  for (int i=0;i<n;i++){
 	for(int j=0;j<n;j++){
      a=x.at(i)-x.at(j);
      b=y.at(i)-y.at(j);
      l=l+sqrt(a*a+b*b);
    }
  }
    l=l/n;
    cout << fixed << setprecision(10);
    cout << l <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    bool ok = false;
    rep(i,sqrt(n) + 1){
        if(i == 0)continue;
        if(n % i)continue;
        else{
            if(i < 10 && n/i < 10){
                ok = true;
            }
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

int main()
{
  std::string o, e;
  std::cin >> o >> e;

  int size = ceil( ( o.size() + e.size() ) / 2.0 );
  for( int i = 0; i < size; i++ ) {
    if( o[ i ] != 0 ) {
      std::cout << o[ i ];
    }
    if( e[ i ] != 0 ) {
      std::cout << e[ i ];
    }
  }

  std::cout << std::endl;
  return 0;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aeroui
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int T = in.nextInt();

            int[] arr = new int[N + 1];
            long ans = 0;
            for (int i = 1; i <= N; i++) {
                arr[i] = in.nextInt();
                ans = ans + 1l * Math.min(T, arr[i] - arr[i - 1]);
            }

            ans = ans + T;
            out.println(ans);
        }

    }
}



Measured memory_bytes: 65400
#include <algorithm>
#include <iostream>

using namespace std;

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

    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    int ans = 999999999;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (i == j) continue;
            for (int k = 0; k < 3; ++k) {
                if (k == i || k == j) continue;
                ans = min(ans, abs(A[j] - A[i]) + abs(A[k] - A[j]));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<tuple>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

const int MAX=510000;

int main()
{
    int n;
    cin>>n;
    int p[n];

    rep(i,n)
    {
        cin>>p[i];
    }
    int ans=0;
    for(int i=0;i<n-2;i++)
    {
        int a,b,c;
        a=p[i];
        b=p[i+1];
        c=p[i+2];
        if((a<b && b<c)|| (c<b && b<a))ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int H=0,W=0;
for(;;){
cin>>H>>W;
if(H==0 && W==0){
	break;
}
for(int i=1; i<=H; i++){
	for(int j=1; j<=W; j++){
		if(i==1 || i==H || j==W || j==1){
			cout<<"#";
		}else{
			cout<<".";
		}
	}

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


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

int a[int(1e5+5)][3];
int dp[1000005][3];

int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2]; 
    }

    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for(int i=1;i<n;i++)
    {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + a[i][1];
        dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + a[i][2];
    }
    
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;

}


Measured memory_bytes: 4096
import sys
import math
A, B, H, M = map(int, input().split())

mnt = 60 * H + M

arg_A = (mnt % 720) * 0.5
arg_B = (mnt % 60) * 6

#print(arg_A, arg_B)

if arg_A == arg_B:
  print(abs(B-A))
  sys.exit()
elif abs(arg_A-arg_B) == 180:
  print(A+B)
  sys.exit()

big = max(arg_A, arg_B)
small = min(arg_A, arg_B)
w = big - small

if w > 180:
  w = 360 - w

ans = (A**2 + B**2 - 2*A*B*math.cos(math.radians(w))) ** 0.5

print(ans)
  

Measured memory_bytes: 9532
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const int MAXN=200000;
int h,w,a,b,res,jc[MAXN+10]={1},jcny[MAXN+10]={1};
int quickpow(int x,int y)
{
	int res=1;
	while(y)
	{
		if(y&1)res=(ll)res*x%MOD;
		y>>=1;x=(ll)x*x%MOD;
	}
	return res;
}
int ny(int x){return quickpow(x,MOD-2);}
int C(int n,int m){return (ll)jc[n]*jcny[m]%MOD*jcny[n-m]%MOD;}
int calc(int n,int m){return C(n+m,n);}
int main()
{
	for(int i=1;i<=MAXN;++i)jc[i]=(ll)jc[i-1]*i%MOD,jcny[i]=ny(jc[i]);
	scanf("%d%d%d%d",&h,&w,&a,&b);res=calc(h-1,w-1);
	for(int i=1;i<=b;++i)
	{
		res-=(ll)calc(h-a-1,i-1)*calc(a-1,w-i)%MOD;
		if(res<0)res+=MOD;
	}
	printf("%d",res);
	return 0;
}

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


public class Program
{
    private string S;
    private int N;

    public void Solve()
    {
        var sc = new Scanner();
        S = sc.Next();
        N = S.Length + 1;

        var ans = new long[N];

        for (int i = 0; i < S.Length; i++)
        {
            if (S[i] == '<')
            {
                ans[i + 1] = ans[i] + 1;
            }
        }

        for (int i = S.Length - 1; i >= 0; i--)
        {
            if (S[i] == '>')
            {
                ans[i] = Math.Max(ans[i], ans[i + 1] + 1);
            }
        }

        Console.WriteLine(ans.Sum());
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt() => int.Parse(Next());
    public long NextLong() => long.Parse(Next());
    public double NextDouble() => double.Parse(Next());

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray() => ToIntArray(Array());
    public long[] LongArray() => ToLongArray(Array());
    public double[] DoubleArray() => ToDoubleArray(Array());

    #endregion
}

Measured memory_bytes: 16864
icase=0
if icase==0:
    n,m=map(int,input().split())
    a=[]
    for i in range(n):
        xi,yi=map(int,input().split())
        a.append([xi,yi])
    c=[]
    for i in range(m):
        xi,yi=map(int,input().split())
        c.append([xi,yi])
    for i in range(n):
        idsmin=10**9
        ip=51
        for ii in range(m-1,-1,-1):
            ids=abs(a[i][0]-c[ii][0])+abs(a[i][1]-c[ii][1])
#            print(ids,i,ii)
            if ids<=idsmin:
                idsmin=ids
                ip=ii+1
        print(ip)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
const int max_n=1e5 + 7;
ll memo[103][max_n];
int w[105], v[105];
ll dp(int pos,int k){
    if(pos==n) return 0;
    if(memo[pos][k]!=-1) return memo[pos][k];
    memo[pos][k]=dp(pos+1,k);
    if(k>=w[pos]) memo[pos][k]=max(memo[pos][k],v[pos]+ dp(pos+1,k-w[pos]));
    
    return memo[pos][k];
}

int main() {
    cin>>n>>k;
    memset(memo,-1,sizeof(memo));
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    cout<<dp(0,k)<<"\n";
   return 0;
}


Measured memory_bytes: 84076
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n = int(readline())
a = list(map(int, readline().split()))
counter = sorted(list(Counter(a).items()))
if n % 2 == 1:
    if counter[0] != (0, 1):
        print(0)
        exit()
    else:
        memo = 2
        counter.pop(0)
else:
    memo = 1
for k, v in counter:
    if memo != k or v != 2:
        print(0)
        exit()
    memo += 2
mod = 10 ** 9 + 7
print(pow(2, len(counter), mod))


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

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;

  vector<vector<int>> edge(n);

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

    edge[a-1].emplace_back(b-1);
    edge[b-1].emplace_back(a-1);
  }

  vector<int> vs(n, 0);
  queue<int> que;
  que.emplace(0);
  vs[0] = 1;

  while (!que.empty()) {
    int from = que.front(); que.pop();

    for (auto to : edge[from]) {
      if (vs[to]) continue;
      vs[to] = from+1;
      que.emplace(to);
    }
  }

  cout << "Yes" << '\n';
  for (int i = 1; i < n; ++i) cout << vs[i] << '\n';

  return (0);
}


Measured memory_bytes: 10248
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  map<int, int> m;
  multiset<int> s;
  for (int w = 1; w <= W; ++w) {
    m[w] = w;
    s.insert(0);
  }

  int a, b;
  for (int h = 1; h <= H; ++h) {
    cin >> a >> b;
    auto it = m.lower_bound(a);
    int mx = -1;
    while (it != m.end() && it->first <= b + 1) {
      mx = max(mx, it->second);
      int d = it->first - it->second;
      s.erase(s.find(d));
      m.erase(it++);
    }

    if (mx != -1 && b + 1 <= W) {
      s.insert(b+1 - mx);
      m[b+1] = mx;
    }
    if (s.empty()) {
      cout << -1 << '\n';
    } else {
      cout << *s.begin() + h << '\n';
    }
  }
  return 0;
}



Measured memory_bytes: 22336
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! p {
    ($($x:expr),*) => {
        $(println!("{:?}", $x);)*
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
#[allow(unused_imports)]
use std::cmp::*;
trait Each: Iterator{
    fn each<F>(self, mut f: F) where
        Self: Sized, F: FnMut(Self::Item),
    {
        self.fold((), move |(), item| f(item));
    }
}
impl<T:Iterator>Each for T{}

fn main(){
    input!{
        n: i32,
    }
    let ans = ((n+1)/2) as f64/n as f64;
    p!(ans);
}

Measured memory_bytes: 4352
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  string s;
  cin>>s;
  vector<vector<ll> >v;
  vector<ll>vv;
  v.push_back(vv);
  ll j=0;
  ll f=0;
  for(ll i=0;i<(ll)s.size();i++){
    if(s[i]=='A'){
      if(f==1){
        v.push_back(vv);
        j++;
        f=0;
      }
      v[j].push_back(1);
      f=0;
    }
    if(s[i]=='B'){
      if(f==0)f=1;
      else {
        v.push_back(vv);
        j++;
        f=1;
      }
    }
    if(s[i]=='C'){
      if(f==1){
        v[j].push_back(2);
      }
      else {
        v.push_back(vv);
        j++;
      }
      f=0;
    }
  }
  ll ans=0;
  for(ll i=0;i<(ll)v.size();i++){
    ll z=1;
    for(ll jj=0;jj<(ll)v[i].size();jj++){
      if(v[i][jj]==1){
        ans+=((ll)v[i].size()-z-jj);
        z++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 8816
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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 ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    vvll dp(s.size()+1, vll(t.size()+1, 0));
    REP(i, s.size()) REP(j, t.size()) {
        if (s[i] == t[j]) dp[i+1][j+1] = dp[i][j]+1;
        else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }

    V<char> ans;
    ll si=s.size()-1, ti=t.size()-1;
    while (si>=0 && ti>=0) {
        if (s[si] == t[ti]) {
            ans.push_back(s[si]);
            si--, ti--;
        } else if (dp[si][ti+1] < dp[si+1][ti]) ti--;
        else si--;
    }

    REP(i, ans.size()) cout << ans[ans.size()-i-1];
    cout << '\n';
    return 0;
}


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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin >> v[i];
    
    cout << count_if(v.begin(), v.end(), [k](int x){return x >= k;});
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
int main(){
	ll n;
	cin>>n;
	ull arr[100005];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	ull b= 1000000000000000000;
	ull hasil = 1;
	sort(arr,arr+n);
	for(int i=0;i<n;i++){
		if(arr[i]==0){
			cout<<0<<endl;
			return 0;
		}
		if(b/arr[i]== 0){
			cout<<-1<<endl;
			return 0;
		}
		b/=arr[i];
		hasil*=arr[i];
	}
	cout<<hasil<<endl;
}

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

int main() {
  int n,m;
  cin >> n >> m;

  vector<int> a(n);
  //vectorに全入力値を代入する
  rep(i,n) cin >> a[i];

  //総投票数を計算する
  int s = 0;
  rep(i,n) s += a[i];

  int cnt = 0;
  rep(i,n) {
    if (a[i]*(4 * m) >= s) cnt++;
  }

  if (cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
//
//  main.c
//  Dirichlet's Theorem on Arithmetic Progressions
//
//  Created by x15071xx on 2016/06/06.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//
//dm+a=n
//n???d??§?????£???a?????????&&?´???°?????°
#include <stdio.h>

#define NUM 1000000

int main(int argc, const char * argv[]) {
    
    int a,d,n,i,j;
    int hurui[NUM] = {0},count_n = 0;
    
    for (i=0; i<=NUM; i++) {
        hurui[i]=1;
    }
    hurui[1]=0;
    
    for (i=2; i<=NUM; i++) {
        if (hurui[i] == 1) {
            for(j = 2 * i; j <= NUM; j += i)
                hurui[j] = 0;
            
        }
    }
    
    while (1) {
        
        scanf("%d %d %d",&a,&d,&n);
        
        if(a==0&&d==0&&n==0){
            break;
        }
        
        for (i = a; i < NUM; i+=d) {
            if (hurui[i] == 1) {
                count_n++;
                if (count_n==n) {
                    printf("%d\n",i);
                    break;
                }
            }
        }
        count_n=0;
        
    }
    return 0;
}

Measured memory_bytes: 4516
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s;
    int sum;
    while (!(s = sc.next()).equals("0")){
      sum = 0;
      for(int i = 0;i < s.length();i++){
        sum += Integer.parseInt(String.valueOf(s.charAt(i)));
      }
      System.out.println(sum);
    }
  }
}



Measured memory_bytes: 26520
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Control.Monad ( replicateM )
import qualified Data.List as L ( sort )


getParm :: IO [Int]
getParm = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,_] <- getParm
  ss    <- replicateM n C.getLine
  C.putStrLn $ minimumCombination ss 

minimumCombination 
 :: [C.ByteString] -> C.ByteString
minimumCombination = C.concat . L.sort

Measured memory_bytes: 508
package main

import (
	"math/rand"
	"time"
	"os"
	"bufio"
	"fmt"
	"strconv"
	"strings"
)

var(
	sc = bufio.NewScanner(os.Stdin)
)

func init()  {
	rand.Seed(time.Now().UnixNano())
	buf := make([]byte, 0) //ここのサイズは何でもよさそう
	sc.Buffer(buf, 1000000009)
}


//||||||||||||||||||||||||||入力|||||||||||||||||||||||||||||||||||||||\
//数字一文字入力
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

//文字列を一行入力
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

//空白区切りの文字列の入力
func spaceLine() []string {
	sc.Scan()
	return strings.Split(sc.Text()," ")
}

//数字を一行入力
func intLine() []int {
	str := spaceLine()
	buf := make([]int,len(str))
	for i,s:=range str{
		buf[i],_ = strconv.Atoi(s)
	}
	return buf
}

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

//ソートする
//sは最初のインデックス fは最後のインデックス
func Sort(ls []float64,l int,r int)  {
	if r - l <= 0{return}
	pipot := l + rand.Intn(r-l+1)
	ls[r],ls[pipot] = ls[pipot],ls[r]
	i := l
	for j:=l;j<r;j++{
		if ls[j] < ls[r]{
			ls[i],ls[j] = ls[j],ls[i]
			i ++
		}
	}
	ls[i],ls[r] = ls[r],ls[i]
	Sort(ls,l,i-1)
	Sort(ls,i+1,r)
}

//配列の大小を指定した要素で比較
//a < bならtrue
func sizeCheck(a []float64,b []float64,ls []int) bool {
	for i:= range ls{
		if a[i] < b[i]{
			return true
		} else if a[i] > b[i] {
			return false
		}
	}
	return false
}

//二次元配列のソート
func Sort2D(ls [][]float64,l int,r int,index []int)  {
	if r - l <= 0{return}
	pipot := l + rand.Intn(r-l+1)
	ls[r],ls[pipot] = ls[pipot],ls[r]
	i := l
	for j:=l;j<r;j++{
		if sizeCheck(ls[j],ls[r],index){
			ls[i],ls[j] = ls[j],ls[i]
			i ++
		}
	}
	ls[i],ls[r] = ls[r],ls[i]
	Sort2D(ls,l,i-1,index)
	Sort2D(ls,i+1,r,index)
}

func main() {
	n := nextInt()
	a := intLine()
	x := 0
	for i:=0;i<n;i++{
		if i % 2 == 0{
			x += a[i]
		} else {
			x -= a[i]
		}
	}
	x /= 2
	fmt.Print(x*2," ")
	for i:=0;i<n-1;i++{
		x = a[i] - x
		if i == n-2{
			fmt.Println(x*2)
			break
		}
		fmt.Print(x*2," ")
	}
}

Measured memory_bytes: 8960
#include <iostream>

 

using namespace std;

 

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


Measured memory_bytes: 3116