akhauriyash/Code-Regression huggingface dataset:
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

// ユークリッドの互除法
fn gcd(x: u64, y: u64) -> u64 {
    let low: u64;
    let high: u64;

    if x > y { 
        high = x;
        low = y;
    } else {
        low = x;
        high = y;
    }

    if low == 0 { high }
    else { gcd(high%low, low) }
}

fn main() {
    let ab: Vec<u64> = read_vec();
    let a = ab[0];
    let b = ab[1];

    let ab_gcd = gcd(a, b);

    println!("{}", a*b/ab_gcd);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	long long n,a[200000],i,z=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		a[i]-=i;
	}
	sort(a,a+n);
	for(i=0;i<n;i++){
		z+=abs(a[n/2]-a[i]);
	}
	cout<<z;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int a;
int main (){
    scanf ("%d", &a);
    printf ("%d\n", 3 * (a * a));
}

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

int main() {
  string S;
  cin >> S;
  int kurokara = 0, shirokara = 0, ans;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      if (S.at(i) == '0') {
        shirokara++;
      }
      else {
        kurokara++;
      }
    }
    else {
      if (S.at(i) == '0') {
        kurokara++;
      }
      else {
        shirokara++;
      }
    }
  }
  ans = min(kurokara, shirokara);
  cout << ans << endl;
  return 0;
}


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

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()


Measured memory_bytes: 68288
#include <iostream>

using namespace std;

int N, M;
const int N_max = 50;
const int M_max = 50;
char A[N_max][N_max], B[M_max][M_max];

int main(){
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin >> A[i][j];
		}
	}
	for(int i = 0; i < M; i++){
		for(int j = 0; j < M; j++){
			cin >> B[i][j];
		}
	}

	bool ans = false;
	bool match;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i+M-1 >= N || j+M-1 >= N){
				continue;
			}

			match = true;
			for(int y = 0; y < M; y++){
				for(int x = 0; x < M; x++){
					if(A[i+y][j+x] != B[y][x]){
						match = false;
						break;
					}
				}
			}
			if(match == true){
				ans = true;
				break;
			}
		}
		if(ans == true){
			break;
		}
	}

	if(ans == true){
		cout << "Yes" << endl;
	}else{
		cout << "No" <<endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t a, b, c, k;
  cin >> a >> b >> c >> k;
 
  if(a > k){
    cout << k << endl;
  }

  else if(a+b>=k){
    cout << a << endl;
  }
  
  else {
    cout << a - (k - (a+b)) << endl;
  }
    
}


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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int q;
int s[100010];
int t;
int ans;
int main(){
	cin>>n;
	for(int i = 0;i < n;i++){
		cin>>s[i];
	}
	cin>>q;
	ans = 0;
	for(int i = 0;i < q;i++){
		cin>>t;
		int left = 0;
		int right = n;
		while(left <=right){
			int mid = (left+right)/2;
			if(s[mid]>t){
				right =mid-1;
			}else if(s[mid]<t){
				left =mid+1;
			}else if(s[mid]==t){
				ans++;
				break;
			}
		}
	}
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 1548
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);

        int ans = 1;
        int sign = 0;
        for (int i = 1; i < N; i++)
        {
            if (sign == 0)
            {
                sign = Math.Sign(A[i] - A[i - 1]);
            }
            else
            {
                if(sign != Math.Sign(A[i] - A[i-1]) && A[i] != A[i - 1])
                {
                    sign = 0;
                    ans++;
                }
            }
        }
        Console.WriteLine(ans);

    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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


void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    ll sum=0;
    rep(i,N)sum+=B[i];
    rep(i,N)if(i>0 and A[i]-A[i-1]==1)sum+=C[A[i-1]-1];
    cout<<sum<<endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::cout<<std::fixed<<std::setprecision(10);//誤差小数10桁まで
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  cout << min((a * n), b) << endl;
  return 0;
}
//templete by private_yusuke

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N, K;
    cin >> N >> K;

    double ans = 0.0;
    REP(i, N){
        ll s = i+1;

        ll count = 0;
        while(s < K ){
            s*=2;
            count++;
        }

        ans += pow(0.5, count);
    }

    cout << ans/(double)N << endl;
}


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

