akhauriyash/Code-Regression huggingface dataset:
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;

string yesorno = "Yes";
vector<vector<LL>> ans;

void solve(){
	//まず条件を満たせるかを確認
	LL sum = 0;
	LL numof_array;
	for(int i=1;;i++){
		sum += i;
		if(N==sum){
			numof_array = i;
			break;
		}
		if(N<sum){
			yesorno = "No";
			return;
		}
	}
	//実際に数列を作っていく
	ans = vector<vector<LL>>(1);
	int counter = 1;
	for(int i=1;i<=numof_array;i++){
		ans.push_back(vector<LL>(0));
		for(int j=0;j<=ans.size()-2;j++){
			ans[j].push_back(counter);
			ans[ans.size()-1].push_back(counter);
			counter++;
		}
	}
}
 
int main(){
    cin >> N;
 
    solve();

    cout << yesorno << endl;
    if(yesorno=="No") return 0;
    cout << ans.size() << endl;
    for(int i=0;i<ans.size();i++){
    	cout << ans[i].size() << " ";
    	for(int j=0;j<ans[i].size();j++) cout << ans[i][j] << " ";
    	cout << endl;
    }
    return 0;
}

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

int main(){
	int N, k[10010], a;

	while(1) {
		int f = 0, b = 0;
		cin>>N;
		if(N == 0) break;

		for(int i = 0; i < N; i++){
			cin>>k[i];
			if(k[i] >= 2) f++;
			if(k[i] != 0) b++;
		
		}

		if(f == 0){
			cout<<"NA"<<endl;
		} else{
			cout<<b + 1<<endl;
		}
		
	}
	return 0;
}



Measured memory_bytes: 3128
n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    x=h[i]
    c[i] = min([c[j]+abs(x-h[j]) for j in range(max(0, i-k), i)])
print(c[n-1])


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

int main()
{
	int x,n,t,minv=10000,s;
	bool a[1005];
	cin>>x>>n;
	
	memset(a,0,sizeof(a));
	
	for(int i=1;i<=n;i++)
	{
		cin>>t;
		a[t]=1;
	}
	
	for(int i=0;i<=1000;i++)
	{
		if(a[i]==0)
		  if(fabs(x-i)<minv)
		  {
		  	minv=fabs(x-i);
		  	s=i;
		  }
	}
	
	cout<<s;
	
	return 0;
	 
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <cstdlib>
#include <ctime>

using namespace std;

//#define HOME
void jakos() {
#ifdef HOME
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

#define endl '\n'
#define int long long
typedef long long ll;

const int mod = 1e9 + 7;
const int base = 179;
const int INF = 1e18;
const int N = 1e5 + 7;

signed main() {
    jakos();

    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        cout << "x";
    }

    return 0;
}

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

using namespace std;

int main()
{
    string cad, cad_2;  cin >> cad >> cad_2;
    if (cad == cad_2.substr(0, cad_2.size() - 1))
        cout << "Yes\n";
    else
        cout << "No\n";
}

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

int main() {
  int K;
  string S;
  cin >> K >> S;
  if(K >= S.size()){
    cout << S << endl;
  }else{
    for(int i = 0;i < K;i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
}

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

		 	String s = sc.next();

			if (s.charAt(2)==s.charAt(3)) {
				if (s.charAt(4)==s.charAt(5)) {
					System.out.println("Yes");
					System.exit(0);
				}
			}
			System.out.println("No");
	}
}


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

int n, m;
char s[505][505];
int a[505][505];
int x[505][505], y[505][505];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", s[i]);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            a[i + 1][j + 1] = (s[i][j] == '#' ? 1 : 0);
        }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j]) x[i][j] = y[i][j] = 1;
        }
    }
    for (int i = 1; i <= n; i++) x[i][1] = y[i][m] = 1;
    for (int i = 1; i <= n; i += 2) {
        for (int j = 1; j < m; j++) x[i][j] = y[i + 1][j + 1] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (x[i][j] == 1) printf("#");
            else printf(".");
        }
        printf("\n");
    }
    printf("\n");
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (y[i][j] == 1) printf("#");
            else printf(".");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3968
def solve(i, m):
	if m == 0:
		return True
	elif i >= n or m < 0:
		return False
	else:
		return solve(i + 1, m) or solve(i + 1, m - A[i])


if __name__ == "__main__":
	n = int(input())
	A = [int(x) for x in input().split()]
	q = int(input())
	M = [int(x) for x in input().split()]
	minA = min(A)
	sumA = sum(A)
	for m in M:
		if m < minA or m > sumA:
			print('no')
		elif solve(0, m):
			print('yes')
		else:
			print('no')


Measured memory_bytes: 5624
import sys  
import math

n = int(input())
arr = list(map(int, input().split()))

cnt = 0
ans = 0
for i in range(0, n):
    if i + 1 == arr[i]:
        cnt = cnt + 1
    else:
        ans = ans + math.ceil(cnt / 2)
        cnt = 0
