akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0;i<(n);++i)
const ll MOD=1e9+7;
//const ll MOD=998244353;

template<typename T>
struct TreeDiameter{
    vector<T> dp;
    vector<vector<pair<int,T>>> G;
    TreeDiameter(int n):dp(n),G(n){}
    void add_edge(int u,int v,T c){
        G[u].emplace_back(v,c);
        G[v].emplace_back(u,c);
    }
    void dfs(int v,int p,int &s){
        if (p<0) dp[v]=T(0);
        if (dp[s]<dp[v]) s=v;
        for (auto e:G[v]){
            int u=e.first;
            if (u==p) continue;
            dp[u]=dp[v]+e.second;
            dfs(u,v,s);
        }
    }
    pair<int,int> endPoints(){
        int s=0;
        dfs(s,-1,s);
        int t=s;
        dfs(t,-1,t);
        return make_pair(s,t);
    }
    T build(){
        int t=endPoints().second;
        return dp[t];
    }
    vector<T> distance(int v){
        dfs(v,-1,v);
        return dp;
    }
    vector<T> farthest(){
        int t=endPoints().second;
        auto ds=dp;
        auto dt=distance(t);
        for (int i=0;i<ds.size();++i) ds[i]=max(ds[i],dt[i]);
        return ds;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    TreeDiameter<int> TD(n);
    rep(i,n-1){
        int s,t,w; cin >> s >> t >> w;
        TD.add_edge(s,t,w);
    }
    vector<int> ans=TD.farthest();
    rep(i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 3948
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int s; cin >> s;
  FOR(i, 1, 999998) {
    // コラッツ数列における唯一のループが 1 -> 4 -> 2 -> 1 らしい
    if (s == 1 || s == 2 || s == 4) {
      cout << i + 3 << '\n';
      return 0;
    } else if (s & 1) s = 3 * s + 1;
    else s >>= 1;
  }
}


Measured memory_bytes: 256
N = input()
N = int(N)
name = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

S = 1
i = 0
Sum = 0
while Sum<N:
    S *= 26
    Sum += S
    i = i+1


ans = []
for j in range(i):
    N -= 1
    r = N%26
    ans.insert(0, name[r])
    N = N//26

ans = ''.join(ans)
print(ans)


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 500010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,L,bot,top;

double tot;

double temperature[maxn],volume[maxn];

void Work(){
	REP(i,2,n){
		double x,y,z;
		scanf("%lf%lf",&x,&y);z=y;
		while(volume[top]<=z){
			tot-=temperature[top]*volume[top];
			z-=volume[top];
			top++;
		}
		tot-=z*temperature[top];volume[top]-=z;
		tot+=x*y;
		while(top<=bot&&temperature[bot]>x){
			x=(x*y+temperature[bot]*volume[bot])/(y+=volume[bot]);
			bot--;
		}
		bot++;
		temperature[bot]=x;volume[bot]=y;
		printf("%.10lf\n",(double)tot/L);
	}
}

void Init(){
	read(n,L); 
	scanf("%lf%lf",&temperature[1],&volume[1]);
	top=bot=1;
	tot=temperature[1]*volume[1];
	printf("%.10lf\n",temperature[1]);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 18304
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

int main(){
    long long int n, a[100009], b[100009];
    cin >> n;
    for(int i=0;i<=n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    long long int cnt =0;
    for(int i=0;i<n;i++){
        cnt += min(a[i]+a[i+1], b[i]);
        if(b[i]-a[i]>0){
            if(a[i+1]>b[i]-a[i]){
                a[i+1] -= b[i]-a[i];
            }
            else{
                a[i+1] = 0;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1792
def odd_even(a, b):
    if a % 2 == b % 2:
        return True
    else:
        return False

n = int(input())
T, X, Y = [0], [0], [0]
for _ in range(n):
    t, x, y = map(int, input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

ans = 'Yes'

for i in range(1,n+1):
    t_dif = T[i] - T[i-1]
    x_dif = abs(X[i]-X[i-1])
    y_dif = abs(Y[i]-Y[i-1])
    if t_dif >= (x_dif + y_dif) and odd_even(t_dif, x_dif+y_dif):
        pass
    else:
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 11816
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    cout << (k % 2 == 0 ? a - b : b - a);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
for _ in range(1, n+1):
    t, x, y = map(int, input().split())
    # x+yは毎秒ごとに必ず偶奇が入れ替わる、といったパリティに関する考え方が重要
    if (x + y) > t or (x + y + t) % 2:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 43736
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
  int n;
  while (cin >> n) {
	bool ok = true;
	int cur = 0;
	for (int i = 0; i < n; ++i) {
	  string s; cin >> s;
	  if (s == "A") ++cur;
	  else --cur;
	  if (cur < 0) ok = false;
	}
	if (cur != 0) ok = false;
	if (ok) puts("YES");
	else puts("NO");
  }
}



Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;

int main() {
  vector<pair<double,string> > V[3], U;
  for(int i = 0; i < 24; ++i) {
    pair<double,string> p;
    cin >> p.second >> p.first;
    V[i/8].push_back(p);
  }
  for(int k = 0; k < 3; ++k) {
    sort(V[k].begin(), V[k].end());
    for(int j = 2; j < V[k].size(); ++j) {
      U.push_back(V[k][j]);
    }
  }
  sort(U.begin(), U.end());
  for(int k = 0; k < 3; ++k) {
    for(int j = 0; j < 2; ++j) {
      printf("%s %.2f\n", V[k][j].second.c_str(), V[k][j].first);
    }
  }
  for(int j = 0; j < 2; ++j) {
    printf("%s %.2f\n", U[j].second.c_str(), U[j].first);
  }
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  long double l;
  cin>>l;
  long double ans=pow(l/3, 3.0);
  cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
N, K = gets.split(" ").map(&:to_i)
H = gets.split(" ").map(&:to_i)
dp = []
dp[0] = 0
(1...N).each{|i|
    min = Float::INFINITY
    (1..K).each{ |j|
        if i - j >= 0
            cost  = dp[i-j] + (H[i-j] - H[i]).abs
            min = cost if min > cost
        end
    }
    dp[i] = min
}
puts dp[N-1]

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

long long N, A, B, C, D;

int main() {
    scanf("%lld%lld%lld%lld%lld", &N, &A, &B, &C, &D);
    for (int i = 0; i != N; ++i) {
        if (N * C - C - i * (C + D) <= B - A && B - A <= N * D - D - i * (C + D)) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;

int n, k, c[11], a[4];
bool dp[11] = { false };
set<int> s;

inline int make(int* a) {
	int r = 0, f = 1;
	for (int i = 0; i < k; i++) {
		r += a[i] * f;
		f *= pow(10, (int)log10(a[i]) + 1);
	}
	return r;
}

int rec(int d = 0) {
	if (d == k) {
		int r = make(a);
		if (s.find(r) == s.end()) {
			s.insert(r);
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			if (!dp[i]) {
				a[d] = c[i];
				dp[i] = true;
				rec(d + 1);
				dp[i] = false;
			}
		}
	}
	return 0;
}

int main(){
	while (scanf("%d",&n), scanf("%d",&k), n != 0) {
		s = set<int>();
		for (int i = 0; i < n; i++) {
			scanf("%d", &c[i]);
		}
		rec();
		printf("%d\n", s.size());
	}

	return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    string a;
    cin >> a;
    a[3] = '8';
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void print_1(int j);
void print_2(int j);
int main(void)
{
	int H, W;
	scanf("%d %d", &H, &W);

	while( H != 0 || W != 0)
	{
		for(int i = 0; i < H; i++)
		{
			for(int j = 0; j < W; j++)
			{
				if(i % 2 == 0)
					print_1(j);
				else
					print_2(j);
			}
			printf("\n");
		}
		printf("\n");

		scanf("%d %d", &H, &W);
	}
	

	return 0;
}

void print_1(int j)
{
	if(j % 2 == 0)
		printf("#");
	else
		printf(".");
}

void print_2(int j)
{
	if(j % 2 == 0)
		printf(".");
	else
		printf("#");
}


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

int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;
  char tmp=S[0];
  int count=1;
  for(int i=1; i<N; i++){
    if(tmp==S[i]) continue;
    tmp=S[i];
    count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll A,B,M;
ll a[100010],b[100010];
int main(){
    cin>>A>>B>>M;
	ll minA=INF;
	for(ll i=0;i<A;i++){
		cin>>a[i];
		minA=min(minA,a[i]);
	}
	ll minB=INF;
	for(ll i=0;i<B;i++){
		cin>>b[i];
		minB=min(minB,b[i]);
	}
	ll ans=minA+minB;
	for(ll i=0;i<M;i++){
		ll x,y,c;
		cin>>x>>y>>c;
		ans=min(ans,a[x-1]+b[y-1]-c);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n,m,q;
    cin >> n >> m >> q;
    vi s(n),t(m);
    rep(i,n) cin >> s[i];
    rep(i,m) cin >> t[i];
    vi a(n,LINF),b(m,LINF);
    rep(i,n){
        int ind = lower_bound(all(t),s[i]) - t.begin();
        if(ind < m)a[i] = abs(s[i]-t[ind]);
        ind--;
        if(ind >= 0)a[i] = min(a[i], s[i] - t[ind]);
    }
    rep(i,m){
        int ind = lower_bound(all(s),t[i]) - s.begin();
        if(ind < n)b[i] = abs(t[i]-s[ind]);
        ind--;
        if(ind >= 0)b[i] = min(b[i], t[i] - s[ind]);
    }
    /*
    rep(i,n)cout << " " << a[i];cout << endl;
    rep(i,m)cout << " " << b[i];cout << endl;
    */
    while(q--){
        int x;
        cin >> x;
        int ans = LINF;
        int ind = lower_bound(all(s),x) - s.begin();
        if(ind < n)ans = min(ans, abs(s[ind]-x) + a[ind]);
        if(ind)ans = min(ans, abs(s[ind-1]-x) + a[ind-1]);
        ind = lower_bound(all(t),x) - t.begin();
        if(ind < m)ans = min(ans, abs(t[ind]-x) + b[ind]);
        if(ind)ans = min(ans, abs(t[ind-1]-x) + b[ind-1]);
        cout << ans << endl;
    }
}


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

int main() {
  int N;
  int A;
  int B;
  
  cin >> N;
  cin >> A;
  cin >> B;
  
  if((N*A) > B){
    cout << B << endl;
  }else{
    cout << (N*A) << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner;

    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        long a = nextLong();
        long v = nextLong();
        long b = nextLong();
        long w = nextLong();
        long t = nextLong();
        double temp = Math.abs(b -a ) * 1.0 / (v-w) *1.0;
        if (temp < 0) {
            System.out.println("NO");
        } else {
            if (temp <= t) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }

    public static void println(Object o) {
        System.out.println(o);
    }

    public static void print(Object o) {
        System.out.print(o);
    }

    public static void printf(String format, Object... o) {
        System.out.printf(format, o);
    }

    public static int nextInt() {
        return Integer.parseInt(scanner.next());
    }

    public static long nextLong() {
        return Long.parseLong(scanner.next());
    }

    public static double nextDouble() {
        return Double.parseDouble(scanner.next());
    }

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static void nextLine() {
        scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }

    public static int MOD = 1_000_000_007;
    public static int MAX = 100000;
    public static long[] fac = new long[MAX];
    public static long[] finv = new long[MAX];
    public static long[] inv = new long[MAX];

    public static void combinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    public static long combination(int n, int k) {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static long factorial(long n) {
        return n <= 0 ? 1 : n * factorial(n - 1);
    }
}

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

int main() {
    int n;
    cin >> n;
    ll sum[n];
    ll bsum = 0;
    rep(i, 0, n) {
        int a, b;
        cin >> a >> b;
        sum[i] = a + b;
        bsum += b;
    }

    sort(sum, sum + n, greater<int>());

    ll ans = 0;
    rep(i, 0, n) {
        if (i % 2 == 0) {
            ans += sum[i];
        }
    }

    ans -= bsum;

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


Measured memory_bytes: 1024
from collections import defaultdict
def main(): 
    N = int(input())
    words = [ "".join(sorted(list(input()))) for i in range(N)]
    w = defaultdict(int)

    for word in words:
        w[word] += 1
        
    pair = 0
    for k, v in w.items():
        if v >= 2:
            pair += v*(v-1)//2
    
    print(pair)

if __name__ == "__main__":
    main()

Measured memory_bytes: 19824
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int not_free_patterns(string &s,int i,vector<ll> &frees){
    if (i == s.length()-1){
        if(s[i] == '1'){
            return 3;
        }else{
            return 1;
        }
    }
    if(s[i] == '1'){
        return (2 * not_free_patterns(s,i+1,frees) + frees[i]) % BASE_NUM;
    }else{
        return not_free_patterns(s,i+1,frees);
    }
}

int main()
{
    // 整数の入力
    string s;
    cin >> s;
    vector<ll> frees;
    ll not_free = 1;
    ll free = 1;
    frees.push_back(1);
    for (int i = 1; i < s.length(); i++)
    {
        frees.push_back(frees[i - 1] * 3 % BASE_NUM);
    }
    reverse(frees.begin(),frees.end());

    // cout << frees.size() << endl;
     cout << not_free_patterns(s,0,frees) << endl;
    return 0;
}

Measured memory_bytes: 6004
#define NDEBUG
#include<deque>
#include<functional>
#include<utility>
#include<cstddef>
#include<cassert>

template<typename T, class Compare = std::less<T>>
class SlidingMinimum{
public:
	using value_compare = Compare;
	using value_type = T;
private:
	using size_type = std::size_t;
	using container_type = std::deque<std::pair<const value_type, size_type>>;
	container_type c;
	value_compare comp;
public:
	SlidingMinimum(const value_compare &x = value_compare()) :comp(x){}
	const value_type &top()const{
		return c.front().first;
	}
	const size_type top_index()const{
		return c.front().second - 1;
	}
	void push(const value_type &x){
		size_type s = 1;
		while (!c.empty() && comp(x, c.back().first)){
			s += c.back().second;
			c.pop_back();
		}
		c.push_back(std::pair<const value_type, size_type>(x, s));
	}
	void push(value_type &&x){
		size_type s = 1;
		while (!c.empty() && comp(x, c.back().first)){
			s += c.back().second;
			c.pop_back();
		}
		c.push_back(std::pair<const value_type, size_type>(std::move(x), s));
	}
	void pop(){
		assert(!c.empty());
		if (!(--c.front().second))
			c.pop_front();
	}
	void clear(){
		c.clear();
	}
};


#include<cstdio>
#include<utility>

int main(){
	int n, l;
	scanf("%d%d", &n, &l);
	SlidingMinimum<int> S;
	int a;
	n -= l;
	while (l--){
		scanf("%d", &a);
		S.push(a);
	}
	printf("%d", S.top());
	while (n--){
		S.pop();
		scanf("%d", &a);
		S.push(a);
		printf(" %d", S.top());
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 3244
n = int(input())
grid = []
for i in range(n):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)

c = 0
for i in range(n-2):
    if grid[i][0] == grid[i][1] and grid[i+1][0] == grid[i+1][1] and grid[i+2][0] == grid[i+2][1]:
        c = 1

if c == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9068
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn readu() -> usize {
    read::<usize>()
}

#[allow(dead_code)]
fn readi() -> i32 {
    read::<i32>()
}

fn main() {
    input! {
        n: usize,
        mut a: [usize; n + 1],
        mut b: [usize; n],
    }

    let mut ans = 0;
    for i in 0..n {
        let d = std::cmp::min(a[i], b[i]);
        ans += d;
        b[i] -= d;

        let d2 = std::cmp::min(b[i], a[i + 1]);
        ans += d2;
        a[i + 1] -= d2;
    }
    println!("{}", ans);
}


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

void b(int n, vector<string> s) {
  int ac = 0, wa = 0, tle = 0, re=0;
  for(int i=0;i<n;i++) {
    if(s[i] == "AC") {
      ac++;
    }
    if(s[i] == "WA") {
      wa++;
    }
    if(s[i] == "TLE") {
      tle++;
    }
    if(s[i] == "RE") {
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++) {
    cin >> s[i];
  }
  b(n, s);
}



Measured memory_bytes: 9484
#include<bits/stdc++.h>
using namespace std;
int a, b, c, x, ans;
int main(){
    cin >> a >> b >> c >> x;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                ans += (i * 500 + j * 100 + k * 50 == x);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    # print (s,t)
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(s))
print (ans)

Measured memory_bytes: 9144
#include <stdio.h>

int main(){
  int a, b, c, count;
  int flag = 0;
  scanf("%d %d %d", &a, &b, &c);

  count = (int)(b / a);
  if(count > c){
    count = c;
  }
  /* while(flag == 0){ */
  /*   if(b > a && count < c){ */
  /*     b -= a; */
  /*     count++; */
  /*   } */
  /*   if(b < a || count == c){ */
  /*     flag = 1; */
  /*   } */
  /* } */
  
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf = 10e17;
const ll mod = inf;//1000000007;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);


ll mulmod(ll x, ll y)
{
	return (x * y) % mod;
}

ll submod(ll x, ll y)
{
	return (x - y + 100 * mod) % mod;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r/2);
		return mulmod(y, y);
	}
	else
	{
		ll y = power(n, (r-1)/2);
		return n * mulmod(y, y) % mod;
	}
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);
	
	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i-1], i);
	}
	
	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	// n (n-1) ... (n-r)
	if ( r == n || r == 0 ) { return 1; }

	ll ans = 1;
	for (ll i = 0; i < r; i++)
		ans = mulmod(ans, n - i);

	 return mulmod(ans, inv[r]);
	// return mulmod(perm[n], mulmod(inv[n-r], inv[r]));
}

bool binary_check(ll mid, ll key)
{
	return mid >= key;
}

ll binary_search()
{
//	ll ng = 0;
//	ll ok = x;
//
//	while (abs(ok - ng) > 1)
//	{
	//	ll mid = (ok+ng) / 2;
	//	if (binary_check(mid, k)) ok = mid;
	//	else ng = mid;
	//}

	return 0;
	//return ok;
}

void pushorcreate(map<ll, vector<ll>> &m, ll key, ll i)
{
	if (m.find(key) == m.end())
	{
		m[key] = vector<ll>(1, i);
	}
	else {
		m[key].push_back(i);
	}
}

ll solve(void)
{
	ll n, m;
	cin >> n >> m;

	cout << (n*(n-1))/2 + (m*(m-1)/2) << endl;

	return 0;
}

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


Measured memory_bytes: 384
n=int(input())
l=[tuple(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:x[0])
s=set()
fa=n-1
if(n==1):
    print(1)
    quit()
for i in range(n):
    for j in range(i+1,n):
        x,y=sorted([l[i],l[j]],key=lambda x:x[0])
        p=l[j][0]-l[i][0]
        q=l[j][1]-l[i][1]
        s=set(l)
        ans=n
        for x,y in l:
            if((x+p,y+q) in s):
                ans-=1
        fa=min(fa,ans)
print(fa)

Measured memory_bytes: 42732
struct csr{E}
    start::Array{Int}
    elist::Array{E}

    function csr{E}(n::Int, edges::Array{Pair{Int, E}}) where E
        start = zeros(Int, n + 1)
        elist = Array{E}(undef, length(edges))
                
        for e in edges
            start[e[1] + 1] += 1
        end
        
        for i = 2:n+1
            start[i] += start[i - 1]
        end

        counter::Array{Int} = copy(start)
        for e in edges
            elist[counter[e[1]] + 1] = e[2] 
            counter[e[1]] += 1
        end

        new{E}(start, elist)
    end
end

struct edge
    to::Int
end

mutable struct scc_graph
    n::Int
    edges::Array{Pair{Int, edge}}

    scc_graph(n::Int) = new(n, Array{Pair{Int, edge},1}())
end

num_vertices(sg::scc_graph)::Int = sg.n

function add_edge!(sg::scc_graph, from::Int, to::Int)
    new_edge = Pair{Int, edge}(from, edge(to))
    push!(sg.edges, new_edge)
end

function dfs_for_scc!(v::Int, g::csr{edge}, ord_group::Array{Int},
    visited::Array{Int}, low::Array{Int}, ord::Array{Int},
    ids::Array{Int}, sg::scc_graph)
    low[v] = ord_group[1]
    ord[v] = ord_group[1]
    ord_group[1] += 1
    push!(visited, v)
    for i = g.start[v] + 1:g.start[v + 1]
        to = g.elist[i].to
        if ord[to] == -1
            dfs_for_scc!(to, g, ord_group, visited, low, ord, ids, sg)
            low[v] = min(low[v], low[to])
        else
            low[v] = min(low[v], ord[to])
        end
    end

    if low[v] == ord[v]
        while true
            u = pop!(visited)
            ord[u] = sg.n
            ids[u] = ord_group[2]
            if u == v
                break
            end
        end
        ord_group[2] += 1
    end
end

function scc_ids(sg::scc_graph)::Pair{Int, Array{Int}}
    g = csr{edge}(sg.n, sg.edges)
    ord_group = [1, 0] 
    visited = Array{Int,1}()
    low = zeros(Int, sg.n)
    ord = [-1 for i = 1:sg.n]
    ids = zeros(Int, sg.n)

    for i = 1:sg.n
        if ord[i] == -1
            dfs_for_scc!(i, g, ord_group, visited, low, ord, ids, sg)
        end
    end

    for i = 1:sg.n
        ids[i] = ord_group[2] - ids[i]
    end

    Pair{Int, Array{Int}}(ord_group[2], ids)
end

function scc(sg::scc_graph)
    ids = scc_ids(sg)
    group_num = ids[1]
    counts = zeros(Int, group_num)
    for x in ids[2]
        counts[x] += 1
    end
    groups = [Array{Int, 1}() for i = 1:group_num]
    for i = 1:sg.n
        push!(groups[ids[2][i]], i)
    end

    groups
end

parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
parseVertex(x) = string(x-1)

function main()
    N,M = readline() |> split |> parseMap
    sg = scc_graph(N)
    for i = 1:M
        a,b = readline() |> split |> parseMap
        add_edge!(sg, a+1, b+1)
    end

    groups = scc(sg)
    println(length(groups))
    for group in groups
        l = length(group)
        println(string(l) * " " * join(map(parseVertex, group)," "))
    end
end

main()

Measured memory_bytes: 533072
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

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

  vector<vector<int>> G(n);
  vector<P> vp;
  for(int i=1,a,b; i<n; i++){ 
    cin >> a >> b; a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a,b);
  }
  
  int k=0;					//iro kazu
  map<P,int> I;
  vector<int> cs(n,0);// color of edge between its parent
  vector<int> used(n,0);
  queue<int> que;
  used[0]=1;
  que.emplace(0);
  
  while(!que.empty()){
    int v=que.front(); que.pop();
    if(k<G[v].size()){ k=G[v].size(); }
    
    int cur=1;
    for(int u:G[v]){
      if(used[u]){ continue; }
      if(cur==cs[v]){ cur++; }
      cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
      used[u]=1;
      que.emplace(u);
    }
  }
  
  cout << k << endl; 
  for(auto p:vp){ cout << I[p] << endl;}
  return 0;
}  

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

int main() {
  std::string s;
  int q, t, f;
  char c;

  std::cin >> s;
  std::cin >> q;

  bool reverse = false;
  std::vector<char> front;
  std::vector<char> back;
  front.reserve(q);
  back.reserve(q);

  for (int i = 0; i < q; i++) {
    std::cin >> t;

    if (t == 1) {
      reverse = !reverse;
    } else {
      std::cin >> f;
      std::cin >> c;

      if (f == 1) {
        if (!reverse) {
          front.push_back(c);
        } else {
          back.push_back(c);
        }
      } else {
        if (!reverse) {
          back.push_back(c);
        } else {
          front.push_back(c);
        }
      }
    }
  }

  if (!reverse) {
    for(std::vector<char>::const_reverse_iterator itr = front.rbegin(); itr != front.rend(); ++itr) {
      std::cout << *itr;
    }
    std::cout << s;
    for(std::vector<char>::const_iterator itr = back.begin(); itr != back.end(); ++itr) {
      std::cout << *itr;
    }
    std::cout << std::endl;
  } else {
    for(std::vector<char>::const_reverse_iterator itr = back.rbegin(); itr != back.rend(); ++itr) {
      std::cout << *itr;
    }
    std::reverse(s.begin(), s.end());
    std::cout << s;
    for(std::vector<char>::const_iterator itr = front.begin(); itr != front.end(); ++itr) {
      std::cout << *itr;
    }
    std::cout << std::endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<string> hyou(n);
		for (int i = 0; i < n; i++) {
			cin >> hyou[i];
		}
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < hyou[i].size(); j++) {
				if (hyou[i][j] == '.') {
					hyou[i][j] = ' ';
				} else {
					hyou[i][j-1] = '+';
					break;
				}
			}
		}
		int a = -1;
		for (int i = 1; i < n; i++) {
			int b = hyou[i].find('+');
			if (b < a) {
				for (int j = i-1; j >= 0; j--) {
					if (hyou[j][b] == ' ') {
						hyou[j][b] = '|';
					} else {
						break;
					}
				}
			}
			a = b;
		}
		for (int i = 0; i < n; i++) {
			cout << hyou[i] << endl;
		}
	}
	return 0;
}

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

  string S, T; cin >> S >> T;
  int A, B; cin >> A >> B;
  string U; cin >> U;
  
  if(S==U) {A--;}
  else if(U==T) {B--;}
  
  cout << A << " " << B <<endl;
}

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

using namespace std;

bool chk[10];
int n, ans = 1e9;

void f(int x, int t) {
	if (x == 6) {
		if (t >= n)
			ans = min(ans, t);

		return;
	}

	for (int i = 0; i <= 9; ++i)
		if (!chk[i])
			f(x + 1, t * 10 + i);
}

int main() {
	int k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= k; ++i) {
		int x;
		scanf("%d", &x);
		chk[x] = true;
	}

	for (int i = 0; i < 6; ++i)
		f(i, 0);

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<deque>
#include<set>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;

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

int main(void)
{
  ll w, h;

  cin >> w >> h;

  ll result = LLINF;

  rep(i,w) {
    ll wDivSize = i * h;
    ll newW = w - i;
    ll wBunkatsu2 = newW / 2;
    vector<ll> allSize;
    allSize.push_back(wDivSize); allSize.push_back(wBunkatsu2*h); 
    if (newW & 1) allSize.push_back((wBunkatsu2+1)*h);
    sort(allSize.begin(), allSize.end());
    result = min(result, allSize.back() - allSize.front());

    ll wBunkatsuH = h / 2;
    vector<ll> allSize2;
    allSize2.push_back(wDivSize); allSize2.push_back(wBunkatsuH*newW);
    if (h & 1) allSize2.push_back((wBunkatsuH+1)*newW);
    sort(allSize2.begin(), allSize2.end());
    result = min(result, allSize2.back() - allSize2.front());
  }

  rep(i, h) {
    ll hDivSize = i * w;
    ll newH = h - i;
    ll hBunkatsu2 = newH / 2;
    vector<ll> allSize3;
    allSize3.push_back(hDivSize); allSize3.push_back(hBunkatsu2*w); 
    if (newH & 1) allSize3.push_back((hBunkatsu2+1)*w);
    sort(allSize3.begin(), allSize3.end());
    result = min(result, allSize3.back() - allSize3.front());

    ll hBunkatsuW = w / 2;
    vector<ll> allSize4;
    allSize4.push_back(hDivSize); allSize4.push_back(hBunkatsuW*newH);
    if (w & 1) allSize4.push_back((hBunkatsuW+1)*newH);
    sort(allSize4.begin(), allSize4.end());
    result = min(result, allSize4.back() - allSize4.front());
  }

  cout << result << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int X;

	public void solve() {
		X = nextInt();
		int sum = 0;
		int i = 0;
		for(;sum < X;i++){
			sum += i;
		}

		out.println(i-1);
	}
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int n,m,ans=0;
	cin >> n >> m;
    vec(a,m);
    vec(b,m);
    vec(c,n);
    vec(d,n);
    REP(i,n){
        c[i] = 0;
        d[i] = 1;
    }
    c[0] = 1;
    REP(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        d[a[i]]--;
        d[b[i]]++;
        if(c[a[i]] == 1){
            c[b[i]]= 1;
        }
        if(d[a[i]] == 0){
            c[a[i]] = 0;
        }
    }
    REP(i,n){
        if(c[i] == 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    print(max(0,min(R) - max(L) + 1))


# Generated by 1.1.4 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
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]" 
    R = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10868
#include <stdio.h>
#pragma warning(disable : 4996)

int main(){

	int a, b, c, i;
	int count = 0;

	scanf("%d %d %d", &a, &b, &c);

	for (i = a; i <= b; i++){
		if ((c % i) == 0)	count++;
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 596
N = int(input())
T,A= map(int,input().split())
H = list(map(int,input().split()))
dif=100000
ans=0
for i in range (len(H)):
    a = abs(A-(T-H[i]*0.006))
    dif=min(a,dif)
    if dif==a:
        ans=i+1

print(ans)

Measured memory_bytes: 3064
import sys
def input(): return sys.stdin.readline().strip()


def main():
    S = input()
    T = input()
    """
    置換が互換の積でかけることから、S->Tの変換がアルファベットの置換で表現できればよい。
    """
    d = {chr(i + 97): -1 for i in range(26)}
    d_inv = {chr(i + 97): -1 for i in range(26)}
    for i, s in enumerate(S):
        t = T[i]
        if d[s] != -1 or d_inv[t] != -1:
            if d[s] != t or d_inv[t] !=s:
                print("No")
                return
        d[s] = t
        d_inv[t] = s
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 41968
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<int> primes;

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void pm(int N){
    vector<int> num;
    for(int i = 2; i <= N; ++i) num.pb(i);
    while(num.size()){
        primes.pb(num[0]);
        for(int j = num.size()-1;j>=0;--j){
            if(num.at(j) % num.at(0) == 0) num.erase(num.begin() + j);
        }
    }
}

ll solve(int N){
    pm(100);
    vector<int> pms(150);
    rep(j,sz(primes)) if(primes[j] <= N){
        int tp = primes[j], ct = 1;
        while(tp <= N) pms[primes[j]]+=N/tp, tp *= primes[j], ct++;
    }

    int ans = 0;
    int c74 = 0,c24 = 0, c14 = 0, c4 = 0, c2 = 0;
    rep1(i,N){
        int j = pms[i];
        if(j >= 74) c74++;
        if(j >= 24) c24++;
        if(j >= 14) c14++;
        if(j >= 4) c4++;
        if(j >= 2) c2++;
    }
    COMinit();
    ans = c74 + c24*(c2-1) + c14*(c4-1) + COM(c4,2)*(c2-2);
    return ans;
}

int main(){
    ll N; cin >> N;
    pr(solve(N));
    return 0;
}

Measured memory_bytes: 12160
import sys

result = []
grade = []
for i in sys.stdin:
    m, f, r = map(int, i.split())
    if m == f == r == -1:
        break
    result.append([m, f, r])

for j in range(len(result)):
    sum = result[j][0] + result[j][1]
    if result[j][0] == -1 or result[j][1] == -1 or sum < 30:
        grade.append('F')
    elif sum >= 80:
        grade.append('A')
    elif 65 <= sum < 80:
        grade.append('B')
    elif 50 <= sum < 65:
        grade.append('C')
    elif 30 <= sum < 50:
        grade.append('D')
        if result[j][2] >= 50:
            grade[j] = 'C'

for k in range(len(grade)):
    print(grade[k])

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

using namespace std;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	int i ,j,k, diff =  INT_MAX, n=s.size();
	for(i = 0 ; i <= n-3 ; ++i)
		if(diff > abs((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0') - 753))
			diff = abs((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0') - 753);
	cout << diff;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
# 拡張ユークリッド互除法
# gcd(a,b)とax+by=gcd(a,b)の最小整数解を返す
def exgcd(a,b):
    if a==0:
        return b,0,1
    else:
        g,y,x=exgcd(b%a,a)
        return g,x-(b//a)*y,y

# 二元の場合の中国剰余定理
# x≡b1(mod m1)かつx≡b2(mod m2)⇔x≡r(mod m)となる(r,m)を返す
# 解なしの時(0,-1)
def crt(b1,m1,b2,m2):
    d,p,q=exgcd(m1,m2)
    if (b2-b1)%d!=0 or d!=1:
        return 0,-1
    m=m1*(m2//d) # m=lcm(m1,m2)
    tmp=(b2-b1)//d*p%(m2//d)
    r=(b1+m1*tmp)%m
    return r,m

ans=10**18
for num in range(1,2*n+1):
    if num*num>2*n:
        break
    if 2*n%num==0:
        r1,m1=crt(0,num,-1,2*n//num)
        r2,m2=crt(0,2*n//num,-1,num)
        if r1!=0:
            ans=min(r1,ans)
        if r2!=0:
            ans=min(r2,ans)
print(ans)

Measured memory_bytes: 72092
import java.util.Scanner;

public class Main {
	
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		solve(n);
		System.out.println("No");
	}
	
	static void solve(int n) {
		if(n - 4 == 0 || n - 7 == 0) {
			System.out.println("Yes");
			System.exit(0);
		}
		if(n-4>0) solve(n-4);
		if(n-7>0) solve(n-7);
	}
}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

template<class T> int LIS(vector<T> a) {
    const T INF = 1<<30; // to be set appropriately
    int n = (int)a.size();
    vector<T> dp(n, INF);
    for (int i = 0; i < n; ++i) {
        *upper_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }
    return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}

int main()
{
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        int tmp; cin >> tmp;
        a[i] = -1 * tmp;
    }
    int ans = LIS(a);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
import fileinput

input = fileinput.input()

while True:
    n = int(next(input).strip())
    if not n: break
    t = [0, 0]
    for _ in range(n):
        [a, b] = map(int, next(input).strip().split())
        if a == b:
            t[0] += a
            t[1] += b
        else:
            t[a < b] += a + b
    print(' '.join(map(str, t)))

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

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

const int INF = 1000000007;

int main(){
	int n; cin>>n;
	int s[110]={0};
	int val=0;
	for(int i=0;i<n;i++){
		cin>>s[i];
		val += s[i];
	}

	sort(s, s+n);
	int ans = val;
	for(int i=1;i<=n;i++){
		if(ans % 10 != 0){
			cout<< ans <<endl;
			return 0;
		}
		else{
			val -= s[i-1];
			ans = val;
		}
		val += s[i-1];
	}

	cout<< 0 <<endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){

    int N, K;
    cin >> N >> K;

    vector<int> nw(N + 1), nxt(N + 1);
    for(int i = 0; i < N; i++){
        cin >> nw[i];
    }
    
    if (K > (int)(2.0 * log2(N)) + 10) {
        for (int i = 0; i < N; i++) {
            cout << N << " ";
        }
        cout << endl;
        return 0;
    }
    
    for (int l = 0; l < K; l++) {

        for (int i = 0; i < N; i++) {
            int l = i - nw[i], r = i + nw[i];
            if (l < 0)l = 0;
            if (r > N - 1)r = N - 1;
            nxt[l]++, nxt[r + 1]--;
        }

        for (int i = 1; i < N; i++)nxt[i] += nxt[i - 1];
        swap(nw, nxt);
        nxt.clear();
        nxt.resize(N + 1);
    }
    for (int i = 0; i < N; i++)cout << nw[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 4848
import scala.io.StdIn


object Main extends App {
  val s  = StdIn.readLine.toString

  def solve(s: String) : String  = {
    var b = ' '
    s.foreach {v =>
      if (v == b) return "Bad" else b = v
    }
    "Good"
  }
  println(solve(s))

}
  



Measured memory_bytes: 25532