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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define mp make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front 
#define pb push_back
#define pp push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

ll n, a, b;

int main() {
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>a>>b;
    cout<<n / (a + b) * a + min(a, n % (a + b))<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
int N;
vector<ll> A(300001, 0);
priority_queue<ll, vector<ll>, greater<ll>> fque;
priority_queue<ll> bque;
ll fsum = 0, bsum = 0;
vector<ll> fv, bv;

int main(void){
	
	scanf("%d", &N);
	for(int i = 0; i < 3 * N; ++i) scanf("%lld", &A[i]);
	
	for(int i = 0; i < N; ++i) fque.push(A[i]), fsum += A[i];
	for(int i = 3 * N - 1; i >= 2 * N; --i) bque.push(A[i]), bsum += A[i];
	
	fv.push_back(fsum);
	for(int i = N; i < 2 * N; ++i){
	    fque.push(A[i]);
	    fsum += A[i];
	    fsum -= fque.top(); fque.pop();
	    fv.push_back(fsum);
	}
	
	bv.push_back(bsum);
	for(int i = 2 * N - 1; i >= N; --i){
	    bque.push(A[i]);
	    bsum += A[i];
	    bsum -= bque.top(); bque.pop();
	    bv.push_back(bsum);
	}
    reverse(bv.begin(), bv.end());
    
    ll ans = -LLONG_MAX;
    for(int i = 0; i < fv.size(); ++i) ans = max(ans, fv[i] - bv[i]);
    printf("%lld\n", ans);
    
    return 0;
}

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

void fnInput(vector<int>& rvnNum)
{
  string sNum;
  cin >> sNum;

  for (int i = 0; i < rvnNum.size(); i++)
    rvnNum[i] = sNum[i] - '0';                 // char → int 変換
}

int fnBitFullSch(const vector<int>& cnrvnNum)
{
  for (int nCtl = 0; nCtl < ( 1 << 3 ) - 1; nCtl++)
  {
    int nSum = cnrvnNum[0];
    for (int nEach = 0; nEach < 3; nEach++)
      if (nCtl & ( 1 << nEach )) nSum += cnrvnNum[nEach + 1];
      else                       nSum -= cnrvnNum[nEach + 1];

    if (nSum == 7)  return nCtl;
  }
  return ( 1 << 3 ) - 1;                       // 必ず答えが存在するため
}
    
void fnResult(const vector<int>& cnrvnNum, int nReslt)
{
  cout << cnrvnNum[0];
  for (int nEach = 0; nEach < 3; nEach++)
  {
    if (nReslt & ( 1 << nEach )) cout << "+";
    else                         cout << "-";

    cout << cnrvnNum[nEach + 1];
  }
  cout << "=7" << endl;
}

int main()
{
  vector<int> vnNum(4);
  
  fnInput(vnNum);
  int nReslt = fnBitFullSch(vnNum);
  fnResult(vnNum, nReslt);

  return 0;
}

Measured memory_bytes: 3616
H, W = map(int, input().split())
sL = []
for i in range(H):
    sL.append(input())
dp = [[0] * W for i in range(H)]

for h in range(H):
    for w in range(W):
        if h == 0 and w == 0:
            if sL[0][0] == ".":
                dp[0][0] = 1
            else: # (1.1) is black
                dp[0][0] = 2
        elif h == 0:
            dp[h][w] = dp[h][w-1] + int(sL[h][w] != sL[h][w-1])
        elif w == 0:
            dp[h][w] = dp[h-1][w] + int(sL[h][w] != sL[h-1][w])
        else:
            A = dp[h-1][w] + int(sL[h][w] != sL[h-1][w])
            B = dp[h][w-1] + int(sL[h][w] != sL[h][w-1])
            dp[h][w] = min(A, B)
            
print(dp[H-1][W-1] // 2)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  rep(i,n) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  
  int result = 0;
  for (int i = 0; i < k; i++) {
    result += vec.at(i);
  }
  
  cout << result;
}

Measured memory_bytes: 3632
def resolve():
  S_base = list(input())
  T = list(input())

  if len(T) > len(S_base):
    print("UNRESTORABLE")
    return True

  for i in reversed(range(len(S_base) - len(T) + 1)):
    isMatched = True
    for t in range(len(T)):
      if not (S_base[i + t] == T[t] or S_base[i + t] == "?"):
        isMatched = False
        break
    if isMatched:
      result = "".join(S_base[:i])+"".join(T)+"".join(S_base[i+len(T):])
      print(result.replace("?", "a"))
      return True

  print("UNRESTORABLE")

if __name__ == "__main__":
  resolve()

Measured memory_bytes: 61920
#include<cstdio>
#include<cmath>
int main()
{
    long long int numb,num[10];
    while(scanf("%lld",&numb)!=EOF)
    {
        for(int i=9,w=1;i>=0;i--,w*=10)num[i]=(numb/w)%10;
        for(int i=9;i>0;i--)for(int j=0;j<i;j++)num[j]=(num[j]+num[j+1])%10;printf("%d\n",num[0]);
    }
    return 0;
}

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

using namespace std;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int l,r;
    int sum = 0;

    cin >> N;
    REP(i, N) {
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;

}



Measured memory_bytes: 256
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    int N;
    cin >> N;
    vector<tuple<string, int, int>> T(N);
    for (int i = 0; i < N; ++i) {
        string S;
        int P;
        cin >> S >> P;
        T[i] = make_tuple(S, -P, i + 1);
    }
    sort(T.begin(), T.end());

    for (auto t : T) {
        cout << get<2>(t) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
from heapq import heappop, heappush

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, Z, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    hq = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]

    ans = [0] * K
    added = {(0, 0, 0)}

    for idx in range(K):
        taste, i, j, k = heappop(hq)
        ans[idx] = -taste
        if i < X - 1 and (i + 1, j, k) not in added:
            heappush(hq, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
            added.add((i + 1, j, k))
        if j < Y - 1 and (i, j + 1, k) not in added:
            heappush(hq, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
            added.add((i, j + 1, k))
        if k < Z - 1 and (i, j, k + 1) not in added:
            heappush(hq, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
            added.add((i, j, k + 1))

    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> hi(N);
  for(ll i = 0LL; i < N;i++){
    cin>>hi[i];
  }
  vector<vector<ll>> g(N);
  for(ll i = 0LL; i < M; i++) {
    ll x, y;
    cin >> x >> y;
    g[x-1LL].push_back(y-1LL);
    g[y-1LL].push_back(x-1LL);
  }
  ll ans = 0LL;
  for(ll i = 0LL; i < N; i++){
    bool y = true;
    for(auto j:g[i]){
      if(hi[i]<=hi[j]) {
        y=false;
        break;
      }
    }
    if(y){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9860
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 20;
int n, m, dp[N][N];
char str[N][N];

int main() {
    scanf("%d%d", &n, &m);
    int tot = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%s", str[i] + 1);
        for (int j = 1; j <= m; j++)
            tot += (str[i][j] == '#');
    }
    memset(dp, 0, sizeof(dp));
    if (str[n][m] == '#') dp[n][m] = 1;
    for (int i = n; i >= 1; i--){
        for (int j = m; j >= 1; j--){
            if (str[i][j] == '.') continue;
            dp[i][j] = 1;
            dp[i][j] += max(dp[i + 1][j], dp[i][j + 1]);
        }
    }
    printf("%s\n", dp[1][1] == tot ? "Possible" : "Impossible");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    Fast;
    long long t,n,m,i,j,k,x=0,y=0,z;
    cin>>n;
    map<long long,long long>mp;
    for(i=0;i<n;i++){
        cin>>m;
        mp[m]++;
        if(mp[m]>1){
            x=1;
        }
    }
    if(x==1){
        cout<<"NO"<<endl;
    }
    else{
    cout<<"YES"<<endl;}
}


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

int main(){
  int n,a;cin >> n >> a;
  int h = n%500;
  if(h <= a)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
	int top[3]={0,0,0},cur;
	for (int i = 0; i < 10; i++)
	{
		cin>>cur;
		if(cur>top[0]){
			top[2]=top[1];
			top[1]=top[0];
			top[0]=cur;
		}else if(cur>top[1]){
			top[2]=top[1];
			top[1]=cur;
		}else if(cur>top[2]){
			top[2]=cur;
		}
	}
	cout<<top[0]<<endl;
	cout<<top[1]<<endl;
	cout<<top[2]<<endl;
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        int N=cin.nextInt();
        int[] W=cin.ArrayInt(N,0);
        int sum=0;
        for(int i=0;i<N;i++)sum+=W[i];
        int ans=1000000;
        int sum2=0;
        for(int i=0;i<N;i++)
        {
            sum2+=W[i];
            if(ans>Math.Abs(2*sum2-sum)){ans=Math.Abs(2*sum2-sum);}
        }
        Console.WriteLine(ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define MAXAS(x,v) x = max(x,v)

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

#define PI 3.141592653589793

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	int n, w;
	cin >> n >> w;
	int ws[n], vs[n];
	map<int, int> dp[n + 1];
	dp[0][0] = 0;
	for (size_t i = 0; i < n; i++) {
		cin >> ws[i] >> vs[i];
	}

	for (size_t i = 0; i < n; i++) {
		for (auto const &e: dp[i]) {
			MAXAS(dp[i + 1][e.first], dp[i][e.first]);
			const int nw = ws[i] + e.first;
			const int nv = vs[i] + e.second;
			if (nw <= w) {
				MAXAS(dp[i + 1][nw], nv);
			}
		}
		cin >> ws[i] >> vs[i];
	}

	int m = 0;
	for (auto const &e: dp[n]) {
		MAXAS(m, dp[n][e.first]);
	}
	cout << m << endl;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int maxlong(int x){ //最大の木の長さ(親の数を数える)
      int ans=0;
      int a[x]={};
      rep(i,x){
      a[root(i)]++;
      }
      rep(i,x){chmax(ans,a[i]);}
      return ans;
    }

};

int main() {
  int n,q;
  cin >> n >>q;
  UnionFind tree(n);
  rep(i,q){
    int a,b,c;
    cin >> a >>b >>c;
    if(a==0)tree.unite(b,c);
    if(a==1)cout << tree.same(b,c) << endl;
  }
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define T pair<int, int>
#define ordered_set tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
signed main(){
    fast();
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y); swap(x, z);
    cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

double dp[30][20000];

int main() {
    cout << fixed;
    cout << setprecision(9);
    while (1) {
        int n, m, K;
        cin >> n >> m >> K;
        if (n == 0) {
            break;
        }
        for (int i = 0; i < 30; i++) {
            fill(dp[i], dp[i] + 20000, 0);
        }
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 20000; j++) {
                if (dp[i - 1][j] > 0) {
                    for (int k = 1; k <= m; k++) {
                        dp[i][j + k] += dp[i - 1][j] / (m * 1.0);
                    }
                }
            }
        }
        double ans = 0;
        double one = 0;
        for (int i = 0; i <= K + 1; i++) {
            one += dp[n][i];
        }
        ans += one;
        for (int i = K + 2; i <= n * m; i++) {
            ans += (i - K) * dp[n][i];
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 7916
from collections import defaultdict
from bisect import bisect_left
 
s = input()
t = input()
s_len = len(s)
t_len = len(t)
if not set(t) <= set(s):
  print(-1)
else: 
  idx = defaultdict(list)
  for i in range(s_len):
    idx[s[i]].append(i)
  
  loop_num = 0
  current_position = -1
  for i in range(t_len):
    char = t[i]
    tmp_idx = idx[char]
    n = bisect_left(tmp_idx, current_position+1)
    if n < len(tmp_idx):
      current_position = tmp_idx[n]
    else:
      current_position = tmp_idx[0]
      loop_num += 1
  print(s_len * loop_num + current_position + 1)

Measured memory_bytes: 7924
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;

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

    static class CGoToScool {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Student> studentList = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int ord = in.nextInt();
                studentList.add(new Student(i + 1, ord));
            }
            Collections.sort(studentList, Comparator.comparing(x -> x.order));

            for (int i = 0; i < studentList.size(); i++) {
                out.print(studentList.get(i).index + " ");
            }
        }

        class Student {
            int index;
            int order;

            public Student(int index, int order) {
                this.order = order;
                this.index = index;
            }

        }

    }
}



Measured memory_bytes: 81264
#include <iostream>
#include <vector>

using namespace std;

bool binarySearch(vector<int> vec, int target)
{
	int l = 0;
	int r = vec.size();
	while (l < r)
	{
		int mid = (l + r) / 2;
		if (vec[mid] == target)
		{
			return(true);
		}
		else if (vec[mid] < target)
		{
			l = mid + 1;
		}
		else
		{
			r = mid;
		}
	}
	return(false);
}

void solve()
{
	int n;
	cin >> n;
	vector<int> S(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> S[i];
	}
	int q;
	cin >> q;
	vector<int> T(q);
	for (int i = 0; i < q; ++i)
	{
		cin >> T[i];
	}
	int ans = 0;
	for (int i = 0; i < q; ++i)
	{
		if (binarySearch(S, T[i]))
		{
			++ans;
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 2060
#include<stdio.h>

int main(){
	int x,a,b;
	
	scanf("%d %d %d",&x,&a,&b);
	
	if(x < b - a){
		printf("dangerous\n");
	} else if(a >= b){
		printf("delicious\n");
	} else {
		printf("safe\n");
	}
	return 0;
}

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

using namespace std;



int main()
{

    int n,m,s=0;
    cin>>n>>m;
    while(n--)
    {
        double a,b,c;
        cin>>a>>b;
        c=sqrt(a*a+b*b);
        if(c<=m) s++;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3776
n = int(input())

k = input()
p = 0
r_count = 0
b_count = 0
for l in range(n):
    if str(k[p]) == "R":
        r_count += 1
        p += 1
    elif str(k[p]) == "B":
        b_count += 1
        p += 1
    else:
        pass

if r_count > b_count:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <cstdio>
#include <string>
#include <iostream>
#include <list>

using namespace std;

bool comp( char s, char t){
    if(s=='?' || s==t) return true;
    else return false;
}

int main()
{
    int i,j;
    string s,t;
    string ans;
    list<int> index;
    string tmp;

    //input
    getline(cin,s);
    getline(cin,t);

    //1.入れる場所を検索
    for(i=0;i<s.length();i++){
        //部分比較
        for(j=0;j<t.length();j++){
            if((i+j)>=s.length()) break;
            if(!comp(s[i+j],t[j])) break;
            if(j==t.length()-1) index.push_back(i);
        }
    }

    //2.入れる場所以外の'?'を'a'にした文字列の生成と辞書順最小の検索
    ans = '~';
    for(auto i=index.begin();i!=index.end();i++){
        tmp = s;
        //'?'->'a'
        for(j=0;j<s.length();j++){
            if(tmp[j]=='?') tmp[j]='a';
        }
        tmp.replace(*i, t.length(), t );
        if(ans>=tmp) ans=tmp;
    }
    if(index.size()==0) ans = "UNRESTORABLE";

    //output
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int N;
int sum;
int main()
{
    scanf("%d", &N);
    const int M = N;
    while (true) {
        sum += (N % 10);
        if (N < 10) {
            break;
        }
        N /= 10;
    }
    //    printf("%d:%d\n\n", M, sum);
    if (M % sum == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


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

using ll = long long;
using namespace std;

int main() {
    int n,m;
    cin>>n>>m;
    vector<int> alpha{},beta{};
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        if(a==1) alpha.push_back(b);
        if(b==n) beta.push_back(a);
    }
    sort(alpha.begin(),alpha.end());
    sort(beta.begin(),beta.end());
    int id=0;
    if(beta.size()==0){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    for(int i=0;i<=alpha.size()-1;i++){
        while(beta.at(id)<alpha.at(i)){
            id++;
            if(id==beta.size()){
                cout<<"IMPOSSIBLE"<<endl;
                return 0;
            }
        }
        if(beta.at(id)==alpha.at(i)){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;

}


Measured memory_bytes: 1276
# 148c

from sys import stdin
import fractions

#stdin = open("test/abc148_d_sample-3.in")

N = int(stdin.readline().strip())
a = list(map(int, stdin.readline().strip().split()))

rem = 0
ne = 1
ok = False

for ai in a:
  #print(ne, ai, rem)
  if ai==ne:
    ne += 1
    ok = True
  else:
    rem += 1

if ok:
  print(rem)
else:
  print("-1")


Measured memory_bytes: 27104
n,k = gets.split.map &:to_i
h = gets.split.map &:to_i

INF = 10**12
dp = Array.new(n,INF)
dp[0] = 0

1.upto(n-1) do |i|
  min = 10000000001
  t = i - k
  t = 0 if t < 0
  t.upto(i-1) do |j|
    cost = (h[i] - h[j]).abs + dp[j]
    min = cost if min > cost
  end
  dp[i] = min
end

puts dp[-1]

## 備忘録として他の方のコードを提出させていただきます

Measured memory_bytes: 8836
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    a, v = map(int, input().split())
    b, w = map(int, input().split())
    t = int(input())

    if v == w:
        print('NO')
        exit()

    if a <= b:
        if 0 < ((b - a) / (v - w)) <= t:
            print('YES')
        else:
            print('NO')
    else:
        if 0 < ((b - a) / (w - v)) <= t:
            print('YES')
        else:
            print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9052
N,M = [int(i) for i in input().split()]
if N >= M:
    print(0)
else:
    koma = sorted(list(map(int, input().split())))
    kaisa = []
    for i in range(M-1):
        kaisa.append(koma[i+1] - koma[i])
    kaisa.sort()
    ans = 0
    for i in range(M-N):
        ans += kaisa[i]
    print(ans)

Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n,m;
while(cin>>l>>m>>n){
int x[l+1]={0};j=0;k=0;
for(i=0;i<n;i++){
    cin>>j;
    x[j]++;
}
for(i=1;i<=l;i++){
        n-=x[i];
    if(m>n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
n+=x[i];
}
} return 0;
}


Measured memory_bytes: 1024
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


#n = ip()                              #入力整数1つ
a,b= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
if b/a == b//a:
    print(b+a)
else :print(b-a)

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

int main(){
    string S;
    cin >> S;
    if(S == "SUN"){
        cout << 7 << endl;
    }
    else if(S == "MON"){
        cout << 6 << endl;
    }
    else if(S == "TUE"){
        cout << 5 << endl;
    }
    else if(S == "WED"){
        cout << 4 << endl;
    }
    else if(S == "THU"){
        cout << 3 << endl;
    }
    else if(S == "FRI"){
        cout << 2 << endl;
    }
    else if(S == "SAT"){
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#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;

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

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

    vector<int> l(c);
    rep(i, c){
        cin >> l[i];
    }

    vector< P > v(n);
    rep(i, n){
        cin >> v[i].second >> v[i].first;
        --v[i].second;
    }
    SORT_INV(v);

    int ans = 0;
    for(int i = 0 ; i < n && m > 0 ; ++i){
        if(l[v[i].second] > 0){
            --l[v[i].second];
            --m;
            ans += v[i].first;
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007

typedef long long ll;
int main() {
  int in;
  int count = 0;
  float out;
  
  scanf("%d", &in);
  for(int i = 1; i <= in; i++) {
    if(i % 2 == 1) count++;
  }
  out = (float)count/in;
  printf("%f\n", out);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

//void linearSearch(int);

int main (){ 

  int n,q,i,j,count=0;
  int S[100000];
  int T[50000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);  
  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
  }
  for(j=0;j<q;j++){
    if(T[j]<S[(n/2)]){
      for(i=0;i<(n/2);i++){
	if(T[j]==S[i]){ 
	  count++;
	  break;
	}
      }
    }
    else{
      for(i=(n/2);i<n;i++){
	if(T[j]==S[i]){
	  count++;
	  break;
	}
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	string s;cin>>s;
	int n = s.length();
	if(n%2==0){
		bool flag = true;
		for(int i=0;i<n;i++){
			if(i%2==0){
				if(s[i]!='h'){
					flag = false; break;
				}
			}
			else{
				if(s[i]!='i'){
					flag = false; break;
				}
			}
		}
		if(flag==true){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	else{
		cout<<"No"<<endl;
	}
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, x, y;
vector<int>v[100000];
bool vis[100000];

int dfs(int x) {
	vis[x] = true;
	int t = 0;
	for (int i : v[x]) {
		if (!vis[i]) {
			t ^= dfs(i);
		}
	}
	return t + 1;
}

int main() {
	cin >> N;
	for (int i = 1; i < N; ++i) {
		cin >> x >> y;
		--x;
		--y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	if (dfs(0) == 1) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 100005;
#define M 998244353
#define double long double
#define BINF 10000000000001
#define MAXN 500005
#define init(arr,val) memset(arr,val,sizeof(arr))
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;



#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);


    int n;
    cin >> n;
    if(n < 1){
        cout << 0 << endl;
    }
    int ans = 0;
    for(int i = 2; i * i <= n; i++){
        int c = 0;
        if(n % i == 0){
            while(n % i == 0){
                n /= i;
                c++;
            }
            //cout << i << ' ' << c << endl;
            int id = 1;
            while(c - id >= 0){
                ans++;
                c -= id;
                id++;
            }
        }
    }

    //deb(n)
    //deb(ans)




    if(n > 1) ans++;
    cout << ans << endl;
    
return 0;
}


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

using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin >> n >> x;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<vector<ll> > mins(n, vector<ll>(n));
    for(int i = 0; i < n; i++){
        mins[i][0] = a[i];
    }
    for(int start = 0; start < n; start++){
        for(int len = 1; len + start < n; len++){
            mins[start][len] = min(mins[start][len-1], a[start+len]);
        }
    }
    ll ans = LINF;
    for(int i = 0; i < n; i++){
        ll temp = x * i;
        for(int j = 0; j < n; j++){
            if(j - i >= 0) temp += mins[j-i][i];
            else temp += min(mins[0][j], mins[n + j - i][i - j - 1]);
        }
        //cout << temp << endl;
        ans = min(ans, temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n=s.size();
    int a,z;
    rep(i,n){
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    for(int j=n-1;j>=0;j--){
        if(s[j]=='Z'){
            z=j;
            break;
        }
    }
    cout << z-a+1 << endl;
    return 0;
}

Measured memory_bytes: 720
/*
 * @Author: Kaustav Vats  
 */
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;


class Main {

    public static void PrintIntArray(int[] Arr) {
        for (int i=0; i<Arr.length; i++) {
            System.out.print(Arr[i] + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) throws IOException{
        Reader.init(System.in);
        long A = Reader.nextLong();
        long B = Reader.nextLong();
        if ((A+B) % 2 == 0) {
            System.out.println((A + B)/2);
        }
        else {
            System.out.println("IMPOSSIBLE");
        }
    }
}


/** Class for buffered reading int and double values */
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
	
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int main()
{
    int x, a;

    cin >> x >> a;

    if(x < a){
        cout << 0;
    }
    else{
        cout << 10;
    }

    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

#define N 110000
vector<int> g[N];
int n;
int d[N];

void dfs(int u){
	for(auto &&v: g[u]){
		if(d[v]>=0) continue;
		d[v] = d[u]+1;
		dfs(v);
	}
}

vector<int> f(int u1, int u2){
	vector<int> r;
	r.reserve(n);
	int u = g[u1][0], uu = u1;
	r.pb(1);
	int p = 2;
	while(u>=0){
		int cnt = g[u].size()-2, v = -1;
		for(auto &&w: g[u]){
			if(w!=uu&&g[w].size()>=2) v = w;
		}
		rep(i, cnt) r.pb(p+1+i);
		r.pb(p);
		p += cnt+1;
		uu = u;
		u = v;
	}
	r.pb(p);
	return r;
}

int main(){
	INIT;
	cin>>n;
	if(n==2){
		cout<<"1 2"<<endl;
		return 0;
	}
	rep(i, n-1){
		int u, v;
		cin>>u>>v;
		u--; v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	int u1 = 0, u2 = 0;
	mset(d, -1);
	d[0] = 0;
	dfs(0);
	rep(i, n) if(d[i]>d[u1]) u1 = i;
	mset(d, -1);
	d[u1] = 0;
	dfs(u1);
	rep(i, n) if(d[i]>d[u2]) u2 = i;
	vector<int> r1 = f(u1, u2), r2 = f(u2, u1);
	if(r1.size()<n){
		cout<<-1<<endl;
		return 0;
	}
	if(r1>r2) r1.swap(r2);
	cout<<r1<<endl;
	return 0;
}


Measured memory_bytes: 10880
<?php
list($n, $m) = ints();
$w[] = 0;
$v[] = 0;
for($i = 0; $i < $n; $i++)list($w[], $v[]) = ints();
$mv = array_sum($v)+1;
$dp = array_fill(0,$n+1,array_fill(0, $mv, 10**10));
$dp[0][0] = 0;
for($i = 1; $i <= $n; ++$i){
    $vi = $v[$i];
    $wi = $w[$i];
    $dp0 = $dp[$i-1];
    $dp1 = &$dp[$i];
    $dp1 = $dp0;
    for($j = 0; $j < $mv; ++$j){
        if($j-$v[$i] >= 0)chmin($dp1[$j], $dp0[$j-$vi] + $wi);
    }
}
$max = 0;
for($j = 0; $j < $mv; ++$j){
    if($dp[$n][$j] <= $m){
        chmax($max, $j);
    }
}
echo $max;


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 651768
import fractions

ABK = list(map(int,input().split()))
LCM = ABK[0] * ABK[1] // fractions.gcd(ABK[0],ABK[1])
count = 0

while count < ABK[2]:
    if ABK[0] % LCM == 0:
        if ABK[1] % LCM == 0:
            count = count + 1
    if count != ABK[2]:
        LCM = LCM - 1

print(LCM)


Measured memory_bytes: 5048
// https://atcoder.jp/contests/abc176/tasks/abc176_e
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> row(H), col(W);
    vector<pair<int, int>> v(M);
    REP(i, M) {
        int r, c;
        cin >> r >> c;
        r--, c--;
        row[r]++;
        col[c]++;
        v[i] = {r, c};
    }
    sort(ALL(v));
    // v.erase(unique(ALL(v)), v.end());

    vector<int> R, C;
    int maxr = -1, maxc = -1;
    REP(i, H) {
        if (row[i] > maxr)
            maxr = row[i], R.clear(), R.push_back(i);
        else if (row[i] == maxr)
            R.push_back(i);
    }
    REP(i, W) {
        if (col[i] > maxc)
            maxc = col[i], C.clear(), C.push_back(i);
        else if (col[i] == maxc)
            C.push_back(i);
    }
    // 爆弾の数が最大の行と列に爆弾があるか確認
    for (auto &r : R) {
        for (auto &c : C) {
            if (!binary_search(ALL(v), make_pair(r, c))) {
                cout << maxr + maxc << endl;
                return;
            }
        }
    }
    cout << maxr + maxc - 1 << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

int main() {
  string s, t, ans = "No";
  cin >> s >> t;
  
  for (int i = 0; i < s.size(); ++i) {
    string rotate_s = s.substr(s.size() - i, i) + s.substr(0, s.size() - i);
    if (rotate_s == t) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3600
import sys
input=lambda :sys.stdin.readline().rstrip()

def num2alpha(num):
    if num<=26:
        return chr(96+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(122)
    else:
        return num2alpha(num//26)+chr(96+num%26)

n = int(input())
print(num2alpha(n))

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;


int main(){

  int n;cin>>n;
  int b[n+10];rep(i,0,n-1)cin>>b[i];

  ll ans=b[0];
  rep(i,0,n-2){
    ans+=min(b[i],b[i+1]);
  }
  ans+=b[n-2];
  out(ans);

  return 0;
}


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

res = 0
for i in range(N):
    res += B[A[i]-1]
    if i > 0:
        if A[i]-1 == A[i-1]:
            res += C[A[i-1]-1]

print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define ALL(x)	(x).begin(), (x).end()
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7,N=1000010;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;cin>>n;
	int a,b,c;cin>>a>>b>>c;
	int A=a,B=b,C=c;
	rep(i,1,n){
		cin>>a>>b>>c;
		int A1=max(a+B,a+C);
		int B1=max(b+A,b+C);
		int C1=max(c+A,c+B);
		A=A1;
		B=B1;
		C=C1;
		//cout<<A<<" "<<B<<" "<<C<<"\n";
	}
	cout<<max(A,max(B,C))<<"\n";
return 0;
}


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
   int a, b;
   cin >> a >> b;
   int n = stoi(to_string(a) + to_string(b));
   auto s = int(sqrt(n));
   cout << (s * s == n ? "Yes\n" : "No\n");
}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  vector<int> b(n);
  rep(i, n) cin >> b.at(i);
  vector<int> c(n);
  rep(i, n) cin >> c.at(i);
  sort(ALL(a)); sort(ALL(b)); sort(ALL(c));

  ll ans = 0;
  for(auto bb : b){
    int an = lower_bound(ALL(a), bb) - a.begin();
    int cn = c.end() - upper_bound(ALL(c), bb);
    ans += (ll)an*cn;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    string s;
    string t;
    cin >> s;
    cin >> t;
    int N=s.size();
    s+=s; //sの長さを二倍にしておく
    vector<int> v[50];
    for(int i=0;i<s.size();i++){
        v[s[i]-'a'].push_back(i); //sにおける各アルファベットのindexを追加
    }
    long long ans=0;
    int ind=0;
    int cnt=0;
    for(int i=0;i<t.size();i++){
        if(v[t[i]-'a'].size()==0){
            cout << -1 << endl;
            return 0;
        }
        int tmp=*lower_bound(v[t[i]-'a'].begin(),v[t[i]-'a'].end(),ind)+1;
        if(tmp>=N){
            ans+=N;
            tmp-=N;
        }
        ind=tmp;
    }
    ans+=ind;
    cout << ans << endl;

}

Measured memory_bytes: 1784