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

const int inf = 1e9;
const ll linf = 1e18;

int main()
{
    string s, t; cin >> s >> t;
    vector<int> l[26];
    for (int i = 0; i < s.length(); i++) {
        l[s[i] - 'a'].push_back(i);
    }

    int rep = 0, pos = -1;
    for (int i = 0; i < t.length(); i++) {
        if (l[t[i] - 'a'].empty()) {
            cout << -1 << endl;
            return 0;
        }

        auto it = upper_bound(l[t[i] - 'a'].begin(), l[t[i] - 'a'].end(), pos);
        if (it == l[t[i] - 'a'].end()) {
            rep++;
            pos = l[t[i] - 'a'].front();
        } else {
            pos = *it;
        }
    }

    ll ans = s.length() * rep + pos + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1216
k, n = map(int, input().split())
A = list(map(int, input().split()))

maxdist = 0
for i in range(n - 1):
    dist = A[i+1]-A[i]
    maxdist = max(maxdist, dist)
    # print(f'maxdist=max({maxdist},{dist})={max(maxdist,dist)}')
else:
    dist = A[0] + k - A[n-1]
    maxdist = max(maxdist, dist)
    # print(f'maxdist=max({maxdist},{dist})={max(maxdist,dist)}')

ans = k - maxdist
# print(maxdist)
print(ans)

Measured memory_bytes: 26436
#include<stdio.h>
#include<vector>
#include<queue>
#include<map>
#define INF 200000000
using namespace std;
typedef pair<int,int> P;
vector<P> e[100000];
vector<P> te[100000];
int d[100000];
bool used[100000];
int bfr[100000];
int dep[100000];
int par[20][100000];
int cos[20][100000];
int n,m,s,q;
priority_queue< P,vector<P>,greater<P> > que;
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
void dykstra(){
	int i;
	while(!que.empty()){
		P p=que.top();que.pop();
		int v=p.second;
		if(p.first>d[v])continue;
		for(i=0;i<e[v].size();i++){
			int u=e[v][i].first;
			int cost=e[v][i].second;
			if(d[u]>d[v]+cost){
				d[u]=d[v]+cost;
				que.push(P(d[u],u));
			}
		}
	}
}
void kraskal(){
	int i;
	for(i=0;i<n;i++){
		used[i]=false;
		d[i]=INF;
		bfr[i]=-1;
	}
	d[0]=0;
	que.push(P(0,0));
	while(!que.empty()){
		P p=que.top();que.pop();
		int v=p.second;
		if(p.first>d[v])continue;
		used[v]=true;
		if(bfr[v]!=-1){
			te[v].push_back(P(bfr[v],-d[v]));
			te[bfr[v]].push_back(P(v,-d[v]));
		}
		for(i=0;i<e[v].size();i++){
			int u=e[v][i].first;
			int cost=e[v][i].second;
			if(!used[u]&&d[u]>cost){
				d[u]=cost;
				bfr[u]=v;
				que.push(P(d[u],u));
			}
		}
	}
}
void dfs(int v,int p,int depth){
	dep[v]=depth;
	for(int i=0;i<te[v].size();i++){
		int u=te[v][i].first;
		if(u==p)continue;
		par[0][u]=v;
		cos[0][u]=te[v][i].second;
		dfs(u,v,depth+1);
	}
}
int lca(int a,int b){
	if(dep[a]>dep[b]){int p=a;a=b;b=p;}
	int dif=dep[b]-dep[a];
	int ans=INF;
	int i;
	for(i=0;i<20;i++){
		if(dif>>i&1){
			ans=min(ans,cos[i][b]);
			b=par[i][b];
		}
	}
	if(a==b)return ans;
	for(i=19;i>=0;i--){
		if(par[i][a]!=par[i][b]){
			ans=min(ans,cos[i][a]);
			ans=min(ans,cos[i][b]);
			a=par[i][a];
			b=par[i][b];
		}
	}
	ans=min(ans,cos[0][a]);
	ans=min(ans,cos[0][b]);
	return ans;
}
	
int main(){
	scanf("%d %d %d %d",&n,&m,&s,&q);
	int i,j;
	for(i=0;i<m;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		a--;b--;
		e[a].push_back(P(b,c));
		e[b].push_back(P(a,c));
	}
	for(i=0;i<n;i++)d[i]=INF;
	for(i=0;i<s;i++){
		int p;
		scanf("%d",&p);
		d[p-1]=0;
		que.push(P(0,p-1));
	}
	dykstra();
	for(i=0;i<n;i++){
		for(j=0;j<e[i].size();j++){
			e[i][j].second=-min(d[i],d[e[i][j].first]);
		}
	}
	kraskal();
	for(i=0;i<20;i++)for(j=0;j<n;j++){
		par[i][j]=-1;
		cos[i][j]=INF;
	}
	dfs(0,-1,0);
	for(i=1;i<20;i++){
		for(j=0;j<n;j++){
			if(par[i-1][j]!=-1){
				par[i][j]=par[i-1][par[i-1][j]];
				cos[i][j]=min(cos[i-1][j],cos[i-1][par[i-1][j]]);
			}
		}
	}
	for(i=0;i<q;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		printf("%d\n",lca(a-1,b-1));
	}
	return 0;
}

Measured memory_bytes: 32384
import itertools

n,m,q = map(int,input().split())
mylist = [list(map(int, input().split())) for i in range(q)]
#print(mylist)

kouho = []
for i in range(1, m+1):
  kouho.append(i)
#print(kouho)

A = list(itertools.combinations_with_replacement(kouho,n))
#print(A)

point = 0
maxp = 0
for a in A:
  point = 0
  #print(a)
  for my in mylist:
    #print(my)
    #print(a[my[1]-1] - a[my[0]-1])
    #print(my[2])
    #print("")
    if a[my[1]-1] - a[my[0]-1] == my[2]:
      point += my[3]
      #print("yes")
      #print(point)
  #print(point)
  if point > maxp:
    maxp = point
    #print("max更新")
    #print(maxp)
print(maxp)
    



Measured memory_bytes: 21484
s = input()
t = input()
c1 = {}
c2 = {}
for i,j in zip(s,t):
    if i in c1:
      if c1[i] != j:
        a = "No"
        break
    else:
      c1[i] = j
    if j in c2:
      if c2[j] != i:
        a = "No"
        break
    else:
      c2[j] = i
else:
  a = "Yes"
print(a)

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

int main()
{
    string s,t;
    cin>>s>>t;
    int l1=s.length(),l2=t.length();
    int ans=1005;
    for(int i=0;i<=l1-l2;i++)
    {
        int temp=0;
        for(int j=0;j<l2;j++)
        {
            if(s[i+j]!=t[j])
            temp++;
        }
        ans=min(ans,temp);
    }
    cout<<ans;
}

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

int main()
{
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if(a1+a2+a3>21){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  int n,m; cin >> n >> m;
  vector<vector<int> > graph(n);
  int u,v,s,t;
  for(int i=0;i<m;++i){
    cin >> u >> v;
    graph[u-1].push_back(v-1);
  }
  cin >> s >> t;
  s--,t--;
  
  vector<vector<long long> > dist(n,vector<long long>(3,-1));
  dist[s][0]=0;
  queue<pair<int,int> > q;
  q.push(make_pair(s,0));
  while(!q.empty()){
    pair<int,int> now=q.front(); q.pop();
    int pto=(now.second+1)%3;
    for(auto to : graph[now.first]){
      if(dist[to][pto]!=-1) continue;
      dist[to][pto]=dist[now.first][now.second]+1;
      q.push(make_pair(to,pto));
    }
  }
  if(dist[t][0]==-1) cout << -1 << endl;
  else cout << dist[t][0]/3 << endl; 
  
  return 0;
}


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

int N,K;
int main(){
    cin >> N >> K;
    double ex[N];
    int p;
    for(int i =0;i<N;i++){
        cin >> p;
        int i_sum=0;
        for(int j =1;j<p+1;j++){
            i_sum += j;
        }
        ex[i] = (double)i_sum/p;
    }
    double tmp_maxi=0;
    for(int i = 0;i<K;i++){
        tmp_maxi += ex[i];      
    }     
    double maxi = tmp_maxi;
    for(int i = K;i<N;i++){
        tmp_maxi = tmp_maxi - ex[i-K] + ex[i];
        if(tmp_maxi>maxi){
            maxi = tmp_maxi;
        }
    }
    printf("%.12f\n",maxi);
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
int main()
{
    long long sum=1;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        sum*=i;
        sum%=mod;
    }
    cout<<sum%mod<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int ans = n  + (int)Math.pow(n,2) + (int)Math.pow(n,3);
        System.out.println(ans);
    }
}


Measured memory_bytes: 26984
#include <iostream>

using namespace std;

typedef long long ll;

int N;
int M=35;
ll X[1005];
ll Y[1005];

int main() {
        cin >> N;
        for (int i=0; i<N; i++)
                cin >> X[i] >> Y[i];

        bool seen_parity[2] = {false,false};
        for (int i=0; i<N; i++) {
                seen_parity[(X[i]+Y[i])%2] = true;
        }

        if (seen_parity[0] && seen_parity[1]) {
                cout << "-1\n";
                return 0;
        }

        if (seen_parity[0])
                cout << M+1 << "\n1\n";
        else
                cout << M << "\n";

        for (int i=M-1; i>=0; i--)
                cout << (1ll << i) << "\n";

        for (int i=0; i<N; i++) {
                if (seen_parity[0]) {
                        cout << "R";
                        X[i]--;
                }
                for (int j=M-1; j>=0; j--) {
                        if (X[i] > Y[i] && X[i] > -Y[i]) {
                                cout << "R";
                                X[i] -= (1ll << j);
                        } else if (Y[i] > X[i] && Y[i] > -X[i]) {
                                cout << "U";
                                Y[i] -= (1ll << j);
                        } else if (-X[i] > Y[i] && -X[i] > -Y[i]) {
                                cout << "L";
                                X[i] += (1ll << j);
                        } else {
                                cout << "D";
                                Y[i] += (1ll << j);
                        }
                }

                cout << "\n";
        }
}

Measured memory_bytes: 256
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

transport_capacities = [
    [1, a]
    ,[2, b]
    ,[3, c]
    ,[4, d]
    ,[5, e]
    ]


#               0  1  2  3  4  5  6
man_in_cties = [0, n, 0, 0, 0, 0, 0]

# 一番輸送力の低い手段
transport_capacities.sort(key=lambda x: x[1])
min_capa_id, capa = transport_capacities.pop(0)

total_time = (min_capa_id-1)

if n % capa > 0:
    total_time += n//capa + 1
else:
    total_time += n//capa

total_time += 5 - min_capa_id

print(total_time)


Measured memory_bytes: 38512
h, w = map(int, input().split())

area = []

for i in range(h):
    a = input()
    area.append(a)

for i in range(h+2):
    if i == 0:
        print('#'*(w+2))
    elif i == h+1:
        print('#'*(w+2))
    else:
        print('#'+area[i-1]+'#')





Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (c - a - b < 0)
    {
        cout << "No" << endl;
    }
    else
    {
        ll d = (c - a - b) * (c - a - b) - 4 * a * b;
        if (d > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3620
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
data = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]
min_id =0
max_id = 100000
for i in range(M):
  min_id = max(min_id,data[i][0])
  max_id = min(max_id,data[i][1])
num = max_id - min_id + 1 if max_id - min_id >= 0 else 0
print(num)

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

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

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



int main(){
   int h,w;
   cin>>h>>w;
   char a[h][w];
   rep(i,h){
      rep(j,w){
         cin>>a[i][j];
      }
   }

   vector<bool> gyou(h,false);
   vector<bool> retsu(w,false);

   rep(i,h){
      bool f=false;
      rep(j,w){
         if(a[i][j]=='#') f=true;
      }
      if(f==true) gyou[i]=true;
   }
   rep(i,w){
      bool f=false;
      rep(j,h){
         if(a[j][i]=='#') f=true;
      }
      if(f==true) retsu[i]=true;
   }

   rep(i,h){
      rep(j,w){
         if(gyou[i]==true && retsu[j]==true){
             cout<<a[i][j];
         }
      }
      if(gyou[i]!=false) cout<<endl;
   }
   

   return 0;
}



Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))
dp = [100000000000] * N
dp[0] = 0
for i in range(N -2):
    dp[i + 2] = min(dp[i + 2],dp[i] + abs(h[i + 2] - h[i]))
    dp[i + 1] = min(dp[i + 1],dp[i] + abs(h[i + 1] - h[i]))