namespace Joyeuse
{
	class Program
	{
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static long cln(long D = -1){
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return long.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			var Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		static string read() { return Console.ReadLine(); }
		#endregion
		
		static void Main(string[] args) {
			var K = cln();
			long[] res;
			int N=50;
			var modulo =K%N;
			var quo=K/N;
			res=new long[N];
			for(int i=0;i<N;i++){
				res[i]=N-1+quo+(modulo>i?N+1:0)-modulo;
			}
			print(N);
			print(string.Join(" ",res));
		}
	}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> csum(n, 0);
  csum[n-1] = a[n-1];
  for (int i = n - 2; i >= 0; i--) {
    csum[i] = (a[i] + csum[i+1]) % mod;
  }

  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ll tmp = a[i] * csum[i+1];
    tmp %= mod;
    ans += tmp;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
 string a;
 cin >> a;
 if(a == "SUN"){
 	cout << 7 << endl;
 }
 if(a == "MON"){
 	cout <<  6<< endl;
 }
 if(a == "TUE"){
 	cout <<  5<< endl;
 }
 if(a == "WED"){
 	cout << 4 << endl;
 }
 if(a == "THU"){
 	cout <<  3<< endl;
 }
 if(a == "FRI"){
 	cout << 2 << endl;
 }
 if(a == "SAT"){
 	cout << 1 << endl;
 }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    ll N;
    cin>>N;
    ll A[N+1], suma[N+1];
    for(ll i=0;i<=N;++i){
        cin>>A[i];
        suma[i] = A[i];
    }
    for(ll i=N-1;i>=0;--i){
        suma[i] += suma[i+1];
    }
    /**
    for(ll i=0;i<=N;++i){
        cout<<suma[i]<<" ";
    }
    cout<<endl;
    **/
    ll num[N+1];
    bool can = true;
    if(A[0]>1) can = false;
    if(A[0]==1) num[0] = 0;
    if(A[0]==0) num[0] = 1;
    for(ll i=1;i<=N;++i){
        num[i] = min(num[i-1]*2, suma[i]);
        if(num[i]<A[i]) {
            can = false;
            break;
        }
        else num[i] -= A[i];
    }
    ll ans = 0;
    if(can){
        for(ll i=0;i<=N;++i){
            ans += num[i] + A[i];
        }
        cout<<ans<<endl;
    }
    else cout<<-1<<endl;
}


Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }
  int maxh = a[0];
  long long int sum = 0;
  for(int i = 1; i <n ; i++)
  {
    if(maxh <= a[i])
    {
      maxh = a[i];
    }
    else
    {
      sum+=(maxh-a[i]);
    }
  }
  cout << sum << "\n";
}

Measured memory_bytes: 4404
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  Printf.printf "\n";
  preorder (fun e -> print_string " "; print_int e) t;
  Printf.printf "\n"

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let delete x t =
  let rec balance = function
    | Nil -> assert false
    | Node (x, Nil, r) -> (x, r)
    | Node (x, l, r) ->
      let (m, l) = balance l in
      (m, Node (x, l, r)) in
  let rec doit = function
    | Nil -> assert false
    | Node (y, l, r) ->
      if x = y then
        if l = Nil then r
        else if r = Nil then l
        else
          let (m, r) = balance r in
          Node (m, l, r)
      else if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | ["find"; n] -> print_endline (if find (int_of_string n) !t then "yes" else "no")
    | ["delete"; n] -> t := delete (int_of_string n) !t
    | _ -> print !t
  done

Measured memory_bytes: 27144
#include<stdio.h>

char pic_a[55][55],pic_b[55][55];
int N, M;

