akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}

		ptr = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return buflen > 0;
	}

	private int readByte() {
		return hasNextByte() ? buffer[ptr++] : -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		Map<Integer, Integer> cnt = new HashMap<Integer, Integer>();
		for (int i = 0; i < n; ++i) {
			int t = sc.nextInt();
			cnt.putIfAbsent(t, 0);
			cnt.put(t, cnt.get(t) + 1);
		}

		if (hasInvalidEntry(n, cnt)) {
			System.out.println(0);
			return;
		}

		final long MOD = 1000000007L;
		long ans = 1L;
		for (int i = 0, f = n / 2; i < f; ++i) {
			ans = ans * 2 % MOD;
		}
		System.out.println(ans);
	}

	static boolean hasInvalidEntry(int n, Map<Integer, Integer> cnt) {
		int nRest = n % 2;
		if (nRest == 0) {
			if (cnt.containsKey(0)) {
				return true;
			}
		} else if (cnt.getOrDefault(0, 32) != 1) {
			return true;
		}

		for (int i = 1; i < n; ++i) {
			if (i % 2 == nRest) {
				if (cnt.containsKey(i)) {
					return true;
				}
			} else if (cnt.getOrDefault(i, 32) != 2) {
				return true;
			}
		}
		return false;
	}
}


Measured memory_bytes: 30808
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		}
		int min = numbers[0];
		long max = -999999999999l;
		for(int i = 1; i < n; i++){
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 101304
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<string>
#include<cmath>
const int N = 1e5 + 7;
const int mod = 1e9 + 7;


int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    int n, e;
    cin>>n>>e;
    int a[n], u, v;
    for(int i =0; i<n; i++)
    a[i] = 0;
    for(int i = 0; i<e;i++)
    {
      cin>>u>>v;
      a[u-1] += 1;
      a[v-1] += 1;
    }

    for(int i = 0; i<n;i++)
    cout<<a[i]<<endl;






    return 0;
}



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

typedef unsigned long long ll;

int main() {
	int n;
	int h;
	cin >> n >> h;
	vector<pair<ll, ll> > data;
	for(int i=0; i<n; i++){
		ll a, b;
		cin >> a >> b;
		data.push_back(make_pair(b, a));
	}
	sort(data.begin(), data.end());
    reverse(data.begin(), data.end());
	int index=0;
	int max=0;
	for(int i=0; i<n; i++){
		if(data.at(i).second >= max){
			max = data.at(i).second;
			index = i;
		}
	}
	ll ans=0;
	int index2 = 0;
	bool which = true;
	while(h > 0 && index2 < n){
		if(data.at(index2).first >= data.at(index).second){
			h -= data.at(index2).first;
			ans++;
            index2++;
		}else{
			break;
		}
	}
	if(h > 0){
		ans += (h+data.at(index).second-1)/data.at(index).second;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2420
#include<stdio.h>
//小さい順にソート
long long c[100002][2];
void merge(int i,int j,long long s[][2]){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d][0]=s[b][0];
        c[d][1]=s[b][1];
        b++;
      }
      else if(j<b){
        c[d][0]=s[a][0];
        c[d][1]=s[a][1];
        a++;
      }
      else if(s[a][0]<s[b][0]){
        c[d][0]=s[a][0];
        c[d][1]=s[a][1];
        a++;
      }
      else{
        c[d][0]=s[b][0];
        c[d][1]=s[b][1];
        b++;
      }
    }
    for(d=i;d<=j;d++){
      s[d][0]=c[d][0];
      s[d][1]=c[d][1];
    }
  }
}

