akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>

using namespace std;

int h, w, n;
vector<pair<int, int>> map;
vector<pair<int, int>> List;

queue<int> q;

int loop(int start, int end) {
	for (int i = 0; i < h * w; i++) {
		map[i].second = 0;
	}
	while (!q.empty()) {
		q.pop();
	}
	queue<int> tmp;
	q.push(start);
	for (int i = 1; true; i++) {
		while (!q.empty()) {
			int front = q.front();
			q.pop();
			map[front].second = -1;

			if (front / w != 0) {
				if (map[front - w].first != 'X' && map[front - w].second != -1) {
					if (front - w == end) {
						return i;
					}
					map[front - w].second = -1;
					tmp.push(front - w);
				}
			}

			if (front / w != h - 1) {
				if (map[front + w].first != 'X' && map[front + w].second != -1) {
					if (front + w == end) {
						return i;
					}
					map[front + w].second = -1;
					tmp.push(front + w);
				}
			}

			if (front % w != 0) {
				if (map[front - 1].first != 'X' && map[front - 1].second != -1) {
					if (front - 1 == end) {
						return i;
					}
					map[front - 1].second = -1;
					tmp.push(front - 1);
				}
			}

			if (front % w != w - 1) {
				if (map[front + 1].first != 'X' && map[front + 1].second != -1) {
					if (front + 1 == end) {
						return i;
					}
					map[front + 1].second = -1;
					tmp.push(front + 1);
				}
			}
		}
		swap(q, tmp);
	}
}

void set_map() {
	pair<int, int> map_p;
	pair<int, int> list_p;
	for (int i = 0; i < h; i++) {
		string tmp;
		cin >> tmp; // map状況
		for (int j = 0; j < w; j++) {
			map_p.first = tmp[j]; // map状況
			map_p.second = 0; //queのための値
			map.push_back(map_p);
			if (map_p.first != 'X' && map_p.first != '.') {
				list_p.first = i * w + j; // map上の何番目なのか
				if (map_p.first == 'S') { // 何番目のゴールなのか
					list_p.second = 0;
				} else {
					list_p.second = map_p.first - '0';
				}
				vector<pair<int, int>>::iterator ite = List.begin();
				int k = 0;
				for (; k < List.size(); ite = std::next(ite, 1), k++) {
					if (list_p.second < List[k].second) {
						List.insert(ite, list_p);
						break;
					}
				}
				if (k == List.size()) {
					List.push_back(list_p);
				}
			}
		}
	}
}