int check(int x, int y) {
	int i, j;
	int flag=0;
	for (i = 0; i < M; i++) {
		for (j = 0; j < M; j++) {		
			if (x + i < N && y + j < N) {
				if (pic_b[i][j] != pic_a[x + i][y + j]) 
					return 0;
			}
			else
				return 0;
		}
	}
	return 1;
}

int main(void) {
	int i, j,result=0;

	scanf("%d %d",&N,&M);
	for (i = 0; i < N; i++) 
			scanf("%s",pic_a[i]);
	for (i = 0; i < M; i++)
		scanf("%s", pic_b[i]);


	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (pic_b[0][0] == pic_a[i][j]) {
				result = check(i,j);
				if (result)break;
			}
		}
		if (result)break;
	}
	if (result)printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

static const int MAX_N = 100;
static const int MAX_W = 10000;

int N, W;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_N + 1][MAX_W + 1];

int dfs(int i, int j) {
  if (i >= N)
    return 0;
  if (dp[i][j] >= 0)
    return dp[i][j];
  int res = dfs(i + 1, j);
  if (j >= w[i]) {
    res = max(res, dfs(i + 1, j - w[i]) + v[i]);
  }
  return dp[i][j] = res;
}

int solve_dfs() {
  fill(dp[0], dp[0] + (MAX_N + 1) * (MAX_W + 1), -1);
  return dfs(0, W);
}

int solve() {
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= W; ++j) {
      if (j < w[i]) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }
  return dp[N][W];
}

int solve_backward() {
  for (int i = N - 1; i >= 0; --i) {
    for (int j = 0; j <= W; ++j) {
      if (j < w[i]) {
        dp[i][j] = dp[i + 1][j];
      } else {
        dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
      }
    }
  }
  return dp[0][W];
}

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; ++i) {
    cin >> v[i] >> w[i];
  }

  int ret = solve();
//  if (ret != solve_dfs())
//    return 1;
//  fill(dp[0], dp[0] + (MAX_N + 1) * (MAX_W + 1), 0);
//  if (ret != solve_backward())
//    return 1;

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 7004
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
	string S,T;
  	cin >> S >> T;
  int j = 0;
  rep(i,3){
  	if(S[i] == T[i]) j++;
  }
  cout << j << endl;
}

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

using namespace std;

const int coin[] = {10, 50, 100, 500};

int main()
{
    int pay;
    bool first = false;;

    while (cin >> pay, pay) {
        int have[4];
        int ans[4] = {0};
        int min_a = 1000000;

        if (first)
            cout << endl;

        for (int i = 0; i < 4; i++)
            cin >> have[i];

        for (int a = 0; a <= have[0]; a++)
            for (int b = 0; b <= have[1]; b++)
                for (int c = 0; c <= have[2]; c++)
                    for (int d = 0; d <= have[3]; d++) {
                        int money = a * coin[0] + b * coin[1] +
                            c * coin[2] + d * coin[3];
                        if (money < pay)
                            continue;

                        int ress = money - pay;
                        int h[4] = {have[0] - a, have[1] - b, have[2] - c,
                                    have[3] - d};


                        for (int i = 3; i >= 0; i--) {
                            int t = ress / coin[i];

                            ress -= coin[i] * t;
                            h[i] += t;
                        }
                        
                        int cnt = 0;
                        for (int i = 0; i < 4; i++)
                            cnt += h[i];
                        if (min_a > cnt) {
                            min_a = cnt;
                            ans[0] = a;
                            ans[1] = b;
                            ans[2] = c;
                            ans[3] = d;
                        }
                    }
        
        for (int i = 0; i < 4; i++)
            if (ans[i] != 0)
                cout << coin[i] << " " << ans[i] << endl;
        first = true;
    }

    return 0;
}

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

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  int count = 0;
  
  for (int i = l; i <= r; i++) {
    if (i % d == 0) {
      count++;
    }
  }
  cout << count << endl;
}

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

const int MAX_V = 505;
const int INF = 1e9;
int G[MAX_V][MAX_V];