ans = ans + math.ceil(cnt / 2)
print(ans)


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

using namespace std;

const int max_n = 2e3 + 5;

int n,x,y;
vector<int> adjl[max_n];
bool v[max_n];
int k[max_n] = {0};
int dist[max_n][max_n] = {0};
queue< pair<int,int> > q;

int main()
{
	cin >> n >> x >> y;
	--x;
	--y;
	for(int i=0;i<n-1;++i)
	{
		adjl[i].push_back(i+1);
		adjl[i+1].push_back(i);
	}
	adjl[x].push_back(y);
	adjl[y].push_back(x);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
			v[j] = false;
		q.push({i,0});
		v[i] = true;
		while(!q.empty())
		{
			int x = (q.front()).first;
			int d = (q.front()).second;
			if(dist[i][x] == 0 and dist[x][i] == 0)
				++k[d];
			dist[i][x] = d;
			q.pop();
			for(int j=0;j<adjl[x].size();++j)
			{
				if(!v[adjl[x][j]])
				{
					v[adjl[x][j]] = true;
					q.push({adjl[x][j],d+1});
				}
			}
		}
	}
	for(int i=1;i<n;++i)
		cout << k[i] << endl;
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int ile=1;
    int n; cin>>n;
    int * a=new int[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int maxx=a[0];
    for(int i=1;i<n;i++)
    {
        if(a[i]>=maxx) ile++;
        maxx=max(maxx,a[i]);
    }
    cout<<ile;
    return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
V iti[ohara];

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

  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) { iti[a[i]].p_b(i); }
  if (Size(iti[1]) == 0)
    Cout(-1);
  else {
    ll now = -1;
    rrep(i, 1, n + 1) {
      int ok = 1;
      rep(j, Size(iti[i])) {
        ll to = iti[i][j];
        if (now < to) {
          now = to;
          ans++;
          ok = 0;
          break;
        }
      }
      if (ok) break;
    }
    Cout(n - ans);
  }
  return 0;
}

Measured memory_bytes: 33152
x = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
l = list(x.split(','))
i = int(input())
s = str(l[i-1])
print(s.replace(' ',''))


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

