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

pair<ll,ll> Qex(string s){
  ll mom=0,child=0,n,i,check=0;
  n=s.size();
  for(i=0;i<n;i++){
    if(s.at(i)=='.'){
      check++;
      break;
    }
  }
  if(check==0){
    mom=1;
    ll p=1;
    for(i=n-1;i>=0;i--){
      child += p*(s.at(i)-'0');
      p *= 10;
    }
    return pair<ll,ll>(mom,child);
  }else{
    ll p=1,j;
    for(j=n-1;j>=i+1;j--){
      child += p*(s.at(j)-'0');
      p *= 10;
    }
    mom=p;
    for(j=i-1;j>=0;j--){
      child += p*(s.at(j)-'0');
      p *= 10;
    }
    return pair<ll,ll>(mom,child);
  }
}

pair<ll,ll> pow25(pair<ll,ll> q){
  ll pow2=0,pow5=0;
  ll mom,child;
  child=q.second;
  while(child%2==0){
    child /= 2;
    pow2++;
  }
  child=q.second;
  while(child%5==0){
    child /= 5;
    pow5++;
  }
  mom=q.first;
  while(mom%2==0){
    mom /= 2;
    pow2--;
  }
  mom=q.first;
  while(mom%5==0){
    mom /= 5;
    pow5--;
  }
  return pair<ll,ll>(pow2,pow5);
}

int main(){
  ll n,i,j;
  cin >> n;
  vector<string> s(n);
  vector<pair<ll,ll>> p(n);
  vector<vector<ll>> a(60,vector<ll>(60,0));
  
  for(i=0;i<n;i++){
    cin >> s.at(i);
    p.at(i)=pow25(Qex(s.at(i)));
    a.at(p.at(i).first+9).at(p.at(i).second+9)++;
  }
  
  ll ans=0;
  
  for(i=0;i<60;i++){
    for(j=0;j<60;j++){
      if(i>=9&&j>=9){
        ans += a.at(i).at(j)*(a.at(i).at(j)-1);
      }
    }
  }
  
  ll k,l;
  for(i=0;i<60;i++){
    for(j=0;j<60;j++){
      for(k=0;k<60;k++){
        for(l=0;l<60;l++){
          if((i!=k||j!=l)&&i+k>=18&&j+l>=18){
            ans += a.at(i).at(j)*a.at(k).at(l);
          }
        }
      }
    }
  }
  
  ans /= 2;
  cout << ans << endl;
  
}

Measured memory_bytes: 12704
using System;
using System.Linq;

namespace agc008_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int min = 2147483647;
            if (x[0] <= x[1])
            {
                min = Math.Min(min, x[1] - x[0]);
            }
            if (x[0] * -1 <= x[1])
            {
                min = Math.Min(min, x[1] - x[0] * -1 + 1);
            }
            if (x[0] <= x[1] * -1)
            {
                min = Math.Min(min, x[1] * -1 - x[0] + 1);
            }
            if (x[0] * -1 <= x[1] * -1)
            {
                min = Math.Min(min, x[1] * -1 - x[0] * -1 + 2);
            }
            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	bool ans=false;
	for(int i=0;i<=n/4;i++){
		for(int j=0;j<=n/7;j++){
			if(i*4+j*7==n)
			ans=true;	
		}
	}
	if(ans)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;

