akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

struct data
{
	int val;
	int no;
};

bool comp(data x, data y)
{
	if(x.val!= y.val)
		return x.val > y.val;
	if(x.no!= y.no)
		return x.no > y.no;
}

int n,m;
int a[N];
set<pair<int,int>> s;
data aa[N];

int32_t main()
{
	IOS;
	cin >> n >> m;
	int ans=0;
	rep(i,1,n)
	{
		cin >> a[i];
		s.insert({a[i],i});
	}
	rep(i,1,m)
	{
		int x;
		int y;
		cin >> x >> y;
		aa[i].no= x;
		aa[i].val = y; 
	}
	sort(aa+1,aa+m+1,comp);
	int i=1;
	while(s.size()>0 && i<=m)
	{
		int tot = aa[i].no;
		while(tot>0 && s.size()>0)
		{
			pair<int,int>  p=*s.begin();
			if(p.first<aa[i].val)
			{
				a[p.second] = aa[i].val;
			}
			tot--;
			s.erase(*s.begin());
		}
		i++;
	}
	rep(j,1,n)
	{
		ans += a[j];
	}
	cout << ans << endl;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int w[6]={2,3,5,10,12,15};
int v[6]={380,550,850,1520,1870,2244};
int dp[60];
const int INF=1e9;

signed main(){
	rep(i,0,60) dp[i]=INF;
	dp[0]=0;
	rep(i,0,6){
		for(int j=0;j+w[i]<=50;j++){
			dp[j+w[i]]=min(dp[j+w[i]],dp[j]+v[i]);
		}
	}
	//rep(i,0,60) o(dp[i]);
	int W;
	while(1){
		cin>>W;
		if(W==0) break;
		W/=100;
		o(dp[W]);
	}	
}

Measured memory_bytes: 1156
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Graph as G

bfs :: [G.Tree Int] -> [[Int]]
bfs [] = []
bfs ts = fmap root ts : bfs (concatMap sub ts)
  where
    root (G.Node r _)  = r
    sub  (G.Node _ sf) = sf

main :: IO ()
main = do
    [n, m] <- fmap read . words <$> getLine :: IO [Int]
    as <- replicateM m $ do
        [a, b] <- fmap read. words <$> getLine :: IO [Int]
        return (a, b)

    let g = G.buildG (1, n) as
    let tree = G.dfs g [1]
    let bss = bfs tree

    if length bss < 3
        then putStrLn "IMPOSSIBLE"
        else do
            if any (== n) (bss !! 2)
                then putStrLn "POSSIBLE"
                else putStrLn "IMPOSSIBLE"

Measured memory_bytes: 149372
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var c = cin.Read;
			if( c=="a"|| c == "e" || c == "i" || c == "o" || c == "u")
				WriteLine("vowel");
			else
				WriteLine("consonant");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define endl "\n"

typedef long long ll;
using namespace std;

//ll const N = 32000;

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

    int N, cnt = 0, minn = 200000;
    cin >> N;

    int arr[N];

    for(int i = 0; i < N; i++)
    {
        cin >> arr[i];
        if(arr[i] <= minn)
        {
            cnt++;
            minn = arr[i];
        }
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 4356
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;

int main(){

int k,a,b;
cin>>k>>a>>b;
for (int i = a; i <=b; i++)
{
    if(i%k==0){
        cout<<"OK"<<endl;return 0;
    }
}
cout<<"NG"<<endl;


    return 0;
}

Measured memory_bytes: 3624
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var arr=[];
   for(var i=0;i<n;i++){
      var v=Arr.shift()-0;
      arr.push(v);
   }
   arr.sort(function(a,b){return a-b;});
   var wait=[];
   var time=0;
   for(var i=0;i<n;i++){
      wait.push(time);
      time+=arr[i];
   }
   var sum=wait.reduce(function(a,b){return a+b;});
   console.log(sum);
}

Measured memory_bytes: 10608
M, N = map(int, input().split())
result = 0

def fact(num):
    result = 1
    while num > 1:
        result *= num
        num -= 1
    return result

if M!=0 or M!=1:
    result += fact(M) // (fact(2) * fact(M-2))

if N!=0 or N!=1:
    result += fact(N) // (fact(2) * fact(N-2))

print(result)

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<int> v_0(N),v_1(N);
  int sum_0 = 0,sum_1 = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == '#')sum_1++;
    v_1[i] = sum_1;
  }
  for(int i = N - 1; i>= 0;i--){
    if(S[i] == '.')sum_0++;
    v_0[i] = sum_0;
  }
  int ans;
  if(sum_0 < sum_1)ans = sum_0;
  else ans = sum_1;
  for(int i = 0; i < N - 1; i++){
    if(v_1[i] + v_0[i+1] < ans)ans = v_1[i]+v_0[i+1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 2180
#include<stdio.h>
#include<math.h>
#include <limits.h>
#include<stdlib.h>





int main() {
	int a, b, c,k;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &k);
	int count = 0;
	
	while (1) {
		count++;
		if (a >= b) {
			b *= 2;
		}
		else if (b >= c) {
			c *= 2;
		}
		else {
			count--;
			break;
		}
	}

	if (k >= count) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1640
a = input()
if a == 'ooo':
    print(1000)
elif a == 'oox' or a == 'oxo' or a == 'xoo':
    print(900)
elif a == 'oxx' or a == 'xxo' or a == 'xox':
    print(800)
else:
    print(700)

Measured memory_bytes: 2940
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        d: usize,
    }
    println!("{}", (n as f64 / (2 * d + 1) as f64).ceil());
}


