akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5,mod1=998244353,mod2=1000000007,mod3=2333;
int n,x=799633,invx1,invx2,invx3;
ll sum1=1,sum2=1,sum3=1;
ll s1[N],s2[N],s3[N];
char s[N];
ll inv(ll x,ll mod){return x==1?x:(mod-mod/x)*inv(mod%x,mod)%mod;}
struct node
{
    ll s1,s2,s3;
    node(ll s1=0,ll s2=0,ll s3=0):s1(s1),s2(s2),s3(s3){}
    void add()
    { s1=(s1+sum1)%mod1;s2=(s2+sum2)%mod2;s3=(s3+sum3)%mod3;}
    void sub()
    { s1=(s1+mod1-sum1)%mod1;s2=(s2+mod2-sum2)%mod2;s3=(s3+mod3-sum3)%mod3;}
    bool operator<(const node&o)const
    {
        if(s1==o.s1&&s2==o.s2) return s3<o.s3;
        if(s1==o.s1) return s2<o.s2;
        return s1<o.s1;
    }
};
void div()
{
    sum1=sum1*invx1%mod1;
    sum2=sum2*invx2%mod2;
    sum3=sum3*invx3%mod3;
}
void mul()
{
    sum1=sum1*x%mod1;
    sum2=sum2*x%mod2;
    sum3=sum3*x%mod3;
}
node f[N];
map<node,int>mp;
int main()
{
    invx1=inv(x%mod1,mod1);
    invx2=inv(x%mod2,mod2);
    invx3=inv(x%mod3,mod3);
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
    {
        f[i]=f[i-1];
        if(s[i]=='>') div();
        if(s[i]=='<') mul();
        if(s[i]=='+') f[i].add();
        if(s[i]=='-') f[i].sub();
        mp[f[i]]++;
    }
    sum1=sum2=sum3=1;
    node now;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        node p=now;
        p.s1=(p.s1+f[n].s1*sum1)%mod1;
        p.s2=(p.s2+f[n].s2*sum2)%mod2;
        p.s3=(p.s3+f[n].s3*sum3)%mod3;
        ans+=mp[p];
        mp[f[i]]--;
        if(s[i]=='>') div();
        if(s[i]=='<') mul();
        if(s[i]=='+') now.add();
        if(s[i]=='-') now.sub();
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 47488
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define gettime printf("\nTime : %0.3lf\n",clock()*1.0/CLOCKS_PER_SEC);
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define Set(x,a) memset(x,a,sizeof(x));

#define vs vector<string>
#define vi vector<int>
#define ll long long
#define ff first
#define ss second

struct comp {
       bool operator() (int a,int b) {
            return a>b;
       }
};

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    int x, a, b;
    scanf("%d %d %d", &x, &a, &b);
    x -= a;
    x %= b;
    printf("%d\n", x);
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d))cout<<"Yes"<<endl;
    else cout<<"No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int n1 = n+1;
        long m[] = new long[n1];
        long h[] = new long[n];
        for (int i = 0; i < n1; i++) {
            m[i] = scan.nextInt();
        }
        for (int i = 0; i < n; i++) {
            h[i] = scan.nextInt();
        }

        long result = 0;
        for (int i = 0; i < n; i++) {
            long xh = h[i];
            if(xh >= m[i]){
                result+=m[i];
                xh-=m[i];
               if(xh>=m[i+1]){
                   result+=m[i+1];
                   m[i+1]=0;
               }else{
                   result+=xh;
                   m[i+1]-=xh;
               }
            }else{
                m[i]-=xh;
                result+=xh;
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 86652
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      int N = Integer.parseInt(br.readLine());
      String S = br.readLine();
      long r = 0, g = 0, b = 0;
      for(int i = 0; i < N; i++){
        char c = S.charAt(i);
        if(c == 'R'){
          r++;
        }else if(c == 'G'){
          g++;
        }else{
          b++;
        }
      }
      
      long ans = r * g * b;
      for(int i = 0; i < N; i++){
        char c1 = S.charAt(i);
        for(int j = i+1; j < N; j++){
          if(j+(j-i) >= N) break;
          char c2 = S.charAt(j);
          char c3 = S.charAt(j+(j-i));
          if(c1 != c2 && c2 != c3 && c1 != c3){
            ans--;
          }
        }
      }
      System.out.println(ans);
    }catch(Exception e){
      System.out.println(e.toString());
    }
  }
}

