akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
using namespace std;
const int maxm=4005;
const int maxv=2002;
const int maxn=200002;
const int mod=1000000007;
int n,ans;
int a[maxn],b[maxn];
int f[maxm][maxm],C[maxm][maxm];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for (int i=1;i<=n;i++) f[maxv-a[i]][maxv-b[i]]++;
	for (int i=1;i<maxm;i++) C[i][0]=C[0][i]=1;
	for (int i=1;i<maxm;i++)
		for (int j=1;j<maxm;j++){
			f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%mod;
			C[i][j]=(C[i-1][j]+C[i][j-1])%mod;
		}
	for (int i=1;i<=n;i++){
		ans=(ans+f[maxv+a[i]][maxv+b[i]])%mod;
		ans=(ans-C[a[i]*2][b[i]*2]+mod)%mod;
	}
	ans=1LL*ans*(mod+1)/2%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 126976
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}


int main(void)
{
	int n;
	int k;
	int h[100000];
	int diffmin = 1000000000;

	scanf("%d %d", &n,&k);

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

	qsort(h, n, sizeof(int), compare_int);

	for (int i = 0; i < n-k+1; i++){
		int st = h[i];
		int ed = h[i + k-1];
		int diff = ed - st;

		if (diff < diffmin) diffmin = diff;
	}

	printf("%d\n", diffmin);

	return 0;
}



Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define w(_t) ll _t;cin>>_t;while(_t--)

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ll d,t,s;cin>>d>>t>>s;
    if(d/(float)s<=t) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3636
import java.io.*;
  
