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

int     main() {
        int N, C;
        cin >>N >>C;
        vector<vector<int>> D(C+1, vector<int> (C+1, 0));
        vector<vector<int>> c(N+1, vector<int> (N+1, 0));
        for (int i=1; i<=C; i++)
                for (int j=1; j<=C; j++)
                        cin >>D.at(i).at(j);
        for (int i=1; i<=N; i++)
                for (int j=1; j<=N; j++)
                        cin >>c.at(i).at(j);
        vector<vector<int>> CN(3, vector<int> (C+1, 0));
        for (int i=1; i<=N; i++)
                for (int j=1; j<=N; j++)
                        CN.at((i+j)%3).at(c.at(i).at(j))++;
        long S=500*500*1000;
        for (int C0=1; C0<=C; C0++) {
                long S0=0;
                for (int i=1; i<=C; i++)
                        S0 += D.at(i).at(C0)*CN.at(0).at(i);
                if (S<=S0) continue;
                for (int C1=1; C1<=C; C1++) {
                        if (C0==C1) continue;
                        long S1=0;
                        for (int i=1; i<=C; i++)
                                S1 += D.at(i).at(C1)*CN.at(1).at(i);
                        if (S<=S0+S1) continue;
                        for (int C2=1; C2<=C; C2++) {
                                if (C0==C2) continue;
                                if (C1==C2) continue;
                                long S2=0;
                                for (int i=1; i<=C; i++)
                                        S2 += D.at(i).at(C2)*CN.at(2).at(i);
                                S = min(S, S0+S1+S2);
                        }
                }
        }
        cout <<S <<endl;
        return 0;
};

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    int n, k; cin >> n >> k;
    ll ans = 0;
    for(int b = k+1; b <= n; b++) {
        ans += (((n+1)/b)*(b-k) + max(((n+1)%b)-k, 0));
        if(k == 0) ans--;
    }
    cout << ans << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans[26];
  for (int i=0; i<26; i++) {
    ans[i] = 50;
  }
  for (int i=0; i<n; i++) {
    string tmp;
    cin >> tmp;
    int cnt[26];
    for (int j=0; j<26; j++) {
      cnt[j] = 0;
    }
    for (int j=0; j<tmp.length(); j++) {
      cnt[tmp[j] - 'a']++;
    }
    for (int j=0; j<26; j++) {
      ans[j] = min(ans[j], cnt[j]);
    }
  }
  for (int i=0; i<26; i++) {
    for (int j=0; j<ans[i]; j++) {
      char tmp = 'a' + i;
      cout << tmp;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n,a,b;
  cin >> n >> a >> b;
  vl x(n);
  rep(i,n) cin  >> x[i];
  ll ans=0;
  rep(i,n-1){
    ans+=min(a*(x[i+1]-x[i]),b);
  }
  cout << ans << endl;
  
}


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

constexpr int lim = 1000;
int cb[lim+1][lim+1], cw[lim+1][lim+1];
int n, k;

void modify(int& x, int& y, int& c){
  c = ((x/k + y/k) % 2)? 1-c: c;
  x %= k;
  y %= k;
}

void init(int* xx, int* yy, int* c){
  REP(i, n){
    if(c[i]) cb[yy[i]+1][xx[i]+1]++;
    else cw[yy[i]+1][xx[i]+1]++;
  }
  
  REP(y, k+1)REP(x, k){
    cb[y][x+1] += cb[y][x];
    cw[y][x+1] += cw[y][x];
  }

  REP(y, k)REP(x, k+1){
    cb[y+1][x] += cb[y][x];
    cw[y+1][x] += cw[y][x];
  }
}

int solve(){
  int ans = 0;
  REP(y, k+1)REP(x, k+1){
    int b = cb[k][k] - cb[y][k] - cb[k][x] + 2*cb[y][x];
    int w = cw[y][k] + cw[k][x] - 2*cw[y][x];

    int bb = cb[y][k] + cb[k][x] - 2*cb[y][x];
    int ww = cw[k][k] - cw[y][k] - cw[k][x] + 2*cw[y][x];

    ans = max(ans, max(b+w, bb+ww));
  }
  return ans;
}

int main(){
  cin >> n >> k;
  int x[n], y[n], c[n];
  REP(i, n){
    char color;
    cin >> x[i] >> y[i] >> color;
    c[i] = (color == 'B')? 1: 0;
    
    modify(x[i], y[i], c[i]);
  }

  init(x, y, c);
  
  cout << solve() << endl;

  return 0;
}


Measured memory_bytes: 9216
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define pb push_back
using ll = long long;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){

  int A = 0;//tap
  int B = 0;//needs
  int ans=0;
  int sock=1;

  cin >> A >> B;

  

  /*mod = B % A;
  if(mod == 0){
    ans = B/A;
  }else{
    ans = B-mod;
    ans = (ans/A)+1;
  }*/
  while(sock < B){
    sock = sock + (A-1);
    ans++;
  }
  cout << ans <<endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,y;
	cin>>n>>y;
	/*for(int a=0;a<=y/10000;a++)
		for(int b=0;b<=y/5000;b++)
			for(int c=0;c<=y/1000;c++)
			{
				if(a*10000+b*5000+c*1000==y&&a+b+c==n)
				{
					cout<<a<<' '<<b<<' '<<c<<endl;
					return 0;
				}
			}
			
	cout<<-1<<' '<<-1<<' '<<-1<<endl;*///Çî¾Ù³¬Ê± 
	for(int a=0;a<=y/10000;a++)
		for(int b=0;b<=y/5000;b++)
			{
				int c=n-a-b;
				if(c>=0&&a*10000+b*5000+c*1000==y)
				{
					cout<<a<<' '<<b<<' '<<c<<endl;
					return 0;
				}
			}
			
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n,l;
    vector<string>moji;
    string buf;
    cin >> n >> l;
    for (int i = 0; i < n; ++i) {
        cin >> buf;
        moji.push_back(buf);
    }
    sort(moji.begin(),moji.end());
    for (int j = 0; j < n; ++j) {
        cout << moji[j];
    }
    cout << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  VI a(s.size());
  VI b(2019);
  int mem = 0;
  int t10mod = 1;
  rep(i, (int)s.size()) {
    mem = ((s.at(i) - '0') * t10mod + mem) % 2019;
    b.at(mem) += 1;
    t10mod = (t10mod * 10) % 2019;
  }
  ll sum = 0;
  rep(i, 2019) { sum += (ll)b.at(i) * (b.at(i) - 1) / 2; }
  sum += b.at(0);
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
typedef long long ll;

const int N = 1e5;

int arr[N], memo[N], n;

int dp() {
	memo[1] = abs(arr[0] - arr[1]);
	for(int i = 2; i < n; ++i)
		memo[i] = min(abs(arr[i] - arr[i - 2]) + memo[i - 2], abs(arr[i] - arr[i - 1]) + memo[i - 1]);
	return memo[n - 1];
}

int main() {
    Data_Nerd

	scanf("%d", &n);

    for(int i = 0; i < n; ++i)
    	scanf("%d", arr + i);

    cout << dp();

    return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())

info_list = []

for i in range(m):
    pi, yi = map(int, input().split())
    info_list.append([i+1, pi, yi])
# print(info_list)

from operator import itemgetter
info_list.sort(key = itemgetter(2))
# print(info_list)


xth = [1 for i in range(1, n+1)]
# print(xth)

for info in info_list:
    info.append(str(info[1]).zfill((6)) + str(xth[info[1]-1]).zfill(6))
    xth[info[1]-1]+=1


info_list.sort(key = itemgetter(0))

for ele in info_list:
    print(ele[3])

Measured memory_bytes: 35028
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 1000
//<<fixed << setprecision(9)

ll EE(ll a, ll b, ll *x, ll *y)
{
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = EE(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll inverse(ll a, ll m)
{
    ll x,y;
    EE(a,m,&x,&y);
    if(x<0) x += m;
    return x;
}

ll choose(ll n,ll k)
{
	ll i;
	ll num=1,den=1;
	for(i=2;i<=k;i++)
	{
		den*=i;
		den%=mod;
	}
	for(i=n-k+1;i<=n;i++)
	{
		num*=i;
		num%=mod;
	}
	
	i=num*inverse(den,mod);
	i%=mod;
	return i;
}

int main()
{
    int n,i,j,t,a;
    boost;
    int m,k;
    cin>>n>>m>>k;

    ll ans=0,temp;
    rep(i,1,n)
    {
        temp= (ll)(n-i)*(n-i+1)/2;
        temp%=mod;
        temp*=((ll)m*m)%mod;
        temp%=mod;
        ans+=temp;
        ans%=mod;
    }
    swap(n,m);
    rep(i,1,n)
    {
        temp= (ll)(n-i)*(n-i+1)/2;
        temp%=mod;
        temp*=((ll)m*m)%mod;
        temp%=mod;
        ans+=temp;
        ans%=mod;
    }
    ans*=choose((ll)n*m-2,k-2);
    ans%=mod;
    cout<<ans;
    return 0;
}



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

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
template <typename T> void IN(T& t){ cin >> t; }
template <typename T, typename ... U> void IN(T& t, U& ... u){ IN(t); IN(u ...); }
template <typename T> void OUT(T t){ cout << t; }
template <typename T, typename ... U> void OUT(T t, U ... u){ OUT(t); OUT(u ...); }
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define ROF(i,b,a) for(int i=b; i>=a; --i)
using LL = long long;
using pii = pair<int,int>;
const int INF = 2e9;
const int NN = 1e5 + 3;

string s;
vector<int> adj[NN];

int32_t main(){ FAST;
	IN(s);
	int n = size(s);
	bool possible = true;
	FOR(i,0,n-2) if(!(s[i] == s[n-2-i])) possible = false;
	if(!(s[0] == '1')) possible = false;
	if(!(s[n-1] == '0')) possible = false;

	if(!possible){
		OUT(-1, "\n");
		return 0;
	}

	OUT(1, " ", 2, "\n");
	reverse(all(s));
	int cur = 2;
	while(cur <= n-1){
		int nxt = cur+1;
		while(!(s[nxt-1] == '1')) ++nxt;
		FOR(i,cur+1,nxt) OUT(cur, " ", i, "\n");
		cur = nxt;
	}
}

Measured memory_bytes: 3920
n, m, k = map(int, input().split())
mod = 998244353


fac = [1] * n
finv = [1] * n
inv = [1] * n


def COMinit():
    for i in range(2, n):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def COM(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


COMinit()
ans = 0
for i in range(k+1):
    ans = (ans + COM(n-1, i) * m * pow(m-1, n-i-1, mod)) % mod
print(ans)


Measured memory_bytes: 32576
//organize and stay in moment
//Abhinav - IIITA
//I love you Disha
#include<bits/stdc++.h>
using namespace std;
#define int long long 
bool poss[100005];
int wei[100005];	// for what minimum weight this value is possible
int32_t main(){
	// we cannot do dp on w cause of constraints 
	// but can do the same on val 
	int n,w; cin>>n>>w;
	int we[n],val[n];
	for(int i=0;i<n;++i)
		cin>>we[i]>>val[i];
	poss[0]=true;
	wei[0]=0;
	for(int i=1;i<100005;++i)
		wei[i]=LLONG_MAX;
	for(int i=0;i<n;++i){
		for(int j=100004;j>=0;--j){ // just reverse the loop and you get the knapsack when multiple values are alllowed
			if(j<val[i])
				break;
			if(poss[j-val[i]] && wei[j-val[i]]+we[i]<=w){
				poss[j]=true;
				wei[j]=min(wei[j],wei[j-val[i]]+we[i]);
			}
		}
	}
	for(int j=100005;j>=0;--j){
		if(poss[j]){
			cout<<j;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 1152
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;


__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}


int main()
{
	int n, m, q;
	
	cin >> n >> m >> q;

	// ２次累積和
	ll a[510][510];

	memset(a, 0, sizeof(a));

	rep(i, m)
	{
		int l, r;
		cin >> l >> r;
		a[l][r]++;
	}

	for(int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			a[i][j] += a[i][j-1];
		}
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			a[i][j] += a[i-1][j];
		}
	}

	/*
	cout << endl;
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	*/

	rep(i, q)
	{
		int lq, rq;
		cin >> lq >> rq;
		cout << a[rq][rq] - a[rq][lq-1] - a[lq-1][rq] + a[lq-1][lq-1] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 2944
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new AOJ1611().doIt();
	}
	class AOJ1611{
		void doIt(){
			while(true) {
				int n = sc.nextInt();
				if(n == 0)break;
				int w[] = new int [n];
				for(int i = 0;i < n;i++)w[i] = sc.nextInt();
				int dp[][] = new int[n][n];
				for(int W = 2;W < n+1;W++) {
					for(int i = 0;i < n;i++) {
						int j = i+W-1;
						if(j >= n) break;
						if(dp[i+1][j-1] == W-2 && Math.abs(w[i] - w[j]) <= 1) dp[i][j] = W;
						for(int k = i;k < j;k++) {
							dp[i][j] = Math.max(dp[i][j], dp[i][k] + dp[k+1][j]);
						}
					}
				}
				
//				for(int i = 0;i < n;i++) {
//					for(int j = 0;j < n;j++) {
//						System.out.print(dp[i][j]+" ");
//					}
//					System.out.println();
//				}
				System.out.println(dp[0][n-1]);
			}
		}
	}
}



Measured memory_bytes: 58016
import sys
 
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline().strip()
def main():
    N,Q = map(int,input().split())
    K = [[] for _ in range(N+1)]
    nums = [0 for _ in range(N+1)]

    for _ in range(N-1):
        a,b = map(int,input().split())
        K[a].append(b)
        K[b].append(a)

    for _ in range(Q):
        p, x = map(int, input().split())
        nums[p] += x

    def dfs(now,parent):
        for i in K[now]:
            if i != parent:
                nums[i] += nums[now]
                dfs(i,now)

    dfs(1,0)
    print(*nums[1:])

if __name__ == '__main__':
    main()

Measured memory_bytes: 268428
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

ll fact[1000001];

ll modpow(ll a, ll x){
	ll res = 1;
	while(x > 0){
		if (x & 1) res=res*a%MOD;
		a = a*a%MOD;
		x >>= 1;
	}
	return res;
}

ll factinv(ll r){
	return modpow(fact[r], MOD - 2);
}

ll comb(ll n, ll r){
	return (fact[n]*factinv(r)%MOD)*factinv(n-r)%MOD;
}


int main(){
	int x, y;
	cin >> x >> y;
	if ((x+y)%3 || max(x, y) > min(x, y)*2){
		cout << 0 << endl;
		return 0;
	}
	fact[0] = 1;
	for (int i = 1; i <= 1000000; i++) fact[i] = fact[i-1]*i%MOD;
	cout << comb((x+y)/3, min(x, y)-(x+y)/3) << endl;
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>

using namespace std;

static const int MAX = 200000;

int main() {
	int R[MAX], n;

	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> R[i];

	int maxv = R[1] - R[0];
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		if (maxv < R[i] - minv)
			maxv = R[i] - minv;
		if (minv > R[i])
			minv = R[i];
	}

	cout << maxv << endl;
}


Measured memory_bytes: 3860
local function getpattern(n, patall, idx)
  local used = {}
  local retary = {}
  local div = patall
  for i = 1, n do used[i] = false end
  for i = n, 1, -1 do
    div = div // i
    local v_idx = idx // div
    idx = idx % div
    local tmp_idx = 0
    for j = 1, n do
      if not used[j] then
        if tmp_idx == v_idx then
          table.insert(retary, j)
          used[j] = true
          break
        else
          tmp_idx = tmp_idx + 1
        end
      end
    end
  end
  return retary
end

local n, m = io.read("*n", "*n")
local edge = {}
for i = 1, n do
  edge[i] = {}
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  edge[a][b], edge[b][a] = true, true
end

local tot = 1
local ret = 0
for i = 1, n do tot = tot * i end
for i = 0, tot - 1 do
  local z = getpattern(n, tot, i)
  local v = true
  for j = 1, n - 1 do
    if not edge[z[j]][z[j + 1]] then
      v = false
      break
    end
  end
  if z[1] == 1 and v then ret = ret + 1 end
end
print(ret)


Measured memory_bytes: 888
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<double> A;


  return A * 2.0 * 3.1415926535897932;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



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

using namespace std;

const int MAX = 100005;
int a[MAX];

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

    #ifdef FUN
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif // FUN

    int n;
    cin >> n;

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

    int dir = 0, ans = 0;
    for(int i = 0; i < n-1; i++) {
        if(dir == 0) {
            if(a[i] == a[i+1]) continue;
            if(a[i] < a[i+1]) dir = 1;
            else dir = -1;
        } else if(dir == -1 && a[i] < a[i+1]) dir = 0, ans++;
        else if(dir == 1 && a[i] > a[i+1]) dir = 0, ans++;
    }

    cout << ans+1 << endl;
}



Measured memory_bytes: 640
import bisect

N,M = list(map(int, input().split()))
As = list(map(int, input().split()))

As.sort()

#print(As)

for _ in range(M):
    discount = As.pop(-1)

    if(discount == 0):
        break

    discount //= 2

    i = bisect.bisect_left(As, discount)
    As.insert(i, discount)
#    print(As)

print(sum(As))

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


int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l=0,m,n,p,x,y,sum=0,cnt=0,diff;
    long double aa=0.0,bb;
    cin>>n;
    long long int A[n];
    cout<<setprecision(10);
    for(i=0;i<n;i++)
    {
        cin>>A[i];
    }
    sort(A,A+n);
    bb=A[0]*1.0000000;
    for(i=1;i<n;i++)
    {
        bb=(bb+A[i])*1.0000;
        bb=bb/2;
    }
    cout<<bb<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,ss,sp,cheak=1;
  char s[101],p[101],temp[2];
  scanf("%s",&s);
  scanf("%s",&p);
  ss=strlen(s);
  sp=strlen(p);
  for(i=0;i<ss;i++){
    if(memcmp(s,p,sp)==0){
      cheak=0;break;
    }
    temp[0]=s[0]; 
    s[ss]=temp[0];
    for(j=0;j<ss;j++){
      s[j]=s[j+1];
    }
  }
  if(cheak==0)printf("Yes\n");
  else printf("No\n");
  return(0);
}

Measured memory_bytes: 532
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>

using namespace std;

int m, n;
bool people[21][21];
int d[21];

void Solution()
{
    cin>>m>>n;
    
    for (int i = 0; i < n; i++)
    {
        int x, y;
        
        cin>>x>>y;
        
        x--, y--;
        
        people[y][x] = true;
        d[y]++;
    }
    
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (d[j] == 0)
            {
                d[j] = -1;
                
                cout << j + 1 << endl;
                
                for (int k = 0; k < m; k++)
                {
                    if (people[k][j])
                    {
                        people[k][j] = false;
                        d[k]--;
                    }
                }
            }
        }
    }
    
}

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

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
ll l, r, mins=inf;
	
