akhauriyash/Code-Regression huggingface dataset:
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
    int n;
    long long total=0;
    cin >> n;
    vector<int> a(n+1), b(n);
    for (int i=0; i<=n; i++) cin >> a[i];
    for (int i=0; i<n; i++) cin >> b[i];
    for (int i=0; i<n; i++) {
        if (a[i] <= b[i]) {
            total += a[i];
            b[i] -= a[i];
            a[i] = 0;
            if (a[i+1] <= b[i]) {
                total += a[i+1];
                b[i] -= a[i+1];
                a[i+1] = 0;
            } else {
                total += b[i];
                a[i+1] -= b[i];
                b[i] = 0;
            }
        } else {
            total += b[i];
            a[i] -= b[i];
            b[i] = 0;
        }
    }
    cout << total;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
int main(){
    
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //#endif

    i64 n,k;
    cin>>n>>k;
    i64 a[n]={0};
    i64 dp[n]={0};
    forn(i,n) cin>>a[i],dp[i]=INT_MAX;
    dp[0]=0;
    for(i64 i=0;i<n;i++){

        for(int j=i+1;j<=i+k;j++){

            if(j<n){


            // if(dp[j]!=0&&(abs(a[i]-a[j])+dp[i])<dp[j])
            // dp[j]=(abs(a[i]-a[j])+dp[i]);


            // else if(dp[j]==0)
            // dp[j]=(abs(a[i]-a[j])+dp[i]);

              dp[j]=min(dp[j],abs(a[i]-a[j])+dp[i]);  

        }
    }
    }

        // for(auto i:dp)
        //     cout<<i<<" ";
    cout<<dp[n-1];


}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
  int a, b, c;
  cin >> a; cin >> b; cin >> c;
  if (a >= b) { cout << "No" << endl; }
  else if (b >= c) { cout << "No" << endl; }
  else { cout << "Yes" << endl; }
  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		long long int n,k,z,i=0,q=0,count=0,c=0,d=0,sum=0;
      	cin >> n ;
      	vector<long long int> vect;
      	long long int arr[100010];
      	memset(arr,0,sizeof(arr));
      	for(i=0;i<n;i++){
        	cin >> z;
          vect.push_back(z);
          arr[z]++;
          sum += z;
        }
      	cin >> q;
      while(q--){
      	cin >> c >> d;
        if(arr[c]==0){cout << sum << endl;continue;}
        else{
          	//k = arr[c];
          	arr[d] += arr[c];
          	sum += (d - c)*arr[c];
          	arr[c]=0;
          	cout << sum << endl;
        }
      }
	}
}

Measured memory_bytes: 5092
#dp[j] ->最低でもj以上のダメージを与えるのに必要な魔力の最小値
#

H,N = map(int,input().split())
dp = [float("INF")]*(H+1)
dp[0] = 0
for i in range(N):
    A,B = map(int,input().split())
    for j in range(1,H+1):
        dp[j] = min(dp[j],dp[max(j-A,0)]+B)

print(dp[-1])


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

#define mp make_pair
#define fst first
#define snd second

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_N = 100000;
int n;
ll m;
ll a[MAX_N];
ll psum[MAX_N+1];
map<ll,int> cnt;

int main()
{
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  psum[0] = 0;
  cnt[psum[0]%m]++;
  for (int i = 0; i < n; ++i) {
    psum[i+1] = psum[i] + a[i];
    cnt[psum[i+1]%m]++;
  }

  ll res = 0;
  for (auto p : cnt) {
    res += 1LL * p.snd * (p.snd-1) / 2;
  }

  cout << res << endl;

  return 0;
}


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

#define fi first
#define se second

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

    int n,m;cin>>n>>m;

    vector<pair<int,int>> p(m);
    for(int i=0;i<m;i++)
    {
        int ip,iy;cin>>ip>>iy;
        p[i]=make_pair(ip,iy);
    }

    vector<vector<pair<int,int>*>> v(n);
    for(int i=0;i<m;i++)v[p[i].fi-1].push_back(&p[i]);

    for(int i=0;i<n;i++)
    {
        if(v[i].size()==0)continue;
        sort(v[i].begin(),v[i].end(),[](pair<int,int>* l, pair<int,int>* r){return l->se<r->se;});
        for(int j=0;j<v[i].size();j++)v[i][j]->se=j+1;
    }

    for(int i=0;i<m;i++) printf("%06d%06d\n",p[i].fi,p[i].se);

    return 0;
}


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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;