int main(int argc, char **argv){

	cin >> h >> w >> n;
	set_map();
	int count = 0;
	for (int i = 1; i < List.size(); i++) {
		count += loop(List[i - 1].first, List[i].first);
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 10436
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) cout << "1" << endl;
    else cout << (h*w+1)/2 << endl;
}

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

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

  map<int, int> m;
  // vector<int> v;
  for(int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;

    // v.push_back(s);
    if(m.count(s) == 1 && m[s] != c) {
      cout << "-1" << endl;
      return 0;
    } else {
      m.emplace(s, c);
    }
  }

  string ans = "";
  for(int i = 1; i <= N; i++) {
    ostringstream ss;
    if(m.count(i) == 1) {
      ss << m[i];
    } else {
      if(i == N){
        ss << 0;
      } else if(i == 1) {
        ss << 1;
      } else {
        ss << 0;
      }
    }
    ans = ans + ss.str();
  }

  if(ans.size() > 1){
    if(ans[0] == '0') {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << ans << endl;
}


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

int main(void){
    int N, K;
    cin >> N >> K;
    if ((N-1)*(N-2)/2 < K)
        cout << -1 << endl;
    else {
        cout << ((N-1) + (N-1)*(N-2)/2 - K) << endl;
        for (int i = 2; i <= N; i++)
            cout << "1 " << i << endl;
        
        int count = (N-1)*(N-2)/2 - K;
        if (count != 0) {
            for (int i = 2; i < N; i++) {
                for (int j = i+1; j <=N; j++) {
                    cout << i << " " << j << endl;
                    count--;
                    if (count == 0)
                        break;
                }
                if (count == 0)
                    break;
            }
        }
    }
}

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

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

    int n;
    cin >> n;
    string ans = "Yes";
    vector<string> w(n);
    rep(i, n) cin >> w[i];

    rep(i,n-1){
        string x = w[i];
        string y = w[i + 1];
        if(x[x.size()-1]!=y[0])
            ans = "No";
    }
    rep(i, n-1) forx(j, i + 1, n) if (w[i] == w[j]) ans = "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
    #include<bits/stdc++.h>
    //#include <ext/pb_ds/assoc_container.hpp> 
    #define vi vector<long long int>
    #define ll long long 
    #define mp make_pair
    #define p push
    #define pb push_back
    #define np next_permutation
    #define fin(i,a,b) for(int i=a;i<b;i++)
    #define max3(a,b,c) max(max(a,b),c)
    #define min3(a,b,c) min(min(a,b),c)
    //typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
    const ll INF =1e18;
    const ll mod =1e9+7;
    using namespace std;
    const int N = 50000;
    int checkprime(int n){
        for(int i=2;i<min(N,n);i++){
            if(n%i==0)return 0;
        }
        return 1;
    }
    //using namespace __gnu_pbds;

    int main(){

        #ifdef _DEBUG
        freopen("input.txt", "r", stdin);
    //	freopen("output.txt", "w", stdout);
    #endif
        ios::sync_with_stdio(0); 
        cin.tie(0);
        cout.tie(0);
        //code from here>>
        ll n;
        cin>>n;
        vector<pair<int,int>> v;

        for(int i=0;i<n;i++){
            int a,b;
            cin>>a>>b;
            v.pb({a,b});
        }
        int flag=0;
        for(int i=0;i<=n-3;i++){
            if(v[i].first==v[i].second){
                if(v[i+1].first==v[i+1].second){
                    if(v[i+2].first==v[i+2].second){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)cout<<"Yes"<<endl;
        else{
            cout<<"No"<<endl;
        }
       
            
        
        
        
        return 0;
    }


Measured memory_bytes: 3644
#include<iostream>

using namespace std;

int main()
{
    int n, d;

    cin>>n>>d;

    int num = 0;
    if(n%(2*d+1) == 0)
        num = n/(2*d+1);
    else
        num = n/(2*d+1) + 1;
    cout<<num;
    
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n = int(readline())
d = list(map(int, readline().split()))
m, *t = map(int, read().split())
d = Counter(d)
for k, v in Counter(t).items():
    if d[k] < v:
        print('NO')
        break
else:
    print('YES')


Measured memory_bytes: 56952
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //__gnu_pbds::gp_hash_table<int, int> table;
//priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;  //min heap

typedef int OwO;
typedef double UwU;

#define int long long
#define double long double
#define INF 1000000000
#define PI 3.14159265358979323846
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vi vector<int>

using namespace std;

OwO main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  double W,H,x,y;
  cin >> W >> H >> x >> y;
  double oup = (double)W*(double)H/2.0;
  int c = 2*x==W&&2*y==H;
  cout << oup << " " << c << endl;


  return 0;
}

Measured memory_bytes: 256
let max_list lst = List.fold_left (fun a b -> if a > b then a else b) (List.hd lst) lst
let min_list lst = List.fold_left (fun a b -> if a < b then a else b) (List.hd lst) lst

let () = 
    Scanf.scanf "%d %d %d" @@ fun a b c -> 
        let lst = [a;b;c] in
        Printf.printf "%d\n" @@ max_list lst - min_list lst


Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10,9) + 7;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	int n;cin >> n;
	vector<int> t(n);
	rep(i,n) cin >> t[i];
	int m; cin >>m;
	vector<int> p(m), x(m);
	rep(i,m){
		cin >> p[i] >> x[i];
	}
	rep(i,m){
		int count = 0;
		rep(j,n){
			if (p[i]==j+1){
				count += x[i];
			}else {
				count += t[j];
			}
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,x,y,a,b;
string s[111];
void init() {
  a=b=0;
  for(int i=0; i<n; i++) {
    s[i]="";
    for(int j=0; j<x; j++) {
      if(j) for(int k=0; k<y; k++) s[i]+='.';
      for(int k=0; k<m; k++) s[i]+='.';
    }
  }
}

void print() {
  for(int i=0; i<n; i++) cout << s[i] << endl;
  cout << "#" << endl;
}

void next() {
  a++;
  if(a==n) {
    a=0;
    b++;
  }
  if(b==x) {
    print();
    init();
  }
}

int main() {
  while(cin >> n && n) {
    cin >> x >> m >> y;
    string t;
    getline(cin,t);
    init();
    while(getline(cin,t)) {
      if(t=="?") {
        if(a||b) print();
        cout << t << endl;
        break;
      }
      int k=0;
      for(int i=0; i<t.size(); i++) {
        s[a][b*(m+y)+k]=t[i];
        k++;
        if(k==m) {
          k=0;
          next();
        }
      }
      if(k||t=="") next();
    }
  }
  return 0;
}

Measured memory_bytes: 3072
#include <stdio.h>
#include <stdlib.h>
#define inf 1<<30
#define min(a,b) a<b?a:b
int needTime(int x[], int start, int end);
int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int x[n],y[n];
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&x[i]);
    }
    for(int i = 0; i < n; i++)
    {
        y[i] = inf;
    }

    int tmp = 0;
    while(tmp <= n - k)
    {
        y[tmp] = needTime(x,tmp,k);
        tmp++;
    }

    int ans = inf;
    for(int i = 0; i < n; i++)
    {
        ans = min(y[i],ans);
    }
    printf("%d\n",ans);
}

int needTime(int x[], int start, int k)
{
    if(x[start] >= 0)
    {
        return x[start + k - 1];
    }
    if(x[start + k - 1] <= 0)
    {
        return abs(x[start]);
    }

    return min(abs(x[start]) * 2 + x[start + k - 1], abs(x[start]) + x[start + k - 1] * 2);
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <algorithm> 
#include <set>
#include <sstream>
#include <bit>
#include <bitset>
#include <iomanip>
#include <queue>
typedef long long int ll;
using namespace std;
int main() {
	int N; cin >> N;
	vector<ll>data(N);
	for (int i = 0; i < N; i++)cin >> data[i];
	sort(data.begin(), data.end());
	bool ans = true;
	for (int i = 0; i < N -1 ; i++) {
		if (data[i] == data[i + 1])ans = false;
	}
	if (ans) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 4396
n=int(input())
a=list(sorted(map(int,input().split())))
d=[0 for i in range(a[-1]+1)]
c=0
for i in range(len(a)):
  if d[a[i]]:
    continue
  if i==len(a)-1 or a[i]!=a[i+1]:
    c+=1
  for j in range(a[i],a[-1]+1,a[i]):
    d[j]=1
print(c)

Measured memory_bytes: 158664
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
ll n,m;
cin>>n>>m;
vector<ll> a(n);
for(auto& h : a)cin>>h;
vector<ll> b(n+1,0);
for(int i=0;i<n;++i)
b[i+1]=(b[i]+a[i])%m;
map<ll,ll> x;
for(auto h : b)
x[h]++;
ll ans=0;
for(auto h : x)
ans+=h.second*(h.second-1)/2;
cout<<ans<<endl;
}


Measured memory_bytes: 5760
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    import math
    fmin = 10 ** 10
    for i in range(1, math.ceil(math.sqrt(n))+1):
        if n % i == 0:
            b = int(n / i)
            if fmin > max(len(str(i)), len(str(b))):
                fmin = max(len(str(i)), len(str(b)))

    print(fmin)


resolve()

Measured memory_bytes: 39152
n = gets.strip.to_i
s = gets.strip

# white count: wc, black count: bc
wc = s.count(".")
bc = 0 
ans = wc
n.times do |i|
  if s[i] == '.'
    wc -= 1
  else
    bc += 1
  end
  ans = wc + bc if ans > wc + bc
end
puts ans


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int h,a;
  cin >> h >>a;
  int c=0;
  while(h>0){
    c++;
    h-=a;
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    N, M = list(map(int, input().split()))
    Hs = list(map(int, input().split()))

    goods = [1 for _ in range(N)]
    for _ in range(M):
        a, b = list(map(int, input().split()))
        a, b = a-1, b-1
        if Hs[a] > Hs[b]:
            goods[b] = 0
        elif Hs[b] > Hs[a]:
            goods[a] = 0
        else:
            goods[a] = 0
            goods[b] = 0

    print(sum(goods))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 20124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define tri pair<pll, ll>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll cpow(ll a, ll b, ll M){ll ans = 1;while(b){if(b&1) ans = ans*a%M; b/=2;a=a*a%M;}return ans;}
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}
ll fexp(ll a, ll b) {return cpow(a, b, MOD);}
ll cinv(ll a, ll p){return cpow(a, p-2, p);} 
ll inverse(ll a)    {return cinv(a, MOD);}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n;
        cin>>n;
        vl vec(n); 
        ll x;
        rep(i, n){
            cin>>x;
            vec[--x] = i;
        }
        vl dp(n);
        dp[0] = 1;
        ll ans = n-1;
        rep1(i, n){
            if(vec[i] > vec[i-1])   dp[i] = dp[i-1] + 1;
            else dp[i] = 1;
            ans = min(ans, n - dp[i]);
        }
        cout<<ans;
    }
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int a,p;
	cin >> a >> p;
	cout << (a*3+p)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int stoi (string s ){
	stringstream ss (s );
	int res;
	ss >> res;
	return res;
}
string itos (int n ){
	stringstream ss;
	ss << n;

	return ss.str();
}

int main()
{
	ios_base::sync_with_stdio(0);
	string a; int l;
	while (cin >> a >> l ){
		if (a == "0" && l == 0 ) break;
		set<int> num; num.clear();
		map<int,int> pos; pos.clear();
		int na = stoi (a );
		num.insert (na );
		int i = 0;
		pos[na] = i;
		while (true ){
			while (a.length() < l ){
				a = '0' + a;
			} // end while
			sort (ALL (a ) );
			int mina = stoi (a );
			reverse (ALL (a ) );
			int maxa = stoi (a );
			int next = maxa - mina;
			++i;
			if (num.count (next ) ){
				cout << pos[next] << ' ' << next << ' ' << i - pos[next] << endl;
				break;
			}else{
				num.insert (next );
				pos[next] = i;
			} // end if
			a = itos (next );
		} // end while
	} // end while
		
	return 0;
}

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

int w, h;
int data[99][99]; //y,x

int solve(int x, int y){

  if(x < 0 || y < 0 || x == w || y == h) return 0;
  if(!data[y][x]) return 0;

  data[y][x] = 0;
  for(int i=-1;i<2;i++) for(int j=-1;j<2;j++) solve(x+j, y+i);

  return 1;
}

int main(){

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> data[i][j];

    int ret = 0;
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) ret += solve(j, i);

    cout << ret << endl;
  }

}