int main(){
	IOS
	cin >> l >> r;
	if(r-l>=2019){
		cout << 0 << '\n';
		return 0;
	}
	for(ll i=l;i<r;i++){
		for(ll j=i+1;j<=r;j++){
			mins=min(mins, (i*j)%2019);
		}
	}
	cout << mins << '\n';
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int n, m;
	var t = ReadIntArray();
	n = t[0]; m = t[1];

	var d = new int[m+1];
	for (int i = 0; i <= m; i++){ d[i] = 0; }

	for (int i = 0; i < n; i++)
	{
	    t = ReadIntArray();
	    int k = t[0];
	    for (int j = 1; j <= k; j++)
	    {
		int a = t[j];
		d[a]++;
	    }
	}

	int ans = 0;
	for (int i = 1; i <=m; i++)
	{
	    if (d[i] == n){ ans++; }
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 13396
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int A, B, C;
  cin >> A >> B >> C;
  array<int, 3> ar = { { A, B, C } };
  sort(begin(ar), end(ar));
  bool ans = ar == array<int, 3>{ { 5, 5, 7 }};
  cout << (ans ? "YES" : "NO") << endl;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll n,m;
    cin >> n >> m;
    vll x(m),dis(m-1);
    rep(i,m)cin >> x[i];
    sort(all(x));

    if(m == 1){
        cout << 0 << endl;
        return 0;
    }

    rep(i,m-1)dis[i] = x[i+1] - x[i];
    sort(all(dis));

    ll ans = 0;

    if(m - n <= 0){
        cout << 0 << endl;
        return 0;
    }

    else rep(i,m-n)ans += dis[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[18], t[18];
    scanf("%s", s);
    int ans = 0;
    int n = strlen(s);
    bool flag = true;
    for (int i = 1; i < n; i++) {
        if (s[i] != '9') flag = false;
        ans += 9;
    }
    if (flag) ans += s[0] - '0';
    else ans += s[0] - '1';
    printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long n;
long long k;
vector <long long> v;
vector <long long> dp;

//long long f(long long i) {
//	if (dp[i] != -1) return dp[i];
//	if (i == n-2) return dp[n-2]=abs(v[i]-v[i+1]);
//	if (i == n-3) return dp[n-3]=abs(v[i]-v[i+2]);
//	long long m1 = dp[i+1] != -1 ? abs(v[i]-v[i+1])+dp[i+1] : abs(v[i]-v[i+1])+f(i+1);
//	long long m2 = dp[i+2] != -1 ? abs(v[i]-v[i+2])+dp[i+2] : abs(v[i]-v[i+2])+f(i+2);
//	return dp[i] = min (m1,m2);
//}

long long f(long long i) {
	if (dp[i] != -1) return dp[i];
	long long mi = 1e9;
	for (int j = 1;j <= k;j++) mi = min(mi,f(i+j)+abs(v[i] - v[i+j]));
	return dp[i] = mi;
}

int main () {
  cin >> n;
  cin >> k;
  long long l = n;
  while (l--) {
    long long x;
    cin >> x;
    v.push_back(x);
    dp.push_back(-1);
  }
  
//  for (int i=0;i<dp.size();i++) cout << dp[i] << " ";
  
  for (int i = 0;i < k && n >= k;i++) dp[dp.size()-2-i] = abs(v[dp.size()-2-i] - v[dp.size()-1]);
  for (int i = 1;i <= n && n < k;i++) dp[dp.size()-i] = abs(v[dp.size()-i] - v[dp.size()-1]);

//  for (int i=0;i<dp.size();i++) cout << dp[i] << " ";
  
  cout << f(0);
  return 0;
}

Measured memory_bytes: 9564
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

from datetime import timedelta, datetime

h1, m1, h2, m2, k = list(map(int, sys.stdin.buffer.readline().split()))

a = h1 * 60 + m1
b = h2 * 60 + m2
d =b - a
# print(d.minute - k)

print(d - k)


Measured memory_bytes: 27140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int mod = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
bool comp(pair<pair<string, int>, int> lhs, pair<pair<string, int>, int> rhs) {
    if (lhs.first.first != rhs.first.first)
        return lhs.first.first < rhs.first.first;
    if (lhs.first.second != rhs.first.second)
        return lhs.first.second > rhs.first.second;
    return lhs.first.first < rhs.first.first;
}
int main() {
    int n; cin >> n;
    vector<pair<pair<string, int>, int> > v;
    rep(i, n) {
        string s; int p;
        cin >> s >> p;
        v.push_back({{s, p}, i + 1});
    }
    sort(v.begin(), v.end(), comp);
    
    /*rep(i, n) {
        cout << v[i].first.first << " " << v[i].first.second << endl;
    }*/
    rep(i, n) {
        cout << v[i].second << endl;
    }
}


Measured memory_bytes: 256
#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, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int d=0;
    int cnt=0;
    for(int i=0;i<=n;++i){
        d+=l[i];
        cnt++;
        if(d>x) break;
    }
    cout << cnt << endl;

    return 0;
}


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

int n, res[3], dp[200005][3], cnt, sum, ans, a[200005], b[200005], f[200005];

int main(){
	//freopen("rand.in", "r", stdin);
	//freopen("zhengjie.out", "w", stdout);
	cin >> n;
	for(int i = 1; i <= n; i++){
		int x = i;
		while(x){
			b[i] += x & 1;
			x >>= 1;
		}
	}
	for(int i = 1; i <= n; i++)
		scanf("%1d", &a[i]), cnt += a[i];
	//cout << cnt << endl;
	for(int i = 1; i <= n; i++){
		res[1] = (res[1] * 2 + a[i]) % (cnt + 1);
		if(cnt != 1)
			res[2] = (res[2] * 2 + a[i]) % (cnt - 1);
		else
			res[2] = 0;
	}
	dp[n][1] = dp[n][2] = 1;
	for(int i = n - 1; i >= 1; i--){
		dp[i][1] = (dp[i + 1][1] * 2) % (cnt + 1);
		if(cnt != 1)
			dp[i][2] = (dp[i + 1][2] * 2) % (cnt - 1);
		else
			dp[i][2] = 0;
	}
	for(int i = 1; i <= n; i++){
		//cout << cnt << endl;
		int mo = cnt + (a[i] == 0? 1: -1);
		if(mo == 0){ cout << 0 << endl; continue; }
		sum = (res[a[i] == 0? 1: 2] + (a[i] == 0? 1: -1) * dp[i][a[i] == 0? 1: 2] + mo) % mo;
		//cout << res[a[i] == 0? 1: 2] << ' ' << sum << ' ' << (a[i] == 0? 1: -1) * dp[i][a[i] == 0? 1: 2] << ' ' << mo << ' ';
		ans = 1;
		while(sum){
			sum = sum % b[sum];
			ans++;
		}
		printf("%d\n", ans);
	} 
	return 0;
}

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

using namespace std;

#define llong long long int
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static llong MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

    int n;
    cin >> n;
    vector<int> X(n), Y(n);
    rep(i, n) cin >> X[i] >> Y[i];

    map<pair<int, int>, int> M;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i == j) continue;
            int dx = X[j] - X[i], dy = Y[j] - Y[i];
            ++M[{dx, dy}];
        }
    }

    int max_cnt = 0;
    stl_rep(itr, M) {
        max_cnt = max(max_cnt, itr->second);
    }

    cout << n - max_cnt << endl;
    
    return 0;
}