void init() {

}

void solve() {
	char c[N];
	char t[N];
	scanf("%s %s", c, t);
	int c_size = strlen(c);
	int t_size = strlen(t);
	ll ans = 0;
	vector<int> v[30];
	for (int i = 0; i < c_size; i++) {
		char k = c[i];
		v[k - 'a'].push_back(i);
	}
	int curr_pos = -1;
	for (int i = 0; i < t_size; i++) {
		char k = t[i];
		vector<int> &vv = v[k - 'a'];
		if (vv.size() == 0) {
			printf("-1\n");
			return;
		}
		int pos;
		auto it = upper_bound(vv.begin(), vv.end(), curr_pos);
		if (it == vv.end()) pos = vv[0];
		else pos = *it;
		if (pos > curr_pos) {
			ans += pos - curr_pos;
			curr_pos = pos;
		}
		else {
			ans += c_size - curr_pos + pos;
			curr_pos = pos;
		}
	}
	printf("%lld", ans);
}

int main() {
	int test_cases_number = 1;
	//    scanf("%d", &test_cases_number);
	//    ios_base::sync_with_stdio(0);
	//    cin.tie(0); cout.tie(0);
	//    cin >> test_cases_number;
	for (int i = 0; i < test_cases_number; i++)
		solve();
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <ctype.h>
int main(void){
	char ch;
	while(1){
		scanf("%c",&ch);
		if(ch=='\n'){
			break;
		}else if(isalpha(ch)==0){
			printf("%c",ch);
		}else if(islower(ch)==0){
			ch = tolower(ch);
			printf("%c",ch);
		}else{
			ch = toupper(ch);
			printf("%c",ch);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define tc(t)  int t; cin>>t; while(t--) 
#define f(n)    for(int i=0;i<n;i++)
#define unordered_map   u_m
#define endl   "\n" 


void i_o_f()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
       freopen("give_input.txt", "r", stdin);
    freopen("give_output.txt", "w", stdout);
#endif
}







int32_t main()
{
	//i_o_f();
  
   int arr[3];
   for(int i=0;i<=2;i++) cin>>arr[i];
   	int count5=0;
   	 int count7=0;
   	for(int i=0;i<3;i++)
   	{

   		if(arr[i]==5)count5++;
   		if(arr[i]==7)count7++;

   	}

   	if(count5==2&&count7==1) cout<<"YES"<<endl;
   	else cout<<"NO"<<endl;
       
 







}

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

namespace abc151
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc151C();
        }
        public static void solve_abc151C()
        {
            int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nm[0];
            int m = nm[1];
            Dictionary<long, long> ac = new Dictionary<long, long>();
            Dictionary<long, long> wa = new Dictionary<long, long>();
            long cntAc = 0;
            long cntWa = 0;
            for (int i = 0; i < m; i++)
            {
                string[] ps = Console.ReadLine().Split();
                int p = Convert.ToInt32(ps[0]);
                if (ps[1] == "AC")
                {
                    if (!ac.ContainsKey(p))
                    {
                        ac.Add(p, 1);
                        cntAc++;
                    }
                }
                else
                {
                    if (!ac.ContainsKey(p))
                    {
                        if (wa.ContainsKey(p))
                        {
                            wa[p]++;
                        }
                        else
                        {
                            wa.Add(p, 1);
                        }
                    }
                }
            }

            foreach(var item in ac)
            {
                if (wa.ContainsKey(item.Key))
                {
                    cntWa += wa[item.Key];
                }
            }
            Console.WriteLine("{0} {1}", cntAc, cntWa);
        }
        
        public static void solve_abc151B()
        {
            int[] nkm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nkm[0];
            int k = nkm[1];
            int m = nkm[2];
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int sum = 0;
            for (int i = 0; i < n - 1; i++)
            {
                sum += a[i];
            }

            int res = -1;
            for (int i = 0; i <= k; i++)
            {
                if ((sum + i) / n >= m)
                {
                    res = i;
                    break;
                }
            }

            Console.WriteLine(res);
        }

        public static void solve_abc151A()
        {
            Console.WriteLine(Convert.ToChar(Convert.ToChar(Console.ReadLine()) + 1));
        }
    }
}


