akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;

    cout << ( a - 1 ) * ( b - 1 ) << endl;
    return 0;
}



Measured memory_bytes: 256
package main

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

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}

	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func check() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	a := scanInt(sc)
	b := scanInt(sc)

	var sum int
	for i := 0; i < 2; i++ {
		if a > b {
			sum += a
			a -= 1
		} else {
			sum += b
			b -= 1
		}
	}

	fmt.Printf("%d\n", sum)

}

func main() {
	check()
}


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

using namespace std;

typedef long long int64;

const int64 INF = 1LL << 58;

int main()
{
  int x, y;
  cin >> x >> y;

  int64 ret = INF;
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < 2; j++) {
      int64 a = i == 0 ? x : -x;
      int64 b = j == 0 ? y : -y;
      if(a <= b) ret = min(ret, b - a + i + j);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 764
#include <iostream>

using namespace std;

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

    int ans;
    if(N % (D * 2 + 1) == 0){
        ans = N / (D * 2 + 1);
    }else{
        ans = N / (D * 2 + 1) + 1;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char **argv)
{
	int id;
	float w, h;
	
	while(scanf("%d,%f,%f", &id, &w, &h) != EOF){
		if((w / (h*h)) >= 25.0){
			printf("%d\n", id);
		}
	}
	
	return 0;
}

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

// 線形探索

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

int main() {
  int n, A[10000+1], q, key, sum=0;

  scanf("%d", &n);
  rep(i, n) scanf("%d", &A[i]);

  scanf("%d", &q);
  rep(i, q) {
    scanf("%d", &key);
    if (search(A, n, key)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> w(n);
    int s1 = 0, s2 = 0;
    for(int i = 0; i < n; i++){
        std::cin >> w[i];
        s2 += w[i];
    }

    int minDiff = s2;

    // s1に属する個数i + 1
    for(int i = 0; i < n; i++){
        s1 += w[i];
        s2 -= w[i];
        minDiff = std::min(minDiff, std::abs(s1- s2));
    }
    std::cout << minDiff << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> /*sort()を使用するのに必要*/

using namespace std;

int main(){
    int N;
    vector<int> L;

    cin >> N;
    for(int i=0; i<N; i++){
        int j;
        cin >> j;
        L.push_back(j);
    }

    sort(L.begin(), L.end()); //ちなみにソートすると3重ループでも通る

    int count = 0;
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){

            //二分探索で3つめを絞る
            int start = j + 1;
            int end = N - 1;
            int k;
            int max = L[i] + L[j];
            while(start < end){
                int middle = (start + end) / 2;
                if(L[middle] >= max){
                    end = middle - 1;
                }else{
                    start = middle + 1;
                }
            }

            for(int k=j+1; k<=start; k++){
                if(L[i] >= L[j] + L[k]) continue;
                if(L[j] >= L[i] + L[k]) continue;
                if(L[k] >= L[i] + L[j]) continue; //すでにやっている
                count ++;
            }
        }
    }

    cout << count;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,W;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    ll dp[n+1][W+1];
    for(ll i=0;i<=n;i++)
    {
        for(int j=0;j<=W;j++)
            dp[i][j] = 0;
    }
   // cout<<dp[1][1]<<endl;
    // array[i][j] represents the maximum value if i th item selected or not with j as max weight ;
    for(ll i=0;i<=n;i++)
    {
        for(ll  j=0;j<=W;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j] = 0 ;
            }
            else if( w[i] <= j )
            {
                dp[i][j] = max( dp[i-1][j] , v[i]+dp[i-1][j-w[i]] ) ;
            }
            else
            {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W]<<endl;
}
/* {60, 100, 120};
    int wt[] = {10, 20, 30};
    int  W = 50; */


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

int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  int l = s.length();
  if(l <= k) cout << s << endl;
  else {
    string t = "";
    rep(i,k) t += s[i];
    t += "...";
    cout << t << endl;
  }
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;

int main(int argc, char **argv) {
    int N, V[20], C[20];

    int res = 0;
    cin >> N;
    for(int i = 0; i < N; ++i)
        cin >> V[i];
    for(int i = 0; i < N; ++i)
        cin >> C[i];

    for(int i = 0; i < N; ++i) {
        if(V[i] > C[i])
            res += V[i] - C[i];
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a1, a2;
  cin >> a1 >> a2;
  set<int> a;
  a.insert(1);
  a.insert(2);
  a.insert(3);
  a.erase(a1);
  a.erase(a2);
  cout << *a.begin() << endl;
  return 0;
}

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

bool valid(string S_) {
  int len = S_.size();
  bool flag = false;
  for(int i=1; i<len; i++) {
    if(i != 1 && i < len-1 && S_[i] == 'C' && flag == false) {
      flag = true;
    } else if (i !=1 && S_[i] == 'C' && flag == true) {
      return false;
    } else if((S_[i] < 'a') || (S_[i] > 'z')) {
      return false;
    }
  }
  
  return flag;
}

int main() {
  string S;
  cin >> S;
  
  if(S[0] == 'A' && valid(S) == true) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <cmath>

using namespace std;

using lli = long long;

#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) ()
#define debug_array(a) ()
#endif

string s;

int main() {
  cin >> s;
  lli bn = 0, ans = 0;
  for (int i=0; i<s.size(); ++i) {
    if (s[i] == 'B') {
      bn++;
    } else {
      ans += bn;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define MAX 100
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int PINK=1;
static const int RED=2;

int m[MAX][MAX];
int prim(int n){
  int u,minv;
  int d[MAX],parent[MAX],color[MAX];
  int i,j;
  for(i=0;i<n;i++){
    d[i]=INFTY;
    parent[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=RED){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=RED;
    for(j=0;j<n;j++){
      if(color[j]!=RED&&m[u][j]!=INFTY){
	if(d[j]>m[u][j]){
	  d[j]=m[u][j];
	  parent[j]=u;
	  color[j]=PINK;
	}
      }
    }
  }
  int sum=0;
  for(i=0;i<n;i++){
    if(parent[i]!=-1)sum+=m[i][parent[i]];
  }
  return sum;
}
int main(){
  int number,i,j;
  int e;
  scanf("%d",&number);
  for(i=0;i<number;i++){
    for(j=0;j<number;j++){
      scanf("%d",&e);
      if(e==-1)m[i][j]=INFTY;
      else m[i][j]=e;
    }
  }
  printf("%d\n",prim(number));
  
  return 0;
}

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] b = new Integer[n - 1];
        for (int i = 0; i < n - 1; i++) {
            b[i] = Integer.parseInt(sc.next());
        }

        Integer[] a = new Integer[n - 1];
        for (int i = 0; i < n - 2; i++) {
            if (b[i] < b[i+1]) {
                a[i] = b[i];
            } else {
                a[i] = b[i + 1];
            }
        }
        a[a.length - 1] = b[b.length - 1];

        int result = b[0];
        for (int num : a) {
            result+=num;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            long a, b, c, k;
            ReadLong(out a, out b, out c, out k);

            long ans = 0;
            ans += Min(a, k);
            k -= Min(a, k);
            k -= Min(b, k);
            ans -= k;

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static string YesNo(bool condition) => condition ? "Yes" : "No";
        static string YESNO(bool condition) => condition ? "YES" : "NO";

        #endregion
    }
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int a, b, c; cin >> a >> b >> c;
    if(a > b && a > c) cout << b*c/2;
    else if(b > a && b > c) cout << a*c/2;
    else cout << a*b/2;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()

n = len(s)
for i in range(n//2):
    if s[i]!=s[n-i-1] :
        print("No")
        exit()

n1 = (n-1)//2
for i in range(n1//2):
    if s[i]!=s[n1-i-1] :
        print("No")
        exit()

n2 = (n+3)//2
for i in range(n-n2):
    if s[i]!=s[n-i-1] :
        print("No")
        exit()

print("Yes")

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, x;
  cin >> N >> x;
  if(x == 1 || x == 2 * N - 1) {
    cout << "No" << endl;
  }else{
    vector<int> res(2 * N - 1);
    iota(ALL(res), 1);
    swap(res[x - 1], res[N - 1]);
    swap(res[0], res[N - 2]);
    swap(res[2 * N - 2], res[N]);
    cout << "Yes" << endl;
    REP(i,2 * N - 1) cout << res[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>

using namespace std;
const int MAX = 1000000;
int data[MAX];

void make(){
  fill(data,data+MAX,1);
  
  for(int i = 2; i*i < 1000000; i++){
    if(data[i] == 1){
      for(int j = i*2; j < 1000000; j+=i) data[j] = 0;
    }
  }
}

int main(){
  make();
  int in;
  while(cin >> in){
    
    int sum = 0;
    for(int i = 2; i <= in; i++){
      if(data[i] == 1) sum++;
    }
    
    cout << sum <<endl;
  }
  return 0;
}

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


unsigned int numberReverse(unsigned int forwardNumber) {
    unsigned int reverseNumber = 0U;
    
    while(forwardNumber != 0U) {
        reverseNumber = forwardNumber % 10 + reverseNumber * 10;
        forwardNumber /= 10;
    }
    return reverseNumber;
}  

int main() {
    unsigned int firstNumber;
    unsigned int lastNumber;
    std::cin >> firstNumber >> lastNumber;
    
    unsigned int numOfPalindrome = 0U;
    for(unsigned int i = firstNumber; i <= lastNumber; ++i) {
        unsigned int reverseNumber = numberReverse(i);
        if(i == reverseNumber) {
            ++numOfPalindrome;
        }
    }
    std::cout << numOfPalindrome << std::endl;
}


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


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

}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<Integer> xs = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            xs.add(sc.nextInt());
        }


        int ans = 0;
        for (int x : xs) {
            ans += 2 * (Math.min(x, Math.abs(K - x)));
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS =1e-10;
double EQ(double a,double b){
	return abs(a-b)<EPS;
}

void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}
struct edge{
	int to;
	int cost;
};

typedef pair<int,pii> ppi;
vector<edge> G[301];
int d[2][301];
const int INF=1000000000;
int N,M;
int dijkstra(){
	for(int i=0;i<2;i++)
		for(int j=0;j<301;j++)
			d[i][j]=INF;
	d[0][0]=0;
	priority_queue<ppi,vector<ppi>,greater<ppi> > pq;
	pq.push(make_pair(0,pii(0,0)));
	while(pq.size()){
		ppi p=pq.top();
		pq.pop();
		int ccost=p.first;
		int cnode=p.second.first;
		int ctick=p.second.second;
		if(d[ctick][cnode]<ccost)continue;
		for(int i=0;i<G[cnode].size();i++){
			edge &e=G[cnode][i];
			int ncost=e.cost+ccost;
			int ntick=ctick;
			int nnode=e.to;
			if(d[ntick][nnode]>ncost){
				pq.push(make_pair(ncost,pii(nnode,ntick)));
				d[ntick][nnode]=ncost;
			}
		}
		// ツチツケツッツトツづーツ使ツ用
		if(ctick==0){
			int ntick=1;
			int ncost=ccost;
			for(int i=0;i<G[cnode].size();i++){
				edge &e1=G[cnode][i];
				int tt=e1.to;
				for(int j=0;j<G[tt].size();j++){
					int nnode=G[tt][j].to;
					if(d[ntick][nnode]>ncost){
						pq.push(make_pair(ncost,pii(nnode,ntick)));
						d[ntick][nnode]=ncost;
					}
				}
			}
		}
	}
	return min(d[0][N-1],d[1][N-1]);
}

void solve(){

	while(cin>>N>>M&&(N|M)){
		for(int i=0;i<301;i++)G[i].clear();
		for(int i=0;i<M;i++){
			int a,b,c;
			cin>>a>>b>>c;
			a--;b--;
			edge e;
			e.to=b;
			e.cost=c;
			G[a].push_back(e);
			e.to=a;
			G[b].push_back(e);
		}
		cout<<dijkstra()<<endl;
	}
}int main(){
	solve();
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdlib>
#include <vector>
#include <stack>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>
#include <numeric>
#include <math.h>

#define LOOP(N) for(int i=0; i<(N); ++i)
#define REP(i, N) for(int i=0; i<(N); ++i)
#define FOR(i, start, end) for(int i=(start); i<(end); ++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using Graph = vector< vector<int> >;

const ll MOD = 1000000007;

void sayYes() {cout << "Yes" << endl;}
void sayNo() {cout << "No" << endl;}


int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    
    ll unit_count = 0;
    REP(i, N) {
        FOR(j, i+1, N) {
            if (A[i] > A[j]) ++unit_count;
        }
    }
    vector<ll> over_count(N, 0);
    REP(i, N) {
        REP(j, N) {
            if (A[i] > A[j]) ++over_count[i];
        }
        // cout << i << " " << over_count[i] << endl;
    }
    
    ll result = unit_count * K % MOD;
    REP(i, N) {
        result += K*(K-1LL)/2LL % MOD * over_count[i] % MOD;
        result %= MOD;
    }
    
    cout << result;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(' ').let { it[0].toInt() to it[1].toLong() }
    val A = readLine()!!.split(' ').map(String::toLong).sorted().toLongArray()
    var l = Long.MIN_VALUE
    var r = Long.MAX_VALUE
    fun countUnder(tgt: Long): Long {
        var cnt = 0L
        for (i in A.indices) {
            var cc = 0
            var ll = i + 1
            var rr = N - 1
            while (ll <= rr) {
                val mm = (ll + rr) / 2
                if (A[i] < 0L) {
                    if (A[i] * A[mm] < tgt) {
                        rr = mm - 1
                        cc = N - mm
                    } else {
                        ll = mm + 1
                    }
                } else {
                    if (A[mm] * A[i] < tgt) {
                        ll = mm + 1
                        cc = mm - i
                    } else {
                        rr = mm - 1
                    }
                }
            }
            cnt += cc
        }
        return cnt
    }
    while (l + 1 < r) {
        val m = (l + r) / 2
        if (countUnder(m) < K) {
            l = m
        } else {
            r = m
        }
    }
    println(l)
}

Measured memory_bytes: 84332
import java.util.*;
public class Main{
	static int[] ans;
	static ArrayList<State>[] list;
	static int max=0;
	static int n;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		ans=new int[n-1];
		list=new ArrayList[n];
		for(int i=0; i<n; i++){
			list[i]=new ArrayList<>();
		}
		for(int i=0; i<n-1; i++){
			int a=sc.nextInt()-1;
			int b=sc.nextInt()-1;
			list[a].add(new State(b,i));
			list[b].add(new State(a,i));
		}
		dfs(-1,-1,0);
		System.out.println(max);
		for(int i=0; i<n-1;i++){
			System.out.println(ans[i]);
		}
		
	}
	static void dfs(int front,int no,int now){
		int count=1;
		for(State i:list[now]){
			if(i.g==front){
				continue;
			}
			if(count==no){
				count++;
			}
			max=Math.max(max,count);
			ans[i.ind]=count;
			dfs(now,count++,i.g);
		}
	}
	static class State{
		int g,ind;
		State(int g,int ind){
			this.g=g;
			this.ind=ind;
		}
	}
}


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

int main()
{
  int n, x, l, d = 0,cnt = 1;
  cin >> n >> x;
  
  while(cin >> l)
  {
    d += l;
    if(d <= x)
      cnt++;
    else
      break;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3556
#include<stdio.h>
#include<math.h>
int main()
{
    unsigned long long n1,n2,sum1,sum2,vagfol,rem,count,k=0;
    scanf("%llu%llu",&n1,&n2);
    vagfol=n2;
    for(count=0;vagfol!=0;count++)
    {
            vagfol=vagfol/10;

    }
    k=pow(10,count);
    n1=n1*k;
    sum1=n1+n2;
    sum2=sqrt(sum1);
    sum2=pow(sum2,2);
    if(sum1==sum2)printf("Yes\n");
    else printf("No\n");
    return 0;
}




Measured memory_bytes: 2368
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ans = sum(B)
for i in range(N-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int a;
    int b;
    int are;
    int cir;
    char buf[100];
    
    fgets(buf,"%d %d",stdin);
    sscanf(buf,"%d %d",&a,&b);
    
    are = a * b;
    cir = 2 * (a + b);
    
    printf("%d %d\n", are,cir);
    return (0);
}



Measured memory_bytes: 2052
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC118A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            if (b % a == 0)
            Console.WriteLine(a + b);
            else 
            Console.WriteLine(b - a);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
import math
A, B, H, M = map(int, input().split())

largeD = 30
smallD = 6

if H == 6 and M == 0:
    num = A + B
    print('{:.10f}'.format(num))
    exit()
else:
    D = H * largeD
    d = M * smallD
    # また、1分毎に0.5度ずつ時針が動いている
    D += 0.5 * M
    if (D >= d):
        num = (A ** 2 + B**2) - (2 * A * B * math.cos(math.radians(D - d)))
        print('{:.10f}'.format(math.sqrt(num)))
    elif (D < d):
        num = (A ** 2 + B**2) - (2 * A * B * math.cos(math.radians(d - D)))
        print('{:.10f}'.format(math.sqrt(num)))


Measured memory_bytes: 9540
#include <bits/stdc++.h>
using longlong=long long;
[[maybe_unused]]auto cmn=[](auto&& a,auto b){if(a>b){a=b;return true;}return false;};
[[maybe_unused]]auto cmx=[](auto&& a,auto b){if(a<b){a=b;return true;}return false;};

struct input_iterator{
    int n;
    input_iterator(int n):n(n){}
    input_iterator&operator++(){--n;return*this;}
    int operator*()const{int x;std::cin>>x;return x;}
};
bool operator!=(input_iterator lhs,input_iterator rhs){return lhs.n!=rhs.n;}
class input{
        int n;
    public:
        input(int n):n(n){}
        input_iterator begin()const{return input_iterator(n);}
        input_iterator end()const{return input_iterator(0);}
};

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n, m, X, Y;
    std::cin >> n >> m >> X >> Y;
    for(int x:input(n)){
        cmx(X,x);
    }
    for(int x:input(m))cmn(Y,x);
    std::cout << (X<Y?"No War":"War") << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  cin>>str;
  int n,gusu,kisu,hidari,migi;
  n=str.size();
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    vec.at(i)=0;
  }
  for(int i=0; i<n; i++){
    gusu=0;
    kisu=0;
    for(int j=i; j<n; j++){
      if(str.at(j)=='R'){
        if(j%2==0){
          gusu=gusu+1;
        }
        else{
          kisu=kisu+1;
        }
      }
      else{
        i=j;
        break;
      }
    }
    hidari=i-1;
    migi=i;
    for(int j=i; j<n; j++){
      i=j;
      if(str.at(j)=='L'){
        if(j%2==0){
          gusu=gusu+1;
        }
        else{
          kisu=kisu+1;
        }
      }
      else{
        break;
      }
    }
    if(hidari%2==0){
      vec.at(hidari)=gusu;
      vec.at(migi)=kisu;
    }
    else{
      vec.at(hidari)=kisu;
      vec.at(migi)=gusu;
    }
    if(i==n-1){
      break;
    }
    i=i-1;
  }
  for(int i=0; i<n; i++){
    cout<<vec.at(i)<<" ";
  }
}

Measured memory_bytes: 1024
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    ans = 0
    for i in range(1, n):
        ans += (n - 1) // i
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 62764
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;cin>>n;
    int a[n];for (int i=0;i<n;i++)cin>>a[i];
    int c=0;
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if (a[j]<a[minj]){
                minj=j;
                 
            }
            
        }
        int b=a[i];a[i]=a[minj]; a[minj]=b;
        if(i!=minj)c+=1;
       
    }
    for (int k=0;k<n-1;k++){cout<<a[k]<<" ";}cout<<a[n-1]<<endl;
    cout<<c<<endl;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
inline int read() {
	int f=1,sum=0;
	char x=getchar();
	for(;(x<'0'||x>'9');x=getchar()) if(x=='-') f=-1;
	for(;x>='0'&&x<='9';x=getchar()) sum=sum*10+x-'0';
	return f*sum;
}

#define M 605
#define mod 1000000007
int n,K;
int pos[M],sum[M];
int g[M],f[M][M],ans;

inline void inc(int &x,int y) {x+=y,x-=x>=mod?mod:0;}

inline void dp(int l,int r) {
	if(sum[r]-sum[l-1]&1) return;
	for1(l,r,i) if(pos[i]&&pos[i]<l||pos[i]>r) return;
	int x=g[sum[r]-sum[l-1]];
	for1(l,r-1,i) inc(x,mod-1ll*f[l][i]*g[sum[r]-sum[i]]%mod);
	f[l][r]=x;
	inc(ans,1ll*x*g[n-2*K-sum[r]+sum[l-1]]%mod);
}

int main () {
	//freopen("a.in","r",stdin);
	n=read()*2,K=read();
	for1(1,K,i) {
		int x=read(),y=read();
		pos[x]=y,pos[y]=x;
	}
	g[0]=1;
	for(int i=2;i<=n;i+=2) g[i]=1ll*(i-1)*g[i-2]%mod;
	for1(1,n,i) sum[i]=sum[i-1]+(!pos[i]);
	for1(1,n,i) FOR2(n-i+1,1,j) dp(j,j+i-1);
	cout<<ans<<endl;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using pii = pair<int, int>;
#define endl '\n'

ll a, b, c, d;

unordered_map<ll, ll> mp;
vector<pii> v;

ll calc(ll n) {
	if(n == 1) return d;
	if(n == 0) return 0;
	ll ret = 1e18;
	if(mp.find(n) != mp.end()) return mp[n];
	ret = min(ret, d * (n % 2) + calc(n / 2) + a);
	ret = min(ret, d * (n % 3) + calc(n / 3) + b);
	ret = min(ret, d * (n % 5) + calc(n / 5) + c);

	ll d1 = ((n+(2-n%2)))/2;
	ll d2 = ((n+(3-n%3)))/3;
	ll d3 = ((n+(5-n%5)))/5;

	if(d1 < n) ret = min(ret, d * (2 - n % 2) + calc(d1) + a);
	if(d2 < n) ret = min(ret, d * (3 - n % 3) + calc(d2) + b);
	if(d3 < n) ret = min(ret, d * (5 - n % 5) + calc(d3) + c);
	ret = min(ret, d * n);

	return mp[n] = ret;
}

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

	while(t--) {
		ll n;
		cin >> n >> a >> b >> c >> d;

		cout << calc(n) << endl;
		mp.clear();
	}
}


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

using str = string;
using ss = stringstream;

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

    str s;cin>>s;
    int ans=0;
    for(int i=0;i<4;i++)
    {
        if(s[i]=='+')ans++;
        else ans--;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3636
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll powmod(ll m, ll p) {
    if (p == 0) return 1;
    ll tmp = powmod(m, p / 2);
    if (p & 1) return (tmp * tmp % MOD) * m % MOD;
    else return tmp * tmp % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vll a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));

    vll fac(n + 1, 1), invfac(n + 1, 1);
    rep(i, 1, n + 1) {
        fac[i] = fac[i - 1] * i % MOD;
        invfac[i] = invfac[i - 1] * powmod(i, MOD - 2) % MOD;
    }

    ll maxs = 0, mins = 0;
    for (ll i = 1; i <= n - k + 1; i++) {
        ll tmpa = a[i - 1];
        if (tmpa < 0) tmpa += MOD;
        mins += (((tmpa * fac[n - i]) % MOD * invfac[k - 1]) % MOD * invfac[n - i - k + 1]) % MOD;
        if (mins >= MOD) mins -= MOD;
    }
    reverse(ALL(a));
    for (ll i = 1; i <= n - k + 1; i++) {
        ll tmpa = a[i - 1];
        if (tmpa < 0) tmpa += MOD;
        maxs += (((tmpa * fac[n - i]) % MOD * invfac[k - 1]) % MOD * invfac[n - i - k + 1]) % MOD;
        if (maxs >= MOD) maxs -= MOD;
    }

    ll ans = maxs - mins;
    if (ans < 0) ans += MOD;
    if (ans >= MOD) ans -= MOD;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    ll A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    ll sum = 0,mini = INF;
    mini = min(A+B,C*2);
    sum += min(X,Y) * mini;
    mini = min(C*2,X > Y ? A : B);
    sum += (max(X,Y)-min(X,Y)) * mini;

    cout << sum << endl;
}

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

using namespace std;

int H, W;
vector<vector<char>> s;
int tonari[4]{-1, 1, -1, 1};

int main()
{
  cin >> H >> W;
  s = vector<vector<char>>(H + 2, vector<char>(W + 2, '.'));

  for (int i = 1; i <= H; i++)
  {
    for (int j = 1; j <= W; j++)
    {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= H; i++)
  {
    for (int j = 1; j <= W; j++)
    {
      if (s[i][j] == '#')
      {
        if (s[i + 1][j] == '.')
        {
          if (s[i - 1][j] == '.')
          {
            if (s[i][j + 1] == '.')
            {
              if (s[i][j - 1] == '.')
              {
                cout << "No" << endl;
                return 0;
              }
            }
          }
        }
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}

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

void solve () {
    int n;
    cin >> n;
    string s;
    cin >> s;
    char c = ' ';
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (c != s[i]) {
            ans++;
        }
        c = s[i];
    }
    cout << ans;

}

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


Measured memory_bytes: 3752
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    long ans = 0;
    for(int i = 0; i < n; i++) {
      long x = sc.nextLong();
      ans += Math.min(2 * x, 2 * Math.abs(k - x));
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include<stdio.h>
#include<stdlib.h>

#define NIL NULL
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
 
Node root;

Node treeSearch(Node u, int k){
  while(u != NIL){
    if(u->key == k) break;

    if(u->key > k) u = u->left;

    else u = u->right;
  }

  return u;
}

/*
  Node treeSuccessor(Node x){
  }
 
  void treeDelete(Node z){
  }
*/

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
 
  if(y == NIL){
    root = z;
  }

  else if(z->key < y->key){
    y->left = z;
  }

  else{
    y->right = z;
  }
}
 
void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
 
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(void){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for(i = 0; i < n; i++){
    scanf("%s", com);
    if (com[0] == 'f') {
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if (t != NIL) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }

    else if(com[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    }

    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }

    else if (com[0] == 'd'){
      /*
        scanf("%d", &x);
        treeDelete(treeSearch(root, x));
      */
    }
  }
 
  return 0;
}

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

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin>>n;
	int a[n];
	for(auto&i:a)cin>>i;
	list<int> l;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			l.push_back(1);
			if(j<n-1&&a[j]>a[j+1]){
				l.push_back(n-1);
				swap(a[j],a[j+1]);
			}
		}
		
	}
	cout<<l.size()<<endl;
	for(auto c:l) cout<<c<<endl;
}

Measured memory_bytes: 2304
n = int(input())
a = list(map(int,input().split()))
b = sum(a)
s1 = 0
sa = 1000000
for i in range(n):
    s1 = s1 + a[i]
    s2 = b - s1
    if abs(s1-s2) < sa:
        sa = abs(s1 - s2)
print(sa)

Measured memory_bytes: 3316
use std::io::*;
 
const SP: u8 = b' ';
const LF: u8 = b'\n';
 
struct CharacterInput<'a> {
    locked_stdin: StdinLock<'a>,
    bytes_buffer: Vec<u8>,
}
 
impl<'a> CharacterInput<'a> {
    fn read(&mut self, delimiter: u8) -> &[u8] {
        self.bytes_buffer.clear();
 
        let mut len = self
            .locked_stdin
            .read_until(delimiter, &mut self.bytes_buffer)
            .unwrap();
 
        if len > 0 {
            len -= 1;
        }
 
        &self.bytes_buffer[0..len]
    }
 
    fn scan_u(&mut self, delimiter: u8) -> u32 {
        self.read(delimiter)
            .into_iter()
            .fold(0, |accumulator, byte| {
                (byte - b'0') as u32 + accumulator * 10
            })
    }

    fn scan_s(&mut self, delimiter: u8) -> &str {
        unsafe { std::str::from_utf8_unchecked(self.read(delimiter)) }
    }
}
 
fn create_cin<'a>(input: StdinLock<'a>, buffer_capacity: usize) -> CharacterInput {
    CharacterInput {
        locked_stdin: input,
        bytes_buffer: Vec::with_capacity(buffer_capacity),
    }
}
 
fn println<T: std::string::ToString>(s: T) {
    println!("{}", s.to_string());
}
 
// ------------------------------------------------------------------------
 
type Pos = (i64, i64);
 
use std::collections::HashMap;
 
fn main() {
    let cin = stdin();
    let cin = &mut create_cin(cin.lock(), 64);
 
    let n = cin.scan_u(LF) as usize;

    if n <= 2 {
        println(1);
        return;
    }

    let mut ball_list: Vec<Pos> = Vec::with_capacity(n);
 
    for _ in 0..n {
        ball_list.push((cin.scan_s(SP).parse().unwrap(), cin.scan_s(LF).parse().unwrap()));
    }
 
    let mut pos_diff_list: HashMap<Pos, usize> = HashMap::with_capacity(n * n);
 
    for i in 0..n - 1 {
        let ball = ball_list[i];
 
        for k in i + 1..n {
            let other_ball = ball_list[k];
            let pos_diff = if other_ball.0 > ball.0 || (other_ball.0 == ball.0 && other_ball.1 > ball.1) {
                (other_ball.0 - ball.0, other_ball.1 - ball.1)
            } else {
                (ball.0 - other_ball.0, ball.1 - other_ball.1)
            };
 
            let count = pos_diff_list.entry(pos_diff).or_insert(0);
            *count += 1;
        }
    }
 
    let max_count = *pos_diff_list.values().max().unwrap();
 
    println(n - max_count);
}


Measured memory_bytes: 4352
local N = io.read("n")

local edges = {}

if N % 2 == 1 then
    for i=1,N do
        for j=i+1,N do
            if j ~= N-i then
                table.insert(edges , tostring(i) .. " " .. tostring(j))
            end
        end
    end
else
    for i=1,N do
        for j=i+1,N do
            if j ~= N+1-i then
                table.insert(edges , tostring(i) .. " " .. tostring(j))
            end
        end
    end
end


print(#edges)
for _,v in pairs(edges) do
    print(v)
end



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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> A(N);
    rep (i, N) {
        cin >> A[i];
    }

    ll ans = pow(3, N);
    ll tmp = 1;
    rep (i, N) {
        if (A[i] % 2 == 0) {
            tmp *= 2;
        }
    }

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

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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int main(void)
{
	string X;
	cin >> X;

	int s = 0, t = 0, c = 0;
	int ans = X.size();
	Rep(i, X.size()){
		if(X[i] == 'S'){
			s++;
		}else{
			t++;
		}
		if(X[i] == 'T' && s > 0 && t > 0){
			s--;
			t--;
			ans -= 2;
		}
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 640
N,A,B,C,D=map(int,input().split())
ans='Yes'
S=input()
if C<D:
    if '##' in S[B-1:D-1] or '##' in S[A-1:C-1]:
        ans='No'
else:
    if '##' in S[B-1:D-1] or '##' in S[A-1:C-1] or '...' not in S[B-2:D+1]:
        ans='No'
print(ans)        

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

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] nums = new long[n];

        int minusNums = 0;
        long min = Long.MAX_VALUE;

        for (int i = 0; i < n; i++) {
            long tmp = sc.nextLong();

            if (tmp < 0) {
                minusNums++;
            }

            tmp = tmp < 0 ? -tmp :tmp;
            if (tmp < min) {
                min = tmp;
            }

            nums[i] = tmp;
        }


        if(minusNums % 2 == 0) {
            min = 0L;
        }

        System.out.println(Arrays.stream(nums).sum() - min - min);

    }

}

Measured memory_bytes: 64040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define do(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i < (k); i ++)
#define dec(i, j, k) for(int i = j; i >= (k); i --)
#define mfil(x, k) memset(x, k, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y, true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y, true) : false; }
struct __init { __init()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cout.precision(16); cout << fixed;
    srand(time(0) ^ ul(new char));
} } static __init__;
/* default code ends here */

const int maxn = 25e6 + 10;
int n;
pii p[3];

ll dp[maxn];

int main()
{
    cin >> n;
    do(i, 0, 2)
        cin >> p[i].fi;
    do(i, 0, 2)
        cin >> p[i].se;
    do(i, 0, 2)
        if(p[i].se > p[i].fi)
            do(j, 0, n - p[i].fi)
                chkmax(dp[j + p[i].fi], dp[j] + p[i].se - p[i].fi);
    ll m = 0;
    do(i, 0, n)
        chkmax(m, dp[i]);
    n += m;
    mfil(dp, 0);
    m = 0;
    do(i, 0, 2)
        if(p[i].fi > p[i].se)
            do(j, 0, n - p[i].se)
                chkmax(dp[j + p[i].se], dp[j] + p[i].fi - p[i].se);
    do(i, 0, n)
        chkmax(m, dp[i]);
    cout << n + m << '\n';
    return 0;
}

Measured memory_bytes: 195584
from functools import lru_cache  # おまじない

l,k=map(int,input().split())

@lru_cache()     # python 素晴らしい
def rec(i,isBlack):
    if i < 0: return 0
    if i == 0: return 1 if not isBlack else 0  # black at bottom
    if isBlack: # top is black
        return rec(i-1, False) + rec(i-k, False)
    else:  # top is white
        return rec(i-1, True)

ans = sum ( rec(i,True) for i in range(1, l+1))
    
print(ans)



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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int main() {
	int n;
	cin >> n;
	LL ma, mi, sum;
	mi = 100000000;
	ma = -mi;
	sum = 0;
	for (int i = 0; i < n; i++) {
		LL a;
		cin >> a;
		ma = max(ma, a);
		mi = min(mi, a);
		sum += a;
	}
	cout << mi << " " << ma << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  string s, t; cin >> s >> t;
  int m = s.size();
  int n = t.size();

  VV dp(m+1, V(n+1));

  rep(i, m) rep(j, n) {
    dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
  }

  string ans = "";
  int i = m, j = n;
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i-1][j]) --i;
    else if (dp[i][j] == dp[i][j-1]) --j;
    else {
      ans = s[i-1] + ans;
      --i, --j;
    }
  }

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