int main(){
  int n,i;
  long long m;
  scanf("%d%lld",&n,&m);
  long long a[n+1][2];
  for(i=0;i<n;i++)
    scanf("%lld%lld",&a[i][0],&a[i][1]);
  merge(0,n-1,a);
  long long count=0,money=0;
  i=0;
  while(count!=m){
    if(count+a[i][1]<m){
      count+=a[i][1];
      money+=a[i][0]*a[i][1];
      i++;
    }
    else{
      money+=a[i][0]*(m-count);
      count=m;
    }
  }
  printf("%lld\n",money);
  return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner scanner = new Scanner(System.in);
        long money = scanner.nextLong();
        long ans = 0;
        ans += money / 500 * 1000;
        ans += (money % 500) / 5 * 5;
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 2017 , mod = 1e9 + 7;
ll dp[N][N] , ps[N][N];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n , k; cin >> n >> k;
    dp[1][1] = ps[1][1] = 1; for(int j=1;j<=k;j++)ps[1][j] = 1;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=i;j++){
            dp[i][j] = ps[i - 1][j]; dp[i][j] %= mod;
            ps[i][j] = (ps[i][j - 1] + dp[i][j]) % mod;
        }
        for(int j=i+1;j<=k;j++)ps[i][j] = ps[i][i];
    }for(int i=0;i<n-k-1;i++)dp[n][k] = (dp[n][k] * 2) % mod;
    cout << dp[n][k] << '\n';
}


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

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;

int N, M;
int dp[5005][5005];
char s[5005];