Measured memory_bytes: 1292
#include <stdio.h>

int main(void)
{
  double a, b, c, d, e, f;
  double x, y;

  while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){

  x = (c*e - b*f) / (a*e - b*d);
  y = (a*f - c*d) / (a*e - b*d);

  if(x == 0) x = 0.000;
  else if(y == 0) y = 0.000;

  printf("%.3f %.3f\n", x, y);

  }

  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

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

  // cout << s - (s/100)*100 << " " << s/100;
  if(1 <= s/100 && s/100   <= 12 && 1 <= s - (s/100)*100 && s - (s/100)*100 <= 12 ){
    cout << "AMBIGUOUS" << endl;
  } else if(1 <= s/100 && s/100 <= 12 && (1 >  s - (s/100)*100 ||  s - (s/100)*100 >= 12 )){
    cout << "MMYY" << endl;
  } else if((1 > s/100 || s/100 >= 12 ) && 1 <= s - (s/100)*100 && s - (s/100)*100 <= 12 ){
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
    
  return 0;
}

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

int main() {
  int N;cin>>N;
  vector<long> kazu(300000,0);//[i]=:数字iはいくつあるか
  vector<long> A(N);
  for(int i=0;i<N;i++){
    int a;cin>>a;
    A[i]=a;
    kazu[a]++;
  }
  long wa=0;//一つも選ばない時の数
  for(int i=0;i<kazu.size();i++){
    wa+=kazu[i]*(kazu[i]-1)/2;
  }
  for(int i=0;i<N;i++){
    cout<<wa-kazu[A[i]]+1<<endl;
  }
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int H = scanner.nextInt();
        int M = scanner.nextInt();

        double angle = Math.abs(360.0*H/12.0 - 360.0*M/60.0 + 30.0*M/60.0);
        double length = Math.sqrt(Math.pow(A, 2) + Math.pow(B, 2) - 2*A*B*Math.cos(Math.toRadians(angle)));
        System.out.println(length);
    }
}