Measured memory_bytes: 32864
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
struct edge { int u, v, w; };
ostream& operator<<(ostream& os, const edge& e) {
    os << "(" << e.u << ", " << e.v << ", " << e.w << ")";
    return os;
}
template <bool Directed> struct graph {
    int n;
    vector<edge> edges;
    vector<vector<int>> adj;
    graph(int n) : n(n), adj(n) {}
    graph(int n, int m) : graph(n) { edges.reserve(m); }
    void add_edge(int u, int v, int w) {
        adj[u].push_back(edges.size());
        edges.push_back({u, v, w});
        if(not Directed) {
            adj[v].push_back(edges.size());
            edges.push_back({v, u, w});
        }
    }
};
template <bool Directed> vector<ll> sssp(graph<Directed>& g, int s) {
    vector<bool> vis(g.n, false);
    vector<ll> d(g.n, numeric_limits<ll>::max());
    d[s] = 0;
    priority_queue<pair<ll, int>> pq;
    pq.push({-d[s], s});
    while(not pq.empty()) {
        int u = pq.top().second; pq.pop();
        if(not vis[u]) {
            vis[u] = true;
            for(int i : g.adj[u]) {
                edge& e = g.edges[i];
                if(not vis[e.v] and d[e.v] > d[u] + e.w) {
                    d[e.v] = d[u] + e.w;
                    pq.push({-d[e.v], e.v});
                }
            }
        }
    }
    return d;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    graph<0> g(2 * m + n + 1);
    map<pair<int, int>, int> id;
    int max_id = 0;
    auto get_node = [&](int u, int c) {
        return id.count({u, c}) ? id[{u, c}] : (id[{u, c}] = max_id++);
    };
    map<int, set<int>> companies_of;
    for(int i = 0; i < m; i++) {
        int p, q, c;
        cin >> p >> q >> c;
        g.add_edge(get_node(p, c), get_node(q, c), 0);
        companies_of[p].insert(c);
        companies_of[q].insert(c);
    }
    for(auto& p : companies_of) {
        int u = p.first;
        set<int>& s = p.second;
        for(int c : s) {
            g.add_edge(get_node(u, c), get_node(u, 0), 1);
        }
    }
    auto d = sssp(g, get_node(1, 0));
    cout << (id.count({n, 0}) and d[id[{n, 0}]] != lim<ll>::max() ? d[id[{n, 0}]] / 2 : -1) << endl;
    return 0;
}


Measured memory_bytes: 112040
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    int n,k;
    scanf("%02d%02d",&n,&k);
    if((n>12&&k==0)||(k>12&&n==0)||(n>12&&k>12)||(n==0&&k==0))
        printf("NA\n");
    else if(n<=12&&k<=12&&n!=0&&k!=0)
        printf("AMBIGUOUS\n");
    else if(k==0||k>12)
        printf("MMYY\n");
    else if(n==0||n>12)
        printf("YYMM\n");
    return 0;
}


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

int main()
{
	int N, a,ans=0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> a;
		for (;;) {
			if (a % 2 == 0) {
				a /= 2;
				ans++;
			}
			else break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
using namespace std;
#include<stack>
int main()
{
	while(1)
	{
		int a,b,n,v,x,y,m[18][18]={0},i,j,c=0,o=0;
		pair<int,int> p,t,g;
		stack<pair<int,int> > q;
		scanf ("%d%d",&a,&b);
		if (a==0&&b==0)
		{
			break;
		}
		g.first=a;
		g.second=b;
		for (i=0;i<18;i++)
		{
			for (j=0;j<18;j++)
			{
				if (i==0||i>a||j==0||j>b)
				{
					m[i][j]=1;
				}
			}
		}
		scanf ("%d",&n);
		for (i=0;i<n;i++)
		{
			scanf ("%d%d",&a,&b);
			m[a][b]=1;
		}
		p.first=1;
		p.second=1;
		q.push(p);
		while(!q.empty())
		{
			t=q.top();
			q.pop();
			if(m[t.first+1][t.second]!=1)
			{
				t.first++;
				if (t==g)
			{
				c++;
			}
				q.push(t);
				t.first--;
			}
			if (m[t.first][t.second+1]!=1)
			{
				t.second++;
				if (t==g)
			{
				c++;
			}
				q.push(t);
				t.second--;
			}
		}
		printf ("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
     
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
const ll MOD2 = 1e9 + 7;
const int MOD = 1e9 + 7;
 
const ull infull = numeric_limits<unsigned long long>::max();
 
void fix(int &x, ll MOD) {
    x = (x % MOD);
    if(x < 0) x += MOD;
    return;
}
 
ll lgput(ll a, ll b, ll MOD) {
    ll ret = 1;
    a %= MOD;
    while(b) {
        if(b&1) ret = ret*a % MOD;
        a = a*a % MOD;
        b >>= 1;
    }
 
    return ret;
}
 
ll inv(ll a, ll MOD) {
    return lgput(a, MOD-2, MOD);
}
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<(int)1e9 + 7>;
 
int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));

    int n;
    cin >> n;

    int k;
    cin >> k;

    vector< Mint >  dp(k + 1);

    Mint ans = 0;
    for(int i = k; i; --i) {
        Mint variante = 0;
        for(int j = i; j <= k; j += i) {
            variante += 1;
            dp[i] -= dp[j];
        }

        dp[i] += variante.pow(n);
        ans += dp[i]*i;
    }

    cout << ans << '\n';
    return 0; 
}

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

#define INF 100100100
#define MOD 1000000007

#define FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
using ll = long long;
using ull = unsigned long long ;

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0);
   int N;
   cin >> N;
   vector<int>a(N);
   FOR(i,N){
      cin >> a[i];
   }
   ll ans = INF;
   ll sum;
   for(int i=-100;i<=100;i++){
      sum = 0;
      for(int j=0;j<N;j++){
         if(a[j] != i)sum += (a[j]-i)*(a[j]-i);
      }
      ans = min(ans,sum);
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int m;
using namespace std;
const int N = 302;
string s;
int f[N][N][N];
int a[N];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> s;
    cin >> m;
    for (int i = 0; i < s.size(); i++) a[i + 1] = s[i] - 'a';
    int n = s.size(); a[0] = -1; a[n + 1] = -1;
    f[1][n][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = n; j >= i; j--) {
            for (int k = 0; k <= m; k++) {
                f[i + 1][j][k] = max(f[i + 1][j][k], f[i][j][k]);
                f[i][j - 1][k] = max(f[i][j - 1][k], f[i][j][k]);
                if (a[i] != a[j]) {
                    f[i + 1][j - 1][k + 1] = max(f[i + 1][j - 1][k + 1], f[i][j][k] + 2 - (i == j));
                }
                else {
                    f[i + 1][j - 1][k] = max(f[i + 1][j - 1][k], f[i][j][k] + 2 - (i == j));
                }
            }
        }
    }
    int mx = 0;
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= m; k++) {
                mx = max(mx, f[i][j][k]);
            }
        }
    }
    cout << mx << "\n";
    return 0;
}