int main(){
  int V,E;
  cin>>V>>E;
  
  for(int i=0;i<V;i++)
    for(int j=0;j<V;j++)
      G[i][j]=INF;
  
  for(int i=0;i<E;i++){
    int s,t;
    cin>>s>>t;
    G[s][t]=-1;    
  }
  
  for(int k=0;k<V;k++)
    for(int i=0;i<V;i++)
      for(int j=0;j<V;j++)
        if(G[i][j]>G[i][k]+G[k][j])
          G[i][j]=G[i][k]+G[k][j];

  for(int i=0;i<V;i++){
    if(G[i][i]<0){
      cout<<1<<endl;
      return 0;
    }
  }
  
  cout<<0<<endl;
  return 0;
}



Measured memory_bytes: 3308
import Control.Monad
main = do
  n <- read <$> getLine
  xy <- forM [1..n] $ \i -> do
    a <- read <$> getLine
    forM [1..a] $ \j -> do
      [x,y] <- map read . words <$> getLine  -- y_{ij} = 1 <=> 人x_{ij}が正直,y_{ij} = 0 <=> 人x_{ij}の発言の真偽は不明
      return (x,y)
  let oks = filter (ok xy) (powerset [1..n])
  print $ maximum $ fmap length oks

powerset :: [Int] -> [[Int]]
powerset = filterM (const [True,False]) 

ok ::[[(Int,Int)]] -> [Int] -> Bool
ok xys kinds = and [(y == 0) /= (x `elem` kinds) | i <- kinds,(x,y) <- xys !! (i-1)]


