akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll N, M, K; cin >> N >> M >> K;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  vector<ll> B(M); rep(i,M) cin >> B[i];
  vector<ll> sa(N+1,0);
  rep(i,N) sa[i+1] = sa[i] + A[i];
  vector<ll> sb(M+1,0);
  rep(i,M) sb[i+1] = sb[i] + B[i];
  ll ans = 0;
  rep(i,N+1){
    ll t = sa[i];
    if(t>K) continue;
    ll lft = K-t;

    chmax(ans,(ll)(i-1+upper_bound(all(sb), lft) - sb.begin()));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9592
#include<bits/stdc++.h>
using namespace std;
char s[100001];
int main()
{
    int a,b;
    cin>>a>>b;
    for(int i=0;i<=a+b;i++) cin>>s[i];
    for(int i=0;i<=a+b;i++)
    {
	if(s[i]<'0'&&i!=a||s[i]>'9'&&i!=a)
	{cout<<"No"<<endl;
    return 0;}
    if(i==a&&s[i]!='-')
    {cout<<"No"<<endl;
    return 0;}
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N,K = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N-1)]

es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

MOD = 10**9+7
ans = K
def rec(v,p=-1,d=0):
    global ans
    k = K-2 if d else K-1
    for to in es[v]:
        if to==p: continue
        ans *= k
        ans %= MOD
        k -= 1
        rec(to,v,d+1)
rec(0)
print(ans)

Measured memory_bytes: 126736
import java.util.*;

public class Main {
	
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int h = sc.nextInt();
			int w = sc.nextInt();
			int [][] data = new int[h][w];
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					data[i][j] = sc.nextInt();
				}
			}
			
			StringBuilder sb = new StringBuilder();
			int indh = 0, indw = 0, add = 1;
			String prev = null;
			boolean find = false;
			int count = 0;
			for(int i = 0; i < h; i++){
				if(i % 2 == 0){
					for(int j = 0; j < w; j++){
						if(find){
							if(data[i][j] % 2 == 0){
								count++;
								sb.append(prev + " " + (i + 1) + " " + (j + 1));
								sb.append("\n");
								prev = (i + 1) + " " + (j + 1);
							}
							else{
								find = false;
								count++;
								sb.append(prev + " " + (i + 1) + " " + (j + 1) );
								sb.append("\n");
								prev = (i + 1) + " " + (j + 1);
							}
							
						}
						else{
							if(data[i][j] % 2 == 0){
							}
							else{
								find = true;
								prev = (i + 1) + " " + (j + 1);
							}
						}
					}
				}
				else{
					for(int j = w-1; j >= 0; j--){
						if(find){
							if(data[i][j] % 2 == 0){
								count++;
								sb.append(prev + " " + (i + 1) + " " + (j + 1) );
								sb.append("\n");
								prev = (i + 1) + " " + (j + 1);
							}
							else{
								find = false;
								count++;
								sb.append(prev + " " + (i + 1) + " " + (j + 1) );
								sb.append("\n");
								prev = (i + 1) + " " + (j + 1);
							}
							
						}
						else{
							if(data[i][j] % 2 == 0){
							}
							else{
								find = true;
								prev = (i + 1) + " " + (j + 1);
							}
						}
					}
				}
			}
			System.out.println(count);
			System.out.print(sb.toString());
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 105196
import numpy as np
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(n-1):
    for j in range(i+1,n):
        a=np.array(x[i])
        b=np.array(x[j])
        ab=sum(np.power((a-b),2))**0.5
        if ab%1==0:
            count+=1
print(count)

Measured memory_bytes: 12480
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int k;
  cin>>k;
  if(k%2==0||k%5==0){
    cout<<-1<<endl;
  }else{
    long long int now=7;
    long long int count=1;
    while(true){
      if(now%k==0){
        cout<<count<<endl;
        break;
      }else{
        now*=10;
        now+=7;
        now%=k;
        count++;
      }
    }
  }
}

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

const int mod = 1e9 + 7;
const int N = 900010;
int n, m, k;
ll fac[N], inv[N], p[N];