Measured memory_bytes: 384
import math
a, b, x = map(int, input().split())

half = a * a * b // 2
if x > half:
    print(math.degrees(math.atan(2 / a  * (b - x / (a * a)))))
else:
    print(math.degrees(math.atan(a * b * b / x / 2)))


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

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> hs(n);
    for(int i=0; i<n; i++) cin >> hs.at(i);

    vector<ll> nodes(n, 1LL << 60);
    nodes.at(0) = 0;
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<=i+k && j<n; j++)
        {
            chmin(nodes.at(j), nodes.at(i) + abs(hs.at(i) - hs.at(j)));
        }
    }
    cout << nodes.back() << '\n';

    return 0;
}


Measured memory_bytes: 1408
def main():
    n = int(input())
    monsters = [int(x) for x in input().split()]
    heroes = [int(x) for x in input().split()]

    sum_monsters = sum(monsters)
    for i in range(n-1, -1, -1):
        if monsters[i+1] >= heroes[i]:
            monsters[i+1] -= heroes[i]
            heroes[i] = 0
        else:
            temp_m = monsters[i+1]
            monsters[i+1] = 0
            heroes[i] -= temp_m
            if monsters[i] >= heroes[i]:
                monsters[i] -= heroes[i]
                heroes[i] = 0
            else:
                temp_m = monsters[i]
                monsters[i] = 0
                heroes[i] -= temp_m

    ans = sum_monsters - sum(monsters)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 19004
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,k;
  int kou[105];
  int count = 1;
  cin >> a >> b >> k;
  for(int i=1; i<=min(a,b); i++){
    if(a % i == 0 && b % i == 0){
      kou[count] = i;
      count++;
    }
  }
  cout << kou[count - k] << endl;
  return 0;
}


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

