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

int main() {
  // dp[i][j][k]
  // kは0以外の桁数0,1,2,3,4以上の5種類
  int dp[120][2][5] = {};
  
  string N;
  int K;
  cin >> N >> K;
  vector<int> n(N.size());
  for(int i = 0; i < N.size(); ++i){
    n.at(i) = N.at(i) - '0';
  }

  dp[0][0][0] = 1;
  for(int i = 0; i < n.size(); ++i){
    for(int j = 0; j < 2; ++j){
      for(int k = 0; k < 5; ++k){
        for(int x = 0; x <= (j ? 9 : n.at(i)); ++x){
          dp[i+1][j || x < n.at(i)][min(k + (x!=0), 4)] += dp[i][j][k];
        }
      }
    }
  }
  cout << dp[n.size()][0][K] + dp[n.size()][1][K] << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        if(a == b && b == c){
            System.out.println(1);
        } else if(a == b || b == c || c == a){
            System.out.println(2);
        } else {
            System.out.println(3);
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


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

// mode=true:RangeMinimumQuery
// mode=false:RangeMaximumQuery
template <typename T>
struct RMQ
{
  T INF;
  bool mode;
  int n;
  vector<T> dat;
  RMQ(int n_, bool minimum)
  {
    mode = minimum;
    if (mode)
      INF = numeric_limits<T>::max();
    else
      INF = numeric_limits<T>::min();
    n = 1;
    while (n < n_)
      n *= 2;
    dat.resize(n * 2 - 1);
    fill(dat.begin(), dat.end(), INF);
  }

  void update(int i, T x)
  {
    i += n - 1;
    dat[i] = x;
    while (i > 0)
    {
      i = (i - 1) / 2;
      if (mode)
        dat[i] = min(dat[i*2+1], dat[i*2+2]);
      else
        dat[i] = max(dat[i*2+1], dat[i*2+2]);
    }
  }

  T query(int a, int b, int k=0, int l=0, int r=-1)
  {
    if (r == -1)
      r = n;
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= b)
      return dat[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    if (mode)
      return min(vl, vr);
    else
      return max(vl, vr);
  }
};

int main()
{
  int n;
  cin >> n;
  vector<int> h(n), a(n);
  rep(i, n)
    cin >> h[i];
  rep(i, n)
    cin >> a[i];
  RMQ<ll> s(n + 1, false);
  s.update(0, 0);
  rep(i, n)
    s.update(h[i], s.query(0, h[i]) + a[i]);
  cout << s.query(0, n + 2) << endl;
  return 0;
}

Measured memory_bytes: 5888
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

void solve(){
    int n;
    cin>>n;
    bool flag=false;
    for(int i=1;i<10;++i){
        if(n%i==0){
            if(n/i<10)flag=true;
        }
    }
    if(flag)cout<<"Yes\n";
    else cout<<"No\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	//cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S, T;
	cin >> S >> T;

	cout << T << S;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int m, f, r;
	char grade;

	while (cin >> m >> f >> r) {
		
		//??¨???-1?????¨?????????
		if (m == -1 && f == -1 && r == -1) {
			break;
		}

		//??????F(1)
		if ( m == -1 || f == -1) {
			grade = 'F';
		}
		//??????A
		 else if (m + f >= 80) {
			grade = 'A';
		}
		//??????B
		 else if (m + f >= 65 && m + f < 80) {
			 grade = 'B';
		 }
		 //??????C
		 else if (m + f >= 50 && m + f < 65) {
			 grade = 'C';
		 }
		 //??????C(2)
		 else if (m + f >= 30 && m + f < 50 && r >= 50) {
			 grade = 'C';
		 }
		 //??????D
		 else if (m + f >= 30 && m + f < 50) {
			 grade = 'D';
		 }
		 //??????F(2)
		 else if (m + f < 30) {
			 grade = 'F';
		 }

		 cout << grade << endl;
	}

	return 0;

}

Measured memory_bytes: 3040
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 100005;

vi g[N];
int P[N];
int col[N];

void dfs(int c, int p) {
  P[c] = p;
  rep(i,0,g[c].size()) {
    int u = g[c][i];
    if(u != p) {
      dfs(u, c);
    }
  }
}

void dfs1(int c, int cc) {
  col[c] = cc;
  rep(i,0,g[c].size()) {
    int u = g[c][i];
    if(u == P[c] || col[u]) continue;
    dfs1(u, cc);
  }
}

int main() {
  int n;
  S(n);
  rep(i,0,n-1) {
    int u,v;
    S2(u,v);
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1,-1);
  vector<int > v;
  int c = n;
  while(c != -1) {
    v.pb(c);
    c = P[c];
  }

  int sz = v.size();
  reverse(all(v));
  rep(i,0,sz) {
    if(i < (sz + 1) / 2) col[v[i]] = 1;
    else col[v[i]] = 2;
  }

  rep(i,0,sz) {
    dfs1(v[i], col[v[i]]);
  }
  int x = 0;
  rep(i,1,n+1) {
    x += col[i] == 1;
    x -= col[i] == 2;
    assert(col[i]);
  }
  if(x > 0) printf("Fennec\n");
  else printf("Snuke\n");
  return 0;
}


Measured memory_bytes: 11640
#include<iostream>
using namespace std;
int main(){
   int a=0,b=1,counter=0;
   cin>>a;
   int c[a+1];
   for(int i=1;i<=a;i++){
       cin>>c[i];
       
   }
   while(b!=2&&counter<a){
       b=c[b];
       //b=b-1;
       counter+=1;
 //      d=b;
   }
   if(b==2){
      // counter+=1;
   }else{
       counter=-1;
   }
   cout<<counter;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main
{
    static int N;
    static int[]A = new int[10000000];

    public static void maxHeapify(int i)
    {
	int l = 2 * i;
	int r = 2 * i + 1;
	int largest;

	if(l <= N && A[l] > A[i])
	    largest = l;
	else 
	    largest = i;

	if(r <= N && A[r] > A[largest])
	    largest = r;

	if(largest != i)
	    {
		int b = A[i];
		A[i] = A[largest];
		A[largest] = b;
		maxHeapify(largest);
	    }
    }

    public static int ex()
    {
	int maxv;
	if(N < 1) return -10000000;

	maxv = A[1];
	A[1] = A[N--];
	maxHeapify(1);
	return maxv;
    }

    public static void increase(int i, int key)
    {
	if(key < A[i]) return;
	A[i] = key;
	while(i > 1 && A[i / 2] < A[i])
	    {
		int b = A[i];
		A[i] = A[i / 2];
		A[i / 2] = b;
		i /= 2;
	    }
    }

    public static void insert(int key)
    {
	N++;
	A[N] = -1000000;
	increase(N,key);
    }

    public static void main(String[]args)
    {
	Scanner In = new Scanner(System.in);
	int key;
	String com;

	while(true)
	    {
		com = In.next();
		if(com.equals("end")) break;

		if(com.equals("insert"))
		    {
			key = In.nextInt();
			insert(key);
		    }
		else
		    {
			System.out.println(ex());
		    }
	    }
    }
}

Measured memory_bytes: 486364
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> c(3);
  int cnt = 0;
  for (int i = 0; i < 1000; ++i) {
    c[2] = i / 100;
    c[1] = (i / 10) % 10;
    c[0] = i % 10;

    int f = 0;
    for (int j = 0; j < n; ++j) {
      if (s[j] == ('0' + c[f])) f++;
      if (f == 3) break;
    }
    if (f == 3) cnt++;
  }
  cout << cnt << endl;
}


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

int main(){
   int h, n;
  int a;
  int s = 0;
  cin >> h >> n;
  rep(i,n){
    cin >> a;
    s += a;
  }
  if(h-s <= 0) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 256
import math

s = int(input())
ans = 0

if s < 2:
    print(ans)
    
else:
    for i in range(1,s//3+1):
        t = s - 3*i
        
        ans += math.factorial(t+(i-1)) // math.factorial(t) // math.factorial(i-1)
        ans %= 10**9 +7
        
    print(ans)

Measured memory_bytes: 73788
#include"bits/stdc++.h"

#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 all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string a, b;
    cin >> a >> b;
    rep(i,min(a.size(), b.size())) {
        cout << a[i] << b[i];
    }
    if (a.size() > b.size())cout << a[a.size() - 1] << endl;
    else if(a.size() < b.size()) cout << b[b.size() - 1] << endl;
}

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

using namespace std;

struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;

const LL mod=1e9+7;
const LL r2=500000004;
LL fact[10000];
struct cww{cww(){
    fact[0]=1;for(int i=1;i<10000;i++)fact[i]=(fact[i-1]*i)%mod;
}}ccw;

#define rep(i,n) for(auto i=(n)*0;i<n;i++)
#define range(it,v) for(auto &it:v)

template<typename T>
class svector:private std::vector<T>{
    using V=std::vector<T>;
    using SV=svector;
private:int sz;
public:
    using V::begin;
    using V::end;
    svector(int n,T ini):V(n*2+1,ini),sz(n){}
    svector(int n):SV(n,T()){}
    svector():V(),sz(0){}
    int size(){return sz;}
    T& operator[](int id){return V::operator[](id+sz);}
    SV& copy(const SV& other){
	V::operator=(other);
	sz=other.sz;
	return (*this);
    }
    SV& operator=(const SV &other){
	return copy(other);
    }
};
// a x + b y = gcd(a, b)
// O(log (a+b) )
LL extgcd(LL a, LL b, LL &x, LL &y) {
  LL g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

// mを法とするaの逆元
// O(log a)
LL invMod(LL a) {
    LL x, y;
    if (extgcd(a, mod, x, y) == 1)return (x + mod) % mod;
    else return 0; // unsolvable
}
// 組み合わせnCk (mod MOD)
// O(n)
LL Comb(LL n,LL k){
	LL u=fact[n];
	LL d=(fact[k]*fact[n-k])%mod;
	return (u*invMod(d))%mod;
}


int main(){
    int N;
    cin>>N;
    vector<int> niku(N),yasai(N);
    int t1=0,t2=0;
    rep(i,N){
	cin>>niku[i]>>yasai[i];
	t1=max(t1,niku[i]);
	t2=max(t2,yasai[i]);
    }
    using SV=svector<LL>;
    svector<SV> dp(t1+1,SV(t2+1,0));
    LL res=0;

    rep(i,N){
	dp[-niku[i]][-yasai[i]]++;
    }
    for(int i=-t1;i<=t1;i++)
	for(int j=-t2;j<=t2;j++)
	    (dp[i][j]+=dp[i][j-1]+dp[i-1][j])%=mod;
    rep(i,N){
	(res+=dp[niku[i]][yasai[i]])%=mod;
    }
    rep(i,N){
	(res+=mod-Comb(niku[i]+niku[i]+yasai[i]+yasai[i],niku[i]+niku[i]))%=mod;
    }
    (res*=r2)%=mod;
    cout<<res<<endl;
    return 0;
}


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

int main() {
	int n; std::cin >> n;
	if ((n & -n) == n) { puts("No"); return 0; }
	puts("Yes");
	for (int i = 1; i < 3; ++ i) printf("%d %d\n", i, i + 1), printf("%d %d\n", i + n, i + n + 1);
	printf("%d %d\n", 3, n + 1);
	for (int i = 4; i < n; i += 2) {
		printf("%d %d\n", i, 1); printf("%d %d\n", i + 1, 1);
		printf("%d %d\n", i + n, i + 1); printf("%d %d\n", i, i + n + 1);
	}
	if (n & 1) return 0;
	int k = 1;
	while (k <= n) k <<= 1; k >>= 1;
	printf("%d %d\n", k ^ 1, n);
	printf("%d %d\n", n ^ k, 2 * n);
	return 0;
}


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

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

  int n,m;cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;

  return 0;
}


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

char lowcmp[26]="abcdefghijklmnopqrstuvwxyz";
char upcmp[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int utoi(char C){return C-'A';}

int main(void){
    int n,k;
    scanf("%d%d",&n,&k);
    char s[n+2];
    scanf("%s",s);
    s[k-1]=lowcmp[utoi(s[k-1])];
    printf("%s\n",s);
    
    
    
    return 0 ;
}


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

signed main(){
  int N;cin>>N;
  vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<i;j++){
      ans+=v[i]*v[j];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int a, b;
   std::cin >> a >> b;
   std::string ss;
   std::cin >> ss;
   bool res = true;
   for(Int i = 0; i < a; ++i)
      res = res and isdigit(ss[i]);
   res = res and ss[a] == '-';
   for(Int i = a + 1; i < a + b + 1; ++i)
      res = res and isdigit(ss[i]);
   puts(res?"Yes":"No");
}


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

#define ll long long
#define endl '\n'
#define pii pair<ll,ll>
#define N 100007
#define mod 1000000007
#define pb push_back;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    ll x;
    cin>>x;
    ll i,cnt=8;
    for(i=0;i<8;i++)
    {
        if(x>=(400+200*i)&&x<=599+(200*i))
        {
            cout<<cnt<<endl;
            break;
        }
        cnt--;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <stack>
#include <stdio.h>
#include <cmath>
using namespace std;
double x[4],y[4];//p,1,2,3
double a[2],b[2],c[2];
void make_line(double x1,double y1,double x2,double y2,int num){
	if(x1!=x2&&y1!=y2){
		a[num]=(y1-y2)/(x1-x2);
		b[num]=-1;
		c[num]=-a[num]*x1+y1;
	}else if(x1==x2){
		a[num]=1;
		b[num]=0;
		c[num]=-x1;
	}else if(y1==y2){
		a[num]=0;
		b[num]=1;
		c[num]=-y1;
	}
	return;
}
int main()
{
	int n;
	cin>>n;
	while(n--){
		bool ans=false;
		cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3];
		make_line(x[0],y[0],x[1],y[1],0);
		make_line(x[2],y[2],x[3],y[3],1);
		if(a[0]==0){
			ans=(a[1]==0);
		}else if(abs((b[0]/a[0])-(b[1]/a[1]))<0.00000001){
			ans=true;
		}
		printf(ans?"YES\n":"NO\n");
	}
    return 0;
}

Measured memory_bytes: 1204
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    W, H, x, y = MI()
    ans = W * H / 2
    has_other = 1 if W / 2 == x and H / 2 == y else 0

    print(ans, has_other)


main()


Measured memory_bytes: 64892
#include<stdio.h>
int G[101][101];
int V[101];
void tree(int n){
int i, j, k=1, A[100], cost, min, sum=0;
     
  A[0] = 0;
  V[0] = 1;
  for(i = 1; i < n; i++){
    V[i] = 0;
  }
  while(1){
    cost = 9999;
    for(i = 0; i < k; i++){
      for(j = 0; j < n; j++){
    if(G[A[i]][j] < cost && G[A[i]][j] != -1 && V[j] != 1){
      cost = G[A[i]][j];
      min = j;
    }
      }
    }
    if(k != n){
      A[k] = min;
      V[min] = 1;
      sum += cost;
      k++;
    }
    else break;
  }
  printf("%d\n", sum);
}



   
main(){
  int n, i, j;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &G[i][j]);
    }
  }
     tree(n);
  return 0;
}
   

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, M; scanf("%d %d", &N, &M);
  vector<int> freqs(N + 5, 0);
  int a, b;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &a, &b);
    if (a == 1) { ++freqs[b]; }
    if (b == N) { ++freqs[a]; }
  }
  bool ok = false;
  for (int i = 0; i < N + 5; ++i) {
    if (freqs[i] >= 2) {
      ok = true;
      break;
    }
  }
  printf("%s\n", ok ? "POSSIBLE" : "IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll a, b;
    cin >> a >> b;
    
    if(a > b) {
        out(a-1);
    }
    else {
        out(a);
    }

    re0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
	string s;
	cin>>s;
	rep(i,0,s.size()-1)
	{
		if(s[i]=='?') s[i]='D';
	}
	int x=0;
	rep(i,0,s.size()-2)
	{
		if(s[i]=='P'&&s[i+1]=='D') x+=1;
	}
	rep(i,0,s.size()-1)
	{
		if(s[i]=='D') x+=1;
	}
	cout<<s;

}