int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	long long int  s[200][200];
	cout << fixed << setprecision(10);
	long double big, small, wa;
	long long int n, m,x, res = 0, cou = 1, mi = 999999999, ma = -9999999999;
	long long int max_id, min_id,L[200000],w,h,y;
	cin >>w>>h>>x>>y ;
	wa = w * h / 2.0;
	if (w == 2 * x && h == 2 * y) {
		cout << wa << " " << 1;
	}
	else {
		cout << wa << " " << 0;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  int M; cin >> M;
  vector<int> a(N, -1);
  rep(i, M) {
    int s, c;
    cin >> s >> c;
    if(a[s-1] != -1 && a[s-1] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s-1] = c;
  }
  if(a[0] == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  if(a[0] == -1) {
    if(N==1) a[0] = 0;
    else a[0] = 1;
  }
  for(auto i:a) {
    if(i == -1) cout << 0;
    else cout << i;
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;
map<P, int> mp;

int getc(int x, int y){
    if (mp.count(P(x, y))) return mp[P(x, y)];
    return -1;
}

bool setc(int x, int y, int c){
    if (mp.count(P(x, y)) && mp[P(x, y)] != c) return false;
    mp[P(x, y)] = c;
    return true;
}

bool canc(int x, int y, int c){
    int a = getc(x, y);
    return a == -1 || a == c;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

int main() {
    ll n, m;
    cin >> n >> m;
    REP(i,m){
        int a = in() - 1, b = in() - 1, c = in();
        mp[P(a, b)] = c;
    }

    // REP(i,n){
    //     REP(j,n){
    //         int x = getc(i,j);
    //         if (x == -1) cout << "*";
    //         else cout << x;
    //     }
    //     cout << endl;
    // }

    REP(i,n){
        int x = getc(i+1,i-1);
        int y = getc(i-1,i+1);
        if (x != -1 && y != -1){
            if (!setc(i, i, x ^ y)){
                cout << 0 << endl;
                return 0;
            }
        }
    }

    VVL dp(n + 1, VL(2));
    REP(k,2) dp[0][k] = (getc(0, 0) != (k ^ 1));
    REP(i,n-1) REP(j,2){
        REP(x,2) REP(y,2) REP(z,2){
            if (canc(i, i + 1, x) && canc(i + 1, i, y) && canc(i + 1, i + 1, z) &&
                (j + x + y + z) % 2 == 0){
                dp[i+1][z] = (dp[i+1][z] + dp[i][j]) % mod;
            }
        }
    }

    ll ans = dp[n-1][0] + dp[n-1][1];
    // cout << ans << endl;
    set<P> st;
    ll filled = 0;
    for (auto tmp : mp){
        P p = tmp.first;
        int c = tmp.second;
        if (abs(p.first - p.second) <= 2) continue;
        st.insert(P(p.first, p.second));
        st.insert(P(p.second, p.first));
        filled++;
        if (p.first > p.second && mp.count(P(p.second, p.first))) filled--;
        if (!canc(p.second, p.first, c)){
            cout << 0 << endl;
            return 0;
        }
    }

    // cout << n * n - (3 * n - 2) << endl;

    ll cnt = (n * n - (3 * n - 2) - st.size()) / 2;
    REP(i,n){
        if (getc(i-1,i+1) != -1 || getc(i+1,i-1) != -1){
            cnt--;
        }
    }
    // cout << cnt << endl;
    ans = (ans * powll(2, cnt)) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<char> color(N);
  for(int i=0;i<N;i++){
    cin>>color.at(i);
  }
  sort(color.begin(),color.end());
  int ans = 1;
  for(int i=0;i<N-1;i++){
    if(color.at(i)!=color.at(i+1)){
      ans++;
    }
  }
  if(ans==3){
    cout<<"Three"<<endl;
  }
  else{
    cout<<"Four"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		 Scanner sc      = new Scanner(System.in);
		 Integer maxLength =  Integer.parseInt(sc.nextLine());
		 String  stringS =  sc.nextLine();

		 if(stringS.length() > maxLength ) {
			 String output = stringS.substring(0, maxLength);
			 System.out.println(output + "...");
		 }else {
			 System.out.println(stringS);
		 }
	}

}

Measured memory_bytes: 38488
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	string a,b,c;
	int ans=0;
	
	cin>>a>>b>>c;
	if(a[a.length()-1]==b[0] && b[b.length()-1]==c[0])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    ll a,b,n;
    cin >> a >> b >> n;
    ll x=min(b-1,n);
    cout << floor(a*x/b) << endl;

    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a,b,c,d,e;
  cin>>a>>b;
  if(a*b%3==0)
    cout<<0<<endl;
  else{
    int a1,b1,c1,a2,b2,c2;
    a1=a/2*(b*2/3);
    b1=a*(b*2/3)-a1;
    c1=a*b-a1-b1;
    a2=a/2*(b*2/3+1);
    b2=a*(b*2/3+1)-a2;
    c2=a*b-a2-b2;
    c=max<int>(max<int>(abs<int>(a1-b1),abs<int>(b1-c1)),abs<int>(c1-a1));
    e=max<int>(abs<int>(a2-b2),max<int>(abs<int>(b2-c2),abs<int>(c2-a2)));
    c=min<int>(c,e);
    swap(a,b);
    a1=a/2*(b*2/3);
    b1=a*(b*2/3)-a1;
    c1=a*b-a1-b1;
    a2=a/2*(b*2/3+1);
    b2=a*(b*2/3+1)-a2;
    c2=a*b-a2-b2;
    d=max<int>(max<int>(abs<int>(a1-b1),abs<int>(b1-c1)),abs<int>(c1-a1));
    e=max<int>(abs<int>(a2-b2),max<int>(abs<int>(b2-c2),abs<int>(c2-a2)));
    d=min<int>(d,e);
    cout<<min<int>(min<int>(c,d),min<int>(a,b))<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  VEC(int, s, N);
  int ans = accumulate(all(s), 0);
  if (ans % 10) {
    print(ans);
    return;
  }
  sort(all(s));
  rep(i, 0, N) {
    if (s[i] % 10) {
      print(ans - s[i]);
      return;
    }
  }
  print(0);
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i < 499500; ++i) {
    int ay = (sqrt(8 * (a + i) + 1) - 1) / 2;
    if ((a + i) + (ay + 1) == (b + i)) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 384
function main(input){
  var n = parseInt(input[0]);
  var a = input[1].split(' ').map(s=>parseInt(s));
  var b = input[2].split(' ').map(s=>parseInt(s));
  
  if(a.reduce((n, sum) => n+sum, 0) < b.reduce((n, sum) => n+sum, 0)) {
    console.log(-1);
    return;
  }

  var count = 0;
  var diff = 0;
  var arr = [];

  for (var i=0; i<n; i++) {
    if (a[i] < b[i]) {
      count++;
      diff += b[i] - a[i];
      arr.push(0);
    } else {
      arr.push(a[i] - b[i]);
    }
  }

  arr=arr.sort((k,j) => j-k);
  var aa = 0;
  var i = 0;
  while(aa < diff) {
    aa += arr[i++];
    count++;
  }

  console.log(count);
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});


Measured memory_bytes: 43756
#include <cstdio>

using namespace std;

int main() {
  int n, d, x;
  scanf("%d%d%d", &n, &d, &x);

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

  printf("%d\n", x);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=1005;
#define M 1000000007
#define double long double
#define BINF 1000000000001
#define init(a,val) memset(a,val,sizeof(a))
const int LG = 22;


 
#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0); 
 
    


    int a,b;
    cin >> a >> b;
    if(b == 1){
        cout << 0;
        return 0;
    }

    int len = 0;
    int c = 0;

    int cur = 1;
    while(cur < b){
        c++;
        cur += a - 1;
    }

    cout << c << endl;
    


 
return 0;
}

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

int main(){
  int n,kotae=0;
  string s,t;
  cin>>s;
  n=s.length();
  if(n%2==0){
    n/=2;
    for(;n>=1;n--){
      t+="hi";
    }
    if(s==t){
      kotae=1;
    }
  }
  if(kotae){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}
  

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

int keta(int64_t N){
	int count = 1;
  	while(N / 10 != 0){
    	N /= 10;
      	count++;
    }
  	return count;
}

int main() {
  int64_t N;
  cin >> N;
  int A = 10;
  int64_t M = 0;
  for(int64_t i = 0; i <= N ; i++){
  	if(i*i >= N){
    	M = i;
      	break;
    }
  }
  for(int64_t i = 1 ; i <= M ; i++){
  	if(N % i == 0){
    	int F = max(keta(i),keta(N/i));
      	if(F < A){
        	A = F;
        }
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    string s;
    cin >> s;
    int n = s.size(), cnt[2]={}, ans = 0;
    fore(i,0,n) {
        int c = s[i]-'0';
        if (cnt[c^1]) {
            cnt[c^1]--;
            ans++;
        } else {
            cnt[c]++;
        }
    }
    cout << ans*2 << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<queue>
#include<vector>
#include<set>

using namespace std;

int n, m;
int a[200005], b[200005];
queue<int> Q;
bool f[200005];
vector<int>V[200005];
int cnt[200005];

int bfs(int s, int e){
  for(int i = 0; i < n; ++i){
    f[i] = false;
    //cnt[i] = 0;
  } 
  f[s] = true;
  Q.push(s);
  int t = 0;
  //int cnt = 0;
  bool judge = false;
  while(!Q.empty() && t < 2){
    t++;
    int tmp = Q.front();
    Q.pop();
    for(int i = 0; i < V[tmp].size(); ++i){
      if(f[V[tmp][i]] == false){
        f[V[tmp][i]] = true;
        Q.push(V[tmp][i]);
        //cnt++;
        if(V[tmp][i] == e && t == 2){
          judge = true;
        }
      }
    }
  }
  return judge;
}

int bfs2(int s, int e){
  for(int i = 0; i < n; ++i){
    f[i] = false;
    cnt[i] = 0;
  } 
  f[s] = true;
  queue<int> Q1;
  //cout << s << endl;
  Q1.push(s);
  //cout << Q.front() << endl;
  //int t = 0;
  //int cnt = 0;
  bool judge = false;
  int tmp2 = 0;
  while(!Q1.empty() && tmp2 < 2){
    //t++;
    int tmp = Q1.front();
    //cout << Q.front() << endl;
    //cout << tmp << endl;
    Q1.pop();
    tmp2 = cnt[tmp];
    for(int i = 0; i < V[tmp].size(); ++i){
      if(f[V[tmp][i]] == false){
        //cout << V[tmp][i] << endl;
        f[V[tmp][i]] = true;
        Q1.push(V[tmp][i]);
        cnt[V[tmp][i]] = cnt[tmp] + 1;
        if(V[tmp][i] == e && cnt[V[tmp][i]] == 2){
          judge = true;
        }
      }
    }
  }
  return judge;
  //cout << t << endl;
  //cout << s << e << endl;
  //cout << judge << endl;
}

int main(){
  cin >> n >> m;
  for(int i = 0; i < m; ++i){
    cin >> a[i] >> b[i];
    V[a[i]].push_back(b[i]);
    V[b[i]].push_back(a[i]);
  }
  if(bfs2(1, n) == false){
    cout << "IMPOSSIBLE" << endl;
  }else{
    cout << "POSSIBLE" << endl;
    //cout << bfs(1, n) << endl;
  }
  //bfs2(1, n);
}

Measured memory_bytes: 14960
def main():
    order = [len(el) for el in list(map(str, input().rstrip().split("T")))]
    x_points = {order[0]}
    y_points = {0}
    for val in order[2::2]:
        plus_val = {x + val for x in list(x_points)}
        minus_val = {x - val for x in list(x_points)}
        x_points = plus_val | minus_val
    for val in order[1::2]:
        plus_val = {y + val for y in list(y_points)}
        minus_val = {y - val for y in list(y_points)}
        y_points = plus_val | minus_val
    target_x, target_y = map(int, input().split())
    if target_x in x_points and target_y in y_points:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 5088
#include<bits/stdc++.h>
    using namespace std;
    using Int = long long;
    template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
    template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
     
    //INSERT ABOVE HERE
    signed main()
	{
      Int n;
      cin>>n;
      vector<Int> xs(n),ys(n);
      for(Int i=0;i<n;i++) cin>>xs[i]>>ys[i];
     
      using D = double;
      D ans=0;
      for(Int i=0;i<n;i++)
	  {
        Int gx=xs[i],gy=ys[i];
        for(Int k=0;k<4;k++)
		{
          Int nx=-gy,ny=gx;
          gx=nx;
          gy=ny;
     
          Int sx=0,sy=0;
          Int px=0,py=0;
          Int qx=0,qy=0;
     
          auto dot=[&](Int x1,Int y1,Int x2,Int y2){return x1*x2+y1*y2;};
          auto cross=[&](Int x1,Int y1,Int x2,Int y2){return x1*y2-x2*y1;};
          for(Int j=0;j<n;j++)
		  {
            Int res=dot(xs[j],ys[j],gx,gy);
            if(res<0) continue;
            if(res>0){sx+=xs[j];sy+=ys[j];continue;}
            if(cross(xs[j],ys[j],gx,gy)>0){px+=xs[j];py+=ys[j];}
			else{qx+=xs[j];qy+=ys[j];}
          }
          D bx=sx,by=sy;bx+=px,by+=py;chmax(ans,bx*bx+by*by);
          bx=sx,by=sy;bx+=qx,by+=qy;chmax(ans,bx*bx+by*by);
        }
      }
      cout<<fixed<<setprecision(12)<<sqrt(ans)<<endl;
      return 0;
    }


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector< pair<int, int> > v;
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    v.push_back({a, i+1});
  }
  sort(v.begin(), v.end());
  for(auto x : v) cout << x.second << " ";
  cout << '\n';
  return 0;
}


Measured memory_bytes: 1780
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
const int MR=1e6+10;


int main(){
	LL n;
	cin>>n;
	LL ans=0;
	LL d=1;
	while(d<=n){
		LL m=n/d;
		LL end=n/m;
		if(end>n) end=n;
		ans+=(d+end)*(end-d+1)*m*(m+1)/4;
		d=end+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){
	//?°???°?????±????????§??????double???
	double x1, y1, x2, y2, d;

	//??\?????????
	cin >> x1 >> y1 >> x2 >> y2;

	d = sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2));
	cout << fixed << d << endl;
	return 0;

}

Measured memory_bytes: 3256
#include<stdio.h>
int h,w,d;
char c[9]="RGBY";
int calc(int x){
	x %= (2*d);
	if(x < 0)x += 2*d;
	return x / d;
}
int main(){
	scanf("%d%d%d",&h,&w,&d);
	for(int i=0; i<h; i++,puts(""))
		for(int j=0; j<w; j++)
			putchar(c[calc(i+j)*2+calc(i-j)]);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define X first
#define Y second
//#define INF 1e12
 
int main() {
	int n;cin>>n;
	int a[n+1]={0};
	for(int i=0;i<n-1;i++)
	{
		int x;cin>>x;
		a[x]++;
	}
	for(int i=1;i<=n;i++)
	cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 4348
N, M, R = map(int, input().split())
r = list(map(int, input().split()))

adj = [[] for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    adj[-A].append((B, C))
    adj[-B].append((A, C))

import heapq

def Dijkstra(N, v_st, v_go):
    cost = [float('inf') for i in range(N)]

    pq = []
    heapq.heappush(pq, (0, v_st))

    while pq:
        c, v_now = heapq.heappop(pq)

        if v_now == v_go:
            return c

        if cost[-v_now] < c:
            continue

        cost[-v_now] = c

        for v, c2 in adj[-v_now]:
            if cost[-v_now] + c2 < cost[-v]:
                cost[-v] = cost[-v_now] + c2
                heapq.heappush(pq, (cost[-v], v))

cost_min = [[float('inf') for i in range(R)] for j in range(R)]

for i in range(R):
    for j in range(i, R):
        cost_min[i][j] = Dijkstra(N, r[i], r[j])
        cost_min[j][i] = cost_min[i][j]

import itertools
p = list(itertools.permutations(range(R)))

ans = float('inf')
for pp in p:
    c = 0
    for i in range(R - 1):
        c += cost_min[pp[i]][pp[i + 1]]

    ans = min(ans, c)
    
print(ans)


Measured memory_bytes: 62296
using System;

namespace HappyBirthday_
{
    class Program
    {
        public static string Solve()
        {
            string input = Console.ReadLine();
            int cutA = int.Parse(input.Split()[0]);
            int cutB = int.Parse(input.Split()[1]);
            // TDKR=A切れ　KMR=B切れ
            if (cutA <= 8 && cutB <= 8)
            {
                // 分けて食べる
                return "Yay!";
            }
            // よろしい。ならば戦争だ
            return ":(";
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve());
        }
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <array>

int main() {
  uint32_t N = 0;
  std::cin >> N;
  std::array<int64_t, 100'001> a;
  a.fill(0);
  int64_t sum = 0;
  for (size_t i = 0; i < N; i++)
  {
    int64_t A = 0;
    std::cin >> A;
    a[A]++;
    sum += A;
  }

  uint32_t Q = 0;
  std::cin >> Q;
  for (size_t q = 0; q < Q; q++)
  {
    int64_t B = 0, C = 0;
    std::cin >> B >> C;
    int64_t num = a[B];
    a[C] += num;
    a[B] = 0;

    sum += (C-B)*num;
    std::cout << sum << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 4376
import copy

n,m=list(map(int,input().split()))
way=[[] for _ in range(n)]
edge=[]
for i in range(m):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    way[a].append(b)
    way[b].append(a)
    edge.append((a,b))
checked=[False]*n

new_way=[]

def searchWay(current,to):
    flg=False
    checked[current]=True
    for i in new_way[current]:
        if i == to:
            return True
        else:
            if not checked[i]:
                if searchWay(i,to):
                    flg=True
                    break
    return flg

ans=0
for i in edge:
    checked=[False]*n
    new_way=copy.deepcopy(way)
    new_way[i[0]].remove(i[1])
    new_way[i[1]].remove(i[0])
    if not searchWay(i[0],i[1]):
        ans+=1
print(ans)

Measured memory_bytes: 3572
N, c = map(int, input().split())
D = [[int(i) for i in input().split()] for j in range(c)]
C = [[int(i) for i in input().split()] for j in range(N)]
A = [[0 for i in range(c)] for j in range(3)]
for i in range(N):
    for j in range(N):
        for k in range(c):
            A[(i+j)%3][k] += D[C[i][j]-1][k]

ans = 1e9
for i in range(c):
    for j in range(i):
        for k in range(j):
            for l in range(3):
                ans = min(ans, A[l][i]+A[(l+1)%3][j]+A[(l+2)%3][k],
                          A[l][i]+A[(l-1)%3][j]+A[(l-2)%3][k])
print(ans)


Measured memory_bytes: 46300
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 400100
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,double> pdd;
inline int mod(int n, int m){int ret = n%m; if(ret < 0) ret += m; return ret;}
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }    else return mod(k*k,m);
}

vector<pii> v;

double calc(pii a,pii b){
	return sqrt((a.ff-b.ff)*(a.ff-b.ff) + (a.ss-b.ss)*(a.ss-b.ss));
}

int32_t main(){
	fastio;
	int n;
	cin>>n;
	v.resize(n);
	vector<int> x;
	for(int i=0;i<n;i++){
		x.pb(i);
		cin>>v[i].ff>>v[i].ss;
	}
	double dist=0;
	do{
		for(int i=0;i<n-1;i++){
			dist+=calc(v[x[i]],v[x[i+1]]);
		}
		
		
	}while(next_permutation(x.begin(),x.end()));
	double fac = 1;
	for(int i=1;i<=n;i++)fac=fac*i;
	dist = 1.0*dist/fac;
	cout<<setprecision(7)<<fixed;
	cout<<dist<<endl;
}

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

typedef long long ll;
typedef long double ld;

#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define fr first
#define sc second

const int N=1e5+6;
ll ar[N];

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    ll sum=0;
    FOR(i,n){
        int a,b;
        cin>>a>>b;
        ar[i]=a+b;
        sum-=(ll)b;
    }
    sort(ar,ar+n);
    FORD(i,n){
        if (i%2!=n%2){
            sum+=ar[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}



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

int main() {
    string s;
    cin >> s;
    for (char c = 'a'; c <= 'z'; c++) {
        if (s.find(c) != string::npos)
            continue;
        else {
            printf("%c\n", c);
            return 0;
        }
    }
    puts("None");
    return 0;
}


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

using namespace std;

const int N = 30;
int b[N];
int a[N];
int c[N];

int main(){
	int n;

	scanf("%d", &n);

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

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

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

	int sum = 0;

	for(int i = 1 ; i <= n ; i++){
		sum += b[a[i]];
		// printf("+%d\n", b[a[i]]);

		if(a[i] == a[i - 1] + 1){
			sum += c[a[i - 1]];
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    numbers=[]
    n,m = map(int,input().split())
    [numbers.append(int(input())) for _ in range(n)]
    n_numbers=np.array(numbers,dtype=int)
    n_numbers.sort()
    print(min(n_numbers[i+m-1] - n_numbers[i] for i in range(n-m+1)))

if __name__=="__main__":
    main()

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

using namespace std;
using ll = long long;
using ull = unsigned long long;


void ABC136E()
{
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (auto& x : A)
		cin >> x;

	ll sum = accumulate(A.begin(), A.end(), 0LL);
	vector<int> B(N);
	int sqrtSum = sqrt(static_cast<double>(sum));
	for (int k = 1; k <= sqrtSum; ++k)
	{
		if (sum % k != 0)
			continue;
		ll X = sum / k;

		for (int i = 0; i < N; ++i)
		{
			B[i] = A[i] % X;
		}
		sort(B.begin(), B.end());
		ll C = 0, D = 0;
		int i = 0, j = N - 1;
		while (i <= j)
		{
			if (C < D)
			{
				C += B[i++];
			}
			else
			{
				D += X - B[j--];
			}
			if (max(C, D) > K)
				break;
		}
		if (max(C,D) <= K)
		{
			cout << X << endl;
			return;
		}

	}

	int x = sum / sqrtSum;
	for (int k = x; k >= 1; --k)
	{
		if (sum % k != 0)
			continue;
		ll X = k;

		for (int i = 0; i < N; ++i)
		{
			B[i] = A[i] % X;
		}
		sort(B.begin(), B.end());
		ll C = 0, D = 0;
		int i = 0, j = N - 1;
		while (i <= j)
		{
			if (C < D)
			{
				C += B[i++];
			}
			else
			{
				D += X - B[j--];
			}
			if (max(C, D) > K)
				break;
		}
		if (max(C, D) <= K)
		{
			cout << X << endl;
			return;
		}

	}

	cout << 1 << endl;
}


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

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

main(){
  string S;
  cin >> S;
  if(S == "hi"){
    cout << "Yes";
  }else if(S == "hihi"){
    cout << "Yes";
  }else if(S == "hihihi"){
    cout << "Yes";
  }else if(S == "hihihihi"){
    cout << "Yes";
  }else if(S == "hihihihihi"){
    cout << "Yes";
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 256
n = int(input())
s = input()

r, b, g = 0, 0, 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    if s[i] == 'G':
        g += 1
    if s[i] == 'B':
        b += 1
ans = r * g * b

for i in range(n):
    for j in range(1, n // 2 + 1):
        if i + 2 * j >= n:
            break
        if s[i] != s[i+j] and s[i] != s[i+2*j] and s[i+j] != s[i+2*j]:
            ans -= 1

print(ans)

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < k; i++)
        ans += a[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//データ入力の準備
		Scanner sc = new Scanner(System.in);
		
		//データ数の配列
		int result[] = new int[26];
		for (int i = 0; i < 26; i++){
			result[i] = 0;
		}
		
		while (sc.hasNext() == true){
			
			//データを小文字に変換して入力
			String temp = sc.nextLine().toLowerCase();
			
			for (int i = 0; i < temp.length(); i++){
				//入力された文字のascllコード
				int ac = temp.charAt(i) - 97;
				if (ac < 0 || 26 <= ac){
					continue;
				}
				result[ac]++;
			}
		}
		
		//結果の出力
		char[] value = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		
		for (int i = 0; i < 26; i++){
			System.out.println(value[i] + " : " + result[i]);
		}
	}
}


Measured memory_bytes: 26240
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let a: i32 = sc.read();
        let op: String = sc.read();
        let op = op.as_bytes()[0] as char;
        let b: i32 = sc.read();
        let ans = match op {
            '+' => a + b,
            '-' => a - b,
            '*' => a * b,
            '/' => a / b,
            _ => break,
        };
        println!("{}", ans);
    }
}


Measured memory_bytes: 5040
program kadai
implicit none
integer  ::  N
integer,allocatable  ::  a(:),b(:)
integer  ::  i

read(*,*) n
allocate(a(n))
allocate(b(n))
read(*,*) a

do i=1,n
    b(i)=i
end do

call qsort(a,b)

write(*,*) b


stop
contains

subroutine swap(a,b)
implicit none
    integer,intent(inout)  ::  a,b
    integer  ::  c
    c=a
    a=b
    b=c
end subroutine swap

subroutine qsort(x,y)
implicit none
    integer, intent(inout)  ::  x(:),y(:)
    integer  ::  first,last
    first=1
    last=size(x)
    call q2sort(x,y,first,last)
    return
end subroutine qsort

recursive subroutine q2sort(x,y,first,last)
    implicit none
    integer, intent(inout)  ::  x(:),y(:)
    integer, intent(inout) ::  first,last
    integer  ::  fir, las
    integer  ::  i,j
    integer  ::  n
    n=x((first+last)/2)
    i=first
    j=last
    do
        do while (x(i)<n)
            i=i+1
        end do
        do while(x(j)>n)
            j=j-1
        end do
        if (i>j .or. i==j) then
            exit
        end if
        call swap(x(i),x(j))
        call swap(y(i),y(j))
        i=i+1
        j=j-1
    end do
    if (first<i-1) then
        las=i-1
        call q2sort(x,y,first,las)
    end if
    if (last>j+1) then
        fir=j+1
        call q2sort(x,y,fir,last)
    end if
end subroutine q2sort


end program kadai


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a[7],m;
    int right[25]={0,2,3,5,4,1,4,6,3,1,2,6,5,1,5,6,2,1,3,6,4,2,4,5,3};
    for(int i=1;i<7;i++)
    {
        cin>>a[i];
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int top,front;
        cin>>top>>front;
                top=int(find(a+1,a+7,top)-a);
                front=int(find(a+1,a+7,front)-a);
                int result=int(find(right+top*4-3,right+top*4,front)-right);
                if(result==top*4)
                    cout<<a[right[top*4-3]]<<endl;
                else
                    cout<<a[right[result+1]]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
  using namespace std;
 
int main(){
  int N;
  cin>>N;
  if(N<1200){
    cout<<"ABC"<<endl;
  }else if(N<2800){
    cout<<"ARC"<<endl;   
  }else{
   cout<<"AGC"<<endl;    
  }
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

MOD = 10**9 + 7

def factorial(a):
    return 1 if a == 1 else a * factorial(a - 1) % MOD

def inverse(x):
    return pow(x, MOD - 2, MOD)

def combination(a, b):
    ans = 1
    for i in range(b):
        ans = ans * (a - i) * inverse(i + 1) % MOD
    return ans

n, a, b = map(int, input().split())
ans = pow(2, n, MOD) - 1
ans -= combination(n, a) + combination(n, b)
print(ans % MOD)


Measured memory_bytes: 40300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
	string S;
	cin>>S;
	rep(i,S.size()){
		if(i==4)cout<<' ';
		cout<<S[i];
	}
	cout<<endl;
}


Measured memory_bytes: 256
//Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void sublime(){ 
	  #ifndef ONLINE_JUDGE 
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
      }
	
int main()
{   
  // sublime();
  
	  ll n,i,j,k;
	   cin>>n>>k;
	   ll arr[n+1];
	   for(i=1; i<=n; i++)
	   	cin>>arr[i];

	   ll dp[n+1];
	   memset(dp,0,sizeof(dp));
	   dp[1]=0;
	   dp[2]=abs(arr[1]-arr[2]);
	   for(i=3; i<=n; i++)
	   {
	   	 ll val=1e9;
	   	 for(j=1; j<=k; j++)
	   	 {
           if(i-j>0)
           {
           	 ll a= abs(arr[i]-arr[i-j])+dp[i-j];
           	 val=min(val,a);
           }
	   	 }
	   	 dp[i]+=val;
	   }
       cout<<dp[n]<<'\n';
	return 0;
}

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

long long int min(long long int *A,long long int N) {
  long long int count1 = A[0];
  for( int i=0; i<N; i++) {
    if (count1 > A[i])
      count1 = A[i];
  }
  return count1;
}

    

long long int max(long long int *A,long long int N) {
  long long int count2 = A[0];
   for( int i=0; i<N; i++) {
    if (count2 < A[i])
      count2 = A[i];
  }
  return count2;
}
  
  

long long int sum(long long int *A,long long int N) {
  long long int count3 = 0;
  for( int i=0; i<N; i++) {
    count3 += A[i];
  }
  return count3;
}
 
  


int main() {
  long long int N,A[10010];
  cin >> N;
  for (int i=0; i<N; i++)
    cin >> A[i];
  cout << min(A,N) << " " << max(A,N) << " " << sum(A,N) << endl;
}

Measured memory_bytes: 3112
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

N,Q=map(int,input().split())

T=[[] for i in range(N)]

for i in range(N-1):
    a,b=map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

O=[0 for i in range(N)]

for i in range(Q):
    p,x=map(int,input().split())
    O[p-1]+=x

def dfs(n):
    for i in T[n]:
        if r[i]:continue
        r[i]=1
        O[i]+=O[n]
        dfs(i)

r=[1]+[0]*(N-1)

dfs(0)

print(*O)
    


Measured memory_bytes: 232424
from itertools import combinations
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(input())
cnt = defaultdict(int)
for _ in range(N):
    s = input()
    cnt[s[0]] += 1

ans = 0
for h in combinations(['M', 'A', 'R', 'C', 'H'], r=3):
    prd = 1
    for s in h:
        prd *= cnt[s]
    ans += prd
print(ans)


Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys
# dp[j][t]=(y1,...,yj から 0 枚以上選んで yi の合計を t − 1250 にするような選び方の総数)

def solve(N: int, A: int, x: "List[int]"):
    x = [x[i]-A for i in range(N)]
    dp = [[0]*2500 for _ in range(N+1)]
    dp[0][1250] = 1

    for j in range(1,N+1):
        for t in range(2500):
            if t-x[j-1]>=0 and t-x[j-1]<2500:
                dp[j][t] = dp[j-1][t] + dp[j-1][t-x[j-1]]
            else:
                dp[j][t] = dp[j-1][t]
    print(dp[N][1250]-1)
    
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, x)

if __name__ == '__main__':
    main()


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

int main(){
  long long n, a[10000];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cout << *min_element( a, a + n) << " "
       << *max_element( a, a + n) << " "
       << accumulate( a, a + n, 0LL) << endl;
}



Measured memory_bytes: 3172
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    rep(i, N) cin >> V.at(i);
    rep(i, N) cin >> C.at(i);

    int sum = 0;
    rep(i, N) {
        if (V.at(i) - C.at(i) > 0) sum += V.at(i) - C.at(i);
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(int a, int b)
{
	return a < b;
	}
int main()
{
	int n, a[300];
	int sum = 0;
	scanf("%d", &n);
	for(int i = 0; i < 2 * n; i++)
	{
		scanf("%d", &a[i]);
		}
	sort(a, a + 2 * n, cmp);
	for(int i = 0; i < 2 * n ; i = i + 2)
	{
		sum = sum + a[i];
		}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
//nani?
//omo ta tori da
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ )
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
//#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
const ll inf=1e10;
const ll MOD=1e9+7;
const ll mod=998244353;
const ll N = 1e7 + 5;
// ac cmtr;
const int MAX_N = 2e5+5;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
//---------------------------

ll a[MAX_N];
ll b[MAX_N];
ll c[MAX_N];

bool cmp(ll a,ll b){
    return a>b;
}
int main(){
    fastio;
    ll x,y,a1,b1,c1;
    cin>>x>>y>>a1>>b1>>c1;
    f(i,0,a1) cin>>a[i];
    f(i,0,b1) cin>>b[i];
    f(i,0,c1) cin>>c[i];
    sort(a,a+a1,cmp);
    sort(b,b+b1,cmp);
    sort(c,c+c1,cmp);
    ll sum  =  0;
    vector <ll> v;
    vector <ll> g;
    f(i,0,x) v.pb(a[i]);
    f(i,0,y) v.pb(b[i]);
    f(i,0,c1) v.pb(c[i]);
    rsor(v);
    f(i,0,x+y){
        sum += v[i];
    }
    cout<<sum<<endl;

   
}

Measured memory_bytes: 9712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)

int main() {
    vel A(3);
    rep(i, 3) {
        cin >> A.at(i);
    }
    ll count5 = 0, count7 = 0;
    rep(i, 3) {
        if (A.at(i) == 5) {
            count5++;
        }
        else if (A.at(i) == 7) {
            count7++;
        }
    }
    if (count5 == 2 && count7 == 1) {
        cout << "YES" <<endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	
	long N; cin >> N;
	string foc; 
	long bsen = 0;
	long ago = 0;
    long basengo = 0;
	long ab = 0;
	long mylen;
	for (int i = 1; i <= N; i++) {
		cin >> foc;
		mylen = foc.length();
		if (foc[0] == 'B') bsen++;
		if (foc[mylen - 1] == 'A') ago++;
        if (foc[0] == 'B' && foc[mylen - 1] == 'A'){bsen--;ago--;basengo++;}
		for (int j = 0; j <= mylen - 2; j++) if (foc[j] == 'A' && foc[j + 1] == 'B') ab++;

	}

    //if (basengo >= 2) res++;
	while(basengo >= 2){res++;basengo--;} //たぶんここまではいい。ここでBAは0or1

    if(ago != 0 && basengo == 1) {res++;ago--;}
    if(bsen != 0 && basengo == 1) {res++; bsen--;}
    
    res += min(ago,bsen);
    res += ab;

	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
ll a[55];
int main()
{
	int i,j,k;
	int n;
	sd(n);
	int maxi=-1e9,maxpos=-1;
	for(i=1;i<=n;i++)
	{
		slld(a[i]);
		if(abs(a[i])>maxi)
		{
			maxi=abs(a[i]);
			maxpos=i;
		}
	}
	vector<pi>v;
	for(i=1;i<=n;i++)
	{
		if(a[maxpos]*a[i]<=0)
		{
			v.pb(mp(maxpos,i));
			a[i]+=a[maxpos];
		}
	}
	if(a[1]>=0)
	{
		for(i=1;i<=n;i++)
		{
			if(a[i]<a[i-1])
			{
				v.pb(mp(i-1,i));
				a[i]+=a[i-1];
			}
		}
	}
	else
	{
		for(i=n;i>=2;i--)
		{
			if(a[i-1]>a[i])
			{
				v.pb(mp(i,i-1));
				a[i-1]+=a[i];
			}
		}
	}
	int x=v.size();
	printf("%d\n",x );
	for(i=0;i<v.size();i++)
		printf("%d %d\n",v[i].first,v[i].second );
	return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int count = 0;
		TreeMap<String, ArrayList<Integer>> map = new TreeMap<>();

		for(int i = 0; i < n; i++) {
			int query = scan.nextInt();
			String key = scan.next();

			switch(query) {

			case 0:	//insert
				int value = scan.nextInt();
				if(!map.containsKey(key)) map.put(key, new ArrayList<Integer>());	//WARNING
				map.get(key).add(value);
				break;

			case 1:	//find
				if(map.get(key) != null)
					for(Integer x : map.get(key)) {
						System.out.println(x);
					}
					break;

			case 2:	//delete
				if(map.get(key) != null) {
					map.remove(key);
				}
				break;

			case 3:	//dump
				String tilKey = scan.next();
				Map<String, ArrayList<Integer>> subM = map.subMap(key,true, tilKey,true);
				for(String x : subM.keySet()){
					for(Integer x2 : subM.get(x)) {
						System.out.println(x + " " + x2);
					}
				}
				break;
			}
		}
	}
}


Measured memory_bytes: 202264