inline ll read() {
	ll s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline ll quickpow(ll a, ll b) {
    ll re = 1;
    while(b) {
        if(b & 1) re *= a;
        re %= mod;
		b >>= 1;
        a *= a;
        a %= mod;
    }
    return re;
}

inline void init() {
	n = read(), m = read(), k = read();
    fac[0] = 1;
    p[0] = 1;
    for(int i = 1 ; i < N; ++i) {
        fac[i] = fac[i - 1] * i % mod;
        p[i] = p[i - 1] * 3LL % mod;
    }
    for(int i = 0; i < N; ++i) { inv[i] = quickpow(fac[i], mod - 2) % mod; }
}

inline ll C(ll x, ll y) { return (fac[x] * inv[y] % mod * inv[x - y] % mod) % mod; }

inline void work() {
	ll ans = 0, x = 1LL;
    --n;
    if(m < k)	swap(m, k);
    for(int i = 0; i <= m + k; ++i) {
        ans = (ans + C(n + i, n) * p[m + k - i] % mod * x) % mod;
        if(i < k) x = (x * 2LL) % mod;
        else if(i < m) x = (x * 2LL - C(i, k)) % mod ;
        else  x = (x * 2LL - C(i, k) - C(i, m)) % mod ;
    }
    printf("%lld\n", (ans + mod) % mod);
}

int main() {
	init();
    work();
    return 0;
}


Measured memory_bytes: 21376
import sys
from itertools import permutations
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    P=tuple([int(_) for _ in input().split()])
    Q=tuple([int(_) for _ in input().split()])
    p_list=list(permutations(list(range(1,n+1))))
    print(abs(p_list.index(Q)-p_list.index(P)))

if __name__=='__main__':
    main()

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

using namespace std;

int check(int a,int b,int c)
{
	if( a+b>c && a+c>b &&b+c >a)
	return 1;
	
	else
	return 0;
	
	
}
int main()
{
	int t;
	t=1;
	while(t--)
	{
   
   
   int i,j,k,n;
   
   cin>>n;
   int a[1000];
   
   for(i=0;i<n;i++)
   cin>>a[i];
   int sum=0;
   
   for(i=0;i<n;i++)
   {
   	  for(j=i+1;j<n;j++)
   	  {
   	  	for(k=j+1;k<n;k++)
   	  	{
   	  		if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&check(a[i],a[j],a[k])==1)
   	  		{
   	  		//	cout<<i<<" "<<j<<" "<<k<<endl;
   	  			sum++;
			}
   	  		
			 }
   	  	
		 }
   	
   }
   
   cout<<sum<<endl;
   
	}



}


Measured memory_bytes: 3620
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
#define endl '\n'
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef queue<int> qii;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
double pi = 2 * acos(0.0); 

double calcAngle(double h, double m){ 
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6 * m;  
    double angle = abs(hour_angle - minute_angle);  
    angle = min(360 - angle, angle);  
    return angle;  
}  

void solve(){
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double degrees1=calcAngle((double)h,(double)m);
    double radians1=(degrees1*pi)/180;
    cout<<fixed<<setprecision(15)<<sqrt((a*a)+(b*b)-2*a*b*cos(radians1))<<'\n';    
}

int main(){ 
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}


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

int main(){
    int n,count=0;
    cin >> n;
    vector<int> d(n);
    vector<int> e(n);
    for(int i=0; i<n; i++) cin >> d[i];
    sort(d.begin(),d.end());
    int j=0;
    for(int i=0;i<n;i++){
        if(d[i]!=d[i-1]){
            count++;
        }
    }
    cout << count;
}

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