Measured memory_bytes: 106368
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

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

  for(int i = 0; i < s.size() -1; i++) {
    if(s.substr(i, 2) == "AC") {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
FIGURE = [18, 48, 6, 30, 20, 34, 16]
loop do
  map = 8.times.map{ gets.chars.map(&:to_i) }
  base, *dots = 4.times.map do
    y = map.index{|i| i.include?(1)}
    x = map[y].index(1)
    map[y][x] = 0
    [x,y]
  end
  points = dots.inject(0){|sum,(x,y)| sum + (x-base[0]) + (y-base[1])*8}
  ans = 'A'
  FIGURE.index(points).times{ ans = ans.next }
  puts ans
  break unless gets
end

Measured memory_bytes: 6120
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;

int n;
int a[maxn];

int pref[maxn];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
}

int add(int x, int y)
{
    x += y;
    if(x >= mod) x -= mod;
    return x;
}

void solve()
{
    pref[0] = 0;
    for(int i = 1; i <= n; ++i)
        pref[i] = add(pref[i - 1], a[i]);
    int ans = 0;
    for(int i = 1; i <= n; ++i)
        ans = add(ans, a[i] * 1LL * pref[i - 1] % mod);
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
const int Q=505,P=1<<20;
int las[Q],e[P],nn[P],c[P],inc;
int S,T;
int cnt[Q],dis[Q];
int Sap(int x,int fl)
{
    if(x==T)return fl;
    int had=0;
    for(int t=las[x];t;t=nn[t]){
        int y=e[t];
        if((!c[t])||dis[x]-1!=dis[y])continue;
        int res=Sap(y,min(c[t],fl-had));
        had+=res,c[t]-=res,c[t^1]+=res;
        if(had==fl||dis[S]>=T)return had;
    }
    --cnt[dis[x]];
    if(!cnt[dis[x]])dis[S]=T;
    cnt[++dis[x]]++;
    return had;
}
void iNS(int x,int y,int z)
{
    e[++inc]=y;
    nn[inc]=las[x];
    las[x]=inc;
    c[inc]=z;
}
void ins(int x,int y,int z)
{iNS(x,y,z),iNS(y,x,0);}
int a[Q][Q],b[Q][Q],cc[Q],uz[Q*Q];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    for(int p=1;p<=m;p++){
        inc=1;
        S=(n<<1)+1,T=S+1;
        memset(las,0,sizeof(las));
        memset(cnt,0,sizeof(cnt));
        memset(dis,0,sizeof(dis));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                if(!uz[a[i][j]])
                    ins(i,(a[i][j]-1)/m+1+n,1);
        for(int i=1;i<=n;i++)
            ins(S,i,1),ins(i+n,T,1);
        int ch=0;
        while(dis[S]<T)ch+=Sap(S,(int)1e9);
        assert(ch==n);
        int now=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++)
                if(!uz[a[i][j]]){
                    now+=2;
                    if(c[now]){
                        uz[a[i][j]]=1;
                        b[i][p]=a[i][j];
                    }
                }
        }
    }
    for(int i=1;i<=n;i++,puts(""))
        for(int j=1;j<=m;j++)
            printf("%d ",b[i][j]);
    for(int j=1;j<=m;j++){
        for(int i=1;i<=n;i++)
            cc[i]=b[i][j];
        sort(cc+1,cc+n+1);
        for(int i=1;i<=n;i++)
            b[i][j]=cc[i];
    }
    for(int i=1;i<=n;i++,puts(""))
        for(int j=1;j<=m;j++)
            printf("%d ",b[i][j]);
    return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 1001000;

