akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 * 1000 + 9;
const int INF = 1e9;
const double EPS = 1e-9;

map<long long, long long> mp;
long long n, p;

long long quickPow(long long a, long long b){
    if(b == 0)
        return 1;

    long long tmp = quickPow(a, b/ 2);
    if(b & 1)
        return tmp * tmp * a;
    return tmp * tmp;
}

void read(){
    cin >> n >> p;
}

void solv(){
    for(long long i = 2; i * i <= p; i++){
        if(p % i == 0){
            while(p % i == 0){
                mp[i]++;
                p /= i;
            }
        }
    }

    if(p > 1)
        mp[p]++;

    long long res = 1;
    for(map<long long, long long>::iterator it = mp.begin(); it != mp.end(); it++){
        res *= quickPow(it->first, it->second / n);
    }

    cout << res << "\n";
}

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

    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif

    read();
    solv();

    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

from collections import deque
import itertools

h,w = map(int,readline().split())
cx,cy = map(int,readline().split())
gx,gy = map(int,readline().split())
cx -= 1
cy -= 1
grid = [readline().rstrip() for i in range(h)]

dist = [[INF]*w for i in range(h)]
dist[cx][cy] = 0

l2 = list(itertools.product([-2,-1,0,1,2],repeat = 2))
l1 = [(-1,0),(1,0),(0,-1),(0,1)]
q1 = deque([(cx,cy)])
q2 = deque([(cx,cy)])

while q1 or q2:
    if q1:
        x,y = q1.popleft()
        for dy,dx in l1:
            ny,nx = y+dy, x+dx
            if not (0 <= ny < w and 0 <= nx < h):
                continue
            if grid[nx][ny] == '#':
                continue
            if dist[nx][ny] > dist[x][y]:
                dist[nx][ny] = dist[x][y]
                q1.append((nx,ny))
                q2.append((nx,ny))
    else:
        x,y = q2.popleft()
        for dy,dx in l2:
            ny,nx = y+dy, x+dx
            if not (0 <= ny < w and 0 <= nx < h):
                continue
            if grid[nx][ny] == '#':
                continue
            if dist[nx][ny] > dist[x][y]+1:
                dist[nx][ny] = dist[x][y]+1
                q1.append((nx,ny))
                q2.append((nx,ny))

print(dist[gx-1][gy-1] if dist[gx-1][gy-1] != INF else -1)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

//const ll INF=(ll)1e18;
const int INF=(1<<30);

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  REP(i,N){
    cin >> h[i];
  }

  vector<int> dp(N,INF);
  dp[0]=0;
  REP(i,N){
    FOR(j,1,K+1){
      if(i+j<N){
        dp[i+j] = min(dp[i] + abs(h[i]-h[i+j]), dp[i+j]);
      }
    }
  }
  cout << dp[N-1] << endl;
}



Measured memory_bytes: 1024
import java.util.Scanner;
import java.io.*;
public class Main{

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		BufferedReader BF=new BufferedReader(new InputStreamReader(System.in));
		int count=0;
			while(sc.hasNext()){
				String a=sc.nextLine();
				String b=yms(a);
				if(a.equals(b))count++;
			}
			System.out.println(count);
	}
	public static String yms(String str) {
		  int length=str.length();
		  char[] code=str.toCharArray();
		  
		  for (int i=0; i<length/2;i++) {
		  char temp= code[i];
		   code[i] = code[length-1-i];
		   code[length-1-i]=temp;
		  }
		  String string = "";
		  for (int i=0; i<length;i++)string+=code[i];
		  //System.out.println();
		  return string;
		 }
	
}

Measured memory_bytes: 15412
import java.util.Scanner;

public class Main {
	public static int M = 1046527;
	public static char H[][] = new char[M][14];
	public static char x[] = new char[14];

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String cmd, dic;
		for(int i = 0; i < N; i++) {
			char []str = new char[14];
			cmd = sc.next();
			dic = sc.next();
			for(int j = 0; j < dic.length(); j++) {
				str[j] = dic.charAt(j);
			}
			if(cmd.charAt(0) == 'i') {
				insert(str);
			}else {
				if(find(str) == 1) {
					System.out.println("yes");
				}else {
					System.out.println("no");
				}
			}
		}
		sc.close();
	}

	//文字から数値に変換
	public static int getChar(char ch) {
		if(ch == 'A') return 1;
		else if(ch == 'C') return 2;
		else if(ch == 'G') return 3;
		else if(ch == 'T') return 4;
		else return 0;
	}

	//文字列から数値に変換してkeyを生成する
	public static long getKey(char []str) {
		long sum = 0;
		long p = 1;
		for(int i = 0; i < 14; i++) {
			sum += p * getChar(str[i]);
			p *= 5;
		}
		return sum;
	}

	public static boolean isCheck(char[] c1, char[] c2) {
		for(int i = 0; i < 14; i++) {
			if(c1[i] != c2[i]) {
				return false;
			}
		}
		return true;
	}

	public static int h1(long key) {
		return (int)(key % M);
	}
	public static int h2(long key) {
		return (int)(key % (M - 1));
	}
	public static void disp(char []c) {
		for(int i = 0; i < 14; i++) {
			System.out.print(c[i]);
		}
		System.out.println();
	}
	public static void strcpy(char[] c1, char[] c2) {
		for(int i = 0; i < 14; i++) {
			c1[i] = c2[i];
		}
	}

	public static int find(char []str) {
		long key = getKey(str);
		int h;
		for(int i = 0; ;i++) {
			h = (h1(key) + i * h2(key)) % M;
			if(isCheck(H[h], str)) {
				return 1;
			}else if(H[h][0] == x[0]) {
				return 0;
			}
		}
	}


	public static int insert(char str[]) {
		long key = getKey(str);
		int h;
		for(int i = 0;; i++) {
			h = (h1(key) + i * h2(key)) % M;
			if(isCheck(H[h], str)) return 1;
			else if(H[h][0]== x[0]) {
				strcpy(H[h], str);
				return 0;
			}
		}
	}
}