int main(){
    int a,b,flag=0;

    cin>>a>>b;

    for(int i=1;i<4;i++){
        if((i*a*b)%2 == 0)
            flag = 0;
        else
            flag++;
    }

    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc060/tasks/arc073_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, T, t, l, sum;
int main()
{
  cin >> N >> T >> l;

  sum = T;
  REP(i, N - 1)
  {
    cin >> t;
    sum += min(T, t - l);
    l = t;
  }

  cout << sum << '\n';

  return 0;
}


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

using namespace std;

int main()
{
  int n;
  cin>>n;
  float ans;
  if(n%2 == 0)
  {
    ans = float(n/2)/n;
  }
  else
  {
    ans = float(n/2 + 1)/n;
  }
  cout.setf(ios::showpoint);
  cout<<setprecision(10)<<ans;
  return 0;
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n,m;
	cin>>n>>m;
	vector<int>p(m);
	vector<int>bulb[m];
	for(int i=0;i<m;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int a;
			cin>>a;
			bulb[i].pb(a-1);
		}
	}
	for(int i=0;i<m;i++){
		cin>>p[i];
	}
	int ma=1<<n;
	int ans=0;
	for(int i=0;i<ma;i++){
		int bcount=0;
		for(int j=0;j<m;j++){
			int count=0;
			for(int k=0;k<bulb[j].size();k++){
				if(((1<<(bulb[j][k]))&i)!=0){
					count++;
				}
				//cout<<i<<" "<<j<<" "<<bulb[j][k]<<" "<<count<<endl;
			}
			if(count%2==p[j]){
				bcount++;
			}
		}
		if(bcount==m){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
from bisect import bisect_left
import random
import time
time_start = time.perf_counter()


#入力
D = int(input())
C = [int(c) for c in input().split()]
S = []
for _ in range(D):
    s = [int(x) for x in input().split()]
    S.append(s)
#初期解
T = []
for _ in range(D):
    t = random.randrange(26)
    T.append(t)

#スコア計算
score = 0
last_day = [[-1] for _ in range(26)]
for d in range(D):
    test = T[d]
    score += S[d][test]
    last_day[test].append(d)
minus = [0] * 26
for i in range(26):
    last_day[i].append(D)
    l = last_day[i]
    for j in range(len(l)-1):
        dd = l[j+1] - l[j] - 1
        minus[i] += C[i] * (dd * (dd + 1)) // 2
    score -= minus[i]

while True:
    time_now = time.perf_counter()
    if time_now - time_start > 1.8:
        break
    d = random.randrange(365)
    q = random.randrange(26)
    old = T[d]
    T[d] = q
    #日程dでの元のテストold
    l = last_day[old]
    ind_old = l.index(d)
    dd_left = l[ind_old] - l[ind_old-1] - 1
    dd_right = l[ind_old+1] - l[ind_old] - 1
    dd = l[ind_old+1] - l[ind_old-1] - 1
    dif_old = C[old] * (((dd_left * (dd_left + 1)) // 2) + ((dd_right * (dd_right + 1)) // 2) - ((dd * (dd + 1)) // 2))
    #日程dでのテストq
    l = last_day[q]
    ind_q = bisect_left(last_day[q],d)
    dd_left = d - l[ind_q-1] - 1
    dd_right = l[ind_q] - d - 1
    dd = l[ind_q] - l[ind_q-1] - 1
    dif_q = C[q] * (((dd * (dd + 1)) // 2) - ((dd_left * (dd_left + 1)) // 2) - ((dd_right * (dd_right + 1)) // 2))
    dif_s = (dif_old + dif_q - S[d][old] + S[d][q])
    if dif_s > 0:
        #新しいスコア
        score += dif_s
        #情報の更新
        minus[old] -= dif_old
        minus[q] -= dif_q
        del last_day[old][ind_old]
        last_day[q].insert(ind_q,d)
    else:
        T[d] = old
for d in range(365):
    print(T[d] + 1)



Measured memory_bytes: 86828
S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])
if a+b+c+d==7:
    print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a-b+c+d==7:
    print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a+b-c+d==7:
    print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif a-b-c+d==7:
    print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif a+b+c-d==7:
    print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a-b+c-d==7:
    print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a+b-c-d==7:
    print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif a-b-c-d==7:
    print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int check(string s1, string s2){
	int a[26] = {0};
	int b[26] = {0};
	REP(i, s1.size()) a[s1[i]-'a'] = 1;
	REP(i, s2.size()) b[s2[i]-'a'] = 1;
	int res = 0;
	REP(i, 26) if(a[i] && b[i]) res++;
	return res;
}
int main(){
     int n;
     string s;
     cin >> n >> s;
     int ans = 0;
     FOR(i,0, n-1){
     	string s1 = s.substr(0, i+1);
     	string s2 = s.substr(i+1, s.size()-i);
     	// cout << s1 << " " << s2 << endl;
     	ans = max(ans, check(s1, s2));
     }
     cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
  char c[10];
  scanf("%s", c);
  int val = 0;
  for (int i = 0; i < 4; i++) {
    if (c[i] == '+') {
      val++;
    } else {
      val--;
    }
  }
  printf("%d\n", val);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<math.h>
#include<algorithm>
typedef long long int ll;
using namespace std;
int n,i;
int a[120];

int main(){
    int x,ans=0;
    bool flag=true;
    cin>>n>>x;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;i++){
        x-=a[i];
        if(x<0)goto end;
    }
    if(x>0){
        cout<<n-1<<endl;
    }
    else{
        cout<<n<<endl;
    }
    flag=false;
    end:
    if(flag)cout<<i<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  for (int i=0;i<n;i++){
    cin >> x[i] >> u[i];
  }
  double sum=0;
  for (int i=0;i<n;i++){
    if(u[i]=="BTC"){
      x[i]*=380000.0;
    }
    sum+=x[i];
  }
  cout << fixed << setprecision(14) << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    ArrayList <Integer> li = new ArrayList <Integer>();
    for(int i=0;i<5;i++){
      int a = sc.nextInt();
      li.add(a);
    }
    for(int i=0;i<5;i++){
      if(li.get(i)==0){
        System.out.println(i+1);
      }
    }
  }
}

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

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

    vector<int> dp(n+1);
    int broken[100001] = {0};
    int prime = 1000000007;

    int tmp;
    for (int i = 0; i < m; ++i){
        cin >> tmp;
        broken[tmp] = 1;
    }

    dp[0] = 1;
    for (int j = 1; j < n+1; ++j){
        if ( broken[j] ){
            dp[j] = 0;
        }else if (j == 1){
            dp[j] = 1;
        }else{
            dp[j] = (dp[j-1] + dp[j-2]) % prime;
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n, y;
    cin >> n >> y;
    for(ll i = 0; i <= n; ++i){
        for(ll j = 0; i + j <= n; ++j){
            const ll k = n - i - j;
            if(y == 10000 * i + 5000 * j + 1000 * k){
                cout << i << ' ' << j << ' ' << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
    return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {FIN

	int i, j, n, m;
	string s, t, r = "";

	cin >> s;
	cin >> t;
	n = s.size(); m = t.size();
	vvi dp(n + 1, vi(m + 1));

	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1])
				dp[i][j] = max(dp[i - 1][j - 1] + 1, max(dp[i - 1][j], dp[i][j - 1]));
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}

	i = n; j = m;
	while (i > 0 and j > 0) {
		if (dp[i][j] == dp[i - 1][j - 1] + 1 and s[i - 1] == t[j - 1]) {
			r += s[i - 1];
			i--, j--;
		} else {
			if (dp[i - 1][j] == dp[i][j])
				i--;
			else
				j--;
		}
	}

	reverse(r.begin(), r.end());
	cout << r << "\n";

	return 0;
}

Measured memory_bytes: 38500
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        k: u32
    }
    if k % 2 == 0 {
        println!("{}", k/2 * k/2);
    } else {
        println!("{}", k/2 * (k/2+1));
    }
}


Measured memory_bytes: 4352
//ITP1_3_B
#include<iostream>
using namespace std;

int main()
{
	int i = 0;
	
	while(1){
	int x;
	cin>>x;
	
	if(x == 0)
	break;
	
	i++;
	
	cout<<"Case "<<i<<": "<<x<<endl;
	}
	
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  
  int ans=0;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    
    ans += b-a+1;
    
  }
  cout<<ans<<endl;
}

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

    int a[4];
    int ans=0;
    cin >>a[0]>>a[1]>>a[2];
    sort(a,a+3);

    ans = a[1] - a[0];
    ans += a[2] - a[1];
        cout <<ans<<endl;


}

Measured memory_bytes: 256
/*
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int N;
	cin>>N;
	vector<int> A(N);
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
	}
	vector<bool> sea(N+2);
	sea[0]=sea[N+1]=true;
	for(int i=0;i<N;i++){
		sea[i+1]=(A[i]<=0);
	}
	int current=0;
	for(int i=1;i<=N;i++){
		if(!sea[i]&&sea[i-1])
		{
			current++;
		}
	}
	vector<pair<int,int> > AandID;
	for(int i=0;i<N;i++){
		if(A[i]>0){
			AandID.push_back(make_pair(A[i],i+1));
		}
	}
	sort(AandID.begin(),AandID.end());
	int answer=current;
	for(int t=0;t<AandID.size();t++){
		int i=AandID[t].second;
		sea[i]=true;
		if(sea[i-1]&&sea[i+1]){
			current--;
		}
		else if(!sea[i-1]&&!sea[i+1]){
			current++;
		}
		if(t+1==AandID.size()||AandID[t].first<AandID[t+1].first){
			answer=max(answer,current);
		}
	}
	cout<<answer<<endl;
	return 0;
}*/
/*
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(void){
	long long N,M;
	cin>>N>>M;
	vector<long long> A(N+2);
	
	return 0;
}*/
/*
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
int main(void)
{
	long long N=0;
	cin>>N;
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	vector<bool> sea(N+2);
	sea[0]=sea[N+1]=true;
	for(int i=0;i<N;i++){
		sea[i+1]=(A[i]<=0);
	}
	long long current=0;
	for(int i=1;i<=N;i++){
		if(sea[i-1]&&!sea[i]){
			current++;
		}
	}
	vector<pair<long long,long long> > V;
	for(int i=0;i<N;i++){
		if(A[i]>0){
			V.push_back(make_pair(A[i],i+1));
		}
	}
	sort(V.begin(),V.end());
	long long answer=current;
	for(int t=0;t<V.size();t++){
		int a=V[t].second;
		sea[a]=true;
		if(!sea[a-1]&&!sea[a+1])
		{
			current++;
		}
		if(sea[a-1]&&sea[a+1])
		{
			current--;
		}
		if(t==V.size()-1||V[t].first<V[t+1].first){
			answer=max(answer,current);
		}
	}
	cout<<answer<<endl;
	return 0;
}*/
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	long long N,M,L,R;
	cin>>N>>M;
	vector<long long> A(N+1);
	A[0]=0;
	for(long long i=1;i<=N;i++){
		cin>>A[i];
	}
	vector<long long> Look(N+1);
	Look[0]=0;
	for(long long i=1;i<=N;i++){
		Look[i]=i-1;
	}
	for(long long i=0;i<M;i++){
		cin>>L;
		cin>>R;
		Look[R]=min(L-1,Look[R]);
	}
	for(long long i=N-1;i>=1;i--){
		Look[i]=min(Look[i],Look[i+1]);
	}
	vector<long long> dp(N+2);
	dp[0]=0;
	for(long long i=1;i<=N;i++){
		dp[i]=max(dp[i-1],dp[Look[i]]+A[i]);
	}
	cout<<dp[N]<<endl;
	return 0;
}


Measured memory_bytes: 7324
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int k,x;
	cin>>k>>x;
	k*=500;
	if(k>=x)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3644
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n;
    scan(n);

    auto adj = new int[][](n, 0);

    foreach (i ; 0 .. n - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    auto c = readln.split.to!(int[]);
    c.sort();

    auto maxS = c.sum(0L) - c.back;

    auto d = new int[](n);
    d[] = -1;

    void dfs(int v, int p) {
        foreach (u ; adj[v]) if (u != p) {
            dfs(u, v);
        }

        d[v] = c.front;
        c.popFront();
    }

    dfs(0, -1);

    writeln(maxS);
    writefln("%(%s %)", d);
}

















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 3068
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  int n;
  cin >> n;
  vector<int> p(n), q(n), r(n);
  rep(i, n) {
    cin >> p[i];
    r[i] = i+1;
  }
  rep(i, n) cin >> q[i];
  
  int cnt = 0, a, b;
  do {
    if (p == r) a = cnt;
    if (q == r) b = cnt;
    cnt++;
  } while (next_permutation(all(r)));
  
  cout << abs(a-b) << endl;
  return 0;
}

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