int main(){
  int N;
  cin>>N;
  vector<string> W(N);
  bool TF=1;
  char f,l;
  for(int i=0;i<N;i++){
    cin>>W.at(i);
    f=W.at(i).at(0);
    if(i==0)
       l=f;
    if(f!=l)
      TF*=0;
    l=W.at(i).at(W.at(i).size()-1);
  }
  
  for(int j=0;j<N;j++){
    for(int k=0;k<N;k++){
      if(W.at(j)==W.at(k) && j!=k)
        TF*=0;
    }
  }
  if(TF==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vector<P> v(n);
  rep(i,n){
    cin>>v[i].S>>v[i].F;
  }
  sort(all(v));

  int ans=0,t=0;
  rep(i,n){
    if(t>=v[i].S) continue;
    t=v[i].F;
    ans++;
  }

  cout<<ans<<endl;



}


Measured memory_bytes: 4412
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
//#include "toollib.h"
#pragma warning (disable:4018)
#define INT_MAX 2147483647

using namespace std;

int main() {
	struct item {
		int value;
		int weight;
		bool operator<(const item & another) const {
			if (weight != another.weight) return weight < another.weight;
			else return value < another.value;
		}
	};
	int N, W;
	cin >> N >> W;
	vector<item> items(N);
	for (int i = 0; i < N; i++) {
		cin >> items[i].value >> items[i].weight;
	}
	sort(items.begin(), items.end());
	vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= W; j++) {
			if (j - items[i - 1].weight >= 0) dp[i][j] = max(dp[i][j - items[i - 1].weight] + items[i - 1].value, dp[i - 1][j]);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 6828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

int main() {
  ll x;
  cin >> x;
  vec ans;
  ans.push_back(1);
  for(ll i=2;i<=x;i++) {
    for(ll j=2;mpow(i,j)<=x;j++) {
      ans.push_back(mpow(i,j));
    }
  }
  sort(ans.rbegin(),ans.rend());
  cout << ans[0] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main()
{
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int N,i,j;
    double v[50],tmp;

    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%lf",&v[i]);
    }

    for(i = 0;i < N;i++){
        for(j = i + 1;j < N;j++){
            if(v[i] > v[j]){
                tmp = v[i];
                v[i] = v[j];
                v[j] = tmp;
            }
        }
    }

    for(i = 0;i < (N - 1);i++){
        v[i + 1] = (v[i] + v[i + 1])/2;
    }

    printf("%f",v[N-1]);
    return 0;
}


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

typedef unsigned long long ll;
int main() {
	ll N; cin >> N;
	vector<ll> A(N);
	for(int i = 0; i < N; ++i) cin >> A[i];

	bool over = false;
	ll sum = 1;
	for(int i = 0; i < N; ++i) {
		if(A[i] == 0) {
			over = false;
			sum = 0;
			break;
		}

		string s1, s2, s3;
		s1 = to_string(sum);
		s2 = to_string(A[i]);
		int k1 = s1.size()-1, k2 = s2.size()-1;
		int keta = k1 + k2;

		sum *= A[i];

		if(keta >= 18) {
			if(sum == 1000000000000000000) over = false;
			else over = true;
		} else {
			string s3 = to_string(sum);
			if(s3.size()-1 >= 18) {
				if(sum == 1000000000000000000) over = false;
				else over = true;
			}
		}
	}

	if(over) {
		cout << "-1" << endl;
	} else {
		cout << sum << endl;
	}

	return 0;
}


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

def resolve():
    n=int(input())
    t,a=map(int, input().split())
    h=list(map(int,input().split()))
    ans=n+1
    minabs=10**18
    for i in range(n):
        tempabs=abs(a-(t-h[i]*0.006))
        if tempabs<minabs:
            minabs=tempabs
            ans=i+1
    print(ans)
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 1e18LL

const ll MAX = 1000000000000000000; //1e18

int main(){
    string s;
    cin >> s;
    bool exist = true;
    int cnt = 0;
    int n = s.size();
    rep(i, n){
        if(i == 0){
            if(s[i] != 'A') exist = false;
        }else if(2 <= i && i <= n-2){
            if(s[i] == 'C') cnt++;
        }else{
            if('a' <= s[i] && s[i] <= 'z'){
                continue;
            }else{
                exist = false;
            }
        }
    }
    if(exist && cnt == 1) cout << "AC" << endl;
    else cout << "WA" << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

#define LIMIT 10000
int divisor[LIMIT+10],md;
void maked(ll n){md=max(md,n);n=min(LIMIT,n);divisor[0]=-1;divisor[1]=1;ll i=2;for(;i*i<=n;i++)if(!divisor[i]){divisor[i]=i;for(ll j=i*i;j<=n;j+=i)if(!divisor[j])divisor[j]=i;}for(;i<=n;i++)if(!divisor[i])divisor[i]=i;}

ll n;
ll d[1010];
int main(){
	maked(2000);
	scanf("%lld",&n);
	rep(i,2,n+1){
		ll t=i;
		while(t!=1){
			d[divisor[t]]++;
			t/=divisor[t];
		}
	}
	ll ans=1;
	rep(i,2,n+1)ans=ans*(d[i]+1)%1000000007;
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,s1=0,s2=0,s3=0;
int32_t main(){
CODE_START;
cin>>n;
s1=1;
s2=1;
s3=1;
for(ll i=1;i<=n;i++)
{
    s1*=10;
    s1%=mod;
    s2*=9;
    s2%=mod;
    s3*=8;
    s3%=mod;

}
ll x=s1+s3-s2*2;
while(x<0){
    x+=mod;
}
cout<<x<<endl;
}




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

int main() {
  int a,b;
  int n;
  while(cin >> a >> b >> n) {
    int ans=0;
    if(a>=b) a%=b;
    for(int i=0; i<n; i++) {
      a*=10;
      int c=a/b;
      a%=b;
      ans+=c;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main()
{
    string sa,sb,sc;
    char k='a';
    cin>>sa>>sb>>sc;
    while (true)
    switch (k)
    {
        case 'a':
            if(sa.size()==0)
            {
                cout<<"A"<<endl;
                return 0;
            }
            else
            {
                k=sa[0];
                sa.erase(0,1);
            }
            break;
        case 'b':
            if(sb.size()==0)
            {
                cout<<"B"<<endl;
                return 0;
            }
            else
            {
                k=sb[0];
                sb.erase(0,1);
            }
            break;
        case 'c':
            if(sc.size()==0)
            {
                cout<<"C"<<endl;
                return 0;
            }
            else
            {
                k=sc[0];
                sc.erase(0,1);
            }
            break;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            var X = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = X[0];
            var M = X[1];

            var G = new List<long>[N];
            for (var i = 0; i < N; i++) G[i] = new List<long>();

            var P = new long[M];
            var Y = new long[M];

            for (var i = 0; i < M; i++) {
                var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
                G[A[0] - 1].Add(A[1]);
                P[i] = A[0];
                Y[i] = A[1];
            }

            for (var i = 0; i < N; i++) G[i].Sort();

            for (var i = 0; i < M; i++) {
                Y[i] = G[P[i] - 1].BinarySearch(Y[i]) + 1;
            }

            for (var i = 0; i < M; i++) {
                Console.WriteLine("{0}{1}", P[i].ToString("D6"), Y[i].ToString("D6"));
            }
        }
    }
}

Measured memory_bytes: 29284
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <math.h>
#include <iterator>


using namespace std;
int main(){
    string str,s;
    int cnt=0;
    cin >> s;
    for(int i=0,l=s.size();i<l;i++){
        if(s[i]>='A'&&s[i]<='Z')s[i]+=('a'-'A');
    }
    while(1){
        cin >> str;
        if(str=="END_OF_TEXT")break;
        for(int i=0,l=str.size();i<l;i++)
            if(str[i]>='A'&&str[i]<='Z') str[i]+=('a'-'A');
        if(s==str) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3188
#template
def inputlist(): return [int(k) for k in input().split()]
#template
def dijkstra(s,n,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0

    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True

        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

H,W = inputlist()
cost = [0]*10
for i in range(10):
    cost[i] = inputlist()
A = [0]*H
for i in range(H):
    A[i] = inputlist()

ans = 0

for x in range(H):
    for y in range(W):
        if A[x][y] == -1:
            continue
        d = dijkstra(A[x][y],10,cost)
        ans += d[1]
print(ans)

Measured memory_bytes: 47852
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main () {
    ll n ;
    cin >> n ;
    vector<ll> a (n+1), b(n) ;
    rep(i, n+1) cin >> a[i] ;
    rep(i, n) cin >> b[i] ;
    ll ans = 0 ;
    rep(i, n){
        if(i == n -1){
            if(a[i] + a[i + 1] > b[i]){
                ans += b[i] ;
                break ;
            }
            else {
                ans += a[i] + a[i + 1] ;
                break ;
            }
        }
        if(a[i] <= b[i]){
            ans += a[i] ;
            if(a[i + 1] > (b[i] - a[i])){
                a[i + 1] -= (b[i] - a[i]) ;
                ans += (b[i] - a[i]) ;
            }
            else {
                ans += a[i + 1] ;
                a[i + 1] = 0 ;
            }
        }
        else {
            ans += b[i] ;
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 4800
R, C, K = map(int, input().split())

V = [[0]*(C+1) for _ in range(R+1)]
dp1 = [[0,0,0,0] for _ in range(C+1)]

for _ in range(K):
    r, c, v = map(int, input().split())
    V[r][c] = v

for r in range(1,R+1):
    dp0 = dp1
    dp1 = [[0,0,0,0] for _ in range(C+1)]
    
    for c in range(1,C+1):
        v = V[r][c]
        dprc  = dp1[c]
        dprcL = dp1[c-1]
        if v==0:
            dprc[0] = max(max(dp0[c]), dprcL[0])
            for n in range(1,4): dprc[n] = dprcL[n]
        else:
            maxT = max(dp0[c])
            dprc[0] = max(maxT  ,             dprcL[0])
            dprc[1] = max(maxT+v, dprcL[0]+v, dprcL[1])
            dprc[2] = max(        dprcL[1]+v, dprcL[2])
            dprc[3] = max(        dprcL[2]+v, dprcL[3])
        

print(max(dp1[C]))


Measured memory_bytes: 210384
from sys import stdin
H, W = [int(_) for _ in stdin.readline().rstrip().split()]
N = int(stdin.readline().rstrip())
A = [int(a) for a in stdin.readline().rstrip().split()]

flattened = []
for i, a in enumerate(A):
  for j in range(a):
    flattened.append(i+1)

ans = [[0]*W for h in range(H)]

index = 0
for h in range(H):
  for w in range(W):
    ans[h][w] = flattened[index]
    index += 1

for h in range(H):
  if h % 2 == 0:
    print(*ans[h], sep=" ")
  else:
    print(*ans[h][::-1], sep=" ")

Measured memory_bytes: 42864
#=input()
n=int(input())
#=map(int,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

def f(x):
    return chr(x+96)

ans = ""
while n >= 26:
    if n % 26 == 0:
        ans += 'z'
        n //= 26
        n -= 1
    else:
        ans += f(n % 26)
        n //= 26
if n != 0:
    ans += f(n)
print(ans[::-1])

Measured memory_bytes: 9060
#include"bits/stdc++.h"
#include<iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

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

	vector<int>x(n);

	for (int i = 0; i < n;i++) {
		cin >> x[i];
	}
	int ans=1000000;

	for (int i = 1; i < 100; i++) {
		int cost=0;
		for (int j = 0; j < n; j++) {
			cost += (x[j] - i)*(x[j] - i);
		}
		ans = min(ans, cost);
	}

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

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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((abs(b-a)<=d && abs(c-b)<=d) || (abs(a-c)<=d)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
s = input()
t = list(input())

tl=[]

for i in range(len(s)):
    wk = ''
    x = i
    for _ in range(len(s)):

        if x == len(s):
            x -= len(s)

        wk += t[x]
        x += 1
        
    tl.append(wk)

if s in tl:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38640
package main

import (
	"bufio"
	"fmt"
	basicIO "io"
	"math"
	"os"
	"strconv"
)

func main() {
	protagonist(os.Stdin, os.Stdout)
}

func protagonist(r basicIO.Reader, w basicIO.Writer) {
	io := NewIO(r, w)
	N, _ := io.nextInt()
	A := make([]int, N)

	min := math.MaxInt64
	sec := math.MaxInt64
	for i := 0; i < N; i++ {
		A[i], _ = io.nextInt()
		if A[i] < sec {
			if A[i] < min {
				sec = min
				min = A[i]
			} else {
				sec = A[i]
			}
		}
	}

	solution := 1

	for num := sec; num > 0; num-- {
		isLimit := false
		for j := 0; j < N; j++ {
			if A[j]%num == 0 {
				continue
			}
			if isLimit {
				goto NotFound
			}
			isLimit = true
		}
		solution = num
		goto Done
	NotFound:
	}

Done:
	io.PutInt(solution)
}

type IO struct {
	Scanner *bufio.Scanner
	Writer  basicIO.Writer
}

func NewIO(r basicIO.Reader, w basicIO.Writer) *IO {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &IO{
		Scanner: s,
		Writer:  w,
	}
}

func (io *IO) nextString() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *IO) nextInt() (int, error) {
	io.Scanner.Scan()
	i, err := strconv.Atoi(io.Scanner.Text())
	return i, err
}

func (io *IO) PutInt(v int) {
	fmt.Fprintf(io.Writer, "%d\n", v)
}

func (io *IO) PutString(s string) {
	fmt.Fprintf(io.Writer, "%s\n", s)
}


Measured memory_bytes: 3072
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {

	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)
	a, _:= strconv.Atoi(readLine(reader))
	if a >= 3200 {
		fmt.Println(readLine(reader))
	} else {
		fmt.Println("red")
	}
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return strings.TrimRight(string(str), "\r\n")
}

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

int main(){
    int tmp;
   rep(i,5){
       cin>>tmp;
       if(tmp==0){
           cout<<i+1<<endl;
       }
   }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)
#define int long long
#define debug(var) cout << "[" << #var << "] " << var << endl
//using ll = long long;

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=998244353;

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

    vector<vector<int> > conn(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        conn[a-1].push_back(b-1);
        conn[b-1].push_back(a-1);
    }

    vector<int> dist(n, -1);
    queue<int> queue;
    queue.push(0);

    dist[0] = 0;
    while(!queue.empty()) {
        int v = queue.front();
        queue.pop();

        for (int nv: conn[v]) {
            if (dist[nv] != -1) continue;

            queue.push(nv);
            dist[nv] = v+1;
        }
    }

    bool ok = true;
    rep(i, dist.size()) {
        if (dist[i] == -1) {
            No();
            ok = false;
        }
    }

    if(ok) {
        Yes();
        FOR(i, 1, dist.size()) {
            cout << dist[i] << endl;
        }
    }
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

int  N;
string S;
int l[200010];
int r[200010];

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

  cin >> N;
  cin >> S;

  int x = 0;
  rep(i, N) {
    if (S[i] == '#') ++x;
    l[i] = x;
  }
  x = 0;
  drep(i, N) {
    if (S[i] == '.') ++x;
    r[i] = x;
  }
  int ans = min(r[0], l[N-1]);
  rep(i,N-1) {
    ans = min(ans, l[i]+r[i+1]);
  }
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

int main(void){
  unsigned short N;
  cin >> N;
  vector<long > Stick;
  for (int i = 0; i < N; i++)
  {
    long tmp; cin >> tmp;
    Stick.push_back(tmp);
  }
  //sort(Stick.begin(), Stick.end());
  
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      for (int k = j+1; k < N; k++)
      {
        if( Stick[i] != Stick[j] && Stick[j] != Stick[k] && Stick[k] != Stick[i]){
          if( (Stick[i]+Stick[j]) > Stick[k] && (Stick[i]+Stick[k]) > Stick[j] && (Stick[j]+Stick[k]) > Stick[i] ){
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 3164
#include <stdio.h>
#include <stdlib.h>

int max(int a, int b);
int min(int a, int b);
int cmp(const void *p, const void *q);

int main(int argc, char const *argv[])
{
    int n;
    int h[100] = {0};
    int i;
    int j;
    int cnt = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }

    i = 0;

    while(i != n) {
        if (h[i] != 0) {
            for (j = i; j < n; j++) {
                if (h[j] > 0) {
                    h[j]--;
                } else {
                    break;
                }
            }
            cnt++;
        } else {
            i++;
        }
    }

    printf("%d", cnt);

    return 0;
}

int max(int a, int b) {
    return a > b ? a : b;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int cmp(const void *p, const void *q) {
    return -(*(int*)p - *(int*)q);
}

Measured memory_bytes: 256
def main():
    num_list = []
    for _ in range(3):
        num_list.append(list(map(int,input().split())))
    n = int(input())
    b_list = [int(input()) for _ in range(n)]

    for i in range(3):
        for j in range(3):
            if num_list[i][j] in b_list:
                num_list[i][j] = '!'

    for i in range(3):
        count = 0
        for j in range(3):
            if num_list[i][j] == '!':
                count += 1
        if count == 3:
            print('Yes')
            exit()

    for i in range(3):
        count = 0
        for j in range(3):
            if num_list[j][i] == '!':
                count += 1
        if count == 3:
            print('Yes')
            exit()
    
    if num_list[0][0] == '!' and num_list[1][1] == '!' and num_list[2][2] == '!':
        print('Yes')
        exit()

    if num_list[0][2] == '!' and num_list[1][1] == '!' and num_list[2][0] == '!':
        print('Yes')
        exit()

    print('No')

if __name__ == '__main__':
    main()

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int N, M;
string S;
char A[200010], B[200010];

int unit(int mid)
{
    int now = mid;
    for(int i = 0; i < M; i++)
    {
        if(S[now] == A[i])
        {
            if(B[i] == 'L')now--;
            else now++;
        }
        if(now == -1)return -1;
        if(now == N)return N;
    }
    return 0;
}

int main()
{
    cin >> N >> M;
    cin >> S;

    for(int i = 0; i < M; i++)cin >> A[i] >> B[i];

    int ansl;
    int l = 0, r = N;
    if(unit(0) != -1)ansl = -1;
    else
    {
        for(int i = 0; i < 60; i++)
        {
            int mid = (l + r) / 2;
            if(unit(mid) == -1)l = mid;
            else r = mid;
        }
    ansl = l;
    }

    int ansr;
    l = -1, r = N;
    if(unit(N - 1) != N)ansr = N;
    else
    {
        for(int i = 0; i < 60; i++)
        {
            int mid = (l + r) / 2;
            if(unit(mid) == N)r = mid;
            else l = mid;
        }
    ansr = r;
    }
    cout << N - (ansl != -1) * (ansl + 1) - (ansr != N) * (N - ansr) << endl;
}


Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	int l[n], r[n];
	for(int i=0; i<n; i++) cin >> l[i] >> r[i];
	int a=0;
	
	for(int i=0; i<n; i++){
		a += r[i]-l[i]+1;
	}
	
	cout << a << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    string s, t; cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());


    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,S,s;
    cin>>N;
    for(int i=1;;i++)
    {
      S=1000*i;
      if(S>N)
      {
          s=S-N;
          break;
      }
      else if(S==N)
      {
          s=0;
         break;
      }
      }
      cout<<s<<endl;
    }


Measured memory_bytes: 3636
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ar := []int{1}
	for i := 6; i <= n; i *= 6 {
		ar = append(ar, i)
	}
	for i := 9; i <= n; i *= 9 {
		ar = append(ar, i)
	}
	dp := make([]int, n+1)
	for i := range dp {
		dp[i] = n
	}
	dp[0] = 0
	for _, v := range ar {
		for i := 0; i+v <= n; i++ {
			if dp[i+v] > dp[i]+1 {
				dp[i+v] = dp[i] + 1
			}
		}
	}
	fmt.Println(dp[n])
}


Measured memory_bytes: 1280
S = input()
N = len(S)

num = [0] * 2019
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % 2019
    _10 *= 10
    _10 %= 2019
    ans += num[now]
    num[now] += 1
print(ans)

Measured memory_bytes: 9272
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        h: usize,
        w: usize,
        k: i64,
        board: [Chars; h],
    }

    let mut ans = 0i64;
    for ha in 0..(1 << h) {
        for wa in 0..(1 << w) {
            let mut blk_cnt = 0i64;
            for i in 0..h {
                for j in 0..w {
                    if board[i][j] == '#' && (ha >> i) & 1 == 0 && (wa >> j) & 1 == 0 {
                        blk_cnt += 1;
                    }
                }
            }

            if blk_cnt == k {
                ans += 1;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2148
use proconio::{input, fastout};
use proconio::marker::Usize1;
use std::collections::HashSet;

pub struct UnionFind {
    pars: Vec<usize>,
    rank: Vec<usize>,
}
impl UnionFind {
    pub fn new(n: usize) -> Self {
        UnionFind {
            pars: (0..n).collect(),
            rank: vec![1; n],
        }
    }
    pub fn find(&mut self, x: usize) -> usize {
        let p = self.pars[x];
        if x != p {
            self.pars[x] = self.find(p);
        }
        self.pars[x]
    }
    pub fn unite(&mut self, x: usize, y: usize) -> bool {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x == y {
            return false;
        }
        if self.rank[x] < self.rank[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.rank[x] += self.rank[y];
        self.pars[y] = x;
        true
    }
    pub fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
    pub fn size(&mut self, x: usize) -> usize {
        let p = self.find(x);
        self.rank[p]
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        v: [(Usize1,Usize1);m]
    }
    let mut u = UnionFind::new(n);
    for (a,b) in v {
        u.unite(a,b);
    }
    let mut h = HashSet::new();
    for i in 0..n {
        h.insert(u.find(i));
    }
    println!("{}", h.len() - 1);
}


Measured memory_bytes: 6332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int i, j;
    i = 0; j = N-1;
    int cnt = 0;
    while(i <= j){
        if(S[i] == 'W' && S[j] == 'R'){
            cnt++;
            i++;
            j--;
        }
        else if(S[i] == 'R' && S[j] == 'R'){
            i++;
        }
        else if(S[i] == 'W' && S[j] == 'W'){
            j--;
        }
        else{
            i++;
            j--;
        }
    }
    printf("%d\n", cnt);

}

Measured memory_bytes: 3856
import java.math.*;
import java.util.*;

public class Main {
    private long mod = 1_000_000_007L;
    private BigInteger bmod = BigInteger.valueOf(mod);
    private BigInteger bkaijo[];
    private BigInteger inv[];

    public void main(Scanner sc) {
        int h = sc.nextInt();
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        inv = new BigInteger[h + w - 1];
        bkaijo = new BigInteger[h + w - 1];
        inv[0] = BigInteger.ONE;
        bkaijo[0] = BigInteger.ONE;
        for (int i = 1; i <= h + w - 2; i++) {
            bkaijo[i] = bkaijo[i - 1].multiply(BigInteger.valueOf(i)).mod(bmod);
            inv[i] = bkaijo[i].modInverse(bmod);
        }

        long ans = 0;
        long ans1, ans2;
        for (int i = b; i < w; i++) {
            ans1 = calc(0, 0, h - a - 1, i);
            ans2 = calc(h - a, i, h - 1, w - 1);
            ans += ans1 * ans2 % mod;
            ans %= mod;
        }

        System.out.println(ans);
    }

    private long calc(int h1, int w1, int h2, int w2) {
        int h = h2 - h1;
        int w = w2 - w1;

        return bkaijo[h + w].multiply(inv[h]).mod(bmod).multiply(inv[w]).mod(bmod).longValue();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5 + 9, M = 4e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    int s, w;cin >> s >> w;
    if(w >= s)  cout << "unsafe";
    else cout << "safe";

}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
    #define ll long long
    #define f   first
    #define s   second
    #define pb          push_back
    #define mod         1000000007
    #define hell        998244353
    #define inf         1000000000000000000LL
    using namespace std;
    ll n,k,m,sum,q;
    ll s,l,r,x,y,h,w;
    //ll a[1005][1005];
    
    void solve()
    {   
        ll n1,n2,n3;
        cin>>n>>m>>k;
        ll v[n][m+1];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m+1;j++) cin>>v[i][j];
        }
        ll ans=inf;
        for(ll i=0;i<(1LL<<n);i++)
        {   vector<ll> v1;
            ll res=0;
            for(ll j=0;j<n;j++)
            {
                if(i&(1LL<<j))
                    v1.pb(j);  
            }
            vector<ll> cnt(m+1);
            for(auto x:v1)
            {
                for(int j=1;j<=m;j++)
                    cnt[j]+=v[x][j];
                res+=v[x][0];
            }
            bool f=0;
            for(int j=1;j<=m;j++)
                if(cnt[j]<k){f=1;break;}
            if(!f) {ans=min(ans,res);}
        }
        if(ans==inf) {cout<<"-1";}
        else cout<<ans;

        
    }   
    int main()
    {   
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        //cout<<primes.size();
        ll t=1;
      //cin>>t;
        while(t--)
            solve();
    }


    


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

#define _GLIBCXX_DEBUG
#define rep(i, V) for (int i = 0; i < V; i++)
#define repr(i, V) for (int i = V-1; i >= 0; i--)
#define repval(i, a, V) for (int i = a; i < V ; i++)
#define all(x) x.begin(), x.end()
#define ld long double
#define eps 0.0000000001
#define mod 1000000007
#define inf 1e16
#define vec vector
#define each(i, mp) for(auto& i:mp)

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

    int l = 0;
    int ansl = 0;
  	int ansr = 0;    
    rep(i, (int)s.size()){
        if (s[i] == '('){
            l++;
        }else if(l > 0){
            l--;
        }else{
            ansl++;
        }
    }
    ansr = l;
  
 	rep(i, ansl) cout << '('; cout << s; rep(i, ansr) cout << ')';
}

Measured memory_bytes: 3612
def abc():
    e = {1}
    for b in range(2, 1001):
        for p in range(2, 11):
            bp = b ** p
            if bp > 1000:
                continue
            e.add(bp)
    x = int(input().rstrip())
    for n in reversed(range(x+1)):
        if n in e:
            print(n)
            return


abc()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n,m;
char x;
string o;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		o="";
		for(int j=1;j<=m;j++)
		{
			cin>>x;
			o+=x;
		}
		cout<<o<<endl;
		cout<<o<<endl;
		
	}
	
	
	
	
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    string x;
    cin>>x;
    if(x[0] == x[1] && x[1] == x[2]){
        cout<<"Yes"<<endl;
    }else if(x[3] == x[1] && x[1] == x[2]){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node
{
  int id;
  struct node *parent;
  struct node *child[2];
} *nodePointer;
nodePointer root;
nodePointer make1node(int);
void insert(nodePointer);
int find(nodePointer,int);
void preorderWalk(nodePointer);
void inorderWalk(nodePointer);
int main(void)
{
  int i;//counter
  int n;//the number of operation
  char op[10];//operation
  int id;//inserted or found number
  nodePointer p;
  root=NULL;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s",op);
      if(strcmp(op,"insert")==0)
	{
	  scanf("%d",&id);
	  p=make1node(id);
	  insert(p);
	}
      else if(strcmp(op,"find")==0)
	{
	  scanf("%d",&id);
	  if(find(root,id)==1) printf("yes\n");
	  else printf("no\n");
	}
      else if(strcmp(op,"print")==0)
	{
	  inorderWalk(root);
	  preorderWalk(root);
	}
      else
	{
	  printf("undefined operation\n");
	  exit(1);
	}
    }
  return 0;
}
nodePointer make1node(int id)
{
  nodePointer p;
  p=(nodePointer)malloc(sizeof(struct node));
  p->id=id;
  p->parent=NULL;
  p->child[0]=NULL;
  p->child[1]=NULL;
  return p;
}
void insert(nodePointer p)
{
  nodePointer parent=NULL;//parent of p
  nodePointer temp=root;
  while(temp!=NULL)
    {
      parent=temp;
      if(p->id < temp->id) temp=temp->child[0];
      else temp=temp->child[1];
    }
  p->parent=parent;
  if(parent==NULL) root=p;
  else if(p->id < parent->id) parent->child[0]=p;
  else parent->child[1]=p;
}
int find(nodePointer p,int id)
{
  if(p==NULL) return 0;
  if(p->id < id) return find(p->child[1],id);
  if(p->id == id) return 1;
  if(p->id > id) return find(p->child[0],id);
}
void preorderWalk(nodePointer p)
{
  if(p!=NULL)
    {
      printf(" %d",p->id);
      preorderWalk(p->child[0]);
      preorderWalk(p->child[1]);
      if(p==root)
	{
	  printf("\n");
	}
    }
}
void inorderWalk(nodePointer p)
{
  if(p!=NULL)
    {
      inorderWalk(p->child[0]);
      printf(" %d",p->id);
      inorderWalk(p->child[1]);
      if(p==root)
	{
	  printf("\n");
	}
    }
}




Measured memory_bytes: 20468
#include <iostream>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a < b) {
        if (b < c) {
            cout << a + b << endl;
        } else {
            cout << a + c << endl;
        }
    } else {
        if (a < c) {
            cout << b + a << endl;
        } else {
            cout << b + c << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    int n;
    cin >> n;
    ll dmin = INF, dmax = -1, rmin = INF, rmax = -1;
    ll x, y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        dmin = (dmin > x + y) ? x + y : dmin;
        dmax = (dmax < x + y) ? x + y : dmax;
        x = 1000000000 - x;
        rmin = (rmin > x + y) ? x + y : rmin;
        rmax = (rmax < x + y) ? x + y : rmax;
    }
    cout << max(dmax - dmin, rmax - rmin) << endl;
    return 0;
}

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

int main(){
    
	int i, a, b, c;
    int ab=0, bc=0, ca=0;
    
	cin >> i;
    
	while(i-- > 0){
        
		cin>> a>> b>> c;
        
        ab = a*a+b*b;
        bc = b*b+c*c;
        ca = c*c+a*a;
		
		if(ab == c*c || bc==a*a || ca==b*b) cout << "YES" << endl;
		else cout << "NO" << endl;
        
	}
    
    
	return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int ans=0;
	string s;
	cin >> s;
	for(int i=0;i<4;i++){
		if(s[i]=='+'){
			ans++;
		}
		else{
			ans--;
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stack>
#include <iostream>
using namespace std;
int main()
{
	stack<int> data;
	int input;
	
	while (cin >> input)
	{
		if (input)
		{
			data.push(input);
		}
		else
		{
			cout << data.top() << endl;
			data.pop();
		}
	}
}

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

#define ll long long 
#define sci(n) scanf("%d",&n)
#define scii(a,b) scanf("%d%d",&a,&b)
#define scl(a) scanf("%lld",&a)
#define F(i,a,b) for(int i =a;i<b;i++)
#define vi vector<int> 
#define vpi vector<pair<int,int>> 
#define vvi vector<vector<int>>
#define pii pair<int,int> 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define w(t)  int t;cin>>t;while(t--)
#define mod 1000000007



int main(){
	float d,t,s;
	cin>>d>>t>>s;
	float x = d/s;
	if(t >=x) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3720
import sys

n = int(input())
if n == 1:
	G = [1]
else:
	G = [g for g in [1, 4, 10, 23, 57, 132, 301, 701] if g < n]
	while True:
		g = int(2.25 * G[-1])
		if g > n:
			break
		G.append(g)
	G.reverse()

A = list(map(int, sys.stdin))
cnt = 0
for g in G:
	for j, v in enumerate(A[g:]):
		while j >= 0 and A[j] > v:
			A[j+g] = A[j]
			j -= g
			cnt += 1
		A[j+g] = v

print(len(G))
print(*G)
print(cnt)
for a in A:
	print(a)


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


int main(){
int i,j,k,t,n;
cin>>n;
if(n%2==0){
    n/=2;
    cout<<n-1;
}else{
    n--;
    cout<<n/2;
    
}
}

Measured memory_bytes: 256