Measured memory_bytes: 21072
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{
    std::priority_queue<lint> heap;

    lint n, m;

    scanf("%lld", &n);
    scanf("%lld", &m);

    for (lint i = 0; i < n; ++i)
    {
        lint tmp;
        scanf("%lld", &tmp);

        heap.push(tmp);
    }

    for (lint i = 0; i < m; ++i)
    {
        lint cur = heap.top();
        heap.pop();
        heap.push(cur / 2);
    }

    lint ans = 0;

    while (!heap.empty())
    {
        ans += heap.top();
        heap.pop();
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 1400
import collections

N, K = map(int, input().split())
A = list(map(int, input().split()))

number = len(set(A))

c = collections.Counter(A)
values,counts=zip(*c.most_common())
count = 0
for i in range(number):
    if number <= K:
        print(count)
        break
    count += counts[-(i+1)]
    number -= 1

Measured memory_bytes: 59568
#include<iostream>
using namespace std;
int main()
{
	int n,r;
	cin>>n>>r;
	int count[51];
	for(int i=0;i<50;i++)
	{
		count[i]=0;
	}
	int c1,c2;
	while(r--)
	{
		cin>>c1>>c2;
		count[c1]++;
		count[c2]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<count[i]<<endl;
	} 
	return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

		// 入力値の取得
		int X = sc.nextInt();
		int N = sc.nextInt();
		
		if (N == 0) {
			System.out.println(X);
			sc.close();
			return;
		}
		
		Set<Integer> p = new HashSet<>();
		for (int i = 0; i < N; i++) {
			p.add(sc.nextInt());
		}
		
		// 結果の出力
		for (int i = 0; i <= 100; i++) {
			if (!p.contains(X - i)) {
				System.out.println(X - i);
				break;
			}
			else if (!p.contains(X + i)) {
				System.out.println(X + i);
				break;
			}
		}

		sc.close();
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#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 (ll i = m; i < n; i++)

int rec(int i, int j, int k){
    if(i==0){
        if(k==0)return 1;
        else return 0;
    }
    int res = 0;
    for (int x = j+1;x<=min(9,k);x++){
        res += rec(i-1,x,k-x);
    }
    return res;
}

int main() {
    while(1){
        int n,s;
        cin >> n >> s;
        if(n==0 && s==0)break;
        cout << rec(n,-1,s) << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    string s;
    cin >> s;
    set<string> st;
    string t = "AKIHABARA";
    rep(i, 1<<9) {
        string x;
        rep(j, 9) {
            if ( (i>>j)&1 ) {
                x += t[j];
            }
            else if ( t[j] != 'A' ) {
                x = "x";
            }
        }
        st.insert(x);
    }
    printf(st.count(s)?"YES":"NO");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
const int MN=1e5+5,inf=0x7fffffff;
int N;
bool c[MN];
struct edge{int to,nex;}e[MN<<1];
int en,hr[MN];
void ins(int x,int y)
{
	e[++en]=(edge){y,hr[x]};hr[x]=en;
	e[++en]=(edge){x,hr[y]};hr[y]=en;
}
int sw[MN],fa[MN],rt,sW;
void dfs1(int x,int f=0)
{
	reg int i;sw[x]=c[x];fa[x]=f;
	for(i=hr[x];i;i=e[i].nex)if(e[i].to^f)dfs1(e[i].to,x),sw[x]+=sw[e[i].to];
	if(sw[x]==sW&&!rt)rt=x;
}
int ans,son[MN],deg[MN];
void dfs2(int x)
{
	if(!sw[x])return;++son[fa[x]];if(x!=rt)ans+=2;
	for(int i=hr[x];i;i=e[i].nex)if(e[i].to^fa[x])dfs2(e[i].to);
	ans+=(deg[x]=son[x]+c[x]+(x!=rt))&1;deg[x]=deg[x]&1?1:-1;
}
int dp[MN][2];
#define fi first
#define se second
void dfs3(int x)
{
	reg int i;
	if(!sw[x])return;pair<int,int> p;p.fi=p.se=0;
	for(i=hr[x];i;i=e[i].nex)if(e[i].to!=fa[x]&&sw[e[i].to])
	{
		dfs3(e[i].to);
		dp[x][0]=max(dp[x][0],dp[e[i].to][0]);
		dp[x][1]=max(dp[x][1],deg[x]+1+dp[e[i].to][1]);
	}
	if(son[x]>=2)
	{
		for(i=hr[x];i;i=e[i].nex)if(e[i].to!=fa[x]&&sw[e[i].to])
		{
			int v=dp[e[i].to][1];
			if(v>p.fi)p.se=p.fi,p.fi=v;
			else if(v>p.se)p.se=v;
		}
		dp[x][0]=max(dp[x][0],deg[x]+1+p.fi+p.se);
	}
	dp[x][0]=max(dp[x][0],dp[x][1]);
}
char s[MN];
int main()
{
	N=read();reg int i,x;
	for(i=1;i<N;++i) x=read(),ins(x,read());
	scanf("%s",s+1);
	for(i=1;i<=N;++i) c[i]=s[i]=='W',sW+=c[i];
	dfs1(1);dfs2(rt);dfs3(rt);
	return 0*printf("%d\n",ans-dp[rt][0]);
}

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

x1,y1,x2,y2=map(int,input().split())
x3=y1-y2+x2
y3=-(x1-x2)+y2
x4=y2-y3+x3
y4=-(x2-x3)+y3
print(x3,y3,x4,y4)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    int n, A, B;
    cin >> n >> A >> B;
    string s;
    cin >> s;
    int cnt_a = 0, cnt_b = 0, sum = 0;
    rep(i, s.length()){
        string ans = "No";
        if(sum < A+B){
            if(s.at(i) == 'a'){
                ans = "Yes";
                cnt_a++;
                sum++;
            }
            else if(s.at(i) == 'b'){
                if(cnt_b < B){
                    ans = "Yes";
                    cnt_b++;
                    sum++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  stack<char>st;
  int ans = 0;
  for(int i = 0;i < s.size();i++){
    if(s[i] == 'S') st.push(s[i]);
    else{
      if(st.size() != 0){
        st.pop();
        ans++;
      }
    }
  }
  cout << s.size()-2*ans << endl;
}


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

int main() {
    int x, t;
    cin >> x >> t;
    if (x < t) cout << 0 << endl;
    else cout << x - t << endl;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  string str;
  cin >> str;
  if(str.size()<=n){
    cout << str;
  }else{
    cout<< str.substr(0,n)<<"...";
  }

  return 0;
}


Measured memory_bytes: 3620
use std::io;
fn main() {
    let mut l1 = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut l1).unwrap();
    let trimed = l1.trim_end();
    let mut itr = trimed.split_ascii_whitespace();
    let a = itr.next().unwrap().parse::<i128>().unwrap();
    let b = itr.next().unwrap().parse::<i128>().unwrap();
    let c = itr.next().unwrap().parse::<i128>().unwrap();
    let mut k = itr.next().unwrap().parse::<i128>().unwrap();
    let mut sum = 0_i128;
    if k <= a {
        sum = sum + k * 1;
        k = 0;
    } else {
        k = k - a;
        sum = sum + a * 1;
    }
    if k != 0 {
        if k <= b {
            k = 0;
        } else {
            k = k - b;
        }
    }
    if k != 0 {
        if k <= c {
            sum = sum - k;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(b%2==0&&a*2<=b&&a*4>=b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 200000 + 50;
const ll INF = (1ll<<60);
ll sum[maxn], a[maxn];
int  n;
int main(){
//freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	while(cin >> n){
		mem(sum,0);
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			sum[i] = sum[i-1] + a[i];
		}
		ll ans = INF;
		for(int i = 1; i < n; i++){
			ans = min(ans, abs(sum[i] - (sum[n] - sum[i])));
		}
		cout << ans << endl;
	}

    return 0;
}

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

namespace abc060_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            if (str[0].Substring(str[0].Length - 1) == str[1].Substring(0, 1) && str[1].Substring(str[1].Length - 1) == str[2].Substring(0, 1))
            {
                Console.WriteLine("YES");
            }

            else
            {
                Console.WriteLine("NO");
            }

            Console.Read();
        }
    }
}

Measured memory_bytes: 25796
from collections import defaultdict

import sys
input = sys.stdin.readline

def main():
    num = int(input())

    link = defaultdict(set)
    weight = defaultdict(int)
    for i in range(num - 1):
        a, b, c = map(int, input().split())
        link[a].add(b)
        link[b].add(a)
        weight[(min(a, b), max(a, b))] = c

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

    dist_data = [-1 for i in range(num + 1)]
    dist_data[k] = 0
    now_check = set()
    next_check = set()
    now_check.add(k)

    while len(now_check) > 0:
        for ele in now_check:
            now_dist = dist_data[ele]
            for now_ele in link[ele]:
                if dist_data[now_ele] != -1:
                    continue
                next_check.add(now_ele)
                dist_data[now_ele] = now_dist + weight[(min(now_ele, ele), max(now_ele, ele))]
        now_check = next_check
        next_check = set()

    for i in range(q_num):
        a, b = map(int, input().split())
        print(dist_data[a] + dist_data[b])



if __name__ == '__main__':
    main()



Measured memory_bytes: 104540
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;
#define inf 1000000007

int main(void){
    int n;
    cin >> n;
    int h[n+1];
    int ans = 0;
    for(int i = 0; i < n; i++)
        cin >> h[i];
    h[n]=0;
    int MIN = 0;
    for(int i = 1; i < n+1; i++){
        if(h[i]<h[i-1]){
            ans+=(h[i-1]-MIN);
            MIN = h[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>



using namespace std;


int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c >0)
    {
        c -= b;
        if (c <= 0)
        {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a <= 0)
        {
            cout << "No" << endl;
            break;
        }
    }
    
    return 0;
}

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

const int d = 365;
int main() {
  vector<int> c(26);
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  vector<vector<int>> s(d, vector<int>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }

  vector<int> t(26);
  for (int i = 0; i < 26; i++) {
    t[i] = i + 1;
  }

  for (int i = 0; i < d; i++) {
    cout << t[rand() % 26] << endl;
  }

  return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }

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

    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];
    int ans=0;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) ans+=a[i]*a[j];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

vector<int> a;
int n;

int main()
{
	cin >> n;

	for (int i = 0;i < 3*n;i++) {
		int t;
		cin >> t;
		a.push_back(t);
	}

	ll ans = 0;

	sort(a.begin(), a.end());

	int k = 3 * n - 1;
	for (int i = 0;i < n;i++) {
		k--;
		ans += (ll)a[k];
		k--;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2420
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{	
	auto N = RD;
	auto H = RDR.ARR;

	long ans;
	long big;
	foreach (i; 0..N)
	{
		if (H[i] >= big) ++ans;
		big = max(big, H[i]);
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
import sys

def f_buy(m, s, a):
  tmp = m//a
  return m-tmp*a, s+tmp

def f_sell(m, s, a):
  return m+s*a, 0

n = int(input())
la = list(map(int, input().split()))
lb = [0]*(n-1)
for i in range(n-1):
  if la[i+1]-la[i] > 0:
    lb[i] = 1
  if la[i+1]-la[i] < 0:
    lb[i] = -1

if lb.count(1) == 0:
  print(1000)
  sys.exit()

m = 1000
s = 0
frg = 0
for i in range(n-1):
  if lb[i] == 1:
    if frg != 1:
      m, s = f_buy(m, s, la[i])
    frg = 1
  if lb[i] == -1:
    if frg != -1:
      m, s = f_sell(m, s, la[i])
    frg = -1

m, s = f_sell(m, s, la[n-1])
print(m)

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    ll n,x,t;
    cin>>n>>x>>t;
    cout<<(n/x+((n%x)!=0))*t<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 3624
h, w = map(int, input().split())
field = [input() for _ in range(h)]

hor = [[0 for _ in range(w)] for _ in range(h)]
ver = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    count = 0
    for j in range(w):
        if field[i][j] == '#':
            for k in range(j-count, j):
                hor[i][k] = count
            count = 0
            hor[i][j] = 0
        else:
            count += 1
    for k in range(w-count, w):
        hor[i][k] = count

for j in range(w):
    count = 0
    for i in range(h):
        if field[i][j] == '#':
            for k in range(i-count, i):
                ver[k][j] = count
            count = 0
            ver[i][j] = 0
        else:
            count += 1
    for k in range(h-count, h):
        ver[k][j] = count

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, hor[i][j] + ver[i][j] - 1)
print(ans)

Measured memory_bytes: 126936
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long n = sc.nextLong();
		long[] a = new long[5];
		for (int i = 0; i < 5; i++) {
			a[i] = sc.nextLong();
		}

		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			min = Math.min(min, a[i]);
		}

		long g = (long) Math.ceil((double) n / min);
		out.println(5 + g - 1);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int ans=0;
  rep(i,0,n){
    int l,r;
    cin>>l>>r;
    ans+=r-l+1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
int main()
{
    int n,y;
    cin>>n>>y;
    vin ans={-1,-1,-1};
    rep(i,n+1){
        for(int j=0;i+j<=n;j++){
            if(10000*i+5000*j+1000*(n-i-j)==y){
                ans[0]=i;
                ans[1]=j;
                ans[2]=n-i-j;
                goto out;
            }
        }
    }
    out:
    cout<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
mod = 10**9+7
s = list(input())[:-1]

s = s[::-1]

ls = len(s)

mod_13_list = [ (10**i) % 13 for i in range(6) ]

dp_list = [ 0 for i in range(13) ]
if  s[0] != "?":
    p = int(s[0])
    dp_list[p] += 1
else:
    for i in range(10):
        dp_list[i] += 1

t = 1
for i in range(1,ls):
    r = mod_13_list[t]
    t = ( t + 1 ) % 6
    new_dp_list = [ 0 for i in range(13) ]
    if s[i] != "?":
        p = int(s[i])
        q = ( p * r ) % 13
        for j in range(13):
            new_dp_list[(j+q)%13] += dp_list[j]
    
    else:
        for k in range(10):
            q = (k * r ) % 13
            for j in range(13):
                new_dp_list[(j+q)%13] += dp_list[j]
    
    dp_list = [ i % mod for i in new_dp_list ]

print(dp_list[5])

Measured memory_bytes: 50672
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int dp[3001][3001] = {0};
string s, t;

void print_lcs(int tbl[][3001], int i, int j) {
    if (i == 0 || j == 0 )
        return;

    if (s[i-1] == t[j-1]) {
        print_lcs(tbl, i-1, j-1);
        cout << s[i-1];
    }
    else {
        if (tbl[i][j-1] > tbl[i-1][j]) {
            print_lcs(tbl, i, j-1);
        } else {
            print_lcs(tbl, i-1, j);
        }
    }
    return;
}

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

    for(int i=1; i<s.size() + 1; ++i){
        for(int j=1; j<t.size() + 1; ++j){
            if(s[i-1] == t[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    print_lcs(dp, s.size(), t.size());
    cout << endl;

    return 0;
}


Measured memory_bytes: 35840
import java.util.*;

public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    final long a = sc.nextLong();
    final long b = sc.nextLong();
    System.out.println(calc(a - 1) ^ calc(b));
    sc.close();
  }

  static long calc(final long n) {
    if (n % 2 != 0) {
        return  ((n + 1) / 2) % 2;
    }
    final long remain = (n / 2) % 2;
    return n + remain;
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
     
    using namespace std;
     
    #define all(x) x.begin(), x.end()
    typedef vector<int> vi;
    typedef pair<int,int> ii;
    typedef long long ll;
     
    const ll inf = 3e18 + 5;
     
    const int MAXN = 1 << 19;
    int N = 400000;
    int seg[2 * MAXN], A[MAXN];
    typedef vector<vi> vvi;
     
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
     
        int n,k;
        cin >> n >> k;
        
        if(n==1)
            cout << k;
        else{
            k--;
            int k2=k;
            for(int i=0; i<n-2; i++)
                k*=k2;
            cout << k*(k2+1);
        }
    }

Measured memory_bytes: 256
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local N = read.n()
local ph = read.N(N)
local pt = {}
for i=1,N do pt[i] = 1 - ph[i] end

local tbl = array(1, 0)
local tbl_n = array(1, 0)
tbl[0] = 1.

for i=1,N do
    tbl_n[0] = tbl[0] * pt[i]
    for j=1,i do
        tbl_n[j] = tbl[j] * pt[i] + tbl[j-1] * ph[i]
    end
    local tmp = tbl
    tbl = tbl_n
    tbl_n = tmp
end
local sum = 0
for c=math.ceil(N/2),N do
    sum = sum + tbl[c]
end
print(sum)

Measured memory_bytes: 888
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var q = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = Enumerable.Range(1, n).ToArray();
        int ctr = 0;
        var pind = ctr;
        var qind = ctr;
        foreach (var perm in Permutations(a))
        {
            if (p.Zip(perm, (x, y) => x == y).All(x => x)) pind = ctr;
            if (q.Zip(perm, (x, y) => x == y).All(x => x)) qind = ctr;
            ctr++;
        }
        Console.WriteLine(Abs(pind - qind));
    }


    static IEnumerable<T[]> Permutations<T>(T[] array) where T : IComparable<T>
    {
        int index = 0;
        yield return array;
        while (true)
        {
            for (int i = array.Length - 1; i > 0; i--)
            {
                if (array[i - 1].CompareTo(array[i]) >= 0) continue;
                int j = Array.FindLastIndex(array, x => array[i - 1].CompareTo(x) < 0);
                T tmp = array[i - 1]; array[i - 1] = array[j]; array[j] = tmp;
                Array.Reverse(array, i, array.Length - i);
                yield return array;
                goto end;
            }
            Array.Reverse(array, index, array.Length);
            yield break;
            end:;
        }
    }
}


Measured memory_bytes: 17608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author CodeMonk
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            if (n % 10 == 9 || (n / 10) == 9)
                out.println("Yes");
            else
                out.println("No");
        }

    }
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    if(dist[N-1]==2)putout("POSSIBLE");
  else putout("IMPOSSIBLE");
}

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

c = 0
if N == 100000:
    c = (99999 - 9999) + (999 - 99) + (9 - 0)
elif N >= 10000:
    c = N - 9999 + (999 - 99) + (9 - 0)
elif N >= 999:
    c = (999 - 99) + (9 - 0)
elif N >= 100:
    c = N - 99 + (9 - 0)
elif N >= 9:
    c = (9 - 0)
else:
    c = N
print(c)

Measured memory_bytes: 38384
#include <iostream>
using namespace std;
int main() {
	int N, X, D[100],min=0,cnt=0;
	cin >> N >> X;
	for (int i = 0;i<N;i++) {
		cin >> D[i];
		if (D[i] < D[min]) {
			min = i;
		}
		X -= D[i];
		cnt++;
	}

	if (X > 0) {
		cnt+=X / D[min];
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.next();
        StringBuilder str = new StringBuilder();
        for (int i=0;i<input.length();++i)
        {
            if (input.charAt(i)=='?')
                str.append('D');
            else
                str.append(input.charAt(i));
        }
        System.out.println(str.toString());
    }
}


Measured memory_bytes: 41840
#include <iostream>
#include <algorithm>
int main() {
	int N, M, a[50], b[50], c[50], d[50], ans[50], K[50] = {};
	std::cin >> N >> M;
	for (int i = 0; i < N; i++)
		std::cin >> a[i] >> b[i];
	for (int i = 0; i < M; i++)
		std::cin >> c[i] >> d[i];

	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++)
			if (j != 0) {
				if (std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]) != ans[i] && ans[i] != std::min(std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]), ans[i])) {
					ans[i] = std::min(std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]), ans[i]);
					K[i] = j + 1;
				}
			}
			else {
				ans[i] = std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]);
				K[i] = 1;
			}
			for (int i = 0; i < N; i++)
				std::cout << K[i] << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() {
  double N,F;
  cin>>N;
  F=N+1;
  if(fmod(N,2)==0){
    cout<<0.5<<endl;
  }
  else{
    cout<<(F/2)/N<<endl;
  }  
  return 0;
}

