akhauriyash/Code-Regression huggingface dataset:
use proconio::{fastout, input};
use std::collections::HashMap;
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        n: usize
    }
    let mut map = HashMap::new();
    let AC = "AC".to_string();
    let WA = "WA".to_string();
    let TLE = "TLE".to_string();
    let RE = "RE".to_string();

    map.insert(AC.to_owned(), 0);
    map.insert(WA.to_owned(), 0);
    map.insert(TLE.to_owned(), 0);
    map.insert(RE.to_owned(), 0);

    for _ in 0..n {
        input! {
            s: String
        }
        let count = map.entry(s).or_insert(0);
        *count += 1;
    }

    println!("AC x {}", map.get(&AC).unwrap());
    println!("WA x {}", map.get(&WA).unwrap());
    println!("TLE x {}", map.get(&TLE).unwrap());
    println!("RE x {}", map.get(&RE).unwrap());
}


Measured memory_bytes: 2568
n,m=map(int,input().split())

dp=[10**9]*(1<<n)
dp[0]=0
for _ in range(m):
    a,b=map(int,input().split())
    key=0
    for i in map(int,input().split()):
        key+=1<<(i-1)
    for i in range(1<<n):
        dp[i|key]=min(dp[i|key],dp[i]+a)
if dp[-1]>10**8:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 47064
#include <cstdio>

int main(void)
{
  int c;
  
  while((c = getchar()) != EOF){
    if('a' <= c && c <= 'z'){
      putchar(c - 'a' + 'A');
    } else if('A' <= c && c <= 'Z'){
      putchar(c - 'A' + 'a');
    } else {
      putchar(c);
    }
  }

  return 0;
}


Measured memory_bytes: 896
def bellman_ford(edges, N, start, end):
    cost = [float("inf") for _ in range(N)]
    cost[start] = 0
    negative = [False for _ in range(N)]

    for i in range(N):
        for j in range(len(edges)):
            fro, to, c = edges[j]

            if cost[to] > cost[fro] + c:
                cost[to] = cost[fro] + c
                # 頂点の数と同じ回数ループすると負の経路がある
                if i == N - 1:
                    negative[to] = True

    if negative[end]:
        return "inf"
    else:
        return -cost[end]


N, M = map(int, input().split())

edges = []
for _ in range(M):
    a, b, c = map(int, input().split())
    edges.append((a - 1, b - 1, -c))

cost = [float("inf") for _ in range(N)]
start = 0
end = N - 1
print(bellman_ford(edges, N, start, end))


Measured memory_bytes: 3444
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = int(input())

for i in range(x, 10**5 + 4):
    if is_prime(i) == True:
        print(i)
        exit()


