akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
// const int MOD = 1000000007;
const int MOD = 998244353;
struct mint {
   ll x;
   mint(ll x = 0) { (this->x = (x + MOD)) %= MOD; }
   mint& operator+=(const mint a) {
      if ((this->x += a.x) >= MOD) x -= MOD;
      return *this;
   }
   mint& operator-=(const mint a) {
      if ((this->x += MOD - a.x) >= MOD) this->x -= MOD;
      return *this;
   }
   mint& operator*=(const mint a) {
      (this->x *= a.x) %= MOD;
      return *this;
   }
   mint operator+(const mint a) const {
      mint res(*this);
      return res += a;
   }
   mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
   }
   mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
   }
   mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
   }
   mint inv() const { return pow(MOD - 2); }
   mint& operator/=(const mint a) { return *this *= a.inv(); }
   mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
   }
};
struct combination {
   vector<mint> fact, ifact;
   combination(int n) : fact(n + 1), ifact(n + 1) {
      assert(n < MOD);
      fact[0] = 1;
      for (int i = 1; i <= n; ++i)
         fact[i] = fact[i - 1] * i;
      ifact[n] = fact[n].inv();
      for (int i = n; i >= 1; --i)
         ifact[i - 1] = ifact[i] * i;
   }
   mint operator()(int n, int k) {
      if (k < 0 || k > n) return 0;
      return fact[n] * ifact[k] * ifact[n - k];
   }
} comb(200005);
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n, m, k;
   cin >> n >> m >> k;
   mint ans = 0;
   mint col = m;
   rrep(x, n - 1, 0) {
      mint now = col;
      now *= comb(n - 1, x);
      if (x <= k) ans += now;
      col *= m - 1;
   }
   cout << ans.x << endl;
   return 0;
}

Measured memory_bytes: 6220
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())

x, y = (B[0], 0) if A[0] > B[0] else (A[0], B[0] - A[0])
A[1], x = (A[1] - y, x + y) if A[1] > y else (0, x + A[1])
for i in range(1, n):
    x, y = (x + B[i], 0) if A[i] > B[i] else (x + A[i], B[i] - A[i])
    A[i+1], x = (A[i+1] - y, x + y) if A[i+1] > y else (0, x + A[i+1])
print(x)

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

int main() {
  int X, Y;
  cin >> X >> Y;

  string ans = "No";
  rep(i, X + 1) {
    if (2 * i + 4 * (X - i) == Y) {
      ans = "Yes";
    };
  }

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


Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	//static long[] a;
	static	int N ;
	static	int M ;
	static long[][] dp;
	static int ans = 100000000;
	static	boolean[] flag ;

	public static void main(String[] args) {


		Scanner s = new Scanner(System.in);			//文字の入力
		N = s.nextInt();
		M = s.nextInt();
		ArrayList<Bridge> graph = new ArrayList<Bridge>();
		boolean[] num = new boolean[50];

		for(int i = 1;i < N+1;i++){
			Bridge bridge = new Bridge(i);
			graph.add(bridge);
		}


		for(int i = 0;i < M;i++){				//グラフ作成
			int a = s.nextInt();
			int b = s.nextInt();


			//すでにその町を作ってある時
			for(int j = 0;j < graph.size();j++){

				if(graph.get(j).p == a){				//町を探す
					graph.get(j).addtown(b);				//町に隣接する町を加える
				}
			}
			for(int j = 0;j < graph.size();j++){
				if(graph.get(j).p == b){				//さっきと逆方向にも繋げる
					graph.get(j).addtown(a);				
				}

			}
		}


		int ans = 0;


		for(int i = 0;i < graph.size();i++){

			if(graph.get(i).townnum() == 1){				//隣接する町が一つなら、その町は橋になるのでグラフから消去
				ans++;
				int deletetown = graph.get(i).p;				//削除する町
				graph.remove(i);

				i = -1;									//削除した後に、隣接する町が一つになる町も出てくる可能性があるのでiをリセットする。
				for(int j = 0;j < graph.size();j++){			//全ての町について、削除する町とつながってる町を探す
					ArrayList<Integer> judge = graph.get(j).town;

					for(int k = 0;k < judge.size();k++){				//つながっている辺を削除
						if(judge.get(k) == deletetown){

							judge.remove(k);
							break;
						}
					}
				}
			}
		}

		System.out.println(ans);





	}

}
class Bridge{
	int p;			//自分の場所
	ArrayList<Integer> town = new ArrayList<Integer>();				//辺でつながっている町
	public Bridge(int n) {
		p = n;
	}
	void addtown(int t){
		town.add(t);
	}

