akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace AtCorder.DP
{
    class EDPC_A
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var dp = new int[n];

            dp[0] = 0;
            dp[1] = Math.Abs(h[1] - h[0]);

            for (int i = 2; i < n; i++)
                dp[i] = Math.Min(dp[i - 2] + Math.Abs(h[i] - h[i-2]), dp[i - 1] + Math.Abs(h[i] - h[i - 1]));
            Console.WriteLine(dp[n - 1]);
        }
    }
}


Measured memory_bytes: 18016
unittest
{
	assert( [ "3 5" ].parse.expand.solve == 0 );
	assert( [ "4 5" ].parse.expand.solve == 2 );
	assert( [ "5 5" ].parse.expand.solve == 4 );
	assert( [ "100000 2" ].parse.expand.solve == 1 );
	assert( [ "100000 100000" ].parse.expand.solve == 50000 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	return tuple( hw[ 0 ], hw[ 1 ] );
}

auto solve( long h, long w )
{
	// 差が小さいほうを取る
	return div3( h, w );
}

auto div3( long h, long w )
{
	if( h % 3 == 0 || w % 3 == 0 ) return 0L;		// マス目に沿って均等に三等分できる
	
	// 三分割したときのサイズを計算
	auto dws = h * ( w / 3 );		// 縦に分割（小さいほう）
	auto dwb = h * ( w / 3 + 1 );		// 縦に分割（大きいほう）
	auto dhs = w * ( h / 3 );		// 横に分割（小さいほう）
	auto dhb = w * ( h / 3 + 1 );		// 横に分割（大きいほう）
	
	// 残りの部分を二等分したときの1つの大きさを計算
	auto rss = new long[ 3 ][ 4 ];
	rss[ 0 ] = dws ~ div2( h, w - w / 3 );
	rss[ 1 ] = dwb ~ div2( h, w - ( w / 3 + 1 ) );
	rss[ 2 ] = dhs ~ div2( h - h / 3, w );
	rss[ 3 ] = dhb ~ div2( h - ( h / 3 + 1 ), w );
	
	// 差が一番小さいものを取る
	auto r = 100000L;
	foreach( rs; rss )
	{
		auto mm = rs.reduce!( max, min );
		r = min( r, mm[ 0 ] - mm[ 1 ] );
	}
	return r;
}

auto div2( long h, long w )
{
	// 二分割したときのサイズを計算
	auto dws = ( 2 <= w ) ? h * ( w / 2 ) : 1000000;		// 縦に分割（小さいほう）
	auto dwb = ( 2 <= w ) ? h * ( w / 2 + 1 ) : 1000000;		// 縦に分割（大きいほう）
	auto dhs = ( 2 <= h ) ? w * ( h / 2 ) : 1000000;		// 横に分割（小さいほう）
	auto dhb = ( 2 <= h ) ? w * ( h / 2 + 1 ) : 1000000;		// 横に分割（大きいほう）
	
	// 偶数行数または偶数列数の場合は等分できる
	if( w % 2 == 0 ) return [ dws, dws ];
	if( h % 2 == 0 ) return [ dhs, dhs ];
	
	// 奇数行数または奇数列数の場合は片方にかたよる
	if( h < w ) return [ dwb, dws ];
	else        return [ dhs, dhb ];
}


Measured memory_bytes: 380
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans1 = 0.0;
    ans1 = w * h / 2;

    int ans2 = 0;
    if((x == w / 2) && (y == h / 2)) {
        ans2 = 1;
    }

    cout << fixed << setprecision(15) << ans1 << " " << ans2 << endl;
}

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