Measured memory_bytes: 9164
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		sc.close();
		Main main = new Main();
		int ans = 0;
		for (int i = 1; i <= num; i += 2) {
			if(main.solve(i) == 8) {
				ans++;
			}
		}
		System.out.println(ans);
	}

	public int solve(int num) {
		int factorsCon = 0;
		if (num == 1) {
			factorsCon = 1;
			return factorsCon;
		}else {
			Main m = new Main();
			BigDecimal bigDecimalNum = new BigDecimal(num);

			for (Map.Entry<Integer, Integer> ent : m.factoring(num).entrySet()) {
				BigDecimal entBigDecimal= new BigDecimal(ent.getKey());
				bigDecimalNum = bigDecimalNum.multiply(BigDecimal.ONE.subtract(BigDecimal.ONE.divide(entBigDecimal,1,RoundingMode.HALF_UP)));
				if (factorsCon == 0) {
					factorsCon += (ent.getValue() + 1);
				} else {
					factorsCon *= (ent.getValue() + 1);
				}
			}
			return factorsCon;
		}
	}

	public Map<Integer, Integer> factoring(int num) {
		Map<Integer, Integer>factors = new HashMap<Integer, Integer>();
		int combNum = num;

		while (true) {
			int factor = 0;

			//入力された値が素数であるか調べる
			int numsPiv = (int)Math.sqrt(combNum); //√N = numsPiv とする
			for (int i = 2; i <= numsPiv; i++) {
				if (combNum % i == 0) {
					factor = i;
					if (factors.containsKey(factor)) {
						factors.put(factor, factors.get(factor) + 1);
					} else {
						factors.put(factor, 1);
					}
					break;
				}
			}
			//入力値自身が素数になればbreak
			if (factor == 0) {
				//Map更新
				if (factors.containsKey(combNum)) {
					factors.put(combNum, factors.get(combNum) + 1);
				} else {
					//なければadd
					factors.put(combNum, 1);
				}
				break;
			}else {
				//はじき出した値で入力値を割って更新
				combNum = combNum / factor;
			}
		}
		return factors;
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

int main() {
    int n;
    scanf("%d" ,&n);
    set<string> se;
    string t;
    for (int i = 0; i < n; i++) {
        cin >> t;
        se.insert(t);
    }

    printf("%d" ,sz(se));
}

Measured memory_bytes: 19416
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<set<int>> vs(n);
    vector<set<int>> rv(n);
    for(int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;y--;
        vs[x].insert(y);
        rv[y].insert(x);
    }
    vector<int> dp(n, 0);
    queue<int> que;
    for(int i = 0; i < n; i++)
    {
        if(vs[i].empty()) que.push(i);
    }
    while(!que.empty())
    {
        int v = que.front();
        que.pop();
        while(!rv[v].empty())
        {
            int nx = *rv[v].begin();
            dp[nx] = max(dp[nx], dp[v] + 1);
            vs[nx].erase(v);
            rv[v].erase(nx);
            if(vs[nx].empty()) que.push(nx);
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 19456
x,k,d = gets.split.map(&:to_i)

bef = (x.abs / d).to_i
if k <= bef
  puts x.abs - d*k
else
  before = x.abs-bef*d
  over = (x.abs-(bef+1)*d).abs
  r = 0
  if before <= over
    r = bef % 2
  else
    r = (bef+1) % 2
  end

  if k%2 == r
    puts [before,over].min
  else
    puts [before,over].max
  end
end

Measured memory_bytes: 14380
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	p := 1
	for i := 1; i <= n; i++ {
		p *= i
		p %= int(math.Pow(10.0, 9.0)) + 7
	}

	fmt.Println(p)
}


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

int main() {
    int n; scanf("%d", &n);
    int a = 0, x, ans = 0;
    for(int i = 1; i <= n; i ++) {
        scanf("%d", &x);
        if(a <= x) ans ++;
        a = max(a, x);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)


int main(){
  ll n;
  cin >>n;
  ll a,ans=0,b[100100]={},c[100100]={};
  map<ll,ll>mp;
  rep(i,n){
    cin >> a;
    if(mp.find(a)==mp.end())mp[a]=0;
    mp[a]++;
  }
  int i=0;
  for(auto p:mp){
    if(p.second>3){
      c[i]=p.first;
      b[i]=p.first;
      i++;
    }else if(p.second>1){
      b[i]=p.first;
      i++;
    }
  }
  sort(b,b+n,greater<int>());
  sort(c,c+n,greater<int>());
  ans=max(b[0]*b[1],b[0]*c[0]);
  cout << ans << endl;
}


Measured memory_bytes: 8064
import java.io.*; 
import java.util.*;

class Main
{ 
	static char []  X , Y;
	static String solve(int m, int n) 
	{ 
		int[][] dp = new int[m+1][n+1]; 


		for (int i=1; i<=m; i++) { 
			for (int j=1; j<=n; j++) { 
				if (X[i-1] == Y[j-1]) 
					dp[i][j] = dp[i-1][j-1] + 1; 
				else
					dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]); 
			} 
		} 


		int index = dp[m][n]; 
		int temp = index; 


		char[] lcs = new char[index+1]; 
		lcs[index] = '\u0000'; 

		int i = m; 
		int j = n; 
		StringBuilder sb = new StringBuilder();
		while (dp[i][j] > 0) 
		{ 

			if (X[i-1] == Y[j-1]) 
			{ 
	
				sb.append(X[i-1]);
				
				i--; 
				j--; 
				index--;	 
			} 


			else if (dp[i-1][j] > dp[i][j-1]) 
				i--; 
			else
				j--; 
		} 
//
//		for(int k=0;k<temp;k++) 
//			sb.append(lcs[k]);
		return sb.reverse().toString();
	} 
	
	public static void main (String[] args) throws IOException 
	{ 
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		 X = sc.next().toCharArray();
		 Y = sc.next().toCharArray();
		int m = X.length; 
		int n = Y.length; 
		String s = solve(m,n);
		pw.println(s);
		pw.close();
	} 
	
} 
class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}

	public Scanner(String file) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(file));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	public int[] nextIntArr(int length) throws IOException{
		int[] arr = new int[length];
		for(int i = 0 ; i < length ; i++)
			arr[i] = Integer.parseInt(next());
		return arr;
	}
	public boolean ready() throws IOException {
		return br.ready();
	}
 }




Measured memory_bytes: 76372
import math
a, b, h, m = map(int, input().split())
m_rad = 6 * m
h_rad = 30 * h + m / 2
rad = abs(h_rad - m_rad)
length_2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(rad))
print(length_2**0.5)