Measured memory_bytes: 372780
#include<iostream>
using namespace std;
#define df 0

double f(int vl,int vr,int vm,int t){
  int M=max(vl,vr),d=2*M-vl-vr,r=t-d;
  double sum=M*t-d*d*0.5+r*r*0.25, h=r*0.5+M-vm;
  if(h<0)h=0;
  sum-=h*h;
  if(df)printf("%lf\n",sum);
  return sum;
}

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  int t[n],v[n];
  for(int& x:t) cin >>x;
  for(int& x:v) cin >>x;
  int w[n+1];
  w[0]=w[n]=0;
  for(int i=0;i<n-1;i++){
    w[i+1]=min(v[i],v[i+1]);
  }
  if(df){
    for(int x: w)printf("%d ",x);
    printf("\n");
  }
  int temp=0;
  for(int i=0;i<n;i++){
    temp+=t[i];
    w[i+1]=min(w[i+1],temp);
    temp=w[i+1];
  }
  if(df){
    for(int x: w)printf("%d ",x);
    printf("\n");
  }
  temp=0;
  for(int i=n-1;i>=0;i--){
    temp+=t[i];
    if(df)printf("min(%d,%d)",temp,w[i]);
    w[i]=min(w[i],temp);
    temp=w[i];
  }
  if(df){
    printf("t[n-1]=%d,w[n]=%d\n",t[n-1],w[n]);
    for(int x: w)printf("%d ",x);
    printf("\n");
  }

  double sum=0;
  for(int i=0;i<n;i++){
    sum+=f(w[i],w[i+1],v[i],t[i]);
  }
  printf("%lf",sum);
}

/// confirm df==0 ///

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	//尻から食べる
	int X, Y, A, B, C,u;
	cin >> X >> Y >> A >> B >> C;
	priority_queue<int, vector<int>, greater<int>>p, q;
	priority_queue<int>r;
	for (size_t i = 0; i < A; i++)
	{
		cin >> u;
		p.push(u);
	}
	for (size_t i = 0; i < B; i++)
	{
		cin >> u;
		q.push(u);
	}
	for (size_t i = 0; i < C; i++)
	{
		cin >> u;
		r.push(u);
	}
	//尻から食べる。
	//①赤く塗って食べる
	//②青く塗って食べる
	//③塗らない
	//置き換えられる限り赤と青の小さい方を塗り林檎に置き換える。
	//p,qは昇順priority_queueにしたほうがいいかも
	while (p.size() != X) {
		p.pop();
	}
	while(q.size()!=Y){
		q.pop();
	}
	int dist,qpush=0,ppush=0;
	while (true) {
		if (r.empty()||r.top()<min(p.top(),q.top()))break;
		else {
			if (ppush == X && qpush == Y)break;
			if (ppush==X||p.top() > q.top()) {
				q.pop();
				q.push(r.top());
				qpush++;
				
			}
			else
			{
				p.pop();
				p.push(r.top());
				ppush++;
			}
			r.pop();
		}
	}
	long long ans = 0;
	while (!p.empty()) {
		ans += (long long)p.top();
		p.pop();
	}
	while (!q.empty()) {
		ans += (long long)q.top();
		q.pop();
	}
	cout << ans;
}

Measured memory_bytes: 1784
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (i % 2 == 0) {
				if (a % 2 == 1) {
					list.add(a);
				}
			} else {
				continue;
			}
		}
		System.out.println(list.size());
	}
}


Measured memory_bytes: 35736
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if (S[K - 1] == 'A') S[K - 1] = 'a';
  if (S[K - 1] == 'B') S[K - 1] = 'b';
  if (S[K - 1] == 'C') S[K - 1] = 'c';
  cout << S << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
from functools import reduce

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