Measured memory_bytes: 35832
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  string s; cin >> s;
  int ans = INF;

  REP(i,2) {
    int tot=0;
    REP(j,s.size()) {
      if (j%2) {
        if (s[j]-'0' == i) {
          tot++;
        }
      } else {
        if (s[j]-'0' != i) {
          tot++;
        }
      }
    }
    chmin(ans,tot);
  }

  COUT(ans);
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323


#define TST 0

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;
    vi a(n);
    // [value: number of the value]
    map<int, int> m;
    ull sum = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        m[a[i]] += 1;
        sum += a[i];
    }
    int Q;
    cin >> Q;
    for(int i = 0;i < Q;i++){
        int B,C;
        cin >> B >> C;
        int diff = C-B;
        sum = sum + m[B] * diff;
        m[C] += m[B];
        m[B] = 0;
        cout << sum << endl;
    }

#if TST==1

#endif
}



Measured memory_bytes: 7960
s =input()

c = 0
m = 0
for i in range (len(s)):
  if s[i] == "A" or s[i] == "T" or s[i] == "C" or s[i] == "G":
      c += 1
      if c >= m:
        m = c
  else:
    c = 0
print(m)
    

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

using namespace std;

void Main() {
    long long N;
    cin >> N;
    map<long long, set<pair<long long, long long> > > tree;
    for (long long i = 0; i < N - 1; ++i) {
        long long a, b, c;
        cin >> a >> b >> c;
        if (tree.count(a) == 0) {
            tree.insert(make_pair(a, set<pair<long long, long long> >()));
        }
        tree[a].insert(make_pair(b, c));
        if (tree.count(b) == 0) {
            tree.insert(make_pair(b, set<pair<long long, long long> >()));
        }
        tree[b].insert(make_pair(a, c));
    }

    long long Q, K;
    cin >> Q >> K;
    vector<long long> distanceFromK(N + 1, -1LL);
    distanceFromK[K] = 0LL;
    queue<long long> q;
    q.push(K);
    while (!q.empty()) {
        long long f = q.front();
        q.pop();
        long long distanceFromTop = distanceFromK[f];
        const set<pair<long long, long long> >& nextNodes = tree[f];
        for (auto e : nextNodes) {
            if (distanceFromK[e.first] < 0) {
                q.push(e.first);
                distanceFromK[e.first] = e.second + distanceFromTop;
            }
        }
    }

    for (long long i = 0; i < Q; ++i) {
        long long x, y;
        cin >> x >> y;
        long long dx = distanceFromK[x];
        long long dy = distanceFromK[y];
        cout << (dx + dy) << endl;
    }

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
	string S, T;
	cin >> S;
	cin >> T;
	int count = 0;
	for (int i = 0; i < 3; i++) {
		if (S.at(i) == T.at(i)) count++;
	}
	cout << count << endl;
}

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