Measured memory_bytes: 9364
#include<bits/stdc++.h>
using namespace std;
string all[]={"KIHBR","KIHBRA","KIHBAR","KIHBARA","KIHABR","KIHABRA","KIHABAR","KIHABARA","AKIHBR","AKIHBRA","AKIHBAR","AKIHBARA","AKIHABR","AKIHABRA","AKIHABAR","AKIHABARA"};
int main()
{
    string s;
    cin>>s;
    bool ans=false;
    for(int i=0;i<16;i++)
    {
        if(s==all[i])
            ans=true;
    }
    if(ans)
    {
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n, m, t; cin >> n >> m >> t;
	int a;
	int study[10002] = {};
	for (int i = 0; i < n; i++) {
		cin >> a;
		study[a - m] += 1; study[min(a + m + 1,t+1)] -= 1;
	}
	for (int i = 1; i <= t + 1; i++) {
		study[i] += study[i - 1];
	}
	int cnt = 0;
	for (int i = 0; i < t; i++) {
		if (study[i] == 0 || study[i + 1] == 0)cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
#define IREP(i,n) for(ll i=1;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG(x) cerr << x << "\n"

int main(){
    int price = 700;
    string s;
    cin >> s;
    for(int i=0;i<3;i++){
        if(s[i]=='o') price += 100;
    }
    cout << price << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
    string s;
    stack<char> st;
    cin >> s;
    
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'S'){
            st.push('S');
        }else if(s[i] == 'T'){
            if(!st.empty() && st.top() == 'S'){
                st.pop();
            }else{
                st.push('T');
            }
        }
    }

    cout << st.size() << endl;
    
    return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N;
    cin >> N;
    usleep(1998000);
    if(N % 2 == 0)cout << N << endl;
    else cout << 2 * N << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
int compare(string a, string b) {
	int i;
	for (i = 0; i < a[i] != '\0'; i++) {
		if (b[i] == '\0')
			return -1;
		else if (a[i] < b[i])
			return 1;
		else if (a[i] > b[i])
			return -1;
	}
	if (b[i] != '\0')
		return 1;
	else
		return 0;
}
int main() {
	ll n, s, b, i, cn, t, ans = 1e+13,j;
	cin >> n >> s;
	for (i = 2; i*i <= n; i++) {
		cn = n;
		t = 0;
		while (cn > 0) {
			t += cn % i;
			cn /= i;
		}
		if (t == s) {
			cout << i << endl;
			return 0;
		}
	}
	for (i = 1; i*i < n; i++) {
		t = i + n - (n / (i + 1) + 1)*i;
		if (t >= s && s >= i && n%i == s % i) {
			t = (n - s) / i + 1;
			ans = min(ans, t);
		}
	}
	if (ans < 1e+12) {
		cout << ans << endl;
		return 0;
	}
	if (s == 1&&n!=1) {
		cout << n << endl;
		return 0;
	}
	if (s == n) {
		cout << n + 1 << endl;
		return 0;
	}
	cout << "-1" << endl;
}

Measured memory_bytes: 4992
import sys
 
def main():
    A = int(input())
    B = int(input())
 
    if(A==1 and B==2 or A==2 and B==1):
        print('3')
    elif(A==1 and B==3 or A==3 and B==1):
        print('2')
    else:    
        print('1')
 
main()

Measured memory_bytes: 2940
#include<cstdio>
#define Mod 1000000007
long long f[4005][4005],ans,fac[8005],inv[4005];
int n,a[200001],b[200001];
long long C(int x,int y){return fac[x+y]*inv[y]%Mod*inv[x]%Mod;}
int main()
{
	fac[0]=inv[1]=1;
	for(int i=1;i<=8000;++i)fac[i]=fac[i-1]*i%Mod;
	for(int i=2;i<=4000;++i)inv[i]=-(Mod/i)*inv[Mod%i]%Mod;
	for(int i=2;i<=4000;++i)inv[i]=(inv[i-1]*inv[i]%Mod+Mod)%Mod;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d%d",a+i,b+i),f[2001-a[i]][2001-b[i]]++;
	for(int i=1;i<=4001;++i)for(int j=1;j<=4001;++j)f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%Mod;
	for(int i=1;i<=n;++i)ans=(ans+f[a[i]+2001][b[i]+2001]-C(2*b[i],2*a[i]))%Mod;
	ans=(ans*inv[2]%Mod+Mod)%Mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 127104
n=int(input())
h=list(map(int,input().split()))
t=[0 for _ in range(n)]
ans = 0
mode = 0
while h != t:
	for i in range(n):
		if h[i] >= 1:
			mode = 1
			h[i] -= 1
		else:
			if mode == 1:
				break
	ans += 1
	mode = 0
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
using namespace std;



int main() {
	
	int n,w[102],a[102];
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> w[i];
		
	}
	a[0] = w[0];
	for (int i = 1; i < n; i++) {
		a[i] = a[i - 1] + w[i];
	}
	int min = 100000;
	for (int i = 0; i < n; i++) {
		if (min > abs((a[n - 1] - a[i]) - a[i]))
			min = abs((a[n - 1] - a[i]) - a[i]);

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


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

using namespace std;

int main(void)
{
  string p = "Positive";
  string n = "Negative";
  string z = "Zero";
  string res = "";
  int a, b;
  cin >> a >> b;
  if(a <= 0 && 0 <= b)
    res = z;
  else if(a > 0)
    res = p;
  else if(a < 0 && b < 0){
    int cnt = b - a + 1;
    if(cnt % 2 == 0)
      res = p;
    else
      res = n;
  }

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
from collections import deque

def main():
    h, w = map(int, input().split())
    c = list(map(lambda x: int(x)+1, input().split()))
    d = list(map(lambda x: int(x)+1, input().split()))
    s = ['#'*(w+4)]*2 + ['#'*2 + input() + '#'*2 for _ in range(h)] + ['#'*(w+4)]*2

    ans = [[-1]*(w+4) for _ in range(h+4)]
    for i in range(h+4):
        for j in range(w+4):
            if s[i][j] == '#':
                ans[i][j] = -2
    ans[c[0]][c[1]] = 0

    move1 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    move2 = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if abs(i)+abs(j) > 1]

    yet = deque([(c[0], c[1])])
    done = deque()

    while yet:
        y, x = yet.popleft()
        done.append((y, x))
        for dy, dx in move1:
            ydy, xdx = y+dy, x+dx
            if ans[ydy][xdx] == -1:
                yet.append((ydy, xdx))
                ans[ydy][xdx] = ans[y][x]

        if len(yet) == 0:
            while done:
                y, x = done.popleft()
                for dy, dx in move2:
                    ydy, xdx = y+dy, x+dx
                    if ans[ydy][xdx] == -1:
                        ans[ydy][xdx] = ans[y][x] + 1
                        yet.append((ydy, xdx))

    print(ans[d[0]][d[1]])

if __name__ == '__main__':
    main()


Measured memory_bytes: 23476
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back

int main() {
  int n,cnt;
  cin >> n;
  cnt=n;
  vector<int> mochi(n,0);

  for(int i = 0; i < n; i++){
      cin >> mochi[i];
  }
  sort(mochi.begin(), mochi.end());
  int i=n-1;
  for(int i = 0; i < n-1; i++){
      if(mochi[i]==mochi[i+1]){
          cnt--;
      } 
  }

  cout << cnt << endl;

}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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; }

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    string s,t;
    cin >> s >> t;

    vector<vector<ll> > dp(s.size()+1, vector<ll>(t.size()+1, 0));

    rep(i,s.size())
    {
        rep(j,t.size())
        {
            if( s[i] == t[j] ) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i][j+1]);
            chmax(dp[i+1][j+1], dp[i+1][j]);
        }
    }
    /*
    rep(i,dp.size())
    {
        rep(j, dp[i].size()) cout << dp[i][j] << " ";
        cout << endl;
    }
    */
    string ans = "";
    ll i = s.size();
    ll j = t.size();
    while( i > 0 && j > 0)
    {
        if( s[i-1] == t[j-1] )
        {
            ans.push_back(s[i-1]);
            i--;
            j--;
        }
        else if( dp[i-1][j] > dp[i][j-1] ) i--;
        else j--;
    }
    reverse(all(ans));
    cout << ans << endl;

}