int power(int x, int y)
{
    int p = x, r = 1;
    while(y)
    {
        if(y & 1)
            r = (1LL * r * p) % mod;
        p = (1LL * p * p) % mod;
        y >>= 1;
    }
    return r;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d\n", &N);
    scanf("%s", s);
    M = strlen(s);

    dp[0][0] = 1;
    /// dp[i][j] - i moves, j characters
    for(int i = 1; i <= N; i++)
    {
        dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
        for(int j = 1; j <= N; j++)
            dp[i][j] = ( (2 * dp[i - 1][j - 1]) % mod + dp[i - 1][j + 1] ) % mod;
    }

    int ans = dp[N][M];
    int p2 = power(2, M);
    int invp2 = power(p2, mod - 2);
    ans = (1LL * ans * invp2) % mod;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 98048
N = int(input())
count_AC = 0
count_WA = 0
count_TLE = 0
count_RE = 0
for _ in range(N):
  x = input()
  if x == 'AC':
    count_AC += 1
  elif x == 'WA':
    count_WA += 1
  elif x == 'TLE':
    count_TLE += 1
  else:
    count_RE += 1
print('AC x {}'.format(count_AC))
print('WA x {}'.format(count_WA))
print('TLE x {}'.format(count_TLE))
print('RE x {}'.format(count_RE))

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
ll a[2][3], res;
string S;

int main() {
	cin >> N >> S;
	res = 1;
	for (char c : S) {
		if (c == 'R') {
			if (a[1][0]) {
				res *= a[1][0];
				--a[1][0];
			}
			else if (a[0][1]) {
				res *= a[0][1];
				--a[0][1];
				++a[1][2];
			}
			else if (a[0][2]) {
				res *= a[0][2];
				--a[0][2];
				++a[1][1];
			}
			else {
				++a[0][0];
			}
		}
		if (c == 'G') {
			if (a[1][1]) {
				res *= a[1][1];
				--a[1][1];
			}
			else if (a[0][2]) {
				res *= a[0][2];
				--a[0][2];
				++a[1][0];
			}
			else if (a[0][0]) {
				res *= a[0][0];
				--a[0][0];
				++a[1][2];
			}
			else {
				++a[0][1];
			}
		}
		if (c == 'B') {
			if (a[1][2]) {
				res *= a[1][2];
				--a[1][2];
			}
			else if (a[0][0]) {
				res *= a[0][0];
				--a[0][0];
				++a[1][1];
			}
			else if (a[0][1]) {
				res *= a[0][1];
				--a[0][1];
				++a[1][0];
			}
			else {
				++a[0][2];
			}
		}
		res %= mod998;
	}
	for (ll i = 1; i <= N; ++i) {
		res *= i;
		res %= mod998;
	}
	cout << res << endl;
}

Measured memory_bytes: 900
import java.util.*;
public class Main {
	public static int ishuan(int n){
		int a1=n%10;
		int a2=n/10000;
		int b1=(n%100-n%10)/10;
		int b2=(n/1000-n/10000*10);
		if(a1==a2&&b1==b2){
			return 1;
		}else{
			return 0;
		}
		
		
	}
    public static void main(String[] args) {
        Scanner kb=new Scanner(System.in);
        while(kb.hasNext()){
        	int a=kb.nextInt();
        	int b=kb.nextInt();  
        	int sum=0;
        	for (int i = a; i <= b; i++) {
				int ans=ishuan(i);
				if(ans==1){
					sum++;
				}
			}
        	System.out.println(sum);
        }
              
    }

}

Measured memory_bytes: 23508
#include <stdio.h>

int calc(int,int);
int main()
{

  int a, b, x, y;

  scanf("%d%d",&a, &b);

  if(a >= b)
    {
      x = a;
      y = b;
    }
  else
    {
      x = b;
      y = a;
    }
  x = calc( x, y);
  
  printf("%d\n", x);
  
  return 0;
}

int calc(int x,int y)
{

  if(x % y == 0)return y;
  else return calc( y, x%y);
}



Measured memory_bytes: 2128
A,B,C,X,Y=map(int,input().split())
a1=C*max(X,Y)*2
a2=A*X+B*Y
if X>=Y:
    a3=A*(X-Y)+C*Y*2
else:
    a3=B*(Y-X)+C*X*2
print(min(a1,a2,a3))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x = i;
        if(i % 3 == 0)cout << " " << i;
        else{
            while(x > 0){
                if(x % 10 == 3){
                    cout << " " << i ;
                    break;

                }
                else x /= 10;
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 3044
package main
import(
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc=bufio.NewScanner(os.Stdin)
func nextInt() int{
  sc.Scan()
  i, e :=strconv.Atoi(sc.Text())
  if e!=nil{
    panic(e)
  }
  return i
}
func main(){
  var i, temp int
  x:=1
  flag:=false
  sc.Split(bufio.ScanWords)
  n:=nextInt()
  a:=make([]int, n)
  for i=0;i<n;i++{
    a[i]=nextInt()
    if a[i]==1{
      flag=true
      temp=i
    }
  }
  if flag==false{
    fmt.Println(-1)
    return
  }
  for i=temp;i<n;i++{
    if a[i]==x{
      x++
    }
  }
  fmt.Println(n-x+1)
}


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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test


const int max_nodes = 5e5;
using edge = int32_t;
vector<edge> g[max_nodes];
bool vis[max_nodes];
struct graph {
    static void reset(int n) {
        for (int i = 0; i <= n; ++i) {
            g[i].clear();
            vis[i] = false;
        }
    }
    graph(int n) { reset(n); }
    int dfs(int u, int par = -1) {
        vis[u] = 1;
        int c = 1;
        for (auto v: g[u]) {
            if (!vis[v]) {
                c += dfs(v, u);
            }
        }
        return c;
    }
    void add_edge(int u, int v) {
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    graph ins(n);
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        ins.add_edge(u, v);
    }
    for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
            ans = max(ans, ins.dfs(i));
        }
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 31128
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
//#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
ll pi = acos(-1) ;
ll z =  1000000007 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return (2*(i+1)) ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;

void solve()
{
    ll x, y , a , b , c ;
    cin >> x >> y >> a >> b >> c ;
    ll p[a] , q[b] , r[c] ;
    fo(i , a)
    {
        cin >> p[i] ;
    }
    fo(i , b)
    {
        cin >> q[i] ;
    }
    fo(i , c)
    {
        cin >> r[i] ;
    }
    sort(p , p + a) ;
    sort(q , q + b) ;
    sort(r , r + c) ;
    reverse(p , p+a) ;
    reverse(q , q + b) ;
    reverse(r , r+c) ;

    /*fo(i , a)
    {
        cout << p[i] << ' ';
    }
    cout << endl ;*/

    multiset<ll> red , green ;
    fo(i , x)
    {
        red.insert(p[i]) ;
    }
    fo(i , y)
    {
        green.insert(q[i]) ;
    }
    fo(i , c)
    {
        ll curr = r[i] ;
        ll curr_r = (*(red.begin())) ;
        ll curr_g = (*(green.begin())) ;

        if(curr_r < curr_g)
        {
            if(curr_r < curr)
            {
                red.erase(red.begin()) ;
                red.insert(curr) ;
            }
            
        }
        else
        {
            if(curr_g < curr)
            {
                green.erase(green.begin()) ;
                green.insert(curr) ;
            }
        }
    }
    ll ans = 0 ;
    auto itr = red.begin() ;
    for(; itr != red.end() ; itr++)
    {
        ans += (*itr) ;
    }
    for(auto itrg = green.begin() ; itrg != green.end() ; itrg++)
    {
        ans += (*itrg) ;
    }
    cout << ans << endl ;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("inputf.txt" , "r" , stdin) ;
    // freopen("outputf.txt" , "w" , stdout) ;
    // freopen("error.txt" , "w" , stderr) ;
    // #endif
    
    ll t ;
    //cin >> t ;
    t = 1 ;
    while(t--)
    {
        solve() ;
    }
    return 0;
}

Measured memory_bytes: 11008
n = int(input())
a_list = list(map(int,input().split(" ")))
a_list = [A-(i+1) for i,A in enumerate(a_list)]

a_list = sorted(a_list)
if n%2 != 0:
    median = a_list[int((n-1)/2)]
else:
    median = int((a_list[int((n+1)/2)]+a_list[int((n-1)/2)])/2)

sad = 0
for a in a_list:
    sad += abs(a - median)
print(sad)

Measured memory_bytes: 25196
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  int cnt = 0;
  cin >> s >> t ;
  for(int i = 0;i < 3;i++){
    if (s[i]==t[i]) {
      cnt ++;
    }
  }
  cout << cnt << "\n" ;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


int main(){
   std::ios::sync_with_stdio(false);
   cin.tie(0);
ll n ;
cin>>n;

vector<ll>v(n+1,1);
for(ll index = 2 ; index <=n;index++)
{
    for(ll j = index;j<=n;j+=index)
    v[j]++;
}

v[0]=0;
ll ans =0;

for(int c = 1 ;c<n;c++)
{
   ans+=v[n-c];

}

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


Measured memory_bytes: 11068
N = gets.to_i
btn = Array.new(N, true)
a = []
cnt = 0

N.times do
  a << gets.to_i
end

nxt = 0
loop do
  break if btn[nxt] == false
  btn[nxt] = false
  nxt = a[nxt]-1
  cnt += 1
  if nxt == 1
    puts cnt
    exit
  end
end

puts -1

Measured memory_bytes: 3892
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(l: usize) -> (Vec<(usize, usize, usize)>, usize) {
    let mut ans = Vec::new();

    let mut acc = Vec::new();

    for i in 0.. {
        let k = 1 << i;
        if k > l { break }
        if (k & l) > 0 {
            acc.push((i,k));
        }
    }

    let (i, r) = acc.pop().unwrap();

    for j in 1..(i+1) {
        ans.push((j, j+1, 0));
        ans.push((j, j+1, 1 << (j-1)));
    }

    let mut r = r;
    for &(j, k) in acc.iter().rev() {
        ans.push((j+1, i+1, r));
        r += k;
    }

    (ans, i+1)
}

fn main() {
    let l = parse_line!(usize);

    let (s, n) = solve(l);
    println!("{} {}", n, s.len());

    for (a,b,c) in s {
        println!("{} {} {}", a, b, c);
    }
}



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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main() {
  int N;
  cin >> N;
  cout << N/3 <<endl;
}
      

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}

int main()
{
    string s, t;
    cin >> s >> t;
    int count = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] != t[i])
        {
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
int main(){
    string n;
    cin >> n;
    int ans=0;
    int num=n.size();
    for(int i=0;i<num/2;i++){
        if(n[i]!=n[num-1-i]){
            ans++;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
t=int(input())
d=dict()
d["AC"]=0
d["WA"]=0
d["TLE"]=0
d["RE"]=0
for i in range(t):
  a=input()
  d[a]=d[a]+1
print("AC","x",d["AC"])  
print("WA","x",d["WA"])  
print("TLE","x",d["TLE"])  
print("RE","x",d["RE"])  


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

typedef long long ll;

const ll mod = 1e9 + 7;
const int N = 402;

void add(ll &a, ll b) { a = (a + b) % mod; }

int n, C, l[N], r[N];
ll dp[N][N], pw[N][N], seg[N][N];

void precalc() {
	for (int i = 1; i < N; i++) {
		pw[i][0] = 1;
		for (int j = 1; j < N; j++)
			pw[i][j] = (pw[i][j - 1] * i) % mod;
	}
	for (int i = 0; i < n; i++) 
		for (int j = 0; j < N; j++) {
			for (int k = l[i]; k <= r[i]; k++)
				add(seg[i][j], pw[k][j]);
		}
}

ll rec(int pos, int c) {
	if (pos == n) return c == 0;
	if (dp[pos][c] != -1) return dp[pos][c];
	ll res = 0;
	for (int i = 0; i <= c; i++) {
		ll nxt = seg[pos][i] * rec(pos + 1, c - i);
		nxt %= mod;
		add(res, nxt);
	}
	return dp[pos][c] = res;
}

int main() {
	cin >> n >> C;
	for (ll i = 0; i < n; i++)
		cin >> l[i];
	for (ll i = 0; i < n; i++)
		cin >> r[i];
	precalc();
	memset(dp, -1, sizeof dp);
	cout << rec(0, C);
}


Measured memory_bytes: 7408
#include <stdio.h>
#include <math.h>

unsigned int  prime[999999];

int main(void)
{
    unsigned int i, j;
    int n;
    int count;
    unsigned int sq_n;
    while (scanf("%d", &n) != EOF){
        count = 0;
         sq_n = (int)sqrt((double)n);
        for (i = 0; i < n; i++){
            prime[i] = 1;
        }
        prime[0] = 0;

        for (i = 1; i < sq_n; i++){
            if (prime[i] == 1){
                for (j = (i + 1); (i + 1) * j <= n; j++){
                    prime[(i + 1) * j - 1] = 0;
                }
            }
        }

        for (i = 0; i < n; i++){
            if (prime[i] == 1){
                count++;
            }
        }
        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 4500
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

int n, q;
int s[100001], t[50001];
int ans = 0;

int main(){
	std::cin >> n;
	rep(i, n)std::cin >> s[i];
	std::cin >> q;
	rep(i, q)std::cin >> t[i];

	std::sort(s, s + n);
	std::sort(t, t + q);

	rep(i, q){
		if (std::binary_search(s, s + n, t[i]))++ans;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1760
#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>;
const int MOD=1000000007;

int main() {
  vector<char> a(4);
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  sort(a.begin(),a.end());
  cout << (a[0]==a[1]&&a[2]==a[3]&&a[1]!=a[2]? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
d = int(input())
c = list(map(int, input().split()))
s = []
lastDays = [0]*26

for _ in range(d):
  s.append(list(map(int, input().split())))

for i in range(d):
  kouho = 0
  kouhoHyouka = -999999999999
  for j in range(26):
    if s[i][j] - c[j] * (i + 1 - lastDays[j]) > kouhoHyouka:
      kouho = j
      kouhoHyouka = s[i][j] - c[j] * (i + 1 - lastDays[j])
  lastDays[j] = i+1
  print(kouho+1)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int N, M;
bool G[10][10];
ll ans = 0;
vector<int> path;
bool used[10];

void check() {
    rep(i, path.size() - 1) {
        if (!G[path[i]][path[i + 1]]) return;
    }
    ans++;
}

void f(int i) {
    if (i == N) {
        check();
        return;
    }

    if (i == 0) {
        used[0] = true;
        path.push_back(0);
        f(i + 1);
    } else {
        for (int j = 1; j < N; j++) {
            if (used[j]) continue;
            used[j] = true;
            path.push_back(j);
            f(i + 1);
            used[j] = false;
            path.pop_back();
        }
    }
}

int main() {
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a][b] = true;
        G[b][a] = true;
    }
    f(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define vi   vector<int>
#define vvi  vector<vi >
#define vvvi vector<vvi >
#define pii  pair<int,int>
#define INF  (int)1e9
#define MOD  (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n;
	cin>>n;
	
	vector<string> s(n);
	vector<char> c(10);
	REP(i,n){
		REP(j,10) cin>>c[j];
		sort(ALL(c));
		s[i]="";
		REP(j,10) s[i]+=c[j];
	}
	sort(ALL(s));
	
	llong ans=0;
	llong cnt=1;
	for(int i=1;i<n;++i){
		if(s[i-1]==s[i]) cnt++;
		else{
			if(cnt>=2) ans+=(cnt*(cnt-1))/2;
			cnt=1;
		}
	}
	if(cnt>=2) ans+=(cnt*(cnt-1))/2;
	
	cout<<ans<<endl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
vector<int> match[1000010];
int tans[1000010];
bool exist[1000010];

int dfs(int v, int c)
{
	if (c == N * N)
	{
		return INF;
	}
	if (tans[v] != 0)
	{
		return tans[v];
	}
	int res = 1;
	for (auto e : match[v])
	{
		chmax(res, dfs(e, c + 1) + 1);
		if (res >= INF)
		{
			tans[v] = INF;
			return INF;
		}
	}
	tans[v] = res;
	return res;
}

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

	cin >> N;
	int a;
	int pa = -1;
	rep(i, 0, N)
	{
		pa = -1;
		rep(j, 0, N - 1)
		{
			cin >> a;
			a--;
			exist[min(i, a)*N + max(i, a)] = true;
			if (pa != -1)
			{
				match[min(i, pa)*N + max(i, pa)].push_back(min(i, a)*N + max(i, a));
			}
			pa = a;
		}
	}

	int ans = 0;
	rep(i, 0, N*N)
	{
		if (exist[i] && tans[i] == 0)
		{
			chmax(ans, dfs(i, 0));
		}
	}

	if (ans == INF)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 110592
N=int(input())
# 105 = 3 * 5 * 7
# 135 = 3 * 3 * 3 * 5
# 165 = 3 * 5 * 11
# 189 = 3 * 3 * 3 * 7
# 195 = 3 * 5 * 13
if N < 105:
    print(0)
elif N < 135:
    print(1)
elif N < 165:
    print(2)
elif N < 189:
    print(3)
elif N < 195:
    print(4)
else:
    print(5)


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

using ll = long long;
using ld = long double;

int main()
{
    string ans;
    string s;
    cin >> s;
    int ls[4];
    string op[] = {"+","-"};
    
    for(int i = 0; i < 4; i++)
    {
        ls[i] = s.at(i)-'0';
    }
    
    
    for(int bit = 0; bit < (1<<3); bit++)
    {
        int tmp = ls[0];
        
        for(int i = 0; i < 3; i++)
        {
            if(((bit>>i)& 1)== 0)//plus
            {
                tmp+=ls[i+1];
            }
            
            else
            {
                tmp-=ls[i+1];
            }
            
        }
        if(tmp==7)
        {
            
            for(int j = 0; j < 3; j++)
            {
                cout << ls[j] << op[(bit>>j) & 1];
            }
            cout << ls[3] << "=7" << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
//#include <bits/stdc++.h>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAX 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

int main() {
  ll N,K;
  cin >> N>>K;
	ll h[N];
  ll dp[N];
  
	FOR(i,0,N-1){
		cin>>h[i];
    dp[i]=LLONG_MAX;
	}
	dp[0]=0;
  dp[1]=abs(h[0],h[1]);
	FOR(i,2,N-1){
    ll cost=LLONG_MAX;
    FOR(j,1,K){
      if(i-j>=0){
        ll tmp=dp[i-j]+abs(h[i],h[i-j]);
        cost=min(cost,tmp);
      }
  //cout<<cost<<endl;
    }
    dp[i]=cost;
	}
  cout<<dp[N-1]<<endl;

	FOR(i,0,N-1){
  //cout<<dp[i]<<endl;
	}

}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
class ilds1_4_c{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    bool[] f = new bool[(int)Math.Pow(5,12)];
    for(int i=0; i<n; i++){
      String[] str = Console.ReadLine().Split(' ');
      if(str[0].Equals("insert")){
        f[str2num(str[1])] = true;
      }
      else{
        if(f[str2num(str[1])]){
          Console.WriteLine("yes");
        }
        else{
          Console.WriteLine("no");
        }
      }
    }
  }
  public static int str2num(String s){
    int ret = 0;
    int mul = 1;
    for(int i=s.Length-1; i>=0; i--){
      ret += hash(s[i])*mul;
      mul *= 4;
    }
    return ret;
  }
  public static int hash(char c){
    int ret = -1;
    switch(c){
      case 'A':
        ret = 1;
        break;
      case 'T':
        ret = 2;
        break;
      case 'G':
        ret = 3;
        break;
      case 'C':
        ret = 4;
        break;
      default:
        break;
    }
    return ret;
  }
}



Measured memory_bytes: 24468
N=list(map(int,list(input())))

for n in range(2**3):
    sum_N=N[0]
    l=[]
    for i in range(3):
        if (n>>i)&1==1: #convert from decimal to binary and shift right
            sum_N+=N[i+1]
            l.append("+")
        else:
            sum_N-=N[i+1]
            l.append("-")
    if sum_N==7:
        break
print("{}{}{}{}{}{}{}".format(N[0],l[0],N[1],l[1],N[2],l[2],N[3])+"=7")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;  
int sum[100001];  
int main()  
{  
    int n;  
    while(scanf("%d",&n)!=EOF)  
    {  
        int a;  
        memset(sum,0,sizeof(sum));  
        for(int i=1;i<=n;i++)  
        {
            scanf("%d",&a);  
            sum[a+1]++;  
            sum[a-1]++;  
            sum[a]++;  
        }  
        sort(sum,sum+100001);  
        printf("%d\n",sum[100000]);  
    }  
    return 0;  
}  


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

int main(void) {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int cnt = 0;
  for(int i=0;i<=100;i++){
    if(a <= i && i < b && c <= i && i < d)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#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(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    int ai = a[n-1];
    auto itr = lower_bound(a.begin(), a.end(), (a[n-1]+1)/2);
    int aj;
    int x = *itr;
    itr--;
    int y = *itr;
    if(a[n-1] % 2 == 0){
        if(a[n-1]/2 - y <= x - a[n-1]/2) aj = y;
        else aj = x;
    }
    else{
        if(a[n-1]/2 - y <= x - (a[n-1]+1)/2) aj = y;
        else aj = x;
    }
    cout << ai << ' ' << aj << endl;
}

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

int main() {
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << a[n-1];
	for (int i = n-2; i >= 0; i--) {
		cout << " " << a[i] ;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    bool a = false, b = false;

    if(s.length() % 2 == 0) a = true;
    if(s[0] == s[s.length() - 1]) b = true;

    if(a ^ b) cout << "Second" << endl;
    else cout << "First" << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <unordered_map>
#include <queue>

using namespace std;

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

    string s;
    int h, w, k, arr[10][10], ans = 0;
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) {
        cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '#') {
                arr[i][j] = 1;
            } else {
                arr[i][j] = 0;
            }
        }
    }
    for (int maskR = 0; maskR < (1 << h); maskR++) {
        for (int maskC = 0; maskC < (1 << w); maskC++) {
            int cnt = 0;

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (arr[i][j] && !((maskR >> i) & 1) && !((maskC >> j) & 1)) {
                        cnt++;
                    }
                }
            }

            if (cnt == k) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

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

int main() {
int N, ans;
  cin >> N;
  ans =0;
  vector<int> a(N-1);
  rep(i, N-1){
    cin >> a.at(i);
  }
  ans += a.at(0);
  ans+=a.at(a.size()-1);

  if(N >= 3){
    rep(i, N-2)
  ans += min(a.at(i), a.at(i+1));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
  input! {
    n: usize,
    s: String,
  }

  let mut cnt : [i64; 3] = [0; 3];
  let cs = s.chars().collect::<Vec<_>>();

  for &c in &cs {
    match c {
      'R' => cnt[0] += 1,
      'G' => cnt[1] += 1,
      'B' => cnt[2] += 1,
      _ => (),
    }
  }

  let mut count = 0;
  for i in 0..n {
    for j in 0..i {
      let k = 2 * i - j;
      if k >= n {
        continue;
      }
      let mut vec = vec![cs[i], cs[j], cs[k]];
      vec.sort();
      if vec == vec!['B', 'G', 'R'] {
        count += 1;
      }
    }
  }
  println!("{}", cnt[0] * cnt[1] * cnt[2] - count);
}

Measured memory_bytes: 2188
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int N, T;
  cin >> N >> T;
  int t[N];
  for(int i=0; i<N; i++) {
    cin >> t[i];
  }
  int ans=0;
  for(int i=0; i<N; i++) {
    if(t[i+1]-t[i]<=T) {
      ans+=t[i+1]-t[i];
    }
    else {
      ans+=T;
    }
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;
int a[201];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        ++a[i];
        for (int j = i + i; j <= n; j += i) {
            ++a[j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (a[i] == 8 && (i & 1))
            ++ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
/*
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define r(i,s,l) for(int i=s;i<l;i++)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<long long,long long>
#define ss second
#define ff first
#define N 2000005
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main(){
    fast();
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    r(i,0,n)
    cin>>a[i];
    int dp[n];
    r(i,0,n)
    dp[i]=INT_MAX;
    dp[0]=0;
    r(i,0,n)
    r(j,1,k+1)
    {
        if(i+j<=n)
        dp[i+j]=min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));
    }
    cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    string N; cin >> N;
    int keta = N.length();
    bool check = 1;
    FOR(i,1, keta)
    {
        if(N[i] != '9') check = 0;
    }

    int ans = 9 * (keta - 1); 
    if(check) ans += N[0] - '0';
    else ans += (N[0] - '0') - 1;

    cout << ans << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    set<char> h;
    for(int i = 0; i < n; i++)
    {
        char a;
        cin >> a;
        h.insert(a);
    }
    if(h.size() == 4) cout << "Four" << endl;
    else cout << "Three" << endl;
}


Measured memory_bytes: 256
import os, sys, re, math

memo = {}
def attack(h):
    result = memo.get(h)
    if result:
        return result
    if h == 1:
        result = 1
    else:
        result = 1 + attack(h // 2) * 2
    memo[h] = result
    return result

H = int(input())

print(attack(H))


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

int busstop[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

int main(){
	int n,s,g,count,k,a;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> s >> g;
		count = 1000000000;
		for(int j = 0;j < 15;++j){
			if(busstop[j] == s){
				int tmp = 0;
				k = j;
				while(busstop[k] != g){
					++k;
					k%=15;
					++tmp;
				}
				if(tmp < count){
					count = tmp;
					a = j;
				}
			}
		}
		while(busstop[a] != g){
			cout << busstop[a++] << " ";
			a  %= 15;
		}
		cout << g << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        System.out.println(Math.min(B / A, C));
    }
}

Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csignal>
#include <csetjmp>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <functional>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include<new>
#include <numeric>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int N;
struct ss{
    int x, y, h;
} a[101];
int num=0;
int cx, cy;
int main() {
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>a[i].x>>a[i].y>>a[i].h;
    }
    for(cx=0;cx<101;cx++){
        for(cy=0;cy<101;cy++){
            num=0;
            bool check=true;
            int hig=0;
            for(int i=1;i<=N;i++){
                if(a[i].h>0) hig=max(abs(a[i].x-cx)+abs(a[i].y-cy)+a[i].h,0);
            }
            for(int i=1;i<=N;i++){
                if(a[i].h!=max(hig-(abs(a[i].x-cx)+abs(a[i].y-cy)),0)) check=false;
            }
            if(check&&hig!=0){
                cout<<cx<<" "<<cy<<" "<<hig<<endl;
                return 0;
            }
        }
    }
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
const int INF = 1000000009;

long x, y;
int main(){
	std::cin >> x >> y;
	long ans = 0;
	while(y >= x){
		y /= 2;
		ans++;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
#define PI 3.14159265359

int main(){
  int x;
  cin >> x;
  if(x ==0) cout << "1" << endl;
  else cout << "0" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	long long res=0;
	
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j+=i)res+=j;
	
	cout<<res;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int n,a,b,c,x;
	int i1;
	int count;
	int y;
	int check;
	int x2;

	while(1){
		cin >> n >> a >> b >> c >> x;
		if (n==0 && a==0 && b==0 && c==0 && x==0) break;
		
		count=0;
		x2=x;
		for(i1=0;i1<n;i1++){
			cin >> y;

			if (y==x && i1==0) continue;

			while(1){
				if (count>10000) break;
				
				x2=(a*x2+b)%c;
				count++;
				if (y==x2) break;
			}
		}

		if (count>10000) cout << -1 << endl;
		else cout << count << endl;

		
	}
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n,m; scanf("%d%d",&n,&m);
   vector<int> t(m),c(m);
   rep(i,0,m)scanf("%d%d",&t[i],&c[i]);
   rep(i,0,1000){
      string s=to_string(i);
      if(s.size()!=n)continue;
      bool f=1;
      rep(j,0,m){
         if(s[t[j]-1]!=c[j]+'0')f=0;
      }
      if(f){
         printf("%d\n",i);
         return 0;
      }
   }
  cout<<-1<<endl;
   return 0;
}

Measured memory_bytes: 256