#define int long long
const int N = 3005;
double dp[N][N];

int32_t main(){
    int n;
    cin >> n;
    double arr[n+1];
    arr[0] = 0;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j == 0){
                dp[i][j] = dp[i-1][j] * (1-arr[i]);
                continue; 
            }
            if(i == j){
                dp[i][j] = dp[i-1][j-1]*arr[i];
                continue;
            }
            double temp = 1;
            temp -= arr[i];
            dp[i][j] = dp[i-1][j]*temp + dp[i-1][j-1]*arr[i];
        }
    }
    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=i;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    double ans = 0;
    int st = ceil((double)n/(double)2);
    for(int i=st;i<=n;i++){
        ans += dp[n][i];
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
}

Measured memory_bytes: 49952
a,b=map(int,input().split())
s=input()
num=["0","1","2","3","4","5","6","7","8","9"]
left=s[:a]
right=s[a+1:]
if s[a] != '-':
    print('No')
    exit()
for i in left:
    if i in num:
        continue
    else:
        print('No')
        exit()
for j in right:
    if j in num:
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main(void)
{
	int h1,h2,k1,k2,a,b,c,d,iwa1,iwa2,yama1,yama2;
	cin>>h1>>h2>>k1>>k2>>a>>b>>c>>d;
	iwa1=h1*a,iwa2=k1*a;
	yama1=h2*b,yama2=k2*b;
	if((iwa1+yama1+(h1/10)*c+(h2/20)*d)>iwa2+yama2+(k1/10)*c+(k2/20)*d) cout<<"hiroshi"<<endl;
	else if((iwa1+yama1+(h1/10)*c+(h2/20)*d)<iwa2+yama2+(k1/10)*c+(k2/20)*d) cout<<"kenjiro"<<endl;
	else cout<<"even"<<endl;
}