Measured memory_bytes: 70784
//API???????????????
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
  	
	private static int[] A = new int[2000001];
	private static int size = 0;
	
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		for(;;){
			String[] instruction = br.readLine().split(" ");
			String str = instruction[0];
			
			if(str.equals("end")){
				break;
			}
			
			
			if(str.equals("insert")){
				size++;
				int num = Integer.parseInt(instruction[1]);
				A[size] = num;
				int i = size;
				while(i > 1 && A[i / 2] < A[i]){
					swap(i, i / 2);
					i /= 2;
				}
			}else if(str.equals("extract")){
				int max = A[1];
				A[1] = 0;
				swap(1, size);
				size--;
				maxHeapify(1);
				System.out.println(max);
			}
		}
	}
	
	public static void maxHeapify(int i){
		int l = i * 2;
		int r = i * 2 + 1; 
		
		//????????????????????????????????§???????????§????????????????????¶
		int large;
		if(l <= size && A[l] > A[i]) large = l;
		else large = i;
		if(r <= size && A[r] > A[large]) large = r;
		//i?????????????????§????????´???
		if(large != i){
			swap(i, large);
			maxHeapify(large);
		}
	}
	
	public static void swap(int i, int j){
		int temp = A[i];
		A[i] = A[j];
		A[j] = temp;
	}
}

Measured memory_bytes: 186056
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: i64,
    }
    let t1 = n / 3;
    let t2 = n / 5;
    let t3 = n / 15;
    println!("{}", n * (n + 1) / 2 - 3 * t1 * (t1 + 1) / 2 - 5 * t2 * (t2 + 1) / 2 + 15 * t3 * (t3 + 1) / 2);
}


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

int main(){

    int n;
    cin >> n;

    string s[100000];

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

    //count関数:範囲内で完全一致する個数を調べる
    //参考:https://cpprefjp.github.io/reference/algorithm/count.html
    cout << "AC x " <<count(s, s + n, "AC") << endl;
    cout << "WA x " << count(s, s + n, "WA") << endl;
    cout << "TLE x " << count(s, s + n, "TLE") << endl;
    cout << "RE x " << count(s, s + n, "RE") << endl;
}

