akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int mul(int a, int b){
    return (ll) a*b %mod;
}

const int nax = 1e5 + 10;
vvi adj;
int n,u,v;

#define black first
#define white second

// returns {black, white}, number of ways in which this 
// child has been colored black , white
pii dfs(int x, int par){
    int all_ch_white = 1;
    int some_ch_black = 0;

    for(auto ad: adj[x]){
        if(ad==par) continue;
        
        pii out = dfs(ad, x);

        // int memo_all_ch_white = all_ch_white;
        some_ch_black = (mul(all_ch_white, out.black) + 
                        mul(some_ch_black, out.white + out.black))%mod;
        
        all_ch_white = mul(all_ch_white, out.white);
    }

    return {all_ch_white, (all_ch_white + some_ch_black)%mod};
}



int main(){
    while(cin>>n){
        adj.clear();
        adj.resize(nax);
        forn(i,n-1){
            cin>>u>>v;
            adj[u].pb(v), adj[v].pb(u);
        }

    pii out = dfs(1,-1);
    ll ans = (out.first + out.second)%mod;
    cout<<ans<<endl;

    }
    return 0;
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 1e5 + 5;
vector<int> graph[MAXN];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	vector<int> P(n, -1);
	queue<int> que;
	que.push(0);
	P[0] = 0;
	while (!que.empty()) {
		int nn = que.front(); que.pop();
		for (int neigh: graph[nn]) {
			if (P[neigh] == -1) {
				que.push(neigh);
				P[neigh] = nn;
			}
		}
	}
	vector<int> ans;
	for (int i = 1; i < n; i++) {
		if (P[i] == -1) {
			//db(i);
			cout << "No" << endl;
			return 0;
		} else {
			ans.push_back(P[i]);
		}
	}
	cout << "Yes" << endl;
	for (auto a: ans) {
		cout << a + 1 << "\n";
	}
}