	int townnum(){
		return town.size();
	}





}




Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define vll vector<long long>
#define mll map<long long,long long>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define pb push_back
#define prll pair<long long,long long>
typedef long long ll;
typedef long double ld;
#define rep(i,a,n)   for(ll i=a; i<n; i++)
#define rrep(i,a,n)  for(ll i=n-1; i>=a; i--)
typedef map<string,ll> msl;
#define mx 100001
ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll revrsno(ll n){
    ll k=0;
    vll z;
    while(n>0){
        z.pb(n%10);
        n/=10;
    }
    rep(i,0,z.size()) k=k*10+z[i];
    return k;
}
bool isPrime(ll n){
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
bool isPowerOfTwo(ll n) { 
   if(n==0) 
   return false; 
   return (ceil(log2(n)) == floor(log2(n))); 
}
ll Totfun(ll n){
    ll z=n;
    if(n%2==0){
        while(n%2==0){
            n/=2;
        }
        z/=2;
    }
    for(ll i=3;i<=sqrt(n);i+=2){
        if(isPrime(i)&&n%i==0){
          while(n%i==0){
            n/=i;
          }
        z-=z/i;  
        }
    }
    if(n>1){
        z-=z/n;
    }
    return z;
}
ll maxPrimeFactor(ll n) { 
    ll maxPrime=-1; 
    while(n%2==0){
        maxPrime=2; 
        n>>=1; 
    } 
    for (ll i=3;i<=sqrt(n);i+=2) { 
        while(n%i==0){ 
            maxPrime=i; 
            n=n/i; 
        } 
    } 
    if (n>2) maxPrime=n; 
    return maxPrime; 
} 
/*
vll a[mx];
ll l[mx],d[mx];
void dfs(ll x,ll y){
   l[x]=1; d[x]=y;
   for(ll i:a[x])
   if(!l[i])
   dfs(i,y+1);
}
void bfs(ll x){
    queue<ll> q;
    q.push(x);
    l[x]=1;
    d[x]=0;
    while(!q.empty()){
        ll cur=q.front();
        q.pop();
        for(ll i : a[cur]){
            if(1-l[i]){
                q.push(i);
                d[i]=d[cur]+1;
                l[i]=1;
            }
        }
    }
}
*/
 /*sort(a,a+n);
    ll d=1;
    vll z;
    for(ll i=1;i<n;i++){
    if(a[i]==a[i-1]){
        d++;
    }
    else{
            z.pb(d);
            d=1;
    }
    }
    z.pb(d);*/
int main(){
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);
   cout.tie(NULL);
   ll n,ans=0;
   ld sum=0;
   cin>>n;
   ll a[n];
   rep(i,0,n){
       cin>>a[i];
       sum+=a[i];
   }
   sum/=n;
   sum=round(sum);
   rep(i,0,n) ans+=(a[i]-sum)*(a[i]-sum);
   cout<<ans;
   return 0;
}

Measured memory_bytes: 384
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  var ans = "Yes";
  input = input.trim().split("\n");
  const [N, M] = input[0].split(" ").map((n) => parseInt(n));
  var a = input[1].split(" ").map((n) => parseInt(n));
  a.sort((a, b) => b - a);
  var top = a.slice(0, M);
  const lim = (1 * arrsum(a)) / (4 * M);

  if (top[top.length - 1] < lim) {
    ans = "No";
  }

  function arrsum(arr) {
    return arr.reduce((c, a, i, self) => {
      return c + a;
    });
  }

  //出力
  console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require("fs").readFileSync("./input.txt", "utf-8"));


Measured memory_bytes: 29624
a=[[0]*5 for _ in [0]*(1<<15)]
for i in range(int((1<<15)**.5)+1):
    a[i*i][1]+=1
    for j in range(i*i+1,min(4*i*i+1,1<<15)):
        for k in range(2,5):
            a[j][k]+=a[j-i*i][k-1]
while 1:
    n=int(input())
    if n==0:break
    print(sum(a[n]))