Measured memory_bytes: 4352
#include<iostream>
#include<math.h>
#include<algorithm>

using namespace std;


const int MOD = 1e9 + 7;
const int mod = 1000000007;

int main(){

    int N, temp;
    bool c = true;
    int ans = 1;
    int line[100100];
    cin >>N;
    for(int i = 0; i < N; i++){
        cin >>line[i];
    }

    sort(line, line + N);
    if(N % 2 != 0){

        for(int i = 0; i < N; i++){
            if(line[i] != (i+1)/2*2){
                c = false;
            }
        }

    }
    if(N % 2 == 0){
        for(int i = 0; i < N; i++){
            if(line[i] != i/2*2+1){
                c  = false;
            }
        }

    }

    for(int i = 0; i < N / 2; i++){
        ans *= 2;
        ans = ans % mod;
    }
    if(c){
        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }


}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  int arr[n];
  for(int i=0;i<n;i++) cin>>arr[i];
  int ans[n]; ans[0]=0; ans[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++){
    ans[i]=min(ans[i-1]+abs(arr[i]-arr[i-1]),ans[i-2]+abs(arr[i]-arr[i-2]));
  }
  cout<<ans[n-1];
  return 0;
}

Measured memory_bytes: 1024
while True:
    try:
        S = input()
        result = 0
        prev = None
        cur = ""
        for c in S:
            if prev is None:
                prev = c
                result += 1
                continue
            cur += c
            if prev == cur:
                continue
            result += 1
            prev = cur
            cur = ""
        print(result)
    except EOFError:
        break

Measured memory_bytes: 3500
import java.util.Scanner;
import java.util.LinkedHashSet;
import java.util.Set;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] w = new String[n];
    for(int i=0;i<n;i++){
      w[i]=sc.next();
    }
     if(check1(w) && check2(w)){
       System.out.println("Yes");
     }else{
       System.out.println("No");
     }
  }    
  static boolean check1(String[] w){
      Set<String> linkedHashSet = new LinkedHashSet<String>();
      for (int i=0;i<w.length;i++) {
       linkedHashSet.add(w[i]);
      }
      Object[] w_after = linkedHashSet.toArray();
      if(w_after.length==w.length){
        return true;
      }else{
        return false;
      }
  }
  static boolean check2(String[] w){
    String e = w[0].substring(w[0].length()-1);
    for(int i=1;i<w.length;i++){
      String f = w[i].substring(0,1);
      if(f.equals(e)){
        e = w[i].substring(w[i].length()-1);
      }else{
        return false;
      }
    }
    return true;
  } 
}

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

int main() {
  int N;
  string S;
  cin>>N>>S;
  
  int sum=0;
  for(int i=0;i<N-2;i++){
    if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C') sum+=1;
  }
  
  cout<<sum<<endl;
  
 
}

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, ac = 0, wa = 0, tle = 0, re = 0; cin >> n;
    string s;
    while (n--)
    {
        cin >> s;
        if(s == "AC") ac++;
        else if(s == "WA") wa++;
        else if(s == "TLE") tle++;
        else re++;
    }
    cout << "AC x " << ac << "\nWA x " << wa << "\nTLE x " << tle << "\nRE x " << re << '\n';
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int n,a,hsh[100005],mx=-1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		++hsh[a];
	}
	for(int i=1;i<=99999;i++)
	{
		mx=max(mx,hsh[i]+hsh[i-1]+hsh[i+1]);
	}
	printf("%d\n",mx);
}

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

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

    string t = "MARCH";
    ll cnt[5] = {0};
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, t.size()) {
            if (s[0] == t[j])
                ++cnt[j];
        }
    }

    ll ans = 0;
    rep(i, 5) {
        rep(j, 5) {
            if (i == j)
                continue;
            vector<bool> flag(5);
            flag[i] = flag[j] = true;

            ll now = cnt[i] * cnt[j];
            rep(k, 5) {
                if (!flag[k])
                    ans += now * cnt[k];
            }
        }
    }

    cout << ans / 6 << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include "atcoder/dsu.hpp"
//#include "atcoder/convolution.hpp"
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
using namespace atcoder;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