dp[N - 1] = min(dp[N -1],dp[N - 2] + abs(h[N - 2] - h[N - 1]))
print(dp[N - 1])

Measured memory_bytes: 13908
#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;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
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
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
template<typename T>
void print_vec(vector<T>a) {
	for (int i = 0; i < a.size(); i++) {
		cout << (i == 0 ? "" : " ") << a[i];
	}
	cout << endl;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, k;
int a[101];
int dp[101][100001];
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j <= k; j++) {
			sum += dp[i][j];
			if (j > a[i]) sum -= dp[i][j - a[i] - 1];
			sum %= Mod;
			dp[i + 1][j] = sum % Mod;
		}
	}
	cout << (dp[n][k] + Mod) % Mod << endl;
}

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

using namespace std;

int count_div(long long num) {
	int res = 0;
	while (num%2 == 0) {
		++res;
		num /= 2;
	}
	return res;
}

int main(void) {
	int N;
	cin >> N;
	vector<long long> a(N);
	long long res = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		res += count_div(a[i]);
	}
	cout << res << endl;

	return 0;
}



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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N, L;
  cin >> N >> L;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int pos = -1;
  for (int i = 0; i + 1 < N; i++) {
    if (a[i] + a[i + 1] >= L) pos = i;
  }
  if (pos < 0) {
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;

  for (int i = 0; i < pos; i++) {
    cout << i + 1 << endl;
  }
  for (int i = N - 1; i > pos + 1; i--) {
    cout << i << endl;
  }
  cout << pos + 1 << endl;

  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <algorithm>
#define DEBUG 0
using namespace std;

int main()
{
    #if DEBUG
    freopen("test.txt", "r", stdin);
    #endif // DEBUG
    //取数据
    int N;
    scanf("%d",&N);
    int *Num = new int [N];

    for(int i=0;i<N;i++)
    {
        scanf("%d",&Num[i]);
    }
    int num4=0;
    int num2=0;
    int num1=0;
    for(int i=0; i<N; i++)
    {
        int temp = Num[i];
        if(temp%4 == 0){
            num4++;
        }else if(temp%2 ==0){
            num2++;
        }else{
            num1++;
        }
    }
    //计算结果
    if(num2 == 0 && num1 <= num4+1)
        printf("Yes\n");
    else if(num2 > 0 && num1 <= num4)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
struct node{
	int a,b;
}c[100005];
bool cmp(node a,node b){return a.b>b.b;}
int n,m,ans,f[100005];
int get(int x){return f[x]==x?x:f[x]=get(f[x]);}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>c[i].a>>c[i].b;
	sort(c+1,c+n+1,cmp);
	for(int i=1;i<=m;i++)
		f[i]=i;
	for(int i=1;i<=n;i++){
		int pos=get(c[i].a);
		if(pos){
			ans+=c[i].b;
			pos==m?f[m]=0:f[pos]=get(pos+1);
		}
	} 
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1536
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
    init();
    ll N;ll K;
    cin>>N>>K;
    vector<ll>count(N+2,0);
    vector<ll>A(N);
    for(int i=0;i<N;i++){
      cin>>A[i];
      count[A[i]]++;
    }
    sort(count.begin(),count.end(),greater<ll>());
    ll ans=N;
    for(int i=0;i<K;i++){
      ans-=count[i];
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    string s;
    rep(i,ty-sy){
        s+='U';
    }
    rep(i,tx-sx){
        s += 'R';
    }
    rep(i, ty - sy)
    {
        s += 'D';
    }
    rep(i, tx - sx)
    {
        s += 'L';
    }
    s += 'L';
    rep(i, ty-sy+1){
        s += 'U';
    }
    rep(i,tx-sx+1){
        s += 'R';
    }
    s += 'D';
    s += 'R';
    rep(i, ty - sy + 1)
    {
        s += 'D';
    }
    rep(i, tx - sx + 1)
    {
        s += 'L';
    }
    s += 'U';
    cout << s << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a=list()
for i in range(1,k+1):
  d=input()
  a.extend(list(map(int,input().split())))
set(a)
cnt=0
for f in range(1,n+1):
  if not(f in a):     
      cnt=cnt+1

print(cnt)


Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    string a, b;
    cin >> a >> b;
    int n = a.size();
    int m = b.size();
    bool bl = (m - n == 1);
    for(int i = 0; i < n; i++){
        bl &= (a[i] == b[i]);
    } 
    if(bl) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3628
n = int(input())
a = [0] + [int(input()) for i in range(n)]

end = {}

end[1] = True
to = a[1]

cnt = 0
while True:
    cnt += 1
    if to == 2:
        print(cnt)
        __import__("sys").exit()
    if end.get(to) == None:
        end[to] = True
        to = a[to]
    else:
        break

print(-1)


Measured memory_bytes: 16288
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int N,Q; cin>>N>>Q;

  vvi ed(N);
  rep(i, N-1){
    int a,b;cin>>a>>b;
    a--;b--;
    ed[a].pb(b);
    ed[b].pb(a);
  }

  vector<int> p(N);
  rep(q, Q){
    int i, x;
    cin>>i>>x;
    i--;
    p[i] += x;
  }

  vi ans(N, -1);
  auto dfs = [&](const auto& dfs, int x, int v) -> void {
    ans[x] = v;
    each(c, ed[x]){
      if (ans[c]==-1) dfs(dfs, c, v+p[c]);
    }
  };
  dfs(dfs, 0LL, p[0]);
  dump(ans);

  rep(i, sz(ans)) cout << ans[i] << (i!=sz(ans)-1 ? " " : "\n");

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

#define ll long long
using namespace std;

#define MAXN 200000
void solve()
{
	int A[2][MAXN],N,K,B[MAXN+1];
	cin>>N>>K;
	for(int i=0; i<N; ++i)
		cin>>A[0][i];
	
	bool changed = true;
	for(int i=1; i<=K && changed; ++i)
	{
		int curr = i%2;
		int prev = curr^1;
		for(int j=0; j<=N; ++j)
			B[j] = 0;
		for(int j=0; j<N; ++j)
		{
			int start = max(j-A[prev][j],0);
			int stop = min(j+A[prev][j]+1,N);
			++B[start];
			--B[stop];
		}
		int s = 0;
		for(int j=0; j<N; ++j)
		{
			s+=B[j];
			A[curr][j]=s;
		}
		changed = false;
		for(int j=0; j<N && (!changed); ++j)
			if(A[curr][j] != A[prev][j])
				changed = true;
	}
	cout<<A[K%2][0];
	for(int i=1; i<N; ++i)
		cout<<" "<<A[K%2][i];
	cout<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//int T;
    //cin>>T;
    //while(T--)
        solve();

	return 0;
}

Measured memory_bytes: 5992
#include <iostream>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void) {
    const double PI=3.14159;
    
    int r;
    
    cin >> r;
    
    cout << 2*PI*r << endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

struct UnionFind {
    vector<int> par;
    
    //要素nで初期化
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    //xが属する集合の根を返す
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    //xとyが同じ集合に属しているかを判定
    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    //xが属する集合とyが属する集合をマージ
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // 計算量が減るよ
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    //xが属する集合のサイズ
    int size(int x) {
        return -par[root(x)];
    }
};


int main(){
	int n,m;cin>>n>>m;
	vector<int> k(n);
	vector<vector<int>> lang(m);
	for(int i = 0; i < n; i++) {
		cin>>k[i];
		for(int j = 0; j < k[i]; j++) {
			int x;cin>>x;
			lang[x - 1].pb(i);
		}
	}

	UnionFind uf(n);
	for(int i = 0; i < m; i++) {
		for(int j = 1; j < lang[i].size(); j++) {
			uf.merge(lang[i][j - 1],lang[i][j]);
		}
	}
	if (uf.size(0) == n){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

	return 0;
}

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

int main() 
{
  int N, A, B;
  cin >> N >> A >> B;
  int plan1 = N * A;
  
  if (plan1 < B) cout << plan1 << endl;
  else cout << B << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()
using ll = long long;
using namespace std;

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> pp, mm;
    ll zero = 0;
    rep(i,n) {
        ll a; cin >> a;
        if (a > 0) pp.pb(a);
        else if (a < 0) mm.pb(-a);
        else zero++;
    }
    sort(all(pp)); ll p = (ll)pp.size();
    sort(all(mm)); ll m = (ll)mm.size();

    if (p * m >= k) {
        ll left = 1, right = 1ll<<60;
        while (right - left > 1) {
            ll mid = (right + left) / 2;
            ll count = 0;
            rep(i,p) {
                ll MIN = (pp[i] + mid - 1) / pp[i];
                ll id = lower_bound(all(mm), MIN) - mm.begin();
                count += m - id; 
            }
            if (count >= k) left = mid;
            else right = mid;
        }
        cout << -left << endl;
        return 0;
    }
    else if (p * m + (p + m) * zero + zero * (zero - 1) / 2 >= k) {
        cout << 0 << endl;
        return 0;
    }
    else {
        k -= p * m + (p + m) * zero + zero * (zero - 1) / 2;
        ll left = 1, right = 1ll<<60;
        while (right - left > 1) {
            ll mid = (right + left) / 2;
            ll count = 0;
            rep(i,p) {
                ll MIN = (pp[i] + mid) / pp[i]; // mid + 1 以上になる
                ll id = lower_bound(all(pp), MIN) - pp.begin();
                count += id;
                if (pp[i] * pp[i] <= mid) count--;
            }
            rep(i,m) {
                ll MIN = (mm[i] + mid) / mm[i]; // mid + 1 以上になる
                ll id = lower_bound(all(mm), MIN) - mm.begin();
                count += id;
                if (mm[i] * mm[i] <= mid) count--;
            }
            if (count < 2 * k) left = mid; 
            else right = mid;
        }
        cout << right << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 5188
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;

int main() {
	int n;
	cin >> n;
	
	string num = to_string(n);
	for (int i = 0; i < num.size(); ++i) {
		if (num.at(i) == '1') {
			num.at(i) = '9';
		}
		else if (num.at(i) == '9') {
			num.at(i) = '1';
		}
	}
	cout << num << endl;
}

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for (int i=0;i<N;i++) cin >> a[i];
    for (int i=0;i<N;i++) cin >> b[i];
    ll cnta = 0;
    ll cntb = 0;
    for (int i=0;i<N;i++){
        if (a[i] > b[i]) cntb += a[i]-b[i];
        else if (a[i] < b[i]) cnta += (b[i]-a[i])/2;
    }
    if (cnta >= cntb) cout << "Yes" << "\n";
    else cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
#include <atcoder/all>
using namespace atcoder;
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
using mint = modint998244353;
const mint inv9 = mint(1)/9;

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 modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

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

/*-----------------------------------------------------------------------------------------------------*/
struct S {
  mint x, w;
  S(mint x=0, mint w=1):x(x),w(w) {}
};
 
S op(S a, S b) {
  return S(a.x*b.w + b.x, a.w*b.w);
}
S e() { return S();}
 
S mapping(int f, S a) {
  if (f == 0) return a;
  return S((a.w-1)*inv9* f, a.w);
}
int composition(int f, int g) {
  if (f == 0) return g;
  return f;
}
int id() { return 0;}
 

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	lazy_segtree<S, op, e, int, mapping, composition, id> tree(n);
	rep(i,n) tree.set(i, S(1, 10));
	rep(i,q){
		int l, r, d; cin >> l >> r >> d;
		l--;
		tree.apply(l, r, d);
		S ans = tree.prod(0,n);
		printf("%d\n", ans.x.val());
	}
}

Measured memory_bytes: 9844
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

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

Measured memory_bytes: 2680
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cmath>
using namespace std;
 
 
int main() {
    string S, T;

    cin >> S >> T;

    vector< vector<int> > s(26);
    vector< vector<int> > t(26);
    
    for (int i = 0; i < S.size(); i++)  s[S[i]-'a'].push_back(i);
    for (int i = 0; i < T.size(); i++)  t[T[i]-'a'].push_back(i);
        
    string ans = "Yes";

    int  check_cnt = 0;
    int  true_cnt  = 0;
    for (int i = 0; i < 26; i++) {
        if (s[i].size() > 1) {
            check_cnt++;
            bool match = false;
            for(int j = 0; j < 26; j++) {
                if (s[i].size() == t[j].size()) {
                    int k;
                    for (k = 0; k < s[i].size(); k++) {
                        if (s[i][k] != t[j][k]) break;
                    }
                    if (k == s[i].size()) match = true;
                }
            }
            if (match) true_cnt++;
        }
    }
    if (check_cnt != true_cnt) ans = "No";

    check_cnt = 0;
    true_cnt  = 0;
    for (int i = 0; i < 26; i++) {
        if (t[i].size() > 1) {
            check_cnt++;
            bool match = false;
            for(int j = 0; j < 26; j++) {
                if (t[i].size() == s[j].size()) {
                    int k;
                    for (k = 0; k < t[i].size(); k++) {
                        if (t[i][k] != s[j][k]) break;
                    }
                    if (k == t[i].size()) match = true;
                }
            }
            if (match) true_cnt++;
        }
    }
    if (check_cnt != true_cnt) ans = "No";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  cin >> m;
  rep(i, m) {
    ll a;
    cin >> a;
    cout << distance(v.begin(), lower_bound(v.begin(), v.end(), a)) << ' ' << distance(v.begin(), upper_bound(v.begin(), v.end(), a)) << endl;
  }
}


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

int main() {
  string s,t,n;
  cin >> s >> t;
  n=s+s;
  if(n.find(t)<s.length()) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int main(){
vector<int> num(102,0);
for(int i = 0;i <=101;i++) num[i] = i;

int x, n, t;
cin >> n >> x ;

    if(x != 0){
for(int i = 0; i < x; i++){
  cin >> t;
  num[t] = 1000;
}
  bool judge = true;
    int dn = n - 1;
    int da = n + 1;
    while(judge){
            if(num[n] != 1000){
            dn = n;
            da = 1000;
            judge = false;     
        }
    else if(num[dn] != 1000 || num[da] != 1000){
            dn = num[dn];
            da = num[da];
            judge = false;        
        }
      else{
            dn--;
            da++;
                }
}
        cout << min(dn,da);
        }
        else cout << n;
}


Measured memory_bytes: 3516
#include <iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int x[105],y[105],h[105],H,n;

int jud(int xx,int yy,int p)
{
    H=h[p]+abs(xx-x[p])+abs(yy-y[p]);
    for(int i=1;i<=n;i++)
    {
        int z=max(0,H-abs(xx-x[i])-abs(yy-y[i]));
        if(z!=h[i])
            return 0;
    }
    return 1;
}

int main()
{
	scanf("%d",&n);
	int p=0;
	for(int i=1;i<=n;i++)
    {
        scanf("%d %d %d",&x[i],&y[i],&h[i]);
        if(!p && h[i]>0)
            p=i;
    }
	for(int i=0;i<=100;i++)
    {
        for(int j=0;j<=100;j++)
        {
            if(jud(i,j,p))
            {
                printf("%d %d %d\n",i,j,H);
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = []
point = [0] * N
for i in range(Q):
    A.append(int(input()))
    point[A[i]-1] += 1

for i in range(N):
    if K - Q + point[i] >= 1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 13688
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;

int main() {
    long long N, D, A, X, H;
    cin >> N >> D >> A;
    vector<pair<long long, long long> > vec;
    vec.reserve(N);
    for (long long i = 0;i < N;i ++) {
        cin >> X >> H;
        vec.push_back(pair<long long, long long>(X, H));
    }
    sort(vec.begin(), vec.end());
    long long dist = D * 2 + 1;
    long long ret = 0;
    long long total_hit(0), damege(0), end(0);
    queue<pair<long long, long long> > q;
    for (long long i = 0;i < N;i ++) {
        while(!q.empty() && vec[i].first >= q.front().first) {
            total_hit -= q.front().second;
            q.pop();
        }
        long long hp = vec[i].second - total_hit * A;
        if (hp < 1) {
            continue;
        }
        long long need = (hp + A - 1) / A;
        ret += need;
        q.push(pair<long long, long long>(vec[i].first + dist, need));
        total_hit += need;
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 4992
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

S = str(input())

if len(S)%2==0:
    if S == 'hi'*(len(S)//2):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int fa[maxn];
int Find(int x)
{
    if(x==fa[x]) return x;
    else return fa[x]=Find(fa[x]);
}
void Union(int a,int b)
{
    fa[Find(b)]=Find(a);
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) fa[i]=i;
    while(m--)
    {
        int u,v,d;
        cin>>u>>v>>d;
        if(Find(u)!=Find(v)) Union(u,v);
    }
    int ans=0;
    for(int i=1;i<=n;i++) if(fa[i]==i) ans++;
    cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] x = new int[N];
        int[] y = new int[N];
        int[] h = new int[N];
        for(int i = 0; i < N; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextInt();
        }
        for(int i = 0; i <= 100; i++) {
            for(int j = 0; j <= 100; j++) {
                int H = 0;
                boolean flag = true;
                for(int k = 0; k < N; k++) {
                    if(h[k] != 0) {
                        H = h[k] + Math.abs(x[k] - i) + Math.abs(y[k] - j);
                        break;
                    }
                }
                for(int k = 0; k < N; k++) {
                    if(h[k] != Math.max(H - Math.abs(x[k]-i) - Math.abs(y[k] - j), 0)) {
                        flag = false;
                    }
                }
                if(flag) {
                    System.out.println(i + " " + j + " " + H);
                }
            }
        }


    }
}


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

typedef unsigned long long ULL;

int N,Ans;
char S[605][605];
int Pow[605],Hash[2][605][605];

ULL Get_Hash(int x,int y,int l,int r){
	return Hash[x][y][r]-Hash[x][y][l-1]*Pow[r-l+1];
}

bool Check(int a,int b){
	int i,j;
	for(i=1;i<=N;i++)
		if(Get_Hash(0,a+i-1,b+i-1,b+N-1)!=Get_Hash(1,b+i-1,a+i-1,a+N-1))
			return false;
	return true;
}

int main(){
	int i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%s",S[i]);
	for(i=0;i<N;i++)	
		for(j=0;j<N;j++)
			S[i+N][j]=S[i][j+N]=S[i+N][j+N]=S[i][j];
	for(i=0;i<2*N;i++)
		for(j=0;j<2*N;j++){
			if(j)
				Hash[0][i][j]=Hash[0][i][j-1]*131+S[i][j]-'0'+1;
			else Hash[0][i][j]=S[i][j]-'0'+1;
		}
	for(j=0;j<2*N;j++)
		for(i=0;i<2*N;i++){
			if(i)
				Hash[1][j][i]=Hash[1][j][i-1]*131+S[i][j]-'0'+1;
			else Hash[1][j][i]=S[i][j]-'0'+1;
		}
	for(Pow[0]=i=1;i<=2*N;i++)
		Pow[i]=Pow[i-1]*131;
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			Ans+=Check(i,j);
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;
 
 class Main {
    public static void main(String[] args){ 
        
         Scanner shuru = new Scanner(System.in);   

        
        int a = shuru.nextInt();
        
        int b = shuru.nextInt();
        int hhh = a;
        
        for( int i = 1;i <= hhh;i ++){

        int c = a > b ? a : b;
            int d = a < b ? a : b;

            a = c % d;
            b = d;

            if(a == 0) {
                System.out.println(d);
                return;
            }

        }


}
}


Measured memory_bytes: 26216
#include<stdio.h>

int gcd(long int m, long int n){
    long int temp;
    while (m % n != 0){
        temp = n;
        n = m % n;
        m = temp;
    }
    return n;
}

int main(void){
    long int a,b,c,d;
    scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
    long int e,f,g,h,l,tmp;
    e = b/c;
    f = b/d;
    tmp = gcd(c,d);
    tmp = c*d/tmp;
    g = b/tmp;
    h = e+f-g;
    h = b-h;

    a--;
    e = a/c;
    f = a/d;
    g = a/tmp;
    l = e+f-g;
    l = a-l;

    long int ans = h-l;

    printf("%ld", ans);

    return 0;
}

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

int main() {

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

  long long answer = 0;

  if (K % 2 == 0) {
    int c1 = N / K;
    int c2 = N / (K / 2) - c1;
    answer =(long long) c1 * c1 * c1 + (long long) c2 * c2 * c2;
  } else {
    long long c = N / K;
    answer =(long long) c * c * c;
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 256
N,T = map(int,input().split())
c = []
t = []
for i in range(N):
  a,b = map(int,input().split())
  c.append(a)
  t.append(b)
result = []
for j in range(N):
  if T >= t[j]:
    result.append(c[j])
  else:
    None
print(min(result) if len(result) > 0 else "TLE")

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int N,M;
    cin >> N >> M;
    int A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N,greater<int>());
    int sum=accumulate(A,A+N,0);
    int border=ceil((double)sum/(4*M));
    bool ans=true;
    rep(i,M){
        if(A[i]<border) ans=false;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		try {
			int lim = Integer.parseInt(in.readLine());

			String[] nums = in.readLine().split(" ");
			int[] a = new int[nums.length];
			
			for (int i = 0; i < a.length; i++) {
				a[i] = Integer.parseInt(nums[i]);
			}
			
			int cnt = 0;
			for (int i = 0; i < a.length; i++) {
				for (int j = (a.length - 1); j > i; j--) {
					if (a[j] < a[j - 1]) {
						int tmp = a[j];
						a[j] = a[j - 1];
						a[j - 1] = tmp;
						cnt++;
					}
				}
			}
			
			System.out.print(a[0]);
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
			System.out.println();
			
			System.out.println(cnt);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        sum += v[i];
    }
    vector<ll> r = v;
    for (int i = 1; i < n; i++) {
        r[i] += r[i-1];
    }

    ll ans = 1e15;
    for (int i = 0; i < n-1; i++) {
        ans = min(ans, abs(r[i] - (sum - r[i])));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
c = []
for _ in range(3):
    c.append(list(map(int, input().split())))

for i in range(2):
    if c[i][0]-c[i][1]!=c[i+1][0]-c[i+1][1]:
        print('No')
        break
    if c[i][1]-c[i][2]!=c[i+1][1]-c[i+1][2]:
        print('No')
        break
    if c[i][2]-c[i][0]!=c[i+1][2]-c[i+1][0]:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 3064
#include <cmath>
#include <iostream>

int main(int argc, char const* argv[]) {
    long long a, b, x;
    std::cin >> a >> b >> x;

    if (a != 0) {
        std::cout << (b - (b % x)) / x - ((a - 1) - ((a - 1) % x)) / x << '\n';
    } else {
        std::cout << (b - (b % x)) / x + 1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#define MAX 200001

int main() {
    int n;
    int A[MAX];
    int min, max;
    
    
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &A[i]);
    }
    min = A[0];
    max = A[1] - A[0];
    for (int i = 1; i < n; i++) {
        max = max > A[i]-min ? max : A[i]-min;
        min = min < A[i] ? min : A[i];
    }
    printf("%d\n", max);
    
    return 0;
}

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

using namespace std;

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

    int N;
    cin >> N;
    string S;
    cin >> S;
    int res = 0;
    char c[3];
    for (c[0] = '0'; c[0] <= '9'; ++c[0]) {
        for (c[1] = '0'; c[1] <= '9'; ++c[1]) {
            for (c[2] = '0'; c[2] <= '9'; ++c[2]) {
                int j = 0;
                for (int i = 0; i < N && j < 3; ++i) {
                    if (S[i] == c[j]) {
                        ++j;
                    }
                }
                res += (j == 3);
            }
        }
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 384
N=input()
a=[]
t=True
for _ in range(int(N)):
    a+=[list(map(int,input().split()))]
for i in range(int(N)):
    if a[i][0]%2==0:
        if abs(a[i][1]+a[i][2])<=a[i][0] and (a[i][1]+a[i][2])%2==0:
            continue
        else:
            print('No')
            t=False
            break
    else:
        if abs(a[i][1]+a[i][2]<=a[i][0]) and (a[i][1]+a[i][2])%2==1:
            continue
        else:
            print('No')
            t=False
            break
if t:
    print('Yes')

Measured memory_bytes: 63064
#include<iostream>
#include<cstdio>
#include<algorithm>
#define INFTY (1>>30)
using namespace std;
int H,heap[2000001];
void maxHeapify(int i){
  int l,r,largest;
  l=i*2;
  r=i*2+1;                     

  if(l<=H&&heap[l]>heap[i]) largest=l;
  else largest=i;
  if(r<=H&&heap[r]>heap[largest]) largest=r;

  if(largest!=i){
    swap(heap[i],heap[largest]);
    maxHeapify(largest);
  }
}
void increasekey(int i,int key){
  if(key<heap[i]) return;
  heap[i]=key;
  while(i>1&&heap[i/2]<heap[i]){
    swap(heap[i/2],heap[i]);
    i=i/2;
  }
}
void insert(int key){
  H++;
  heap[H]=-INFTY;
  increasekey(H,key);
}
int extract(){
  int maxv;
  if(H<1) return -INFTY;
  maxv=heap[1];
  heap[1]=heap[H--];
  maxHeapify(1);
  return maxv;
}
int main(){
  int key;
  string com;
  while(1){
    cin>>com;
    if(com=="end") break;
    if(com=="insert"){
      scanf("%d",&key);
      insert(key);
    }else printf("%d\n",extract());
  }
  return 0;
}



Measured memory_bytes: 7252