vector<PII> G[MAX];
vector<PII> g[MAX];
VI V[MAX];

VI I[MAX];
int ST[MAX];

int D[MAX];

int getV(int x, int c)
{
	int pos = lower_bound(ALL(V[x]), c) - V[x].begin();
	return I[x][pos];
}

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

	int n, m;
	scanf("%d%d", &n, &m);

	FOR (i, 0, m)
	{
		int x, y, c;
		scanf("%d%d%d", &x, &y, &c);
		x--;
		y--;
		c--;

		G[x].PB(MP(y, c));
		G[y].PB(MP(x, c));
		V[x].PB(c);
		V[y].PB(c);
	}

	int sz = 0;

	FOR (i, 0, n)
	{
		VI& v = V[i];

		sort(ALL(v));
		v.erase(unique(ALL(v)), v.end());

		I[i].resize(SZ(v));
		FOR (j, 0, SZ(v))
		{
			I[i][j] = sz++;
		}
	}

	FOR (i, 0, n)
	{
		ST[i] = sz++;
	}

	FOR (i, 0, n)
	{
		FOR (j, 0, SZ(G[i]))
		{
			int to = G[i][j].first;
			int c = G[i][j].second;

			int x = getV(i, c);
			int y = getV(to, c);

			g[x].PB(MP(y, 0));
			g[y].PB(MP(x, 0));
		}


		FOR (j, 0, SZ(V[i]))
		{
			int ind = I[i][j];
			int st = ST[i];

			g[ind].PB(MP(st, 0));
			g[st].PB(MP(ind, 1));
		}
	}

	set<PII> S;

	FOR (i, 0, sz)
	{
		D[i] = INF;
	}

	D[ST[0]] = 0;
	S.insert(MP(0, ST[0]));

	while(SZ(S))
	{
		int x = S.begin()->second;
		S.erase(S.begin());

		FOR (i, 0, SZ(g[x]))
		{
			int to = g[x][i].first;
			int c = g[x][i].second;

			if (D[to] > D[x] + c)
			{
				S.erase(MP(D[to], to));
				D[to] = D[x] + c;
				S.insert(MP(D[to], to));
			}
		}
	}

	int res = D[ST[n-1]];

	if (res == INF) res = -1;

	cout<<res<<endl;





}


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

void solve(std::string T) {
    rep(i, T.size()) {
        if (T[i] == '?') {
            T[i] = 'D';
        }
    }
    cout << T << endl;
}

int main() {
    std::string T;
    std::cin >> T;
    solve(T);
    return 0;
}


Measured memory_bytes: 3872
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <deque>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

    int L = 0;
    int R = 100005;
    for (int i = 0; i < M; i++)
    {
        int cnt;
        cin >> cnt;
        L = max(L, cnt);
        cin >> cnt;
        R = min(R, cnt);
    }
    cout << max(R - L + 1, 0) << endl;
    return 0;
}


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