int main(void){
    int N,Q;
    cin >> N >> Q;
    dsu d(N);
    rep(i,Q){
        int t,u,v;
        cin >> t >> u >> v;
        if(t==0) d.merge(u,v);
        else cout << d.same(u,v) << endl;
    }
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a[n+1]={0};
	for(int i=1;i<=n;i++) cin>>a[i];
	bool win[n+1][k+1] = {{0}};	//win[i][j] represents first player wins if true else second player
					//given first i elements and j stones remaining with first player's turn
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(j<a[1]&& j>=0){
				win[i][j] = false;
			}
			else{
				win[i][j]=true;
				for(int x=1;x<=i;x++){
					if(j>=a[x])
						win[i][j]&=win[i][j-a[x]];
					if(win[i][j]==false) break;
				}
				win[i][j] = !win[i][j];
			}
		}
	}
	if(win[n][k]) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 10112
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
ll prime[1000001];
bool cnt[1000001];
void sieve(int n){
	prime[1] = 1;
	vector<ll>p;
	for(int i=2;i<=n;i++){
		if(prime[i] == 0){
			prime[i] = i;
			p.pb(i);
		}
	     for(int j=0;j<(int)(p.size()) && p[j] <= prime[i] && i*p[j] <= n;j++){
		prime[i*p[j]] = p[j];
	}
}
}
int main()
{
	owo
	int n;
	cin>>n;
	vector<ll>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sieve(1e6+1);
	bool par = 1;
	ll g = a[0];
	for(int i=0;i<n;i++)g = gcd(g,a[i]);
	for(int i=0;i<n;i++){
		while(a[i] != 1){
			ll j = prime[a[i]];
			//cout<<a[i]<<" "<<j<<'\n';
			if(cnt[j]){par=0;break;}
			cnt[j] = 1;
			while(a[i]%j == 0)a[i]/=j;
		}
		if(!par)break;
	}
	if(par)cout<<"pairwise coprime";
	else if(g == 1)cout<<"setwise coprime";
	else cout<<"not coprime";
}


Measured memory_bytes: 19860
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n, k;
  cin >> n >> k;
  ll x[n];
  REP(i, n) cin >> x[i];

  ll sum = 0;

  REP(y, n){
    if(k - x[y] < x[y]) sum += 2 * (k - x[y]);
    else sum += 2 * x[y];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int func(int num){
    int cnt = 1;
    while(num / 10 != 0){
        cnt++;
        num /= 10;
    }
    return cnt;
}

int main(){
    int N, M;
    cin >> N >> M;
    int s[M], c[M];
    rep(i, M) cin >> s[i] >> c[i];
    int d[M];
    rep(i, M) d[i] = N - s[i] + 1;

    int ans = 1001;
    rep(i, 10){
        rep(j, 10){
            rep(k, 10){
                bool is = true;
                int num = i * 100 + j * 10 + k;
                int n[] = {k, j, i};
                if(func(num) != N) is = false;
                rep(itr, M){
                    if(n[d[itr]-1] != c[itr]) is = false;
                }
                if(is) ans = min(ans, num);
            }
        }
    }
    if(ans == 1001) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

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

typedef long long int ll;
int arr[500005];
int arr2[100005];
int arr3[100005];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,sum=0;
cin>>n;
for(int i=1;i<=n-1;i++)
    cin>>arr[i];

for(int i=1;i<n-1;i++)
{
    sum+=min(arr[i],arr[i+1]);
}
sum+=arr[n-1]+arr[1];
cout<<sum<<endl;
return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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; }

//INT_MAX	2,147,483,647 = 2*1.0e9


int cost[100010];

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

  rep(i, N+1) cost[i] = N;
  cost[0] = 0;

  for(int i = 0; i < N; i++){
    for(int j = 1; i + j < N+1; j*=6){
      chmin(cost[i + j], cost[i] + 1);
    }
    for(int k = 1; i + k < N+1; k*=9){
      chmin(cost[i + k], cost[i] + 1);
    }
  }

  cout << cost[N] << endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
const int MAX_N = 110000; 
constexpr double EPS = 1E-11;

using namespace std;

//fixed << setprecision(10)

int main() {
	int n, a, b; cin >> n >> a >> b;

	int mx = min(a, b);
	int mn = 0;

	if (a + b > n) {
		mn = a + b - n;
	}
	else if (a == b && a == n) {
		mn = 0;
	}

	cout << mx << ' ' << mn << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		scn.nextLine();
		char[] S = scn.nextLine().toCharArray();
		for(int i = 0;i < N;i++) {
			System.out.print(S[i]);
			System.out.print(S[N+1+i]);
		}
	}

}


Measured memory_bytes: 23124
#det = ae - bd
#x = (ce - bf) / det
#y = (af - cd) / det

#-0.000 対策
EPS = 1e-4

while True:
    try:
        a, b, c, d, e, f = map(float, input().split())
        det = a*e - b*d
        x = (c*e - b*f) / det + EPS
        y = (a*f - c*d) / det + EPS
        print('{0:.3f} {1:.3f}'.format(x, y))
    
    except EOFError:
        break



Measured memory_bytes: 5576
//転がす方向を決める処理と実際に転がす処理を分けると楽ちん。
#include<iostream>
using namespace std;

int n;
int t, f;

int dy[4] = {1,0,-1,0};
int dx[4] = {0,1,0,-1};
int tfrbl[7][4] = {{0},{3,5,4,2},{3,1,4,6},{6,5,1,2},{1,5,6,2},{3,6,4,1},{3,2,4,5}};	//側面右回り

