akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

const int maxN=101;
const int maxVal=1e5;
const long long INF=(1LL<<60);

int n,w;
int wei[maxN];
int val[maxN];

long long dp[maxVal+1];

int main(){
    cin>>n>>w;
    for(int i=1;i<=n;i++){
        cin>>wei[i]>>val[i];
    }

    for(int i=0;i<=maxVal;i++){
        dp[i]=INF;
    }

    dp[0]=0;
    for(int i=1;i<=n;i++){
        for(int j=maxVal;j>=val[i];j--){
            dp[j]=min(dp[j],dp[j-val[i]]+wei[i]);
        }
    }

    long long sol=0;
    for(int i=0;i<=maxVal;i++){
        if(dp[i]<=w){
            sol=max(sol,1LL*i);
        }
    }

    cout<<sol;

    return 0;
}

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

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();

  int a;
  int p;
  String q1;
  String[] q2;
  int q=0;
  int sum=0;
for(a=1;a<=n;a++){
    p=a%10;
    q1=String.valueOf(a);
    q2=q1.split("");
    q=Integer.parseInt(q2[0]);
if(p==0){
  continue;
}
if(p==q&&p!=n){
  sum=sum+(Math.min(p,n)-n)/(p-n);
}
if(p==q&&p==n){
  sum=sum+1;
}
if(10*p+q!=n){
  sum=sum+(Math.min(10*p+q,n)-n)/(10*p+q-n);
}
if(10*p+q==n){
  sum=sum+1;
}
  
if(100*p+q<=n&&n<=100*p+90+q){
  sum=sum+(n-100*p-q)/10+1;
}
if(100*p+90+q<n){
  sum=sum+10;
}
  
if(1000*p+q<=n&&n<=1000*p+990+q){
  sum=sum+(n-1000*p-q)/10+1;
}
if(1000*p+990+q<n){
  sum=sum+100;
}

if(10000*p+q<=n&&n<=10000*p+9990+q){
  sum=sum+(n-10000*p-q)/10+1;
}
if(10000*p+9990+q<n){
  sum=sum+1000;
}
  
if(100000*p+q<=n&&n<=100000*p+99990+q){
  sum=sum+(n-100000*p-q)/10+1;
}
if(100000*p+99990+q<n){
  sum=sum+10000;
}

}
System.out.println(sum);
}
}

Measured memory_bytes: 94320
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int a,b,k;
  cin>>a>>b>>k;
  for(int i=0;i<k;i++){
    if(i%2==0){
      a/=2;
      b+=a;
    }else{
      b/=2;
      a+=b;
    }
  }
  cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i,j,H,W;
    while(scanf("%d %d\n",&H,&W),H>0&&W>0){
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                putchar((i+j)%2==0?'#':'.');
            }
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}



Measured memory_bytes: 2140
#include<iostream>
using namespace std;
int h[100010],n;int v[100010];
int js(int a,int b){return a>b?a-b:b-a;}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){scanf("%d",&h[i]);}
	v[0]=0;v[1]=js(h[1],h[0]);
	for(int i=2;i<n;i++){v[i]=min(v[i-1]+js(h[i],h[i-1]),v[i-2]+js(h[i],h[i-2]));}
	cout<<v[n-1]<<endl;
}

Measured memory_bytes: 1024
import numpy as np
# スペース区切りの整数の入力
X, N = map(int, input().split())

if N == 0:
    print(X)
    exit(0)

P = np.array(list(map(int, input().split())))

## sec2
for i in range(101):
    if sum(P == X - i) == 0:
        print(X - i)
        exit(0)
    if sum(P == X + i) == 0:
        print(X + i)
        exit(0)


