akhauriyash/Code-Regression huggingface dataset:
str = gets.split
H,W = str[0].to_i, str[1].to_i
s = Array.new(H){Array.new(W,0)}
t = Array.new(H){Array.new(W,0)}

for i in 0...H do
    str = gets.chomp
    for j in 0...W do
        if str[j] == "#"
            s[i][j] = 1
        end
    end
end

t[0][0] = s[0][0]
for i in 1...W do
    t[0][i] = t[0][i-1]
    if t[0][i] % 2 != s[0][i] % 2
        t[0][i] += 1
    end
end
for i in 1...H do
    t[i][0] = t[i-1][0]
    if t[i][0] % 2 != s[i][0] % 2
        t[i][0] += 1
    end
end

for i in 1...H do
    for j in 1...W do
        if t[i-1][j] < t[i][j-1]
            t[i][j] = t[i-1][j]
        else
            t[i][j] = t[i][j-1]
        end
        if t[i][j] % 2 != s[i][j] % 2
            t[i][j] += 1
        end
    end
end

answer = (t[H-1][W-1]+1)/2
puts answer

Measured memory_bytes: 2044
//abc145_c.cpp
//Sat Nov 16 20:53:11 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<double,double> P;

int main(){
	double n;
	cin >> n;

	vector<P> p;
	for (int i=0;i<n;i++){
		double x,y;
		cin >> x >> y;
		p.push_back(make_pair(x,y));
	}

	double temptotal = 0;
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (i==j){
				continue;
			}else {
				double tempx = pow(p[i].first-p[j].first,2);
				double tempy = pow(p[i].second-p[j].second,2);
				temptotal += sqrt(tempx+tempy);
			}
		}
	}

	double waru = 1;
	for (int i=1;i<=n;i++){
		waru *= i;
	}
	double ans = temptotal/n;

	printf("%.8f\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)


int main() {
  int k,x;
  cin>>k>>x;
  if(k*500>=x){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=505,L=1e9;
int mp[N][N],n,m,h,w,k;ll sum,sk;
int main(){
	scanf("%d%d%d%d",&n,&m,&h,&w);
	if(h==1&&w==1)return puts("No"),0;
	k=(L-1)/(h*w-1),sum=1ll*k*(n*m-(n/h*h)*(m/w*w));
	sk=1ll*k*(h*w-1)+1;
	if((n/h)*(m/w)>sum)return puts("No"),0;
	puts("Yes");
	for(R int i=h;i<=n;i+=h)for(R int j=w;j<=m;j+=w)mp[i][j]=1;
	fp(i,1,n){
		fp(j,1,m)printf("%d ",mp[i][j]?-sk:k);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3968
N = int(input())

mylist = []

flag = True
while (flag):
    sho = N // 26
    amari = N % 26
    kurisagari = False
    if amari == 0 :
        mylist.append(26)
        kurisagari = True
    else:
        mylist.append(amari)

    if sho < 27:
        flag = False
        if kurisagari:
            mylist.append(sho - 1)
        else:
            mylist.append(sho)
    else:
        if kurisagari:
            N = sho - 1
        else:
            N = sho
# print(mylist)

num2alpha = lambda c: chr(c+96)

alphabet_list = [num2alpha(i) for i in mylist]
# alphabet_list = alphabet_list[::-1]

print(''.join(alphabet_list[::-1]).strip("`"))


Measured memory_bytes: 9208
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from heapq import heappush, heappop


def dijkstra(graph: list, start, INF=float('inf')) -> list:
    n = len(graph)
    dist = [INF] * n
    visited = [False] * n

    dist[start] = 0
    que = [(0, start)]

    while que:
        cost, cur = heappop(que)

        if visited[cur]:
            continue

        visited[cur] = True

        for nextnode, edgecost in graph[cur]:
            nextcost = cost + edgecost
            if nextcost < dist[nextnode]:
                dist[nextnode] = nextcost
                heappush(que, (nextcost, nextnode))

    return dist

n, m, s, t = li()
s -= 1
t -= 1

yen_graph = [[] for _ in range(n)]
snk_graph = [[] for _ in range(n)]

for _ in range(m):
    u, v, a, b = li()
    u -= 1
    v -= 1

    yen_graph[u].append((v, a))
    yen_graph[v].append((u, a))
    snk_graph[u].append((v, b))
    snk_graph[v].append((u, b))

yen_dist = dijkstra(yen_graph, s)
snk_dist = dijkstra(snk_graph, t)

initial = 10**15

ans = [-1]*n
for i in range(n-1, -1, -1):
    if i == n-1:
        ans[i] = initial - (yen_dist[i] + snk_dist[i])

    else:
        ans[i] = max(ans[i+1], initial - (yen_dist[i] + snk_dist[i]))

for ansi in ans:
    print(ansi)

Measured memory_bytes: 125548
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		int[][] adjMatrix = new int[totalVertex][totalVertex];
		Iterator<LinkedList<Integer>> list = adjList.iterator(); 
		int i = 0;
		int j = 0; 
		while(list.hasNext()) {
			LinkedList<Integer> temp = list.next();
			while(j < temp.size()) {
				int num = temp.get(j);
				adjMatrix[i][num] = 1;
				j++;
			}//ends while
			j = 0;
			i++;
		}//ends while
		
		for(int k = 0; k< totalVertex; k++) {
			for(int l = 0; l< totalVertex; l++) {
				if(l == totalVertex - 1) System.out.print(adjMatrix[k][l]);
				else System.out.print(adjMatrix[k][l] + " ");
				
			}
			System.out.println();
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main{
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}


Measured memory_bytes: 32576
#include <iostream>
#include<cmath>
#include<vector>
 int insertion_sort(std::vector<int> &a, int n, int gap) {
	int count = 0;
	for (int i = gap; i < n; ++i) {
		int v = a[i];
		int j = i - gap;
		while (j >= 0 && a[j] > v) {
			a[j + gap] = a[j];
			j -= gap;
			count++;
		}
		a[j + gap] = v;
	}
	return count;
}
void shell_sort(std::vector<int>& a, int n) {
	std::vector< int>gaps(11, 1);
	for (int i = 1; i < 11; ++i) {
		gaps[i] = pow(4, i) + 3 * std::pow(2, i - 1) + 1;
	}
 //{ 1,8,23,77,281,1073,4193,16577,65921,262913,1050113 };
	
	int gap_num = 0, count = 0;
	while (gaps[gap_num + 1] < n) { gap_num++; }
	for (int i = gap_num; i >= 0; --i) { count += insertion_sort(a, n, gaps[i]); }
	std::cout << (gap_num + 1) << '\n';
	for (int i = gap_num; i; --i) std::cout << gaps[i] << ' ';
	std::cout << gaps[0] << '\n';
	std::cout << count << '\n';
}
int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	std::cin >> n;
	std::vector<int> a(n, 0);
	for (int i = 0; i < n; ++i) {
		std::cin >> a[i];
	}
	shell_sort(a, n);
	for (int i = 0; i < n; ++i) { std::cout << a[i] << '\n'; }
}

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

using namespace std;

typedef unsigned long long int ull;

void printInBinary(ull n)
{
    char bin32[] = "00000000000000000000000000000000";
    
    for(int i = 31; i >= 0 && n; i--)
    {
        if(n & 1)
            bin32[i] = '1';
        n >>= 1;
    }
    
    cout << bin32 << "\n";
}

int main() 
{
    ull x, y, z;
    cin >> x >> y;
    
    z = (x & y);
    
    printInBinary(z);
    
    z = (x | y);
    
    printInBinary(z);
    
    z = (x ^ y);
    
    printInBinary(z);
    
    return 0;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, i;
	cin >> N >> i;

	cout << N - i + 1 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<int, int> mp;
    int ans = 0;
    rep(i, 0, n){
        int a;
        cin >> a;
        mp[a]++;
    }
    for(auto it = mp.begin(); it != mp.end(); it++){
        if(it -> second >= it -> first) ans += it -> second - it -> first;
        else ans += it -> second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6272
n, k = [int(x) for x in input().split()]
s = set()

for i in range(k):
	d = int(input())
	s.update([int(x) for x in input().split()])

ans = 0

for x in range(1,n+1):
	if x not in s:
		ans += 1

print(ans)

Measured memory_bytes: 9184
x,n=map(int,input().split())
p=input().split()
if p.count(str(x))==0:
  print(x)
  exit()
i=1
while True:
 x=x-i
 if p.count(str(x))==0:
  print(x)
  exit()
 x=x+2*i
 if p.count(str(x))==0:
  print(x)
  exit()
 x=x-i
 i=i+1

Measured memory_bytes: 9192
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=10e5+3;
long long arr[N];

int main()
{


/*

int n,x,y;
cin>>n>>x>>y;
for(int i=0;i<n;i++){

    cin>>a[i]>>b[i];

}
for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
    if(i!=j){
    double res=(b[i]-b[j])*(a[i]-a[j]); }
int t=slope[0]; int counter=1;
for(int i=1;i<slope.size();i++){
    if(slope[i]!=t) counter++;
    t=slope[i];



    slope.push_back(res);

}
for(auto x: slope)cout<<x<<" ";
//if(counter==0){cout<<1; return 0;}
cout<<counter;
/*




}


*/
long long n;
cin>>n;
long long int mini=10e7;
for(int i=0;i<n;i++)cin>>arr[i];
for(int i=n-1;i>0;i--){
    if(arr[i]<arr[i-1]){
arr[i-1]--;
        if(arr[i-1]>arr[i]){cout<<"No"; return 0;}

    }
   


}

cout<<"Yes";









}

Measured memory_bytes: 1024
N = int(input())
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26 == 0:
        return num2alpha(num // 26 - 1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
print(num2alpha(N).lower())

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int dp[3010][6010] = {};

int main(){
    int n, t;
    cin >> n >> t;
    vector<pii> dish(n);
    for (int i = 0; i < n; ++i) {
        cin >> dish[i].first >> dish[i].second;
    }
    sort(dish.begin(), dish.end());

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < t; ++j) {
            dp[i+1][j+dish[i].first] = max(dp[i+1][j+dish[i].first], dp[i][j] + dish[i].second);
        }
        for (int j = 0; j < 6010; ++j) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }

    int res = 0;
    for (int i = t; i < 6010; ++i) {
        res = max(res, dp[n][i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 70656
import sys

# n:参考書の数
# m:アルゴリズム数
# x:目標の理解度
# arr[0]:C円, …理解度UP値
n, m, x = map(int, input().split())
arr = []
for i in range(n):
    c = list(map(int, input().split()))
    arr.append(c)

# 最小コストを求める
ret = sys.maxsize
for i in range(2**n):
    _cost = 0
    _know = [0] * m
    for j in range(n):
        if i & (1 << j):
            for k in range(m):
                _know[k] += arr[j][1+k]
            _cost += arr[j][0]

    # 目標に達しているかチェック
    flag = True
    for j in range(m):
        if _know[j] < x:
            flag = False
            break

    if flag and ret > _cost:
        ret = _cost

if ret == sys.maxsize:
    ret = -1

print("{}".format(ret))

Measured memory_bytes: 9136
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	/*int n;
	cin >> n;
	if (n % 2 == 0)cout << n / 2;
	else cout << n / 2 + 1;*/

	int bingo[3][3];
	for(int i=0;i<3;i++)
		for (int j = 0; j < 3; j++)
		{
			cin >> bingo[i][j];
		}
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int b = 0;
		cin >> b;
		for(int j=0;j<3;j++)
			for (int k = 0; k < 3; k++)
			{
				if (bingo[j][k] == b)bingo[j][k] = -1;
			}
	}
	
	for (int i = 0; i < 3; i++) {
		int ans = 0;
		for (int j = 0; j < 3; j++)
		{
			if (bingo[i][j] == -1)ans += 1;
			if (ans == 3) { cout << "Yes"; exit(0); }
		}
		ans = 0;
		for (int j = 0; j < 3; j++)
		{
			if (bingo[j][i] == -1)ans += 1;
			if (ans == 3) { cout << "Yes"; exit(0); }
		}
	}
	int dog = bingo[0][0] + bingo[1][1] + bingo[2][2];
	if(dog==-3) { cout << "Yes"; exit(0); }
	int cat = bingo[0][2] + bingo[1][1] + bingo[2][0];
	if(cat==-3) { cout << "Yes"; exit(0); }
	cout << "No";
	return 0;
}



Measured memory_bytes: 3600
n = int(input())
a_list = list(map(int, input().split()))
b_list =list(map(int, input().split()))
ans = 0
for i in range(n-1,-1,-1):
    if a_list[i+1] >= b_list[i]:
        a_list[i+1] -=b_list[i]
        ans += b_list[i]
    elif a_list[i+1] < b_list[i]:
        ans += a_list[i+1]
        ans += min(a_list[i], (b_list[i]-a_list[i+1]))
        a_list[i] = max(0,a_list[i] -(b_list[i]-a_list[i+1]))
        a_list[i+1]=0

    #print(a_list)
print(ans)

Measured memory_bytes: 24192
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main(string[] args) {
        string s;
        while (!string.IsNullOrEmpty(s = Console.ReadLine())) {
            string[] ss = s.Split(' ');
            int a = int.Parse(ss[0]);
            int b = int.Parse(ss[1]);
            Console.WriteLine((a + b).ToString().Length);
        }
    }
}       

Measured memory_bytes: 8976
def test():
    a,b,c,d = map(int,input().split())
    if abs(a-c) <= d:
        print("Yes")
    elif  abs(a-b)<= d and abs(b-c) <= d:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    test()


Measured memory_bytes: 2940
#include<iostream>
#include<numeric>
#include<cmath>
#include<vector>
#include<string>

using namespace std;

int main() {
	int  a, b;

	cin >>a >>b;

    if((a*b)%2==0){
    cout<<"Even"<<endl;
    }else{
    cout<<"Odd"<<endl;
    
    }
    
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
ll dp[101][100001];
ll dp2[101][100001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n>>k;
    	ll ar[n];
    	for(int i=0;i<n;i++)
    	{
    		cin>>ar[i];
    		dp[i+1][0] = 1;
    		dp2[i+1][0] = 1;
    	}
    	dp[0][0] = 1;
    	dp2[0][0] = 1;
		for(int j=1;j<=k;j++)
    	{
    		dp2[0][j]=1;
    		for(int i=1;i<=n;i++)
    		{
    			ll val = ar[i-1];
    			if(val>=j)
    			{
    				dp[i][j] = (dp2[i-1][j]);
    			}
    			else
    			{
    				dp[i][j] = (dp2[i-1][j] - dp2[i-1][j-val-1] +mod )%mod; 
    			}
    			// dp[i][j]+=;
    			dp2[i][j] += (dp2[i][j-1] + dp[i][j])%mod;
    			dp2[i][j] %= mod;
    			// cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<dp2[i][j]<<endl;
    		}
    	}
    	cout<<dp[n][k]<<endl;
    }
    return 0;
}

Measured memory_bytes: 158080
#include <iostream>

#include <string>
#include <vector>

using namespace std;
 
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=0;i<n;i++)
#define ll long long int


int main(){
  cin.tie(NULL);
  cout.tie(NULL);
  int n,a,b;
  cin >> n >> a >> b;
  if(abs(a-b)%2 == 0){
    cout << "Alice"<<endl;
  }else{
    cout << "Borys" << endl;
  }

  return 0;
}

Measured memory_bytes: 764
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define per(i,a,b) for(int i = (a); i >= (b); i--)
#define mst(a,b) memset(a,b,sizeof(a));
#define clr(a) mst(a,0);
#define pb  push_back
#define mp  make_pair
#define first fi
#define second se
int dir[4][2] = {1,0,-1,0,0,1,0,-1};
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const double PI = acos(-1);
//head

int k,ans = 0;

int main(int argc, char const *argv[]){

	cin >> k;
	for(int i = 1; i <= k; i++){
		for(int j = i+1; j <= k; j++){
			if(i&1 && j&1) continue;
			if(!(i&1) && !(j&1)) continue;
			ans++;
		}
	}
	cout << ans << endl;

	
	return 0;
}












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

using namespace std;

int main() {
  int i, j;

  int n;
  while(cin >> n && n) {
    vector<int> a;
    a.reserve(1000000);

    int sm = 0;
    for(i = 0; i < n; ++i) {
      int p;
      cin >> p;
      a.push_back(p);
      sm += p;
    }

    sm *= 2;
    for(i = 1; i * (i + 1) < sm; ++i) ;
    if(i * (i + 1) > sm) {
      cout << -1 << endl;
      continue;
    }

    for(i = 0; i <= 10000; ++i) {
      for(j = 0; j < (int)a.size() && a[j] == j + 1; ++j) ;
      if(j >= (int)a.size()) break;

      for(j = 0; j < (int)a.size(); ++j)
        --a[j];
      a.push_back(a.size());
      a.erase(remove(a.begin(), a.end(), 0), a.end());
    }

    cout << (i > 10000 ? -1 : i) << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>

using namespace std;

int main() {
	long long a, b, k;

	cin >> a >> b >> k;

	if((k - a) >= 0) {
		if((k - a) >= b) {
			b = 0;
		} else {
			b = b - (k - a);
		}
		a = 0;
	} else {
		a = a - k;
	}

	cout << a << ' ' << b << '\n';

	return 0;
}


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

string s;
int k,ans;

main(){
cin>>s>>k;
for(int i=0;i<s.size();i++){if(s[i]!='1'){ans=s[i]-'0';break;}}
if(k<=100)
for(int i=0;i<k;i++){
if(s[i]!='1'){ans=s[i]-'0';break;}
else ans=1;
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<n/i-1;i++){
        if(n%i==0){
            ans+=n/i-1;
        }
    }
    cout<<ans<<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>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    string s;
    cin >> s;
    int a = 0, b = 0;
    rep(i,s.size()) {
        if (s[i] == '0') a++;
        else b++;
    }
    int ans = 2*min(a,b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3728
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        sx: isize,
        sy: isize,
        tx: isize,
        ty: isize,
    }

    fn print(c: char, n: isize) {
        for _ in 0..n as usize {
            print!("{}", c);
        }
    }

    print('U', ty-sy);
    print('R', tx-sx);
    print('D', ty-sy);
    print('L', tx-sx+1);
    print('U', ty-sy+1);
    print('R', tx-sx+1);
    print('D', 1);
    print('R', 1);
    print('D', ty-sy+1);
    print('L', tx-sx+1);
    print('U', 1);

    println!("");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    
    int ok = 1;
    int N = S.size();
    
    for (int i=0; i<N/2; i++) {
        if (S.at(i) != S.at(N - i - 1)) {
            ok = 0;
            break;
        }
    }
    
    int N2 = (N-1)/2;
    for (int i=0; i<N2/2; i++) {
        if (S.at(i) != S.at(N2 - i - 1)) {
            ok = 0;
            break;
        }
    }
    
    for (int i = (N+3)/2 -1; i<N-1; i++) {
        int j= i-((N+3)/2 -1);
        if (S.at(i) != S.at(N-j-1)) {
            ok = 0;
            break;
        }
    
    }
    
    if (ok == 1){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <map>
#define pb push_back
#define ll long long
using namespace std;
int N,K;
int dp[10000005],a[105];
int main()
{
    int i,j;
    cin>>N>>K;
    for(i=1;i<=N;i++)
    {
        cin>>a[i];
    }
    //Vom completa DP cu 1 daca castiga primul jucator si respectiv 2, daca castiga al doilea
    for(i=0;i<=K;i++)//numarul de posibile luari de pietre
        for(j=1;j<=N;j++)//numarul de pietre luate
    {
        if(i-a[j]>=0 && dp[i-a[j]]==2)
        {
            dp[i]=1;
            break;
        }
        dp[i]=2;
    }
    //N-numarul de pietre posibile
    //K-numarul initial de pietre
    cout<<(dp[K]==1?"First":"Second");
    return 0;
}


Measured memory_bytes: 640
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    di = {}
    for i, a in enumerate(A):
        di[i] = - a + i + 1

    di = sorted(di.items(), key=lambda x: x[1])
    md = di[len(di) // 2][1]

    ret = 0
    for d in di:
        ret += abs(md - d[1])

    print(ret)


if __name__ == '__main__':
    main()


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for(int i = 0; i < n; i++){
    if(i == 0){
      cin >> a.at(0) >> b.at(0) >> c.at(0);
    }
    else{
      int ai, bi, ci;
      cin >> ai >> bi >> ci;
      a.at(i) = max(b.at(i-1), c.at(i-1)) + ai;
      b.at(i) = max(a.at(i-1), c.at(i-1)) + bi;
      c.at(i) = max(a.at(i-1), b.at(i-1)) + ci;
    }
  }
  cout << max(a.at(n-1), max(b.at(n-1), c.at(n-1))) << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int a, b, c, x, y;
    int ans;

    cin >> a >> b >> c >> x >> y;

    int cand_1 = 2 * c * min(x, y) + ((x > y) ? a: b) * abs(x - y);
    int cand_2 = 2 * c * max(x, y);
    int cand_3 = a * x + b * y;

    ans = min(cand_1, cand_2);
    ans = min(ans, cand_3);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rip(a,b) for(int (a)=0;(a)<(b);(a)++)
using namespace std;

int main(){
    string S;
    cin >> S;
    if(S[2]==S[3]&&S[4]==S[5]){
        cout << "Yes" << endl; 
    }else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
n = int(input())
cands = set([])

def dfs(s,l,k):#str, len,kinds
  if l == n:
    cands.add(s)
  else:
    for i in range(k):
      dfs(s+chr(97+i), l+1,k)
    dfs(s+chr(97+k),l+1,k+1)

dfs('',0,0)
ans = list(cands)
ans.sort()
for a in ans:
  print(a)

Measured memory_bytes: 17088
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
memo=dict()
def rec(v):
    if v in memo:return memo[v]
    res=0
    for nv in graph[v]:
        res=max(res,rec(nv)+1)
    memo[v]=res
    return res
def main():
    n,m=map(int,input().split())
    XY=[tuple(map(int,input().split())) for i in range(m)]
    global graph
    graph=[[]for _ in range(n)]
    for x,y in XY:
        graph[x-1].append(y-1)
    ans=0
    for v in range(n):
        ans=max(ans,rec(v))
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 80924
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int ans, n;

void dfs(long long a, int cnt3, int cnt5, int cnt7){
    if(a > n) return;
    if(cnt3 > 0 && cnt5 > 0 && cnt7 > 0){
        ans++;
    }
    dfs(10 * a + 3, cnt3 + 1, cnt5, cnt7);
    dfs(10 * a + 5, cnt3, cnt5 + 1, cnt7);
    dfs(10 * a + 7, cnt3, cnt5, cnt7 + 1);
}

int main(){
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << ans << endl;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n, m; std::cin >> n >> m;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) {
        std::cin >> ab[i].fi >> ab[i].se;
    }
    sort(rng(ab));
    ll ans = 0;
    rep(i, n) {
        if (m > ab[i].se) {
            m -= ab[i].se;
            ans += ab[i].fi * ab[i].se;
        } else {
            ans += ab[i].fi * m;
            m = 0;
        }
        if (m == 0) break;
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <chrono>
#include <vector>

using namespace std;

int main()
{
    int K, N;
    cin >> N >> K;
    long long cnt_mod_k = 0;
    long long cnt_mod_k_half = 0;
    for (int i = 1; i <= N; i++)
    {
        if (i % K == 0)
        {
            cnt_mod_k += 1;
        }
        else if (K % 2 == 0 && i % K == K / 2)
        {
            cnt_mod_k_half += 1;
        }
    }
    long long ans = pow(cnt_mod_k, 3) + pow(cnt_mod_k_half, 3);
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N; cin >> N;
  int a[100010];
  for ( int i = 1; i <= N; i++ ) cin >> a[i];
  int i = 1;
  int cnt = 0;
  while(1){
    if ( cnt >= N + 2 ) {
      cout << -1 << endl;
      return 0;
    }
    i = a[i];
    cnt++;
    if ( i == 2 ) {
      cout << cnt << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 768
import numpy as np
from collections import defaultdict
from heapq import heappush, heappop
from math import ceil


def djkstra_adj_list(adj_list, src):
    dist = defaultdict(lambda: np.inf)
    dist[src] = 0

    prev = defaultdict(lambda: None)

    queue = []
    heappush(queue, (dist[src], src))

    while len(queue) > 0:
        dist_u, u = heappop(queue)
        vs = adj_list[u]
        for v, weight in vs:
            alt = dist_u + weight
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
                heappush(queue, (alt, v))

    return dist, prev


def djkstra_adj_mat(adj_mat, src):
    dist = defaultdict(lambda: np.inf)
    dist[src] = 0

    prev = defaultdict(lambda: None)

    queue = []
    heappush(queue, (dist[src], src))

    while len(queue) > 0:
        dist_u, u = heappop(queue)
        vs = np.argwhere(adj_mat[u] > 0).flatten()
        for v in vs:
            weight = adj_mat[u, v]
            alt = dist_u + weight
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
                heappush(queue, (alt, v))

    return dist, prev


def main():

    N = int(input())
    As = []
    for _ in range(N):
        A = int(input())
        As.append(A)
    As = np.array(As, dtype=np.int)

    i_max = np.argmax(As)

    A_max = As[i_max]
    if np.sum(As == A_max) > 1:
        for i in range(N):
            print(A_max)
    else:
        A_max2 = np.max(As[As != A_max])
        for i in range(N):
            if i == i_max:
                print(A_max2)
            else:
                print(A_max)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21816
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
long long modinv(long long a){//a ÷ b mod. MOD の求め方 : a * modinv(b) % MOD
    long long b = MOD, u = 1, v = 0;
    while(b){
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if(u < 0) u += MOD;
    return u;
}
 
signed main(){
    ll n,k;
    cin >> n >> k;
    vector<P> v(n);
    REP(i,n){
        cin >> v[i].first;
        v[i].second = i;
    }
    ll a[n];
    REP(i,n){
        int cnt = 0;
        for(int j = i + 1; j < n; j++){
            if(v[j].first < v[i].first){
                cnt++;
            }
        }
        a[i] = cnt;
    }
    sort(ALL(v));
    ll d[n];
    d[v[0].second] = 0;
    for(int i = 1; i < n; i++){
        if(v[i - 1].first < v[i].first){
            d[v[i].second] = i;
        }else{
            d[v[i].second] = d[v[i - 1].second];
        }
    }
    ll ans = 0;
    REP(i,n){
        ans += (k * 2 * a[i]) / 2 % MOD + k % MOD * (k - 1) % MOD * d[i] % MOD * modinv(2) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import numpy as np

def main():
    N = int(input().strip())
    arr = np.zeros(N, np.int32)
    for i in range(N):
        arr[i] = int(input().strip())
    arr2 = np.sort(arr)[::-1]
    max1, max2 = arr2[0], arr2[1]

    for i in range(N):
        print(max1) if arr[i] != max1 else print(max2)

if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int dp[10001];

int main(){
  int n,w;cin>>n>>w;
  rep(i, n){
    int cv, cw;cin>>cv>>cw;
    rrep1(tw, w) if(tw-cw>=0)dp[tw] = max(dp[tw], dp[tw-cw] + cv);
  }
  
  cout<<dp[w]<<endl;

  return 0;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, Y;
    cin >> N >> Y;
    
    int a = -1, b = -1, c = -1;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N-i; j++) {
            if (10000*i + 5000*j + 1000*(N-i-j) == Y && N-i-j >= 0) {
                a = i;
                b = j;
                c = N-i-j;
                break;
            }
        }
    }
    
    cout << a << " " << b << " " << c << endl;
    
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> T deg2rad(T deg) {return deg*2*M_PI/360;}
template<class T> T rad2deg(T rad) {return rad*360/(2*M_PI);}

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

const ll MOD=1e9+7;
const ll MAX=5e6;

int main() {
  int N;cin>>N;
  vector<int> LS(N);
  REP(i,N) cin>>LS[i];
  sort(ALL(LS));

  // 真ん中の長さの辺Yでループする
  // 真ん中より下の辺Xをその左側からループで選んで、右側でlower_bound(X+Y)のところより下の数をカウント
  ll ans=0;
  FOR(i,1,N-1) {
    REP(j,i) {
      ans += lower_bound(ALL(LS),LS[i]+LS[j])-LS.begin()-i-1;
    }
  }
  OUT(ans);

  return 0;
}

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

int main() {
	string s; cin >> s;
	int len = s.length();
	bool ok = false;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	int cnt = 0;
	
	for (int i = 2; i < len - 1; i++) {
		if (s[i] == 'C') {
			cnt++;
		}
	}
	if (cnt > 1 || cnt == 0) {
		cout << "WA" << endl;
		return 0;
	}
	int cnt2 = 0;
	for (int i = 1; i < len; i++) {
		if (s[i] >= 'A' && s[i] <= 'Z')
			cnt2++;
		if (cnt2 > 1) {
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << "AC" << endl;
	return 0;
}


Measured memory_bytes: 256
// #include<bits/stdc++.h>
// #define lli long long int
// #define MOD 1000000007
// #define KING 1000000002
// #define queen 1000002
// #define fi first
// #define se second
// #define se second
// #define lsb(i) (i & -i)
// #define nl cout<<'\n'
// #define TEST cout<<"TEST",nl
// #define pr pair<lli,lli>
// #define pb push_back
// #define eb emplace_back
// #define mp make_pair
// #define vi vector<lli>
// #define vpi vector<pr> 
// #define P pair<lli,pr>
// #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
// #define NA(i,s,n) for(lli i=s;i<n;i++)
// using namespace std;

// void solve(){
//     lli n; cin>>n;
//     vi a(n+1), b(n+1, 0), c(n+1, 0);
//     set<lli> s1, s2;
//     NA(i,1,n+1) {
//         cin>>a[i];
//         s1.insert(a[i]);
//         if(*(s1.rbegin()) == i && s1.size()==i) b[i] = 1;
//     }
//     for(lli i=n; i>0; --i){
//         s2.insert(a[i]); 
//         if(*(s2.rbegin()) == (n-i+1) && s2.size()==(n-i+1)) c[i]=1;
//     }
//     lli res = 0; vi ans;
//     NA(i,1,n) if(b[i] && b[i]==c[i+1]) ++res, ans.pb(i);
//     cout<<res; nl;
//     for(lli i:ans) cout<<i<<' '<<n-i<<'\n';
//     return; 
// }
// int main(){
//     fastIO;
//     lli t = 1; cin>>t; 
//     NA(i,0,t) {
//         // cout<<"Case #"<<(i+1)<<": ";
//         solve();
//     }
//     return 0;
// }


#include<bits/stdc++.h>
#define lli long long int
#define NA(i,s,n) for(lli i=s; i<n; ++i)
#define nl cout<<'\n'
using namespace std;

lli n, k, c = 0, d = 0, m;
int main(){

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
    cin>>n>>m;
    lli a[n]; NA(i,0,n) cin>>a[i], d+=a[i];
    double f = d / (4.0 * m); // cout<<f<<'\n';
    NA(i,0,n){
        if(a[i]>=f) c++;
    }
    if(c>=m) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int N;
vector<vector<int>> item;

int main() {
    cin >> N;
    item = vector<vector<int>>(N, vector<int>(3));
    rep(i, N) cin >> item[i][0] >> item[i][1] >> item[i][2];

    // 状態 (i,prev) : i 日たって，前回 prev の遊びをした状態
    // ma(i,prev) : 状態(i,prev) での幸福度の最大値

    // もらうDP
    vector<vector<int>> ma(N + 1, vector<int>(3, -1));
    ma[0][0] = ma[0][1] = ma[0][2] = 0;

    for (int i = 1; i <= N; i++) {
        for (int prev = 0; prev < 3; prev++) {
            for (int k = 0; k < 3; k++) {
                if (prev == k) continue;
                ma[i][prev] =
                    max(ma[i][prev], ma[i - 1][k] + item[i - 1][prev]);
            }
        }
    }
    int ans = -1;
    for (int i = 0; i < 3; i++) {
        ans = max(ma[N][i], ans);
    }
    // cout << ans << endl;

    // 配るDP
    vector<vector<int>> maa(N + 1, vector<int>(3, -1));
    for (int i = 0; i < 3; i++) {
        maa[0][i] = 0;
    }
    for (int i = 0; i < N; i++) {
        for (int from = 0; from < 3; from++) {
            for (int to = 0; to < 3; to++) {
                if (from == to) continue;
                maa[i + 1][to] =
                    max(maa[i + 1][to], maa[i][from] + item[i][to]);
            }
        }
    }
    ans = -1;
    for (int i = 0; i < 3; i++) {
        ans = max(ma[N][i], ans);
    }
    cout << ans << endl;

    return 0;
}

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

class baseball{
    private:
    int runner; //number of runner
    int score; //score
    int out_count; //counter of out
    int third_base; //runner is or not
  
    public:
    void initial();
    int getScore();
    int getOutCount();
    void singleHit_1();
    void singleHit_2();
    void homerun();
    void out();
    
};

//initialize
void baseball::initial(){
    runner = 0;
    score = 0;
    out_count = 0;
    third_base = 0;
}

int baseball::getScore(){
    return score;
}

int baseball::getOutCount(){
    return out_count;
}

/*
update runner
 */
void baseball::singleHit_1(){
    if(runner < 3){
        ++runner;
    }
}

/*
increment of score
 */
void baseball::singleHit_2(){
    ++score;
}

/*
clear runner
and
add {(number of runner) + 1} to score
 */
void baseball::homerun(){
    score = score + (runner + 1);
    runner = 0;
}

/*
increment of out_count
 */
void baseball::out(){
    ++out_count;
}

int main(void){
    baseball bb;

    int n;
    std::cin >> n;

    std::string str;
    int count = 0; //counter of hit
    
    bb.initial();
    for(int i = 0; i < n; i++){
        while(bb.getOutCount() < 3){
	    std::cin >> str;
	    if(str == "HIT"){
	        ++count;
		if(count < 4){ //runner is less than 3
		    bb.singleHit_1();
		} else if(count >= 4){ //runner is 3
		    bb.singleHit_2();
		}
	    } else if(str == "HOMERUN"){
	        bb.homerun();
		count = 0;
	    } else if(str == "OUT"){
	        bb.out();
	    }
	}
	std::cout << bb.getScore() << std::endl;
	bb.initial();
	count = 0;
    }
    
    return 0;
}

Measured memory_bytes: 3004
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC113_C();
        }

        static void ABC113_C()
        {
            var NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NM[0];
            var M = NM[1];
            var PY = new Dictionary<string, string>();
            var dict = new Dictionary<int, List<int>>();

            for (var m = 0; m < M; m++)
            {
                var py = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                if (!dict.ContainsKey(py[0]))
                    dict.Add(py[0], new List<int>());

                PY.Add($"{py[0]}{py[1]}", "");
                dict[py[0]].Add(py[1]);
            }

            foreach (var key in dict.Keys)
            {
                if (dict[key].Count > 1)
                    dict[key].Sort();
            }

            foreach (var key in dict.Keys)
            {
                var number = 1;
                foreach (var year in dict[key])
                {
                    PY[$"{key}{year}"] = $"{key:000000}{number:000000}";
                    number++;
                }
            }

            foreach (var value in PY.Values)
                Console.WriteLine(value);
        }
    }
}

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

int main(){
	string s;
	string p;
	int i,len;
	cin>>s;
	cin>>p;
	len=s.size();
	for(i=0 ; i<len ; i++){
		s.push_back(s[i]);
	}
	if(s.find(p)!=string::npos){
		cout << "Yes" << endl;			
	} else {
		cout << "No" << endl;
	}
	return 0;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }


int main() {
  lint n,k; cin >> n >> k;
  vector<int> a(n); for(lint i=0;i<n;i++) { cin >> a[i]; }

  vector<int> b(n,0);
  for(lint i=0;i<n;i++) { b[a[i]-1]++; }
  sort(b.begin(),b.end(),greater<int>());

  lint ans=0;
  for(lint i=k;i<n;i++) { ans += b[i]; }

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

Measured memory_bytes: 1792
#正負で分割
#dpの作り方はARCの方の人のロジックを参考にした。
#こんなんでええんや...
def 解():
    iN,iA =[int(x) for x in input().split()]
    aX = [int(x) - iA for x in input().split()]
    aPlus = [x for x in aX if 0 < x ]
    aMinus = [-1 * x for x in aX if x < 0  ]
    iLenPlus = len(aPlus)
    iLenMinus = len(aMinus)
    iLen0 = iN - iLenPlus - iLenMinus

    iCZero = 2**iLen0 - 1 #sum(k=1..N){nCk} = 2^n -1

    iRet = 0
    iRet += iCZero
    iCZero += 1 #0の場合を追加

    iUlim = min(sum(aPlus) , sum(aMinus))
    if 0 < iUlim:
        dp1 = {0:1}
        for iX in aPlus:
            for k,v in dp1.copy().items():
                dp1[k+iX] = dp1.get(k+iX,0)+v
        dp2 = {0:1}
        for iX in aMinus:
            for k,v in dp2.copy().items():
                dp2[k+iX] = dp2.get(k+iX,0)+v
        for i in range(1,iUlim+1):
            if i in dp1 and i in dp2:
                iRet += iCZero * dp1[i] * dp2[i]
    print(iRet)
解()


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

int main()
{
	int n, d[101];

	cin >> n;

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

	sort(d + 1, d + n + 1);

	int count = 1;

	for (int i = 1; i < n; i++)
	{
		if (d[i] < d[i + 1])
		{
			count++;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256