Measured memory_bytes: 384
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] linesp = line.split("");
        for(int i = 0; i < linesp.length; i++) {
            if(Character.isUpperCase(line.charAt(i))) {
                System.out.print(linesp[i].toLowerCase());
            }else {
                System.out.print(linesp[i].toUpperCase());
            }
        }
         System.out.println("");
    }
}


Measured memory_bytes: 26024
import fractions

a,b,k=map(int,input().split())

gcd=fractions.gcd(a,b)
cd_list=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        cd_list.append(gcd/i)
ans=int(cd_list[k-1])
print(ans)

Measured memory_bytes: 5048
S = input()
K = int(input())
s = set()
for i in "abcdefghijklnmopqrstuvwxyz":
    for j in range(len(S)):
        if i == S[j]:
            for k in range(K):
                s.add(S[j:j+k+1])
    if len(s) >= K:break
print(sorted(s)[K-1])

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{   int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b&&b==c){
        printf("1");
    }
    else if(a==b||a==c||b==c){
        printf("2");
    }else printf("3");

    return 0;
}


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

int main() {
  ll N;
  cin >> N;
  if (N % 2 == 1) cout << 0 << endl;
  else {
    ll ans = 0;
    for (ll i = 10; i <= N; i *= 5) {
      ans += N/i;
    }
    cout << ans << endl;
  }
}


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