Measured memory_bytes: 6796
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[100001], b[100001];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	long long count = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (b[i] - (a[i] + count) % b[i] != b[i]) {
			count += b[i] - (a[i] + count) % b[i];
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
vector<int> vertexs[200000];
int visited[200000] = {};
int main() {
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		vertexs[a].push_back(b);
		vertexs[b].push_back(a);
	}
	vector<int> hoge,hogehoge;
	hoge.push_back(1);
	visited[1] = true;
	while (true) {
		for (int i = 0;i < vertexs[hoge[hoge.size() - 1]].size();++i) {
			if (visited[vertexs[hoge[hoge.size() - 1]][i]] == false) {
				visited[vertexs[hoge[hoge.size() - 1]][i]] = true;
				hoge.push_back(vertexs[hoge[hoge.size() - 1]][i]);
				goto ok;
			}
		}
		break;
	ok:;
	}
	hogehoge.push_back(1);
	while (true) {
		for (int i = 0;i < vertexs[hogehoge[hogehoge.size() - 1]].size();++i) {
			if (visited[vertexs[hogehoge[hogehoge.size() - 1]][i]] == false) {
				visited[vertexs[hogehoge[hogehoge.size() - 1]][i]] = true;
				hogehoge.push_back(vertexs[hogehoge[hogehoge.size() - 1]][i]);
				goto ok2;
			}
		}
		break;
	ok2:;
	}
	cout << hoge.size()+hogehoge.size()-1 << endl;
	for (int i = hogehoge.size() - 1;i > 0;--i) {
		cout << hogehoge[i] << " ";
	}
	for (int i = 0;i < hoge.size();++i) {
		cout << hoge[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 9464
#include <stdio.h>
#include <stdlib.h>
main()
{

  int i;
  int j;
  int length;
  int temp;
  int *buf;
  int minj;
  int sum = 0;

  scanf("%d",&length);
 
  buf = (int *)malloc(sizeof(int)*length);

  for(i = 0;i < length;i++)
    {
      scanf("%d",&buf[i]);
    }

  for(i = 0;i < length;i++)
    {
      minj = i;
      for(j = i;j < length;j++)
	{
	  if(buf[j] < buf[minj])
	    {
	      minj = j;
	    }
	}
      if(buf[i] != buf[minj])
	{
	  temp = buf[i];
	  buf[i] = buf[minj];
	  buf[minj] = temp;
	  sum++;
	}
    }

  for(i = 0;i < length;i++)
    {
      printf("%d",buf[i]);
      if(i != length - 1)
	{
	  printf(" ");
	}
    }
  printf("\n");
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 604
#include "bits/stdc++.h"
using namespace std;


int main() {

	int N;
	cin >> N;
	vector<int64_t> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	int count = 0;
	for (int i = 0;i < N;) {
		int count_i = 0;
		for (int j = i;j < N;j++) {
			if (A.at(i) == A.at(j)) {
				count_i++;
			}
			else {
				break;
			}
		}
		if (count_i % 2 != 0) 
			count++;
		i += count_i;
	}

	cout << count;
}


Measured memory_bytes: 1024
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.{NumericRange, Queue}
import scala.collection.mutable
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    println(if (sc.next.sorted == "abc") ("Yes") else ("No"))
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

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

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

    /*
    long long p[n];
    for(int i = 0; i < n; i++) p[i] = (long long) i + 1;

    long long maximum = 0;

    //  O(n!n)
    /*
    long long a[n];
    do {
        long long sum = 0;
        for(int i = 1; i <= n; i++) {
            sum += i % p[i - 1];
        }
        if(maximum < sum) {
            maximum = sum;
            for(int i = 0; i < n; i++) a[i] = p[i];
        }
    } while(next_permutation(p, p + n));

    cout << maximum << endl;
    */
    
    cout << n * (n - 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
def gcd(a, b)
  while b > 0
    a,b = b,a % b
  end
  a
end

n, x_large = gets.chop.split.map(&:to_i)
x = gets.chop.split.map(&:to_i)

x << x_large

x.sort!
x = x.map{ |num| num-x[0]}


ans = gcd(x[0],x[1])

unless n == 1
  for i in 2..n
    ans = gcd(ans, x[i])
  end
else
  ans = x[1]
end

print ans


Measured memory_bytes: 10624
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	char a;
	cin >> a;
	char ans = a + 1;
	cout << ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

ll N;

int dfs(string s) {
    if (stoll(s) > N) return 0;

    vector<bool> check(3, false);
    for (char c : s) {
        if (c == '3') check[0] = true;
        if (c == '5') check[1] = true;
        if (c == '7') check[2] = true;
    }
    
    int sum = 0;
    if (check[0] and check[1] and check[2]) sum = 1;

    for (char c : {'7', '5', '3'}) {
        sum += dfs(s+c);
    }

    return sum;
}

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

    cin >> N;
    
    cout << dfs("0") << endl;
    return 0;
}


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

using int64 = int64_t;

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

  int64 sum = 0;
  for (int64 k = 1; k * (k + 1) < n; ++k) {
    if ((n - k) % k == 0) {
      int64 m = (n - k) / k;
      sum += m;
    }
  }

  cout << sum << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
	char A1[15],B1[15],C1[15];
	int bola1,bola2;
	scanf("%s %s",A1,B1);
	scanf("%d %d",&bola1,&bola2);
	scanf("%s",C1);
	
	(strcmp(C1,A1)==0) ? bola1-- : bola2--;
	printf("%d %d\n",bola1,bola2);
	
	return 0;
	
}
	

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ld a,b,h,m;cin>>a>>b>>h>>m;
    ld ha = (h+m/60)/12*2*M_PI;
    ld hm = m/60*2*M_PI;
    cout<<setprecision(12)<<sqrt(a*a+b*b-2*a*b*cos(ha-hm));
    return 0;
}

Measured memory_bytes: 4168
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   lli n;
   cin>>n;
   if(n%2==1)
   cout<<(n/2)+1<<"\n";
   else
   cout<<n/2<<"\n";
}

Measured memory_bytes: 3612
n = int(input())
hxy = []

for i in range(n):
    x, y, h = map(int, input().split())
    hxy.append((h, x, y))

hxy.sort(reverse=True)
    
for i in range(101):
    for j in range(101):
        h, x, y = hxy[0]
        H = h + abs(x - i) + abs(y - j)
        if all(h == max(H - abs(x - i) - abs(y - j), 0) for h, x, y in hxy):
            print(i, j, H)

Measured memory_bytes: 3064
n, h = gets.chomp.split.map(&:to_i)
d = []
am = 0

n.times do
  ai, bi = gets.chomp.split.map(&:to_i)
  am = [am, ai].max
  d << [ai, bi]
end

d.sort_by! {|_, b| b }

i = n - 1
while i >= 0 && h > 0 && am < d[i][1]
  h -= d[i][1]
  i -= 1
end

res = n - 1 - i
if h > 0
  res += (h + am - 1) / am
end
puts res

Measured memory_bytes: 24080
#include <bits/stdc++.h>
using namespace std;
int main(){
  char b;
  cin >> b;
  if(b == 'A')cout << "T" << endl;
  else if(b == 'T')cout << "A" << endl;
  else if(b == 'G')cout << "C" << endl;
  else if(b == 'C')cout << "G" << endl;
}

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

prime = [0] * (N + 1)
for i in range(1, N + 1) :
    while i % 2 == 0 :
        i //= 2
        prime[2] += 1
    j = 3
    while i != 1 :
        while i % j == 0 :
            i //= j
            prime[j] += 1
        j += 2

# 3 5 15 25 75
over = [0] * 5

for i in range(1, N + 1) :
    if 74 <= prime[i] :
        over[4] += 1
    elif 24 <= prime[i] :
        over[3] += 1
    elif 14 <= prime[i] :
        over[2] += 1
    elif 4 <= prime[i] :
        over[1] += 1
    elif 2 <= prime[i] :
        over[0] += 1
        
s = [sum(over[i:]) for i in range(5)]

ret = 0
# 3*5*5
ret += over[0] * s[1] * (s[1] - 1) // 2
ret += s[1] * (s[1] - 1) * (s[1] - 2) // 2
# 3*25
ret += (over[0] + over[1] + over[2]) * s[3]
ret += s[3] * (s[3] - 1)
# 5*15
ret += over[1] * s[2]
ret += s[2] * (s[2] - 1)
# 75
ret += over[4]
print(ret)

Measured memory_bytes: 38256
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    char s;
    cin >> s;
    if(s-'a' >= 0 && s - 'a' < 26){
        cout << 'a' << endl;
    }
    else{
        cout << 'A' << endl;
    }
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
#D - 756
import sys 
import math
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())