Measured memory_bytes: 12124
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int n,t,a;
	vector<int> v;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		v.clear();
		rep(i,n){
			scanf("%d",&t);
			v.push_back(t);
		}
		//sort(v.begin(),v.end());
		partial_sum(v.begin(),v.end(),v.begin());
		a=v[0];
		rep(i,n){
			reps(j,0,i){
				t=v[i];
				if(j!=i)t-=v[j];
				a=max(a,t);
			}
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
//#define INF (1 <<29)
const int INF = int(100 * 100 * (1e5 + 1));
//const int INF = 1 << 29;
int N, M, R;
int d[201][201];
int r[8];
int min_cost = INF;
//int min_cost = INF;

void dfs(int from_idx, int dist, int used) {

    if (used == (1 << R) - 1) {
        min_cost = min(min_cost, dist);
        return;
    }

    for (int to_idx = 0; to_idx < R; ++to_idx) if (!(used >> to_idx & 1)) {
        if (dist == -1) {
            dfs(to_idx, 0, used | 1 << to_idx);
        } else {
            dfs(to_idx, dist + d[r[from_idx]][r[to_idx]], used | 1 << to_idx);
        }
    }
}


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

    cin >> N >> M >> R;

    for (int i = 1; i <= N; ++i) {
        fill(d[i] + 1, d[i] + N + 1, min_cost);
        d[i][i] = 0;
    }
    for (int i = 0; i < R; ++i) {
        cin >> r[i];
    }
    int a, b, c;
    for (int i = 0; i < M; ++i) {
        cin >> a >> b >> c;
        if (d[a][b] > c) d[a][b] = d[b][a] = c;
    }
    for (int k = 1; k <= N; ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    dfs(0, -1, 0);

    cout << min_cost << '\n';

    return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;

namespace arc084_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(a);
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(b);
            int[] c = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(c);
            long[] bcount = new long[n];
            int x;
            for (x = 0; x < n && a[x] < b[0]; x++) ;
            bcount[0] = x;
            for (int i = 1; i < n; i++)
            {
                long j;
                for (j = bcount[i - 1]; j < n && a[j] < b[i]; j++) ;
                bcount[i] = j;
            }
            long[] ccount = new long[n]; long[] cret = new long[n];
            long sum = 0;
            for (x = 0; x < n && b[x] < c[0]; x++) sum += bcount[x];
            ccount[0] = x; cret[0] = sum;
            for (int i = 1; i < n; i++)
            {
                long j;
                for (j = ccount[i - 1]; j < n && b[j] < c[i]; j++) sum += bcount[j];
                ccount[i] = j; cret[i] = sum;
            }
            long ret = 0;
            for (int i = 0; i < n; i++) ret += cret[i];
            Console.WriteLine(cret.Sum());
        }
    }
}

Measured memory_bytes: 42312
#include <algorithm>
#include <iostream>
#include <string>

int main()
{
    std::string S;
    std::string a = "";
    int Q = 0;
    std::cin >> S >> Q;

    int T, F;
    char C;

    bool flip = false;

    for (int i = 0; i < Q; ++i) {
        std::cin >> T;
        if (T == 1) {
            flip = !flip;
        } else if (T == 2) {
            std::cin >> F >> C;
            if ((!flip && (F == 1)) || (flip && (F == 2))) {
                a += C;
            } else {
                S += C;
            }
        }
    }

    if (flip) {
        std::reverse(S.begin(), S.end());
        std::cout << (S + a);
    } else {
        if (a != "") {
            std::reverse(a.begin(), a.end());
        }
        std::cout << (a + S);
    }


    return 0;
}

Measured memory_bytes: 1248
def main():
    N = int(input())
    A = list(map(int, input().split()))
    SelectionSort(A, N)

def SelectionSort(A, N):
    count = 0
    
    for i in range(N):
        mini = i
        for j in range(i,N):
            if A[j] < A[mini]:
                mini = j
        if A[i] > A[mini]:
            A[i], A[mini] = A[mini], A[i]
            count += 1
    print(*A)
    print(count)

main()



Measured memory_bytes: 5612
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final PrintStream so = System.out;
    static final Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        int H = ni();
        int W = ni();
        if (H % 3 == 0 || W % 3 == 0) {
            so.println(0);
            return;
        }
        
        so.println(Math.min(solve(H, W), solve(W, H)));
    }
    
    static long solve(long H, long W) {
        long min = Long.MAX_VALUE;
        long S = H*W;
        for (int h = 1; h < H; h++) {
            long S1 = h*W;
            long S2 = W/2 * (H-h);
            long S3 = (S-S1) - S2;
            min = Math.min(maxMinusMin(S1, S2, S3), min);
        }
        
        if (H > 3) {
            long minH = H / 3;
            long maxH = minH + 1;
            min = Math.min(min, (maxH - minH)*W);
        }
        
        return min;
    }
    
    static long maxMinusMin(long a1, long a2, long a3) {
        long max = Math.max(a1, Math.max(a2, a3));
        long min = Math.min(a1, Math.min(a2, a3));
        return max - min;
    }
    
    static int ni() {
        return sc.nextInt();
    }
    
    static long nl() {
        return sc.nextLong();
    }

    static char[] nsToChars() {
        return sc.next().toCharArray();
    }
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	int a, z;
	dec(i, s.size()) { if(s[i] == 'A') { a = i; } }
	inc(i, s.size()) { if(s[i] == 'Z') { z = i; } }
	
	cout << (z - a + 1) << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 100
#define INF 1e9 + 5
#define LINF 1e18 + 5