//tfrblのどれを下にするか(f=0,r=1,b=2,l=3で指定)、そしたら転がす。
//仕様がこんがらがる。補正の補正の…うわぁぁぁ。
//vec = 盤面におけるサイコロの移動方向、zure = 今、前面がtfrbl[t][zure]となっている。
void goron(int vec, int zure, int &t, int &f) {
	int p = tfrbl[t][(vec+zure+2)%4];	//tの変化は、転がす方向とずれに影響(というより、下にする面の値に影響)
	int q;
	//fの変化は、転がす方向にのみ影響
	if ( vec == 0 )
		q = t;
	if ( vec == 1 || vec == 3 )
		q = f;
	if ( vec == 2 )
		q = 7-t;
		
	t = p;
	f = q;
}

int main() {
	while( cin >> n ) {
		if ( !n ) break;
		int high[300][300] = {0}, cy = 114, cx = 114;
		int num[300][300] = {0};
		while(n--) {
			cin >> t >> f;
			int py = cy, px = cx;
			while(high[py][px]) {
				int i, index = -1;
				int zure;
				//例：t = 1, f = 4ならzure = 2になる
				for( zure = 0; zure < 4; zure++ ) {
					if ( tfrbl[t][zure] == f )
						break;
				}
				
				//i, index : 盤面におけるサイコロの移動方向
				for( i = 0; i < 4; i++ ) {
					//転がる条件(下にする面の値は、tと転がす方向だけでなく向きにも影響される。)
					if ( high[py+dy[i]][px+dx[i]] < high[py][px] && tfrbl[t][(i+zure)%4] >= 4 )
						if ( index == -1 || tfrbl[t][(i+zure)%4] > tfrbl[t][(index+zure)%4] ) {
							index = i;
						}
				}
				//cout << index << endl;
				if ( index == -1 )
					break;
				//転がす( dy[i], dx[i] )進むために、tfrbl[(index+zure)%4]が下になるように転がす。
				//同じt,fにおいて、同じ面を下にして転がしても、実際に転がす方向によって、次のt,fが変わるので要注意。
				goron(index, zure, t, f);
				py += dy[index]; px += dx[index];
			}
			high[py][px]++;
			num[py][px] = t;
			//cout << py << " " << px << " " << t << " " << f << endl;
		}
		
		int count[7] = {0};
		for( int i = 0; i < 300; i++ ) {
			for( int j = 0; j < 300; j++ ) {
				count[num[i][j]]++;
			}
		}
		
		for( int i = 1; i < 6; i++ ) {
			cout << count[i] << " ";
		}
		cout << count[6] << endl;
	}
	return 0;
}

Measured memory_bytes: 1868
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define ABS(x) ((x) > 0 ? (x) : -(x))

int main()
{
	int n;
	int x[101], y[101];
	int i, j;
	double z=0.0;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
		scanf("%d", &x[i]);

	for (i = 0; i < n; i++)
		scanf("%d", &y[i]);


	for (i = 0; i < n; i++)
		z+= ABS(x[i] - y[i]);

	printf("%f\n", z);

	z = 0.0;

	for (i = 0; i < n; i++)
		z += pow(x[i] - y[i],2);

	printf("%f\n", sqrt(z));

	z = 0.0;

	for (i = 0; i < n; i++)
		z += pow(ABS(x[i] - y[i]), 3);

	printf("%f\n", pow(z, (double)1 / 3));

	double max = 0;

	for (i = 0; i < n; i++)
	{
		if (ABS(x[i] - y[i]) > max)
			max = ABS(x[i] - y[i]);
	}

	printf("%f\n", max);

	return 0;
}