Measured memory_bytes: 10884
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
  int dp[5001];
  int g[] ={200, 300, 500, 1000, 1200, 1500};
  int value[] ={380, 550, 850, 1520, 1870, 2244};

  fill(dp, dp+5001, 1 << 29);
  
  dp[0] = 0;
  
  for(int i = 0 ; i < 6 ; i++){
    for(int j = 0 ; j+g[i] <= 5000 ; j+=100){
      dp[j+g[i]] = min(dp[j+g[i]], dp[j]+value[i]);
    }
  }
  
  int n;
  while(cin >> n, n){
    cout << dp[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>



int main(void){
  
  int n;
  int numab;
  int numcd;
  int ans;
  int k = 10;
  int sumab, sumcd;
  int i;
  
  int a;
  int c;
  
  while( scanf("%d", &n) != EOF ){
  
  ans = 0;
  if( n <= 36){
    for( i = 0; i < 19; i++ ){
      sumab = i;
      sumcd = n - sumab;
      numab = 0;
      numcd = 0;
      
      if( sumcd >= 0 && sumcd <= 18 ){
      
      
        for( a = 0; a < k; a++ ){
          if( sumab - a < k && sumab - a >= 0) numab++;
        }
     
        for( c = 0; c < k; c++ ){
          if( sumcd - c < k && sumcd - c >= 0) numcd++;
        }
    
        ans += (numab*numcd);
      }
    }
  }
  
  printf("%d\n", ans);
   
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const* argv[]) {
  string line;
  int i;
  while (cin>>line) {
    for (int i = 0;i<line.size();i++) {
      if (line[i] == '@') {
        for (int j='0';j<line[i+1];j++)
          cout<<line[i+2];
        i+=2;
      } else {
        cout<<line[i];
      }
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll N, M; cin >> N >> M;
    vll A(N);
    rep(i, 0, N){
        cin >> A[i];
    }   
    vll cumod(N+1);
    ll cum = 0;
    cumod[0] = 0;
    rep(i, 0, N){
        cum += A[i] % M;
        cum %= M;
        cumod[i+1] = cum; 
    }
    Map mp;
    set<ll> st;
    rep(i, 0, N+1){
        ll t = cumod[i];
        st.insert(t);
        if(mp.find(t) == mp.end()){
            mp[t] = 1;
        }else{
            mp[t]++;
        }
    }
    ll ans = 0;
    for(auto x: st){
        if(mp[x] > 1){
            ans += (mp[x]*(mp[x]-1)/2);
        }
    }
    prt(ans);
}

Measured memory_bytes: 8704
#include<stdio.h>
int main(){
    int n=0,i,j,p=0,x[10000];
    long long int Sum=0;
    scanf("%d",&n);

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

    for(i=0;i<n;i++){
        for(j=n-1;j>i;j--){
            if(x[j]<x[j-1]){
                p=x[j-1];
                x[j-1]=x[j];
                x[j]=p;
            }
        }
    }

    printf("%d %d %lld\n",x[0],x[n-1],Sum);

    return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

const string YES = "Possible";
const string NO = "Impossible";

void no()
{
    cout << NO << endl;
    exit(0);
}
int main()
{
    int N;
    cin >> N;
    map<int, int> ma;
    REP(_, N)
    {
        int a;
        cin >> a;
        ma[a]++;
    }

    int maxi = prev(ma.end())->first;
    int mini = ma.begin()->first;
    if (mini != (maxi + 1) / 2 or ma[mini] != 1 + maxi % 2) no();
    FOR(i, mini + 1, maxi + 1) if (ma[i] < 2) no();

    cout << YES << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

typedef pair<long long int,int> P;


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

	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	sort(a,a+3);


	cout << (a[1]-a[0]) + (a[2] - a[1]) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<math.h>
int main()
{
   int a,b,c,t;
   scanf("%d%d%d",&a,&b,&c);
   if(a<b)
   {
       t=a;
       a=b;
       b=t;
   }
   if(a<c)
   {
       t=a;
       a=c;
       c=t;
   }

   printf("%d\n",a*10+b+c);
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

bool cmp(pii& a, pii&b) {
  return a.second < b.second;
}
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  pii arr[n];
  int a, b;
  fi(0, n) {
    cin >> a >> b;
    // cin>>arr[i].first>>arr[i].second;
    arr[i].first = a - b;
    arr[i].second = a + b;
  }
  sort(arr, arr+n, cmp);
  int now = arr[0].second;
  ans = 1;
  fi(1, n) {
    pii a = arr[i];
    if(a.first >= now) {
      now = arr[i].second;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
class UnionFindTree
{
    vector<int> parent;
    vector<int> depth;
    vector<int> cnt;

public:
    UnionFindTree(int n) : parent(n), depth(n), cnt(n)
    {
        for (int i = 0; i < n; i++)
        {
            parent[i] = i;
            depth[i] = 0;
            cnt[i] = 1;
        }
    }

    //木の根を求める
    int find(int x)
    {
        if (parent[x] == x)
        {
            return x;
        }
        else
        {
            return parent[x] = find(parent[x]);
        }
    }

    //xとyの属する集合を併合
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (depth[x] < depth[y])
        {
            parent[x] = y;
            cnt[y] += cnt[x];
        }
        else
        {
            parent[y] = x;
            cnt[x] += cnt[y];
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }
    // 同じ集合に属しているか判定
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    // 集合のサイズを取得
    int size(int x)
    {
        return cnt[find(x)];
    }
};

int main(){
   ll n,m,p[101010];
   cin>>n>>m;
   UnionFindTree u(n+10);
   rep(i,n){cin>>p[i];}
   rep(i,m){
      int a,b;
      cin>>a>>b;
      u.unite(a,b);
   }
   ll ans=0;
   rep(i,n){
      if(u.same(i+1,p[i]))ans++;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main() {
    size_t n;
    string s, t;
    cin >> n >> s >> t;
    for (size_t i = 0; i < n; ++i) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;
int main(){
	int a,b;
	std::cin >> a>>b;
	if(a<=9&&b<=9)std::cout << a*b << std::endl;
	else std::cout << -1 << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<functional>


#define TEST 0
#if TEST
FILE* in = freopen("./Q.txt", "r", stdin);
FILE* out = freopen("./ans.txt", "w", stdout);
#endif

using namespace std;

const int dx[6] = { 1, 1, 0, -1, -1, 0 };
const int dy[6] = { 0, 1, 1, 0, -1, -1 };
int x, y;
map<pair<int, int>, bool> state;
queue<int> qx,qy,qt;
int t,n;
int sx, sy;

int f(int nx,int ny,int turn){
	int ans = 0;
	state[make_pair(nx,ny)] = true;
	qx.push(nx);
	qy.push(ny);
	qt.push(turn);
		while (!qx.empty()){
			nx = qx.front(), ny = qy.front(), turn = qt.front();
				qx.pop();
				qy.pop();
				qt.pop();
					ans++;
			if (turn < t){
				for (int i = 0; i < 6; ++i){
					if (!state[make_pair(nx + dx[i],ny + dy[i])]){
						qx.push(nx + dx[i]);
						qy.push(ny + dy[i]);
						qt.push(turn + 1);
						state[make_pair(nx+dx[i], ny+dy[i])] = true;
					}
				}
			}
	}
	return ans;
}


int main(){

	while (1){
		cin >> t >> n;
		if (!t&&!n)break;

		for (int i = 0; i < n; ++i){
			cin >> x >> y;
			state[make_pair(x,y)]=true;
		}
		cin >> sx >> sy;
			cout << f(sx, sy, 0) << endl;

		state.clear();

	}
#if TEST
	fclose(in);
	fclose(out);
#endif
	return 0;

}

Measured memory_bytes: 3284
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int K,S,c = 0;
    cin >> K >> S;

    rep(i, K + 1){
        rep(j, K + 1){
            int Z = S - (i + j);
            if(Z <= K && Z >= 0){
                c++;
            }
        }
    }

    cout << c << endl;
}

Measured memory_bytes: 256
import math
n,d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        c=0
        for k in range(d):
            c+=(x[i][k]-x[j][k])**2
        if math.sqrt(c)==int(math.sqrt(c)):
            ans+=1
print(ans)

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

int solveV(const vector<vector<int>> &G, int N, int K) {
    auto bfs = [&](int s) -> vector<int> {
        vector<int> dist(N, -1);
        queue<int> que;
        dist[s] = 0;
        que.push(s);
        while(!que.empty()) {
            int cur = que.front();
            que.pop();
            for(auto &to : G[cur]) {
                if(dist[to] == -1) {
                    dist[to] = dist[cur] + 1;
                    que.push(to);
                }
            }
        }
        return dist;
    };
    int ans = N;
    for(int s = 0; s < N; ++s) {
        auto dist = bfs(s);
        int res = 0;
        for(int i = 0; i < N; ++i) {
            if(dist[i] > K / 2) ++res;
        }
        ans = min(ans, res);
    }
    return ans;
}

int solveE(const vector<vector<int>> &G, int N, int K) {
    auto bfs = [&](int s, int t) -> vector<int> {
        vector<int> dist(N, -1);
        queue<int> que;
        dist[s] = 0;
        dist[t] = 0;
        que.push(s);
        que.push(t);
        while(!que.empty()) {
            int cur = que.front();
            que.pop();
            for(auto &to : G[cur]) {
                if(dist[to] == -1) {
                    dist[to] = dist[cur] + 1;
                    que.push(to);
                }
            }
        }
        return dist;
    };
    int ans = N;
    for(int s = 0; s < N; ++s) {
        for(auto &t : G[s]) {
            auto dist = bfs(s, t);
            int res = 0;
            for(int i = 0; i < N; ++i) {
                if(dist[i] > K / 2) ++res;
            }
            ans = min(ans, res);
        }
    }
    return ans;
}

void solve() {
    int N, K;
    cin >> N >> K;
    vector<vector<int>> G(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if(K % 2) cout << solveE(G, N, K) << '\n';
    else cout << solveV(G, N, K) << '\n';
}

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


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

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

    int ans = 0;
    rep(i,n){
        int tmp;
        cin >> tmp;
        if(i % 2 == 0 && tmp % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
n, m = map(int, input().split())
city = []
for i in range(m):
  p, y = map(int, input().split())
  city.append([i, p, y])

city.sort(key=lambda x: x[2])
city.sort(key=lambda x: x[1])

city_id = []
cnt = 0
pref = 0
for ci in city:
  if ci[1] != pref:
    pref = ci[1]
    cnt = 0
  cnt += 1
  id = '{0:0>6}{1:0>6}'.format(pref, cnt)
  city_id.append([ci[0], id])
city_id.sort(key=lambda x: x[0])
for ci in city_id:
  print(ci[1])


Measured memory_bytes: 41348
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
using llong = long long;

llong n, m, l;
llong q, s, t;
llong a, b, c;
llong g[305][305];

void f() {
    for (int c = 0; c < 3; c++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (i == j) continue;
                for (int k = 1; k <= n; k++) {
                    if (i == k || j == k) continue;
                    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
                }
            }
        }
    }
};

int main() {
    for (int i = 0; i < 305; i++) {
        for (int j = 0; j < 305; j++) {
            g[i][j] = 1ll << 60ll;
            if (i == j) g[i][j] = 0;
        }
    }
    
    cin >> n >> m >> l;
    for (int i = 0; i < m; i++) {
        cin >> a >> b >> c;
        if (c > l) continue;
        
        g[a][b] = c;
        g[b][a] = c;
    }

    f();
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) {
                g[i][j] = 0;
            }
            else if (g[i][j] <= l) {
                g[i][j] = 1;
            }
        }
    }

    f();

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

        if (g[s][t] >= (1ll << 60ll)) cout << -1 << endl;
        else cout << g[s][t] - 1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1280
package main

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

var sc = bufio.NewScanner(os.Stdin)

func swap(a int64, b int64) (int64, int64) {
	return b, a
}

func gcd(a int64, b int64) int64 {
	if b > a {
		a, b = swap(a, b)
	}
	if b == 0 {
		return a
	} else {
		return gcd(a%b, b)
	}
}

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

func min(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func nextLong() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func nextByte() byte {
	sc.Scan()
	s := sc.Bytes()
	return s[0]
}

func main() {
	sc.Split(bufio.ScanWords)
	//ans := 1
	A := nextLong()
	B := nextString()
	B100 := int(B[0]-'0')*100 + int(B[2]-'0')*10 + int(B[3]-'0')
	ans := int64(A) * int64(B100)
	ans /= int64(100)
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 1772
n=int(input())
if n==1: print(0); exit()
M=10**6+1
l=[]
p=[1]*M
p[0]=p[1]=0
for i in range(2,M):
  if p[i]:
    l.append(i)
    for j in range(2*i,M,i):
      p[j]=0
d={}
for k in l:
  c=0
  while n%k==0: n//=k; c+=1
  if c>0: d[k]=c
s=[1]
for i in range(2,9):
  s.append(s[-1]+i)
a=0
for i in d.values():
  for j in s:
    if j>i: break
    a+=1
print(a+(n>1))

Measured memory_bytes: 80612
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e17;
const long double PI=acos(-1);


void solve(int T){
    int n;
    set<int>s;
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        s.insert(x);
    }
    if(s.size()==n){
        cout<<"YES\n";
    }
    else {
        cout<<"NO\n";
    }
}

int main() {
    fastio
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}





Measured memory_bytes: 12964
#include <iostream>
using namespace std;
int main (){
	int A,B;
  	bool ok=0;
  	cin>>A>>B;
  	if((A*B*1)%2==1){
   		cout<<"Yes";
  		return 0;
} 
  	if((A*B*2)%2==1){
    	cout<<"Yes";
  		return 0;
    }  
  	if((A*B*3)%2==1){
    	cout<<"Yes";
  		return 0;
    }
  cout<<"No";
}

Measured memory_bytes: 764
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        Console.ReadLine();
        Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Count(x => x % 2 == 1) % 2 == 0 ? "YES" : "NO");
    }
}

Measured memory_bytes: 18144
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int k;
  cin >> k;
  vector<int> a(k);
  rep(i, k) cin >> a.at(i);
  if(a.back() != 2){
    cout << -1 << endl;
    return 0;
  }
  ll mn = 2, mx = 2;
  rrep(i, k){
    int now = a.at(i);
    if(mn % now != 0 && mx < mn + (now - mn % now)){
      cout << -1 << endl;
      return 0;
    }
    mn = (mn + now - 1) / now * now;
    mx = (mx / now * now) + now - 1;
  }
  cout << mn << " " << mx << endl;
  return 0;
}

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

int main() {
  int n;
  int t = 0;
  cin>>n;
  for(int i=0; i < n; i++){
    char a;
    cin>>a;
    if(a == 'Y'){
      cout<<"Four"<<endl;
      t = 0;
      break;
    }else{
      t++;
    }
  }
  if(t >= 1){
     cout<<"Three"<<endl;
  }
}


Measured memory_bytes: 3628
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    S = input()
    p1 = None
    p2 = None
    for i, s in enumerate(S):
        if s == p1:
            print(i, i + 1)
            return
        if s == p2:
            print(i - 1, i + 1)
            return
        p1, p2 = s, p1

    print(-1, -1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include<iostream>
using namespace std;
main(){
  int i,j,k,n,x,a,b,c=0;
  
  
  while(1){
    b=0;
    cin >> n >> x;
    if(n==0 && x==0)break;
    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
	
	
	for(k=j+1;k<=n;k++){
      
	  a=0;
	  a=i+j+k;
	  if(a==x){
	    b+=1;
	  }

	}
      }
    }
    cout << b << endl;
  }
  
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <climits>
#include <set>


using namespace std;

typedef long long ll;

const int maxn=3e5+10;


class cmp
{
public:
    bool operator()(int l,int r)
    {
        return l>r;
    }
};

ll a[maxn];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<3*n;i++)
        scanf("%I64d",&a[i]);
    priority_queue<ll,vector<ll>, cmp> q1;
    ll l[maxn],r[maxn];
    memset(l,0,sizeof(l));
    memset(r,0,sizeof(r));
    ll s=0;
    for(int i=0;i<n;i++)
    {
        q1.push(a[i]);
        s+=a[i];
        l[i]=s;
    }
    for(int j=n;j<3*n;j++)
    {
        if(a[j]>q1.top())
        {
            s-=q1.top();
            q1.pop();
            q1.push(a[j]);
            s+=a[j];
        }
        l[j]=s;
    }
    priority_queue<ll> q;
    reverse(a, a+3*n);
    s=0;
    for(int i=0;i<n;i++)
    {
        q.push(a[i]);
        s+=a[i];
        r[i]=s;
    }
//    for(int i=0;i<3*n;i++)
//        cout<<l[i]<<endl;
    for(int i=n;i<3*n;i++)
    {
        if(q.top()>a[i])
        {
            s-=q.top();
            q.pop();
            q.push(a[i]);
            s+=a[i];
        }
        r[i]=s;
    }
    
//    for(int i=0;i<3*n;i++)
//        cout<<r[i]<<endl;
//    
    ll res=LLONG_MIN;
    for(int i=n-1;i<2*n;i++)
    {
        if(l[i]-r[3*n-i-1-1]>res)
            res=l[i]-r[3*n-i-1-1];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 9588
import sys
sys.setrecursionlimit(1000000000)

n,u,v = map(int,input().split())
u -= 1
v -= 1
G = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

distT = [-1]*n
distA = [-1]*n
distT[u] = 0
distA[v] = 0
def dfs(now,dist):
    for nxt in G[now]:
        if dist[nxt] != -1: continue
        dist[nxt] = dist[now]+1
        dfs(nxt,dist)
dfs(u,distT)
dfs(v,distA)

mx = 0
for i in range(n):
    if distT[i] < distA[i]:
        mx = max(mx, distA[i])
ans = mx-1
print(ans)

Measured memory_bytes: 102200
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x)&(-x)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define maxd 1000000007
typedef long long ll;
const int N=100000;
const double pi=acos(-1.0);

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if ((a==b) && (a==c)) cout << "Yes";else cout << "No";
	return 0;
}


Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[] p=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int[] a=new int[n],b=new int[n];
		for(int i=0;i<n;i++){b[p[i]-1]=i+500000000;}
		a[0]=1;
		b[0]--;
		for(int i=1;i<n;i++){
			a[i]=a[i-1]+1;
			b[i]-=a[i-1]+1;
			if(b[i]>=b[i-1]){
				a[i]+=b[i]-b[i-1]+1;
				b[i]=b[i-1]-1;
			}
		}
		Console.WriteLine(String.Join(" ",a));
		Console.WriteLine(String.Join(" ",b));
	}
}

Measured memory_bytes: 16864
import java.util.Scanner

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val A = 1 to N map (_ => sc.nextInt)

    val ans = Math.max(scan(A(0), A.drop(1)), scan(A(1), A.take(1) ++ A.drop(2)))
    println(ans)

  }

  def scan(t: Int, A: Seq[Int]): Int = {

    val mx = Math.sqrt(t).toInt + 1
    val candidates = (1 to mx).filter(t % _ == 0).flatMap(x => Seq(x, t/x)).distinct

    val map: mutable.Map[Int, Int] = mutable.Map(candidates.map(_ -> 0): _*)
    A.foreach { a =>
      candidates.foreach { c =>
        {
          val d = if (a % c != 0) 1 else 0
          map.put(c, map.get(c).get + d)
        }
      }
    }
    map.filter(_._2 <= 1).keySet.max
  }
}

Measured memory_bytes: 119464
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, c = 0, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 0) continue;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) {
                c++;
            }
        }
        if (c == 8) {
            ans++;
        }
        c = 0;
    }
    cout << ans << endl;
}

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