using namespace std;
using ll = long long;
vector<ll> v;
vector<ll> w;
vector<vector<ll>> memo;

//이 문제에서는 똑같은 백팩 문제인데.. W가 너무 크다. 10^9
//따라서 모든 v에 대한 값을 구하기로 해보자.
ll solve(int n, int k)
{
    if (n < 0)
        return 0;
    ll best = LINF;
    if (memo[n][k] != LINF)
        return memo[n][k];
    if (k - v[n] >= 0)
    {
        best = max(best, solve(n - 1, k - w[n]) + v[n]);
    }
    best = max(best, solve(n - 1, k));

    memo[n][k] = best;
    return best;
}

int main2() //이건 재귀로 어떻게 풀어야할지 모르겠네..;;
{
    int n, W;
    scanf("%d %d", &n, &W);
    v.resize(n + 1);
    w.resize(n + 1);
    int vsum = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d", &w[i], &v[i]);
        vsum += v[i];
    }
    memo.resize(n + 1, vector<ll>(vsum + 1, LINF));

    //solve 는 n번째 물건이고 모든 물건의 가치의 합은 vsum이라고 할때..
    cout << solve(n, vsum);

    return 0;
}
void min_self(ll &a, ll b)
{
    a = min(a, b);
}

int main()
{ //이건 선형으로 푼다.
    int n, W;
    cin >> n >> W;
    //dp[i] i 가 value때 최소의 weight를 구하자.
    v.resize(n + 1);
    w.resize(n + 1);
    int vsum = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d", &w[i], &v[i]);
        vsum += v[i];
    }
    vector<ll> dp(vsum + 1, LINF);
    dp[0]=0;
    for (int item = 0; item < n; item++)
    {
        for (int value_already = vsum - v[item]; value_already >= 0; value_already--)
        {
            min_self(dp[value_already+v[item]], dp[value_already]+ w[item]);
        }
    }
    ll ans = 0;
    for(int i=0;i<=vsum;i++){
        if(dp[i]<=W)
            ans = max(ans, (ll) i);
    }
    cout<<ans;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if (e-a <= k)
		cout << "Yay!\n";
	else
		cout << ":(\n";
	return 0;
}

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

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

    map<int, int> mp;
    rep(i, N) {
        int a;
        cin >> a;
        ++mp[a];
    }

    priority_queue<int, vector<int>, greater<int>> que;
    for (auto p : mp)
        que.push(p.second);

    int ans = 0;
    K = mp.size() - K;

    rep(i, K) ans += que.top(), que.pop();

    cout << ans << endl;

    return 0;
}

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

int f(int a, int b){
    while(1){
        if(a < b) swap(a, b);
        if(!b) break;
        a %= b;
    }
    return a;
}

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

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

    int g = A[0];
    for(int i = 1; i < n; i++){
        g = f(g, A[i]);
    }

    cout << g << endl;



    return 0;
}

Measured memory_bytes: 768
n = int(input())
xy = []
for _ in range(n):
    xy.append(list(map(int, input().split())))

tmp1 = []
tmp2 = []
for i in range(n):
    tmp1.append([xy[i][0]+xy[i][1], xy[i][0], xy[i][1]])
    tmp2.append([xy[i][0]-xy[i][1], xy[i][0], xy[i][1]])
tmp1.sort()
tmp2.sort()

ans = 0

if (tmp1[-1][2]-tmp1[0][2])*(tmp1[-1][1]-tmp1[0][1]) >= 0:
    tmp = tmp1[-1][0]-tmp1[0][0]
    ans = max(tmp, ans)
if (tmp2[-1][2]-tmp2[0][2])*(tmp2[-1][1]-tmp2[0][1]) <= 0:
    tmp = tmp2[-1][0]-tmp2[0][0]
    ans = max(tmp, ans)

print(ans)


Measured memory_bytes: 150592
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const long long MOD=1000000007;
const long long LMOD=998244353;
//const long long LMOD=1000000007;
#define Fi first
#define Se second
#define P2 pair
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define Cb make_pair
#define ll long long
#define Ull unsigned long long
#define Sf scanf
#define Pf printf
#define Pb push_back
#define Psh push
#define Stc stack
#define Vct vector
#define Ret return
#define Re0 return 0z
#define Sz size
#define Is insert
#define Que queue
#define Emp empty
#define Fro front
#define Rv reverse
#define Er erase
#define Bg begin
#define Srt sort
#define Pq priority_queue
#define Ite iterator
int a[1001];
int t[1001];
int main()
{
	int n;
	Sf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		Sf("%d",&a[i]);
	}
	int g=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=i)g++;
	}
	if(g==2||g==0)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