Measured memory_bytes: 3092
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
time = []

for i in range(N):
    a = int(input())
    time.append(a)

print(lcm(*time))


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

int main() {
	string s;
	cin >> s;
	ll ans = 0;
	for (int i = 0;i < s.size();i++) {
		if (s[i] == '2') {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INFTY = (1<<21);
static const int MAX =100;

int n, M[MAX][MAX];

int prim(){
    int u,minv;
    int d[MAX],p[MAX], color[MAX];
    
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }
    d[0] = 0;
    
    while(1){
        minv = INFTY;
        u = -1;
        for(int i = 0; i < n; i++){
            if(minv > d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u == -1)break;
        color[u] = BLACK;
        for(int v = 0; v < n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v] > M[u][v]){
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0; i < n; i++)if(p[i] != -1)sum += M[i][p[i]];
                return sum;
    }   

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int e; cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }
    cout << prim() << endl;
    
    return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int x[n];
  int y[n];
  long h[n];
  int i,j,k;
  int cx,cy;
  long hh;
  int chk=0;
  for(i=0;i<n;i++){
    cin >> x[i] >> y[i] >> h[i];
  }
  for(i=0;i<=100;i++){
    for(j=0;j<=100;j++){
      chk = 1;
      for(k=0;k<n;k++){
        if(h[k]>0){
          hh=h[k]+abs(x[k]-i)+abs(y[k]-j);
          cx = i;
          cy = j;
          break;
        }
      }
      for(k=0;k<n;k++){
        if(h[k]!=max(long(0),hh-abs(x[k]-cx)-abs(y[k]-cy)))chk=0;
      }
      if(chk==1)break;
    }
    if(chk==1)break;
  }
  cout << cx << " " << cy << " " << hh;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0593>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    ll N,M; cin >> N >> M;
    vector<ll> A(N),B(M);
    for(auto& in:A) cin >> in;
    for(auto& in:B) cin >> in;
    
    vector<ll> Vote(N,0);
    for(int i = 0; i < M;i++){
        for(int j = 0; j < N;j++){
            if(A[j] <= B[i]){
                Vote[j]++;
                break;
            }
        }
    }
    res = max_element(Vote.begin(), Vote.end()) - Vote.begin()+1;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3196
#include <stdio.h>

int main(void)
{
    int W, H, x, y, r;

    scanf("%d %d %d %d %d", &W, &H ,&x , &y, &r);

    if ((x + r) > W || (x - r) < 0)
        printf("No\n");

    else if ((y +r) > H || (y - r) < 0)
        printf("No\n"); 

    else 
        printf("Yes\n");

    return 0;
 }


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

int main(){
  double W,H,x,y;
  cin>>W>>H>>x>>y;
  cout<<W*H/2<<" ";
  if(x==W/2 && y==H/2){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
}

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    int N,R;
    cin >> N >> R;
    if(N > 10){
        cout << R;
    } else {
        cout << R + 100*(10-N);
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
string S;
int T[100003];

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

  cin >> S;
  int i =0;
  int even_cnt = 0;
  int odd_cnt = 0;
  int l_tamari = 0;
  int r_tamari = 1;
  while(i < S.size()){
    if (i%2) even_cnt+= 1;
    else odd_cnt+= 1;
    char p = S[i];
    char n = S[i+1];
    if (p == 'L' && n == 'R'){
      if (l_tamari%2 == 0){
        T[l_tamari] = odd_cnt;
        T[r_tamari] = even_cnt;
        even_cnt = 0;
        odd_cnt = 0;
      } else {
        T[l_tamari] = even_cnt;
        T[r_tamari] = odd_cnt;
        even_cnt = 0;
        odd_cnt = 0;
      }
      i++;
      continue;
    }
    if (p == 'R' && n == 'L'){
      l_tamari = i;
      r_tamari = i+1;
    }
    i++;
  }

  // 最後
    if (l_tamari%2 == 0){
      T[l_tamari] = odd_cnt;
      T[r_tamari] = even_cnt;
    } else {
      T[l_tamari] = even_cnt;
      T[r_tamari] = odd_cnt;
    }

  rep(i, S.size()){
    cout << T[i] << ' ';
  }
  return 0;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer x=nil->next;
  while(x!=nil && x->key!=key) x=x->next;
  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t=nil->prev;
  deleteNode(t);
}

void delete(int key){
  NodePointer x;
  x=listSearch(key);
  deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

int main(){
    int h,w,d;
    cin >> h >> w >> d;
    int x[90001];
    int y[90001];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int a;
            cin >> a;
            x[a]=i;
            y[a]=j;
        }
    }

    int dis[90001];
    for(int i=d+1;i<=h*w;i++){
        dis[i] = dis[i-d] + abs(x[i]-x[i-d]) + abs(y[i]-y[i-d]);
    }
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int l,r;
        cin >> l >> r;
        cout << dis[r] - dis[l]<< endl;
    }
}

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

using namespace std;

int main(){
    int s;
    vector<int> vv;
    vector<int> cv;

    cin >> s;

    int x = s;
    int c = s; 
    while(x--){
        int a;
        cin >> a;
        vv.push_back(a);
    }

    while(c--){
        int a;
        cin >> a;
        cv.push_back(a);
    }

    x = 0;
    c = 0;
    for(int a = 0; a<s; ++a){
        if(vv[a] >= cv[a]){
            x+=vv[a];
            c+=cv[a];
        }
    }

    cout << x-c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint INF = 1e18;
#define rep(i, n) for(int i = 0; i < int(n); i++)
 
signed main(){
	int a, b;
	cin >> a >> b;
	int ans = (b - 1) / (a - 1);
	if((b - 1) % (a - 1) != 0) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
li = []
for i in range(n):
    x,l=map(int,input().split())
    li.append([x-l,x+l])
li.sort(key = lambda x:x[1])
ans = 1
r = li[0][1]
for i in range(1,n):
    if r <= li[i][0]:
        ans += 1
        r = li[i][1]
print(ans)

Measured memory_bytes: 62936
#include<bits/stdc++.h>
using namespace std;
string s,r;

int ok(int p){
	for(int i=0;i<r.size();i++){
		if(s[p+i]!='?'&&s[p+i]!=r[i])return 0;
	}
	return 1;
}

int main(){
	int c=0;
	bool b=0;
	cin>>s>>r;
	for(int i=s.size()-r.size();i>=0;i--){
		if(ok(i)){
			for(int j=0;j<r.size();j++){
				s[i+j]=r[j];
			}
			b=1;
			break;
		}
	}
	if(b){
		for(int i=0;i<s.size();i++){
			cout<<(s[i]=='?'?'a':s[i]);
		}
		cout<<'\n';
	}else{
		cout<<"UNRESTORABLE\n";
	}
} 

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int t, a[100], i=0, cont=1, nve;

  scanf("%d", &t);

  while(t--){
    scanf("%d", &a[i]);
    i++;
  }

  for(int k=i-1, c=i-2; k>=1; k--, c--){
    nve=0;
          for(int j=k; j>=0 ; j--){

              if( (a[k] < a[j]) && (k!=j)){
                  nve=1;}
            }

          if(nve!=1)
              cont++;
  }

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

  return 0;
}


Measured memory_bytes: 128
#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; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int k, cnt = 0;
    cin >> k;

    priority_queue<int, vector<ll>, greater<ll>> que;
    
    for (ll i = 1; i < 10; i++) {
        que.emplace(i);
    }
    ll now;
    while (cnt < k) {
        now = que.top();
        que.pop();
        cnt++;

        ll last = now % 10;
        if (last - 1 >= 0) que.emplace(now*10 + last-1);
        que.emplace(now*10 + last);
        if (last + 1 <= 9) que.emplace(now*10 + last+1);
    }

    cout << now << endl;

    return 0;
}



Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;

int main() {
    double l;
    cin >> l;
    double ans=l*l*l/27;
    printf("%.12f\n",ans);
}
 



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>

using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main()
{
    int x;
    cin >> x;
    Vl d;
    d = divisor(x);
    //rep(i, d.size())  cout << d[i] << endl;

    int a, b;
    bool f = false;
    rep(i, int(d.size())) {
        for (int j = -1000; j <= 1000; j++) {
            a = j;
            b = a - d[i];
            if ((a * a * a * a * a - b * b * b * b * b )== x) {
                f = true;
                break;
            }
        }
        if (f)  break;
    }
    cout << a << " " << b << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <iomanip>
#include <map>
#include <stack>
#include <sstream>

using namespace std;
int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int size;
	std::cin >> size;
	int qanak = 0;
	std::vector <int> v(size);
	for (int i = 0; i < v.size(); i++)
	{
		std::cin >> v[i];
	}
	
	for (int i = 0; i < size; ++i)
	{
		if (v[i] % 2 !=0 && i % 2 !=1 )
		{
			//cout << v[i] << endl;
			qanak++;
		}
		//cout<< v[i] << endl;
	}
	//cout << ".........................." << endl;
	cout << qanak;

	return 0;

}

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    set<int> values;
    for (int i = 0; i < N; i++) {
        values.insert(d[i]);
    }
    cout << values.size() << endl;
}