Measured memory_bytes: 6760
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

use std::cmp::{min, max};

fn gcd(a: usize, b: usize, book: &mut Vec<Vec<usize>>) -> usize {
    let mut x = min(a, b);
    let mut y = max(a, b);

    if book[x][y] != 0 {
        return book[x][y];
    }

    while x != 0 {
        let t = y % x;
        y = x;
        x = t;
    }

    book[x][y] = y;
    y
}

fn main() {
    scan!(k; usize);
    let mut book = vec![vec![0; 201]; 201];

    let mut s = 0;
    for a in 1..k+1 {
        for b in 1..a+1 {
            for c in 1..b+1 {
                let t = gcd(a, gcd(b, c, &mut book), &mut book);
                let u = if a == b && a == c {
                    1
                } else if a == b || b == c {
                    3
                } else {
                    6
                };
                // println!("gcd({} {} {}) = {}", a, b, c, t);
                s += t * u;
            }
        }
    }

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


Measured memory_bytes: 2464
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000000000
int n;

int main(){
    long long n;
	cin >> n;
	
	cout << n*(n-1)/2 <<endl;
	
    
    return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int main() {
	int N, K;
	cin >> N >> K;
	int sukunai = N / K;
	int amari = N % K;//amariはk未満
	if (amari == 0) {
		int ooi = sukunai + amari;
		cout << abs(ooi - sukunai) << endl;
	}
	else {
		int ooi = sukunai +1;
		cout << abs(ooi - sukunai) << endl;
	}
	
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main() {

	string s;
	cin >> s;

	ll ans = 0;
	REP(i, 1, s.size()){
		if(s[i] != s[i-1]) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
import os

input = os.sys.stdin.readline

N = int(input())

a = list(map(int, input().split()))

ans = False
b = [0]*N

for i in range(N, 0 ,-1):
    b_sum = 0
    for j in range(i, N+1, i):
        b_sum += b[j-1]
    if b_sum % 2 != a[i-1]: b[i-1] = 1
if b==[0]*N:print(0)      
else:
    print(sum(b))
    print(*[k+1 for k, l in enumerate(b) if l==1])

Measured memory_bytes: 13080
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
struct data
{
	int p1,p2,val,a;
	inline data(CI P1=0,CI P2=0,CI Val=0,CI A=0)
	{
		p1=P1; p2=P2; val=Val; a=A;
	}
	#define calc(lstx) ((lstx>nx)+(a-lstx<na-nx))
	inline int get(CI na,CI nx)
	{
		int ret=val+calc(0); if (p1<=a) ret=min(ret,val-1+calc(p1));
		if (p2<=a) ret=min(ret,val-2+calc(p2)); return ret;
	}
	#undef calc
}f[N]; int n;
int main()
{
	RI i; for (scanf("%d",&n),f[0]=data(1,1),i=1;i<=n;++i)
	{
		scanf("%d",&f[i].a); f[i].val=f[i-1].get(f[i].a,0); int l,r,mid;
		l=1; r=f[i].a; while (l<=r) if (f[i-1].get(f[i].a,mid=l+r>>1)==f[i].val)
		l=mid+1; else r=mid-1; f[i].p1=l;
		r=f[i].a; while (l<=r) if (f[i-1].get(f[i].a,mid=l+r>>1)==f[i].val-1)
		l=mid+1; else r=mid-1; f[i].p2=l;
	}
	return printf("%d",f[n].get(0,0)),0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  map<int,int> cnt;
  rep(i,N){
    int d;
    cin >> d;
    cnt[d]++;
  }

  vector<pair<int,int>> v;
  int sum = 0;
  FOR(it,cnt){
    sum += it->second;
    v.emplace_back(it->first, sum);
  }

  rep(i,v.size()){
    if(v[i].second == N - v[i].second){
      cout << v[i+1].first - v[i].first << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 3840
D = int(input())
C = list(map(int, input().split()))
SS = [list(map(int, input().split())) for i in range(D)]

Last = [-1] * 26


for d in range(D):
    S = SS[d]
    t = -1
    x = -1e100
    for i, s in enumerate(S):
        score = s - sum(c * d - (max(last, 0)) for c, last in zip(C, Last))
        if score > x:
            x = score
            t = i

    print(t + 1)


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

int main()
{
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  
  if(K<=A)
    cout<<K;
  else if(K<=A+B)
    cout<<A;
  else
    cout<<A-(K-A-B);
}

Measured memory_bytes: 3196
# -*- coding: utf-8 -*-

def main():
    n = int(input())
    r = n % 10
    if r in [2, 4, 5, 7, 9]:
        print('hon\n')
    elif r in [0, 1, 6, 8]:
        print('pon\n')
    else:
        print('bon\n')

if __name__ == '__main__':
    main()


Measured memory_bytes: 61824
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if((a==b and a !=c) or (b==c and a !=c) or (a==c and a !=b))

{
cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}

return 0;
}

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

int main()
{
  string s; cin >> s;
  int ans = 0;
  for (auto c: s) {
    if (c=='+') ans++;
    else ans--;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, K = map(int,input().split())

if K > 0:
    count = 0

    for b in range(K+1, N+1):
        p = N // b
        r = N % b
        count = count + p*(b-K)
        if r >= K:
            count = count + r-K+1
    
    print(count)
else:
    print(N*N)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;
int main() {
	int n, y, x;
	cin >> n >> y >> x;
	cout << x << " " << n << " " << y << " " << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import deque
def inpl(): return map(int, input().split())
N = int(input())

G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = inpl()
    G[a].append([b, c])
    G[b].append([a, c])

Q, K = inpl()

def BFS(G, K):
    DQ = deque([K])
    D = [-1] * (N+1)
    D[K] = 0
    while DQ:
        p = DQ.popleft()
        for q, c in G[p]:
            if D[q] == -1:
                D[q] = D[p] + c
                DQ.append(q)
    return D

D = BFS(G, K)
for _ in range(Q):
    x, y = inpl()
    print(D[x] + D[y])

Measured memory_bytes: 49964
using namespace std;
#include<iostream>
#include<stdio.h>
int main(){
int x;cin >>x;
int a[x];
for (int j =1;j<=x;j++) cin>>a[j];
for (int i=1;i<=x;i++){
	cout<<"node "<<i<<": key = "<<a[i]<<", ";
	if(i>1) cout<<"parent key = "<<a[i/2]<<", ";
	if(i*2<=x)	cout<<"left key = "<<a[i*2]<<", ";
	if((i*2)+1<=x)	cout<<"right key = "<<a[(i*2)+1]<<", ";
cout<<endl;
}
}


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

int main()
{
  int D, G, ans = 10000, c, count, sum, N = 0;
  vector<vector<int>> a(10, vector<int>(2, 0));
  bool flag;

  cin >> D >> G;
  for (int i = 0; i < D; i++)
  {
    cin >> a[i][0] >> c;
    a[i][1] = a[i][0] * 100 * (i + 1) + c;
  }
  for (int i = 1; i <= D; i++)
  {
    for (int tmp = 1; tmp < (1 << D); tmp++)
    {
      bitset<10> s(tmp);
      sum = 0;
      count = 0;
      for (int j = 0; j < D; j++)
      {
        if (s.test(j))
        {
          sum += a[j][1];
          count += a[j][0];
        }
      }
      if (sum < G)
        continue;
      ans = min(ans, count);
      for (int j = 0; j < D; j++)
      {
        if (s.test(j))
        {
          if (sum - a[j][1] < G)
            ans = min(ans, count - a[j][0] + (G - (sum - a[j][1]) - 1) / ((j + 1) * 100) + 1);
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N;
int A[200005];
int ans[200005];

int main(){
    cin>>N;
    for(int i=2;i<=N;i++) cin>>A[i];

    for(int i=2;i<=N;i++) ans[A[i]]++;

    repn(i,N) cout<<ans[i]<<endl;
}

Measured memory_bytes: 5152
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a > b:
    a -= v * t
    b -= w * t
    print('YES' if a <= b else 'NO')
elif a < b:
    a += v * t
    b += w * t
    print('YES' if a >= b else 'NO')



Measured memory_bytes: 61888
# KEYENCE String 全通りのパターンを探索する

# input process
S = input()
s_length = len(S)

# initialization
is_same = False
for i in range(s_length):
    for j in range(i, s_length):
        # string slice
        tmp_str = S[:i+1] + S[j:]
        if tmp_str=="keyence":
            is_same = True
            break

if is_same:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 38640
#include<cstdio>

using namespace std;

int c[26];

int check(){
	for(int i = 0; i < 26; i++) if(c[i] >= 2) return 0;
	return 1;
}

int main(){
	char s[27]; scanf("%s", s);
	for(int i = 0; s[i] != '\0'; i++) c[s[i] - 'a']++;
	puts(check() ? "yes" : "no");
	return 0;
}

Measured memory_bytes: 128
import math

D, G = list(map(int, input().split()))
p = [list(map(int, input().split())) for _ in range(D)]
ResMin = 1000

for i in range(2**D):
    numProb = 0
    numPoint = 0
    maxProb = 0
    bonusflag = [0]*D
    for j in range(D):
        if ((i >> j) & 1):
            bonusflag[D-1-j] = 1

    for k in range(D):
        if bonusflag[k] == 1:
            numProb += p[k][0]
            numPoint += (100*(k+1)*p[k][0] + p[k][1])
        else:
            maxProb = k
    if numPoint < G:
        sub = math.ceil((G-numPoint)/(100*(maxProb+1)))
        if sub <= p[maxProb][0]:
            numProb += sub
        else:
            continue
    if numProb < ResMin:
        ResMin = numProb

print(ResMin)

Measured memory_bytes: 3188
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()


N = I()

ans = 0
b_start,a_end,b_start_a_end = 0,0,0
# Bで始まりAで終わらない文字列、Bで始まらずAで終わる文字列、Bで始まりAで終わる文字列の個数
for i in range(N):
    s = S()
    if s[0] == 'B' and s[-1] == 'A':
        b_start_a_end += 1
    elif s[0] == 'B':
        b_start += 1
    elif s[-1] == 'A':
        a_end += 1
    for j in range(len(s)-1):
        if s[j] == 'A' and s[j+1] == 'B':
            ans += 1

if b_start_a_end == 0:
    print(ans+min(b_start,a_end))
else:
    ans += b_start_a_end-1  # b_start_a_end == 1 として良い
    if a_end > 0:
        ans += 1
        a_end -= 1
    if b_start > 0:
        ans += 1
        b_start -= 1
    ans += min(b_start,a_end)
    print(ans)


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

int main(){
    ll a,b,n,x,ans;
    cin >> a >> b >> n;
    if(n<b-1){
        ans=(a*n)/b;
    }
    else{
        ans=(a*(b-1))/b;
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
	
	string n; cin >> n;
	char t = n[n.size() - 1];
	string ans;
	if (t == '0' || t == '1' || t == '6' || t == '8') {
		ans = "pon";
	}
	else if (t == '3') {
		ans = "bon";
	}
	else {
		ans = "hon";
	}

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

Measured memory_bytes: 3552
//
//  main.cpp
//  Problem Code
//
//  Created by Algo张伯威 on 2020/4/24.
//  Copyright © 2020 Algo张伯威. All rights reserved.
//

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <set>
using namespace std;

int c[20], a[20][20];
int now[20];
int n, m, x, ans = -1;

void check(int cost) {
    for(int i = 1; i <= m; i++) {
        if(now[i] < x) return;
    }
    if(ans == -1) ans = cost;
    else ans = min(ans, cost);
}

void dfs(int t, int cost) {
    if(t == n + 1) {
        check(cost);
        return;
    }
    dfs(t + 1, cost);
    for(int i = 1; i <= m; i++) {
        now[i] += a[t][i];
    }
    dfs(t + 1, cost + c[t]);
    for(int i = 1; i <= m; i++) {
        now[i] -= a[t][i];
    }
}

int main() {
    scanf("%d%d%d", &n, &m, &x);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &c[i]);
        for(int j = 1; j <= m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    dfs(1, 0);
    printf("%d\n", ans);
    
    return 0;
}






















Measured memory_bytes: 3824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            String str1 = strArr[0];
            int str1Length = str1.length();
            String str2 = strArr[1];
            int str2Length = str2.length();
            String str3 = strArr[2];
            if (str1.substring(str1Length - 1, str1Length).equals(str2.substring(0, 1)) && str2.substring(str2Length - 1, str2Length).equals(str3.substring(0, 1))) {
            	System.out.println("YES");
            } else {
            	System.out.println("NO");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 21460
#include <iostream>

int main()
{
	int i, N, M, a[51], b[51], n[51];
	std::cin >> N >> M;
	for ( i = 1; i <= N; i++ ){
		n[i] = 0;
	} 
	
	for ( i = 1; i <= M; i++ ){
		std::cin >> a[i] >> b[i];
		n[ a[i] ]++;
		n[ b[i] ]++;
	}

	for ( i = 1; i <= N; i++ ){
		std::cout << n[i] <<std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    string s; cin >> s;
    Int res = 0;
    Int apos = LLONG_MAX;
    rep(i, 0, s.size()) {
        if (s[i] == 'A') apos = min(apos, i);
        if (s[i] == 'Z') res = max(res, i-apos);
    }

    cout << res+1 << endl;
}


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

using namespace std;

#define int long long
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, K, h[100001];
int dp[100001];

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

    cin >> N >> K;
    for(int i = 0; i < N; ++i) cin >> h[i + 1];
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for(int i = 3; i <= N; ++i) {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        for(int j = 2; j <= K && i - j >= 1; ++j)
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1792
public class Main {
	int i=100100;
	long a[] =new long[i];
	String b[] =new String[i];
	int four=0,two=0,one=0;
	String str;
	String[] temp;
	public static void main(String[] args) {
		Main c=new Main();
		java.util.Scanner sc =new java.util.Scanner (System.in);
		String str=sc.nextLine();
		String[] temp=str.trim().split(" ");
		int n=(int) Long.parseLong(temp[0]);
		c.read_in(n,sc);
		c.check();
		sc.close();
	}
	public void read_in(int n, java.util.Scanner sc){
			str=sc.nextLine();
			temp=str.trim().split(" ");
		for(i=0;i<n;i++){
			a[i]= Long.parseLong(temp[i]);
			if(a[i]%4==0){
				four++;
			}
			else if(a[i]%2==0){
				two++;
			}
			else	one++;
		}		
	}
	public void check(){
		 if(one>four+1||(one==four+1&&two!=0)) 
			 System.out.println("No");
	      else System.out.println("Yes");
	}
}

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

using namespace std;

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

    int n;

    while (cin >> n, n) {
        vector<int> a(n);
        for (int i = 0; i < n; ++i) cin >> a[i];

        int ans = abs(a[n - 1] - a[0]);
        for (int i = 0; i < n - 1; ++i)
            for (int j = i + 1; j < n; ++j)
                ans = min(ans, abs(a[j] - a[i]));

        cout << ans << '\n';
    }

    return 0;
}



Measured memory_bytes: 3156
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 2e5 + 10;

int n;
int a[N], b[N], c[N];

inline int check(int x) {
	for (int i = 1; i <= n; ++i)	c[i] = a[i] >= x;
	int mid = 1 + n >> 1, l = mid, r = mid, res = c[mid];
	c[0] = c[1];
	for (; l >= 1 && c[l - 1] != c[l] && c[r + 1] != c[r]; --l, ++r)	res ^= 1;
	return res;
}

inline int solve() {
	int l = 1, r = n, res;
	while (l <= r) {
		int mid = l + r >> 1;
		if (check(b[mid]))	l = mid + 1, res = mid;
		else r = mid - 1;
	}
	return b[res];
}

int main() {
	
	scanf("%d", &n);
	n = n * 2 - 1;
	for (int i = 1; i <= n; ++i)	scanf("%d", a + i);
	for (int i = 1; i <= n; ++i)	b[i] = a[i];
	
	sort(b + 1, b + n + 1);
	
	printf("%d\n", solve());	
	
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int a,b;
    cin>>a>>b;
    cout<<max(a,b)+max(max(a,b)-1,min(a,b))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 3005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len;
ll dp[MAXN][MAXN],psa[MAXN][MAXN],res;
char arr[MAXN];

int main(){
	scanf("%d",&len);
	for(int i=2; i<=len; i++)
		scanf(" %c",&arr[i]);
	dp[1][1] = psa[1][1] = 1;
	for(int i=2; i<=len; i++){
		for(int k=1; k<=i; k++){
			if(arr[i] == '<'){
				if(k == 1) dp[i][k] = 0;
				else dp[i][k] = psa[i-1][k-1];
			}else{
				if(k == i) dp[i][k] = 0;
				else dp[i][k] = ((psa[i-1][i-1]-psa[i-1][k-1])%MOD+MOD)%MOD;
			}
			psa[i][k] = (psa[i][k-1]+dp[i][k])%MOD;
		}
	}
	for(int i=1; i<=len; i++)
		res = (res+dp[len][i])%MOD;
	printf("%lld\n",res);
}

Measured memory_bytes: 139648
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key))sum++;
  }
  printf("%d\n", sum);
  return 0;
}



Measured memory_bytes: 2048
a, b, c = map(int, input().split())
a_tmp = a ; b_tmp = b ; c_tmp = c
count = 0
while True :
    if a == b == c and a%2 == 0 :
        print("-1")
        break
    elif a%2 == 1 or b%2 == 1 or c%2 == 1 :
        print(count)
        break
    else :
        a = b_tmp/2 + c_tmp/2
        b = a_tmp/2 + c_tmp/2
        c = a_tmp/2 + b_tmp/2
        a_tmp = a ; b_tmp = b ; c_tmp = c
        count += 1


Measured memory_bytes: 9196
#include <stdio.h>
#define ARY 10000

int main(void){
	int i , j , n , ary[ARY+1] , max;
	for(i=1;i<ARY+1;i++){
		ary[i] = 1;
	}
	ary[1] = 0;
	for(i=2;i*i<=ARY;i++){
		for(j=2;j<=ARY;j++){
			if((i!=j)&&(j%i==0)) ary[j] = 0;
		}
	}
	while(1){
		scanf("%d" , &n);
		if(n==0) break;
		for(i=5;i<=n;i+=2){
			if(ary[i] && ary[i-2]) max = i;
		}
		printf("%d %d\n" , max-2 , max);
	}
	return 0;
}

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

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int main() {
  string x,y;
  std::cin >> x >> y;

  string op = "=";
  if(x < y) op = "<";
  else if(x>y) op = ">";
  cout << op << endl;

  return 0;
}


Measured memory_bytes: 256
A, B = map(int,input().split())

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

G = gcd(A, B)

ans = 1
d = 2
while d * d <= G:
  if G % d == 0:
    ans += 1
    while G % d == 0:
      G = (G // d)
  d += 1
if G > 1:
  ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int main() {
  double x1,y1,x2,y2;
  double dis=0.0;
  cin>>x1>>y1>>x2>>y2;
  dis=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
  cout<<fixed<<setprecision(6)<<dis<<endl;
  return 0;
}

Measured memory_bytes: 1284