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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll dist[310][310];
ll dist2[310][310];

// ワーシャルフロイド
void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

// ワーシャルフロイド2
void warshall_floyd2(int n) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
      }
    }
  }
}

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

    Fill(dist, INF);
    Fill(dist2, INF);

    REP(i, M){
        ll a, b, c;
        cin >> a >> b >> c;
        dist[a-1][b-1] = c;
        dist[b-1][a-1] = c;
    }

    ll Q;
    cin >> Q;

    vector<ll> S(Q);
    vector<ll> T(Q);
    REP(i, Q){
        cin >> S[i] >> T[i];
    }

    warshall_floyd(N);
    
    REP(i, N){
        REP(j, N){
            if(dist[i][j] <= L){
                dist2[i][j] = 1;
            }
        }
    }

    warshall_floyd2(N);

    REP(i, Q){
        if(dist2[S[i]-1][T[i]-1] > N){
            cout << -1 << endl;
        }
        else{
            cout << dist2[S[i]-1][T[i]-1] - 1 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll C(ll n,ll m)//n<m
{
    ll c[5];
    c[0]=1;
    for(int i=1;i<=n;i++)
    {
        c[i]=((c[i-1]*(m-i+1)))/i;
    }
    return c[n];
}
int ball[200005],num[200005];
int main()
{
    memset(num,0,sizeof num);
    int n,maxn=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>ball[i];
        maxn=max(maxn,ball[i]);
        num[ball[i]]++;
    }
    ll ans=0;
    for(int i=1;i<=maxn;i++)
    {
        ans+=C(2,num[i]);
    }
    for(int i=0;i<n;i++)
    {
        int x=ball[i];
        cout<<ans-C(2,num[x])+C(2,num[x]-1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>
#include <limits.h>

int i = 0, n, x, min = INT_MAX, max = INT_MIN;
long int sum = 0;

int main() {
    scanf("%d", &n);
    printf("");
    while (i < n) {
        scanf("%d", &x);
        printf("");
        if (x < min) {
            min = x;
        }
        if (x > max){
            max = x;
        }
        sum = sum + x;
        i++;
    }
    printf("%d %d %ld\n", min, max, sum);
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------


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

    int n;
    cin >> n;
    cout << (n <= 999 ? "ABC" : "ABD") << endl;

    return 0;
}


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

int main()
{
    int n, m;
    int N = 1500 * 1000;
    while(1){
        cin >> n; cin >> m;
        if(n * m == 0){
            break;
        }
        int v_interval[n], h_interval[m];
        for (int i = 0; i < n; i++) {
            cin >> v_interval[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> h_interval[i];
        }
        
        
        short v_length_num[N+1];
        for(int i = 0; i < N+1; i++){
            v_length_num[i] = 0;
        }
        int v_length = 0;
        for(int i = 0; i < n; i++){
            for(int j = i; j < n; j++){
                if(i == j){
                    v_length = v_interval[i];
                } else {
                    v_length += v_interval[j];
                }
                v_length_num[v_length]++;
            }
        }


        short h_length_num[N+1];
        for(int i = 0; i < N+1; i++){
            h_length_num[i] = 0;
        }
        int h_length = 0;
        for(int i = 0; i < m; i++){
            for(int j = i; j < m; j++){
                if(i == j){
                    h_length = h_interval[i];
                } else {
                    h_length += h_interval[j];
                }
                h_length_num[h_length]++;
            }
        }


        int count = 0;
        for(int i = 0; i < N+1; i++){
            count += v_length_num[i] * h_length_num[i];
        }
        cout << count << endl;
    }
    return 0;
}

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

int main(){
   int n, r, ans;

   cin >> n >> r;

   if(n < 10) ans = r + 100*(10-n); 
   else ans = r;
   cout << ans;
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int h, n, a[100005], suma = 0;
    cin >> h >> n;
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    for(int i=0; i<n; i++) {
        suma += a[i];
        if(suma >= h) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

struct Point{
	double x, y;
};


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

	int n;
	cin >> n;

	const int MOD = 1000000007;

	map<int, int>m;
	for (int i = 1; i <= n; i++) {
		int x = i;

		for (int j = 2; j * j <= x; j++) {
			while (x % j == 0) {
				m[j]++;
				x /= j;
			}
		}
		if (x > 1) m[x]++;
	}

	LL ans = 1;
	for (auto t : m) {
		ans = (ans * (t.second + 1)) % MOD;
	}

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

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;

    cin >> n;

    vector<int> h(n);

    rep(i, n) cin >> h[i];

    h[0]--;

    for (int i = 1; i <= n - 1; i++)
    {
        if (h[i - 1] < h[i] && h[i] >= h[i + 1])
        {
            h[i]--;
        }
    }

    bool flag = 1;

    rep(i, n - 1)
    {
        if (h[i] > h[i + 1])
        {
            flag = 0;
        }
    }

    if (flag == 1)
    {
        OP("Yes")
    }
    else
    {
        OP("No")
    }

    return 0;
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("lld", &x); return (x); }

string replace(string input, string str1, string str2)
{
	string::size_type pos(input.find(str1));

	while(pos != string::npos)
	{
		input.replace(pos, str1.length(), str2);
		pos = input.find(str1, pos + str2.length());
	}

	return input;
}

int main()
{
	string str;
	getline(cin, str);
	size_t pos = 0;
	
	str = replace(str, "apple", "PEACH");
	str = replace(str, "peach", "apple");
	str = replace(str, "PEACH", "peach");

	cout << str << endl;

	return (0);
}

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

using namespace std;

#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)

LL bit[505];
LL n,m,q,ans[100005];

void update(LL i, LL val)
{
	while(i<=n) {
		bit[i]+=val;
		i+=i&-i;
	}
}
LL query(LL i)
{
	LL ret=0;
	while(i>0) {
		ret+=bit[i];
		i-=i&-i;
	}
	return ret;
}

vector< pair<pLL,pLL> > v; 

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>q;
	rep(i,1,m){
		LL l,r;
		cin>>l>>r;
		v.pb(mp(mp(r,0),mp(l,0)));
	}
	rep(i,1,q){
		LL l,r;
		cin>>l>>r;
		v.pb(mp(mp(r,l),mp(1,i)));
	}
	sort(v.begin(), v.end());
	for(auto x: v) {
		if(x.ff.ss==0){
			update(x.ss.ff, 1);
		}
		else{
			ans[x.ss.ss]=query(x.ff.ff)-query(x.ff.ss-1);
		}
	}
	rep(i,1,q) cout<<ans[i]<<endl;
}

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

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))



int main() {
	int N, A, B;
	scanf("%d %d %d", &N, &A, &B);

	int tmp,sum;
	int ans = 0;
	REPS(i, N) {
		sum = 0;
		tmp = i;
		while (tmp > 0) {
			sum += tmp % 10;
			tmp /= 10;
		}
		if (sum >= A&&sum <= B)ans+=i;
	}
	PRINTD(ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
using namespace std;

typedef long long ll;

#define INF 10e7
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

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

int main() {
  int h,w; scanf("%d %d", &h,&w);

  char s[h][w];
  int bl = 0;
  rep(i,h)rep(j,w) {
    cin >> s[i][j];
    if (s[i][j] == '#') bl++;
  }

  queue<pair<int, int>> que;
  pair<int,int> initp = make_pair(0,0);
  que.push(initp);

  int d[h][w];
  rep(i,h)rep(j,w) d[i][j] = INF;
  d[0][0] = 0;

  while(que.size()) {
    pair<int, int> tmp = que.front(); que.pop();
    if (tmp.first == h-1 and tmp.second == w-1) break;

    for (int i = 0; i < 4; ++i) {
      int nx = tmp.first + dx[i], ny = tmp.second + dy[i];

      if (nx >= 0 and nx < h and ny >= 0 and ny < w and d[nx][ny] == INF and s[nx][ny] != '#') {
        que.push(make_pair(nx,ny));
        d[nx][ny] = d[tmp.first][tmp.second] + 1;
      }
    }
  }
  if (d[h-1][w-1] == INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << h * w - bl - 1 - d[h-1][w-1] << endl;
}


Measured memory_bytes: 256
class ReversingNumbers:
    def output(self, a):
        s = ""
        a.reverse()
        for i in range(len(a)-1):
            s += "%d " % (a[i])
        s += "%d" % (a[len(a)-1])
        print s

if __name__ == "__main__":
    rn = ReversingNumbers()
    raw_input()
    a = map(int, raw_input().split())
    rn.output(a)

Measured memory_bytes: 6440
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s[110];
  map<string,bool> mp;
  int n,i;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> s[i];
    if(mp[s[i]]==true){
      cout << "No" << endl;
      return 0;
    }
    else{
      mp[s[i]]=true;
    }
  }
  for(i=1;i<n;i++){
    if(s[i-1][s[i-1].size()-1]!=s[i][0]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3608
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author lstd
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}



void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using namespace std;

class ARedOrNot {
public:
	void solve(std::istream& in, std::ostream& out) {
		int a;
		string s;

		in >> a >> s;

		out << (a < 3200? "red" : s);

	}
};

int main() {
	ARedOrNot solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdint>
using namespace std;

const int N_MAX = 3000;

int culc_gcd(int a, int b) {
    if(a < b) swap(a, b);
    int r = a % b;
    a = b;
    b = r;
    return (r == 0) ? a : culc_gcd(a, b);
}

int main() {
    int N;
    int a[N_MAX];

    cin >> N;
    // unsigned long long lcm;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        ans += a[i] - 1;
        // lcm = (i == 0) ? a[i] : (lcm * a[i]) / culc_gcd(lcm, a[i]);
    }

    // for(int i = 0; i < N; i++) {
    //     ans += (lcm - 1) % a[i];
    // }

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


Measured memory_bytes: 256
object Main extends App {
  val abhm = scala.io.StdIn.readLine()
  val abhmaArray = abhm.split(" ").map(_.toInt).toSeq
  val a = abhmaArray(0)
  val b = abhmaArray(1)
  val h = abhmaArray(2)
  val m = abhmaArray(3)
  val hDegree = h * 30 + m * 0.5
  val mDegree = (m * 6).toDouble

  var triangleDegree = 0d
  if(hDegree > mDegree) {
    triangleDegree =
      if (hDegree - mDegree > 180d) {
        360d - hDegree + mDegree
      } else {
        hDegree - mDegree
      }
  } else {
    triangleDegree =
      if (mDegree - hDegree > 180d) {
        360d - mDegree + hDegree
      } else {
        mDegree - hDegree
      }
  }
  if (triangleDegree == 0d) {
    println(Math.abs(a - b))
  } else if (triangleDegree == 180d) {
    println(a + b)
  } else {
    println(Math.sqrt(a * a + b * b - 2d * a * b * Math.cos(Math.toRadians(triangleDegree))))
  }

}

Measured memory_bytes: 54780
n = gets.to_i
t = gets.chomp.split.map(&:to_i)
m = gets.to_i
p = []
m.times do
  p << gets.chomp.split.map(&:to_i)
end

sum = t.inject(&:+)

p.each do |pp|
  print "#{sum-(t[pp[0]-1]-pp[1])}\n"
end

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

class Proc{
public:
  string nam;
  int tim;
  Proc(){
    nam = "";
    tim = 0;
  }
};

Proc Q[100001];
class Queue{
private:
  int f;
  int r;
public:
  Queue(){
    f = 0;
    r = 0;
  }
  int next(int p) const{
    return (p+1)%100001;
  }
  bool isFull() const{
    return (next(r) == f);
  }
  bool isEmpty() const{
    return (r == f);
  }
  void push(Proc d){
    if(isFull()){
      return;
    }
    Q[r] = d;
    r = next(r);
  }
  Proc front(){
    if(isEmpty()){
      Proc e;
      e.tim = -1;
      return e;
    }
    return Q[f];
  }
  void pop(){
    if(isEmpty()){
      return;
    }
    f = next(f);
  }
};

int main(){
  Queue qu;
  int n,q;
  cin >> n >> q;
  for(int i=0;i<n;i++){
    Proc p;
    cin >> p.nam >> p.tim;
    qu.push(p);
  }
  int total_tim = 0;
  while(!qu.isEmpty()){
    Proc p = qu.front();
    qu.pop();
    if(p.tim <= q){
      total_tim += p.tim;
      cout << p.nam << ' ' << total_tim << endl;
    }else{
      total_tim += q;
      p.tim -=q;
      qu.push(p);
    }
  }
  return 0;
}



Measured memory_bytes: 7112
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(1e6) + 5;
int f[N];
int ss[N];
char str[N];
int get(int k)
{
    return k == f[k] ? k : f[k] = get(f[k]);
}
int main(void)
{
    cin>>(str + 1);
    int n = strlen(str + 1);
    str[0] = str[++n] = 'a';
    for (int i = 1;i <= n;++i)
        ss[i] = str[i] - str[i - 1],f[i] = i;
    for (int i = 1;i+i <= n;++i)
    {
        f[n - i + 1] = i;
        ss[i] += ss[n - i + 1];
    }
    int m;
    cin>>m;
    while (m --)
    {
        int l,r;
        cin>>l>>r;
        ++r;
        l = get(l);r = get(r);
        if (l == r) continue;
        f[r] = l;
        ss[l] += ss[r];
    }
    for (int i = 1;i <= n;++i)
        if ((ss[i] % 26) && i == get(i))
            return puts("NO") * 0;
    puts("YES");
    return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int m[3001] = {}, s[3001] = {}, si[3001] = {};
  double ans = 0;
  int mst = 0, mmz = 0;

  s[c] = 1;
  s[d] = 1;
  rep(i, 0, f + 1) {
    if(s[i]) {
      for(int j = i; j <= f; j += c) s[j] = 1;
      for(int j = i; j <= f; j += d) s[j] = 1;
    }
  }

  rep(i, 0, f + 1) {
    for(int j = i; j >= 0; j--) {
      if(s[j]) {
        si[i] = j;
        break;
      }
    }
  }


  m[a * 100] = 1;
  m[b * 100] = 1;

  rep(i, 100, f + 1) {
    if(m[i]) {
      for(int j = i; j <= f; j += a * 100) m[j] = 1;
      for(int j = i; j <= f; j += b * 100) m[j] = 1;
      int k = i / 100;
      int mi = 0;
      while(si[k * e - mi] + i > f) mi++;
      if(si[k * e - mi] <= 0) continue;
      if(i + si[k * e - mi] > 0 && ans < (100 * (si[k * e - mi])) / (double)(i + si[k * e - mi])) {
        ans = (100 * (si[k * e - mi])) / (double)(i + si[k * e - mi]);
        mst = si[k * e - mi];
        mmz = i;
      }
    }
  }
  if(!mst) cout << a * 100 << " " << 0 << endl;
  else cout << mmz + mst << " " << mst << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, a[SIZE];
  ll ans = 0;

  scanf("%d", &n);

  
  for(int i=0;i<n;i++){
    scanf("%d", a+i);
    if ((i == 0 && a[i] > 0) || a[i-1] + 1 < a[i]){
      puts("-1");
      return 0;
    }
    if(i > 0){
      if(a[i-1] +1 == a[i]) ans++;
      else ans += a[i];
    }
  }

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



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int getIndex(char c) {
    if (islower(c)) return c - 'a';
    return 26 + (c - 'A');
}

char getChar(int index) {
    if (index < 26) return char('a' + index);
    return char('A' + (index - 26));
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> k(n);
        for (int i=0; i<n; ++i) cin >> k[i];
        string s;
        cin >> s;
        int j = 0;
        for (int i=0; i<(int)s.size(); ++i) {
            s[i] = getChar((getIndex(s[i]) - k[j] + 52) % 52);
            j = (j + 1) % n;
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
K, A, B = map(int, input().split())
total = 0
if A + 2 >= B:
  total = K + 1
else:
  P = K - A - 1
  total = B
  syou = P//2
  zyou = P%2
  total = total + syou*(B - A) + zyou
print(total)  

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;

ll a[maxN];
char s[maxN];
ll power(ll x,ll p,ll M)
{
	if(p == 0)
	{
		return 1;
	}
	ll t = power(x,p/2,M);
	t = t*t%M;
	if(p&1 == 1)
	{
		t = t*x%M;
	}
	return t;
}
ll get(int L,int R,int M)
{
	ll x = (a[R] - a[L-1] + M)%M;
	ll t = power(10,(L-1)*(M-2),M);
	return x*t%M;
}
vector<int> v[10010];
int main()
{
	int n,M;
	scanf("%d%d",&n,&M);
	scanf("%s",s+1);
	ll ans = 0;
	if(M==2 || M==5)
	{
		for(int i=1;i<=n;i++)
		{
			if((s[i]-'0')%M == 0)
			{
				ans += i;
			}
		}
	}
	else
	{
		reverse(s+1,s+1+n);
		for(int i=1;i<=n;i++)
		{
			ll y = s[i]-'0';
			a[i] = (a[i-1] + y*power(10,i-1,M))%M;
		}
		v[0].push_back(0);
		for(int i=1;i<=n;i++)
		{
			v[a[i]].push_back(i);
		}
		for(int i=0;i<M;i++)
		{
			ll x = v[i].size();
			ans += (x * (x-1))/2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3712
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    int a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(k<=a)
    {
        ans=k;
        k=0;
    }
    else
    {
        ans+=a;
        k-=a;
    }
    if(k<=b)
    k=0;
    else
    k-=b;
    ans-=k;
    cout<<ans;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	ll w, h, x, y; cin >> w >> h >> x >> y;
	cout << fixed << setprecision(10) << 0.5*(w*h) << ' ';
	if( (double)x == 0.5*w && (double)y == 0.5*h ) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
c=[]
for i in range(3):
    c.append([int(i) for i in input().split()])

a1,a2,a3=[0,c[1][1]-c[0][1],c[2][1]-c[0][1]]
b1,b2,b3=[c[0][0],c[0][1],c[0][2]]

ans=[[a1+b1,a1+b2,a1+b3],[a2+b1,a2+b2,a2+b3],[a3+b1,a3+b2,a3+b3]]

if ans==c:
    print("Yes")
else:
    print("No")



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

int main() {
  int N;
  cin >> N;
  unsigned long long a=2,b=1;
  for (int i=0;i<max(0,N-1);i++){
    unsigned long long c=b;
    b+=a;
    a=c;
  }
  if (N==1){
    cout << 1 << endl;
  }
  else{
  	cout << b << endl;  
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s,t;
    cin >> s >> t;
    bool hantei=false;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    
    if(s<t) hantei=true;
    if(hantei) cout << "Yes" <<endl;
    else        cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>
using namespace std;
typedef complex<double> P;

const int XMIN = -2013;
const int YMIN = XMIN;
const int XMAX = 2013;
const int YMAX = XMAX;
const int INF = (1<<28);

struct L : public vector<P> {
  L(P a, P b) {
    push_back(a);
    push_back(b);
  }
};

int N;
vector<P> ps;

double getY(L l, double x) {
  return (l[1].imag()-l[0].imag()) * (x - l[0].real()) / (l[1].real()-l[0].real())
                   + l[0].imag();
}

int main() {
  while(cin >> N && N) {
    ps.resize(N);
    for(int i = 0; i < N; ++i) {
      cin >> ps[i].real() >> ps[i].imag();
    }

    vector<L> ls;
    for(int i = 0; i < N; ++i) {
      P a = ps[i];
      P b = ps[(i+1)%N];
      if(a.real() == b.real()) continue;
      if(a.real() > b.real()) swap(a,b);
      ls.push_back(L(a,b));
    }

    int res = 0;
    for(int x = XMIN; x <= XMAX; ++x) {
      vector<pair<pair<double,double>, int> > v;
      for(int i = 0; i < ls.size(); ++i) {
        if(ls[i][0].real() <= x && x+1 <= ls[i][1].real()) {
          v.push_back(make_pair(make_pair(getY(ls[i], x), getY(ls[i],x+1)), i));
        }
      }
      sort(v.begin(), v.end());
      for(int i = 0, y = -INF, f = 0; i < v.size(); ++i, f = 1-f) {
        int ind = v[i].second;
        double y1 = getY(ls[ind], x);
        double y2 = getY(ls[ind], x+1);
        if(y1 > y2) swap(y1, y2);
        y1 = floor(y1);
        y2 = ceil(y2);
        y1 = max((double)y, y1);
        if(f) res += y1 - y;
        res += y2 - y1;
        y = y2;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1268
fun main(args: Array<String>) {
    val (D, G) = readLine()!!.split(" ").map { it.toInt() }
    val pAndC = listOf<Pair<Int, Int>>().toMutableList()
    (1..D).forEach {
        val (p, c) = (readLine()!!.split(" ").map { it.toInt() })
        pAndC.add(Pair(p, c));
    }


    val bitSize = D
    val allConbinations = Math.pow(2.toDouble(), bitSize.toDouble()).toInt()
    var minSolvedCount = Int.MAX_VALUE
    for (bits in 1..allConbinations) {
        var aqquiredScore = 0
        var count = 0
        for (i in 0..(bitSize - 1)) {
            val problemScore = 100 * (i + 1)
            val problemSize = pAndC.get(i).first
            val bonusScore = pAndC.get(i).second

            val iThProblemsShouldBeSolvedAll = bits.isBitSet(i)

            if (iThProblemsShouldBeSolvedAll) {
                count += problemSize
                aqquiredScore += problemScore * problemSize + bonusScore
            }
        }

        for (i in (bitSize-1) downTo 0) {
            val ithProblemsNotSolvedYet = !bits.isBitSet(i)
            val problemScore = 100 * (i + 1)
            var problemSize = if(ithProblemsNotSolvedYet) {
                pAndC.get(i).first
            } else {
                0
            }

            while (problemSize > 0 && aqquiredScore < G) {
                problemSize--
                count++
                aqquiredScore += problemScore
            }
        }
        minSolvedCount = Math.min(minSolvedCount, count)
    }

    println(minSolvedCount)
}


fun Int.isBitSet(index: Int) : Boolean {
  return this.shr(index).and(1) == 1
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                   1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int K;
  cin >> K;
  cout << A.at(K - 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int chi, candy;
    cin >> chi >> candy ;
    
    set<int> have;
    
    int num, tmp;
    for(int i = 0; i < candy; i++){
        cin >> num ;
        for(int j = 0; j < num ; j++){
            cin >> tmp ;
            have.insert(tmp);
        }
    }
    
    cout << chi - have.size() << endl;
    
}


Measured memory_bytes: 3584
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = list(map(int, input().split()))

  ans = 0
  for i in range(N):
    if ((i+1) % 2 == 1) and (A[i] % 2 == 1):
      ans += 1
  print(ans)


if(__name__ == '__main__'):
  main()

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  vs s(n);
  rep(i,n){
    cin>>s[i];
  }
  int m;cin>>m;
  vs t(m);
  rep(i,m)cin>>t[i];
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  
  int b=0;
  int ans=0;
  while(b<n){
    int tmp=0;
    string now=s[b];
    rep(i,n){
      if(now==s[i]){
        tmp++;
      }
    }
    rep(i,m){
      if(now==t[i])tmp--;
    }
    if(ans<tmp)ans=tmp;
    b++;
  }
  cout(ans);
  return 0;
}

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

int main() {
    int N, ans = 1;
    long long s;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    s = A.at(0);
    for (int i = 1; i < N; i++) {
        if (A.at(i) > 2 * s) {
            ans = 1;
        } else {
            ans++;
        }
        s += A.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub fn divisors(n: u64) -> Vec<u64> {
    let mut res = Vec::new();
    let mut x = 1;
    while x * x <= n {
        if n % x == 0 {
            res.push(x);
            let y = n / x;
            if y != x {
                res.push(y);
            }
        }
        x += 1;
    }
    res
}

fn solve() {
    input! {
        n: u64
    };

    let mut res = std::u64::MAX;
    for a in divisors(n) {
        let d = a + n / a - 2;
        if d < res {
            res = d;
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int x, n;
  cin >> x >> n;
  vector<int> cnt(1000000);
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    ++cnt[p];
  }
  for (int i = 0; ; i++) {
    if (!cnt[x - i]) {
      cout << x - i << '\n';
      return 0;
    } 
    if (!cnt[x + i]) {
      cout << x + i << '\n';
      return 0;
    }
  }
  return 0;
}

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

int main(){
    string s ;
    cin >> s ;
    int n = s.size() ;
    int m = 2019 ;
    reverse(s.begin(),s.end()) ;
    int x = 1 , total = 0 ;
    vector<int> val(2019,0) ;
    val[total] = 1 ;
    ll ans = 0 ;
    rep(i,n){
        total += (s[i] - '0')*x ;
        total %= m ;
        val[total]++;
        x = 10*x%m ;
    }
    rep(j,2019) ans += ( val[j] - 1)*val[j]/2 ;
    cout << ans << endl;
}

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

int A[100010];
int myabs(int a) {return a>0?a:-a;}
int main(void)
{
  int N,i,s=0;
  
  cin >> N;
  A[0]=A[N+1]=0;
  for(i=1;i<=N;i++){
    cin >> A[i];
    s+=myabs(A[i]-A[i-1]);
  }
  s+=myabs(A[N+1]-A[N]);
  
  for(i=1;i<=N;i++){
    int s1=s-myabs(A[i]-A[i-1])-myabs(A[i+1]-A[i] )
      +myabs(A[i+1]-A[i-1]);
    cout << s1 << endl;
  }
}
      
      
      
      
      
      
      
      
      

Measured memory_bytes: 1664
fun main(args: Array<String>) {
    val a = readInt()
    val b = readInt()
    val ans = (1..3).map { it }
    println(ans.first { it != a && it != b })
}


// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


Measured memory_bytes: 33812
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    int n=1000000;
    cin>>x;
    int prime[1000000]={0};
    for(int i=2;i<=sqrt(n);i++){
        if(!prime[i])
        for(int j=2;i*j<=n;j++){
            if(i*j<=n)
                prime[i*j]=1;
        }
    }
    int i=x;
    while(prime[i]){
        i++;
    }
    cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>

using namespace std;

int main()
{
    int n ;
    cin>>n ;
    int ans = 0 ;
    for(int i = 1 ; i <= n ; ++i)
    {
        int cnt = 0 ;
        for(int j= 1 ; j <= i ; ++j)
            if(i % j == 0)
             cnt++;
        if(i & 1)
        ans += (cnt == 8);
    }
    cout<<ans;
    return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int64 N, K; cin >> N >> K;
    vector<int> L(N);
    rep(i, N) {
        cin >> L[i];
        L[i]--;
    }

    vector<vector<int>> V(100, vector<int>(N));
    V[0] = L;

    reps(1, i, V.size()) {
        rep(j, N) {
            V[i][j] = V[i-1][V[i-1][j]];
        }
    }

    int p = 0;
    bitset<64> v(K);
    rep(i, v.size()) {
        if (v[i]) {
            p = V[i][p];
        }
    }

    cout << p+1 << endl;
}


Measured memory_bytes: 83192
#include <stdio.h>
#define min(a, b) ((a)>(b) ? (b) : (a))
int n, m, x;
int a[14][14];
int c[14];
int ans = 10000000;
int flag = 1;
void dfs(int num, int algo[], int cost){
  if(num == n){
    for(int i=1; i<=m; i++){
      if(algo[i] < x)  break;
      if(i == m){
	ans = min(ans, cost);
	flag = 0;
      }
    }
    return;
  }

  if(1){
    dfs(num+1, algo, cost);
    int newa[14] = {0};
    for(int i=1; i<=m; i++)
      newa[i] = algo[i] + a[num+1][i];
    dfs(num+1, newa, cost+c[num+1]);
  }
}

int main(){
 
  scanf("%d%d%d", &n, &m, &x);
  for(int i=1; i<=n; i++){
    scanf("%d", &c[i]);
    for(int j=1; j<=m; j++){
      scanf("%d", &a[i][j]);
    }
  }

  int algo[14] = {0};
  dfs(0, algo, 0);
  if(flag) ans = -1;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1732
from collections import deque

n, q = map(int, input().split())
eg = [[] for _ in range(n + 1)]

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

cnt = [0] * (n + 1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p] += x


q = deque()
q.append(1)
seen = {1}
ans = [0] * (n + 1)
ans[1] = cnt[1]
while q:
    v = q.pop()
    for t in eg[v]:
        if t in seen:
            continue
        q.append(t)
        seen.add(t)
        ans[t] = ans[v] + cnt[t]

print(*ans[1:])


Measured memory_bytes: 156852
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define debug cerr << "-- " << __LINE__ << " --" << endl
#define MOD 1000000007
#define ALL(o) (o).begin(), (o).end()
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template <typename T> string to_string(const vector<T> &xs) {string s="["; for(int i=0;i<xs.size();i++) s += (i>0 ? " " : "") + to_string(xs[i]); return s + "]";}
template <typename T> ll argmax(const T &xs) {return distance(xs.begin(), max_element(xs.begin(), xs.end()));}
template <typename T> ll argmin(const T &xs) {return distance(xs.begin(), min_element(xs.begin(), xs.end()));}
ll nextLL(){ll x; scanf("%lld", &x); return x;}
int nextInt(){int x; scanf("%d", &x); return x;}
string nextString(){string s; cin >> s; return s;}


ll extgcd(ll a, ll b, ll &x, ll &y) {
    /* g を返す時点で ax + by == g となる */
    ll g = a; x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}
ll gcd(ll a, ll b) { ll x, y; return extgcd(a, b, x, y); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll remainder(ll x, ll y) {assert(y > 0); ll r = x % y; if (r < 0) r += y; return r;}
ll quotient(ll x, ll y) {assert(y > 0); return (x - remainder(x, y)) / y;}

class llm{
	ll n;
public:
	llm(){n = 0;}
	llm(ll n){this->n = (n >= 0) ? (n % MOD) : (MOD - 1 - (-n-1 % MOD));}
	operator ll() const {return n;}
	llm operator+(const llm &y) const{ return llm((ll)*this + (ll)y);}
	llm operator+=(const llm &y) { *this = *this + y; return *this;}
	llm operator-(const llm &y) const{ return llm((ll)*this - (ll)y);}
	llm operator-=(const llm &y) { *this = *this - y; return *this;}
	llm operator-() const{ return llm(0) - *this;}
	llm operator*(const llm &y) const{ return llm((ll)*this * (ll)y);}
	llm operator*=(const llm &y) { *this = *this * y; return *this;}
	llm operator/(const llm &y) const{ return *this * y.inv();}
	llm operator/=(const llm &y) { *this = *this / y; return *this;}
	llm inv() const{
		ll x, y;
		if (extgcd(n, MOD, x, y) == 1) return llm(x);
  		return llm(0); // unsolvable
	}
	friend istream& operator >> (istream& os, llm& x);
	friend ostream& operator << (ostream& os, const llm& x);
};
istream& operator >> (istream& is, llm& x){ll n; is >> n; x = llm(n); return is;}
ostream& operator << (ostream& os, const llm& x){os << (ll)x; return os;}

template<typename T> T comb(ll n, ll k){
	T ret = 1;
	for(ll i=1;i<=k;i++) ret = ret * T(n - k + i) / T(i);
	return ret;
}


ll n, m;
int main(void){
	cin >> n >> m;
	if (n % 2 == 1){
		for(ll i=0;i<m;i++){
			cout << 1+i << " " << n-i << endl;
		}
	}else{
		ll cnt = 0;
		ll st = n / 2 + 1;
		ll ed = n * 3 / 4;
		for(ll i=st;i<=ed;i++){
			cout << i << " " << ed + ed+1 - i << endl;
			cnt++;
			if (cnt==m) return 0;
		}
		ll mid = (n + 2) / 4;
		for(ll i=1;i<mid;i++){
			cout << i << " " << mid*2 - i << endl;
			cnt++;
			if (cnt==m) return 0;
		}
	}
	
	


    return 0;
}




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


def check(data):
    diff={}
    
    for i in range(3):
        for j in range(2):
            
            # diff b
            key_b = "b_" + str(j) + "-" + str(j+1)
            delta_b = data[i][j+1] - data[i][j]
            if key_b in diff:
                if diff[key_b] != delta_b:
                    return False
            else:
                diff[key_b] = delta_b

    for j in range(3):
        for i in range(2):
            # diff a
            key_a="a_" + str(i) + "-" + str(i+1)
            delta_a = data[i+1][j] - data[i][j]
            if key_a in diff:
                if diff[key_a] != delta_a:
                    return False
            else:
                diff[key_a] = delta_a

    return True

#----------
data = [list(map(int, input().rstrip().split())) for _ in range(3)]
#----------
if check(data):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
N = int(input())
x_u = [input().split() for _ in range(N)]
x_u = [(float(i[0]), i[1]) for i in x_u]

result = 0
for x, u in x_u:
    if u == "JPY":
        result += x
    else:
        result += x * 380000.0

print(result)

Measured memory_bytes: 3060
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    print((I()-2)*180)
if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
  int a, b;
  char op;
  bool isLoop = true;
  while (isLoop) {
    int c;
    cin >> a >> op >> b;
    if (op == '+') {
      c = a + b;
      cout << c << endl;
    }
    if (op == '-') {
      c = a - b;
      cout << c << endl;
    }
    if (op == '*') {
      c = a * b;
      cout << c << endl;
    }
    if (op == '/') {
      c = a / b;
      cout << c << endl;
    }
    if (op == '?') {
      isLoop = false;
    }
  }
  return 0;
}


Measured memory_bytes: 3088
from fractions import gcd
#from math import gcd

N = int(input()) # N < 10 ** 5
A = [int(x) for x in input().split()]

g = A[0]
gcd1 = [0] * N
gcd1[0] = A[0]
for i in range(1, N):
    g = gcd1[i] = gcd(A[i], g)

g = A[N-1]
gcd2 = [0] * N
gcd2[N-1] = A[N-1]
for i in range(0, N-1)[::-1]:
    g = gcd2[i] = gcd(A[i], g)

gcd0 = [0] * N
gcd0[0] = gcd2[1]
gcd0[N-1] = gcd1[N-2]

for i in range(1, N-1):
    gcd0[i] = gcd(gcd1[i-1], gcd2[i+1])

print(max(gcd0))


Measured memory_bytes: 16172
fun main(args: Array<String>) {

    fun gcd(a: Int, b: Int): Int {
        return if (b == 0) a else gcd(b, a % b)
    }

    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val a = readLine()!!.split(' ').map { it.toInt() }

    val m = a.max()!!
    val g = a.reduce { acc, i -> gcd(acc, i) }

    println(if (k <= m && k % g == 0) "POSSIBLE" else "IMPOSSIBLE")
}


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

int main(void){
  string a, b, c;
  cin >> a >> b;
  c = a + b;
  
  int n = stoi(c);

  for(int i = 0; i < 1000; i++){
    if(n == i * i){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
 
  return 0;
}


Measured memory_bytes: 256