int main(){
  int n,m;
  cin >>n>>m;
  priority_queue<int> price;
  rep(i,n){
    int a;
    cin >> a;
    price.push(a);
  }
  rep(i,m){
    int a= price.top();
    price.pop();
    price.push(a/2);
  }
  ll ans=0;
  rep(i,n){
    int a=price.top(); price.pop();
    ans+=a;
  }
 
  cout<<ans;

}



Measured memory_bytes: 892
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
//prototype declaration
int func(int a, int b);
//gloval variable
double pi = 3.1415926535897932384626433;

int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    int ans = func(a, b);
    printf("%d\n", ans);
    return 0;
}
int func(int a, int b){
    int res = 0;
    res = (b-a-1)*(b-a)/2-a;
    return res;
}

Measured memory_bytes: 1676
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline string bool_to_string(bool b, const string &tval, const string fval) { return b ? tval : fval; } 
string YESNO(bool b) { return bool_to_string(b, "YES", "NO"); }
string YesNo(bool b) { return bool_to_string(b, "Yes", "No"); }
string yesno(bool b) { return bool_to_string(b, "yes", "no"); }

int main() {
  int n;
  while (cin >> n) {
    vint v(n); REP(i,n) cin >> v[i];
    cout << *max_element(ALL(v)) - *min_element(ALL(v)) << endl;
  }
}