int c[3][3];

int main() {
	rep(i, 3)rep(j, 3) cin >> c[i][j];
	bool elf = false;
	for (int i = 0; i <= c[0][0]; ++i) {
		for (int j = 0; j <= c[0][1]; ++j) {
			for (int k = 0; k <= c[0][2]; ++k) {
				bool tmp = true;
				for (int l = 0; l < 3; ++l) {
					if (c[l][0] - i == c[l][1] - j && c[l][1] - j == c[l][2] - k);
					else tmp = false;
				}
				if (tmp) elf = true;
			}
		}
	}
	if (elf) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(1e18)

typedef struct {
	int w;
	int s;
	int v;
}tuple;

signed compare_tuple(const void *_a, const void *_b){
	tuple a = *(tuple *)_a, b = *(tuple *)_b;
	int sub = (a.w + a.s) - (b.w + b.s);
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

int max(int a, int b){
	return a >= b ? a : b;
}

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, i, j, maxs = 0, ans = 0;
	scanf("%lld", &N);
	tuple *tps = (tuple *)malloc(sizeof(tuple) * N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld%lld", &tps[i].w, &tps[i].s, &tps[i].v);
		maxs = max(maxs, tps[i].s);
	}
	qsort(tps, N, sizeof(tuple), compare_tuple);
	int *dp = (int *)malloc(sizeof(int) * (maxs + 1));
	dp[0] = 0;
	for(j = 1; j <= maxs; j++){
		dp[j] = -inf;
	}
	for(i = 0; i < N; i++){
		for(j = 0; j <= tps[i].s; j++){
			ans = max(ans, dp[j] + tps[i].v);
		}
//		ans = max(ans, dp[tps[i].s] + tps[i].v);
		for(j = min(maxs, tps[i].s + tps[i].w); j >= tps[i].w; j--){
			dp[j] = max(dp[j], dp[j - tps[i].w] + tps[i].v);
		}
/*		printf("i = %lld\n", i);
		for(j = 0; j <= maxs; j++){
			printf("%lld ", dp[j]);
		}
		printf("\n");
*/	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
number = input().split(" ")
total= 1
y = 0
for i,a in enumerate(number):
    total *= int(a)
    x = 1
    for j,b in enumerate(number):
        if i == j:
            x *= 1
        else:
            x *= int(b)
    y += x
print(total/y)

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<set>

using namespace std;

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

 int n = 0;
 cin >> n;

 set<string> dic;

 for(int i = 0; i < n; i++){
  string buf1,buf2;
  cin >> buf1 >>buf2;
  if(buf1 == "insert"){
    dic.insert(buf2);
  }else{
   if(dic.find(buf2) != dic.end()){
    cout << "yes" << '\n';
   }else{
    cout << "no" << '\n';
   }
  }
 }
 return 0;
}

Measured memory_bytes: 27060
void main()
{
    long[] abc = readln.split.to!(long[]);

    if (abc.all!"a & 1")
    {
        abc.sort!"a < b";
        writeln(abc[0] * abc[1]);
    }
    else
    {
        0.writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s;
	cin >> s;
	bool is = true;
	rep(i, s.size() - 1) {
		if (s[i] == s[i + 1])is = false;
	}
	cout << (is ? "Good" : "Bad") << "\n";

	return 0;
}

Measured memory_bytes: 256