Measured memory_bytes: 3736
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  ll X,	K, D;
  cin>>X>>K>>D;
  X = abs(X);
  ll a = X/D;
  ll ans = 0;
  if(a >= K) {
    ans = X - D*K;
  } else {
    ans = X - D*a;
    ll rem = K - a;
    //cout << a << " " << rem << " " << ans << endl;                                  
    if(rem % 2LL != 0) {
      ans = abs(ans - D);
      //cout << a << " " << rem << " " << ans << endl;                                
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  vector<long long> c(26);
  for (char d : s) {
    ++c[d - 'a'];
  }
  long long ans = (long long) s.size() * (s.size() - 1) / 2 + 1;
  for (int i = 0; i < 26; ++i) {
    ans -= c[i] * (c[i] - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

// https://github.com/drken1215/algorithm/blob/master/DP/inversion_number.cpp
template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

template<class T> long long inversion_number(const vector<T> &a) {
    int n = (int)a.size();
    vector<T> b = a;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    
    long long res = 0;
    BIT<int> bit(n);
    for (int i = 0; i < n; ++i) {
        int order = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
        ++order;
        res += bit.sum(order+1, n+1);
        bit.add(order, 1);
    }
    return res;
}

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

    string s;
    cin >> s;

    vector< vector<int> > v;
    vector<int> now;
    rep(i, s.size()){
        if(s[i] == 'A'){
            now.emplace_back(1);
        }else if(i < i_len - 1 && s[i] == 'B' && s[i + 1] == 'C'){
            now.emplace_back(0);
            ++i;
        }else{
            v.emplace_back(now);
            now.clear();
        }
    }
    v.emplace_back(now);

    lint ans = 0;
    rep(i, v.size()){
        ans += inversion_number(v[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8516
import numpy as np
import numba

@numba.njit("i8(i8,i8,i8)", cache=True)
def pow_numba(a, r, mod):
    r %= (mod-1)
    res = 1
    while r:
        if r%2:
            res = res * a % mod
        a = a * a % mod
        r //= 2
    return res

@numba.njit("UniTuple(i8,3)(i8,i8)", cache=True)
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

@numba.njit("UniTuple(i8[:],2)(i8,i8)", cache=True)
def get_table(mod, n_max):
    f = 1
    fac = [f]
    for i in range(1, n_max+1):
        f = f * i % mod
        fac.append(f)
    #f = egcd(f, mod)[1] % mod
    f = pow_numba(f, -1, mod)
    facinv = [f]
    for i in range(n_max, 0, -1):
        f = f * i % mod
        facinv.append(f)
    facinv.reverse()
    return np.array(fac), np.array(facinv)

@numba.njit("i8(i8,i8)", cache=True)
def solve(K, N):
    mod = 10**9+7
    fac, facinv = get_table(mod, 2020202)
    ans = 0
    for i in range(K+1):
        a = fac[N+K-1-i] * facinv[N-1] % mod * facinv[K-i] % mod
        a = a * pow_numba(25, K-i, mod) % mod * pow_numba(26, i, mod) % mod
        ans += a
    return ans % mod

K = int(input())
S = input()
N = len(S)
print(solve(K, N))


Measured memory_bytes: 156196
x, y, a, b, c = [int(t) for t in input().split()]
p = [int(t) for t in input().split()]
q = [int(t) for t in input().split()]
r = [int(t) for t in input().split()]

s = []
p.sort(reverse=True)
p = p[:x]

q.sort(reverse=True)
q = q[:y]

s = p + q + r
s.sort(reverse=True)
s = s[:x+y]
print(sum(s))

Measured memory_bytes: 23644
n = map(int, input().split())
h = input().split()
h = [int(i) for i in h]

c = 0

if len(h)==1:
    print(1)
else:
    m = h[0]
    for i in h:
        if i>=m:
            c += 1
            m = i

    print(c)



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

int main(){
	int n;
	cin >> n;
	vector<int>a(n);
	long long int ans = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		ans += a[i];
	}
	cout << ans - n << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int x[n],y[n];
    for(int i = 0; i < n; i++){
        cin >> x[i];
        y[i] = x[i];
    }
    sort(y,y+n);
    int m1 = y[n/2-1], m2 = y[n/2];
    for(int i = 0; i < n; i++){
        if(x[i] <= m1) cout << m2 << endl;
        else if(x[i] >= m2) cout << m1 << endl;
    }


}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const long long  int INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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 (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"

class UnionFind{
public:
	vector<int> par;	// par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
	vector<int> rank;	//ランク
	vector<ll> diff_weight;

	UnionFind(int N=1,int SUM_UNITY=0){
		par.resize(N),	rank.resize(N),	diff_weight.resize(N);
		for (int i = 0; i < N; ++i) par[i] = i,rank[i]=0,diff_weight[i]=SUM_UNITY;
	}
	int root(int x){// データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if(par[x]==x)return x;
		else{
			int r=root(par[x]);
			diff_weight[x]+=diff_weight[par[x]];	//累積和を取る
			return par[x]=r;
		}
	};

	bool issame(int x,int y){
		return(root(x)==root(y));
	};

	// weight(ry)-weight(rx)=wとなるようにmergeする
	bool merge(int x,int y,int w){
		w+=weight(x);		//rootとの重み差分を補正
		w-=weight(y);
		int rx = root(x); 	//xの根をrx
		int ry = root(y); 	//yの根をry
		if (rx == ry) return false; //xとyの根が同じ(=同じ木にある)時はそのまま
		if(rank[rx]<rank[ry])	swap(rx, ry),w=-w;// rank[rx] >= rank[ry] となるように rx と ry を swap (それに合わせて w も符号反転します)
		if (rank[rx] == rank[ry]) ++rank[rx];// y (のroot) を x (のroot) の下にくっつける
		par[ry] = rx; 		//xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		diff_weight[ry]=w;	// x が y の親になるので、x と y の差分を diff_weight[y] に記録
		return true;
	}
	ll weight(int x){
		root(x);	//経路圧縮
		return diff_weight[x];
	}
	int diff(int x,int y){
		return weight(y)-weight(x);
	}
};

void Main()
{
	ll N,M;
	ll result=0;
	string S;
	cin>>N>>M;
	ll l,r,d;
	UnionFind uni(N);
	REP(i, M)
	{
		cin >> l>>r>>d;
		l--,r--;
		if(uni.issame(l,r)&&uni.diff(l,r)!=d){
				COUT("No");
				return;
		}
		else{
			uni.merge(l,r,d);
		}
	}
	COUT("Yes");
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


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

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    ans += v - i - 1;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)));
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

typedef long  LL;

int N;
int A[100010];
LL dp[100010];
int x;

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		scanf("%d" , A + i);
	}
	dp[0] = A[0] - 1;
	x = 2;
	repp(i,1,N){
		dp[i] = dp[i - 1] + (A[i] - 1) / x;
		if(A[i] == x) ++x;
	}
	printf("%lld\n" , dp[N - 1]);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  string S;

  cin >> S;

  if((S == "AAA")||(S =="BBB" )){
    cout << "No" << endl;
  }

  else{
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

ll gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    while(y > 0) {
        ll tmp = x % y;
        x = y;
        y = tmp;
    }
    return x;
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

int main() {
    int n;
    cin >> n;
    ll ans = 1;
    rep(i, 0, n) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	cout << (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0] ? "YES" : "NO") << endl;

	return 0;
}


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

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=2e5+10, maxm=5e4+10, lg=21, mod=1e9+7, inf=1e18;

ll n,a[maxn];
bool check(ll d){
	map<ll,ll> mp;
	for(int i=1;i<n;i++){
		if(a[i]>a[i-1]) continue;
		if(d==1) return 0;
		ll r=a[i];
		while(mp[r]==d-1) mp[r--]=0;
		if(r==0) return 0;
		mp[r]++;
		mp.erase(mp.upper_bound(r),mp.end());
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	ll l=0,r=n,mid;
	while(r-l>1){
		mid=(l+r)/2;
		(check(mid) ? r:l)=mid;
	}
	cout<<r;
	
	return 0;
}






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

using namespace std;

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

int main(){
    int n,r,p,c; //r?????????????????°???p????????£?????????????????????????????????????????????c????????£???????????????????????°
    
    while(cin >> n >> r && n!=0 && r != 0){
        int cards[n];
        
        rep(i,n) cards[i] = n-i;
    
        //???????????£?????°
        rep(i,r){
            cin >> p >> c;
            rotate(cards, cards+p-1, cards+p-1+c);
            //rotate(??????????????????????????????,?????¢??°,??¨????????????????????????) *(start<=?<end)??????????????????+????????¨?????¢??°???-1?????????
        }
        
        cout << cards[0] << endl;
    }
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1000000000+7;
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
ll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans.sz+1;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol(const vector<int>& v1, 
               const vector<int>& v2){ 
 return v1[0] < v2[0]; } 

 ll sumdegit(ll n)
 {
 	ll sum=0;
 	while(n>0)
 	{
 		sum+=(n%10);
 		n/=10; 	}
 		return sum;
 }

void solve()
{
	ll n;
	cin>>n;
	cout<<(ceil1(n,1000)*1000)-n;
	return;
}  
int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> w(n);
	int total = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		total += w[i];
	}
	long long d = 100000000;
	for (int i = 0; i < n; i++) {
		int s1 = 0;
		for (int j = 0; j < i; j++) {
			s1 += w[j];
		}
		int s2 = total - s1;
		d = (d < abs(s1 - s2)) ? d : abs(s1 - s2);
	}
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list( map(int, input().split()) )


for i in range(N): A[i] -= i
A.sort()

ans = b = 0
if N%2 == 1: b = A[N//2]
else: b = (A[N//2-1]+A[N//2]) // 2
for a in A:
        ans += abs( a-b )
print(ans)

Measured memory_bytes: 26708
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int a,b,c; cin >>a>>b>>c;

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



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

int main(){
    string s, t;
    cin >> s >> t;
    bool ans = true;
    vector<int> ab1(26, -1), ab2(26, -1);

    for(int i = 0; i < s.size(); i++){
        int num = s[i] - 'a';
        if(ab1[num] >= 0){
            if(t[i] != t[ab1[num]]){
                ans = false;
                break;
            }
        }
        ab1[num] = i;

        num = t[i] - 'a';
        if(ab2[num] >= 0){
            if(s[i] != s[ab2[num]]){
                ans = false;
                break;
            }
        }
        ab2[num] = i;
    }

    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int a = 0;  //TopCoDeerがpを出した回数
    rep(i, n) {
        if(s[i] == 'p') {
            a++;
        }
    }

    cout << n/2 - a;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e17;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

vl dijkstra(int s, const vector< vector<pll> > &g){
  ll n = g.size();
  vl d(n, INF); d[s] = 0;
  priority_queue< pll, vector<pll>, greater<pll> > q;
  q.em( pll(0,s) );

  while(not q.empty()){
    pll p = q.top(); q.pop();
    ll cost = p.first, v = p.second;
    if(d[v] < cost) continue;

    for(pll e : g[v]){
      ll ncost = cost + e.first, u = e.second;
      if(d[u] > ncost){
        d[u] = ncost;
        q.em( pll(ncost, u) );
      }
    }
  }
  return d;
}

int main(){
  ll n, m, r, q;
  cin >> n >> m >> r >> q;
  vector< vector<pll> > g(n+r);
  rep(i,m){
    ll a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    g[b].eb( MP(c,a) );
  }
  rep(i,n) g[n+i%r].eb( MP(0,i) );

  vector<vl> d(r);
  rep(i,r) d[i] = dijkstra(n+i, g);

  ll ans = 0;
  rep(i,q){
    int x,y,z;
    cin >> x >> y >> z;
    x--; y--;

    ll cost = INF;
    rep(j,r) chmin(cost, d[j][x] + d[j][y]);
    ans += max(0LL, z - cost);
  }
  cout << ans << endl;
}

Measured memory_bytes: 18164
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
#define MAX 100000

int main()
{
	char n[3];
	char total[3];
	int count = 0;
	for (int i = 0; i < 3; i++)
	{
		cin>>n[i];
	}
	
	for (int i = 0; i < 3; i++)
	{
		total[i] = n[2 - i];
	}

	for (int i = 0; i < 3; i++)
	{
		if (total[i] == n[i])
		{
			count++;
		}
	}
	
	if (count == 3)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n, sb = 0, sc = 0, a[101], b[101], c[101];
	for (int i = 0; i < 101; i++) {
		b[i] = 0;
		c[i] = 0;
	}
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) {
			b[i] = 1;
			if (a[i] % 3 == 0||a[i]%5==0) {
				c[i] = 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		sb = sb + b[i];
		sc = sc + c[i];
	}
	if (sb == sc) {
		printf("APPROVED");
	}
	else {
		printf("DENIED");
	}
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct State{
  int score;
  int backpos;
  State(int sc,int bp){
    score=sc;
    backpos=bp;
  }
};

bool isnum(char c){
  return '0'<=c&&c<='9';
}

int strtoi(std::string s){
  int result=0;
  for(int i=0;i<s.size();i++){
    result+=(s[i]-'0')*std::pow(10,s.size()-i-1);
  }
  return result;
}

State Base(std::string s,int frontpos){
  int persepoint=frontpos+1;
  std::string numstr;
  while(isnum(s[persepoint])){
    numstr+=s[persepoint];
    persepoint++;
  }

  int result=strtoi(numstr);


  return State(result,persepoint);
}

State Formula(std::string s, int frontpos){
  State result(0,0);
  if(isnum(s[frontpos+2])){
    //baseが続く
    std::vector<int> vote;
    int persepoint=frontpos+1;
    while(1){
      State state=Base(s,persepoint);
      vote.push_back(state.score/2+1);
      persepoint=state.backpos+1;
      if(s[persepoint]!='[') break;

    }
    std::sort(vote.begin(), vote.end());
    for(int i=0;i<vote.size()/2+1;i++){
      result.score+=vote[i];
    }
    result.backpos=persepoint;
    return result;

  }else{
    std::vector<int> vote;
    int persepoint=frontpos+1;
    while(1){
      State state=Formula(s,persepoint);
      vote.push_back(state.score);
      persepoint=state.backpos+1;
      if(s[persepoint]!='[') break;
    }
    std::sort(vote.begin(), vote.end());
    for(int i=0;i<vote.size()/2+1;i++){
      result.score+=vote[i];
    }
    result.backpos=persepoint;
    return result;
  }
}

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

  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    std::string s;
    cin>>s;
    cout<<Formula(s,0).score<<endl;
  }

  return 0;
}



Measured memory_bytes: 3448
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
    int a = s[0] - '0';
    int b = s[1] - '0';
    int c = s[2] - '0';
    int d = s[3] - '0';
    string answer = "";

      if(a+b+c+d == 7)
      {
        answer=a.ToString()+"+"+b.ToString()+"+"+c.ToString()+"+"+d.ToString()+"=7";
      }
      if(a+b+c-d == 7)
      {
        answer=a.ToString()+"+"+b.ToString()+"+"+c.ToString()+"-"+d.ToString()+"=7";
      }
      if(a+b-c+d == 7)
      {
        answer=a.ToString()+"+"+b.ToString()+"-"+c.ToString()+"+"+d.ToString()+"=7";
      }
      if(a+b-c-d == 7)
      {
        answer=a.ToString()+"+"+b.ToString()+"-"+c.ToString()+"-"+d.ToString()+"=7";
      }
      if(a-b+c+d == 7)
      {
        answer=a.ToString()+"-"+b.ToString()+"+"+c.ToString()+"+"+d.ToString()+"=7";
      }
      if(a-b+c-d == 7)
      {
        answer=a.ToString()+"-"+b.ToString()+"+"+c.ToString()+"-"+d.ToString()+"=7";
      }
      if(a-b-c+d == 7)
      {
        answer=a.ToString()+"-"+b.ToString()+"-"+c.ToString()+"+"+d.ToString()+"=7";
      }
      if(a-b-c-d == 7)
      {
        answer=a.ToString()+"-"+b.ToString()+"-"+c.ToString()+"-"+d.ToString()+"=7";
      }
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF = 1000000000000000;

int main(){
  int n;
  std::cin >> n;
  std::vector<pair<int,int>> v(n);

  REP(i,n){
    std::cin >> v[i].first;
    v[i].second = i+1;
  }

  sort(ALL(v));

  REP(i,n){
    std::cout << v[i].second << " ";
  }
  std::cout << '\n';
}


Measured memory_bytes: 1536
//In the name of 'ALLAH'//
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x , y , z ;
    cin >> x >> y >> z ;
    set<int> s;
    for(int i=0;i<3;i++)
    {
        s.insert(x);
        s.insert(y);
        s.insert(z);

    }
    cout<<s.size()<<endl;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int a[114514];
int main(){
	int n,k,s;
	cin>>n>>k>>s;
	for(int i=1;i<=k;++i) a[i]=s;
	for(int i=k+1;i<=n;++i) a[i]=(s==1e9?s-1:s+1);
	for(int i=1;i<=n;++i)cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 3984
import sys
from statistics import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
xxx = na()
r = median_high(xxx)
l = median_low(xxx)
for i in range(n):
    if xxx[i] <= l:
        print(r)
    elif xxx[i] >= r:
        print(l)

Measured memory_bytes: 27200
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  string s;
  int K;
  cin >> s;
  cin >> K;
  
  vector <string> subs;
  
  for(int i=0; i<s.size(); i++){
    for(int j=1; j<=K; j++){
      if(i+j > s.size())
	continue;
      else
	subs.push_back(s.substr(i, j));
    }
  }


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

  subs.erase(unique(subs.begin(), subs.end()), subs.end());
  
  cout << subs[K-1] << endl;
  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define INF 200000000
using namespace std;
typedef pair<int, int> P;
struct line {
  int to,time,cost;
};

vector<line> L[1000];
int costv[1000];
int timev[1000];

void mincost(int from,int to) {
  priority_queue<P, vector<P>, greater<P> > que;
  for(int i=0;i<1000;i++) {
    costv[i] = INF;
  }
  costv[from] = 0;
  que.push(P(0,from));
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if(costv[v] < p.first) continue;
    for(unsigned int i=0;i < L[v].size();i++) {
      line l = L[v][i];
      if(costv[l.to] > costv[v] + l.cost) {
	costv[l.to] = costv[v] + l.cost;
	que.push(P(costv[l.to], l.to));
      }
    }
  }
  cout << costv[to] << endl;
}

void mintime(int from,int to) {
  priority_queue<P, vector<P>, greater<P> > que;
  for(int i=0;i<1000;i++) {
    timev[i] = INF;
  }
  timev[from] = 0;
  que.push(P(0,from));
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if(timev[v] < p.first) continue;
    for(unsigned int i=0;i < L[v].size();i++) {
      line l = L[v][i];
      if(timev[l.to] > timev[v] + l.time) {
	timev[l.to] = timev[v] + l.time;
	que.push(P(timev[l.to], l.to));
      }
    }
  }
  cout << timev[to] << endl;
}

int main() {
  int n,m,k;
  while(cin >> n >> m) {
    if(n==0&&m==0)break;
    for(int i=0;i<1000;i++) {
      L[i].clear();
    }
    for(int i=0;i<n;i++) { //input line
      line temp;
      int f,t,ti,co;
      cin >> f >> t >> co >> ti;
      temp.to = t;
      temp.time = ti;
      temp.cost = co;
      L[f].push_back(temp);
      temp.to = f;
      L[t].push_back(temp);
    }

    cin >> k;
    for(int i=0;i<k;i++) {
      int p,q,r;
      cin >> p >> q >> r;
      if(r == 0)
	mincost(p,q);
      else
	mintime(p,q);
    }
  }
}

Measured memory_bytes: 1020