Measured memory_bytes: 888
n=int(input())
list=input().split()
a=list[0]
b=list[1]
def split(w):
    return [all for all in w]
a=split(a)
b=split(b)
c=0
str=""
for i in range(len(a)):
  str=a[c]+str
  str=b[c]+str
  c+=1
print(str[::-1])

Measured memory_bytes: 9148
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){

int N,A;
cin>>N>>A;
ll dp[N*50+1][N+1];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
int x[N+1];
rep3(i,N)cin>>x[i];
rep3(j,N){
    
    repr3(k,j)repr3(i,N*50+1){
    if(i>=x[j]){
    dp[i][k]+=dp[i-x[j]][k-1];
    }
    
    
    }
}

ll ans=0;
rep3(i,N*50)rep3(k,N){
    if(i==k*A)ans+=dp[i][k];
}
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 4592
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int> a(5),b(5),c(5);
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		b[i] = (a[i] + 9) / 10 * 10;
		c[i] = a[i] % 10;
		if (c[i] == 0) {
			c[i] = 10;
		}
	}
	int min=0;
	int ans = 0;
	for (int i = 0; i < 5; i++) {
		min = (c[i] <= c[min]) ? i : min;
	}
	b[min] = a[min];
	for (int i = 0; i < 5; i++) {
		ans += b[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#次のコードを改変した
#https://abc099.contest.atcoder.jp/submissions/2657877
    #リストの内包表記を自分でも分かる書き方に直した
from itertools import product
from collections import Counter

n, c = map(int, input().split())
color_costs = [list(map(int, input().split())) for _ in range(c)]
matrix = [list(map(int, input().split())) for _ in range(n)]

res = []
for r in range(3):
    color_count = Counter(matrix[i][j] - 1 for i in range(n) for j in range(n) if (i + j) % 3 == r)

    def color_cost(color):
        return sum(color_costs[ccolor][color] * ccount for ccolor, ccount in color_count.items())
    cx = [(color, color_cost(color)) for color in range(c)]
    sorted_by_cost = sorted(cx, key=lambda x:x[1])
    cheapest3 = sorted_by_cost[:3]
    res.append(cheapest3)

#print(res)
color_pickss = product(*res)
#for picks in color_pickss:
#    print(picks)
filtered_unique = (picks for picks in color_pickss if len(set(color for color, _ in picks)) == 3)
costs = (sum(cost for _, cost in picks) for picks in filtered_unique)
print(min(costs))

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

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

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

const ll MAXN = 1000001;
bool P[MAXN];
bool S[MAXN];

template<typename T> T gcdraw(T a, T b) { return a ? gcdraw(b%a, a) : b; }
template<typename T> T gcd(T a, T b)
{
    const auto aa = abs(a), bb = abs(b);
    return aa > bb ? gcdraw(aa, bb) : gcdraw(bb, aa);
}

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

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

    vector<ll> PS = { 1, 2 };
    for (ll i=3;i*i<=MAXN;i+=2) if (!P[i])
    {
        for (ll j=2*i;j<=MAXN;j+=i) { P[j] = true; }
        PS.emplace_back(i);
    }

    bool isPairwise = true;

    ll cur = A[0];

    for (ll i=0;i<N;++i)
    {
        if (isPairwise) for (const auto& p: PS)
        {
            if (A[i] < p * p) { break; }
            if (A[i] % p) { continue; }

            const auto x = p;
            const auto y = A[i] / p;

            if (x != 1 && S[x]) { isPairwise = false; }
            if (y != 1 && S[y]) { isPairwise = false; }

            S[x] = true;
            S[y] = true;
        }

        cur = gcd(cur, A[i]);
    }

    const auto isSetwise = cur == 1;

    if (isPairwise)     { cout << "pairwise coprime" << endl; }
    else if (isSetwise) { cout << "setwise coprime" << endl; }
    else                { cout << "not coprime" << endl; }

    return 0;
}


Measured memory_bytes: 12112
#!/usr/bin/env python3
import sys


def solve(N: int):
    ans = []
    for i in range(1, N+1):
        if i % 3 == 0 or i % 5 == 0:
            continue
        ans.append(i)
    print(sum(ans))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()



Measured memory_bytes: 30052
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
	int q;
	double x1,x2,x3,x4,y1,y2,y3,y4,slope1,slope2,naiseki;

	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		if(x1 == x2 && x3 == x4){
			printf("2\n");
		}else if(x1 == x2 && x3 != x4){
			if(y3 == y4)printf("1\n");
			else{
				printf("0\n");
			}
		}else if(x1 != x2 && x3 == x4){
			if(y1 == y2)printf("1\n");
			else{
				printf("0\n");
			}
		}else{
			slope1 = (y2-y1)/(x2-x1);
			slope2 = (y4-y3)/(x4-x3);
			naiseki = (x2-x1)*(x4-x3)+(y2-y1)*(y4-y3);
			if(fabs(slope1-slope2) < 0.00000001){
				printf("2\n");
			}else if(fabs(naiseki) < 0.00000001){
				printf("1\n");
			}else{
				printf("0\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 2704
#include <stdio.h>
int main(){
  int a,b,c,ans;
scanf("%d%d%d",&a,&b,&c);
if(a==b&&b==c&&a==c) printf("1");
else if(a!=b&&b!=c&&a!=c)printf("3");
else printf("2");
  return 0;
}


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

#define ff first
#define ss second

int main()
{
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		cout << "Bad" << endl;
	} else {
		cout << "Good" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, k;
int a[3000000];
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	priority_queue<H, vector<H>, greater<H>>p;
	priority_queue<H>q;
	for (int i = 0; i < k; i++) {
		p.push(H{ a[i],i });
		q.push(H{ a[i],i });
	}
	int ans = 1;
	for (int i = k; i < n; i++) {
		while (p.top().y <= i - k) p.pop();
		while (q.top().y <= i - k) q.pop();
		if (!(p.top().x >= a[i - k] && q.top().x <= a[i]))
			ans++;
		p.push(H{ a[i],i });
		q.push(H{ a[i],i });
	}
	int sum = 0;
	for (int i = 0; i < n; ) {
		int j = i + 1;
		while (j < n && a[j - 1] <= a[j]) j++;
		if (j - i >= k) sum++;
		i = j;
	}
	if (sum > 1) {
		ans -= sum - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 12000
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>


using namespace std;
typedef long long ll;

ll n,a,b,c[10010]={0};
ll m=0,d[10010]={0};
ll deg[10010]={0};
vector<ll>edge[10010];

signed main() {
	cin>>n;
    for(int i=0;i<n-1;++i){
        cin>>a>>b;
        edge[a].push_back(b);
        edge[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }
    for(int i=0;i<n;++i){
        cin>>c[i];
    }
    sort(c,c+n);
    for(int i=0;i<n;++i){
        for(int j=1;j<n;++j){
            if(deg[j]==1){
                d[j]=c[i];
                deg[j]--;
                for(int k=0;k<edge[j].size();++k){
                    if(deg[edge[j][k]]>=1)deg[edge[j][k]]--;
                }
                m+=c[i];
                break;
            }
        }
    }
	for(int i=1;i<=n;++i){
        if(d[i]==0)d[i]=c[n-1];
    }

    cout<<m<<endl;
    cout<<d[1];
    for(int i=2;i<=n;++i){
        printf(" %d",d[i]);
    }
    cout<<endl;
	
	return 0;
}


Measured memory_bytes: 1152
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
class UnionSet
{
public:
	int fa[N];
	int dis[N];
	void init()
	{
		MEM(fa, -1);
		MEM(dis, 0);
	}
	int getdis(int x)
	{
		Find(x);
		return dis[x];
	}
	int treesize(int x)
	{
		return -fa[Find(x)];
	}
	int Find(int x)
	{
		int root = x;
		int d = 0;
		while (fa[root] >= 0)
		{
			d += dis[root];
			root = fa[root];
		}
		while (x != root)
		{
			tie(d, dis[x]) = make_pair(d - dis[x], d);
			int tmp = fa[x];
			fa[x] = root;
			x = tmp;
		}
		return root;
	}
	void Union(int x, int y, int w)
	{
		int px = Find(x);
		int py = Find(y);
		//if (fa[px] > fa[py]) swap(px, py);
		int sz = fa[px] + fa[py];
		fa[py] = px;
		fa[px] = sz;
		dis[py] = dis[x] + w - dis[y];
	}
} uf;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	scanf("%d%d", &n, &m);
	uf.init();
	while (m--)
	{
		int l, r, d;
		scanf("%d%d%d", &l, &r, &d);
		if (uf.Find(l) != uf.Find(r))
		{
			uf.Union(r, l, d);
		}
		else
		{
			if (uf.getdis(l) - uf.getdis(r) != d)
				puts("No"), exit(0);
		}
	}
	puts("Yes");
	return 0;
}


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

using namespace std;

int main()
{
    while (1)
    {
        int x, y, s, maxv=0;
        cin>>x>>y>>s;
        if (x==0 && y==0 && s==0) break;
        for (int i=1; i<s; i++)
        {
            for (int j=1; j<s; j++)
            {
                if (i*(100+x)/100+j*(100+x)/100==s)
                {
                    maxv=max(maxv, i*(100+y)/100+j*(100+y)/100);
                }
            }
        }
        cout<<maxv<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
double K(double x) { return x * x; }

int main(){
	int n; cin>>n;
	map<string, int> map;
	int best = 0;
	for(int i = 0; i < n; i++){
		string s; cin>>s;
		map[s]++;
		best = max(best, map[s]);
	}
	vector<string> ans;
	for(auto x: map){
		if(x.second ==best){
			ans.push_back(x.first);
		}
	}
	sort(ans.begin(), ans.end());
	for(string s: ans){
		cout<<s<<endl;
	}
}


Measured memory_bytes: 26868
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll a[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; i++)
        cin >> a[i];
    vector<ll> v;
    for (ll i = n; i; i--)
    {
        for (ll j = 2 * i; j <= n; j += i)
            a[i] ^= a[j] % 2;
        if (a[i])
            v.push_back(i);
    }
    cout << v.size() << "\n";
    for (ll e : v)
        cout << e << " ";
    return 0;
}

Measured memory_bytes: 3700
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    string s;
    scan(s);

    writeln(s.canFind("AC") ? "Yes" : "No");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(br.readLine());
        final int h = Integer.parseInt(tok.nextToken());
        final int w = Integer.parseInt(tok.nextToken());
        char[][] mat = new char[h][w];
        boolean[] row = new boolean[h];
        boolean[] col = new boolean[w];

        // 読み込み
        String str;
        char c;
        for (int i = 0; i < h; i++) {
            str = br.readLine();
            for (int j = 0; j < w; j++) {
                c = str.charAt(j);
                mat[i][j] = c;
                if (c == '#') {
                    row[i] = true;
                    col[j] = true;
                }
            }
        }
        // 表示
        for (int i = 0; i < h; i++) {
            if (!row[i]) continue;
            for (int j = 0; j < w; j++) {
                if (col[j])
                    System.out.print(mat[i][j]);
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 22868
#include <iostream>

using namespace std;

int main() {
	int group_a[7] = { 1,3,5,7,8,10,12 };
	int group_b[4] = { 4,6,9,11 };
	int group_c[1] = { 2 };
	int x, y;
	cin >> x >> y;
	int gx, gy;
	for (int i = 0; i < 7 ;++i) {
		if (x == group_a[i]) {
			gx = 1;
		}
		if (y == group_a[i]) {
			gy = 1;
		}
	}
	for (int i = 0; i < 4;++i) {
		if (x == group_b[i]) {
			gx = 2;
		}
		if (y == group_b[i]) {
			gy = 2;
		}
	}
	for (int i = 0; i < 1;++i) {
		if (x == group_c[i]) {
			gx = 3;
		}
		if (y == group_c[i]) {
			gy = 3;
		}
	}
	if (gx == gy) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
open Hashtbl
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let h = create n
let acs = Array.iter (fun a -> replace h a @@ try find h a + 1 with _ -> 1) a_s; List.(fold (fun a c xs -> (a, c) :: xs) h [] |> filter (fun (_, c) -> c >= 2) |> sort (fun x y -> compare y x))
let _ = Printf.printf "%d\n" @@ match acs with (a, c) :: (b, _) :: _ -> if c >= 4 then a * a else a * b | (a, c) :: _ -> if c >= 4 then a * a else 0 | _ -> 0

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair

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

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        while(n!=0)
        {
            if(n%10==7){cout<<"Yes"<<endl;return 0;}
            n=n/10;
        }
        cout<<"No"<<endl;
        return 0;

    }


    return 0;
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int gcd(int a, int b) {
    if( a < b ){
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;

    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

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

    int a[N];
    for(int i = 0; i < N; i++ ) {
        int x;
        cin >> x;

        a[i] = abs(X - x);
    }

    int ans = a[0];
    for (int i = 1; i < N; i++) {
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 640