akhauriyash/Code-Regression huggingface dataset:
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int y, m, d;

    for(;sc.hasNext();){
      y = sc.nextInt(); m = sc.nextInt(); d = sc.nextInt();

      if(y < 1868)out.println("pre-meiji");
      else if(y == 1868 && m < 9)out.println("pre-meiji");
      else if(y == 1868 && m == 9 && d < 8)out.println("pre-meiji");
      else if(y < 1912)out.printf("meiji %d %d %d%n", y - 1867, m, d);
      else if(y == 1912 && m < 7)
        out.printf("meiji %d %d %d%n", y - 1867, m, d);
      else if(y == 1912 && m == 7 && d < 30)
        out.printf("meiji %d %d %d%n", y - 1867, m, d);
      else if(y < 1926)out.printf("taisho %d %d %d%n", y - 1911, m, d);
      else if(y == 1926 && m < 12)
        out.printf("taisho %d %d %d%n", y - 1911, m, d);
      else if(y == 1926 && m == 12 && d < 25)
        out.printf("taisho %d %d %d%n", y - 1911, m, d);
      else if(y < 1989)out.printf("showa %d %d %d%n", y - 1925, m, d);
      else if(y == 1989 && m < 1)
        out.printf("showa %d %d %d%n", y - 1925, m, d);
      else if(y == 1989 && m == 1 && d < 8)
        out.printf("showa %d %d %d%n", y - 1925, m, d);
      else out.printf("heisei %d %d %d%n", y - 1988, m, d);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 17232
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n: i32 = read();
    let values: Vec<i32> = (0..n).map(|_| read()).collect();
    let len: usize = values.len();
    let mut ans: i32 = 0;
    
    for i in 0..len - 1 {
        let fs = values[i];
        let sl = &values[i + 1..];
        for value in sl {
            ans += fs * value;
        }
    }

    println!("{}", ans);
}



Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=list(map(float,sys.stdin.readline().rstrip().split()))

dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0]=1
for i in range(n):
    for j in range(0,i+1):
        dp[i+1][j+1] += dp[i][j]*arr[i]
        dp[i+1][j] += dp[i][j] * (1-arr[i])

ans = 0
for i in range(n//2 +1,n+1):
    ans += dp[n][i]
print(ans)


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

#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define per(i,n) for (int i=(int)(n)-1;i>=0;i--)
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define Rep(i,n) for (int i=0;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define cmax(x,y) x=max(x,y)
#define cmin(x,y) x=min(x,y)
#define pii pair<int,int>
#define vi vector <int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=1e5+3;
const int MOD=1e9+7;

int n;
int f[MAXN][2];
vi g[MAXN];

int dfs(int x,bool f,int frm){
	if (::f[x][f]) re ::f[x][f];
	ll ret=1;
	if (!f){
		for (int &i:g[x]){
			if (i==frm) continue;
			ret*=(dfs(i,0,x)+dfs(i,1,x));
			ret%=MOD;
		}
	}else{
		for (int &i:g[x]){
			if (i==frm) continue;
			ret*=dfs(i,0,x);
			ret%=MOD;
		}
	}
	re ::f[x][f]=ret%MOD;
}

int main(){
	int x,y;
	cin>>n;
	rep(i,n-1){
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	cout<<(dfs(1,1,-1)+dfs(1,0,-1))%MOD<<endl;
	re 0;
}

Measured memory_bytes: 13440
#include<bits/stdc++.h>
using namespace std;
#define P pair<int,int>

int main() {
  queue<P> que;
  int H, W;
  long long INF = 1000000000, x, y;
  cin >> H >> W;
  char a[H][W];
  int S[H][W], dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> a[i][j];
      S[i][j] = INF;
      if(a[i][j] == '#') {
        S[i][j] = 0;
        que.push({i, j});
      }
    }
  }
  while(!que.empty()) {
    P p = que.front();
    que.pop();
    x = p.first; y = p.second;
    for(int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= H || ny < 0 || ny >= W)continue;
      if (S[nx][ny] == INF) {
		S[nx][ny] = S[x][y] + 1;
		que.push({ nx,ny });
      }
    }
  }
  int ans = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      ans = max(ans, S[i][j]);
    }
  }
  cout << ans;
}