def prime_factorize(n,cnt):
    for i in range(2,int(math.sqrt(n))+1):
        if n % i == 0:
            while n % i ==0:
                n //= i
                cnt[i] +=1
    if n != 1:
        cnt[n] +=1
    return 

cnt = defaultdict(int)
for i in range(2,N+1):
    prime_factorize(i,cnt)
# n以上の個数を返す
def num(n):
    c = 0
    for v in cnt.values():
        if v < n:
            break
        c += 1
    return c 

print(num(74) + num(24)*(num(2)-1) + num(14)*(num(4)-1) + num(4)*(num(4)-1)*(num(2)-2)//2)           

Measured memory_bytes: 65312
#include<bits/stdc++.h>
using namespace std;
char a[111111];
bool ok(char a,char b)
{
	if(a=='q'&&b=='p') return 1;
	if(a=='p'&&b=='q') return 1;
	if(a=='b'&&b=='d') return 1;
	if(a=='d'&&b=='b') return 1;
	return 0;
}
stack <char> s;
int main()
{
	cin>>a;
	for(int i=0;i<(strlen(a)+1)/2;i++) s.push(a[i]);
	for(int i=(strlen(a)+1)/2;i<strlen(a);i++){
		if(!ok(s.top(),a[i])){
			cout<<"No"<<endl;return 0;
		}
		
		s.pop();
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    map<pair<int, int>, bool> mp;

    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;

        mp[{a, b}] = true;
    }

    for(int i = 2; i < n; i++){
        if(mp[{1, i}] && mp[{i, n}])
            return cout << "POSSIBLE\n", 0;
    }

    cout << "IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 28556
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var e = Array.ConvertAll(line, int.Parse);
        Array.Sort(e);
        if (e[0] != e[1] | e[2] != e[3]) Console.WriteLine("no");
        else Console.WriteLine("yes");
    }
}

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  for(int i=1;;i++)
  {
    C-=B;
    A-=D;
    if(C<=0)
    {
       cout<<"Yes";
    	break;
    }
    else if(A<=0)
    {
        cout<<"No";
    	break;
    }
     
  }
  
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  int d;
  cin >> d;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(d, vector<int>(26));
  rep(i, d) rep(j, 26) cin >> s[i][j];

  vector<int> last(26, -1);
  rep(i, d) {
    int res = 0, idx = -1;
    rep(j, 26) {
      if (c[j] * (i - last[j]) > res) res = c[j] * (i - last[j]), idx = j;
      else if (c[j] * (i - last[j]) == res && c[j] > c[idx]) res = c[j] * (i - last[j]), idx = j;
    }
    last[idx] = i;
    cout << idx + 1 << '\n';
  }

  




  
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    bool flag=true;
	cin>>s;
    for(int i=0;i<s.size();i++){
    	if((i+1)%2==1){
    		if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
    			flag=false;
			}
		}
		else if((i+1)%2==0){
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
			    flag=false;   	
			}
		}
		if(flag==false){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;


vector<int> v, w;


vector<int> getvec(int p) {
    int lim = 100010;
    vector<int> vv, ww;
    for (int j = p; ; j = (j - 1) >> 1) {
        vv.push_back(v[j]);
        ww.push_back(w[j]);
        if (j == 0) break;
    }

    int m = vv.size();
    vector<int> lis(lim);
    for (int i = 0; i < (1 << m); ++i) {
        int vs = 0, ws = 0;
        for (int j = 0; j < m; ++j) {
            if ((i >> j) & 1) {
                vs += vv[j];
                ws += ww[j];
            }
        }
        if (ws < lim) {
            lis[ws] = max(lis[ws], vs);
        }
    }
    for (int i = 1; i < lim; ++i) {
        lis[i] = max(lis[i], lis[i - 1]);
    }
    return lis;
}

vector<P> getvec(int p, int par) {
    int lim = 100010;
    vector<int> vv, ww;
    for (int j = p; ; j = (j - 1) >> 1) {
        vv.push_back(v[j]);
        ww.push_back(w[j]);
        if (j == par) break;
    }

    int m = vv.size();
    vector<P> lis;
    for (int i = 0; i < (1 << m); ++i) {
        int vs = 0, ws = 0;
        for (int j = 0; j < m; ++j) {
            if ((i >> j) & 1) {
                vs += vv[j];
                ws += ww[j];
            }
        }
        if (ws < lim) {
            lis.push_back({ ws, vs });
        }
    }
    return lis;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    v = vector<int>(n);
    w = vector<int>(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i] >> w[i];
    }
    int q;
    cin >> q;
    vector<vector<P>> que(n, vector<P>());
    for (int i = 0; i < q; ++i) {
        int u, l;
        cin >> u >> l;
        --u;
        que[u].push_back({ l, i });
    }
    vector<vector<int>> memo(1 << 11);
    vector<int> ans(q);
    for (int i = 0; i < n; ++i) {
        if (i < (1 << 11)) {
            vector<int> lis = getvec(i);
            memo[i] = lis;
            for (auto& p : que[i]) {
                int l = p.first;
                ans[p.second] = lis[l];
            }
        }
        else {
            int pp = i;
            while (((pp - 1) >> 1) >= (1 << 11)) {
                pp = (pp - 1) >> 1;
            }
            const vector<int>& lis1 = memo[(pp - 1) >> 1];
            vector<P> lis2 = getvec(i, pp);

            for (auto& p : que[i]) {
                int l = p.first;
                int ma = 0;
                for (auto& j : lis2) {
                    if (j.first <= l) {
                        ma = max(ma, lis1[l - j.first] + j.second);
                    }
                }
                ans[p.second] = ma;
            }
        }
    }
    for (auto& i : ans) {
        cout << i << '\n';
    }


    return 0;
}