Measured memory_bytes: 256
def cal(lst1, lst2):
    lst3 = [0, 0, 0]
    for i in range(3):
        if lst1[i] in lst2:
            lst3[i] = 1
    return lst3

def judge(a, b, c):
    if (a == 1) and (a == b == c):
        return True
    else:
        return False

A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))
A_3 = list(map(int, input().split()))
N = int(input())
b = [int(input()) for _ in range(N)]

C_1 = []
C_2 = []
C_3 = []

C_1 = cal(A_1, b)
C_2 = cal(A_2, b)
C_3 = cal(A_3, b)

a = judge(C_1[0], C_2[0], C_3[0])
b = judge(C_1[1], C_2[1], C_3[1])
c = judge(C_1[2], C_2[2], C_3[2])

d = judge(C_1[0], C_1[1], C_1[2])
e = judge(C_2[0], C_2[1], C_2[2])
f = judge(C_3[0], C_3[1], C_3[2])

g = judge(C_1[0], C_2[1], C_3[2])
h = judge(C_1[2], C_2[1], C_3[0])

lst = [a, b, c, d, e, f, g, h]

if True in lst:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int N;
int x[100000];
int cnt[100000];
int best[100000];

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

	int ima_best = 1;
	int mokuhyou = 1;
	for (int i = 0; i < N; i++) {
		best[i] = ima_best;
		if (x[i] < mokuhyou) { 
			ima_best += 1; 
		}
		else {
			mokuhyou += 2;
		}
		
	}
	for (int i = 0; i < N; i++) {
		cnt[best[i] - 1] += 1;
	}