class Main{
    public static void main(String args[]) throws IOException{
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(buf.readLine());
        StringBuilder sb = new StringBuilder();
          
        int num = 0;
        for(int j=3; j<=n; j++){
            if(j%3==0){
                sb.append(" "+j);
            } else {
                num = j;
                while(num != 0){
                    if(num%10==3){
                        sb.append(" "+j);
                        break;
                    } else{
                        num = num/10;
                    }   
                }
            }           
  
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 26268
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
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(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

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

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  method(input,set<int>){
    int n = in();
    set<int> s;
    rep(_,n)s.emplace(in());
    return s;
  };
  set<int> ans;
  method(add,void,set<int> s){
    foreach(i,s)ans.emplace(i);
  };
  add(input());
  add(input());
  foreach(i,ans){
    cout << i << endl;
  }
}



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

using namespace std;

#define db(a) cout<<#a<<" = "<<a<<endl
#define db2(a,b) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<endl
#define db3(a,b,c) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<endl
#define db4(a,b,c,d) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<endl

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

/*
Sample input/outputs


*/

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	char ar[100000];
    int n;
    cin>>n;
    
    for(int i = 0; i< n; i++)
    {
    	cin>>ar[i];
	}
	
	int count = 1;
	for(int i = 0; i< n-1; i++)
	{
		if(ar[i] != ar[i+1])
		count++;
	}
     
    cout<<count<<endl;
	return 0;
}


















Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	cin >> N;
	vi d(N);
	ll sum = 0;
	rep(i, N) {
		cin >> d[i];
		sum += d[i];
	}
	ll ans = 0;
	rep(i, N) {
		ans += d[i] * (sum - d[i]);
	}
	ans /= 2;
	cout << ans << endl;
	return 0;
}

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

int main()
{
    while (true)
    {
        int n;
        cin >> n;
        if (n==0)
        {
            break;
        }
        vector<int> scores(n);
        double sum=0;
        for (int i=0; i<n; i++)
        {
            int score;
            cin >> score;
            scores.at(i) = score;
            sum += score;
        }
        double mean = sum/n;
        double variance = 0;
        for (int i=0; i<n; i++)
        {
            variance += pow(scores.at(i)-mean, 2);
        }
        variance /= n;
        cout << fixed << setprecision(15) << sqrt(variance) << endl;
    }
}


Measured memory_bytes: 3240
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const int maxn=1e6+10;
const int maxm=20;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n;
int ans[maxn*2];
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        int st=maxn-1,ed=maxn;
        for(int i=0;i<n;i++)
        {
            if(i%2==0)
                scanf("%d",&ans[ed++]);
            else
                scanf("%d",&ans[st--]);
        }
        if(n%2==0)
        for(int i=st+1;i<ed;i++)
            printf("%d%s",ans[i],i==ed-1?"\n":" ");
        else
            for(int i=ed-1;i>st;i--)
            printf("%d%s",ans[i],i==st+1?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

// DAME:
int main() {
    int m;
    cin >> m;
    vector<ll> d(m), c(m);
    rep(i, m) cin >> d[i] >> c[i];
    ll ans = 0;
    ll sum = 0;
    rep(i, m){
        sum += (d[i] * c[i]);
        ans += c[i];
    }
    ans--;

    ans += (sum-1)/9;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string str;cin>>str;
  int count=0;
  if(str.length()==1)
   cout<<0;
   else
   {
     /* code */for(int i=0;i<=str.length()/2-1;i++)
  {
    if(str[i]!=str[str.length()-i-1])
      count++;
  }
  cout<<count;
   }
   
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#define INF 1e+9
using namespace std;

struct edge{ int to,cost; };
typedef pair<int,int> P;

int main(){
	int n,k,c[5000],r[5000],a,b;
	int d[5000];
	vector<int> taxi[5000];
	vector<edge> G[5000];
	cin >> n >> k;
	for(int i = 0;i < n;i++){
		cin >> c[i] >> r[i];
		d[i] = INF;
	}
	d[0] = 0;
	for(int i = 0;i < k;i++){
		cin >> a >> b;
		taxi[a - 1].push_back(b - 1);
		taxi[b - 1].push_back(a - 1);
	}
	for(int i = 0;i < n;i++){
		bool used[5000] = {};
		used[i] = true;
		queue<int> que;
		que.push(i);
		for(int j = 0;j < r[i];j++){
			int siz = que.size();
			for(int l = 0;l < siz;l++){
				int v = que.front();que.pop();
				for(int m = 0;m < taxi[v].size();m++){
					if(!used[taxi[v][m]]){
						used[taxi[v][m]] = true;
						G[i].push_back({taxi[v][m],c[i]});
						que.push(taxi[v][m]);
					}
				}
			}
		}
	}
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,0));
	while(!que.empty()){
		P p = que.top();que.pop();
		int vv = p.second;
		if(d[vv] < p.first) continue;
		for(int i = 0;i < G[vv].size();i++){
			edge e = G[vv][i];
			if(d[e.to] > d[vv] + e.cost){
				d[e.to] = d[vv] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
	cout << d[n - 1] << endl;
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    int a, b; cin >> a >> b;
    int tot = 0;
    
    if(a < b) swap(a, b);
    tot += a;
    a--;
    if(a < b) swap(a, b);
    tot += a;
    a--;
    
    cout << tot << endl;
    
    return;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int a, b, h; cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*void mayank()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}*/
#define ll long long
#define inf 1e9
const int mxN = 1e5;
ll a[mxN + 1], b[mxN + 1];
ll solve(vector<int> ans, int n) {
	vector<int>dp(n + 1); // One based Indexing.
	dp[1] = 0;
	for (int i = 2; i <= n; i++) {

		int option1 = abs(ans[i - 1] - ans[i]) + dp[i - 1];
		int option2 =  (i == 2) ? inf : abs(ans[i - 2] - ans[i]) + dp[i - 2];
		dp[i] = min(option1, option2);
	}
	return dp[n];
	// Last stone reach // O(n) Time and this dp array could be
	// avoided if we just take 3 variable as it only depend on its last 2 states
}
int main()
{
	//mayank();
	ll n;
	cin >> n;
	vector<int>d(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> d[i];
	}
	cout << solve(d, n);
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{
  long long int n;
  long long int sum = 0;
  
  cin >> n;
  
  for (long long int i = 0; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    }
    else {
      sum += i;
    }
  }
  
  cout << sum << endl;
}

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

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

  int N[n*2], M[m*2];
  for (int i=0; i<n*2; i+=2) {
    cin >> N[i] >> N[i+1];
  }

  for (int i=0; i<m*2; i+=2) {
    cin >> M[i] >> M[i+1];
  }

  int ans[n];
  for (int i=0; i<n*2; i+=2) {
    long long min=1000000000000000;
    for (int j=0; j<m*2; j+=2) {
      if (min>abs(N[i]-M[j])+abs(N[i+1]-M[j+1])) {
        min=abs(N[i]-M[j])+abs(N[i+1]-M[j+1]);
        ans[i/2]=j/2+1;
      }
    }
  }

  for (int i=0; i<n; i++) {
    cout << ans[i] << endl;
  }
}

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

int main() {
  int N,M;
  cin>>N;
  map<int, int> card;  // 名前→成績
  for(int i=0;i<N;i++){
    int s;
    cin >>s;
    if(card.count(s)){
      card[s] ++;
    }
    else{
      card[s] =1;
    }
  }
  int ans=0;
  for(auto p: card){
    auto v = p.second;
    if(v%2==1) ans++;
  }
  cout<< ans<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
            
    typedef long long ll;
    using namespace std;
            
    #define F first
    #define S second
    #define sqr(x) x*x
    #define pb push_back
    #define mp make_pair
    #define sz(x) ((int) (x).size())
    #define all(x) (x).begin(), (x).end()
    #define allr(x) (x).rbegin(), (x).rend()
    #define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
        
    const ll mod=1000000007;
    ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
    int lcm(int a,int b){return abs(a*b)/gcd(a,b);}

    bool comp(pair<int,int> a, pair <int, int> b){
        return a.S < b.S;
    }

    int sum;
    vector <int> v;
    vector<int> v1;
    int main(){ios_base::sync_with_stdio(0);cin.tie(0);
        for(int i = 0; i < 5; ++i){
            int x;
            cin >> x;
            v.pb((((x + 9) / 10 ) * 10) - x);
            v1.pb( ( (x + 9) / 10 ) * 10);
        }
        sort(all(v));
        reverse(all(v));
        int sum  = 0;
        for(int i =0; i < v1.size(); ++i){
            sum += v1[i];
        }
        cout << sum - v[0];

    }

Measured memory_bytes: 256
r,g,b,n=map(int,input().split())
ans=0
for i in range(n//b+1):
    bi=b*i
    for j in range(n//g+1):
        gj=g*j
        if gj+bi>n:
            break
        elif gj+bi==n:
            ans=ans+1
            break
        elif (n-(gj+bi))%r==0:
            ans=ans+1
print(ans)

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

using namespace std;
const int MAX = 2e5;

int main(){
  	int n;
  	int arr[MAX + 5];
  	int s = 0;
  	cin>>n;
  	for(int i = 0; i < n; i++){
      	cin>>arr[i];
      	s ^= arr[i];
    }
  	for(int i = 0; i < n; i++){
      	cout<<int(s ^ arr[i])<<" ";
    }
	return 0;  
}

Measured memory_bytes: 4312
s = input()

if s[0] == 'A' and s[2:-1].count('C') == 1:
    for c in s[1:]:
        if c != 'C' and c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
            print('WA')
            exit()
    print('AC')
else:
    print('WA')

Measured memory_bytes: 2940
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残すな
//数値計算 基本はdouble
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}   // 

int main() {
	vector<double> a(3);
	cin >> a[0] >> a[1] >> a[2];
	
	sort(ALL(a));

	cout << a[0] * a[1] / 2.0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 100

void
print(int [], int);

void
insertionSort(int [], int);

int
main(void)
{
    int arr[SIZE];
    int i, n;

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

void
insertionSort(int arr[], int n)
{
    int i, j, tmp;
    print(arr, n);
    for (i = 1; i < n; i++) {
        tmp = arr[i];
        for (j = i - 1; j >= 0 && arr[j] > tmp; j--)
            arr[j + 1] = arr[j];
        arr[j + 1] = tmp;
        print(arr, n);
    }
}

void
print(int arr[], int n)
{
    int i = 0;
    printf("%d", arr[i++]);
    for ( ; i < n; i++)
        printf(" %d", arr[i]);
    putchar('\n');
}


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

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> maze(H, vector<char>(W));
    vector<vector<int>> di = {{1,0},{-1,0},{0,1},{0,-1}};
    queue<pair<int, int>> q;
    priority_queue<int> pq;
    pq.push(0);
    vector<vector<int>> state(H, vector<int>(W,-1));
    rep(i, H) rep(j, W) cin >> maze[i][j];
    rep(i, H) rep(j, W){
        if(maze[i][j] == '.'){
            q.push(make_pair(i, j));
            rep(l, H) rep(m, W) state[l][m] = -1;
            state[i][j] = 0;
            pq.push(0);
            while(q.size() != 0){
                rep(k, 4) if(0 <= q.front().first+di[k][0] && q.front().first+di[k][0] <= H-1 && 0 <= q.front().second+di[k][1] && q.front().second+di[k][1] <= W-1){
                    if(maze[q.front().first+di[k][0]][q.front().second+di[k][1]] == '.' && state[q.front().first+di[k][0]][q.front().second+di[k][1]] == -1){
                        q.push(make_pair(q.front().first+di[k][0], q.front().second+di[k][1]));
                        state[q.front().first+di[k][0]][q.front().second+di[k][1]] = state[q.front().first][q.front().second] + 1;
                        pq.push(state[q.front().first+di[k][0]][q.front().second+di[k][1]]);
                    }
                }
                q.pop();
            }
        }
    }
    cout << pq.top() << endl;
}

Measured memory_bytes: 1400
/*  ex9-2
    toshiwaka */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SIZE 100000

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}


int main(void){
    //1 ≤ N ≤ 10^5
    //入力の最大の要素数はSIZE+1
    char input[SIZE+1];
    //pop用
    char tmp;
    //入力の長さ,取り除くことができるキューブの数
    int len, count = 0;
    //最初のノードの指す先
    node *first = NULL;

    //入力
    scanf("%s", input);
    len = strlen(input);

    //判定後、スタックに格納
    for(int i = 0; i < len; i++){
      //スタックが空かどうか
      if(first == NULL){
        push(&first, input[i]);
      } else {
        tmp = pop(&first);
        //一致判定
        if(tmp == input[i]){
          push(&first, tmp);
          push(&first, input[i]);
        } else {
          count += 2;
        }
      }
    }

    //結果を出力
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 4956
n = int(input())

_SUBBASE = 26
subtra = 26
divCnt = 0

while True:
    if n <= subtra:
        break
    n -= subtra
    subtra = subtra * _SUBBASE
    divCnt += 1

n -= 1

anslist = []
for _ in range(divCnt+1):
    anslist.append(n%26)
    n = n//26

anslist.reverse()
for ac in anslist:
    print(chr(ord('a') + ac), end="")
print()




Measured memory_bytes: 9180
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[][] M = new int[H][];
		for(int i=0;i<H;i++) M[i] = new int[W];
		for(int i=0;i<N;i++){
			switch(A[i]){
				case 1: for(int j=0;j<X[i];j++) for(int k=0;k<H;k++) M[k][j] = 1; break;
				case 2: for(int j=X[i];j<W;j++) for(int k=0;k<H;k++) M[k][j] = 1; break;
				case 3: for(int j=0;j<W;j++) for(int k=0;k<Y[i];k++) M[k][j] = 1; break;
				case 4: for(int j=0;j<W;j++) for(int k=Y[i];k<H;k++) M[k][j] = 1; break;
			}
		}
		
		int w = 0;
		for(int i=0;i<H;i++) for(int j=0;j<W;j++) w += M[i][j] == 0 ? 1 : 0;
		Console.WriteLine(w);
		
		
		
	}
	int W,H,N;
	int[] X, Y, A;
	public Sol(){
		var d = ria();
		W = d[0]; H = d[1]; N = d[2];
		X = new int[N];
		Y = new int[N];
		A = new int[N];
		for(int i=0;i<N;i++){
			d = ria();
			X[i] = d[0]; Y[i] = d[1]; A[i] = d[2];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 205

int N;
int dp[NUM][NUM];

int grundy(int num_white,int num_black){

	if(dp[num_white][num_black] != -1)return dp[num_white][num_black];

	set<int> S;

	if(num_white > 0){
		S.insert(grundy(num_white-1,num_black));
	}

	for(int i = 1; i <= min(num_black,num_white); i++){
		S.insert(grundy(num_white,num_black-i));
	}

	if(num_black > 0){
		S.insert(grundy(num_white+1,num_black-1));
	}

	int ret = 0;
	while(S.count(ret) != 0)ret++;

	return dp[num_white][num_black] = ret;
}

int main(){

	scanf("%d",&N);

	int num_white,num_black;
	int number = 0;

	for(int i = 0; i < NUM; i++){
		for(int k = 0; k < NUM; k++){
			dp[i][k] = -1;
		}
	}

	for(int loop = 0; loop < N; loop++){

		scanf("%d %d",&num_white,&num_black);

		number ^= grundy(num_white,num_black);
	}

	if(number != 0){

		printf("0\n");
	}else{

		printf("1\n");
	}

	return 0;
}



Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main(){
	fastio();
	string s, t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	cout<<(a-(u==s))<<" "<<b-(u==t);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,s,j,k;
  int a[11][46];
  for(int s=0;s<46;s++)
    for(int n=0;n<11;n++)
      a[n][s]=0;
  n=s=0;
  for(int i=0;i<1024;i++){
    for(j=i,n=0;j>0;j/=2)
      n += j%2;
    for(j=i,s=0,k=0;j>0;j/=2,k++)
      s += j%2*k;
    a[n][s]++;
  }
  while(true){
    cin>>n>>s;
    if(!n&&!s)
      break;
    if(s<46)
      cout<<a[n][s]<<endl;
    else
      cout<<0<<endl;
  }
  return 0;
}
//  for(cin>>n>>s;n||s;cout<<a[n][s]<<endl,cin>>n>>s);

Measured memory_bytes: 0
s = gets.chomp
t = gets.chomp


(s.size-t.size).downto(0) do |i|
#    puts s.slice(i, t.size).gsub(/\?/, ".")
    pat = s[i, t.size]

    ret = false
    pat.size.times do |j|
        ret = pat[j] == '?' || pat[j] == t[j]
        break if ret == false
    end
    if ret
        s[i, t.size] = t
        puts s.gsub('?','a')
        exit
    end
#    if /#{s.slice(i, t.size).gsub("?", ".")}/ === t
#        puts s.gsub!("?","a")
#        exit
#    end
end

puts "UNRESTORABLE"


Measured memory_bytes: 1788
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	X = int(input())
	
	ans = []
	for i in range(1, 1000):
		for j in range(2, 1000):
			tmp = i**j
			if tmp > X:
				break
			ans.append(tmp)
			
	ans.sort()
	print(ans[-1])
			
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 13232
my $input = <STDIN>;
chomp $input;

my @candy = split(/\s/, $input);
@candy = sort {$a <=> $b} @candy;

if ($candy[2] - $candy[0] == $candy[1]) {
    print 'Yes', "\n";
} else {
    print 'No', "\n";
}

exit;

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

int main(){
  int n;

  while(cin >> n){
    int level = 0;
    bool flg = true;

    for(int i = 0; i < n; i++){
      char ch;
      int m;
      cin >> ch >> m;

      if(ch == '('){
        level += m;
      }
      else{
        level -= m;
      }

      if(level < 0){
        flg = false;
      }
    }

    if(level != 0) flg = false;

    cout << (flg ? "YES" : "NO") << endl;
  }
}

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

int main(){
  string a, b;
  cin >> a >> b;
  string s = a + b;
  int c = stoi(s);
  for (int i = 0; i < 1000; i++) {
    if (c == i * i){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using f32 = float;
using f64 = double;
using f80 = __float80;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<LL>;
using vvl = vector<vl>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
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 main()
{
    LL n,a,b,c;
    string A;
    cin >> A;
     vector<LL> aa(A.size());
   for(char c='a';c<='z';c++){
       if(A.find(c)==string::npos){
			cout<<c<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
	return 0;
   
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};


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

    int n,r;
    cin >> n >> r;
    int min=0;
    if(n < 10){
        min = 100 * (10 - n);
    }
    r += min;
    cout << r << endl;

    cout << endl;
    return 0;
}


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

int main()
{
  int N;
  cin>>N;
  int ans=N*25/27;
  if(ans*27/25==N)cout<<ans<<endl;
  else if((ans+1)*27/25==N)cout<<ans+1<<endl;
  else cout<<":("<<endl;
}

Measured memory_bytes: 256
n,ma,mb=map(int,input().split())
inf=10**4
A=[]
append=A.append
for i in range(n):
  a,b,c=map(int,input().split())
  append([a,b,c])
DP=[[[inf]*(10*n+1) for _ in range(10*n+1)] for _ in range(n+1)]
DP[0][0][0]=0
for i in range(n):
  a,b,c=A[i][0],A[i][1],A[i][2]
  for j in range(10*(i+1)+1):
    for k in range(10*(i+1)+1):
      if j>=a and k>=b:
        DP[i+1][j][k]=min(DP[i][j-a][k-b]+c,DP[i][j][k])
      else:
        DP[i+1][j][k]=DP[i][j][k]
ans=inf
for i in range(10*n+1):
  for j in range(10*n+1):
    if i*mb==j*ma and i*j!=0:
      ans=min(ans,DP[n][i][j])
print(ans if ans!=inf else -1)

Measured memory_bytes: 60524
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long seconds = Long.parseLong(br.readLine());
        int h = (int) seconds/60/60;
        int m = (int) (seconds/60)%60;
        int s = (int) seconds%60;
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 24292
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, s: Chars};

    let mut v: Vec<char> = Vec::new();
    v.push(s[0]);

    for i in 1..n {
        if s[i] == s[i - 1] {
            continue;
        } else {
            v.push(s[i])
        }
    }

    println!("{}", v.len());
}


Measured memory_bytes: 2916
//
//  main.cpp
//  hitachi2020A

#include <iostream>
#include <string> // stringを使う
using namespace std;
int main(int argc, const char * argv[]) {
    string S;
    cin >> S;
    bool ok=true;
    unsigned long length=S.length();
    if (length%2==1) { // 文字数が奇数ならダメ
        cout<<"No"<<endl;
        return 0;
    }
    for (long i=0; i<length; i++) {
        if (i%2==0&&S.at(i)!='h') { // 偶数番はhでなければならない
            ok=false;
        }
        if (i%2==1&&S.at(i)!='i') { // 奇数番はiでなければならない
            ok=false;
        }
    }
    if (ok==true) {
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long int a=0;
  long long int w=0;
  long long int r=0;
  long long int t=0;
  for(int i=0;i<n;i++)
  {
     string s;
      cin>>s;
    if(s=="AC")
      a++;
    else if(s=="WA")
      w++;
    else if(s=="TLE")
      t++;
    else if(s=="RE")
      r++;
  }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
using namespace std;
int a,vis[66],n,k;
bool check(int x)
{
	while(x)
	{
		if(vis[x%10]) return 0;
		x/=10;
	}
	return 1;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d",&a);
		vis[a]=1;
	}
	for(int i=n;;i++)
	{
		if(check(i))
		{
			printf("%d",i);
			break;
		}
	}
}

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

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

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

    int ans = 0;
    while(a[0] != -1) {
        for(int i = 0; i < n; i++) {
            if(a[i] % 2 == 0) {
                a[i] /= 2;
            } else {
                cout << ans << endl;
                return 0;
            }
        }
        ans++;
    }
    
    return 0;
}

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！
int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    cout << (n / (a + b) * a) + (min (n % (a + b), a)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    char s; cin >> s;
    ll x = s-'a';
    if (x>=0&&x<=25) cout << 'a' << endl;
    else cout << 'A' << endl;
}

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

int main(){

    double a1, a2; cin >> a1 >> a2;

    if(a1 > a2) swap(a1, a2);


    if(a2 - a1 > 180){
        a2 -= 360;
    }

    double ans = (a2 + a1) / 2;
    if(ans < 0) ans += 360;
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <utility>
#include <functional>
#include <numeric>

//TODO

template <class T>
using vec = std::vector<T>;

constexpr int nil = -1;
constexpr int inf = 1 << 30;

struct Edge
{
    int to;
    int cost;
};

vec<int> dijkstra(const vec<vec<Edge>>& edges)
{
    using namespace std;

    const int n = edges.size();
    vec<int> distances(n, inf);
    vec<bool> reached(n, false);

    distances[0] = 0;

    while (true)
    {
        int minCost {inf};
        int u {};

        for (int i = 0; i < n; ++i)
        {
            if (!reached[i] && distances[i] < minCost)
            {
                minCost = distances[i];
                u = i;
            }
        }

        if (minCost == inf)
            break;
        
        reached[u] = true;

        for (auto& e : edges[u])
        {
            distances[e.to] = min(distances[e.to], distances[u] + e.cost);
        }
    }

    return distances;
}

void solve()
{
    using namespace std;
    int n;
    cin >> n;

    //隣接リスト形式
    vec<vec<Edge>> edges(n);
    
    //入力
    for (int i = 0; i < n; ++i)
    {
        int v, k;
        cin >> v >> k;
        for (int j = 0; j < k; ++j)
        {
            int to, cost;
            cin >> to >> cost;
            edges[i].push_back({to, cost});
        }
    }

    auto d = dijkstra(edges);

    for (int i = 0; i < n; ++i)
    {
        cout << i << " " << d[i] << endl;
    }
}

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


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

int main()
{
    int n;
    int l,r;
    int ans=0;

    cin >> n;

    int i;
    for(i=0;i<n;i++){
        cin >> l >> r;
        ans+=r-l+1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
    int a,b,i,c;

    scanf("%d%d",&a,&b);
    i=b;
    if(b<10)
        a*=10;
    else if(b<100)
        a*=100;
    c=a+b;
    for(i=0;i<=100;i++)
        if(c==i*i){
            printf("Yes");
            return 0;
        }
    printf("No");

    return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] } // maxにするためにあえて変更
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]

	return x
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := scanInt(), scanInt()
	A := make(IntHeap, N)
	for i := 0; i < N; i++ {
		A[i] = scanInt()
	}

	heap.Init(&A)
	for i := 0; i < M; i++ {
		max := heap.Pop(&A).(int)
		heap.Push(&A, max/2)
	}

	ans := 0
	for _, a := range A {
		ans += a
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4608
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a > b) {
        for(int i = 0; i < a; i++){
            cout << b;
        }
    }else{
        for(int i = 0; i < b; i++){
            cout << a;
        }
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <cassert>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

vector<int> Z_Algorithm(string s)
{
    vector<int> res(s.size());

    int l = 0;
    int r = 0;

    for (int i = 1; i < s.size(); i++)
    {
        if (r < i)
        {
            l = i;
            r = i;
            while (r < s.size() && s[r] == s[r - l])
                r++;
            res[i] = r - l;
            r--;
        }
        else
        {
            int k = i - l;
            if (res[k] < r - i + 1)
            {
                res[i] = res[k];
            }
            else
            {
                l = i;
                r++;
                while (r < s.size() && s[r] == s[r - l])
                    r++;
                res[i] = r - l;
                r--;
            }
        }
    }

    res[0] = s.size();

    return res;
}

int main()
{
    string w;
    cin >> w;

    bool same = true;
    REP(i, w.size() - 1)
    if (w[i] != w[i + 1])
        same = false;

    if (same)
    {
        cout << w.size() << endl
             << 1 << endl;
        return 0;
    }

    int div = 0;

    for (int i = w.size() - 1; i > 1; i--)
    {
        if (w.size() % i)
            continue;

        string p = w.substr(0, w.size() / i);

        string c = "";
        REP(j, i)
        c += p;

        if (c == w)
        {
            div = i;
            break;
        }
    }

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

    int size = w.size() / div;

    V z = Z_Algorithm(w);

    bool g[512345];
    fill(g, g + w.size(), true);

    for (int i = 1; i < w.size(); i++)
    {
        for (int k = 2; (k - 1) * i <= z[i]; k++)
            g[k * i] = false;
    }

    reverse(w.begin(), w.end());
    z = Z_Algorithm(w);

    for (int i = 1; i < w.size(); i++)
    {
        for (int k = 2; (k - 1) * i <= z[i]; k++)
            g[w.size() - k * i] = false;
    }

    int res = 0;
    for (int i = 1; i < w.size(); i++)
        res += g[i];

    cout << 2 << endl
         << res << endl;

    return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long DP[5000][5001][2];
long Combs[5001];
vector<int> G[5001];
int dfs(int v,int f){
	int ans = 1;
	DP[v][1][0] = 1;
	FOR(i,G[v].size()){
		int t = G[v][i];
		if(t != f){
			int x = dfs(t,v);
			long c0 = 0;
			long c1 = 0;
			for(int k=1;k<=x;k++){
				c0 += Combs[k]*DP[t][k][0]%mod;
				c1 += Combs[k]*DP[t][k][1]%mod;
			}
			c0 %= mod;
			c1 %= mod;
			for(int j=ans;j>=1;j--){
				for(int k=1;k<=x;k++){
					DP[v][j+k][0] += DP[v][j][0]*DP[t][k][0]%mod;
					DP[v][j+k][0] += DP[v][j][1]*DP[t][k][1]%mod;
					DP[v][j+k][1] += DP[v][j][0]*DP[t][k][1]%mod;
					DP[v][j+k][1] += DP[v][j][1]*DP[t][k][0]%mod;
					DP[v][j+k][0] %= mod;
					DP[v][j+k][1] %= mod;
				}
				long temp0 = DP[v][j][0]*c1%mod + DP[v][j][1]*c0%mod;
				long temp1 = DP[v][j][0]*c0%mod + DP[v][j][1]*c1%mod;
				DP[v][j][0] = temp0 % mod;
				DP[v][j][1] = temp1 % mod;
			}
			ans += x;
		}
	}
	return ans;
} 
void Calc(){
	int N = rei();
	FOR(i,N-1){
		int x = rei()-1;
		int y = rei()-1;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	Combs[0] = 1;
	for(int i=2;i<=N;i+=2){
		Combs[i] = (i-1) * Combs[i-2] % mod;
	}
	dfs(0,-1);
	long count = 0;
	for(int i=1;i<=N;i++){
		count += Combs[i]*DP[0][i][0]%mod;
		count += mod - Combs[i]*DP[0][i][1]%mod;
	}
	count %= mod;
	cout<<count<<endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 389760
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    if (n == 1 && m == 1) cout << 1;
    else if (n == 1 || m == 1) cout << n * m - 2;
    else cout << (n - 2) * (m - 2);
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = list(map(int,input().split()))

S = sum(A)
line = -(-S/(4*M))

A.sort()
A = A[::-1]
flag = 1
for i in range(M):
    if A[i] < line:
        flag = 0
        break
if flag == 1:
    print('Yes')
else:
    print('No')

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct Edge {
    int to;     // 辺の行き先
    int cost; // 辺の重み
    Edge(int t, int c) : to(t), cost(c) { }
};

vector<ll> dijkstra(vector<vector<Edge>> &g, int s) {
    vector<ll> dist(g.size(), inf);

    using Pli = pair<ll, int>;
    priority_queue< Pli, vector<Pli>, greater<Pli> > que;
    dist[s] = 0;
    que.emplace(dist[s], s);

    while (!que.empty()) {
        ll cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if (dist[idx] < cost) continue;

        for (auto &e: g[idx]) {
            auto next_cost = cost + e.cost;
            if (dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector <vector<Edge>> G(n);

    for (int i = 0; i < n-1; i++) {
        G[i].push_back(Edge(i+1, 1));
        G[i+1].push_back(Edge(i, 1));
    }
    G[x].push_back(Edge(y, 1));
    G[y].push_back(Edge(x, 1));
    vector <int> ans(n-1, 0);

    for (int i = 0; i < n; i++) {
        vector<ll> cost = dijkstra(G, i);
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            ans[cost[j]-1]++;
        }
    }
    
    for (int i = 0; i < n-1; i++) {
        cout << ans[i]/2 << endl;
    }
    return 0;
}



Measured memory_bytes: 384
from scipy.sparse import*
_,*s=open(i:=0)
M=999
*g,=eval('[0]*M,'*M)
for t in s:
 i+=1;j=0
 for u in t:k=i*20+j;g[k][k+20]=u>'#'<(s+['#'*M])[i][j];j+=1;g[k][k+1]=u>'#'<t[j]
a=csgraph.johnson(csr_matrix(g),0)
print(int(max(a[a<M])))

Measured memory_bytes: 55336