Measured memory_bytes: 13328
#include <stdio.h>
int main (){
int a,b,c=0,d=0,i;
scanf ("%d%d",&a,&b);
for (i=0;i<a;i++){
scanf ("%d",&d);
if (d<b-d){
  c=c+d;
}
else{
  c=c+b-d;
}
}
printf ("%d",c*2);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


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

	ll n, m, t; scanf("%lld %lld %lld", &n, &m, &t);
	vector<ll> a(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	ll cur = 0;
	ll res = 0;
	for (int i = 0; i < n; i++) {
		res += max(0LL, a[i] - m - cur);
		cur = a[i] + m;
	}
	res += max(0LL, t - cur);
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
using ll = __int128;
lli w[100005], d[100005];

lli n, k;
ll calc(ll x)
{
    ll sum = 0;
    rep(i, n)
    {
        if (w[i] > x) {
            continue;
        } else {
            sum += (x - (ll)w[i]) / (ll)d[i] + 1;
        }
    }
    return sum;
}
int main()
{
    cin >> n >> k;
    rep(i, n)
    {
        cin >> w[i] >> d[i];
    }
    ll up = 1000000000000000000000000000000;
    ll low = 0;
    while (up - low > 1) {
        ll mid = (up + low) >> 1;
        if (calc(mid) >= k) {
            up = mid;
        } else {
            low = mid;
        }
    }
    cout << (lli)up << endl;
}


Measured memory_bytes: 1792
N = int(input())
results = [input() for _ in range(N)]

C = [0] * 4
dic = ['AC', 'WA', 'TLE', 'RE']

for result in results:
    for i in range(4):
        if result == dic[i]:
            C[i] += 1
            break

for j in range(4):
    print(dic[j] + ' x ' + str(C[j]))

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

int main()
{
int x=0,max=0;
int n,i;
char ch[101];
cin>>n;
cin>>ch;
for(i=0;i<n;i++)
{
if(ch[i]=='I')
{
x++;
if(max<x)
max=x;
}
else
x--;
}
cout<<max;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 800000000
#define MAX 1000

int main(){
  int N,A;
  cin>>N>>A;
  vector<int> x(N);
  vector<int> plus,minus;
  ll zero=0;
  for(int i=0;i<N;i++){
    cin>>x.at(i);
    x.at(i)-=A;
    if(x.at(i)>0){
      plus.push_back(x.at(i));
    }else if(x.at(i)<0){
      minus.push_back(-x.at(i));
    }else{
      zero++;
    }
  }
  sort(plus.begin(),plus.end());
  sort(minus.begin(),minus.end());

  vector<ll> dp1(5001,-1),dp2(5001,-1);
  dp1.at(0)=1;dp2.at(0)=1;
  for(int i=0;i<plus.size();i++){
    for(int j=5000;j>=0;j--){
      if(j-plus.at(i)<0){
        break;
      }
      if(dp1.at(j-plus.at(i))!=-1){
        if(dp1.at(j)==-1){
          dp1.at(j)=dp1.at(j-plus.at(i));
        }else{
          dp1.at(j)+=dp1.at(j-plus.at(i));
        }
      }
    }
  }
  for(int i=0;i<minus.size();i++){
    for(int j=5000;j>=0;j--){
      if(j-minus.at(i)<0){
        break;
      }
      if(dp2.at(j-minus.at(i))!=-1){
        if(dp2.at(j)==-1){
          dp2.at(j)=dp2.at(j-minus.at(i));
        }else{
          dp2.at(j)+=dp2.at(j-minus.at(i));
        }
      }
    }
  }
  ll sum=0;
  for(int i=1;i<5000;i++){
    sum+=max<ll>(dp1.at(i),0)*max<ll>(dp2.at(i),0);
  }
  if(zero==0){
    cout<<sum<<endl;
  }else{
    cout<<(1ull<<zero)*(sum+1)-1<<endl;
  }

}


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

int x[10000000];
int p, q, n;

int main() {
	for (int i = 0; i < 4000; i++) {
		for (int j = 0; j*j < 10000000 - i*i; j++) {
			x[i*i + j*j]++;
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		int sum = 0;
		cin >> p >> q;
		int r = p*p + q*q;
		for (int i = 1; i <= r; i++) {
			if (r%i == 0) {
				sum += x[i] * x[r / i];
			}
		}
		if (sum == 8) { cout << 'P' << endl; }
		else { cout << 'C' << endl; }
	}
	return 0;
}

Measured memory_bytes: 40212
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

import math

def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

n = ni()
ans = [0]*n

for i in range(n):
    for j in range(1,55556):
        if j % 5 == 1 and is_prime(j) == True and not j in ans:
           ans[i] = j
           break
for i in ans:
    print(i, end=" ")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B==C+D) {
    cout << "Balanced" << endl;
  } else if(A+B<C+D) {
    cout << "Right" << endl;
  } else {
    cout << "Left" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(float,input().split()))
dp = [[0] * (N+2) for _ in range(N+1)]
dp[0][0] = 1


for omote in range(N+1):
    for i in range(N):
        dp[i+1][omote] += dp[i][omote] * (1 - P[i])
        dp[i+1][omote+1] += dp[i][omote] * P[i] 

ans = 0
for omote in range(N+1):
    ans += dp[N][omote] if omote > N - omote else 0
print(ans)

Measured memory_bytes: 206472
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 100000

typedef struct {
  char name[10];
  int t;
} process;
int head=0, tail=0;
process queue[M+1];

void put(process p){
  queue[tail++]=p;
  tail%=M;
}

process get(void){
  head %= M;
  return queue[head++];
}

int empty(){
  return head%M==tail;
}

int main(void){
  int i, n, q, t, total=0;
  char *name;
  scanf("%d %d", &n, &q);
  process p[n];
  name=malloc(sizeof(char));
  for(i=0; i<n; i++){
    scanf("%s %d", p[i].name, &p[i].t);
    put(p[i]);
  }
  while(!empty()){
    process p=get();
    if((p.t-q)<=0){
      total+=p.t;
      printf("%s %d\n", p.name, total);
    }else{
      total+=q;
      p.t-=q;
      put(p);
    }
  }
}

Measured memory_bytes: 4108
class csr:
    def __init__(self,N,edges):
        self.start = [0]*(N+1)
        self.elist = [0]*len(edges)
        for e in edges:
            self.start[e[0]+1] += 1
        for i in range(1,N+1):
            self.start[i] += self.start[i-1] 
        counter = self.start[:]
        for e in edges:
            self.elist[counter[e[0]]] = e[1]
            counter[e[0]] += 1

class scc_graph:
    #__slots__ = ['N','edges']
    def __init__(self,N):
        self.N = N
        self.edges = []
    
    def add_edge(self,v,w):
        self.edges.append((v,w))

    def scc_ids(self):
        N = self.N
        g = csr(N,self.edges)
        now_ord = group_num = 0
        visited = []
        low = [0]*N
        order = [-1]*N
        ids = [0]*N
        parent = [-1]*N
        stack = []
        for i in range(N):
            if order[i] == -1:
                stack.append(i);stack.append(i)
                while stack:
                    v = stack.pop()
                    if order[v] == -1:
                        low[v] = order[v] = now_ord
                        now_ord += 1
                        visited.append(v)
                        for j in range(g.start[v],g.start[v+1]):
                            to = g.elist[j]
                            if order[to] == -1:
                                stack.append(to);stack.append(to)
                                parent[to] = v
                            else:
                                low[v] = min(low[v],order[to])
                    else:
                        if low[v] == order[v]:
                            while True:
                                u = visited.pop()
                                order[u] = N
                                ids[u] = group_num
                                if u == v:
                                    break
                            group_num += 1
                        if parent[v] != -1:
                            low[parent[v]] = min(low[parent[v]],low[v])
        for i,x in enumerate(ids):
            ids[i] = group_num-1-x

        return group_num,ids
    
    def scc(self):
        group_num,ids = self.scc_ids()
        groups = [[] for _ in range(group_num)]
        for i,x in enumerate(ids):
            groups[x].append(i)
        return groups
    
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N,M = map(int,readline().split())
ab = list(map(int,read().split()))
sg = scc_graph(N)

it = iter(ab)
for a,b in zip(it,it):
    sg.add_edge(a,b)

scc = sg.scc()
print(len(scc))
for group in scc:
    print(str(len(group))+' '+' '.join(map(str,group)))

Measured memory_bytes: 212784
//tree walk

#include<stdio.h>
#define N 10000

struct Node
{
  int p,l,r;
};

struct Node tree[N];
int n;

void pre(int x)
{
  if(x == -1) return;
  printf(" %d",x);
  pre(tree[x].l);
  pre(tree[x].r);
}

void in(int x)
{
  if(x == -1) return;
  in(tree[x].l);
  printf(" %d",x);
  in(tree[x].r);
}

void post(int x)
{
  if(x == -1) return;
  post(tree[x].l);
  post(tree[x].r);
  printf(" %d",x);
}

int main()
{
  int i,pa,le,ri,root;
  
  //input & initialize number
  scanf("%d",&n);
  for(i = 0; i < n; i++) tree[i].p = -1;

  for(i = 0; i < n; i++)
    {
      scanf("%d %d %d",&pa,&le,&ri);
      tree[pa].l = le;
      tree[pa].r = ri;
      if(le != -1) tree[le].p = pa;
      if(ri != -1) tree[ri].p = pa;
    }

  for(i = 0;i < n; i++)
    {
      if(tree[i].p == -1) root = i;
    }

  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2132
#b.py
n,l = map(int,input().split())
if l < 0 and n > abs(l):
    print(int((n+2*l-1)*n/2))
else:
    if l < 0:
        print(int((n+2*l-1)*n/2 -l-n+1))
    else:
        print(int((n+2*l-1)*n/2 -l))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

#define DBG(x) cerr << #x << ": " << x << endl
using namespace std;

int solve(const vector<int> As,int K) {
  //int q = min_element(As.begin(), As.end()) - As.begin();
  int N = As.size();

  int a = (N+K-3)/(K-1);
  
  return a;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> As(N);
  for (int i=0; i<N; i++)
    cin >> As[i];

  cout << solve(As, K) << endl;
}


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

int main(){
  ll n, max=-1000000, min=1000000, sum=0;
  cin >> n;
  rep(i, n){
    int a;
    cin >> a;
    sum+=a;
    if(a>max){
      max=a;
    }
    if(a<min){
      min=a;
    }
  }

  cout << min << " " << max << " " << sum << endl;

  return 0;
}


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> coef(M);
  vector<vector<int>> vec(N, vector<int>(M));
  for (int i = 0; i < M; i++) {
    cin >> coef[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> vec[i][j];
    }
  }
  int clear = 0;
  for (int i = 0; i < N; i++) {
    int sum = C;
    for (int j = 0; j < M; j++) {
      sum += coef[j] * vec[i][j];
    }
    if (sum > 0) {
      clear++;
    }
  }
  cout << clear << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<cctype>


using namespace std;

int main(){
	string a;
int b=0;
	cin>>a;
	b=a.size();
	
	if(b==2){
	cout<<a[0]<<a[1]<<endl;
	}else{cout<<a[2]<<a[1]<<a[0]<<endl;}
	
	

	
	return 0;
}




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

using namespace std;

const int dx[] = {1, 0};
const int dy[] = {0, 1};

vector<string> board(80);
string memo[80][80];
int W, H;

inline bool isDigit(int x, int y)
{
    if ('0' <= board[y][x] && board[y][x] <= '9')
        return true;
    else
        return false;
}

string Rec(int x, int y)
{
    if (memo[y][x].size() != 0)
        return memo[y][x];

    string s, tmp;
    for (int d = 0; d < 2; ++d) {
        int nx = x + dx[d];
        int ny = y + dy[d];

        if (nx < 0 || nx >= W || ny < 0 || ny >= H || !isDigit(nx, ny))
            continue;

        tmp = Rec(nx, ny);
        if (tmp.size() > s.size() || (tmp.size() == s.size() && tmp > s))
            s = tmp;
    }

    return memo[y][x] = board[y][x] + s;
}

int main()
{
    while (cin >> W >> H, W || H) {
        // Input
        for (int i = 0; i < H; ++i)
            cin >> board[i];

        // Init
        for (int i = 0; i < H; ++i)
            for (int j = 0; j < W; ++j)
                memo[i][j] = "";

        // Solve
        string tmp, ans;
        for (int i = 0; i < H; ++i)
            for (int j = 0; j < W; ++j)
                if (isDigit(j, i)) {
                    tmp = Rec(j, i);
                    int index = 0;
                    while (tmp[index] == '0')
                        index++;
                    tmp = tmp.substr(index);

                    if (tmp.size() > ans.size() || (tmp.size() == ans.size() && tmp > ans))
                        ans = tmp;
                }

        // Output
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1396
n, c = map(int, input().split(" "))

time = list()
for i in range(0, n):
    s, t, c = map(int, input().split(" "))
    time.append((s, t, c))

time_sorted = sorted(time, key=lambda x: (x[2], x[1]))

time_joined = list()
prev = None
for current in time_sorted:
    if prev is None:
        prev = current

    elif prev[2] == current[2] and prev[1] == current[0]:
        prev = (prev[0], current[1], current[2])

    else:
        time_joined.append(prev)
        prev = current

time_joined.append(prev)
# print(time_joined)

time_list = list()
for s, t, c in time_joined:
    time_list.append((s - 0.5, "s"))
    time_list.append((t, "t"))

time_list_sorted = sorted(time_list, key=lambda x: x[0])

current = 0
ans = 0

for t, s in time_list_sorted:
    if s == "s":
        current += 1
        ans = max(ans, current)
    else:
        current -= 1

print(ans)


Measured memory_bytes: 41596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
const long long INF = 1LL << 60;
struct Edge
{
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

int main()
{
    ll n;
    cin >> n;
    Graph G(n);
    rep(i, n - 1)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }

    vector<int> ans(n, -1);
    ans[0] = 0;
    queue<int> que;
    que.push(0);
    //BFSで実装
    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (auto e : G[v])
        {
            if (ans[e.to] != -1)
                continue;

            if (e.weight % 2 == 0)
                ans[e.to] = ans[v];
            else if (ans[v] == 0)
                ans[e.to] = 1;
            else if (ans[v] == 1)
                ans[e.to] = 0;

            que.push(e.to);
        }
    }

    rep(i, n) cout << ans[i] << endl;
}

Measured memory_bytes: 9400
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int C[VMAX+1],n;
void CountingSort(short *A,short *B){
  int j,i;
  for(i=0;i<VMAX;i++) C[i]=0;
  for(i=0;i<n;i++) C[A[i+1]]++;
  for(i=1;i<VMAX;i++) C[i]=C[i]+C[i-1];
  for(i=n;i>=1;i--){
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }
}
int main(){
  unsigned short *A,*B;
  int i,j;

  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=1;i<=n;i++) scanf("%hu",&A[i]);
  CountingSort(A,B);
  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i!=n) printf(" ");
  }
  printf("\n");
  return 0;
}



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

ll N;


int main(){
	cin>>N;
	vector<ll> A(N);

	for(int i=0;i<N;i++)
		A.at(i) = 0;
	for(int i=0;i<N-1;i++){
		ll a;
		cin>>a;
		A.at(a-1) += 1;
	}
	for(int i=0;i<N;i++)
		cout<<A.at(i)<<endl;
	
}

Measured memory_bytes: 4788
#include "bits/stdc++.h"
using namespace std;
long long a , b , c;
long long solve(long long a , long long b , long long c){
    if(a & 1){
        return b * c;
    }
    return 0;
}
int main(){
    cin >> a >> b >> c;
    cout << min(solve(a , b , c) , min(solve(b , c , a) , solve(c , a , b))) << endl;
}

Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline()[:-1]

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
N, S = map(int, input().split())
#L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=998244353

ans=0
dp=[0]*(S+1)
for a in A:
    dp[0]+=1
    for i in reversed(range(a,S+1)):
        dp[i]+=dp[i-a]
        dp[i]%=mod
    ans+=dp[-1]
    ans%=mod
    #print(dp)

print(ans)


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A (N);

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

    int count = 0;
    for (int i = 0; i < N; i++) {
        int a = A[i];
        if (!(a*4*M < total)) {
            count++;
        }
    }

    cout << (count >= M ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define mod (1000000007)
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int h,w;char g[55][55];

bool judge(int x,int y){
    if(x>=0&&x<h&&y>=0&&y<w)return g[x][y]=='#';
    else return 0;
}

void solve() 
{
    cin>>h>>w;REP(i,h)REP(j,w)cin>>g[i][j];
    REP(i,h)REP(j,w){
        bool f=0;
        REP(k,4)if(judge(i+dx[k],j+dy[k]))f=1;
        if(f||g[i][j]=='.')continue;
        cout<<"No"<<endl;
        return;
    }cout<<"Yes"<<endl;
}

int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  4 19:20:51 2020

@author: Kanaru Sato
"""

n,m = list(map(int, input().split()))

if n <= 1:
    ans1 = 0
else:
    ans1 = n*(n-1)/2

if m <= 1:
    ans2 = 0
else:
    ans2 = m*(m-1)/2
    
ans = ans1+ans2
print(int(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <array>
#include <stdlib.h>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define REP(i,a,b) for(i = (a); i < (b); i++)
#define rep(i,n) REP(i,0,n)
#define bitget(a,b) (((a) >> (b)) & 1)

using namespace std;

int i, j, k;

int main() {
	int n;
	int a[100000];
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a,a+n);
	ll int d = 1;
	ll int ans1 = 0, ans2 = 0;
	for (i = n - 2; i > -1; i--) {
		if (a[i] == a[i + 1]) {
			d++;
		}
		else {
			d = 1;
		}
		if (d == 2) {
			if (ans1 == 0) {
				ans1 = a[i];
				d = 0;
			}
			else {
				ans2 = a[i];
				d = -1;
			}
		}
		if (d == -1) {
			break;
		}
	}
	cout << ans1*ans2 << endl;

	return 0;
}

Measured memory_bytes: 640
import sys
from math import sqrt
from collections import Counter, defaultdict

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n, k = MI()
    mod = n % k
    if mod > abs(mod - k):
        print(abs(mod - k))
    else:
        print(mod)

    pass


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
n = int(input())
a = [int(i) for i in input().split()]

humi = 0
tmp = a[0]
for i in range(1,n):
    b = 0
    if a[i] < tmp:
        b = tmp - a[i]
        humi += b
        tmp = a[i] + b
    else:
        tmp = a[i]
print(humi)


Measured memory_bytes: 32192
//============================================================================
// Name        : test.cpp
// Author      : Qihan
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
typedef long long int LLI;
typedef pair<int,int> PII;
const int maxs = (10000 + 10);
int main(){
//	freopen("/home/qihan/Documents/in","r",stdin);
	LLI x,y;
	scanf("%lld",&x);
	LLI cnt = x / 11 * 2;
	y = x % 11;
	if(y > 6)	cnt += 2;
	else if(y <= 6 && y >= 1)	cnt += 1;
	printf("%lld\n",cnt);
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>

int main(void){

    int n, x, min, max;

    scanf("%d", &n);
    scanf("%d", &x);
    min = x;
    scanf("%d", &x);
    max = x - min;
    if(x<min) min=x;
    for(int i=0;i<n-2;i++){
        scanf("%d", &x);
        if(x - min > max) max = x - min;
        if(x < min) min = x;
    }
    printf("%d\n", max);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (s.substr(i, 3) == "ABC") cnt += 1;
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 760
#include<iostream>
#include<vector>
using namespace std;
int main() {
    int N;
    cin >> N;
    long long int m = 0;
    vector<long long int>a(N);
    for (int i = 0; i < N; i++)cin >> a[i];
    for (int i = 1; i < N; i++) {
        if (a[i] < a[i - 1]) {
            m += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    cout << m << endl;
    return 0;
}

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

using namespace std;

int a[111];
int main() {
    int n, m;
    while (cin >> n >> m) {
        for (int i = 0; i < m; ++i) {
            cin >> a[i];
        }
        int ans = 0, last = -1;
        for (int k = 0; k < n; ++k) {
            int mx = 0, id = -1;
            for (int i = 0; i < m; ++i) {
                if (a[i] > mx && i != last) {
                    mx = a[i];
                    id = i;
                }
            }
            if (id != -1) {
                a[id]--;
                last = id;
            } else {
                a[last]--;
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    int k,x;
    cin>>k>>x;
    int f,e;
    f=x-k+1;
    if(f<(-1000000)){
        f=-1000000;
    }
    e=x+k-1;
    if(f>(1000000)){
        e=1000000;
    }
    cout<<f;
    f++;
    for(int i=f;i<=e;i++){
        cout<<" "<<i;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.io.*;

class Main {
    public static void main(String[] args)throws IOException{ 
    	InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader read = new BufferedReader(in);
    	   	                                                 
    	int n = Integer.parseInt(read.readLine());
        int taroP = 0;
        int hanaP = 0;

        for(int N = 0; N < n; N++){
           // String taro = read.readLine();
           // String hana = read.readLine();
        	
        	String line = read.readLine();
        	String [] tarohana = line.split(" ");

                if(tarohana[0].compareTo(tarohana[1]) > 0){
                taroP = taroP + 3;
                }
                else if(tarohana[0].compareTo(tarohana[1]) < 0){
                hanaP = hanaP + 3;
                }
                else if(tarohana[0].compareTo(tarohana[1]) == 0){
                 taroP = taroP + 1;
                 hanaP = hanaP + 1;
                }
        }
        System.out.println(taroP+" "+hanaP);
    }
}

Measured memory_bytes: 25360
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
using int64 = long long;

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

void dfs(vector<int> A, int pre) {
    if (A.size() == n) {
        int sum = 0;
        for (int i=0; i<q; i++)
            if (A[b[i]]-A[a[i]]==c[i]) sum+=d[i];
        ans = max(ans, sum);
        return;
    }

    for (int i=pre; i<=m; i++) {
        A.push_back(i);
        dfs(A, i);
        A.pop_back();
    }
}

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

    for (int i=0; i<q; i++) {
        int aa, bb, cc, dd;
        cin >> aa >> bb >> cc >> dd;
        aa--; bb--;
        a.push_back(aa);
        b.push_back(bb);
        c.push_back(cc);
        d.push_back(dd);
    }

    dfs(vector<int>(), 1);

    cout << ans << endl;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b;
	cin>>a>>b;
	if (a%3==0||b%3==0||(a+b)%3==0){
		cout<<"Possible";
	}
	else {
		cout<<"Impossible";
	}
	return 0;
}

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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n,a,b;
  cin>>n>>a>>b;
  if (a*n < b)
  {
  	cout<<a*n;
  }
  else
  {
  	cout<<b;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,a[N],st[N],b[N],hs[N],tot,head[N],nex[N<<1],to[N<<1],wi[N<<1];
void add(int u,int v,int w){to[++tot]=v;nex[tot]=head[u];head[u]=tot;wi[tot]=w;}
bool vis[N],use[N];
int lowb(int x)
{
    return lower_bound(hs+1,hs+1+n,x)-hs;
}
int uppb(int x)
{
    return upper_bound(hs+1,hs+1+n,x)-hs;
}
bool dfs(int u)
{
    vis[u]=true;
    int x=st[u];
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        if(!vis[v]&&dfs(v))
        {
            x^=1;use[wi[i]]=true;
        }
    }
    return x;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i],&b[i]),hs[i]=a[i];
    sort(hs+1,hs+1+n);
    for(int i=1;i<=n;i++)
        a[i]=lowb(a[i]),st[a[i]]=b[i];
    for(int i=n+1;i>=1;i--)
        st[i]^=st[i-1];
    for(int i=1;i<=n+1;i++)
        if(st[i]==st[i-1])
            b[i]=0;
    else b[i]=1;
    //for(int i=1;i<=n+1;i++)
    //    printf(i==n+1?"%d\n":"%d ",b[i]);
    for(int i=1;i<=m;i++)
    {
        int l,r;scanf("%d%d",&l,&r);
        l=lowb(l);
        r=uppb(r)-1;
        if(l<=r)
            add(l,r+1,i),add(r+1,l,i);
    }
    for(int i=1;i<=n+1;i++)
        if(!vis[i]&&dfs(i))
    {
        printf("-1\n");return 0;
    }
    int ans=0;
    for(int i=1;i<=m;i++)
        if(use[i]) ans++;
    printf("%d\n",ans);
    for(int i=1;i<=m;i++)
    if(use[i])
        printf("%d ",i);
}


Measured memory_bytes: 10880
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,a,b;
cin>>n>>a>>b;
vector<ll> h(n);
ll sum=0;
for(int i=0;i<n;i++){cin>>h[i];sum+=h[i];}
ll l=-1,r=(1<<30);
while(r-l>1){
  ll mid=(l+r)/2;
  ll tmp=a-b;
  ll need=0;
  for(int i=0;i<n;i++){
    if(h[i]-b*mid<=0)continue;
    need+=(h[i]-b*mid+tmp-1)/tmp;
  }
  if(need<=mid)r=mid;
  else l=mid;
}
cout<<r<<endl;
}



Measured memory_bytes: 1024
n = int(input())
s = input()
m = s.count('.')
c = (0, m)
for i in range(n):
    if s[i] == '#':
        c = (c[0]+1, c[1])
    else:
        c = (c[0], max(c[1]-1, 0))
    m = min(c[0] + c[1], m)
print(m)

Measured memory_bytes: 3500
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
s = [0]*(len(a)+1)
for i in range(len(a)):
    s[i+1] = s[i] + a[i]
c = Counter(s)
ans = 0
for v in c.values():
    if v >= 2:
        ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 41672
#include<stdio.h>
int main(void){
    int n,i,j,count;
    count = 1;
    scanf("%d",&n);
    int p[n],a[n];
    for(i=1;i<=n;i++){
    scanf("%d",&p[i]);
    a[i] = i;
}
for(j=1;j<=n;j++){
    if(a[j]==p[j]){
        count++;
    }
}
if(count > n-2){
    printf("YES");
}
else
{
    printf("NO");
}
return 0;
}

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

using namespace std;

int main(void){
    long long N,A,B,C,D,E;
    cin>>N>>A>>B>>C>>D>>E;
    long long ans=0;
    long long time=min({A,B,C,D,E});
    ans=ceil((double)N/(double)time)+4;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    char sa[101], sb[101], sc[101], drop, winner;
    scanf("%s%s%s", sa, sb, sc);
    for(int count=0;; count++){
        if(count==0||drop=='a'){
            winner='A';
            if(sa[0]=='\0') break;
            drop=sa[0];
            strcpy(sa, sa+1);
        }
        else if(drop=='b'){
            winner='B';
            if(sb[0]=='\0') break;
            drop=sb[0];
            strcpy(sb, sb+1);
        }
        else if(drop=='c'){
            winner='C';
            if(sc[0]=='\0') break;
            drop=sc[0];
            strcpy(sc, sc+1);
        }
    }
    printf("%c", winner);
    return 0;
}

Measured memory_bytes: 1640
using System;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        //黒から白に変わるポイントを消すための対処法は次の二通り。

        //最初に黒から白に変わるポイント以降を全部黒にする
        //最後に黒から白に変わるポイント以前を全部白にする

        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();

        if (S == "#" || S == ".")
        {
            Console.WriteLine(0);
            return;
        }
        

        //それより左に何個黒があるかを知る配列。
        int[] arr1 = new int[N + 1];
        //それより左に何個白があるかを知る配列
        int[] arr2 = new int[N + 1];

        int siroNum = 0;
        int kuroNum = 0;
        for (int i = 0; i < N; i++)
        {
            char c = S[i];
            if (c == '#') kuroNum++;
            else if (c == '.') siroNum++;

            arr1[i + 1] = kuroNum;
            arr2[i + 1] = siroNum;
        }

        int ans = int.MaxValue;
        for (int i = 0; i < N + 1; i++)
        {
            //境界前を全部白にして境界後を全部黒にすると仮定するとどれだけ
            int n1 = arr1[i];
            int n2 = arr2[N] - arr2[i];
            ans = Math.Min(ans, n1 + n2);
        }
        

        Console.WriteLine(ans);
    }
}

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

using namespace std;

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

const int N = (int) 1e5 + 100;

vector<int> g[N];
int res;
int k;

int dfs(int v, int p = -1) {
  int h = 0;
  for (int u : g[v]) {
    h = max(h, dfs(u, v) + 1);
  }
  if (v != 0) {
    if (h == k - 1 && p != 0) {
      res++;
      return -1;
    }
  }
  return h;
}

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

  int n;
  cin >> n >> k;
  vector<int> p(n);
  for (int &x : p) {
    cin >> x;
    --x;
  }
  if (p[0] != 0) {
    res++;
    p[0] = 0;
  }
  for (int i = 1; i < n; i++) {
    g[p[i]].push_back(i);
  }
  dfs(0);
  cout << res;
  return 0;
}

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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


#define      TEST    int t ; cin >> t ; while( t -- )

const ll big = 10e7 + 11 ;
const double PI  =3.141592653589793238463;

int  main (  ) {

    FASTIO ;

    double n ;
    cin >> n ;

    double ans = 2 * PI * n ;

    cout << setprecision( 2 ) << fixed << ans ;

    return  0 ;
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = ((res%mod) * (a%mod))%mod;
      a = ((a%mod) * (a%mod))%mod;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("inn.txt","r",stdin);
  freopen("ouut.txt","w",stdout);
  #endif
}
///////////U L R D
int dx[4]={0,-1,1,0};
int dy[4]={1,0,0,-1};


int main() 
{ 
    fast_io
    go();
    int n;cin>>n;
    intt ans=0;
    vi v(n);
    for0(i,n)
    {
      cin>>v[i];
      if((i+1)%2 && v[i]%2)
        ans++;
    }
    cout << ans <<'\n';
}

/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/




















Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  int data[n+1][3];
  data[0][0]=0,data[0][1]=0,data[0][2]=0;
  for(int i=1;i<=n;i++){
  	cin>>data[i][0];
  	cin>>data[i][1];
  	cin>>data[i][2];
  }
  bool repeated = false;
  for(int i=1;i<=n;i++){
  	if(data[i][1]==data[i-1][1]&&data[i][2]==data[i-1][2]){
  		repeated=true;
  	}
  }
  if(repeated){
  	cout<<"No"<<endl;
  	return 0;
  }
  int curX=0,curY=0,curTime=0;
  for(int i=1;i<=n;i++){
  	curTime+=abs(curX-data[i][1])+abs(curY-data[i][2]);
  	if(curTime>data[i][0]||(data[i][0]-data[i-1][0]+abs(curX-data[i][1])+abs(curY-data[i][2]))%2!=0){
  		cout<<"No"<<endl;
  		return 0;
  	}
  	curX=data[i][1],curY=data[i][2];
  }
  cout<<"Yes"<<endl;
}








Measured memory_bytes: 1408
import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
import itertools
import copy

n = int(input())

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

if is_prime(n):
    print(1)
    exit()

if n == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

nums = factorization(n)

ans = 0
cnt = 0
tmp = {}
#print(nums)
for i in range(len(nums)):
    num = nums[i][1]

    for j in range(1,10*8):
        num -= j
        ans += 1
        if (num < j+1):
            if num>0:
                #print(tmp)
                if len(tmp) == 0:
                    tmp[nums[i][0]] = num
                    tmp2 = copy.copy(tmp)
                else:
                    tmp = copy.copy(tmp2)
                    for a in tmp.values():
                        #print(a)
                        if a > 0:
                            a -= 1
                            #ans += 1
                            #print(tmp)
                            if num - 1 > 0:
                                tmp2[nums[i][0]] = num -1
            break

#print(tmp)

tmp = sorted(tmp.items(), key=lambda x:x[1])

print(ans)

Measured memory_bytes: 27224
/**
 *   Author: Praveen Ojha
 *   Created: 14 April 2019
 *   Time: 07:01:49
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define inf 1e18+5
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
	int a,b;
	cin>>a>>b;
	cout<<max(a+(a-1),max(b+(b-1),a+b))<<"\n";
return 0;
}

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

using vi = vector<int>;


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

  vi dp(100010); // dp[i]: i円の買い物ができれば1 できなければ0

  dp[0] = 1;

  for(int i=0; i<=X; i++){
    bool x1 = (i-100 >= 0 && dp[i-100] == 1);
    bool x2 = (i-101 >= 0 && dp[i-101] == 1);
    bool x3 = (i-102 >= 0 && dp[i-102] == 1);
    bool x4 = (i-103 >= 0 && dp[i-103] == 1);
    bool x5 = (i-104 >= 0 && dp[i-104] == 1);
    bool x6 = (i-105 >= 0 && dp[i-105] == 1);

    if(x1 || x2 || x3 || x4 || x5 || x6){
      dp[i] = 1;
    }
  }

  cout << dp[X] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define int int64_t
#define pcnt __builtin_popcount
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define vec vector<int>
#define mat vector<vector<int>> //mat データ名(縦,vec(横));
int64_t INF = 1000000000000000001; //10^18+1
int MOD = 1000000007; //10^9+7
//cout << fixed << setprecision(15); (小数点以下表示)

signed main () {
  int X,Y,A,B,C,ans=0,a;
  cin >> X >> Y >> A >> B >> C;
  vec p,q,r,eat;
  for(int i=0;i<A;i++)cin >> a,p.pb(a);
  for(int i=0;i<B;i++)cin >> a,q.pb(a);
  for(int i=0;i<C;i++)cin >> a,r.pb(a);
  sort(ALL(p));
  sort(ALL(q));
  for(int i=0;i<X;i++)eat.pb(p.at(A-i-1));
  for(int i=0;i<Y;i++)eat.pb(q.at(B-i-1));
  eat.insert(eat.end(),ALL(r));
  sort(ALL(eat));
  for(int i=0;i<X+Y;i++)ans+=eat.at(C+X+Y-i-1);
  cout << ans << endl;
}

Measured memory_bytes: 6768
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int main (){
    int s ;
    cin >> s ;
    vector<ll> dp (s + 1) ;
    dp[0] = 1 ;
    rep(i, s + 1){
        if(i - 3 < 0) continue ;
        else {
            for(int j = i - 3 ; j >= 0 ; j--){
                dp[i] += dp[j] ;
                dp[i] %= mod ;
            }
        }
    }
    cout << dp[s] << endl ; 
}

Measured memory_bytes: 3636
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++)
			arr[i] = input.nextInt();
		for(int i = n-1; i >= 0; i--)
		{
			if(i == 0)
				System.out.println(arr[i]);
			else 
				System.out.print(arr[i] + " ");
		}
	}
}

Measured memory_bytes: 26388