Measured memory_bytes: 35584
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll x,k,d; cin >> x >> k >> d;
	x=abs(x);
	ll p=x/d;
	if(k<=p){
		printf("%lld\n",x-k*d);
	}
	else{
		if((k-p)%2==0){
			printf("%lld\n",x-p*d);
		}
		else{
			printf("%lld\n",abs(x-p*d-d));
		}
	}
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int q = 0; q < n; q++){
        cin >> a[q];
        a[q]--;
    }
    vector<int> ans;
    bool was[n] = {};
    int q1 = 0;
    while (!was[q1]){
        was[q1] = true;
        ans.push_back(q1);
        q1 = a[q1];
    }
    if (k < ans.size()){
        cout << ans[k]+1 << endl;
    }else{
        k -= ans.size();
        int ind = -1;
        for (int q = 0; q < ans.size(); q++){
            if (ans[q] == q1){
                ind = q;
                break;
            }
        }
        cout << ans[ind+k % (ans.size()-ind)]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 7068
while True:
    n, m, a = map(int, input().split())
    if n == 0: break
    ls = [[0 for i in range(n+1)] for i in range(1001)]
    for i in range(m):
        h, p, q = map(int, input().split())
        ls[h][p] = 1
    ls.reverse()
    for t in ls:
        if t[a] == 1:
            a += 1
        elif t[a-1] == 1:
            a -= 1
    print(a)

Measured memory_bytes: 8440
#include<stdio.h>

int main()
{
   int h,w,i,j;


for(;;)
{
       scanf("%d %d",&h,&w);
       if(h==0 && w==0)
        break;
   for(i=0;i<h;i++)
   {
       for(j=0;j<w;j++)
       {
           printf("#");
       }
       printf("\n");
   }

   printf("\n");
}


}



Measured memory_bytes: 2136
# 先頭のB1から順番に処理をする
# Biはi番目に残っている敵の数をCiとして
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sum = 0
c = a
for i in range(n):
    if c[i] > b[i]:
        sum += b[i] # 同じ街の敵のみ倒して終了
    elif c[i+1] > b[i] - c[i]: #次の街の敵も倒せるが、途中で力つきる
        sum += b[i]
        c[i+1] = c[i+1]-b[i]+c[i]
    else: #次の街まで全員倒した
        sum += c[i+1] + c[i]
        c[i+1] = 0
print(sum)


Measured memory_bytes: 82020