def mymin(a, b):
    # ここに実装してください
    if a < b:
        return a
    else :
        return b

def mymax(a, b):
    # ここに実装してください
    if a < b:
        return b
    else :
        return a


def mysum(a, b):
    # ここに実装してください
    return a + b

print(reduce(mymin, values), reduce(mymax, values), reduce(mysum, values))


Measured memory_bytes: 7268
H = int(input())

while H:
  Ali = [list(map(int,input().split())) for _ in range(H)]
  score = 0
  while True:
    sc = score
    for i in range(H):
      Row = Ali[i]
      #5つ
      if Row[0] == Row[1] == Row[2] == Row[3] == Row[4]:
        score += Row[0]*5
        Ali[i][0] = Ali[i][1] = Ali[i][2] = Ali[i][3] = Ali[i][4] = 0
      
      #4つ
      if Row[0] == Row[1] == Row[2] == Row[3]:
        score += Row[0]*4
        Ali[i][0] = Ali[i][1] = Ali[i][2] = Ali[i][3] = 0
      
      if Row[1] == Row[2] == Row[3] == Row[4]:
        score += Row[1]*4
        Ali[i][1] = Ali[i][2] = Ali[i][3] = Ali[i][4] = 0
      
    #3つ
      if Row[0] == Row[1] == Row[2]:
        score += Row[0]*3
        Ali[i][0] = Ali[i][1] = Ali[i][2] = 0
      
      if Row[1] == Row[2] == Row[3]:
        score += Row[1]*3
        Ali[i][1] = Ali[i][2] = Ali[i][3] = 0
      
      if Row[2] == Row[3] == Row[4]:
        score += Row[2]*3
        Ali[i][2] = Ali[i][3] = Ali[i][4] = 0
        
    if sc == score:
      break
      
    #落としていく処理
    #下から上に見ていく
    for i in range(1,H+1):
      for j in range(0,5):
        if Ali[-i][j] == 0:
          for k in range(i+1,H+1):
            if Ali[-k][j] != 0:
              Ali[-i][j] = Ali[-k][j]
              Ali[-k][j] = 0
              break
              
  print(score)
  H = int(input())


Measured memory_bytes: 5640
N, W  = (int(i) for i in input().split()) 
w = []
v = []
for i in range(N):
    aa, bb = [int(i) for i in input().split()] 
    w.append(aa)
    v.append(bb)

# dp[i][v] : i-1番目までで価値がvのときの重さを表す