S=input()
flag=0
for i in range(len(S)):
    if i%2==0:
        if not (S[i]=='R' or S[i]=='U' or S[i]=='D'):
            flag=1
    else:
        if not (S[i]=='L' or S[i]=='U' or S[i]=='D'):
            flag=1
if flag==0:
    print('Yes')
else:
    print('No')

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

int main() {
	int H, W, k;
	cin >> H >> W;
	vector<string> a(H);
	for (string& i : a) cin >> i;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			for (k = j; k >= 0; --k) {
				if ('c' == a[i][k]) break;
			}
			if (-1 == k) cout << -1;
			else cout << j - k;
			if (1 + j != W) cout << ' ';
		}
		cout << endl;
	}
}


Measured memory_bytes: 3180
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
struct E {
	int from, to, cost;
};
using G = vector<vector<E>>;
vector<int> p;
G g;
constexpr ll inf = 1e18 + 1;
int n, w;

vector<ll> rec1(const vector<ll> &x, int v, int par) {
	auto a = x;
	for (auto e : g[v]) {
		if (e.to != par) {
			auto tmp = rec1(a, e.to, v);
			REP(i, w + 1 - e.cost) {
				a[i + e.cost] = max(a[i + e.cost], tmp[i]);
			}
		}
	}
	REP(i, w + 1) {
		a[i] += p[v];
	}
	return a;
}
vector<ll> rec0(int v, int par) {
	vector<ll> ret(w + 1, -inf);
	ret[0] = 0;
	vector<ll> z(w + 1, -inf);
	z[0] = 0;
	for (auto &&e : g[v]) {
		if (e.to != par) {
			auto tmp = rec0(e.to, v);
			REP(i, w + 1) {
				ret[i] = max(ret[i], tmp[i]);
			}
			auto tmp1 = rec1(z, e.to, v);
			REP(i, w + 1) {
				ret[i] = max(ret[i], tmp1[i]);
			}
		}
	}
	return ret;
}

int main() {

	cin >> n >> w;
	p.resize(n);
	REP(i, n) cin >> p[i];
	g.resize(n);
	REP(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].push_back(E{a, b, c});
		g[b].push_back(E{b, a, c});
	}
	vector<ll> ans = rec0(0, -1);
	vector<ll> init(w + 1, -inf);
	init[0] = 0;
	vector<ll> ans1 = rec1(init, 0, -1);
	ll res = -inf;
	res = max(res, *max_element(begin(ans), end(ans)));
	res = max(res, *max_element(begin(ans1), end(ans1)));
	cout << res << endl;
}


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