Measured memory_bytes: 815912
n = list(input())
n = list(map(int,n))
m = len(n)
if m == 1:
    print(n[0])
elif len(set(n)) == 1 and n[0] == 9:
    print(9 * m)
elif len(set(n)) == 2 and n[0] != 9 and n[1] == 9:
    print(n[0] + (m - 1) * 9)
else:
    print(n[0] - 1 + (m - 1) * 9)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll ans = (x / 500) * 1000;
    x -= (x / 500) * 500;
    ans += (x / 5) * 5;
    cout << ans << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define mem0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), a.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll K, N, maxx;
    maxx = 0;
    ll A[200001];
    cin >> K >> N;
    for(ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll diff[200001];
    mem0(diff);

    for(ll i = 0; i < N; i++) {
        if(i == 0) {
            diff[i] = A[i] + K - A[N - 1];
        } else {
            diff[i] = A[i] - A[i - 1];
        }
        maxx = max(maxx, diff[i]);
    }

    cout << K - maxx << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int i,j,minv=9999999;
	int suma=0,sumb=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<n;i++){
		suma=0;
		sumb=0;
		for(int j=0;j<i;j++)suma+=a[j];
		for(int j=i;j<n;j++)sumb+=a[j];
		minv=min(minv,abs(suma-sumb));
	}
	cout<<minv;
}


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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n + 1, 0);
    for(int i = 0; i < n + 1; ++i){
        cin >> a.at(i);
    }
    ll total = 0;
    for(int i = 0; i < n; ++i){
        ll b;
        cin >> b;
        ll x = min(a.at(i), b);
        total += x;
        b -= x;
        ll y = min(a.at(i + 1), b);
        total += y;
        a.at(i + 1) -= y;
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 1024
m,p,i,x,s,w;main(n){for(;scanf("%d%d%d",&n,&m,&p),n;printf("%d\n",w?(int)(s*((100-p)/100.0))/w:0))for(s=i=0;i++<n;s+=x*100)scanf("%d",&x),w=i-m?w:x;exit(0);}

Measured memory_bytes: 0
'use strict';
(function(input){
  input=input.trim().split(/\n/);
  const N=input.shift()-0;
  input=input.map(str=>str.split(/\s+/).map(x=>x-0));
  
  function Node(){
    var t=this;
    t.connected=[];
    t.group='none';
  }
  
  const nodes=new Array(N+1);
  
  for(let i=1;i<=N;i++){
    nodes[i]=new Node();
  }
  
  input.forEach(function(a){
    var odd=a[2]%2;
    nodes[a[0]].connected.push([a[1],odd]);
    nodes[a[1]].connected.push([a[0],odd]);
  });
  
  const stack=[1];
  
  nodes[1].group=0;
  
  while(stack.length>0){
    let i=stack[stack.length-1];
    let t=nodes[i];
    if(t.connected.length===0){
      stack.pop();
    }else{
      let c=t.connected[t.connected.length-1];
      let n=nodes[c[0]];
      if(n.group==='none'){
        n.group=(t.group+c[1])%2;
        stack.push(c[0]);
      }else{
        t.connected.pop();
      }
    }
  }
  
  const ans=[];
  for(let i=1;i<=N;i++){
    ans.push(nodes[i].group);
  }
  console.log(ans.join('\n'));
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 80128
#include <iostream>
using namespace std;
int main(void){
    int N = 0, H = 0, W = 0;
    int a = 0, b = 0;

    //入力
    cin >> N >> H >> W;
    
    //処理
    a = N - H + 1;
    b = N - W + 1;

    //出力
    cout << a*b << endl;

    return 0;
}


Measured memory_bytes: 256