int main() {

  string input;

  while( getline( cin, input ) ) {

    int map[3][3] = {0};

    for ( int i = 0; i < 9; i++ ) {

      if ( input[i] == 'o' ) {
	map[i%3][i/3] = 1;
      }else if ( input[i] == 'x' ) {
	map[i%3][i/3] = 4;
      }

    }

    int ans = 0;
    int cnt = 0;

    for ( int i = 0; i < 3; i++ ) {
      cnt = 0;
      for ( int j = 0; j < 3; j++ ) {
	cnt += map[j][i];
      }
      if ( cnt == 3 ) ans = 1;
      if ( cnt == 12 ) ans = 2;
    }

    for ( int i = 0; i < 3; i++ ) {
      cnt = 0;
      for ( int j = 0; j < 3; j++ ) {
	cnt += map[i][j];
      }
      if ( cnt == 3 ) ans = 1;
      if ( cnt == 12 ) ans = 2;
    }

    cnt = 0;
    for ( int i = 0; i < 3; i++ ) {
      cnt += map[i][2-i];
    }
    if ( cnt == 3 ) ans = 1;
    if ( cnt == 12 ) ans = 2;

    cnt = 0;
    for ( int i = 0; i < 3; i++ ) {
      cnt += map[i][i];
    }
    if ( cnt == 3 ) ans = 1;
    if ( cnt == 12 ) ans = 2;

    if ( ans == 0 ) {
      cout << "d";
    }else if ( ans == 1 ) {
      cout << "o";
    }else {
      cout << "x";
    }
    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define count count1
#define NIL -1
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
// std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// int myRand(int R) {
// 	int val=rng() % R;
//       assert(val>=0);
//       return val;
// }
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int32_t MOD=MOD1;

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
           string s,t;
           cin>>s>>t;
           int cnt=0;
           rep(i,0,s.length())
           {
               cnt+=(s[i]!=t[i]);
           }
           cout<<cnt<<endl;
      }
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 3752
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
int main(void){
    ll A,B,K;
    cin>>A>>B>>K;
    if(A>K)cout<<A-K<<" "<<B<<endl;
    else if((A+B)>K)cout<<0<<" "<<B-(K-A)<<endl;
    else cout<<0<<" "<<0<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(int a, int b){
   return b ? GCD(b, a%b) : a;
}

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

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

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

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

   int cnt = 0;
   for(int i = 0; i < n; i++){
      int i_diff = (d.size() - i - 1) - i;
      if(i_diff == 1){
         for(int j = d[i]; j < d[i+1]; j++){
            cnt++;
         }
      }
   }

   cout << cnt << endl;


   return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PI acos(-1.0)
using namespace std;
const int mod=1e9+7;
int arr[21][21];
ll dp[21][(ll)1<<21];
int n;
ll add_self(ll &p, ll q)
{
    p+=q;
    if(p>=mod) p-=mod;
}
ll DP(int pos, int bit)
{
    if(pos>=n) return 1;
    if(dp[pos][bit]!=-1) return dp[pos][bit];
    ll ans=0;
    for(int i=0; i<n; i++)
    {
        if(arr[pos][i] && !(bit&(1<<i)))
        {
            ans=(ans+DP(pos+1, (bit|(1<<i))))%mod;
        }

    }
    return dp[pos][bit]=ans;
}
int main()
{
    memset(dp, -1, sizeof dp);
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            scanf("%d", &arr[i][j]);
    }
    ll ans=DP(0, 0);


    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 344448
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 201000,mod = 1e9+7;
struct node{int x,y;}p[N];
int n,m,a[N],b[N],c[N],bx[N],by[N],cntx,cnty,tot;
vector<int> h[N];
void modify(int x,int k){
	for(int i=x;i;i-=i&-i) c[i]=(c[i]+k)%mod;
}
int query(int x){
	int ans=0;
	for(int i=x;i<=cnty+1;i+=i&-i) ans=(ans+c[i])%mod;
	return ans;
}
int main(){
	read(n);read(m);
	for(int i=1;i<=n;i++)
		read(a[i]);
	for(int i=1;i<=m;i++)
		read(b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	for(int i=1;i<=n;i++){
		int k=upper_bound(b+1,b+m+1,a[i])-b;
		if(k==1||k>m) continue;
		p[++tot]={b[k]-a[i],a[i]-b[k-1]};
		bx[++cntx]=p[tot].x;
		by[++cnty]=p[tot].y;
	}
	sort(bx+1,bx+cntx+1);
	sort(by+1,by+cnty+1);
	cntx=unique(bx+1,bx+cntx+1)-bx-1;
	cnty=unique(by+1,by+cnty+1)-by-1;
	for(int i=1;i<=tot;i++){
		p[i].x=lower_bound(bx+1,bx+cntx+1,p[i].x)-bx,
		p[i].y=lower_bound(by+1,by+cnty+1,p[i].y)-by;
		h[p[i].x].push_back(p[i].y);
	}
	modify(cnty+1,1);
	for(int i=cntx;i;i--){
		vector<pair<int,int> > V;
		sort(h[i].begin(),h[i].end());
		h[i].resize(unique(h[i].begin(),h[i].end())-h[i].begin());
		for(int y:h[i]) V.emplace_back(y,query(y+1));
		for(auto pr:V) modify(pr.first,pr.second);
	}
	cout<<query(1)<<'\n';
	return 0;
}


Measured memory_bytes: 12288
import java.util.Scanner;

public class Main {

	public static int n;
	public static int[] A;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		A = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int[] m = new int[q];
		for (int i = 0; i < q; i++) {
			m[i] = sc.nextInt();
		}

		for (int i = 0; i < q; i++) {
			if (solve(0, m[i])) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}

	}

	public static boolean solve(int i, int m) {
		if (m == 0) {
			return true;
		}
		if (i >= n) {
			return false;
		}
		boolean res = solve(i + 1, m) || solve(i + 1, m - A[i]);
		return res;
	}

}


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

int SumofDigit(int a ) {
  int pre = 0 ;
  while( a != 0 ){
    pre += a % 10 ;
    a /= 10 ;
  }
  return pre ;
}

int main () {
  int N , A , B ;
  cin >> N >> A >> B ;
  
  int ans = 0 ;
  
  for(int i = 1 ; i < N + 1; i++ ) {
    if( SumofDigit(i) >= A && SumofDigit(i) <= B) ans += i ;
  }
  cout << ans << endl ;
}

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

using namespace std;

int solve(string s, string t, int n){
    // sの文字のうち, かぶっていない文字の数をiとする
    // 全探索する
    for (int i = 0; i < n; i++){
        if (s.substr(i) == t.substr(0,n-i)) return n + i;
    }
    
    // n文字すべてかぶらない-> 2*n
    return 2*n;
}

int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    
    cout << solve(s,t,n) << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;cin>>s;
  ll ans=0;
  ll now=0;
  for(ll i=0;i<s.size();i++){
    if(s[i]=='B')continue;
    ans+=i-now;
    now++;
  }
  cout<<ans;
}

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

int main()
{
    int n, m=0, ans=0;
    int *hs;
    scanf("%d", &n);
    hs = malloc(sizeof(int)*n);
    for(int i=0;i<n;i++) scanf("%d", hs+i);
    m = hs[0];
    for(int i=0;i<n;i++){
        if(hs[i] >= m){
            ans++;
            m = hs[i];
        }
    }
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream> //cout
#include <cstring> //c
#include <vector> //vector
#include <cmath> //roundup
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
    unsigned long long A, B;
    string Bstr;
    cin >> A >> Bstr;

    Bstr.replace(Bstr.size()-3, 1, "");
    B = atoi(Bstr.c_str());

    unsigned long long ans;
    // cout << "a:" << A << ", b:" << B << endl;
    ans = A * B;

    // cout << "ans:" << ans << endl;
    ans /= 100;

    cout << ans << endl;
}


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

int main() {
    string s;
    cin >> s;
    int size = s.size()/2;
    //cout << size << endl;
    for(int i=0;i<size;i++){
            s.erase(s.begin()+i+1);
    //        cout << s << endl;
    }
    cout << s << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2]||s[1]==s[2]&&s[2]==s[3]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
import math

a,b,h,m = map(int, input().split())
huna = m*6
zia = (60*h + m)*0.5
sita = 0.0
if huna >= zia:sita = huna - zia
else:sita = zia - huna

if sita > 90:sita = 360 - sita
ans = (a**2 + b**2 - 2*a*b*math.cos(math.radians(sita)))**0.5
print('{:.20f}'.format(ans))

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e6+6;
int s[N];
void sieve(){
	for(int i=2;i<N;i++){
		if(s[i]==0){
			s[i]=i;
			for(int j=i+i;j<N;j+=i){
				if(!s[j])s[j]=i;
			}
		}
	}
}
ll sq(ll a){return (a*a)%mod;}
ll pw(ll a,ll b){
	if(b==0)return 1;
	if(b==1)return a;
	if(b&1)return (a*sq(pw(a,b>>1)))%mod;
	return sq(pw(a,b>>1))%mod;
}

int mcl[N];
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;cin>>n;
	sieve();
	vector<ll>v;
	for(int i=0;i<n;i++){
		ll a;cin>>a;v.push_back(a);
		map<int,int>mp;
		while(a!=1){
			mp[s[a]]++;
			a/=s[a];
		}
		for(auto u:mp){
			mcl[u.first]=max(mcl[u.first],u.second);
		}
	}
	ll l=1;
	for(int i=2;i<=N;i++){
		while(mcl[i]--){
			l*=i;
			l%=mod;
		}
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ans+=(l*pw(v[i],mod-2));
		ans%=mod;
	}
	cout<<ans;
}