int main() {
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  a.push_back(a[0]+k);
  int l=0;
  for(int i=0;i<n;i++) {
    l = max(l,a[i+1]-a[i]);
  }
  int ans=k-l;
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,n;
	scanf("%d%d",&h,&n);
	while(n--)
	{
		int x;
		scanf("%d",&x);
		h-=x;
	}
	puts(h>0?"No":"Yes");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll X, N;
    cin >> X >> N;

    vector<ll> P(N);
    rep (i, N) { cin >> P[i]; }

    const auto isInclude = [&](ll x)
    {
        for (const auto p : P) { if (p == x) { return true; } }
        return false;
    };

    const auto solve = [&]()
    {
        rep (i, X)
        {
            const ll lhs = X - i;
            const ll rhs = X + i;
            if (!isInclude(lhs)) { return lhs; }
            if (!isInclude(rhs)) { return rhs; }
        }

        return 0LL;
    };

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3632
implicit none
integer,parameter :: PREC=8
integer :: a,b,c,d,e,f
integer :: sol, sugar
integer :: maxsol,maxsug
integer :: waters(30)
integer :: water,water_a
integer :: na,nb,nc,nd,nw
integer :: maxc,maxd
integer :: i,j,k
logical :: flg
real(PREC) :: water_req,conc,maxconc

read *,a,b,c,d,e,f

waters(:) = 0
nw = 0
do_a: do na = 0, 30
   water_a = na * a * 100
   if (water_a > f) then
      exit do_a
   endif
   do_b: do nb = 0, 30
      if (na == 0 .and. nb == 0) then
         cycle do_b
      endif
      water = water_a + nb * b * 100
      if (water > f) then
         cycle do_a
      endif
      flg = .false.
      do_k: do k = 1, nw
         if (water == waters(k)) then
            flg = .true.
            exit do_k
         endif
      enddo do_k
      if (flg) then
         cycle do_b
      endif
      nw = nw + 1
      waters(nw) = water
   enddo do_b
enddo do_a

i = nw
flg = .false.
do while (i > 1 .or. flg)
   i = (i * 10) / 13
   if (i < 1) then
      i = 1
   else if (i == 9 .or. i == 10) then 
      i = 11
   endif
   flg = .false.
   do j = 1, nw-i
      if (waters(j) > waters(j+i)) then
         k = waters(j) 
         waters(j) = waters(j+i)
         waters(j+i) = k
         flg = .true.
      endif
   enddo
enddo

maxc = ceiling(f*e/real(c*(100+e),kind=PREC))
maxd = ceiling(f*e/real(d*(100+e),kind=PREC))

maxconc = 0.0
maxsol = 100*a
maxsug = 0
do nc = 0, maxc
   do nd = 0, maxd
      sugar = nc * c + nd * d
      water_req = sugar / real(e,kind=PREC) * 100.0
      if (water_req > real(f,kind=PREC)) then
         exit
      endif
      water = 0
      do k = 1, nw
         if (water_req <= real(waters(k),kind=PREC)) then
            water = waters(k)
            exit
         endif
      enddo
      if (water == 0) then
         exit
      endif
      
      sol = water + sugar
      if (sol > f) then
         cycle
      endif
      
      conc = 100 * sugar / real(sol,kind=PREC)
      if (conc > maxconc) then
         maxconc = conc
         maxsol = sol
         maxsug = sugar
      endif
   enddo
enddo

print '(i0,1x,i0)',maxsol,maxsug
end

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

int main() {
	string O, E;
	cin >> O >> E;
	for (int i = 0; i < O.size() + E.size(); i++) {
		if (i % 2 == 0) cout << O[i / 2];
		else cout << E[i / 2];
	}
	cout << endl;
}

Measured memory_bytes: 256
import sys

n = int(input())
h = list(map(int, input().split()))

if n == 1:
    print('Yes')
    sys.exit()

cnt = 0
for i in range(n-1):
    if h[i] - h[i+1] == 1:
        cnt += 1
        if cnt == 2:
            print('No')
            sys.exit()
    elif h[i] - h[i+1] > 1:
        print('No')
        sys.exit()
    elif h[i] - h[i+1] < 0:
        cnt = 0

print('Yes')

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

using namespace std;

int cur, mn = 1001;
string s, t;

int main() {
  cin >> s >> t;
  
  for (int i = 0; i < s.size() - t.size() + 1; ++i) {
    cur = 0;
    for (int j = 0; j < t.size(); ++j) {
      if (s[i + j] != t[j])
        ++cur;
    }
    
    mn = min(mn, cur);
  }
  
  cout << mn << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define REP(i,n) for (ll i = 0; i < n; i++)
#define REPR(i,n) for (ll i = n-1; i >= 0; i--)
#define FOR(i,m,n) for (ll i = m; i < n; i++)
#define FORE(x,xs) for (auto& x : xs)
#define ALL(x) x.begin(), x.end()

const int MAX_N = 210;
const int MAX_X = 1e5+10;
const int MOD = 1e9+7;
ll dp[MAX_N][MAX_X];

int N, X;
vi S;

ll dfs (int n, int x) {
    if (dp[n][x] != -1) return dp[n][x];
    if (n==0) return dp[n][x] = x % S[0];
    return dp[n][x] = (n * dfs(n-1, x) + dfs(n-1, x%S[n])) % MOD;
}

int main() {
    cin >> N >> X;
    REP (n, MAX_N) REP (x, MAX_X) dp[n][x] = -1;
    S = vi(N);
    REP (i, N) cin >> S[i];
    sort(ALL(S));

    cout << dfs(N-1, X) << endl;
}

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<pair<ll,ll>> A(N);
  for (auto &p : A) cin >> p.first >> p.second;
  sort(A.begin(), A.end());
  
  ll L = 0;
  for (ll i = 0; i < N; i++) {
    if (L + A[i].second >= K) {
      cout << A[i].first << endl;
      return 0;
    }
    L += A[i].second;
  }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int N; cin >> N;
  vi A(N), B(N), C(N-1);
  REP(i,N) {
    cin >> A[i];
    A[i]--;
  }
  REP(i,N) cin >> B[i];
  REP(i,N-1) cin >> C[i];

  int ans = 0;
  REP(i,N) {
    ans += B[A[i]];
    if (i != 0) {
      if (A[i-1]+1 == A[i]) ans += C[A[i-1]];
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
/*  ex3_4
    Graku   */
#include <stdio.h>
#include <math.h>

int main(void) {
    int num; //declaration
    scanf("%d", &num);

    int flag = 0; //if exist (i, j) s.t. n == i * j, flag == 1, else flag == 0
    for (int i = 1; i <= 9; ++i) { //1 <= i <= 9
        if (flag) { //if already find (i, j) s.t. n == i * j, break
            break;
        }
        for (int j = i; j <= 9; ++j) { //i <= j <= 9, dont have to check (i, j) s.t. i > j
            if (num == i * j) { //if find (i, j) s.t. n == i * j, flag = 1
                flag = 1;
                break;
            }
        }
    }

    if (flag) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}

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

int sx,sy;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int use[1000][1000];
char  state[1000][1000];
int H,W,N;
queue<pair<int,int> > quer;
bool check(int nowx,int nowy){
  return nowx>=0 && nowy>=0 && nowy<H && nowx<W  && use[nowx][nowy]==0 && state[nowx][nowy]!='X';
}
void solve(int nx,int ny)
{

  for(int i=0;i<4;i++){
    if(check(nx+dx[i],ny+dy[i]) && !( nx+dx[i]==sx && ny+dy[i]==sy)){
      quer.push( pair<int, int >(nx+dx[i],ny+dy[i]) );
      use[nx+dx[i]][ny+dy[i]]=use[nx][ny]+1;
    }
    }
  
}
int achieve(int goalNumber){

  solve(sx,sy);
  while(state[quer.front().first][quer.front().second]!=goalNumber+'0'){
    solve(quer.front().first,quer.front().second);

    quer.pop();
  }
  sx=quer.front().first;
  sy=quer.front().second;
  // cout << sx << sy << endl;
  while(!quer.empty()){
    quer.pop();
  }
  /* for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      //cout << use[j][i] ;
      printf("%3d",use[j][i]);
    }
    cout << endl;
    }*/
  // cout << endl;
  return  use[sx][sy];
  //
}

int main(void){

  int sum=0;
  cin >> H >> W >> N;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> state[j][i];
      if(state[j][i] == 'S'){
	sx=j;
	sy=i;
      }
	
    }
  }
  for(int l=1;l<=N;l++){
   
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	use[j][i]= 0;
      }
    }
  
    sum+=achieve(l);
  }
  cout << sum << endl;
}
  

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int fLen(ll a) {
  string aStr = to_string(a);
  return aStr.size();
}
int main() {
  ll n; cin >> n;
  int res = fLen(n);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
		res = min(res, fLen(n / i));
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int main(){

	int n = nxt();
	string s, t;
	cin >> s >> t;
	for (int m = n;; m++) {
		int k = n + n - m;
		if (s.substr(n - k) == t.substr(0, k)) {
			cout << m << "\n";
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
using System;

namespace Math_Functions
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ');
            var a = double.Parse(x[0]);
            var b = double.Parse(x[1]);
            var c = double.Parse(x[2]);

            var t = c * Math.PI / 180;

            Console.Write("{0:F4}\n{1:F4}\n{2:F4}\n",
            (a * b * Math.Sin(t)) / 2,
            a + b + Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(t)),
            b * Math.Sin(t));
        }
    }
}