maxval = 100001
dp = [[1000000000000 for i in range(maxval)] for j in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(maxval):
        if j - v[i] >= 0:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

mv = 0
for i in range(N+1):
    for j in range(maxval):
        j0 = maxval - 1 - j
        if dp[i][j0] <= W:
            if mv < j0:
                mv = j0

print(mv)



Measured memory_bytes: 171784
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

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

const int MAXN = 303;
const ll MOD = 1e9+7;
int N, M;
vector<ii> cond[MAXN];
ll dp[MAXN][MAXN][MAXN];
ll f(int r, int g, int b){
    ll &ret = dp[r][g][b];
    if(ret!=-1) return ret;
    ret = 0;
    int i = max(r, max(g,b));
    FOR(j,0,cond[i].size()){
        int l=cond[i][j].fst, x=cond[i][j].snd;
        int cnt = (r>=l) + (g>=l) + (b>=l);
        if(cnt != x) return ret;
    }
    if(i==N) return ret=1;
    return ret = (f(i+1,g,b) + f(r,i+1,b) + f(r, g, i+1))%MOD;
}
int main(){
    scan(N,M);
    FOR(i,0,M){
        int l,r,x; scan(l,r,x);
        cond[r].pb({l,x});
    }
    ms(dp,-1);
    printf("%lld\n",f(0,0,0));
}


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

int w,h;
int n;

bool rgn[2001][2001];
int max_x,max_y;

vector<int> x1,x2,y1_,y2;
vector<int> sortx,sorty;

void DFS(int x,int y){
	if(!rgn[x][y]) return;
	rgn[x][y] = false;

	// up
	if(x > 0){
		DFS(x-1,y);
	}
	if(x < max_x-1){
		DFS(x+1,y);
	}
	if(y > 0){
		DFS(x,y-1);
	}
	if(y < max_y-1){
		DFS(x,y+1);
	}
}

int main(){
	while(scanf("%d%d",&w,&h),w != 0){
		scanf("%d",&n);
		x1 = vector<int>(n);
		x2 = vector<int>(n);
		y1_ = vector<int>(n);
		y2 = vector<int>(n);
		sortx = vector<int>(n*2+2);
		sorty = vector<int>(n*2+2);
		for(int i = 0; i < n; i++){
			scanf("%d%d%d%d",&x1[i],&y1_[i],&x2[i],&y2[i]);
			sortx[i]   = x1[i];
			sortx[i+n] = x2[i];
			sorty[i]   = y1_[i];
			sorty[i+n] = y2[i];
		}
		sortx[n*2] = 0;
		sortx[n*2+1] = w-1;
		sorty[n*2] = 0;
		sorty[n*2+1] = h-1;
		// coord compression
		sort(sortx.begin(),sortx.end());
		sortx.erase(unique(sortx.begin(),sortx.end()),sortx.end());
		sort(sorty.begin(),sorty.end());
		sorty.erase(unique(sorty.begin(),sorty.end()),sorty.end());
		for(int i = 0; i < n; i++){
			vector<int>::iterator itr = lower_bound(sortx.begin(),sortx.end(),x1[i]);
			x1[i] = distance(sortx.begin(),itr);
			itr = lower_bound(sortx.begin(),sortx.end(),x2[i]);
			x2[i] = distance(sortx.begin(),itr);
			itr = lower_bound(sorty.begin(),sorty.end(),y1_[i]);
			y1_[i] = distance(sorty.begin(),itr);
			itr = lower_bound(sorty.begin(),sorty.end(),y2[i]);
			y2[i] = distance(sorty.begin(),itr);
		}
		max_x = sortx.size() - 1;
		max_y = sorty.size() - 1;

		// set tape region
		for(int i = 0; i < max_x; i++){
			for(int j = 0; j < max_y; j++){
				rgn[i][j] = true;
			}
		}
		for(int t = 0; t < n; t++){
			for(int i = x1[t]; i < x2[t]; i++){
				for(int j = y1_[t]; j < y2[t]; j++){
					rgn[i][j] = false;
				}
			}
		}
		
		// DFS
		int ans = 0;
		for(int i = 0; i < max_x; i++){
			for(int j = 0; j < max_y; j++){
				if(!rgn[i][j]) continue;

				DFS(i,j);
				ans++;
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}



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

int main() {
  int X;
  cin >> X;
  while (true) {
    bool flag = true;
    for (int i = 2; i <= sqrt(X); ++i)
      if (X % i == 0)
        flag = false;
    if (flag) {
      cout << X << endl;
      return 0;
    }
    ++X;
  }
}

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

public class Main {

  public static void main(String[] args) {
    main1();
  }

  private static void main1() {
    Scanner scanner = new Scanner(System.in);
    String line = scanner.next();
    String seikai = "CODEFESTIVAL2016";
    int count = 0;
    for (int i = 0; i < line.length(); i++) {
      if (line.charAt(i) != seikai.charAt(i))
        count++;
    }
System.out.println(count);
    scanner.close();
  }

  private static void main2() {
    Scanner scanner = new Scanner(System.in);
    String line = scanner.next();
    scanner.close();
  }

  private static void main3() {
    Scanner scanner = new Scanner(System.in);
    String line = scanner.next();
    scanner.close();
  }

  private static void main4() {
    Scanner scanner = new Scanner(System.in);
    String line = scanner.next();
    scanner.close();
  }

}

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;cin>>n;
	int arr[n];
	for(int i = 0; i < n; ++i) cin>>arr[i];
	if(n&1){
		cout<<0<<endl;
	} else{
		sort(arr, arr + n);
		int val = arr[n/2], val2 = arr[n/2 - 1];
		cout<<val - val2<<endl;
	}
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;


int main() {
    ll n; cin >> n;
    vector<double> v(n);
    rep(i, 0, n) cin >> v[i];

    sort(ALL(v));

    rep(i, 0, n-1){
        v[i+1] = (v[i]+v[i+1])/2;
    }

    cout << setprecision(14) << v[n-1] << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;

int main(){

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

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

    int dh = 1e9;
    sort(h, h+n);
    for(int i=0; i<n-k+1; i++){
        if(h[i+k-1] - h[i] < dh){
            dh = h[i+k-1] - h[i];
        }
    }

    cout << dh << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

#define mod 1000000007

int main() {
    long long n; std::cin >> n;

    int a = n;
    int b = 1;
    for(int i = std::sqrt(n); i > 0; i--) {
        if(n%i == 0) {
            a = i;
            b = n/i;
            break;
        }
    }

    std::string A = std::to_string(a);
    std::string B = std::to_string(b);

    std::cout << std::max(A.size(), B.size()) << std::endl;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
vector<int>g[100009];
bool book[100009];
int dp[100009],n,m,ans;
int dfs(int x) {
	if(book[x]) return dp[x];
	book[x]=1;
	for(int i=0;i<g[x].size();i++) dp[x]=max(dp[x],dfs(g[x][i])+1);
	return dp[x];
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;i++) {
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
	}
	for(int i=1;i<=n;i++)
		ans=max(ans,dfs(i));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a[7];
    rep(i, 7) cin >> a[i];
    int ans = a[1];
    int x = (a[0] / 2 + a[3] / 2 + a[4] / 2) * 2, y = 0;
    if (a[0] > 0 && a[3] > 0 && a[4] > 0)
    {
        y = 3;
        a[0]--, a[3]--, a[4]--;
        y += (a[0] / 2 + a[3] / 2 + a[4] / 2) * 2;
    }
    ans += max(x, y);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    
    //文字
    String a = sc.next();
    //判定
    if(Character.isUpperCase(a.charAt(0))) {
      System.out.println("A");
    }
    else {
      System.out.println("a");
    }
  }
}

Measured memory_bytes: 35756
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    cout << max(0,A-2*B);
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt[] = new int[n] ;
		long ans = 1;
		for(int i = 0; i < n; i++)cnt[i] = 0; 
		for(int i = 0; i < n; i++) cnt[sc.nextInt()]++; 
		boolean key = true;
		int idx = 1;
		if(n % 2 != 0) {
			idx++;
			if(cnt[0] != 1) 	cnt[2] = 0;//key=falseと同義
			
		}
		while(idx < n) {
			if(cnt[idx] != 2) {
				key = false;
				break;
			}
			idx += 2;
		}
		if(key) {
			for(int i = 0; i < n / 2; i++) {
				ans = ans *  2 % 1000000007;
			}
		}
		else ans = 0;
		System.out.println(ans);
	}
}

Measured memory_bytes: 50036
def main() -> None:
    N = int(input())
    l = [v for v in range(1, N + 1) if v % 2 == 1]

    c = t = 0

    for n in l:
        for i in range(1, n + 1):
            if n % i == 0:
                t = t + 1
        c = (c + 1) if t == 8 else c
        t = 0
    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int maxdiff = max(abs(a1-a2), max(abs(a2-a3), abs(a3-a1)));
    cout << abs(a1-a2) + abs(a2-a3) + abs(a3-a1) - maxdiff << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const ll INF = (int)100100100100100;

int main() {
    //ll N; cin >> N;
    ll N,W; cin >> N >> W;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    ll dp[N+1][100100];
    for(int i=0;i<N+1;i++){
        for(int j=0;j<100099;j++){
            dp[i][j]=INF;
        }
    }
    ll w[N];
    ll v[N];
    for(int i=0;i<N;i++){
        cin >> w[i] >> v[i];
    }
  	dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=100099;j++){
          	if(j-v[i]>=0){
                dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
            }
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        }
    }
    ll mak=0;
    for(int i=0;i<100099;i++){
        if(dp[N][i]<=W)mak=i;
    }
    cout << mak;
}

/*



 */



Measured memory_bytes: 79232
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[] resH = new int[h];
		int[] resW = new int[w];
		char[][] grid = new char[h][w];
		for(int i = 0; i < h; i++){
		    String s = sc.next();
		    char[] c = s.toCharArray();
		    for(int j = 0; j < w; j++){
		        grid[i][j] = c[j];
		        if(c[j] == '#'){
		            resH[i] = 1;
		            resW[j] = 1;
		        }
		    }
		}
		
		// 計算
		
		// 出力
		for(int i = 0; i < h; i++){
		    if(resH[i] == 0) continue;
		    for(int j = 0; j < w; j++){
		        if(resW[j] == 0) continue;
		        System.out.print(grid[i][j]);
		    }
		    System.out.println("");
		}
	}
}