Measured memory_bytes: 11604
#include<stdio.h>

int K[10005][10005];
void knapsack(int n, int wMax,int W[],int b[])
{

	for(int i=1;i<=n;i++)
	{
		for(int w=0;w<=wMax;w++)
		{
			if(W[i] <= w)
			{
				if(b[i] + K[i-1][w-W[i]] > K[i-1][w])
				{
					K[i][w] = b[i] + K[i-1][w-W[i]];
				}else
				{
					K[i][w] = K[i-1][w];
				}
			}else
			{
				K[i][w]=K[i-1][w];
			}
		}
	}
	
	printf("%d\n",K[n][wMax]);
}


int main()
{
	int N,Weight;
	int V[10000],W[10000];
	int answer;
	
	scanf("%d %d",&N,&Weight); getchar();
	for(int i=1;i<=N;i++)
	{
		scanf("%d %d",&V[i],&W[i]); getchar();
	}
	
	knapsack(N,Weight,W,V);
	
	return 0;
}


Measured memory_bytes: 5696
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  string s;
  cin >> s;
  for(int bit = 0; bit <= (1<<3); ++bit){
    string ans = "";
    ans += s[0];
    int value = s[0] - '0';
    int b = bit;
    for(int i = 1; i < 4; ++i){
      if(b & 1) {
        value += s[i] - '0';
        ans += '+';
      } else {
        value -= s[i] - '0';
        ans += '-';
      }
      ans += s[i];
      b = b >> 1;
    }
    if(value == 7)  {
      cout << ans  + "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
set<string> se;
int main()
{
    int n;
    while (cin>>n)
    {
        string temp;
        cin>>temp;
        se.insert(temp);
        n--;
        int flag=1;
        while (n--)
        {
            string te;
            cin>>te;
            if (se.count(te)!=0)
            {
                flag=0;
            }
            se.insert(te);
            if (te[0]!=temp[temp.length()-1])
            {
                flag=0;
            }
            temp=te;
        }
        if (flag)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import collections
N = int(input())
Red_list = []
Blue_list = []
max = 0
for i in range(N):
    s = str(input())
    Red_list.append(s)
M = int(input())
for j in range(M):
    t = str(input())
    Blue_list.append(t)
count_red = collections.Counter(Red_list)
count_blue = collections.Counter(Blue_list)
result = count_red - count_blue
lists = list(result.values())
for i in range(len(lists)):
    if max < lists[i]:
        max = lists[i]
print(max)


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	string X; cin >> X;
	vint U1(N+1), U2(N+1); //U1: pcnt-1, U2: pcnt+1
	vint pow1(N+1, 1), pow2(N+1, 1);

	int pcnt = count(begin(X), end(X), '1');
	int p1 = max(pcnt-1, 1), p2 = pcnt+1;

	for (int i = N-1; i >= 0; i--) {
		if (i < N-1) {
			pow1[i] = (pow1[i+1] * 2) % p1;
			pow2[i] = (pow2[i+1] * 2) % p2;
		}
		U1[i] = U1[i+1];
		U2[i] = U2[i+1];
		if (X[i] == '1') {
			(U1[i] += pow1[i]) %= p1;
			(U2[i] += pow2[i]) %= p2;
		}
	}
	//cout << U1[0] << " " << U2[0] << endl;

	for (int i = 0; i < N; i++) {
		int nxtval, cnt = 1;
		if (X[i] == '1') {
			if (pcnt == 1) {
				cout << 0 << el;
				continue;
			} else {
				nxtval = (U1[0] + p1 - pow1[i]) % p1;
			}
		} else {
			nxtval = (U2[0] + pow2[i]) % p2;
		}

		///cout << nxtval << " ";

		while (nxtval) {
			int pc = __builtin_popcount(nxtval);
			nxtval = nxtval % pc;
			cnt++;
		}
		cout << cnt << el;
	}
}

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


Measured memory_bytes: 6760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll n;cin>>n;
    map<string,ll>mp;
    ll maxi=0;
    f(i,0,n){
        string s;cin>>s;
        mp[s]++;
        maxi=max(maxi,mp[s]);
    }
    for(auto x:mp){
        if(x.S==maxi)cout<<x.F<<endl;
    }
    return 0;  
} 

Measured memory_bytes: 23808
# 動物の数がX匹、　足の総数がY本
X,Y = map(int,input().split())
#print(X,Y)
turu = 2
kame = 4
flag = False
for i in range(0, X + 1): # 0, 1, 2, 3
    #print("亀が{0}匹の場合".format(i))
    turu_num = X - i
    #print("鶴は{0}匹".format(turu_num))
    leg_total = kame * i + turu_num * turu
    #print("足の総数は{0}".format(leg_total))
    if(leg_total == Y):
      flag = True
      break
#    for q in range(0, X - i + 1):
#        print("鶴は{0}匹".format(q))
#        if kame * i + turu * q == Y and (i + q) <= X:
#            flag += 1
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n, w;
  cin >> n >> w;
  VL best(w+1, -1); //the max value of weight i we can achieve
  best[0] = 0;
  forx(i, n) {
    ll w1, v1;
    cin >> w1 >> v1;
    for (int i = w-w1; i >= 0; --i) {
      if (best[i] >= 0) {
        best[i+w1] = max(best[i+w1], best[i]+v1);
      }
    }
  }
  ll ans = 0;
  for (ll v : best) {
    ans = max(ans, v);
  }
  cout << ans << nl;
  
  cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl;
  return 0;
}



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

int selectionsort(vector<int>& v, int n) {
	int count = 0;
	for (int i = 0; i < n - 1; ++i) {
		int minv =i;
		for (int j = i+1; j < n; ++j) {
			if (v[minv] > v[j]) {
				minv = j;
			}
		}
		if (minv != i)++count;
		swap(v[i],v[minv]);
	}
	return count;
}

int main() {
	int n;
	cin >> n;
	vector<int>v(n);
	for (int i = 0; i < n; ++i)cin >> v[i];
	int ans = selectionsort(v, n);
	for (int i = 0; i < n; ++i) {
		if (i)cout << " ";
		cout << v[i];
	}
	cout << endl;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <algorithm>
using std::pair;
using std::make_pair;
#include <vector>
using std::vector;

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<vector<PII> > VP;

int main(void) {
    while (1) {
        int n; // pc
        int m; // person
        scanf("%d%d", &n, &m);
        if (n == 0 && m == 0) {
            break;
        }

        VI pc(m + 1, 0);
        VI start(m + 1, 0);

        VP time(m + 1);

        int r;
        scanf("%d", &r);
        for (int i = 0; i < r; i++) {
            int t;
            int n2; // pc
            int m2; // person
            int s;
            scanf("%d%d%d%d", &t, &n2, &m2, &s);
            if (s == 1) {
                if (pc[m2] == 0) {
                    start[m2] = t;
                }
                pc[m2]++;
            } else {
                pc[m2]--;
                if (pc[m2] == 0) {
                    int end = t;
                    time[m2].push_back(make_pair(start[m2], end));
                }
            }
        }

        int q;
        scanf("%d", &q);
        for (int i = 0; i < q; i++) {
            int s;
            int e;
            int m2;
            scanf("%d%d%d", &s, &e, &m2);
            int count = 0;

            for (int j = 0; j < (int)(time[m2].size()); j++) {
                int first = time[m2][j].first;
                int second = time[m2][j].second;
                int start;
                int end;
                if (s < first) {
                    start = first;
                } else if (s <= second) {
                    start = s;
                } else {
                    continue;
                }
                if (e < first) {
                    break;
                } else if (e <= second) {
                    end = e;
                } else {
                    end = second;
                }
                count += end - start;
            }
            printf("%d\n", count);
        }

    }
    return 0;
}

Measured memory_bytes: 3496
#include<iostream>

using namespace std;

double dp[100000+1];
int main(void){
  int n;
  while( cin >> n ) {
    if(n == 0)break;
    double ans = 0;
	//初期化
    fill(dp, dp+n+1,0);
	//計算
	int i,j;
    for(i=0; i<=n; i++){
      double rate = 1, prate=1, base=1-dp[i];
      for(j=i+1; j<=n; j++){
			double nrate = rate * prate;
			if(nrate<0.0000000001)break;
			dp[j]+=(nrate * base);
			prate=nrate;
			rate *= 0.5;
      }
      ans += dp[i];
    }
    printf("%0.8lf\n",ans);
  }
}

Measured memory_bytes: 0
import sys
a, b, n = map(int, input().split())

if n < b:
    ans = a * n // b  
    print(ans)
    sys.exit()  
elif n == b:
    ans = a * (b-1) // b
    print(ans)
    sys.exit()

# n == 1のときは0 問題なし
r = n // b
ans = 0
# for i in range(1, r + 1):
#     t = i * b - 1
#     ans_t = a * t // b - (a * (i - 1))
#     ans = max(ans, ans_t) 
    # print(i, t, ans)

t = r * b - 1
ans_t = a * t // b - (a * (r - 1))
ans = max(ans, ans_t) 

ans_t = a * n // b - (a * (n // b))
ans = max(ans, ans_t) 

print(ans)

Measured memory_bytes: 9156
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Fri Mar 27 18:29:10 JST 2020
 **/

signed main() {
    Int H, W;
    cin >> H >> W;
    vector<string> a(H);
    REP(i, H) cin >> a[i];
    vector<Int> rows, cols;
    REP(i, H) {
        bool ok = false;
        REP(j, W) {
            if (a[i][j] == '#') ok = true;
        }
        if (ok) rows.push_back(i);
    }
    REP(j, W) {
        bool ok = false;
        REP(i, H) {
            if (a[i][j] == '#') ok = true;
        }
        if (ok) cols.push_back(j);
    }
    for (Int i : rows) {
        for (Int j : cols) {
            cout << a[i][j];
        }
        cout << endl;
    }
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

vector <vector <int> > adj(200000+5);
vector <int> a(200000+1,0);
vector <bool> vis(200000+1,false);

void dfs(int v,int p)
{
    vis[v]=true;
    if(p!=-1)
    {
        a[v]+=a[p];
    }

    for(int u:adj[v])
    {
        if(not vis[u])
        {
            dfs(u,v);
        }
    }
}


int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n,q;
    cin>>n>>q;

    loop(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;

        adj[a].pb(b);
        adj[b].pb(a);
    }

    while(q--)
    {
        int v,x;
        cin>>v>>x;
        a[v]+=x;
    }

    dfs(1,-1);

    for(int i=1;i<n+1;i++) cout<<a[i]<< " ";


    return 0;
}


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

const int INF=1e+9;
int N,K;
int h[100010];


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

  for(int i=0;i<n;++i){
    cin >> h[i];
  }
  vector<int> dp(n, 1e9 + 10);
	dp[0] = 0;

	for (auto i = 1; i < n; ++i) {
		for (int j = i - 1; j >= i - k and j >= 0; --j) {
			int a = abs(h[i] - h[j]);
			dp[i] = min(dp[i], a + dp[j]);
		}
	}

	cout << dp[n - 1];
  return 0;
}


Measured memory_bytes: 1024