Measured memory_bytes: 9228
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
K = int(input())
flag = 0
num = 7
for i in range(10**6):
    if num % K == 0:
        print(i+1)
        flag = 1
        break
    num += 7*pow(10,i+1,K)
if flag == 0:
    print(-1)


Measured memory_bytes: 10572
N, W = map(int, input().split())

dp = [[float('inf')]*(10**5+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
  w, v = map(int, input().split())
  for j in range(10**5+1):
    dp[i][j] = dp[i-1][j]
    if j >= v:
      dp[i][j] = min(dp[i][j], dp[i-1][j-v]+w)

ans = 0
for j in range(10**5+1):
  if dp[N][j] <= W:
    ans = max(ans, j)
print(ans)

Measured memory_bytes: 311176
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int K;
  cin >> K;
  string S;
  cin >> S;

  int N = len(S);
  if (N <= K) {
    cout << S << endl;
    return 0;
  }

  cout << S.substr(0, K) << "..." << endl;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,m;
  cin >> n >> m;
  vector<int32> a(n);
  REP(i,n)cin >> a[i];
  sort(a.begin(),a.end());
  vector<int64> asum(n+1,0);
  REP(i,n)asum[i+1] = a[i] + asum[i];
  int32 l = a[0] * 2, r = a[n-1] * 2 + 1;
  while(r - l > 1){
    int32 mid = (l + r) / 2;
    int32 cnt = 0;
    REP(i,n){
      cnt += a.end() - lower_bound(ALL(a),mid-a[i]);
    }
    // cout << mid << " " << cnt << endl;
    if(cnt >= m){
      l = mid;
    }else{
      r = mid;
    }
  }
  int64 ans = 0;
  int32 cnt = 0;
  REP(i,n){
    int32 idx = lower_bound(ALL(a),l-a[i]) - a.begin();
    ans += asum[n] - asum[idx] + (n - idx) * a[i];
    cnt += n-idx;
  }
  ans -= (cnt - m) * l;
  ANS(ans);
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    int K;
    cin >> s >> K;
    int n = s.size();

    VVI dp0(n+1, VI(K+2)), dp1(n+1, VI(K+2));
    dp0[0][0] = 1;
    rep(i,n) rep(j, K+1){
        int nd = s[i] - '0';
        rep(d, 10){
            if (d == 0){
                dp1[i+1][j] += dp1[i][j];
                if (d < nd) dp1[i+1][j] += dp0[i][j];
                if (d == nd) dp0[i+1][j] += dp0[i][j];
            }else {
                if (d <= nd){
                    dp1[i+1][j+1] += dp1[i][j];
                    if (d == nd) dp0[i+1][j+1] += dp0[i][j];
                    else dp1[i+1][j+1] += dp0[i][j];
                }else{
                    dp1[i+1][j+1] += dp1[i][j];
                }
            }
        }
    }
    cout << (dp0[n][K] + dp1[n][K]) << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[30][51000];

int main(){
    ll q;
    cin>> q;
    string s[q],t[q];
    for (ll i=0;i<q;i++){
        cin >> s[i] >> t[i];
    }
    ll dp[1100][1100];
    memset(dp,0,sizeof(dp));
    for (ll i=0;i<q;i++){
        ll dp[1100][1100];
        memset(dp,0,sizeof(dp));
        for (ll j=0;j<s[i].size();j++){
            for (ll k=0;k<t[i].size();k++){
                if (s[i][j]==t[i][k]){
                    dp[j+1][k+1]=dp[j][k]+1;
                }else{
                    dp[j+1][k+1]=max(dp[j][k+1],dp[j+1][k]);
                }
            }
        }
        cout << dp[s[i].size()][t[i].size()] << endl;
    }
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  bool ans=true;
  int n=s.size();
  for(int i=0;i<n;i++){
    if(s[i]=='L'&&i%2==0) ans=false;
    if(s[i]=='R'&&i%2==1) ans=false;
  }
  cout << (ans?"Yes":"No") << endl;
}

Measured memory_bytes: 256
void main(){
	string[] s;
	foreach(_;0..3){
		s ~= readln().chomp();
	}
	( s[0][0].to!string ~ s[1][1].to!string ~ s[2][2].to!string ).writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2780
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Char
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

readIntTriplet :: BS.ByteString -> (Int, Int, Int)
readIntTriplet s = let Just (a, s') = BS.readInt s
                       Just (b, s'') = BS.readInt $ BS.dropWhile isSpace s'
                       Just (c, _) = BS.readInt $ BS.dropWhile isSpace s''
                   in (a, b, c)

main = do
  n <- readLn
  happiness <- V.replicateM n (readIntTriplet <$> BS.getLine)
  let (a,b,c) = V.foldl1' (\(!a,!b,!c) (!a',!b',!c') -> (max b c + a', max a c + b', max a b + c')) happiness
  print (max a (max b c))


Measured memory_bytes: 3452
#include <cstdio>
#include<iostream>
#include <vector>
#include <sstream>
#include <string>
#include <iterator>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector<int> nums;
    vector<int> orig;
    int n;
    cin >> n >> ws;
    string line;
    for (int i = 0; i < n; i++) {
        getline(cin, line);
        stringstream ss(line);
        int ti;
        ss >> ti;
        nums.push_back(ti);
        orig.push_back(ti);
    }
    sort(nums.begin(), nums.end());
    for (int i =  0; i < n; i++) {
        if (orig[i] == nums[n-1]) {
            cout << nums[n-2] << endl;
        } else {
            cout << nums[n-1] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3436
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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

int main()
{

  string s;
  cin >> s;

  if (s <= "2019/04/30")cout<<"Heisei"<<endl;
  else cout<<"TBD"<<endl;

  return 0;
}


Measured memory_bytes: 256
n, y = map(int, input().split())
can = True
c = []
d = []
for i in range(n+1):
    for j in range(n+1-i):
        calc = 10000 * i + 5000 * j + 1000 * (n-i-j)
        d.append(calc)
        if calc == y:
            s = " ".join([str(i), str(j), str(n-i-j)])
            c.append(s)
            can = False
            break
if can:
    s = " ".join([str(-1)]*3)
    print(s)
else:
    print(c[0])

Measured memory_bytes: 82344
#include <bits/stdc++.h>
#define Rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;

//----------------library in this time--------------------------------
template <typename T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <typename T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <typename T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}
//------------------------main function-------------------------------
void Main(){
    u64 a,b,c;
    cin >> a >> b >> c;
    if(a > b + c){
        cout << 0 << endl;
    }else{
        cout << (b + c) - a << endl;
    }
    
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    
    Main();
    return 0;
}


Measured memory_bytes: 256