int main(){
    // 先にすべての引数を受け取っておく
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int ls[Q], rs[Q];
    for(int i = 0; i < Q; i++){
        cin >> ls[i] >> rs[i];
    }

    // 典型的な累積和問題
    int cnt[N];
    cnt[0] = 0;
    int tot = 0;

    for(int i = 1; i < N; i++){
        if(S[i-1] == 'A' && S[i] == 'C') tot++;
        cnt[i] = tot;
    }
    // ACカウント配列 cnt の完成

    for(int i = 0; i < Q; i++){
        cout << cnt[rs[i]-1] - cnt [ls[i]-1] << "\n";
    }

    cout << "\n";

    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll a[6],f;
ll i, j;
int main(){
    fornum(i,0,6){
        scanf("%lld", &a[i]);
    }
    fornum(i,0,4){
        if(a[i+1]-a[0]>a[5]){
            printf(":(");
            return 0;
        }
    }
    printf("Yay!");
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
s = 1
if n%2!=0:
  if l.count(0)!=1:
    s =0
  else:
    l.remove(0)
    if len(set(l))==(n-1)//2:
      s = 2**((n-1)//2)
    else:
      s =0
else:
    if len(set(l))==n//2:
      s = 2**(n//2)
    else:
      s = 0
print(int(s)%(10**9+7))
      
    

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int x,y,z,k; cin >>x>>y>>z>>k;
    vl a(x),b(y),c(z);
    rep(i,x)cin>>a[i];
    rep(i,y)cin>>b[i];
    rep(i,z)cin>>c[i];
    vl d;
    rep(i,x) rep(j,y) d.push_back(a[i]+b[j]);
    sort(all(d),greater<ll>());
    vl e;
    rep(i,min(k,x*y)) rep(j,z) e.push_back(d[i]+c[j]);
    sort(all(e),greater<ll>());
    rep(i,k) out(e[i]);
}


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



int main(){
    string Si,T;
    cin>>Si>>T;
    int sl=Si.size(),tl=T.size(),keyfront=-1;
    if(tl>sl){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    string Ti="";
    for(int i=0;i<tl;i++){
        if(T.at(i)=='a'){
            Ti+='?';
        }
        else{
            Ti+=T.at(i);
        }
    }
    for(int i=0;i<=sl-tl;i++){
        if(Si.substr(i,tl)==Ti){
            keyfront=i;
        }
    }
    if(keyfront!=-1){
        for(int i=0;i<sl;i++){
            if(i==keyfront){
                cout<<T;
                i+=tl-1;
            }
            else if(Si.at(i)=='?'){
                cout<<'a';
            }
            else{
                cout<<Si.at(i);
            }
        }
        cout<<endl;
        return 0;
    }
    for(int i=sl-tl;i>=0;i--){
        bool co=true;
        for(int j=0;j<tl;j++){
            if(Si.at(i+j)!='?'&&Si.at(i+j)!=T.at(j)){
                co=false;
            }
        }
        if(co){
            keyfront=i;
            break;
        }
    }
    if(keyfront!=-1){
        for(int i=0;i<sl;i++){
            if(i==keyfront){
                cout<<T;
                i+=tl-1;
            }
            else if(Si.at(i)=='?'){
                cout<<'a';
            }
            else{
                cout<<Si.at(i);
            }
        }
        cout<<endl;
    }
    else{
        cout<<"UNRESTORABLE"<<endl;
    }
}

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

using namespace std;

int main() {
	long long  A,V,B,W,T;
	cin >> A >> V >> B >> W>> T;
	if (V == W) {//同速
		cout << "NO"<< endl;
		return 0;
	}
	if (V < W) {//子供のほうが早い
		cout << "NO" << endl;
		return 0;
	}
	long long dist = B - A;
	if (dist < 0) {
		dist = -dist;
	}
	if (dist > T * (V -W)) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

#define ll long long

const ll int lim = 1e9 + 7;
int H, N, tmp, a[1000], b[1000], out[10001];
 
void solve() {
    std::cin >> H >> N;
    for (int i=0; i<N; ++i)
        std::cin >> a[i] >> b[i];
    for (int i=0; i<10001; ++i)
        out[i] = lim*2;
    out[0] = 0;
    for (int i=0; i<N; ++i) {
        for (int j=0; j<H; ++j) {
            tmp = std::min(H, j + a[i]);
            if (out[tmp] > (out[j] + b[i]))
                out[tmp] = out[j] + b[i];
        }
    }
    std::cout << out[H] << std::endl;
}
 
int main() {
    std::ios_base::sync_with_stdio(0);
    solve();
    return 0;
}


Measured memory_bytes: 3236
import sys


fin = sys.stdin.readline
N, T = [int(elem) for elem in fin().split()]
t_list = [int(elem) for elem in fin().split()]

time_to_expire = 0
total_time = t_list[-1] + T
for t in t_list:
    if time_to_expire < t:
        total_time -= (t - time_to_expire)
    time_to_expire = t + T
print(total_time)


Measured memory_bytes: 78288
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll n;
    cin>>n;
    ll x[110],y[110],h[110];
    rep(i,n){
        cin>>x[i]>>y[i]>>h[i];
    }
    ll cx=-1,cy=-1,H=-1;
    rep(i,101){
        rep(j,101){
            ll height=-1;
            vll v;
            bool ok=true;
            rep(k,n){
                if(h[k]>0){
                    if(height==-1){
                        height=h[k]+abs(i-x[k])+abs(j-y[k]);
                    }
                    else{
                        if(height!=h[k]+abs(i-x[k])+abs(j-y[k])){
                            ok=false;
                            break;
                        }
                    }
                }
            }
            if(!ok) continue;
            rep(k,n){
                if(h[k]==0){
                    v.pb(h[k]+abs(i-x[k])+abs(j-y[k]));
                }
            }
            rep(k,(ll)v.size()){
                if(v[k]==0) ok=false;
                if(height>v[k]) ok=false;
            }
            if(ok){
                cx=i,cy=j,H=height;
                break;
            }
        }
    }
    cout<<cx<<" "<<cy<<" "<<H<<endl;
}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N, X, m[101];
	cin >> N >> X;

	int S = 0, M = 1001001001;

	for (int i = 0; i < N; ++i) {
		cin >> m[i];
		S += m[i];
		if (m[i] < M) M = m[i];
	}
	int ans = N + (X - S) / M;
	cout << ans << endl;
}


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

typedef long long ll;


ll la[200005], lb[200005];
double point[200005];
int sz;

double cross(int i, int j) {
	return -1.0 * (lb[i] - lb[j]) / (la[i] - la[j]);
}

void insert(ll b, ll d) {
	la[sz] = b;
	lb[sz] = d;
	point[sz] = sz ? cross(sz - 1, sz) : -1e18;
	while (sz > 1 && cross(sz - 2, sz - 1) > cross(sz - 1, sz)) {
		point[sz - 1] = cross(sz - 2, sz);
		la[sz - 1] = la[sz];
		lb[sz - 1] = lb[sz];
		sz--;
	}
	sz++;
}

ll find(ll x) {
	int idx = upper_bound(point, point + sz, x) - point - 1;
	return la[idx] * x + lb[idx];
}
ll h[200005];
ll dp[200005];

int main() {
	int N; ll C; scanf("%d %lld", &N, &C);
	for (int i = 1; i <= N; i++) {
		scanf("%lld", h + i);
		dp[i] = find(h[i]) + h[i] * h[i] + C;
		if (i == 1) dp[i] = 0;
		insert(-2 * h[i], dp[i] + h[i] * h[i]);
	}
	printf("%lld\n", dp[N]);
}


Measured memory_bytes: 7936
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main()
{
    int A, B, K;
    std::cin >> A >> B >> K;

    int cnt = 0;
    int i;
    for (i = std::min(A, B); cnt < K; i--)
    {
        if (A % i == 0 && B % i == 0)
        {
            cnt++;
        }
    }
    i++;
    std::cout << i << std::endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
if s ==	'SUN':
    print(7)
elif s =='MON':
    print(6)
elif s =='TUE':
    print(5)
elif s =='WED':
    print(4)
elif s =='THU':
    print(3)
elif s =='FRI':
    print(2)
else:
    print(1)


Measured memory_bytes: 2940
import java.util.*

fun main(args: Array<out String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val digits = read(n)
    val isAppear = BooleanArray(n * (n + 1) / 2 + 1){false}
    for (left in digits.indices) {
        if (digits[left] in isAppear.indices) isAppear[digits[left]] = true
        if (digits[left] != 0) {
            var right = left + 1
            var current = digits[left]
            while(right in digits.indices && current in isAppear.indices) {
                current *= 10
                current += digits[right++]
                if (current in isAppear.indices) isAppear[current] = true
            }
        }
    }
    println(isAppear.indices.find{!isAppear[it]})
}
fun read(k: Int): List<Int> {
    val stack = Stack<List<Int>>()
    var count = 0
    while(count < k){
        stack.add(readLine()!!.trim().split(' ').map(String::toInt))
        count += stack.peek().size
    }
    return stack.flatten()
}


Measured memory_bytes: 34936