int main(){
  string S;
  cin >> S;
  
  sort(S.begin(), S.end());
  if(S.at(0) == S.at(1) && S.at(1) != S.at(2) && S.at(2) == S.at(3))
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
//abc157-3
//date 03/05
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(void)
{
  int N   = 0;          //N
  int M   = 0;          //M
  int ans = 0;          //最小値
  int cal = 1;          //作業用
  bool flag = true;     //矛盾がないか確認
  int s[5]    = {0};    //s[i]
  int c[5]    = {0};    //c[i]
  int rank[3] = {-1};   //各桁の値

  //値の読み込み
  scanf("%d %d",&N,&M );
  for (size_t i = 0; i < M; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }

  for (size_t i = 0; i < M; i++) {
    //左端の位の値が0となる場合
    if (s[i] == 1 && c[i] == 0 && N>=2) {
      flag = false;
    }
    //同じ位を表しているのに、異なる数値が表されている場合
    for (size_t j = i; j < M; j++){
      if (s[i] == s[j] && c[i] != c[j]) {
        flag = false;
      }
    }
    //左からs[i]番目の数値をrank[s[i]-1]に格納
    rank[s[i]-1] = c[i];
  }

  //出力部
  //存在しない
  if (flag == false) {
    printf("-1\n" );
  }
  //存在する
  else{
    //左端が指定されていないとき、一桁なら0、二桁以上なら1を格納
    if (rank[0] == -1 && N >= 2) {
      if (N >= 2) {
        rank[0] = 1;
      }else rank[0] = 0;
    }
    for (size_t i = 0; i < N; i++) {
      cal = 1;
      //printf("rank[%d] = %d\n",i,rank[i] );
      if (rank[i] != -1) {
        //calに10^(N-1-i)を格納
        for (size_t j = i; j < N-1; j++) {
          cal*=10;
        }
        //足し合わせ
        ans += rank[i] * cal;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}


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

using namespace std;


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

	vector <int> v(3);

	cin >> v[0] >> v[1] >> v[2];

	sort(v.rbegin(),v.rend());

	cout << 10*v[0] + v[1] + v[2] << '\n';
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int i,n;
  scanf("%d",&n);
  char a[n],b[n];
  scanf("%s %s",a,b);
  for(i=0;i<n;i++){
    printf("%c%c",a[i],b[i]);
    if(i==n-1) printf("\n");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Scanner;

/*
問題文

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long x = sc.nextInt();

        long[][] input = new long[n][m+1];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m + 1; j++) {
                input[i][j] = sc.nextInt();
            }
        }

        int ans = 1200001;

        // 2^Nの買う、買わないの全通りを探索する
        for (int i = 0; i < Math.pow(2,n); i++) {
            boolean flg = true;
            int[] arr = new int[m];
            int sum = 0;

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

                // 買う場合、金額の計算と、この組み合わせの中で
                // アルゴリズムの習熟度がx以上になるかを計算する
                if ((1 & i >> j) == 1) {
                    sum+=input[j][0];   // 金額の計算
                    
					for(int k = 1; k <= m; k++)   // Aj,1 Aj,2  ⋯ Aj,M の縦の足し算
					{
						arr[k-1]+=input[j][k];
					}
                };
            }
            // 合計結果について、一つずつ、x以上となっているか確認
            for (int j = 0; j < m; j++) {
                if (arr[j] < x) {
                    flg = false;
                }    
            }
            // 習熟度がx以上の場合
            if (flg) {
                ans = Math.min(ans, sum);
            }
        }

        if (ans == 1200001) {
            System.out.println("-1");
        } else {
            System.out.println(ans);

        }
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll a,b;cin >>a>>b;
    ll g=__gcd(a,b);
    cout <<a*b/g<<endl;
    return 0;
}



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

using namespace std;

int main(void) {
  int n; cin >> n;
  
  int rmn = 0;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    if (a == rmn+1) {
      rmn++;
    }
  }

  cout << (rmn ? n - rmn : -1) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

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

using namespace std;
using Graph = vector<vector<int>>;

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

    Graph G(N+1);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }


    vector<int> guide(N+1, -1);
    vector<int> dist(N+1, -1);
    queue<int> que;

    dist[1] = 0;
    dist[0] = 0;
    que.push(1); 

    while (!que.empty()) {
        int v = que.front(); 
        que.pop();

        for (int nv : G[v]) {
            if (dist[nv] != -1) continue;

            dist[nv] = dist[v] + 1;
            guide[nv] = v;
            que.push(nv);
        }
    }

    bool flag=true;
    for(int i=2; i<=N; i++){
        if(guide[i]==-1) flag=false;
    }

    if(flag==false) puts("No");
    else{
        puts("Yes");
        for(int i=2; i<=N; i++){
            out(guide[i]);
        }
    }
    
}

Measured memory_bytes: 10572
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static int[] dp = new int[0];

    public static void main(String[] args) {
        int N = sc.nextInt();
        dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        calc(N);
        System.out.println(dp[N]);
    }

    private static void calc(int n) {
        for (int i = 1; i <= n; i++) {
            int power = 1;
            int ans = Integer.MAX_VALUE;
            while (0 <= i - power) {
                ans = Math.min(ans, 1 + dp[i - power]);
                power *= 6;
            }

            power = 1;
            while (0 <= i - power) {
                ans = Math.min(ans, 1 + dp[i - power]);
                power *= 9;
            }
            dp[i] = ans;
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  
  rep(i, N){
    cin >> A[i];
    B[A[i] - 1] = i+1;
  }
  
  rep(i, N) cout << B[i] << " ";
}

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

public class Main{

	static final Scanner s=new Scanner(System.in);

	public static void main(String args[]){
		char[] c=s.next().toCharArray();
		for(int i=s.nextInt();i>0;i--) {
			switch(s.next()){
			case "replace":
				int bufa=s.nextInt(),bufb=s.nextInt();
				String in=s.next();
				for(;bufa<=bufb;bufa++)
					c[bufa]=in.charAt(in.length()-1-bufb+bufa);
				break;
			case "reverse":
				reverse(c,s.nextInt(),s.nextInt());
				break;
			case "print":
				System.out.println(
						String.valueOf(
								Arrays.copyOfRange(c,s.nextInt(),s.nextInt()+1)
								)
						);
				break;
			}
		}
	}


	public static void swap(char[] c, int a, int b){
		char x=c[b];
		c[b]=c[a];
		c[a]=x;
	}
	public static void reverse(char[] c, int l, int r){
		int buf=(l+r+1)/2;
		for(int i=l; i<buf; i++){
			swap(c,i,r-i+l);
		}
	}
}

Measured memory_bytes: 29116
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

ll power(ll a,ll b)
{
    if(b==0)
    return 1;
    
    ll x=0;
    if(b%2==0)
    {
        x=power(a,b/2);
        return (x*x);
    }
    else
    {
        x=power(a,b-1);
        return a*x;
    }
}

int main()
{
    arena
    ll n;
    cin>>n;
    if(n%2!=0)
    {cout<<"0";
    return 0;}
    
    n=n/2;
    ll k=1;
    ll sum=0;
    while((n/(power(5,k)))>0)
    {
        sum+=(n/power(5,k));
        k++;
    }
    cout<<sum;
}

Measured memory_bytes: 256
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace Fish.aizu
{
	public static class AizuOnlineJudge
	{
		public static int[] SplitToInts(string line)
		{
			return line.Split(' ').Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return line.Split(' ').Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return line.Split(' ').Select(x => long.Parse(x)).ToArray();
		}
		public static int Main()
		{
			Compute(Console.In, Console.Out);
			return 0;
		}
		
		public static void Compute(TextReader reader, TextWriter writer)
		{
			var line = reader.ReadLine();
			var stringBuilder = new StringBuilder(line.Length);
			foreach (var c in line)
			{
				stringBuilder.Append(char.IsLower(c) ? char.ToUpper(c) : char.ToLower(c));
			}
			writer.WriteLine(stringBuilder.ToString());
		}
	}
}

Measured memory_bytes: 5636
import math

a, b, h, m = list(map(int, input().split()))
deg_a = (60 * h + m) * 0.5
deg_b = 6 * m
deg = deg_a - deg_b
rad = math.radians(deg)

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(c2 ** 0.5)


Measured memory_bytes: 9496
abc ="abcdefghijklmnopqrstuvwxyz"
word = input()
num = 0
for i in range(26):
    for j in range(len(word)):
        if word[j] == abc[i]:
            num = num + 1
    if num % 2 != 0:
        break
    num = 0
if num % 2 != 0:
    print("No")
else:
    print("Yes")

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

int main() {
  string s;
  cin >> s;
  bool flag = 1;
  rep(i, 3) {
    if (s.at(i) == s.at(i+1)) flag = 0;
  }
  if (flag) cout << "Good" << endl;
  else cout << "Bad" << endl;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
cnt = 0
B = []
ans = 0
for i in range(N + 1):
    if cnt == 0:
         B += list(map(int, input().split()))
         cnt += 1
    else:
        L = list(map(int, input().split()))
        judge = 0
        for i in range(len(L)):
            judge += L[i] * B[i]
        judge += C
        if judge > 0:
            ans += 1


print(ans)


Measured memory_bytes: 3060
N,K = map (int, input ().split ())
a = input ()
if a[K-1] == 'A':
  print (a[:K-1]+'a'+a[K:])
elif a[K-1] == 'B':
  print (a[:K-1]+'b'+a[K:])
else:
  print (a[:K-1]+'c'+a[K:])

Measured memory_bytes: 9116
def solve():

    N, K = [int(i) for i in input().split()]
    xlist = [int(i) for i in input().split()]

    cost = float("inf")

    for i in range(N-K+1):
        j = i+K-1
        cost = min(
            cost,
            abs(xlist[i])+abs(xlist[j]-xlist[i]),
            abs(xlist[j])+abs(xlist[i]-xlist[j])
        )

    print(cost)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 62576
# include <iostream>
# include <cstdio>
using namespace std;
int a,b,c,x,y,ans;
int main()
{
  scanf("%d %d %d",&a,&b,&c);
  if(a > b)swap(a,b);if(b > c)swap(b,c);
  if(a > b)swap(a,b);
  ans = c - b + (b - a) / 2;
  if((b - a) & 1)ans += 2;
  printf("%d\n",ans);
}

Measured memory_bytes: 256
import itertools

N,C=map(int,input().split())
D=[[] for _ in range(C)]
c=[[] for _ in range(N)]

for i in range(C):
    D[i]=list(map(int,input().split()))
    
for i in range(N):
    c[i]=list(map(int,input().split()))
    
hist=[[0]*C for i in range(3)]#hist[i][j]は余りiのマスにj色のマスがいくつあるか
    
    
for i in range(N):
    for j in range(N):
        rem=(i+j+2)%3
        hist[rem][c[i][j]-1]+=1
    
ans=10**10
for cset in itertools.permutations(range(C), 3):
    temp=0
    for i in range(3):
        for j in range(C):
            temp+=hist[i][j]*D[j][cset[i]]
    ans=min(ans,temp)
    
print(ans)
    

Measured memory_bytes: 43740
import collections


N = int(input())
a = list(map(int, input().split()))
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
    print("Yes")
elif (L == 2) and (C[0] > 0) and (C[e[0]] * 2 == C[e[1]]):
    print("Yes")
elif (L == 3) and (C[e[0]] == C[e[1]] == C[e[2]]) and ((e[0] ^ e[1]) == e[2]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14468
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int a[105];
  cin>>n;
  int ans=0;
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i++)
  {
      if((!(i&1))&&a[i]&1)
        ans++;
  }
  cout<<ans<<endl;
}


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

int main(){
    int n = 0;
    int a,b,x;
    cin >> a>>b>>x;
    
    int flag=0;
    int ans=0;

    if(a>x)flag=0;
    else{
        if(b-1 >= x-a)flag=1;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    if(flag==1)cout << "YES" <<endl;
    else cout << "NO" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <float.h>
#include <math.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    double  resv = DBL_MAX;
    int     resn = 0;
    int     n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    while ( n-- )
    {
      double bmi;
      int i, h, w;

      scanf ( "%d%d%d", &i, &h, &w );
      bmi = fabs ( 22. - (double)( w ) / (double)( h * h ) * 10000. );

      if ( bmi < resv )
      {
        resv = bmi;
        resn = i;
      }
    }

    printf ( "%d\n", resn );
  }

  return ( 0 );
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], W = l[1];

            var max = N * 1000;
            var dp = new long[N + 1, max + 1];

            for (var i = 0; i <= N; i++) for (var j = 0; j <= max; j++) dp[i, j] = long.MaxValue / 2;
            dp[0, 0] = 0;

            for (var i = 0; i < N; i++)
            {
                var wv = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (var j = 0; j <= max; j++)
                {
                    if (j - wv[1] >= 0)
                    {
                        dp[i + 1, j] = Math.Min(dp[i, j], dp[i, j - wv[1]] + wv[0]);
                    }
                    else
                    {
                        dp[i + 1, j] = dp[i, j];
                    }
                }
            }

            for (int i = max; i >= 0; i--)
            {
                if (dp[N, i] <= W)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }
    }
}


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

long long n,a,b;
int main() {
	cin>>n>>a>>b;
	if(((b-a)&1)==0) {//直接相遇。
		cout<<(b-a)/2;
		return 0;
	}
	
	long long timl=(a-1)+(b-a+1)/2,
	timr=(n-b)+(b-a+1)/2;
	cout<<min(timl,timr);
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int s = max(a, c), f = min(b, d);
    cout << max(0, f - s) << '\n';
    return 0;
}


Measured memory_bytes: 256
import math
S = input()
pt1 = "01"*math.ceil(len(S)/2)
pt2 = "10"*math.ceil(len(S)/2)
if len(pt1) != len(S):
    pt1 = pt1[:-1]
    pt2 = pt2[:-1]
ans = []
tmp1 = 0
tmp2 = 0
for i in range(len(S)):
    if S[i] != pt1[i]:
        tmp1 += 1
    if S[i] != pt2[i]:
        tmp2 += 1
print(min([tmp1,tmp2]))

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

using namespace std;

int main()
{
  while(1){
    int K;
    cin>>K;
    if(K == 0){
      break;
    }

    int pair = (K * (K-1)) / 2;
    int sum = 0;
    for(int i = 0; i < pair;++i){
      int a;
      cin>>a;
      sum += a;
    }

    sum = sum / (K-1);
    cout<<sum<<endl;
  }
  return 0;
}


Measured memory_bytes: 2988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;


int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N+1), B(N);
	for (ll i = 0; i < N+1; ++i)
		cin >> A[i];
	for (ll i = 0; i < N; ++i)
		cin >> B[i];

	ll res{0};
	for (ll i = 0; i < N; ++i)
	{
		// i and i + 1
		ll b = min(A[i], B[i]);
		res += b;
		if (b == A[i])
		{
			B[i] -= b;
			ll bb = min(A[i+1], B[i]);
			res += bb;
			A[i+1] -= bb;
		}
	}
	std::cout << res << std::endl;
}


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

int main(){
	char tbl[100] = "";
	int rtbl[128] = {};
	int x = 0;
	for(char c = 'a'; c <= 'z'; ++c){
		tbl[x] = c;
		rtbl[c] = x;
		++x;
	}
	for(char c = 'A'; c <= 'Z'; ++c){
		tbl[x] = c;
		rtbl[c] = x;
		++x;
	}

	int n;
	while(cin >> n, n){
		vector<int> k(n);
		for(int i = 0; i < n; ++i){
			cin >> k[i];
		}
		string s, t;
		cin >> s;

		x = 0;
		for(int i = 0; i < s.size(); ++i){
			t += tbl[(rtbl[s[i]] - k[x] + 52) % 52];
			x = (x + 1) % n;
		}
		cout << t << endl;
	}
}

Measured memory_bytes: 1208
taka_h, taka_a, aoki_h, aoki_a = map(int, input().split())

while True:
    aoki_h -=taka_a
    taka_h -= aoki_a
    if(aoki_h <=0):
        print("Yes")
        break
    elif(taka_h <= 0):
        print("No")
        break

Measured memory_bytes: 9172
#include<cstdio>
const int N=2e5+10;
int ans,next[N],head[N],t[N],f[N],bz[N],tot; 
void ad(int x,int y)
{
	tot++;
	next[tot]=head[x];
	head[x]=tot;
	t[tot]=y;
}
int max(int x,int y)
{
	if (x>y) return x;
	return y;
}
int min(int x,int y)
{
	if (x<y) return x;
	return y;
}
void dfs(int x,int fa)
{
	int i=head[x],l=0;
	while (i)
	{
		if (t[i]==fa) 
		{
			i=next[i];
			continue;
		}
		dfs(t[i],x);
		l=l|(bz[x]&bz[t[i]]);
		bz[x]=bz[x]|bz[t[i]];
		i=next[i];
	} 
	if (!bz[x]) bz[x]=1;
	else 
	{
		while ((1<<f[x])<l||(1<<f[x])&bz[x]) f[x]++;
		bz[x]=(bz[x]>>f[x]<<f[x])|(1<<f[x]);
	}
	ans=max(ans,f[x]);
}
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		ad(x,y);
		ad(y,x);	
	}
	dfs(1,0); 
	printf("%d\n",ans); 
} 

Measured memory_bytes: 6272
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
	int a, b = 0;
	char op[5];
	while (true){
		cin >> a >> op >> b;
		if (op[0] == '+'){
			cout << a + b << endl;
		}
		else if (op[0] == '-'){
			cout << a - b << endl;
		}
		if (op[0] == '*'){
			cout << a*b << endl;
		}
		if (op[0] == '/'){
			cout << a / b << endl;
		}
		if (op[0] == '?'){
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3076
/*
 *  - 中途半端に解く配点は 1 種類以下であり、それ以外の配点は完全に解くかまったく解かない。
 *  - 中途半端に解く配点があるなら、それは完全に解く配点以外の配点の中で最も高い配点である。
 *  はーなるほどね……この考察が出来ず永遠に解けなかったので editorial 読みました
 */

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

#define update debug("Update!"); ret = tmp; debug(tmp); debug(i);

int main(int argc, const char* argv[]) {
	ll d, g;
	cin >> d >> g;

	ll ret = 0;
	vector<ll> p(d), c(d);
	rep(i, d) {
		cin >> p[i] >> c[i];
		ret += p[i];
	}

	rep(i, 1 << d) {
		ll max_incomplete = -1;
		ll score = 0;
		ll tmp = 0;
		rep(j, d) {
			if( (i & (1 << j)) != 0 ) {
				tmp += p[j];
				score += 100 * (j + 1) * p[j] + c[j];
			} else {
				max_incomplete = j;
			}
		}

		if(score >= g) {
			if(tmp < ret) {
				update;
			}
			continue;
		}

		if(max_incomplete < 0) {
			cerr << "Error! Error! Error! Error! Error! Error! Error! Error! Error! Error! Error! " << endl;
			debug(i);
			debug(tmp);
			debug(score);
			return 0;
		}

		ll n = ( (g - score) + ((max_incomplete + 1) * 100) - 1 ) / ((max_incomplete + 1) * 100); // 中途半端に解く問題は n 問解く必要がある
		debug(g - score);
		debug(max_incomplete);
		debug(n);
		if(n > p[max_incomplete]) continue; // n 問解きたいけど、そんなに出題されないなら不適
		tmp += n;
		if(tmp < ret) {
			update;
		}
	}

	cout << ret << endl;

	return 0;
}


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

public class Main {

	public static void main(String[] args) throws Exception {
		String line = readLine();
		String[] strArray = line.split(" ");
		int[] array = new int[strArray.length];
		for(int i = 0; i < array.length; i++ ) {
			array[i] = Integer.parseInt(strArray[i]);
		}
		int distanceA = Math.abs(array[0] - array[1]);
		int distanceB = Math.abs(array[0] - array[2]);
		if(distanceA < distanceB) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}
	}


	private static String readLine() throws Exception {
		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
		return br.readLine();
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    int dp[n] = {};
    for (int i = 1; i <= n; i++) {
        dp[i] = dp[i - 1] + 1;
        int num6 = 6;
        while (num6 <= i) {
            dp[i] = min(dp[i], dp[i - num6] + 1);
            num6 *= 6;
        }
        int num9 = 9;
        while (num9 <= i) {
            dp[i] = min(dp[i], dp[i - num9] + 1);
            num9 *= 9;
        }
    }

    cout << dp[n] << endl;
    return 0;
}


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

int main() {
    int n, ans = 0;
    string x;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i] >> t[i];
    }
    cin >> x;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == x && i < n - 1) {
            for (int j = i+1; j < n; j++)
            {
                ans += t[j];
            }
            cout << ans << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

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

int main() {
  
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  int ans = 0;
  REP(i,k+1) {
    if (a >= b) b*=2;
    else if (b >= c) c *= 2;
    else ans = 1;
  }
  
  if (ans == 1) cout << "Yes" << endl;
  else cout << "No" << endl; 

}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A==7&&B==5&&C==5) {
    cout << "YES" << endl;
  }
  else if (A==5&&B==7&&C==5) {
    cout << "YES" << endl;
  }
  else if (A==5&&B==5&&C==7) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
#include<array>
#include<algorithm>
#include<queue>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
#include<bitset>
#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}
//long nHr(int n, int r) {
//	n = n + r - 1;
//	return nCr(n, r);
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}



void solve(){
 ll n,k;
 cin >> n >> k;
 g(min(n % k,k-n%k))  ; 
}
int main()
{
#ifndef ONLINE_JUDGE
input_from_file
#endif
 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
    //cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

class segtree{

    public:
    int N;
    ll init_val;
    vector<ll>dat;

    segtree(int _n,ll _init_val):init_val(_init_val){
        N=1;while(N < _n)N*=2;
        dat.resize(2*N - 1,_init_val);
    }

    void error_op(){cout<<init_val<<endl;}//クエリの例外処理

    void UpD_RMQ(int k,ll a){
        k += N-1;dat[k]=a;
        while(k > 0){
            k = (k-1)/2;//親へ移動
            dat[k] = min( dat[2*k+1],dat[2*k+2] );//子を比較(片方はさっき更新したやつ)
        }
    }

    void UpD_RSQ(int k,ll add){
        k += N-1;dat[k]+=add;
        while(k > 0){
            k=(k-1)/2; dat[k]+=add;
        }
    }

    ll Query_RSQ(int st,int ed,int idx,int l,int r){//st<=x<edのRSQを返す  ※dat[idx]は、l<=idx<rのクエリを持つ。
        //db3(dat[idx],l,r);ln;
        
        if(r <=st || ed <= l){return init_val;}
        else if(st <= l && r <= ed)return dat[idx];//答えが判明するのはここ
        else{
            ll ar = Query_RSQ(st,ed,idx*2 + 1, l , (l+r)/2 );
            ll al = Query_RSQ(st,ed,idx*2 + 2, (l+r)/2 , r);
            return ar+al;
        }
    }
    ll Query_RMQ(int st,int ed,int idx,int l,int r){//st<=x<edのRMQを返す  ※dat[idx]は、l<=idx<rのクエリを持つ。
        //db3(dat[idx],l,r);ln;
        if(r <=st || ed <= l){return init_val;}
        else if(st<=l && r<=ed)return dat[idx];//答えが判明するのはここ
        else{
            ll ar = Query_RMQ(st,ed,idx*2 + 1, l , (l+r)/2 );//子へ再帰的にクエリを渡す
            ll al = Query_RMQ(st,ed,idx*2 + 2, (l+r)/2 , r );//
            return min(ar,al);
        }
    }

};

int main(){

    ll ans=0;
    int n,q;
    cin>>n>>q;

    segtree sgt(n,INF);
    //db(sgt.N);ln;

    rep(i,q){
        int com;
        cin>>com;

        if(com==0){
            int i,x;
            cin>>i>>x;
            sgt.UpD_RMQ(i,x);
        }else{
            int s,t;
            cin>>s>>t;++t;
            cout << sgt.Query_RMQ(s,t,0,0,(sgt.N)) <<endl;
        }
    }

    //cout<<ans<<endl;
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}



Measured memory_bytes: 4884
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
int n, m, h[100009], x, y;
vector<int> g[100009];
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=1;i<=m;i++) {
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int ans = 0;
    for(int i=1;i<=n;i++) {
        bool p = 1;
        for(auto el : g[i]) {
            if(h[el] >= h[i]) {
                p = 0;
                break;
            }
        }
        ans += p;
    }
    cout<<ans;
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


Measured memory_bytes: 9172
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        
        if (r - l >= 2018) {
            System.out.println(0);
            return;
        }
        
        int min = 2000000000;
        for (int i = l; i < r; i++) {
            for (int j = l + 1; j <= r; j++) {
                int tmp = i % 2019;
                int tmp2 = j % 2019;
                min = Math.min(min, ((int)tmp*tmp2)%2019);
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 35824
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int32_t main() {
    int n, h; cin >> n >> h;
    vector<pair<int,bool> > v;
    rep (i,n) {
        int a,b; cin >> a >> b;
        v.emplace_back(a,true);
        v.emplace_back(b,false);
    }
    sort(all(v)); reverse(all(v));
    int c = 0;
    for (cauto &p : v) {
        if (p.snd) {
            c += (h+p.fst-1)/p.fst;
            break;
        } else {
            h -= p.fst;
            c++;
            if (h <= 0) break;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
void solve(){
    int n;
    cin >> n;
    int a[n];
    set<int> s;
    for(int &i : a){
        cin >> i;
        if(s.find(i) == s.end()){
            s.insert(i);
        }else{
            s.erase(i);
        }
    }
    cout << (int)s.size() << '\n';
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        solve();
    }
}

Measured memory_bytes: 39796
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> vec(N + 1, 0);
  for (int i = 1; i < N; i++) {
    if (S[i - 1] == 'A' && S[i] == 'C') {
      vec[i+1] = vec[i] + 1;
    } else {
      vec[i+1] = vec[i];
    }
  }

  while(Q--) {
    int l, r;
    cin >> l >> r;
    cout << vec[r] - vec[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000


int main()
{
    fastio;
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    ll c=0;
    ll ans = INT_MIN;
    ll i;
    ll diff[n];
    
    for(i=0;i<n;i++){
    cin>>a[i];
    cin>>b[i];
    }
    for(i=0;i<n;i++)
    diff[i] =  a[i]-b[i];
    for(i=0;i<n;i++)
    {
        if(diff[i]==0)
        c++;
        else
        {
            ans = max(c,ans);
            c=0;
        }
    }
    ans = max(c,ans);
    if(ans>=3)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3648
// AOJ 2856: Window
// 2017.11.23 bal4u@uu

#include <stdio.h>

char buf[102];
char f[10102];

int main()
{
	int n, h, w, x;
	int i, l, r, ans;
	
	scanf("%d%d%d", &n, &h, &w);
	for (i = 0; i < n; i++) {
		scanf("%d", &x);
		l = i*w, r = l+w;
		if (i & 1) l -= x, r -= x;
		else       l += x, r += x;
		if (l < 0) l = 0;
		while (l < r) f[l++] = 1;
	}
	ans = 0, i = n*w; while (i--) if (!f[i]) ans++;
	printf("%d\n", ans*h);
	return 0;
}

Measured memory_bytes: 1852
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World"<< endl;
    }
    else{
        int A,B;
        cin >> A>> B;
        cout << A+B<<endl;
    }

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  double a;
  double sum=0.0;
  string c;
  for(int i=0;i<N;i++){
    cin >> a >> c;
    if(c=="BTC"){sum+=a*380000.0;}
    else{sum+=a;}
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
int prime(int n) {
    int i, flag = 0;
    if(n==2)
    return 1;
    for (i = 2; i <= sqrt(n) + 2; ++i) {

        // condition for non-prime
        if (n % i == 0) {
            flag = 1;
            break;
        }
    }

    if (n == 1) {
        // printf("1 is neither prime nor composite.");
        return 0;
    }
    else {
        if (flag == 0)
            return 1;
        else
            return 0;
    }
    return 0;
}
int main()
{
    int x,i;
    scanf("%d",&x);
    while(prime(x)!=1)
    {
        x+=1;
    }
    printf("%d",x);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = [list(map(int, input().split())) for _ in range(2)]
b = [[0] * n for _ in range(2)]
b[0][0] = a[0][0]
for i in range(1, n):
  b[0][i] = b[0][i - 1] + a[0][i]
b[1][n - 1] = a[1][n - 1]
for i in range(1, n):
  b[1][n - 1 - i] = b[1][n - i] + a[1][n - 1 - i]
print(max(b[0][i] + b[1][i] for i in range(n)))


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

int main() {
	
	int n;
	cin >> n;
	int i, x1 = 0, x0 = 0, x2 = 0;
	for (i = 0; i < n; i++)
	{
	    int a;
	    cin >> a;
	    if (a%4 == 0)
	    x0++;
	    else if (a%4 == 2)
	    x2++;
	    else
	    x1++;
	}
	if ((x2 == 0 and x0 >= n/2) or (x2 > 0 and x0 >= x1))
	cout << "Yes";
	else
	cout << "No";
	
	return 0;
}


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

using namespace std;

long long n,len,q;
long long num;
long long block;
long long a[100010];
long long b[100010];
long long to[100010];
long long next[100010];
long long step[100010];

int find(int x)
{
	int ans=0;
	int l=x+1;
	int r=n;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(a[mid]-a[x]<=len)
		{
			l=mid+1;
			ans=mid;
		}
		else
		{
			r=mid-1;
		}
	}
	return ans;
}

void build(void)
{
	for(int i=1;i<n;i++)
	{
		to[i]=find(i);
	}
	to[n]=n+1;
	block=sqrt(n);
	num=ceil(n/block);
	for(int i=1;i<=n;i++)
	{
		b[i]=(i-1)/block+1;
	}
	for(int i=1;i<=n;i++)
	{
		int p=i;
		int cnt=0;
		while(b[p]==b[i])
		{
			p=to[p];
			cnt++;
		}
		next[i]=p;
		step[i]=cnt;
	}
}

int query(int x,int y)
{
	int res=0;
	while(b[x]<b[y])
	{
		res+=step[x];
		x=next[x];
	}
	while(x<y)
	{
		x=to[x];
		res++;
	}
	return res;
}

int main(void)
{
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	cin >> len >> q;
	build();
	for(int i=1;i<=q;i++)
	{
		int x,y;
		cin >> x >> y;
		if(x>y)
		{
			swap(x,y);
		}
		cout << query(x,y) << endl;
	}
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;
const int MAX = 1e5;

int n, color[MAX];
vector<int> G[MAX];

void dfs(int r, int c) {
  color[r] = c;
  REP(i, G[r].size()) {
    int v = G[r][i];
    if (color[v] == -1) {
      color[v] = r;
      dfs(v, c);
    }
  }
}

int main() {
  int s, t, m, q, id = 0;
  cin >> n >> m;
  REP(i, m) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  REP(i, n) color[i] = -1;
  REP(i, n) { if (color[i] == -1) dfs(i, id++); }
  cin >> q;
  REP(i, q) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 13612
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, A, B, C, D, E = sc.nextLong
    val min = Array(A, B, C, D, E).min
    val result = (Math.ceil(N / min.toDouble) + 4).toLong
    println(result)
  }
}


Measured memory_bytes: 27336
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll mod = 1e9 + 7;
int main() {
	ll N;
	cin >> N;
	vector<ll> W(N);
	vector<ll> S(N);
	ll Wma = -(1e13);
	ll Sma = -(1e13);
	ll Wmi = (1e13);
	ll Smi = (1e13);

	rep(i, N) {
		ll x, y;
		cin >> x >> y;
		W.at(i) = x + y;
		S.at(i) = x - y;
		Wma = max(Wma, W.at(i));
		Sma = max(Sma, S.at(i));
		Wmi = min(Wmi, W.at(i));
		Smi = min(Smi, S.at(i));
	}
	cout << max(Wma - Wmi, Sma - Smi) << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  int N, K; cin >> N >> K;
  string result = ((N+1)/2>=K) ? "YES" : "NO";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger a, b, c;
		a = new BigInteger(sc.next());
		b = new BigInteger(sc.next());
		c = new BigInteger(sc.next());
		System.out
				.println(a.multiply(b).multiply(new BigInteger("4")).compareTo(c.subtract(a).subtract(b).pow(2)) == -1 && c.subtract(a).subtract(b).compareTo(new BigInteger("0")) == 1 ? "Yes" : "No");

	}

}


Measured memory_bytes: 21972