Measured memory_bytes: 2116
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int K;
int A[100000];
int B[100000];
int C[100000];
int main(){
  int i;
  int cur;
  rd(N);
  rd(K);
  cur = K;
  for(i=(0);i<(N);i+=(2)){
    A[i] = cur++;
  }
  for(i=(1);i<(N);i+=(2)){
    A[i] = cur++;
  }
  for(i=(1);i<(N);i+=(2)){
    B[i] = cur++;
  }
  for(i=(0);i<(N);i+=(2)){
    B[i] = cur++;
  }
  for(i=(0);i<(N);i++){
    C[i] = cur++;
  }
  for(i=(0);i<(N);i++){
    if(A[i]+B[i] > C[i]){
      wt_L(-1);
      wt_L('\n');
      return 0;
    }
  }
  for(i=(0);i<(N);i++){
    wt_L(A[i]);
    wt_L(' ');
    wt_L(B[i]);
    wt_L(' ');
    wt_L(C[i]);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191108-1

// --- original code ---
// int N, K;
// int A[1d5], B[1d5], C[1d5];
// {
//   int cur;
//   rd(N,K);
//   cur = K;
//   rep(i,0,N,2) A[i] = cur++;
//   rep(i,1,N,2) A[i] = cur++;
//   rep(i,1,N,2) B[i] = cur++;
//   rep(i,0,N,2) B[i] = cur++;
//   rep(i,N) C[i] = cur++;
// 
//   rep(i,N) if(A[i]+B[i] > C[i]) wt(-1), return 0;
//   rep(i,N) wt(A[i],B[i],C[i]);
// }


Measured memory_bytes: 3456
#include<iostream>
#include<cstring>
using namespace std;
int main() {
	int K;
	char S[101] = "";
	char c;
	cin >> K;
	cin >> S;
	if (strlen(S) <= K ) {
		cout << S << endl;
	}
	else {
		S[K] = '\0';
		cout << S << "..." << endl;
	}
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main() {
  float x1, y1, x2, y2, x3, y3, xp, yp;
  while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    float a_x = x2 - x1, a_y = y2 - y1;
    float b_x = x3 - x1, b_y = y3 - y1;
    float c_x = xp - x1, c_y = yp - y1;
    float det = a_x * b_y - a_y * b_x;
    float s = (b_y * c_x - b_x * c_y) / det, t = (-a_y * c_x + a_x * c_y) / det;
    cout << ((0 <= s && s <= 1 && 0 <= t && t <= 1 && s + t <= 1) ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <map>
using namespace std;

int p[8];
int d[4] = {-1, 1, -4, 4};
map<string, int> m;

int dfs() {
    string s = "01234567";
    int count = 0;
    int pos;

    queue<string> q;
    q.push(s);
    m[s] = count;
    while(q.size()) {
        s = q.front(); q.pop();
        count = m[s];
        pos = s.find('0');

        for(int i = 0; i < 4; i++) {
            if(0 <= pos+d[i] && pos+d[i] < 8 &&
            !(pos == 3 && d[i] == 1) && !(pos == 4 && d[i] == -1)) {
                string s_next = s;
                swap(s_next[pos], s_next[pos+d[i]]);
                if(m.find(s_next) == m.end()) {
                    q.push(s_next);
                    m[s_next] = count+1;
                }
            }
        }
    }

    return 0;
}

int main() {
    dfs();

    while(cin >> p[0]) {
        for(int i = 1; i < 8; i++) {
            cin >> p[i];
        }
        stringstream ss;

        for(int i = 0; i < 8; i++) {
            ss << p[i];
        }
        string s = ss.str();

        cout << m[s] << endl;
    }

    return 0;
}

Measured memory_bytes: 3468
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000000
int main(){
  int n;
  cin>>n;
  int cnt=0,c=0,b=0,a=0;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    for(int j=0;j<s.size()-1;j++){
      if(s[j]=='A'&&s[j+1]=='B')cnt++;
    }
    if(s[0]=='B'&&s[s.size()-1]=='A')c++;
    else if(s[s.size()-1]=='A')a++;
    else if(s[0]=='B')b++;
  }
  //cout<<a<<' '<<b<<' '<<c<<' '<<cnt<<endl;
  int ans=0;
  if(a>0&&b>0){
    ans=cnt+c+1+min(a-1,b-1);
  }
  else if(a>0){
    ans=cnt+c;
  }
  else if(b>0){
    ans=cnt+c;
  }
  else if(a==0&&b==0&&c==0){
    ans=cnt;
  }
  else{
    ans=cnt+c-1;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
   int k;
   
   scanf("%d", &k);

   int x = 7 % k;

   for (int i = 1; i <= k; i++) {
      if (x == 0) {
         printf("%d\n", i);
         return 0;
      }

      x = (x * 10 + 7) % k;
   }

   printf("-1\n");
   return 0;
}


Measured memory_bytes: 1720
/*
    NO 
        TIME 
            TO 
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=998244353;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0);
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,k,m,d,b,c,q,x;
int vis[100005];
void dfs(int i,vector<vector<int>>& v)
{
    vis[i]=1;
    for(auto &j: v[i])
    {
        if(!vis[j])
            dfs(j,v);
    }
}

int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif
 
 int n,m;
 cin>>n>>m;
 vector<vector<int>> v(n+1);
 for(int i=1;i<=m;i++)
 {
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
 }
 int ans=0;
 for(int i=1;i<=n;i++)
 {
    if(!vis[i])
        dfs(i,v),ans++;
 }

 cout<<ans-1;
 
}



Measured memory_bytes: 9920
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
vector<pair<int, int> > conn[101010];
int ans[101010];
void dfs(int a, int pa, int c)
{
	ans[a] = c;
	for(auto x: conn[a])
		if(x.first != pa)
			dfs(x.first, a, c^x.second);
}
int main()
{
    int N;
	cin>>N;
	rep(i,N-1){
		int u, v, w;
		cin>>u>>v>>w;
		conn[u].emplace_back(v, w%2);
		conn[v].emplace_back(u, w%2);
	}
	dfs(1, 0, 0);
	rep(i,N)
		cout<<ans[i+1]<<endl;
}

Measured memory_bytes: 8448
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back
#define SZ(x) ll(x.size())

using namespace std;
const int maxn = 1000*100+5 ;

int main()
{
	migmig ;
	int a,  b ; 
	cin>>a>>b ; 
	if(a > 12 ) cout<<b ; 
	else if( a > 5) cout<<b/2; 
	else cout<< 0 ; 

}
//////
////////
///////////



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

struct camel{
    int k; // 条件を満たす位置
    int d; // 条件を満たした時にもらえる追加の報酬
};

int main()
{
    int t;
    cin >> t;
    for(int ti=0; ti<t; ++ti){
        int n;
        cin >> n;
        vector<camel> vc_l, vc_r;
        ll sum=0;
        for(int ci=0; ci<n; ++ci){
            int k, l, r;
            cin >> k >> l >> r;
            if(l>r){
                sum += r;
                vc_l.emplace_back(camel{k, l-r});
            }else if(l==r){
                // どこにおいても良い場合
                sum += r;
            }else{
                // l<r
                sum += l;
                vc_r.emplace_back(camel{k, r-l});
            }
        }
        // なるべく先頭近くに置きたいもの
        sort(vc_l.begin(), vc_l.end(), [](const camel &a, const camel &b){
            return a.k < b.k;
        });
        auto cmp = [](const camel &a, const camel &b){return a.d > b.d;};
        priority_queue<camel, vector<camel>, decltype(cmp)> pq(cmp);
        int ci=0;
        for(int j=1; j<=n; ++j){
            while(ci<vc_l.size() && vc_l[ci].k==j){
                pq.push(vc_l[ci]);
                ++ci;
            }
            while(pq.size()>j)pq.pop();
        }
        while(pq.size()>0){
            sum+=pq.top().d;
            pq.pop();
        }
        // なるべく末尾近くに置きたいもの
        sort(vc_r.begin(), vc_r.end(), [](const camel &a, const camel &b){
            return a.k > b.k;
        });
        ci=0;
        for(int j=n; j>=1; --j){
            while(ci<vc_r.size() && vc_r[ci].k==j){
                pq.push(vc_r[ci]);
                ++ci;
            }
            while(pq.size()>n-j)pq.pop();
        }
        while(pq.size()>0){
            sum+=pq.top().d;
            pq.pop();
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define INF_MAX INT_MAX
#define INF_MIN ((int)1<<31)-1
using namespace std;
class Segtree{
    vector<int> tree;
    int n=1,m,Inf;
    void Set(vector<int> vec){
        rep(i,n*2-2)tree[i+1]=Inf;
        rep(i,vec.size())tree[i+n]=vec.at(i);
        update(0,n-1);
    }
    int sum(int a,int b){
        if(m==0)return max(a,b);
        else if(m==1)return min(a,b);
        else if(m==2)return a+b;
        else return a*b;
    }
    int query(int a,int b,int x,int l,int r){
        if(r<a||b<l)return Inf;
        if(a<=l&&b>=r)return tree[x];
        return sum(query(a,b,x*2,l,(l+r)/2),query(a,b,x*2+1,(l+r)/2+1,r));
    }
    void update(int l,int r){
        l+=n,r+=n;
        l/=2,r/=2;
        while(1){
            if(l==0)break;
            int xl=l;
            for(;xl<=r;xl+=2){
                tree[xl]=sum(tree[xl*2],tree[xl*2+1]);
            }
            l/=2,r/=2;
        }
    }
public:
    void Max(vector<int> vec){
        m=0;
        Inf=INF_MAX;
        Set(vec);
    }
    void Min(vector<int> vec){
        m=1;
        Inf=INF_MIN;
        Set(vec);
    }
    void Add(vector<int> vec){
        m=2;
        Inf=0;
        Set(vec);
    }
    void Multiply(vector<int> vec){
        m=3;
        Inf=1;
        Set(vec);
    }
    Segtree(int in){
        for(;in>n;n*=2);
        tree.resize(n*2);
    }
    void Set(int a,int b){
        tree[a+n]+=b;
        update(a,a);
    }
    int query(int a,int b){
        return query(a,b,1,0,n-1);
    }
};
class Union_Find{
private:
    vector<int> t,s;
public:
    Union_Find(int max_length){
        rep(i,max_length+1){
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x,int y){
        if(same(x,y))return;
        int tx=Find(x),ty=Find(y);
        if(s[tx]<s[ty]){
            s[ty]+=s[tx];
            t[tx]=ty;
        }
        else if(s[tx]>s[ty]){
            s[tx]+=s[ty];
            t[ty]=tx;
        }
        else if(tx>ty){
            t[tx]=ty;
            s[ty]+=s[tx];
        }
        else{
            t[ty]=tx;
            s[tx]+=s[ty];
        }
    }
    int Find(int n){
        if(t[n]==n)return n;
        else return t[n]=Find(t[n]);
    }
    bool same(int x,int y){
        return Find(x)==Find(y);
    }
};
signed main(){
    int n,q;
    cin>>n>>q;
    Segtree seg(n);
    seg.Add({});
    rep(i,q){
        int a,b,c;
        cin>>a>>b>>c;
        if(a)cout<<seg.query(b-1,c-1)<<endl;
        else seg.Set(b-1,c);
    }
    return 0;
}


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

A = []
B = []

for i in range(N):
    c, d = map(int, input().split())
    A.append(c)
    B.append(d)
    
ans = 0

for i in range(N-1, -1, -1):
    if (A[i]+ans)%B[i] > 0:
        ans = ans + (B[i] - (A[i]+ans)%B[i])
    
print(ans)

Measured memory_bytes: 11052
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<sstream>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll MOD=1000000007;
int n,w;
int t;
int main()
{
	t=1;
	while(cin>>w,w)
	{
		int dp[1001][1001]={0};
		cin>>n;
		vector<P> num(n);
		for(int i=0;i<n;i++)
		{
		 	char tt;
		 	int x,y;
		 	cin>>x>>tt>>y;
		 	num[i].first=x;
		 	num[i].second=y;
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<=w;j++)
			{
				if(num[i].second-j<=0)dp[i+1][j]=max(dp[i][j],dp[i][j-num[i].second]+num[i].first);
				else dp[i+1][j]=dp[i][j];
			}
		}
		cout<<"Case "<<t<<":"<<endl;;
		t++;
		int mmax=0;
		int ans;
		for(int i=w;i>=0;i--)
		{
			if(mmax<=dp[n][i])
			{
				mmax=dp[n][i];
				ans=i;
			}
		}
		cout<<mmax<<endl;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 5124
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include <algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define forz(i,a,b) for(int i=(a);i<=(b);i++)
#define forf(i,a,b) for(int i=(a);i>=(b);i--)
#define mems(x,v) memset(x,v,sizeof(x))
using namespace std;
int n,i,j,m;
int dp[120][120];
char s[120][120];
int main()
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)scanf("%s",s[i]);
memset(dp,0,sizeof(dp));
if(s[1][0]=='#')dp[1][1]=1;
for(i=2;i<=m;i++)
{
    dp[1][i]=dp[1][i-1];
    if(s[1][i-1]=='#'&&s[1][i-2]!='#')dp[1][i]++;
}
for(i=2;i<=n;i++)
{
    dp[i][1]=dp[i-1][1];
    if(s[i][0]=='#'&&s[i-1][0]!='#')dp[i][1]++;
}
for(i=2;i<=n;i++)
    for(j=2;j<=m;j++)
{
    if(s[i][j-1]=='#')dp[i][j]=min(dp[i][j-1]+(s[i][j-2]!='#'),dp[i-1][j]+(s[i-1][j-1]!='#'));
    else dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
}
printf("%d",dp[n][m]);
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mx = 1e5+7;

int ara[mx],prime[mx],cnt[mx];

void sieve()
{
    for(int i = 2; i <= mx; i++)
    {
        if(ara[i]==0){
            prime[i] = 1;
            for(int j = 2*i; j < mx; j += i) ara[j] = 1;
        }
    }
    for(int i = 2; i < mx; i++){
        if(prime[i] and prime[(i+1)/2]) cnt[i] = 1;
        cnt[i] += cnt[i-1];
    }
}

int main()
{
    sieve();
    int t;
    cin >> t;
    while(t--)
    {
        int a,b;
        cin >> a >> b;
        cout << cnt[b] - cnt[a-1] << endl;
    }
}


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

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  if(a>=b){
    cout << "delicious" << endl;
    return 0;
  } else if (a+x>=b){
    cout << "safe" << endl;
    return 0;
  }
  cout << "dangerous" << endl;
}


Measured memory_bytes: 256
import itertools

def find_missing(l):
    """
    l: a list of cards
    returns a list of missing cards in order of suit(spades, harts, clubs, diamonds) and rank
    """
    suits = ['S', 'H', 'C', 'D']
    ranks = [i for i in range(1, 14)]
    cards = list(itertools.product(suits, ranks))

    for suit in suits:
        for i in range(1, 14):
            if (suit, i) in l:
                cards.remove((suit, i))

    return cards

if __name__ == '__main__':

    num = int(input())
    cards = []

    for i in range(num):
        line = input().split(' ')
        cards.append((line[0], int(line[1])))

    missing = find_missing(cards)
    for (s, i) in missing:
        print("{0} {1}".format(s, i))

Measured memory_bytes: 7780
#include <iostream>
#include <cctype>
#include <cstring>

using namespace std;

int main() {
	char s[201], s_copy[101], p[101];

	cin >> s >> p;

	strcpy(s_copy, s);

	strcat(s, s_copy);

	if (strstr(s, p) == NULL) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N,M,Q;cin>>N>>M>>Q;
    int Table[N+1][N+1];
    REP(i,N+1)REP(j,N+1)Table[i][j]=0;
    REP(i,M){
        int l,r;cin>>l>>r;
        Table[l][r]++;
    }
    int sumT[N+1][N+1];
  	REP(i,N+1)REP(j,N+1)sumT[i][j]=0;
    REPS(i,N){
        REPS(j,N){
            if(j==1)sumT[i][1]=Table[i][1];
            else sumT[i][j]=sumT[i][j-1]+Table[i][j];
        }
    }
    REP(i,Q){
        int l,r;cin>>l>>r;
        int ans=0;
        for(int z=l;z<=r;z++){
            ans+=sumT[z][r]-sumT[z][l-1];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4864
package main

import "fmt"
    
func main() {
    var a,b int
    fmt.Scan(&a)
    fmt.Scan(&b)
    
    if a > b {
        fmt.Println("a > b")
    }else if a == b {
        fmt.Println("a == b")
    }else {
        fmt.Println("a < b")
    }
    
    
}


Measured memory_bytes: 1108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Program
{

    static void Main()
    {
        var sc = new Scanner();
        int h = sc.Int();
        int w = sc.Int();
        string[] px =new string[h];
        for (int i = 0; i < h; i++)
			{
                px[i] = Console.ReadLine();
                        
        }
        for (int i = 0; i <h ; i++)
        {
            Console.WriteLine(px[i]);
            Console.WriteLine(px[i]);
        }
    }
}
static class Extentions
{
    public static IEnumerable<T> Outpuut<T>(this IEnumerable<T> source)
    {
        foreach (var item in source)
        {
            Console.WriteLine(item);
        }
        return source;
    }
    public static T Print<T>(this T obj)
    {
        Console.WriteLine(obj);
        return obj;
    }
}
public class Scanner
{
    public Scanner()
    {
        byte[] inputBuffer = new byte[1024];
        System.IO.Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);
        Console.SetIn(new System.IO.StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
    }
    string[] buffer = new string[0];
    int index = 0;
    public char[] SplitChars { get; set; }
    public string String()
    {
        if (index < buffer.Length) return buffer[index++];
        string line = "";
        while (line == "") line = Console.ReadLine();
        if (line == null) return null;
        buffer = line.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries);
        index = 0;
        return buffer[index++];
    }
    public string[] StringArray(int count) { return NextArray(count, x => x); }
    public void Skip(int count) { for (int i = 0; i < count; i++) String(); }
    public T Next<T>(Func<string, T> parser) { return parser(String()); }
    public T[] NextArray<T>(int count, Func<string, T> parser)
    {
        var arr = new T[count];
        for (int i = 0; i < count; i++) arr[i] = Next(parser);
        return arr;
    }
    public int Int() { return Next(int.Parse); }
    public int[] IntArray(int count) { return NextArray(count, int.Parse); }
    public double Double() { return Next(double.Parse); }
    public double[] DoubleArray(int count) { return NextArray(count, double.Parse); }
}


Measured memory_bytes: 2776
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

int N, M;
vector<int> A;
vector<pair<int, int> > BC;

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

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

    int tmpb, tmpc;
    for(int i = 0; i < M; i++){
        cin >> tmpb >> tmpc;
        BC.push_back(make_pair(tmpc, tmpb));
    }

    stable_sort(A.begin(), A.end()); // マージソート
    stable_sort(BC.begin(), BC.end()); // マージソート

    int indA = 0; // A インデックス指定用
    int indBC = M - 1; // BC インデックス指定用
    long ans = 0; // 解答用
    int num = 0; // 各 BC 階層でのカウント用
    bool fin = true; // 交換リストが残っているか

    while(indA < N){
        if(!fin) ans += (long) A[indA];
        else if(indBC >= 0 && A[indA] < BC[indBC].first){
            ans += (long) BC[indBC].first;
            num++;
        }
        else ans += (long) A[indA];

        indA++;

        if(fin){
            if(BC[indBC].second == num){
            indBC--;
            num = 0;
            }
            if(indBC == -1) fin = false;
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 2420
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    ans =0
    W,H,x,y = ints_raw()
    ans =W*H/2
    
    w2 = W/2
    h2 = H/2
    is_one = 1
    if w2 ==x and h2 ==y:
        is_one =1
    #elif w2==x or h2==y:
    else:
        is_one =0
    print(ans,is_one)
main()


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int x,y;
  cin>>x>>y;
  x+=y/2;
  cout<<x<<"\n";
  return 0;
}

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

int main(){
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> fridge(a), range(b);
    vector<vector<int>> coupon(m, vector<int>(3));
    for(int i = 0; i < a; i++){
        cin >> fridge[i];
    }
    for(int i = 0; i < b; i++){
        cin >> range[i];
    }
    for(int i = 0; i < m; i++){
        cin >> coupon[i][0] >> coupon[i][1] >> coupon[i][2];
    }

    int fridgeMin = *min_element(fridge.begin(), fridge.end());
    int rangeMin = *min_element(range.begin(), range.end());
    int costMinWithoutCoupon = fridgeMin + rangeMin;

    //calculate cost with using coupon
    int costMinWithCoupon = 1000000;
    for(int i = 0; i < m; i++){
        int costOfFridge = fridge[coupon[i][0] - 1];
        int costOfRange = range[coupon[i][1] - 1];
        int costWithCoupon = costOfFridge + costOfRange - coupon[i][2];
        costMinWithCoupon = min(costMinWithCoupon, costWithCoupon);
    }
    
    int ans = min(costMinWithCoupon, costMinWithoutCoupon);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528