Measured memory_bytes: 27284
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(input())
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i], _ = strconv.Atoi(input())
	}
	ans := "Yes"

	for i := n - 1; i > 0; i-- {
		if h[i] < h[i-1] {
			if h[i] == h[i-1]-1 {
				h[i-1]--
			} else {
				ans = "No"
				break
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 3072
n, m, x = map(int, input().split())
books = []
for i in range(n):
	books.append(tuple(map(int, input().split())))

def combinations():
	from itertools import product
	
	for i in product([0, 1], repeat = n):
		lst = []
		for j in range(n):
			if i[j] == 1:
				lst.append(books[j])
		yield lst

ans = 10**9
for books_bought in combinations():
	level = [0]*m
	cost = 0
	for book in books_bought:
		cost += book[0]
		for i in range(m):
			level[i] += book[i + 1]
		
	for num in level:
		if num < x:
			break
	else:
		ans = min(ans, cost)

if ans == 10**9:
	print (-1)
else:
	print (ans)		

Measured memory_bytes: 9216
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <cassert>
#define SIZE 200005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[SIZE],DM[SIZE];
int dr[SIZE],ch[SIZE];
int n,m;

bool left(int p)
{
	for(int i=0;i<m;i++)
	{
		if(str[p]-'A'==ch[i])
		{
			p+=dr[i];
			if(p<0) return true;
			if(p>=n) return false;
		}
	}
	return false;
}
bool right(int p)
{
	for(int i=0;i<m;i++)
	{
		if(str[p]-'A'==ch[i])
		{
			p+=dr[i];
			if(p>=n) return true;
			if(p<0) return false;
		}
	}
	return false;
}
int main()
{
	scanf("%d %d",&n,&m);
	scanf("%s",&str);
	for(int i=0;i<m;i++)
	{
		scanf("%s",&DM);
		ch[i]=DM[0]-'A';
		scanf("%s",&DM);
		if(DM[0]=='L') dr[i]=-1;
		else dr[i]=1;
	}
	int ret=n;
	int l=-1,r=n;
	while(r-l>1)
	{
		int d=(l+r)/2;
		if(left(d)) l=d;
		else r=d;
	}
	ret-=r;
	l=-1,r=n;
	while(r-l>1)
	{
		int d=(l+r)/2;
		if(right(d)) r=d;
		else l=d;
	}
	ret-=n-r;
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>

int main()
{
    int ca[256] = {};
    int cnt = 0;
    char ch;

    for (int i = 0; i < 4; i++) {
        ch = getchar();

        if (!ca[ch]) {
            cnt++;
            ca[ch] = 1;
        }
    }

    if (cnt == 2) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define SUBIF(a, b, x) ((x) ? (b) : (a))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


double n;


bool judge(double x){
	return (x == (int)x);
}


string solve(){
	n *= 16;
	if(!judge(n)) return "NA";
	int N = (int)n;
	string bin;
	do {
		bin.pb('0'+(N&1));
	} while(N/=2);
	string integer, decimal;
	reper(i, 3, 0) decimal.pb(bin[i]);
	rep(i, 0, 12-SIZE(bin)) integer.pb('0');
	reper(i, SIZE(bin)-1, 4) integer.pb(bin[i]);
	return integer+'.'+decimal;
}


signed main(){
	while(cin >> n, 0 <= n) cout << solve() << endl;

	return 0;
}


Measured memory_bytes: 3140
n=int(input())
A=list(map(int,input().split()))
ans=1
for i in range(n):
  if A[i]==0:
    print(0)
    exit()
for i in range(n):
  #if len(str(A[i]))>19:
   # print(-1)
   # exit()
  ans*=A[i]
  if ans>10**18:
    print(-1)
    exit()
print(ans)

Measured memory_bytes: 21800
#include <stdio.h>

int main()
{
	int d, n, x=1;
	
	scanf("%d %d", &d, &n);
	
	while(d--) x *= 100;
	
	if(n == 100) printf("%d", 101*x);
	else printf("%d", n*x);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main(){
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
 
	int d1 = e-a;

 
	if(d1>k){
	cout << ":(" << endl;
	}else {
	cout << "Yay!" << endl;
	}
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
signed main(){
    io();
    int n; cin >> n;
    vector<ll> a(n + 1), b(n);
    for(int i = 0; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> b[i];
    }
    ll tot = 0;
    for(int i = 0; i < n; ++i){
        if(b[i] >= a[i]){
            tot += a[i];
            b[i] -= a[i];
        }else{
            tot += b[i];
            b[i] = 0;
        }
        if(b[i] >= a[i + 1]){
            tot += a[i + 1];
            a[i + 1] = 0;
        }else{
            tot += b[i];
            a[i + 1] -= b[i];
        }
    }
    cout << tot << '\n';
    return 0; 
}

Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string S,T;cin>>S>>T;
	int ans=inf;
	rep(i,len(S)-len(T)+1){
		int cnt=0;
		rep(j,len(T))if(S[i+j]!=T[j])cnt++;
		chmin(ans,cnt);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3656
def main():
    A,B,K = (int(_) for _ in input().split())

    lowerNum = A
    if A > B :
        lowerNum = B

    th_counter = 0
    for i in range(lowerNum,0,-1):
        if A % i == 0 and B % i == 0 :
            th_counter += 1
            if th_counter == K:
                print(i)
                break

if __name__ == '__main__':
    main()


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

int main() {
  int64_t H;
  cin >> H;
  int64_t k = 1;
  
  while(H >= k){
    k = k*2;
  }
  
  cout << k-1 << endl;

}

Measured memory_bytes: 256
// 最大流を求めるアルゴリズム

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int INF = INT_MAX;

struct Edge {
  int to;
  int cap;
  int rev;

  Edge(int to = -1, int cap = -1, int rev = -1) {
    this->to = to;
    this->cap = cap;
    this->rev = rev;
  }
};

const int MAX_V = 20010;
bool used[MAX_V];
int H, W;
int start;
int goal;
vector <Edge> G[MAX_V];

void add_edge(int from, int to, int cap) {
  if (from == to || from == start) {
    to += (H * W);
  } else {
    from += (H * W);
  }
  G[from].push_back(Edge(to, cap, G[to].size()));
  G[to].push_back(Edge(from, 0, G[from].size() - 1));
}

void add_edge_start(int from, int to, int cap) {
  G[from].push_back(Edge(to, cap, G[to].size()));
  G[to].push_back(Edge(from, 0, G[from].size() - 1));
}

int dfs(int v, int t, int f) {
  if (v == t) return f;

  used[v] = true;

  for (int i = 0; i < G[v].size(); ++i) {
    Edge *e = &G[v][i];

    if (!used[e->to] && e->cap > 0) {
      int d = dfs(e->to, t, min(f, e->cap));
      if (d > 0) {
        e->cap -= d;
        G[e->to][e->rev].cap += d;
        return d;
      }
    }
  }

  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0) return flow;
    flow += f;
  }
}

int DY[4] = {-1, 0, 1, 0};
int DX[4] = {0, 1, 0, -1};

int main() {
  cin >> H >> W;
  char grid[H][W];
  start = 2 * H * W + 1;
  goal = 2 * H * W + 2;
  set<int> saku_points;
  set<int> goal_points;

  string row;
  for (int y = 0; y < H; ++y) {
    cin >> row;

    for (int x = 0; x < W; ++x) {
      int z = y * W + x;
      char c = row[x];

      add_edge(z, z, 1);

      grid[y][x] = c;

      for (int i = 0; i < 4; ++i) {
        int ny = y + DY[i];
        int nx = x + DX[i];
        int nz = ny * W + nx;

        if (ny < 0 || nx < 0 || H <= ny || W <= nx) {
          if (c == 'X') {
            cout << -1 << endl;
            return 0;
          }
          goal_points.insert(z);
        } else {
          if (c == 'X') saku_points.insert(nz);
          add_edge(z, nz, 1);
        }
      }
    }
  }

  for (int z : goal_points) {
    add_edge(z, goal, 1);
  }

  for (int z : saku_points) {
    int y = z / W;
    int x = z % W;

    if (grid[y][x] == 'X') continue;

    add_edge_start(start, z, 1);
  }

  cout << max_flow(start, goal) << endl;

  return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>
int main(void){
    int a, b, c, t;
    scanf("%d %d %d", &a, &b, &c);
    if(a > b){
        t = a;
        a = b;
        b = t;
    }    
    if(b > c){
        t = b;
        b = c;
        c = t;
    }    
    if(a > b){
        t = a;
        a = b;
        b = t;
    }
        printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2112
using System;

class Probrem {
    public static void Main() {
        while (true) {
            var strs = Console.ReadLine().Split();
            if (strs[1] == "?") return;
            var a = int.Parse(strs[0]);
            var b = int.Parse(strs[2]);
            Console.WriteLine(strs[1] == "+" ? a + b :
                              strs[1] == "-" ? a - b :
                              strs[1] == "*" ? a * b : a / b);
        }
    }
}


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

using namespace std;
using ll = long long;


int main()
{
	string s; cin >> s;
	ll ans = 0, cnt = 0;
	int n = s.size();

	for(int i = 0; i < n; i++) {

		if(s[i] == 'B')continue;
		ans += i - cnt;
		cnt++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        System.out.println(n*n);
    }
}

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

int main() {
  string N;
  cin >> N;
  if (N == "RRR"){
    cout << 3 << endl;
  }
  else if (N == "RRS" || N == "SRR"){
    cout << 2 << endl;
  }
  else if (N == "SSS"){
    cout << 0 << endl;;
  }
  else {
    cout << 1 << endl;
  }
}



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

int main() {
  string s;
  int f_half, s_half;
  string ans;

  cin >> s;

  f_half = ((s[0] - '0') * 10) + (s[1] - '0');
  s_half = ((s[2] - '0') * 10) + (s[3] - '0');

  if(s_half>0&&s_half<=12) {
    if(f_half>12) {
      ans = "YYMM";
    }
    else if(f_half==0){
      ans = "YYMM";
    }
    else if(f_half>0&&f_half<=12) {
      ans = "AMBIGUOUS";
    }
  }
  else if(f_half>0&&f_half<=12) {
    if(s_half>12) {
      ans = "MMYY";
    }
    else if(s_half==0){
    ans = "MMYY";
    }
  }
  else {
    ans = "NA";
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();
        int[] x = sc.IntArray();

        int answer = Math.Abs(k - x[0]);

        for (int i = 1; i < n; i++)
        {
            answer = Gcd(answer, Math.Abs(x[i] - x[i - 1]));
        }

        Console.WriteLine(answer);
    }

    // 最大公約数
    private static int Gcd(int a, int b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            int r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

int	main()
{
	int	N;
	cin >> N;
	string	S;
	cin >> S;
	int	size = S.size();
	string	shifted(S);
	for (int i = 0; i < size; ++i) {
		shifted.at(i) = 'A' + (S.at(i) - 'A' + N) % 26;
	}
	cout << shifted << endl;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def cal(board):
    H = len(board)
    gain = 0
    tmp = [1]*5
    for row in board:
        for i in range(1, 5):
            tmp[i] = tmp[i-1] * (row[i-1] == row[i]) + 1
        for i in range(4, -1, -1):
            if tmp[i] >= 3:
                gain += row[i] * tmp[i]
                for j in range(i, i-tmp[i], -1):
                    row[j] = 0
                break

    for col in range(5):
        i = H-1
        for row in board[::-1]:
            if row[col]:
                board[i][col] = row[col]
                i -= 1
        for i in range(i, -1, -1):
            board[i][col] = 0

    return gain


while True:
    H = int(input())
    if H == 0:
        break

    board = []
    for _ in [0]*H:
        *line, = map(int, input().split())
        board.append(line)

    score = 0
    while True:
        gain = cal(board)
        if gain == 0:
            break
        score += gain
    print(score)



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


int main()
{
	ll n;
	cin>>n;
	ll a[n+1], b[n+1], c[n+1];
	for(int i=1; i<=n; i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}

	ll ha[n+1], hb[n+1], hc[n+1];

	ha[0] = 0; ha[1] = a[1];
	hb[0] = 0; hb[1] = b[1];
	hc[0] = 0; hc[1] = c[1];
	
	for(int i=2; i<=n; i++)
	{
		ha[i]  = a[i] + max(hb[i-1],hc[i-1]);
		hb[i]  = b[i] + max(hc[i-1],ha[i-1]);
		hc[i]  = c[i] + max(ha[i-1],hb[i-1]);
	}

	cout<<max(ha[n],max(hb[n],hc[n]));
	
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  lint h, w; cin >> h >> w;
  if (min(h, w) == 1) {
    cout << 1 << endl;
    return 0;
  }

  lint e = w / 2;
  lint o = e + (w % 2);
  lint a = (h + 2 - 1) / 2;
  lint b = h / 2;
  cout << a * o + b * e << endl;
  return 0;
}


Measured memory_bytes: 256
/* ex4_2 C-:
    dada__  */
#include<stdio.h>
#include<math.h>
#define PI 3.14159265358979

int main(void){
    int hour_length, min_length, hour, min;
    double rad, distance;

    scanf("%d %d %d %d", &hour_length, &min_length, &hour, &min);

    rad = (min*PI/30)-((hour*60+min)*PI/360); //時針と分針の成す角

    //余弦定理による端点間の距離の算出
    distance = sqrt((double) (pow(hour_length,2) + pow(min_length,2) - 2*hour_length*min_length*cos(rad)));
    printf("%.9f\n", distance);

    return 0;
}

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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  int num1 = (N == 0) ? 0 : N * (N-1) / 2;
  int num2 = (M == 0) ? 0 : M * (M-1) / 2;
  
  cout <<  num1 + num2;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    val total = a.sum()
    val answer = if (a.filter { it >= total / (4.0 * m) }.size >= m) "Yes" else "No"

    println(answer)
}

Measured memory_bytes: 37960
#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 k, a, b;
  cin >> k >> a >> b;
  if (a <= b/k*k) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdint>
#include <type_traits>
#include <vector>


template<uint32_t mod> class Residue_Field {
public:
    uint32_t num = 0;
    Residue_Field() { }
    Residue_Field(const Residue_Field &x) : num(x.num) { }
    template<class T> Residue_Field(T x) {
        using Int = typename std::conditional<sizeof(T) >= 4, T, int32_t>::type;
        Int y = x;
        y %= static_cast<Int>(mod);
        if(y < 0) y += mod;
        num = static_cast<uint32_t>(y);
    }
    Residue_Field& operator+=(Residue_Field x) {
        num += x.num;
        if(num >= mod) num -= mod;
        return *this;
    }
    Residue_Field& operator-=(Residue_Field x) {
        if(num < x.num) num += mod;
        num -= x.num;
        return *this;
    }
    Residue_Field& operator*=(Residue_Field x) {
        num = static_cast<uint64_t>(num) * x.num % mod;
        return *this;
    }
    Residue_Field& operator/=(Residue_Field x) {
        return *this *= x.inv();
    }
    Residue_Field operator+(Residue_Field x) const { return Residue_Field(*this) += x; }
    Residue_Field operator-(Residue_Field x) const { return Residue_Field(*this) -= x; }
    Residue_Field operator*(Residue_Field x) const { return Residue_Field(*this) *= x; }
    Residue_Field operator/(Residue_Field x) const { return Residue_Field(*this) /= x; }
    Residue_Field pow(uint64_t x) const {
        Residue_Field ans = 1, cnt = *this;
        while(x){
            if(x & 1) ans *= cnt;
            cnt *= cnt;
            x >>= 1;
        }
        return ans;
    }
    Residue_Field inv() const { return pow(mod - 2); }
};

int main(){
    using Mint = Residue_Field<998244353>;
    
    int n, s;
    std::cin >> n >> s;
    std::vector<int> a(n);
    for(int& x : a) std::cin >> x;
    
    std::vector<Mint> dp(s + 1);
    dp[0] = Mint(2).pow(n);
    for(int x : a) {
        for(int i = s; i >= x; i--) dp[i] += dp[i - x] / 2;
    }
    std::cout << dp[s].num << std::endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int sentou(int n){
  if(n<10) return n;
  else return sentou(n/10);
}

int main(){
  int N;
  cin >>N;
  int freq[10][10];
  
  rep(i,10)rep(j,10) freq[i][j]=0;
  
  rep1(i,N){
    int F = sentou(i);
    int L = i%10;
    freq[F][L] ++;
  }
  
  int ans = 0;
  
  rep1(i,N){
    int F = sentou(i);
    int L = i%10;
    ans += freq[L][F];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int K=sc.nextInt();
		int x[]=new int[B];
		int y=0;
		
		for(int i=1;i<=B;i++) {
			if(A%i==0&&B%i==0) {
				x[y]=i;
				y++;
				
			}
			
		}
		System.out.println(x[y-K]);
}
}

Measured memory_bytes: 23124
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cctype>
using namespace std;
 
pair<string, vector<string> > parse(string s)
{
    for(int i=0; i<s.size(); i++)
        if(!isalpha(s[i])) s[i] = ' ';
     
    s.erase(s.end() - 1);
 
    stringstream ss(s);
    string n;
    ss >> n;
 
    string a;
    vector<string> res;
    while(ss >> a) { res.push_back(a); }
     
    return make_pair(n, res); 
}
 
bool vis[100];
set<string> ans;
void dfs(int u, map<string, int>& dic, vector<vector<string> >& graph)
{
    vis[u] = true;
 
    for(int i=0; i<graph[u].size(); i++) {
        string n = graph[u][i];
        if(dic.count(n)) {
            int v = dic[n];
            if(vis[v]) continue;
            dfs(v, dic, graph);
        }
        else ans.insert(n);
    }
}
 
int main()
{
    int N;
    while(cin >> N, N) {
        map<string, int> dic;
        vector<vector<string> > graph(N);
 
        for(int i=0; i<N; i++) {
            string s;
            cin >> s;
 
            pair<string, vector<string> > p = parse(s);
            string n = p.first;
            dic[n] = i;
 
            for(int j=0; j<p.second.size(); j++)
                graph[i].push_back(p.second[j]);
        }   
 
        memset(vis, 0, sizeof(vis));
        ans.clear();
        dfs(0, dic, graph);
 
        cout << ans.size() << endl;
    }
     
}

Measured memory_bytes: 1360
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        boolean judge = s.contains("7");
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 35720
#include <iostream>

using namespace std;

int
main()
{
  int n;
  cin >> n;
  int pi;
  cin >> pi;
  int a = 1;
  int min = pi;
  for (int i = 1; i < n; ++i) {
    cin >> pi;
    if (pi < min) {
      ++a;
      min = pi;
    }
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int n,min = 1000000000,ans = 0;
    cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    rep(i,n){
        if(min > p[i]){
            min = p[i];
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let s: Vec<char> = it.next().unwrap().chars().collect();
    let t: Vec<char> = it.next().unwrap().chars().collect();
    if s.len() + 1 != t.len() {
        println!("{}", "No");
        return;
    }
    if s != t[..s.len()].to_vec() {
        println!("{}", "No");
        return;
    }
    println!("{}", "Yes");
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

ll mod_pow(ll a, ll n){
  if(n == 0) return 1;
  if(n % 2 == 0) return mod_pow((a * a) % mod, n/2);
  return (a * mod_pow(a, n-1) % mod);
}

signed main(){
  string s; cin >> s;
  int one = 0;
  int ans = 0;
  rep(i,s.size()-1){
    if(s[i] == '1'){
      int tmp = (mod_pow(2,one) * mod_pow(3,s.size()-i-1)) % mod;
      ans += tmp;
      ans %= mod;
      one++;
    }
    dump(ans);
  }
  ans += mod_pow(2,one);
  ans %= mod;
  if(s[s.size()-1] == '1'){
    one++;
    ans += mod_pow(2,one);
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iterator>
#include <numeric>
#include <functional>
#include <climits>



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

int main(int argc, char *argv[]){
  size_t n;
  cin >> n;
  vector<int> v(n);
  for (size_t i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (size_t k = 0; k < n-1; k++) {
    cout << v[k] << " ";
  }
  cout << v[n-1] << endl;
  for (size_t i = 1; i < n; i++) {
    int j = i-1;
    while(j >= 0 && v[j] > v[j+1]){
      int x = v[j];
      v[j] = v[j+1];
      v[j+1] = x;
      j--;
    }
    for (size_t k = 0; k < n-1; k++) {
      cout << v[k] << " ";
    }
    cout << v[n-1] << endl;
  }


  
  return 0;
}

Measured memory_bytes: 1204
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])
    else:
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])

if revcnt % 2 != 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))

Measured memory_bytes: 10228
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
      ll n,r;
      cin>>n>>r;

      if(n>=10)
      {
          cout<<r<<endl;
      }
      else
      {
          ll ans = 100*(10-n);
          ans+=r;
          cout<<ans<<endl;
      }
}


Measured memory_bytes: 256
n, t = map(int, input().split())
a = list(map(int, input().split()))

small = 10**9
adv = []
for i in range(1, n):
    small = min(small, a[i-1])
    adv.append(a[i] - small)

count = 0
highest = max(adv)
for i in range(n-1):
    if adv[i] == highest:
        count += 1

print(count)

Measured memory_bytes: 15020
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  string s;
    cin >> s;
    
    cout << s[0] << s[1] << s[2];

}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    int ans = N;
    int min_m = INF;
    for (int i = 0; i < N; i++) {
        cin >> m.at(i);
        chmin(min_m, m[i]);
        X -= m[i];
    }
    cout << ans + X / min_m << endl;
}


Measured memory_bytes: 256
A =  [[int(x) for x in input().split()] for i in range(3)]
n = int(input())

bingo = [[False]*3 for i in range(3)]
num = [[-1]*2 for i in range(101)]
for i in range(3):
    for j in range(3):
        num[A[i][j]][0] = i
        num[A[i][j]][1] = j

for i in range(n):
    index = int(input())
    x,y = num[index]
    if(x==-1 or y==-1):
        continue
    bingo[x][y]=True

isOk = False
#縦
for i in range(3):
    cnt = 0
    for j in range(3):
        if(bingo[i][j]):
            cnt+=1
        if(cnt==3):
            isOk = True
            break

#横
for i in range(3):
    cnt = 0
    for j in range(3):
        if(bingo[j][i]):
            cnt+=1
        if(cnt==3):
            isOk = True
            break

#斜め
if(bingo[0][0] and bingo[1][1] and bingo[2][2]):
    isOk = True

if(bingo[2][0] and bingo[1][1] and bingo[0][2]):
    isOk = True

if(isOk):
    print('Yes')
else:
    print('No')

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

int main(){
    int n; cin>>n;
    int A[n]; 
    rep(i,n)cin>>A[i];
    ll sum[1<<n];
    rep(bit,1<<n){
        sum[bit]=0;
        rep(i,n){
            if(bit&(1<<i))sum[bit]+=A[i];
        }
   }
    int q; cin>>q;
    rep(i,q){
        int m; cin>>m;
        bool ans=false;
        for(int bit=0; bit<(1<<n); bit++){
            if(sum[bit]==m)ans=true;
        }
        if(ans)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 11176
import java.util.Scanner;

	public class Main {

		static long mod = 1000000007;

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			String[] t = sc.nextLine().split(" ");
			int n  	   = Integer.parseInt(t[0]);
			//long k = Long.parseLong(t[1].replaceAll("\\.", ""));

			String[] r = sc.nextLine().split(" ");
			long[] list = new long[n];
			long ans    = 0;
			for(int i = 0; i < n; i ++) {
				list[i] = Long.parseLong(r[i]);
				ans    += list[i] - 1;
			}

			System.out.println(ans);
		}

	}

Measured memory_bytes: 37560
#include <iostream>

using namespace std;

int D, N, ans;

int main()
{
	cin>>D>>N;
	
	if(D==0) ans=1;
	
	else if(D==1) ans=100;

	else if(D==2) ans=10000;

	if(N==100) cout<<101*ans<<'\n'; 
	
	else cout<<N*ans<<'\n';
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j, e, sum;
  int M[MAX][MAX];
  int u, v;
  int minv;
  int d[MAX];
  int p[MAX];
  int vis[MAX];

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

  for ( i = 0; i < n; i++ ) {
    d[i] = INFTY;
    p[i] = -1;
    vis[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for ( i = 0; i < n; i++ ){
      if ( minv > d[i] && !vis[i] ){
	u = i;
	minv = d[i];
      }
    }
    if ( u == -1 ) break;
    vis[u] = 1;
    for ( v = 0; v < n; v++ ){
      if ( !vis[v] && M[u][v] != INFTY ){
	if ( d[v] > M[u][v] ){
	  d[v] =  M[u][v];
	  p[v] = u;
	}
      }
    }
  }

  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }

  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 2056
import java.math.*
import java.util.BitSet

class FordFulkerson(val N: Int) {
    // 辺の配列
    // 容量は別に持つため、ここでは終点のリストのみ持つ
    val edges = Array(N, {mutableListOf<Int>()})
    val capacity = Array(N, {IntArray(N, {-1})})
    val used = BitSet(N)
    
    private fun dfs(s: Int, d: Int, flow: Int): Int {
        used.set(s)
        
        if (s == d) {
            return flow
        }
        
        for (e in edges[s]) {
            if (!used.get(e) && capacity[s][e] > 0) {
                val flowTmp = dfs(e, d, Math.min(capacity[s][e], flow))
                if (flowTmp > 0) {
                    capacity[s][e] -= flowTmp
                    capacity[e][s] += flowTmp
                    return flowTmp
                }
            }
        }
        
        return 0
    }
    
    fun add(from: Int, to: Int, cap: Int) {
        edges[from].add(to)
        edges[to].add(from)
        capacity[from][to] = cap
        capacity[to][from] = 0
    }
    
    fun solve(source: Int, sink: Int): Int {
        var flow = 0
        while (true) {
            used.clear()
            
            val flowTmp = dfs(source, sink, Int.MAX_VALUE)
            
            if (flowTmp == 0) {
                break
            }
            
            flow += flowTmp
        }
        return flow
    }
}

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    // フォード・ファルカーソンで解く
    // 0をsource, 2N + 1をsinkとするため、2N + 2のノードを用意する
    val ff = FordFulkerson(N * 2 + 2)
    
    val red = (1..N).map {val (a, b) = readInputLine().split(" ").map{it.toInt()}; Pair(a, b)}
    val blue = (1..N).map {val (c, d) = readInputLine().split(" ").map{it.toInt()}; Pair(c, d)}
    
    for (i in 1..N) {
        ff.add(0, i, 1)
        ff.add(N + i, N * 2 + 1, 1)
    }
    
    for ((i, r) in red.withIndex()) {
        for ((j, b) in blue.withIndex()) {
            if (r.first < b.first && r.second < b.second) {
                ff.add(i + 1, j + N + 1, 1)
            }
        }
    }
    
    println(ff.solve(0, N * 2 + 1))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 39020
# coding: utf-8
i = 0
while True:
    line = input().rstrip().split()
    H = int(line[0])
    W = int(line[1])
    if H == 0 and W == 0:
        print("\n",end="")
        break
    if (i != 0):
        print("\n",end="")
    for i in range(H):
        for j in range(W):
            print("#",end="")
        print("\n",end="")
    i += 1


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

#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define ll long long
const ll INF = 2LL<<60;

int main()
{
    int N, K;
    cin >> N >> K;
    
    int max = N - (K - 1);

    if(K == 1)  cout << 0 << endl;
    else cout << max - 1 << endl;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".in", "r")){
        freopen(Task".in", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    int n, k; cin >> n >> k;
    vector<int> a(n), f(n);
    for (int i=0; i<n; ++i){
        cin >> a[i];
        if (i) f[i] = 2e9 + 5;
        for (int j=i-1; j>=0 && j>=i-k; --j){
            f[i] = min(f[i], f[j] + abs(a[i] - a[j]));
        }
    }
    cout << f[n-1] << '\n';
}


Measured memory_bytes: 1024
#include <stdio.h>
  #include <deque>
  #include <string>

  using namespace std;

  int main()
  {
      int N;
      char S[1000];

      scanf(" %d %s", &N, S);

      deque<char> output;


      int depth = 0;

      for (int i = 0; i < N; i++) {

          if(S[i] == '(') {
              depth++;
          } else {
              depth--;
          }

          if(depth<0) {
              output.push_front('(');
              depth=0;
          }
          output.push_back(S[i]);
      }

      for(int i=0; i<depth; i++) {
          output.push_back(')');
      }

      for(int i=0; i<output.size(); i++) {
          printf("%c", output[i]);
      }

      printf("\n");
  }

Measured memory_bytes: 256
#include<iostream>

int main(){
    int n, k, h, ans = 0;

    std::cin >> n >> k;
    for(int a = 0; a < n; a++){
        std::cin >> h;
        if(h >= k){
            ans++;
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a=0,b=0,x=0,i=2,total=0;
    float t=0;
    scanf("%d %d %f",&a,&b,&t);
    x=a;
    while(x<=t+0.5)
    {
        total+=b;
        x=i*a;
        i++;
    }
    printf("%d",total);
    
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;cin>>n;
    vector <long long int > v;
    for(int i=0;i<n;i++)
    {
        long long int a;cin>>a;
        v.push_back(a);
        
    }
    
    sort(v.begin(),v.end(),greater<long long int>());
    long long int before=-1;
    long long int g=-9999;
    for(long long int x:v){
        if (before==x)
        {
            if(g==-9999)
            {
                g=x;
                before=-1;
                continue;
                
            }
            else 
            {
                cout<<g*x;
                return 0;
            }
            
        }//before == x;
        else
        {
            before = x;
            continue;
            
        }
    }
    
    cout << 0;
    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){ T x; cin >> x; return (x); }
template<typename T=int,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return move(x); }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

	int N=in(),K=in();
	int V=0;
	while(N){
		V++;
		N/=K;
	}
	out(V);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <climits>

using namespace std;
/*
  問題文

  N 個の整数 a_1,a_2,..,a_N が与えられます。えび君はこれらを書き換えて
  全て同じ整数にしようとしています。各a_i (1≦i≦N)は高々一回しか書き換
  えられません(書き換えなくても良い)。整数xを整数yに書き換えるとき、コ
  ストが(x-y)^2かかります。仮にa_i=a_j (i≠j)だとしても、ひとつ分のコス
  トで同時に書き換えることは出来ません(入出力例2 を参照)。えび君が目的
  を達成するのに必要なコストの総和の最小値を求めてください。

  制約

  * 1≦N≦100
  * -100≦a_i≦100
*/

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int a_max = -100;
    int a_min = 100;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a_max = max(a_max, a[i]);
        a_min = min(a_min, a[i]);
    }

    long mincost = LONG_MAX;
    for (int i = a_min; i <= a_max; i++) {
        long cost = 0;
        for (int j = 0; j < a.size(); j++) {
            cost += (a[j] - i) * (a[j] - i);
        }
        mincost = min(mincost, cost);
    }

    cout << mincost << endl;

    return 0;
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n;
  std::cin>>n;
  
  ll count[3]={0};

  rep(i,0,n){
    ll a;
    std::cin>>a;
    if(a%4==0){
      count[2]++;
    }else if(a%2==0){
      count[1]++;
    }else{
      count[0]++;
    }
  }

  if(count[1]>0)count[0]++;

  if(count[0]<=count[2]+1)std::cout<<"Yes";
  else std::cout<<"No";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)

int main()
{
    int A,B,C,X;
    cin >> A >> B >> C >> X;

    int cnt = 0;
    repi(i,A+1){
        repi(j,B+1){
            repi(k,C+1){
                if(i*500 + j*100 + k*50 == X)cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int[] W = new int[N+1];

            for(int i = 1 ; i <= N ; i++){
                W[i] = sc.nextInt();
            }
            sc.close();

            int S1 = 0;
            int S2 = 0;
            int ans = 1000000;
            for(int i = 1 ; i < N ; i++){
                for(int j = 1 ; j <= i ; j++){
                    S1 += W[j];
                }
                for(int k = i+1 ; k <= N ; k++){
                    S2 += W[k];
                }
               // System.out.println(S1-S2);
                ans = Math.min(ans,Math.abs(S1-S2));
                S1 = 0;
                S2 = 0;
            }

            System.out.println(ans);
    }
}



Measured memory_bytes: 21332