Measured memory_bytes: 27604
d = int(input())
c = list(map(int,input().split()))
ans = []
fin = [1]*d
pen = [0]*26
sattemp = 0
sat = 0
sl = [list(map(int,input().split())) for i in range(d)]
for k in range(900,3000):
    for i in range(d):
        s = sl[i]
        sp = sum(pen)
        temp = -(10**9)
        for j in range(26):
            if s[j]-(sp-pen[j])**(k*0.001) > temp:
                temp = s[j]-(sp-pen[j])**(k*0.001)
                tempans = j+1
        ans += [tempans]
        sattemp += s[tempans-1]-sp+pen[tempans-1]
        for j in range(26):
            pen[j] += c[j]
            pen[tempans-1] = 0
    if sattemp > sat:
        sat = sattemp
        fin = ans
    ans = []
    pen = [0]*26
    # print(k,sattemp)
    sattemp = 0
for i in fin:
    print(i)

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

int main(){
    int64_t N;
    cin >> N;
    if(N%2){
        cout << 0 << endl;
        return 0;
    }
    int64_t num2 = 0, num5 = 0;
    for(int k=1; k<64; k++){
        int64_t n = N;
        for(int i=0; i<k; i++) n /= 2;
        num2 += n;
    }
    for(int k=1; k<64; k++){
        int64_t n = N/2;
        for(int i=0; i<k; i++) n /= 5;
        num5 += n;
    }
    cout << min(num2, num5) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	int id;
	int score;
	int rank;
} team;

typedef struct _teamlist{
	team t[100];
	struct _teamlist* next;
} teamlist;