//	for (int i = 0; i < N; i++) {
//		cout << cnt[i] << " ";
//	}
//	cout << "\n";
	long long ans = 1;
	int p = 0;
	for (int i = 0; i < N; i++) {
		p += cnt[i];
		ans = (ans * (p - i)) % 1000000007;
	}
	cout << ans;

}

Measured memory_bytes: 1408
#![allow(unused_imports)]

use itertools::Itertools as _;
use num::integer::gcd;
use proconio::input;

fn main() {
    input! {
        k: usize,
    }

    let mut s = 0;
    for i in 1..=k {
        for j in 1..=k {
            for l in 1..=k {
                s += gcd(gcd(i, j), l);
            }
        }
    }

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


Measured memory_bytes: 2112
n = int(input())
m = [[-1 for i in range(n)] for j in range(n)] #お隣さんへのコストを保存（この中から最小を探す）

v = set()
v.add(0)

for i in range(n): #隣接の辺のコストを入力
  nums = list(map(int, input().split()))
  for j in range(n):
    m[i][j] = nums[j]


def prim_mst(n):
  isVisited = [False] * n
  d = [0] + [2001] * (n-1)      #TとV-Tのを繋ぐ最小辺の重みを格納する

  while  True:
    mincost = 2001
    for i in range(n):
      if not (isVisited[i]) and d[i] < mincost:
        mincost = d[i]
        u = i
    isVisited[u] = True


    if mincost == 2001:        #mincostが2001になったら繰り返し作業終了
      break

    for v in range (n):
      if (not isVisited[v]) and (m[u][v] != -1):
        if m[u][v] < d[v]:
          d[v] = m[u][v]
  print(sum(d))

prim_mst(n)



Measured memory_bytes: 5772