int main() {
  int a,b; cin>>a>>b;
  if (a<=8&&b<=8) cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
}


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

namespace Aojx
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string s;
            while ((s = Console.ReadLine()) != null)
            {
                double[] row = s.Split(' ').Select(e => double.Parse(e)).ToArray();
                double x1 = row[0], y1 = row[1], x2 = row[2], y2 = row[3],
                x3 = row[4], y3 = row[5], xp = row[6], yp = row[7];

                double abap = CrossProductSign(
                                  new double[]{ x2 - x1, y2 - y1 },
                                  new double[]{ xp - x1, yp - y1 }
                              );
                double bcbp = CrossProductSign(
                                  new double[]{ x3 - x2, y3 - y2 },
                                  new double[]{ xp - x2, yp - y2 }
                              );
                double cacp = CrossProductSign(
                                  new double[]{ x1 - x3, y1 - y3 },
                                  new double[]{ xp - x3, yp - y3 }
                              );

                if (abap == bcbp && bcbp == cacp)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
        }

        public static double CrossProductSign(double[] a, double[] b)
        {
            return Math.Sign(a[0] * b[1] - a[1] * b[0]);
        }
    }
}

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

void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  rep(i, m) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());
  int l = 1;
  int r = n;
  int ans = 1;
  rep(i, m) {
    int nextL = v[i].first;
    int nextR = v[i].second;
    if (l < nextR && r > nextL) {
      l = max(l, nextL);
      r = min(r, nextR);
    } else {
      l = nextL;
      r = nextR;
      ans++;
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Mod=998244353;

int n,nn; char S[200010];
int ans[400010];
int solve(int x)
{
	x>>=1;
	int res=0;
	for (int i=1;i<=x;i++) res=(res*2+S[i]-'0')%Mod;
	bool flg=false;  //greater or not
	for (int i=x+1,j=1,k=1;i<=n;i++)
	{
		char t=S[j]^k;
		if (t!=S[i])
		{
			flg=S[i]<t; break;
		}
		if (j==x) j=1,k^=1;
		else j++;
	}
	
	//if (S[i]!=S[(i-1)%x+1]){flg=S[i]<S[(i-1)%x+1];break;}
	if (!flg) res=(res+1)%Mod;
	//printf("solve %d %d\n",x*2,res);
	return res;
}
int main()
{
	scanf("%d%s",&n,S+1); nn=n+n;
	for (int i=nn;i;i-=2)
		if (nn%i==0&&n%i==(i>>1))
			ans[i]=solve(i);
	//for (int i=1;i<=nn;i++) printf("ans %d: %d\n",i,ans[i]);
	for (int i=2;i<=nn;i+=2)
		if (nn%i==0&&n%i==(i>>1))
			for (int j=i+i;j<=nn;j+=i)
				if (nn%j==0&&n%j==(j>>1))
					ans[j]=(ans[j]-ans[i])%Mod;
	int res=0;
	for (int i=2;i<=nn;i+=2) res=(res+1LL*i*ans[i])%Mod;
	printf("%d\n",(res+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 384
a, b, c, x, y = [int(i) for i in input().split()]
print((2 * c * min(x, y) + min(a * (x - y), 2 * c * (x - y)) if x > y else 2 * c * min(x, y) + min(b * (y - x), 2 * c * (y - x))) if a + b > c * 2 else a * x + b * y)


Measured memory_bytes: 3060
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long>A(N);
    for (int i = 0; i < N; i++)cin >> A[i];
    sort(A.begin(),A.end(), greater<long long>());

    long long max1 = 0, max2 = 0;
    for (int i = 0; i < N-1; i++) {
        if (max1 != 0 && max2 != 0)break;
        if (A[i] == A[i + 1]) {
            if (max1 == 0) {
                max1 = A[i];
                i++;
            }
            else max2 = A[i];
        }
    }
    cout << max1*max2 << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

int N;
vector<int> w;

int solve() {
    vector<vector<int>> dp(N+1, vector<int>(N+1, -N));
    for (int i = 0; i <= N; ++i) {
        dp[i][i] = 0;
        if (i < N) dp[i][i+1] = 0;
    }
    for (int bet = 2; bet <= N; ++bet) {
        for (int i = 0; i + bet <= N; ++i) {
            int j = i + bet;
            if (dp[i+1][j-1] == j-i-2) {
                if (abs(w[i] - w[j-1]) <= 1) chmax(dp[i][j], j-i);
                else chmax(dp[i][j], j-i-2);
            }
            for (int k = i+1; k <= j-1; ++k) {
                chmax(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    return dp[0][N];
}

int main() {
    while (cin >> N, N) {
        w.resize(N);
        for (int i = 0; i < N; ++i) cin >> w[i];
        cout << solve() << endl;
    }
}



















Measured memory_bytes: 3272
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main 
{
	static class C implements Comparator<Cake>
	{
		long mula;
		long mulb;
		long mulc;
		
		public C(long ma, long mb, long mc)
		{
			mula = ma;
			mulb = mb;
			mulc = mc;
		}
		
		@Override
		public int compare(Cake o1, Cake o2) 
		{
			long com =  ((o2.a*mula + o2.b*mulb + o2.c*mulc)-(o1.a*mula + o1.b*mulb + o1.c*mulc));
			if(com > 0)return 1;
			if(com < 0)return -1;
			return 0;
		}
	}
	
	static class Cake
	{
		long a;
		long b;
		long c;
		
		public Cake(long a0, long b0, long c0)
		{
			a = a0;
			b = b0;
			c = c0;
		}
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		Cake[] cake = new Cake[n];
		
		for(int i = 0; i < n; i++)
		{
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			
			cake[i] =new Cake(a,b,c);
		}
		
		C c;
		long max = -999999999999999999l;
		
		
		for(long ka = -1; ka <= 1; ka+=2)
			for(long kb = -1; kb <= 1; kb+=2)
				for(long kc = -1; kc <= 1; kc+=2)
				{
					long cur = 0;
					c = new C(ka,kb,kc);
					Arrays.sort(cake,c);
					for(int i = 0; i < m; i++)
						cur += cake[i].a*ka + cake[i].b*kb + cake[i].c*kc;
					max = Math.max(cur, max);
				}
			
		
		System.out.println(max);
		

	}

}


Measured memory_bytes: 27976
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

void kesan(int, int, int, int, int, int);
int main(){
  int h, m, s, hh, mm, ss, i;
  for(i = 0; i < 3; i++){
    cin >> h >> m >> s >> hh >> mm >> ss;
    kesan(h, m, s, hh, mm, ss);
  }
  return 0;
}

void kesan(int h1, int m1, int s1, int h2, int m2, int s2){
  int t1 = h1 * 3600 + m1 * 60 + s1;
  int t2 = h2 * 3600 + m2 * 60 + s2;
  int t = t2 - t1;
  int h = t / 3600;
  t -= h * 3600;
  int m = t / 60;
  t -= m * 60;
  int s = t;
  //printf("t1:%d t2:%d t:%d\n", t1, t2, t);
  printf("%d %d %d\n", h, m, s);
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main(){
  cin>>N>>A; 
  ll ans = A, last = A; 
  rep(i,N-2){ 
    cin>>A; 
    ans += min(A, last); 
    last = A; 
  } 
  ans += A; 
  cout<<ans<<endl; 
}


Measured memory_bytes: 256
sub f{my$i=pop;$p[$i]=$p[$i]-$i?f($p[$i]//=$i):$i}@s=(1)x<>;$%=@s*$#s/2;map{unshift@a,$%;$%-=$s[$A]*$s[$B],$s[$p[$A]=$B]+=$s[$A]if($A=f$`-/ /)-($B=f$'-1)}reverse<>;print"@a"

Measured memory_bytes: 41728
#include <iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

int retl(int K,int L){
    int tmp=0;
    while(pow(2,tmp) * L < K){
        tmp++;
    }
    return tmp;
}

struct A{
    string s;
    int p;
    int order;
};


int main(){
    int N;
    cin  >> N;
  
    int W[N];
    FOR(i,N){
        cin >>W[i];
    }
    
    int ab=pow(10,5);

    for(int i=0;i<N-1;i++){
        int t1=0;
        int t2=0;
        for(int j=0;j<=i;j++){
            t1+=W[j];
        }
        for(int j=i+1;j<N;j++){
            t2+=W[j];
        }
        if(ab>abs(t1-t2)){
            ab=abs(t1-t2);
        }
    }

    int ans=ab;
    cout << ans << endl;

    return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#define REPN(i, m, n) for(int (i)=(int)(m); (i)<(int)(n); (i)++)
#define REP_REV(i, n) for(int (i)=(int)(n)-1; (i)>=0; (i)--)
#define debug(x) cout << #x << ": " << (x) << endl;

using namespace std;

int main() {
//    ifstream in("C:\\Users\\P218024\\Documents\\Cpp Projects\\abc094\\sample.txt");
//    cin.rdbuf(in.rdbuf());

//    cin.tie(0);
//    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int X[n] = {0};
    int X_copy[n] = {0};
    REP(i,n) {
        scanf("%d", &X[i]);
//        cin >> X[i];
        X_copy[i] = X[i];
    }

    sort(X, X+n);

    int a = X[n / 2 - 1];
    int b = X[n / 2];
    REP(i, n) {
        cout << ((X_copy[i] < b) ? b : a) << endl;
    }

}

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

struct UnionFind {
    vector<int> data; int sz;

    UnionFind(int sz) : data(sz, -1), sz(sz) { }

    bool unite(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        sz--;
        return true;
    }

    bool is_same(int x, int y) { return root(x) == root(y); }

    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

    int size(int x) { return -data[root(x)]; }

    int size() { return sz; }

};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n+m);
    for (int v = 0; v < n; v++) {
        int k; cin >> k;
        for (int _ = 0; _ < k; _++) {
            int u; cin >> u; u += n-1;
            uf.unite(v, u);
        }
    }
    
    bool ok = true;
    for (int v = 0; v < n; v++) {
        if (uf.root(v) != uf.root(0)) {
            ok = false;
        }
    }
    
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int mad=1000000007;
int dp[2005][2005];
int a[2005],b[2005];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++){
        scanf("%d",&a[i]);
    }
    for(int i=1; i<=m; i++){
        scanf("%d",&b[i]);
    }
    for(int i=0; i<=n; i++)
        for(int j=0; j<=m; j++)
            dp[i][j]=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
            if(a[i]==b[j])
                dp[i][j]+=dp[i-1][j-1]+1;
            if(dp[i][j]<0)
                dp[i][j]+=mad;
            if(dp[i][j]>=mad)
                dp[i][j]%=mad;
        }
    }

    printf("%d\n",(dp[n][m]+1)%mad);
    return 0;
}


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

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

    ll x, sum = 0, cur = 0;
    cin >> x;

    while(sum < x) {
        ++cur;
        sum += cur;
    }

    cout << cur << endl;
}

Measured memory_bytes: 256
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  200019
ll n;
std::vector<ll> a(N);
std::map<pii,ll> zz;
ll func(ll pos,ll rem)
{
    
    if(rem==0)
        return zz[{pos,rem}]=0;
    if(zz.find({pos,rem})!=zz.end())
        return zz[{pos,rem}];       
    if((n-pos+1)<2*rem || pos>=n)
    {
        return zz[{pos,rem}]=-1e18;   
    }    
    ll vl=func(pos+1,rem);
    vl=max(vl,func(pos+2,rem-1)+a[pos]);
    return zz[{pos,rem}] = vl;
}
int main()
{
    
    io    

    cin>>n;
    rep(i,0,n)
    cin>>a[i];
    cout<<func(0,n/2);
    


}

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

using namespace std;


int main()
{
    double a, b, x;
    double c;

    cin >> a >> b >> x;

    x = x / a;
    if(x >= a * b / 2)
    {
      double  S = 2 *(a * b - x) / a;
      c = atan2(S,a);
    }
    else
    {
      double S = x * 2 / b;
      c = atan2(b,S);
    }
    double PI = acos(-1);
    c = (c * 360) /(2 * PI);
    cout <<fixed<< setprecision(10) << c;
    return 0;
}


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

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    map<int, int> data;
    for(int i = 0; i < n; i++) {
      int num;
      cin >> num;
      data[num]++;
    }
    map<int, int>::iterator it = data.begin();

    while(it != data.end()) {
      if(it->second > n/2) {
	cout << it->first << endl;
	break;
      }
      it++;
      if(it == data.end()) {
	cout << "NO COLOR" << endl;
      }
    }
  }
  return 0;
}

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

using namespace std;

typedef long long	ll;

const int N = int(2e5 + 1);
const ll M = 2019;
ll cnt[M + 10];
int d;
char s[N + 5];
int n;

int main(){

	scanf("%s", s);

	n = strlen(s);

	cnt[0]++;

	ll ans = 0LL;
	ll pt = 1LL;
	ll ac = 0LL;

	for(int i = n - 1 ; i >= 0 ; i--){
		ac += (s[i] - '0') * pt;

		ac %= M;

		pt = (pt * 10LL) % M;

		ans += cnt[ac];

		cnt[ac]++;
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3928
#include<stdio.h>
int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    int a, total=0;
    for (int i=0; i<m; ++i){
        scanf("%d", &a);
        total+=a;
    }
    if (total>n){
        printf("-1\n");
    }else{
        printf("%d\n", n-total);
    }
    return 0;
}


Measured memory_bytes: 1720
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int main(){

	double a, b, C, x, S, L, h;
	cin >> a >> b >> C;

	C = C*3.1415926535 / 180;

	//高さ h
	h = b*sin(C);

	//面積 S
	S = a*h / 2;

	//周の長さ L
	x = pow(a,2)+pow(b,2) - 2 * a*b*cos(C);
	x = sqrt(x);
	L = a + b + x;

	printf("%f\n%f\n%f\n", S, L, h);

	return 0;
}


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

int main(){
  int N, M, a, b, c, d, l, cp;
  cin >> N >> M;
  int S[N][2], C[M][2], A[N];
  for (int i = 0; i < N; i++){
    cin >> S[i][0] >> S[i][1];
  }
  
  for (int i = 0; i < M; i++){
    cin >> C[i][0] >> C[i][1];
  }
    
  for (int i = 0; i < N; i++){
    a = S[i][0];
    b = S[i][1];
    l = 1000000000;
    for (int j = M-1; j >= 0; j--){
      c = C[j][0];
      d = C[j][1];
      if (abs(a-c)+abs(b-d) <= l){
        l = abs(a-c)+abs(b-d);
        cp = j;
      }
    }
    
    A[i] = cp + 1;
  }
  
  for (int i = 0; i < N; i++){
    cout << A[i] << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int n, y;
    while(~scanf("%d%d", &n, &y)) {
        bool flag = 0;
        for(int i = 0; i <= n && !flag; ++i) {
            for(int j = 0; j <= n - i && !flag; ++j) {
                if(n - i - j < 0) break;
                if(10000 * i + j * 5000 + (n - i - j) * 1000 == y) {
                    flag = 1;
                    printf("%d %d %d\n", i, j, n - i - j);
                    break;
                }
            }
        }
        if(!flag) puts("-1 -1 -1");
    }
}


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

int main() {
    int N;
    cin>>N;
    map<string,int> map;
    string S;
    for(int i=0;i<N;i++){
        
        cin>>S;
        map[S]=1;
    }
    cout<<map.size()<<endl;
    

}

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

// Problem https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_a

int main(void){
    int N,K;
    cin >> N >> K;
    int all1rem;
    all1rem = N - K;
    int answer;
    answer = all1rem;
    if( K == 1){
        answer=0;
    }
    cout << answer << endl;

}

Measured memory_bytes: 256