int compid(const void* x,const void* y) {
	int xx,yy;
	xx=((team*)x)->id;
	yy=((team*)y)->id;
	if(xx>yy)return 1;
	else if(xx<yy)return -1;
	else return 0;
}

int compscore(const void* x,const void* y) {
	int xx,yy;
	xx=((team*)x)->score;
	yy=((team*)y)->score;
	if(xx<yy)return 1;
	else if(xx>yy)return -1;
	else return 0;
}

int main(void) {
	team* all;
	teamlist* tlist;
	teamlist* currenttlist;
	int id,score;
	int teamnum;
	int i;
	int rank;
	team* nowteam;
	team searchfor;
	teamnum=0;
	currenttlist=tlist=calloc(1,sizeof(teamlist));
	currenttlist->next=NULL;
	while(1) {
		scanf("%d,%d",&id,&score);
		if(id==0 && score==0)break;
		currenttlist->t[teamnum%100].id=id;
		currenttlist->t[teamnum%100].score=score;
		teamnum++;
		if(teamnum%100==0) {
			currenttlist->next=calloc(1,sizeof(teamlist));
			currenttlist=currenttlist->next;
			currenttlist->next=NULL;
		}
	}
	all=calloc(teamnum,sizeof(team));
	currenttlist=tlist;
	for(i=0;currenttlist!=NULL;i++) {
		memcpy(&all[i*100],currenttlist->t,
			sizeof(team)*((teamnum>=(i+1)*100)?100:teamnum%100));
		currenttlist=currenttlist->next;
	}
	while(tlist!=NULL) {
		currenttlist=tlist->next;
		free(tlist);
		tlist=currenttlist;
	}
	qsort(all,teamnum,sizeof(team),compscore);
	all[0].rank=1;
	for(i=1,rank=1;i<teamnum;i++) {
		if(all[i].score!=all[i-1].score)rank++;
		all[i].rank=rank;
	}
	qsort(all,teamnum,sizeof(team),compid);
	while(1) {
		if(scanf("%d",&id)==-1)break;
		searchfor.id=id;
		nowteam=bsearch(&searchfor,all,teamnum,sizeof(team),compid);
		if(nowteam==NULL)printf("0\n");
		else printf("%d\n",nowteam->rank);
	}
	free(all);
	return 0;
}

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

int main() {
	string o,e;
    cin >> o;
    cin >> e;
    for(int i=0;i<e.size();i++){
      cout << o.at(i) << e.at(i);
    }
    if(o.size()>e.size()){
      cout << o.at(o.size()-1);
    }
    cout << endl;
}


Measured memory_bytes: 256
import sys

N = int(input())
flag = False
for i in range((101 // 4) + 1):
    for j in range((101 // 7) + 1):
        total = (4 * i + 7 * j)
        if total == 0:
            continue
        if N == total:
            print("Yes")
            flag = True
            break
    if flag:
        break
if not flag:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h> 
    //#define M_PI 3.14159265358979323846



using namespace std;

#define rep(i,a,b) for(int i=a;i<b;++i)
#define repb(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define vc vector<char>
#define vld vector<ld>
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
#define vvld vector<vector<ld> >
#define vpii vector<pii>
#define vpll vector<pll>
#define ld long double
#define ll long long
#define sz(a) (ll)a.size()
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define ssortB(arr)   stable_sort(arr.begin(),arr.end(),greater<ll >());
#define pii pair<int,int>
#define pll pair<long long,long long>
#define ff first
#define ss second
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define endl "\n" 
#define PI acos(-1.0)
#define GCD(a,b) __gcd(a,b)
#define popcount(x) __builtin_popcountll(x)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define r1(x) cin>>x
#define r2(x,y) cin>>x>>y
#define r3(x,y,z) cin>>x>>y>>z
#define r4(a,b,c,d) cin>>a>>b>>c>>d
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define fix(f,n) fixed<<setprecision(n)<<f<<endl
#define check(ds, a) (ds.find(a)!=ds.end()?1:0)
#define mem(arr)  memset(arr,0,sizeof(arr))
const int M=(int)1e9+7;
const int MAXN=(int)1e6+1;
int spf[MAXN]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
int main(){
    IOS;
    vi flag(MAXN,0);
    sieve();
    int n;cin>>n;
    int f=0,g=0;
    vi arr(n,0);
    
    rep(i,0,n){
        cin>>arr[i];
        int temp=arr[i];
        int prev=-1;
        while(temp!=1){
            int x=spf[temp];
            if(x!=prev)flag[x]++;
            temp/=x;
            prev=x;
        }
    }
    //cout<<"hi"<<endl;
    rep(i,0,MAXN){
        if(flag[i]>1)f=1;
        if(flag[i]==n)g=1;
    }
    if(!f)cout<<"pairwise coprime"<<endl;

    else if(!g) cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
}

Measured memory_bytes: 15060
import math
import numpy as np
a,b=[int(v) for v in input().split()]

min_8=math.ceil(a/0.08)
max_8=(a+1)//0.08

min_10=math.ceil(b/0.1)
max_10=(b+1)//0.1


range_8 = np.arange(min_8,max_8+1).astype(int)
range_10 = np.arange(min_10,max_10+1).astype(int)

try:
    print(min(np.intersect1d(range_8,range_10)))
except:
    print(-1)   

Measured memory_bytes: 21428
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	string s;
	while (cin >> s)
	{
		for (int i = 0; i < s.length(); i+=2)
		{
			cout << s[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <utility>
#include <algorithm>

using namespace std;

int main () {
  cin.tie(0);
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++) cin >> h[i];
  
  int see = 0;
  int maxh = 0;
  
  for (int i = 0; i < n; i++) {
    if (maxh <= h[i]) {
      see++;
      maxh = h[i];
    }
  }
  
  cout << see << "\n";
}

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

int n, t, s; 
int a[3030], b[3030];

int dp[3030];

int main()
{
  cin >> n >> t >> s;
  for (int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }

  int ans = 0;
  for (int i = 0; i < n; i++){
    for (int j = t; j >= b[i]; j--){
      int x = j - b[i];
      if ((s <= x) || (j <= s)){
        dp[j] = max(dp[j], dp[x] + a[i]);
        ans = max(ans, dp[j]);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi a(3*n); rep(i, 3*n) cin >> a[i];
	
	auto calc = [](const vi &a){
		int n = a.size(), m = n / 3;
		vector<ll> res;
		ll sum = 0;
		priority_queue<int, vi, greater<int>> q;
		rep(i, m){
			sum += a[i];
			q.push(a[i]);
		}
		rep(i, m + 1){
			res.pb(sum);
			q.push(a[i + m]);
			sum += a[i + m] - q.top(); q.pop();
		}
		return res;
	};
	
	vector<ll> x = calc(a);
	reverse(all(a));
	rep(i, 3*n) a[i] *= -1;
	vector<ll> y = calc(a);
	
	ll ans = -1e18;
	rep(i, x.size()) ans = max(ans, x[i] + y[x.size() - 1 - i]);
	cout << ans << endl;
	//dbg(x); dbg(y);
	
	return 0;
}

Measured memory_bytes: 4460
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから----------- 
int main(void){
    int n;
    cin >> n;
    bool p = false;
    string s = to_string(n);
    int f = s[s.size() - 1] - '0';
    switch(f){
        case 0:
        p = true;
        break;
        case 1:
        p = true;
        break;
        case 2:
        p = false;
        break;
        case 3:
        p = false;
        break;
        case 4:
        p = false;
        break;
        case 5:
        p = false;
        break;
        case 6:
        p = true;
        break;
        case 7:
        p = false;
        break;
        case 8:
        p = true;
        break;
        case 9:
        p = false;
        break;
    }

    if(f == 3){
        cout << "bon" << endl;
    } else if(p){
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3700
#import time

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

    As.sort()
    amax = max(As) + 1
    lis = [True] * amax
    ans = 0

    for i in range(N-1):
        if lis[As[i]]:
            for j in range(As[i], amax, As[i]):
                lis[j] = False
            if As[i] < As[i+1]:
                ans += 1
    if lis[-1]:
        ans += 1

    return ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Measured memory_bytes: 32216
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,a[SZ],f[SZ][2];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	memset(f,127/3,sizeof f);
	f[0][1]=0;
	for(int i=1;i<=n;++i)
	{
		if(a[i]==a[i-1])
			f[i][0]=f[i-1][1],
			f[i][1]=min(f[i-1][1],f[i-1][0])+1;
		else
			f[i][0]=min(f[i-1][0],f[i-1][1]),
			f[i][1]=f[i][0]+1;
	}
	cout<<min(f[n][0],f[n][1])<<"\n";
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int main(){
    int N;
    cin>>N;
    vector<P> Bracketfirst(0);
    vector<P> Bracketsecond(0);
    //A (
    //B )
    for(int i=0;i<N;i++){
        int A=0,B=0;
        string S;
        cin>>S;
        for(int j=0;j<(int)S.size();j++){
            if(S.at(j)=='('){
                A++;
            }
            else{
                if(A>0){
                    A--;
                }
                else{
                    B++;
                }
            }
        }
        if(A>=B){
            Bracketfirst.push_back(make_pair(B,A));
        }
        else{
            Bracketsecond.push_back(make_pair(A,B));
        }
    }
    sort(Bracketfirst.begin(),Bracketfirst.end());
    sort(Bracketsecond.begin(),Bracketsecond.end());
    reverse(Bracketsecond.begin(),Bracketsecond.end());
    string answer="";
    for(int i=0;i<(int)Bracketfirst.size();i++){
        //cout<<Bracket.at(i).first<<" "<<Bracket.at(i).second<<endl;
        for(int j=0;j<Bracketfirst.at(i).first;j++){
            answer+=")";
        }
        for(int j=0;j<Bracketfirst.at(i).second;j++){
            answer+="(";
        }
    }
    for(int i=0;i<(int)Bracketsecond.size();i++){
        //cout<<Bracket.at(i).first<<" "<<Bracket.at(i).second<<endl;
        for(int j=0;j<Bracketsecond.at(i).second;j++){
            answer+=")";
        }
        for(int j=0;j<Bracketsecond.at(i).first;j++){
            answer+="(";
        }
    }
    //cout<<answer<<endl;
    int a=0,b=0;
    for(int i=0;i<(int)answer.size();i++){
        if(answer.at(i)=='('){
            a++;
        }
        if(answer.at(i)==')'){
            b++;
        }
        if(a<b){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(a==b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 13840
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	cin >> N;
	vl P = { 3,5,7,11,13,17,19,23,29 };
	for (i = 0; i < P.size(); i++) {
		for (j = 0; j < P.size(); j++) {
			if(i==j) continue;
			if (P[i] * P[i] * P[i] * P[j] <= N) {
				ans++;
			}
		}
	}
	for (i = 0; i < P.size(); i++) {
		for (j = i+1; j < P.size(); j++) {
			for (k = j+1; k < P.size(); k++) {
				if (i == j || j == k) continue;
				if (P[i] * P[j] * P[k] <= N) {
					ans++;
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

VI g[200010];
int a[200010], p[200010];

bool func(int st, int v) {
  int i = p[st];
  int pre = v;
  // cout << i << " " << pre << endl;
  while(i != st) {
    set<int> s;
    s.insert(pre);
    for(int j: g[i]) {
      s.insert(a[j]);
    }
    int g = 0;
    while(s.count(g)) g++;
    a[i] = g;
    pre = g;
    // cout << i << " " << pre << endl;
    i = p[i];
  }

  set<int> s;
  s.insert(pre);
  for(int j: g[i]) s.insert(a[j]);
  int g = 0;
  while(s.count(g)) g++;
  a[st] = g;
  // cout << "g:" << g << endl;
  return g == v;
}

signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) {
    // int p;
    cin >> p[i];
    p[i]--;
    g[p[i]].PB(i);
  }

  queue<int> que;
  REP(i, n) {
    //葉なら
    if(g[i].size() == 0) {
      que.push(i);
    }
    a[i] = -1;
  }

  //サイクル以外の値を決定
  while(que.size()) {
    int q = que.front(); que.pop();
    if(a[q] >= 0) continue;

    set<int> s;
    bool ng = false;
    for(int i: g[q]) {
      if(a[i] < 0) ng = true;
      s.insert(a[i]);
    }
    if(ng) continue;

    int g = 0;
    while(s.count(g)) g++;

    a[q] = g;
    que.push(p[q]);
  }
  // REP(i, n) cout << a[i] << " "; cout << endl;

  //サイクル上の適当な頂点を一点選ぶ
  int x;
  REP(i, n) if(a[i] == -1) x = i;

  set<int> s;
  for(int i: g[x]) s.insert(a[i]);
  int fir = 0;
  while(s.count(fir)) ++fir;
  int sec = fir + 1;
  while(s.count(sec)) ++sec;

  if(func(x, fir)) cout << "POSSIBLE" << endl;
  else if(func(x, sec)) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  // REP(i, n) cout << a[i] << " "; cout << endl;

  return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	ll a,v,b,w,t; cin>>a>>v>>b>>w>>t;
	if(t*v>=w*t+abs(a-b)) cout << "YES"<<endl;
	else cout <<"NO"<<endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int cnt1 = 0;
        int cnt2 = 0;
        int cnt4 = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a % 4 == 0) {
                cnt4++;
            } else if (a % 2 == 0) {
                cnt2++;
            } else {
                cnt1++;
            }
        }

        System.out.println(((cnt1 > cnt4) ? (((cnt1 - cnt4) == 1) && (cnt2 == 0)) : true) ? "Yes"
            : "No");
    }

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


Measured memory_bytes: 48180
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 2000 + 20;
const long long mod = 1e9 + 7;
int n;
long long k;
long long a[MAXN], a1[MAXN] = {}, a2[MAXN] = {};


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

    int m, d, d1 = 0, d2 = 0;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
    	cin >> a[i];
    }

    for(int i = 0; i < n; i++){
    	for(int j = i + 1; j < n; j++) {
    		if(a[i] > a[j]) {
    			a1[i]++;
    			a2[i]++;
    		}
    	}
    	for(int j = 0; j < i; j++) {
    		if(a[i] > a[j])
    			a2[i]++;
    	}
    }

    long long res = 0;
    for(int i = 0; i < n; i++) {
    	res = (res + a1[i] * k % mod) % mod;
    	res = (res + a2[i] * (k * (k - 1) / 2 % mod) % mod) % mod;
    }
    cout << res << endl;


    return 0;
}











Measured memory_bytes: 256