akhauriyash/Code-Regression huggingface dataset:
Public Class Compiler
    Shared Sub Main()
        Dim inputNM As String() = Console.ReadLine().Split(" ")
        Dim n As Integer = Integer.Parse(inputNM(0))
        Dim m As Integer = Integer.Parse(inputNM(1))
        Dim output As Integer = 0
        If n < m Then 
            Dim inputXs As String() = Console.ReadLine().Split(" ")
            Dim xs(0 To m - 1) As Integer
            For i As Integer = 0 To m - 1
                xs(i) = Integer.Parse(inputXs(i))
            Next
            Array.Sort(xs)
            Dim dists(0 To m - 2) As Integer
            For i As Integer = m - 2 To 0 Step -1
                dists(i) = xs(i + 1) - xs(i)
            Next
            Array.Sort(dists)
            Dim l As Integer = 0
            For i As Integer = m - 2 To (m - 2) - (n - 2) Step -1
                l += dists(i)
            Next
            output = xs(m - 1) - xs(0) - l
        End If
        Console.WriteLine(output)
    End Sub
End Class

Measured memory_bytes: 24984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  long cnt=0;
  for(int A=1;A<=1000000;A++){
    for(int B=A;B<=N/A;B++){
      if(A*B<N){
        if(A==B)cnt++;
        else cnt+=2;
      }
    }
  }
  cout<<cnt<<endl;
}


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

    class Sample35
    {

        static void Main()
        {
            int card = 0;

            //parse int and out of range about the length of string.
            try
            {
                card = int.Parse(Console.ReadLine());

                if ( card < 0 || 1000 < card)
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch(FormatException e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("カードの枚数は数字で入力してください。");
                Environment.Exit(0);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("カードの枚数が範囲外です。");
                Environment.Exit(0);
            }
            
            int tarosPoint = 0;
            int hanakosPoint = 0;
            int tarosHandsLength = 0;
            int hanakosHandsLength = 0;

            for (int i = 0; i < card; i++)
            {
                string[] words = Console.ReadLine().Split().ToArray();

                string tarosHands = words[0];
                string hanakosHands = words[1];

                tarosHandsLength = tarosHands.Length;
                hanakosHandsLength = hanakosHands.Length;

                //out of range about the length of words.
                try
                {
                    if (100 < tarosHandsLength || 100 < hanakosHandsLength)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Console.WriteLine(e.StackTrace);
                    Console.WriteLine("文字列の長さが範囲外です。");
                    Environment.Exit(0);
                }

                if (tarosHands == hanakosHands)
                {
                    tarosPoint++;
                    hanakosPoint++;
                    continue;
                }
                string original = tarosHands;

                Array.Sort(words);

                string edition = words[0];

                if (original == edition)
                {
                    hanakosPoint += 3;
                }
                else
                {
                    tarosPoint += 3;
                }
            }
            Console.WriteLine("{0} {1}", tarosPoint, hanakosPoint);
        }
    }   


Measured memory_bytes: 19172
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;


ll inf = numeric_limits<ll>::max() / 2;

struct Edge{
    ll to, cost;
};

struct Node{
    ll id, dist, pre;
    vector<Edge> edges{};
    explicit Node(ll id): id(id){}
};

ll BellmanFord(ll from, ll to, vector<Node> & graph){
    for (Node & node: graph){
        if (node.id == from){
            node.dist = 0;
        } else {
            node.dist = inf;
        }
        node.pre = -1;
    }
    for (auto && i: irange(0LL, (ll)graph.size())){
        for (Node & node: graph) {
            for (Edge & edge: node.edges){
                if (graph.at(edge.to).dist > node.dist + edge.cost){
                    graph.at(edge.to).dist = node.dist + edge.cost;
                    graph.at(edge.to).pre = node.id;
                }
            }
        }
    }
    ll ret_tmp = graph.at(to).dist;
    for (Node & node: graph) {
        for (Edge & edge: node.edges){
            if (graph.at(edge.to).dist > node.dist + edge.cost){
                graph.at(edge.to).dist = node.dist + edge.cost;
                graph.at(edge.to).pre = node.id;
            }
        }
    }
    if (ret_tmp == graph.at(to).dist){
        return graph.at(to).dist;
    } else {
        return inf;
    }
}


int main() {
    ll N, M;
    cin >> N >> M;
    vector<Node> graph{};
    for (auto && i: irange(0LL, N)){
        graph.emplace_back(Node(i));
    }
    for (auto && i: irange(0LL, M)) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        c = (-c);
        graph.at(a).edges.emplace_back(Edge{b, c});
    }
    ll min_cost = BellmanFord(0, N-1, graph);
    if (min_cost == inf){
        cout << "inf" << endl;
    } else {
        cout << -min_cost << endl;
    }

    return 0;
}

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

#define fastIO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MP make_pair
#define inf INT_MAX
#define minf INT_MIN

typedef long long int lli;

ofstream outfile;
ifstream infile;

int main()
{
	infile.open("input.txt");
	outfile.open("output.txt");

	fastIO;
	int i, n, t, t2;
	cin >> n;
	deque <int> mydeq;

	
	for(i = 1; i <= n; ++i)
	{
		cin >> t;
		if( i % 2)
		{
			mydeq.pf(t);
		}
		else
		{
			mydeq.pb(t);
		}
	}

	if( n % 2)
	{
		for(i = 0; i < mydeq.size(); ++i)
		{
			cout << mydeq[i] << ' ';
		}
	}
	else
	{
		for(i  = mydeq.size()-1; i >= 0; --i)
		{
			cout << mydeq[i] << ' ';
		}
	}

}	

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

int main() {
    int n;
    cin >> n;
    while (n > 10) {
        n %= 10;
    }
    string ans;
    switch(n) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            ans = "hon";
            break;
        
      	case 0:
        case 1:
        case 6:
        case 8:
            ans = "pon";
            break;
        
        case 3:
            ans = "bon";
            break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=100000000;
ll INF=10000000000000000;


int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i,n) cin >> v.at(i);
    int e=min(n,k);
    ll ans=0;
    for (int i=e;i>=0;i--){
        
        for (int l=0;l<i+1;l++){
            ll u=0;
        vector<ll> vv(i);
        rep(j,i-l) {
            vv.at(j)=v.at(j); 
        }
        rep(j,l){
            vv.at(i-l+j)=v.at(n-1-j);
        }
        sort(vv.begin(),vv.end());
        int w=k-i;
        for (int j=0;j<i;j++){
            //cout << vv.at(j) << " ";
            if (vv.at(j)<0 && w>0) {w--;continue;}
            u+=vv.at(j);
        }
        //cout << endl;
        ans=max(ans,u);
        
        }
        //cout << ans << endl;
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    Num_lis =[]
    n = int(input())
    if n == 0:
        break
    for i in range(n):
        Num_lis.append(list(map(int,input().split())))

    for j in range(n):
        sum_num = 0
        for k in range(n):
            sum_num += Num_lis[j][k]
        Num_lis[j].append(sum_num)

    Num_lis.append([])
    for l in range(n + 1):
        wa = 0
        for m in range(n):
            wa += Num_lis[m][l]
        Num_lis[n].append(wa)
    for o in range(n + 1):
        s_num = ""
        for p in range(n + 1):
            s_num = s_num + '{:>5}'.format(Num_lis[o][p])
        print(s_num)

Measured memory_bytes: 7512
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(n-2):
    if ((p[i+0] < p[i+1]) and (p[i+1] < p[i+2])) or ((p[i+0] > p[i+1]) and (p[i+1] > p[i+2])):
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long mon[100005];
int main(){
    int a;
    long long b;
    cin >> a >> b;
    for (int i = 0; i < a; ++i) {
        int aa, bb;
        cin >> aa >> bb;
        mon[aa] += bb; 
    }
    for (int i = 1; i <= 100005; ++i){
        if (b <= mon[i]) {
            cout << i << endl;
            break; 
        }
        b -= mon[i];
    }
}


Measured memory_bytes: 1024
#include <bitset>
#include <iostream>
#include <stdio.h>
#include <unordered_map>

#define MAX_N 100'000

using namespace std;

int main() {
  int N;
  cin >> N;
  unordered_map<int, int> M;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    ++M[a];
  }
  if (M.size() == 1 && M[0] == N) {
    printf("Yes\n");
  } else if (M.size() == 2 && N % 3 == 0 && M[0] == N / 3 && N - M[0] == 2 * (N / 3)) {
    printf("Yes\n");
  } else if (M.size() == 3 && N % 3 == 0) {
    bitset<MAX_N> B(0);
    for (auto &m : M) {
      if (m.second != N / 3) {
        printf("No\n");
        return 0;
      }
      bitset<MAX_N> _B(m.first);
      B ^= _B;
    }
    if (B.none()) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  } else {
    printf("No\n");
  }
}

Measured memory_bytes: 5900
#include <iostream>
using namespace std;
int main(){
int  a,b,c,k;
int re=0;//結果を代入する
int sum=0;
cin >>a >>b >>c >>k;
sum=a+b+c; //枚数の総和
  if(a>=k) re=k;
 else if(k==sum) re=a+(-1)*c;
else if(k<=a+b)re=a;
else {
    c=k-(a+b);
    re=a+(-1)*c;
}    
 
cout <<re <<endl;
return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    ll a,b,c;
    cin >>a >>b >>c;

    ll ans=0;
    if(a%2==1 && b%2==1 && c%2==1) ans=min({a*b,b*c,c*a});

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


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

typedef struct{
  char name[10];
  int time;
} data;

void A(data *);
int main(){
  int n,q,i,head,tail,j=0,all=0,timel[100000];
  data queue[200000],output[100000];
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",queue[i].name,&queue[i].time);
  }

  head=0;
  tail=n-1;
  while(head!=tail){
      queue[head].time-=q;
      if(queue[head].time<=0){
        output[j]=queue[head];
        all=all+q+queue[head].time;
        timel[j]=all;
        j++;
      }
      else {
        tail++;
        queue[tail]=queue[head];
        all+=q;
      }
      head++;
    }
    output[j]=queue[head];
    all=all+queue[head].time;
    timel[j]=all;

    for(i=0;i<=j;i++){
      printf("%s %d\n",output[i].name,timel[i]);
    }
  }



Measured memory_bytes: 5272
//提出 #4996265を参考
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	ll ans = 1;
	int n;
	string s;
	cin >> n >> s;
	ll cnt[26] = {};
	REP(i, n){
		cnt[s[i] - 'a']++;
	}

	REP(i, 26) ans = (ans * (cnt[i] + 1)) % MOD;

	cout << (ans - 1) % MOD << endl;

}


Measured memory_bytes: 512
function Main(input) {
    var input = input.split('\n');
  	var jewel = parseInt(input[0], 10);
  	var prices = input[1].split(' ').map(Number);
  	var costs = input[2].split(' ').map(Number);
  	var profit = 0;
  	var maxPro = 0;
  
  	for(var i = 0; i < jewel; i++) {
      profit = prices[i] - costs[i];
      if(profit > 0) {
        maxPro = maxPro + profit;
      }
    }
 
  console.log(maxPro);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    ld a,b;cin>>a>>b;
    cout<<fixed<<setprecision(0)<<floor(a*b);
}

Measured memory_bytes: 3828
import scala.io.StdIn.{readLine, readInt}

object Main extends App {
  import MergeSort.mergeSort

  readInt()
  val xs  = readLine().split(' ').map { _.toLong }
  val ans = mergeSort(xs)
  println(ans)
}

object MergeSort {
  val Max: Int      = 200000
  val Sentinel: Int = 2000000000

  def mergeSort(xs: Array[Long]): Long = {

    val ls = new Array[Long](Max / 2 + 2)
    val rs = new Array[Long](Max / 2 + 2)

    def run(left: Int, right: Int): Long = {
      val m = right - left
      if (m <= 1) 0
      else {
        val mid  = (left + right) / 2
        val cnt1 = run(left, mid)
        val cnt2 = run(mid, right)
        val cnt3 = merge(left, mid, right)
        cnt1 + cnt2 + cnt3
      }
    }

    def merge(left: Int, mid: Int, right: Int): Long = {
      val n1   = mid - left
      val n2   = right - mid
      Array.copy(xs, left, ls, 0, n1)
      Array.copy(xs, mid, rs, 0, n2)
      ls(n1) = Sentinel
      rs(n2) = Sentinel
      var i, j = 0
      var cnt  = 0L
      var k    = left
      while (k < right) {
        if (ls(i) <= rs(j)) {
          xs(k) = ls(i)
          i += 1
        } else {
          xs(k) = rs(j)
          j += 1
          cnt += n1 - i
        }
        k += 1
      }

      cnt
    }

    run(0, xs.length)
  }
}



Measured memory_bytes: 79664
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
void CountingSort(unsigned short *,unsigned short *,int);

int n;

int main(){
  unsigned short *A, *B;
  int i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
  }
  CountingSort(A,B,VMAX);

  free(A);
  free(B);

  return 0;
}
void CountingSort(unsigned short *A,unsigned short *B,int k){
  int i,j;
  int C[VMAX+1];
  for(i=0;i<=k;i++){
    C[i] = 0;
  }
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i] = C[i]+C[i-1];
  }
  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
}
  



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

int main(){
    int N;
    cin >> N;
    if(N>=64)cout << 64 << endl;
    else if(N>=32)cout << 32 << endl;
    else if(N>=16)cout << 16 << endl;
    else if(N>=8)cout << 8 << endl;
    else if(N>=4)cout << 4 << endl;
    else if(N>=2)cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
}

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

#define INF 999999999

using namespace std;

// input
string s1, s2, s3;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> s1 >> s2 >> s3;
    transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
    transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
    transform(s3.begin(), s3.end(), s3.begin(), ::toupper);

    cout << s1[0] << s2[0] << s3[0] << "\n";
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX


int n,d,ans;
double x[10][10];

signed main() {
    cin >> n >> d;
    rep(i,n) rep(j,d) cin >> x[i][j];
    rep(i,n) repo(j,i+1,n) {
        double sum=0;
        rep(k,d) sum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        sum = sqrt(sum);
        if (sum == (int)sum) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
a, b = gets.split(" ").map(&:to_i)

c = (a * 100 / 8.0).ceil
d = (b * 100 / 10.0).ceil

n = [c, d].max
ans = -1

while (n * 0.08).floor == a || (n * 0.1).floor == b
  ans = n if (n * 0.08).floor == a && (n * 0.1).floor == b
  n -= 1
end

puts ans


Measured memory_bytes: 1788
/*   You have lost, my dear   */

#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define mod 1000000007
using namespace std;
int n;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    int sol=0;
    for(int i=1;i<=n;++i)
    {
        int nr;
        cin>>nr;
        while(nr%2==0)
            ++sol,nr/=2;
    }
    cout<<sol;
    return 0;
}


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

using namespace std;
using ll=long long ;

void solve() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x; x--;
    }
    vector<int> c(3*m);
    vector<int> d(3*m);
    ll base = 0;
    for (int i = 1; i < n; i++) {
        int x = a[i-1], y = a[i];
        if (x > y) y += m;
        base += y-x;
        if (y-x <= 1) continue;
        c[x+1]++; c[y]--; d[y] += y-x-1;
        c[x+1+m]++; c[y+m]--; d[y+m] += y-x-1;
    }
    int cnt = 0;
    ll v = base;
    ll res = base;
    for (int i = 0; i < 2*m; i++) {
        v -= cnt;
        res = min(res, v);
        cnt += c[i];
        v += d[i];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	set<string> w;
	string x;
	for (int i = 0; i < n; i++) {
		string y;
		cin >> y;
		if (i&&y[0] != x.back())
			goto pnz;
		if (!w.insert(y).second)
			goto pnz;
		x = y;
	}
	cout << "Yes" << endl;
	return 0;
pnz:
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int r[200];
int s[200];
long long dp[200][200][2];
int v[200][200][2];
int n;
long long INF=99999999999999LL;
int sum;
long long solve(int a,int b,int c){
	if(v[a][b][c])return dp[a][b][c];
	v[a][b][c]=1;
	if(a==n){
		if(b==0){
			if(c==0)dp[a][b][c]=-INF;
			else dp[a][b][c]=INF;
		}else{
			if(c==0)dp[a][b][c]=INF;
			else dp[a][b][c]=-INF;
		}
	//	printf("%d %d %d: %lld\n",a,b,c,dp[a][b][c]);
		return dp[a][b][c];
	}
	if(c==0)dp[a][b][c]=INF;
	else dp[a][b][c]=-INF;
	if(b-s[a]*(1-c)>=0){
		//long long t=solve(a+1,b-s[a]*(1-c),!c);
		if(c==0){
			long long t=-INF;
		//	printf("%d\n",b-s[a]);
			for(int i=0;i<b-s[a];i++){
				//if(i>sum)printf("ng\n");
				t=max(t,solve(a+1,i,1)+1);
			}
			dp[a][b][c]=min(dp[a][b][c],t-r[a]);
		}else{
			long long t=INF;
			for(int i=b+1;i<=sum;i++)t=min(t,solve(a+1,i,0)-1);
			dp[a][b][c]=max(dp[a][b][c],t+r[a]);
		}
	}
	if(b-s[a]*c>=0){
		long long t=solve(a+1,b-s[a]*c,c);
		if(c==0){
			t=max(t+r[a],0LL);
			dp[a][b][c]=min(dp[a][b][c],t+1);
		}else{
			t=min(t-r[a],0LL);
			dp[a][b][c]=max(dp[a][b][c],t-1);
		}
	}
//	printf("%d %d %d: %lld\n",a,b,c,dp[a][b][c]);
	return dp[a][b][c];
}
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	n=a;
	for(int i=0;i<a;i++)scanf("%d%d",r+i,s+i);
	sum=0;
	for(int i=0;i<a;i++)sum+=s[i];
	for(int i=sum;i>=0;i--){
		if(b-c>=solve(0,i,0)){
			printf("%d %d\n",i,sum-i);return 0;
		}
	}
	
}

Measured memory_bytes: 1756
N = int(input())
S = input()
R = []
G = []
B = []
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    elif S[i] == 'B':
        B.append(i)
ans = len(R)*len(G)*len(B)
for i in range(1,(N+1)//2):
    for j in range(i,N-i):
        if S[j] != S[j-i] and S[j] != S[j+i] and S[j-i] != S[j+i]:
            ans -= 1
print(ans)

Measured memory_bytes: 9216
#include<iostream>
using namespace std;
int main(){
  int n;
  int h[105];
  
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>h[i];
  }
  h[0]=0;
  
  int ans=0;
  for(int i=1;i<=n;i++){
    if(h[i]>h[i-1])ans+=h[i]-h[i-1];
  }
  cout<<ans<<"\n";
  return 0;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int N;
  cin >> N;
  int a[N];
  rep(i,N){
    cin >> a[i];
  }
  sort(a,a+N);
  ll sum = 0;
  rep(i,N-1) sum += a[i];
  if(sum > a[N-1] ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(s,e) for(ll i=s;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = 100000000000009;
ll i;

int main(){
    ll N,M;
    cin>>N>>M;
    cout<<N*(N-1)/2+M*(M-1)/2<<endl;
}

Measured memory_bytes: 256
module ABC139

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_B

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_B

    ! variables for this <subroutine>
    integer(INT32) :: num_strip_needed
    integer(INT32) :: num_socket_strip
    integer(INT32) :: num_socket_needed
    integer(INT32) :: num_socket_total

    ! support variables for this <subroutine>
    integer(INT32) :: itr

    ! STEP.01
    ! read out the given data
    read(unit=INPUT_UNIT, fmt=*) num_socket_strip, num_socket_needed

    ! STEP.02
    ! initialize the variables for this <subroutine>
    num_strip_needed = 0_INT32
    num_socket_total = 1_INT32

    ! STEP.03
    ! calculate the answer of this task
    do while (num_socket_total .lt. num_socket_needed)
      num_strip_needed = num_strip_needed + 1_INT32
      num_socket_total = num_socket_total + num_socket_strip - 1_INT32
    end do

    ! STEP.03
    ! output the answer of this task
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') num_strip_needed

    ! STEP.END
    return

  end subroutine task_B

end module ABC139

program main

  ! <module>s to import
  use, non_intrinsic :: ABC139

  ! require all variables to be explicitly declared
  implicit none

  call task_B

end program main

Measured memory_bytes: 768
n, t = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]

mn = 10**10
for i in range(n):
    if lst[i][1] <= t and mn > lst[i][0]:
        mn = min(mn, lst[i][0])

if mn == 10 ** 10:
    print("TLE")
else:
    print(mn)

Measured memory_bytes: 3060
/*
 * 	Roses are red
 * 		Violets are blue
 * 			I cried
 * 				And so did you
*/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
//typedef double f80;
#define double long double
#define pii pair<int,int>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
#define deb cout<<"Line: "<<__LINE__<<" plz "
typedef long long ll;
const ll inf=1e18;
const ll mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powm(ll a, ll b, ll m);

int a[200001];
int lol[200001],lol2[200001];
void solve()
{
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	stack<int> lolo;
	for(int i=0; i<400000; i++)
		lolo.push(n+1);
	for(int i=n; i>1; i--)
	{
		int te=a[i],te1=a[i-1];
		int ct=0;
		while(te<te1)
		{
			te*=4;
			ct++;
		}
		while(te>=4*te1)
		{
			te/=4;
			ct--;
		}
		if(ct<0)
		{
			for(int j=0; j<(-ct); j++)
				lolo.push(i);
		}
		else
		{
			for(int j=0; j<ct; j++)
			{
				lol[i]+=lolo.top()-i;
				lolo.pop();
			}
		}
		lol[i]+=lol[i+1];
	}
	while(lolo.size())
		lolo.pop();
	for(int i=0; i<400000; i++)
		lolo.push(n+1);
	reverse(a+1,a+n+1);
	for(int i=n; i>1; i--)
		{
			int te=a[i],te1=a[i-1];
			int ct=0;
			while(te<te1)
			{
				te*=4;
				ct++;
			}
			while(te>=4*te1)
			{
				te/=4;
				ct--;
			}
			if(ct<0)
			{
				for(int j=0; j<(-ct); j++)
					lolo.push(i);
			}
			else
			{
				for(int j=0; j<ct; j++)
				{
					lol2[i]+=lolo.top()-i;
					lolo.pop();
				}
			}
			lol2[i]+=lol2[i+1];
		}
	int ans=inf;
	for(int i=1; i<=n; i++)
	{
		lol[i]<<=1;
		lol2[i]<<=1;
	}
	for(int i=1; i<=n; i++)
		lol[i]=lol[i+1],lol2[i]=lol2[i+1];
//	for(int i=1; i<=n; i++)
//		cout<<lol[i]<<" ";
//	cout<<endl;
	reverse(lol2+1,lol2+n+1);
//	for(int i=1; i<=n; i++)
//		cout<<lol2[i]<<" ";
//	cout<<endl;
	for(int i=1; i<=n; i++)
	{
		ans=min(ans,i-1+lol2[i-1]+lol[i]);
	}
	cout<<ans<<endl;
}
signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
	auto clk=clock();
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	clk=clock()-clk;
	cout<<endl<<endl<< "Time Elapsed: " << ((double)clk)/CLOCKS_PER_SEC <<endl;
#endif
	return 0;
}
ll powm(ll a,ll b, ll m) {
	ll te=1;
	while(b) {
		if(b&1) te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


Measured memory_bytes: 8176
import collections
N,K = map(int,input().split())
a = list(map(int,input().split()))
b = a.copy()
b = list(set(b))

a = collections.Counter(a)
a = sorted(a.values())
ans = 0
for i in range(len(b)-K):
    ans += a[i]
print(ans)

Measured memory_bytes: 40500
#include <iostream>

using namespace std;

int main() {

	int m, d;

	while(cin >> m >> d) {
		if(m==0&&d==0)
			break;

		switch(m) {
			case 1:
				d+=0;
				break;
			case 2:
				d+=31;
				break;
			case 3:
				d+=60;
				break;
			case 4:
				d+=91;
				break;
			case 5:
				d+=121;
				break;
			case 6:
				d+=152;
				break;
			case 7:
				d+=182;
				break;
			case 8:
				d+=213;
				break;
			case 9:
				d+=244;
				break;
			case 10:
				d+=274;
				break;
			case 11:
				d+=305;
				break;
			case 12:
				d+=335;
		}
 
		d%=7;
		switch(d) {
			case 0:
				cout << "Wednesday" << endl;
				break;
			case 1:
				cout << "Thursday" << endl;
				break;
			case 2:
				cout << "Friday" << endl;
				break;
			case 3:
				cout << "Saturday" << endl;
				break;
			case 4:
				cout << "Sunday" << endl;
				break;
			case 5:
				cout << "Monday" << endl;
				break;
			case 6:
				cout << "Tuesday" << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 0
/*
 * atcoder/abc131_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N;
vector<pair<ll, ll> > A;
void solve() {
  cin >> N;
  A.resize(N);
  loop(n,0,N) cin >> A[n].second >> A[n].first;
  sort(A.begin(), A.end());

  ll t = 0;
  loop(n,0,N) {
    t += A[n].second;
    if (t > A[n].first) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
    
bool isOutOfRange(int i,int j,int w,int h){

    if(i<0 || i>=h)return true;
    if(j<0 || j>=w)return true;
    return false;
}

int main(){
    int flag=1;
    int tflag=0;
    int h,w;
    string s[h];

    cin >>h>>w;
    for (int i = 0; i < h; i++){
        cin >>s[i];
    }
    
    
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            tflag=0;

            if(s[i][j]=='.'){
                continue;
            }else{

                if(isOutOfRange(i-1,j,w,h)==false){
                    if(s[i-1][j]=='.')tflag++;
                }else{
                    tflag++;
                }
                
                if(isOutOfRange(i,j-1,w,h)==false){
                    if(s[i][j-1]=='.')tflag++;
                }else{
                    tflag++;
                }
                
                if(isOutOfRange(i,j+1,w,h)==false){
                    if(s[i][j+1]=='.')tflag++;
                }else{
                    tflag++;
                }
                
                if(isOutOfRange(i+1,j,w,h)==false){
                    if(s[i+1][j]=='.')tflag++;
                }else{
                    tflag++;
                }
                
            }
            if(tflag==4)flag=0;
        }
    }
    //cout << ans <<endl;
    //cout <<fixed<<setprecision(16)<< ans <<endl;

    if(flag==1)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 49408
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 12 13:14:59 2018
ABC047B
@author: maezawa
"""
w, h, n = list(map(int, input().split()))
xl = 0
xu = w
yl = 0
yu = h

for i in range(n):
    xi, yi, ai = list(map(int, input().split()))
    if ai == 1:
        if xl < xi:
            xl = xi
    elif ai == 2:
        if xu > xi:
            xu = xi
    elif ai == 3:
        if yl < yi:
            yl = yi
    else:
        if yu > yi:
            yu = yi
if xl<=xu and yl<=yu:
    ans = (xu-xl)*(yu-yl)
else:
    ans = 0
print(ans)


Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 510
using namespace std;
int read(){
	int nm=0,fh=1; int cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
char ch[M][M]; int n,m;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),m=read();
	for(int i=1;i<=n;i++) scanf("%s",ch[i]+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(ch[i][j]=='#') putchar('#');
			else if(i==1||(i<n&&(j&1))) putchar('#');
			else putchar('.');
		} putchar('\n');
	} putchar('\n');
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(ch[i][j]=='#') putchar('#');
			else if(i==n||(i>1&&!(j&1))) putchar('#');
			else putchar('.');
		} putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,m;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	if(n%2==1)
	{
		for(int i=1;i<=m;i++)
			cout<<i<<' '<<n-i+1<<endl;
		return 0;
	}
	else
	{
		int l=1,r=n;
		bool flag=false;
		while(m)
		{
			cout<<l<<' '<<r<<endl;
			m--;
			l++;
			r--;
			if(r-l<=n-(r-l)&&!flag) r--,flag=true;
		}
	}
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s,t;
    cin >> s >> t;

    map<string,int> mp;
    
    int a, b;
    cin >> a >> b;

    mp[s] = a;
    mp[t] = b;

    string u;
    cin >> u;

    mp[u]--;

    cout << mp[s] << ' ' << mp[t] << endl;

}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n : i64,
    }
    let mut ans = 1;
    for i in 2..100000 {
        if i*i > n {
            break;
        }
        else {
            ans = i * i;
        }
    }
    println!("{:?}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;

	vector<map<ll, ll>> e(N);
	vector<map<ll,bool>> flg(N);
	
	rep(i, 0, N-1) {
		ll a, b;
		std::cin >> a >> b;
		a--; b--;

		e[a][b] = i;
		e[b][a] = i;
	}

	stack<ll> st;
	st.push(0);
	vll col(N - 1,-1);

	ll cnt = 0;
	while (!st.empty()) {
		ll cur = st.top();
		st.pop();
		ll tmp = 1;
		for (auto itr = e[cur].begin(); itr != e[cur].end(); itr++) {
			if (col[itr->second] < 0) {
				while (flg[cur][tmp]) {
					tmp++;
				}
				col[itr->second] = tmp;
				flg[cur][tmp] = true;
				flg[itr->first][tmp] = true;
				st.push(itr->first);
			}
		}
		cnt = max(cnt, tmp);
	}

	std::cout << cnt << endl;
	rep(i, 0, N - 1) {
		std::cout << col[i] << endl;
	}

	return 0;
}


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

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr;
            while(true)
            {
                arr = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(e => e).ToArray();
                if (arr[0] == 0 && arr[1] == 0) break;

                Console.WriteLine($"{arr[0]} {arr[1]}");
            }
        }
    }
}



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

    static int N;
    static int a[100000];
    static int b[100000];

// index が条件を満たすかどうか
bool isOK(int mid) {
    b[0] = mid;
    for(int i=1;i<N;i++){
        b[i] = (a[i-1] - b[i-1]/2) *2;
    }


    if (b[0]/2+b[N-1]/2 >= a[N-1]) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int left, int right) {

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = (left + (right - left) / 2);

        if (isOK(mid)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}


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

    int ans = binary_search(0, min(a[0],a[N-1])*2);

    b[0] = ans;
    for(int i=1;i<N;i++){
        b[i] = (a[i-1] - b[i-1]/2) *2;
    }
    if (b[0]/2+b[N-1]/2 == a[N-1]){            
        for(int i=0;i<N;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
        return 0;
    }

    b[0] = ans-1;
    for(int i=1;i<N;i++){
        b[i] = (a[i-1] - b[i-1]/2) *2;
    }
    if (b[0]/2+b[N-1]/2 == a[N-1]){            
        for(int i=0;i<N;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
        return 0;
    }

    b[0] = ans+1;
    for(int i=1;i<N;i++){
        b[i] = (a[i-1] - b[i-1]/2) *2;
    }
    if (b[0]/2+b[N-1]/2 == a[N-1]){            
        for(int i=0;i<N;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
        return 0;
    }

}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);
using ll = long long;
using namespace std;
using ld = long double;
typedef pair<int,int> ii;
const int MAXN = 2*1e5 + 5;
vector<vector<int>> g;
int d[MAXN];
bitset<MAXN> f;
int trace[MAXN];

void bfs()
{
    f.reset();
    queue<int> qu;
    qu.push(0);
    while(!qu.empty())
    {
        int u=qu.front();
        qu.pop();
        if (f[u]==1) continue;
        f[u]=1;
        for(auto it:g[u])
        {
            if (f[it]==0)
            d[it]+=d[u];
            qu.push(it);
        }
    }
}


int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    int n;
    int q;
    cin >> n;
    cin >> q;
    g= vector<vector<int>> (n);
    for(int i=0; i<n-1; i++)
    {
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    while(q--)
    {
        int u,z;
        cin >> u >> z;
        u--;
        d[u]+=z;
    }
    bfs();
    for(int i=0; i<n ; ++i)
        cout << d[i] << " ";
    return 0;
}



Measured memory_bytes: 15604
h,w,k = map(int,input().split())
k -= 1
dp = [[0]*w for _ in range(h+1)]
dp[0][0] = 1
mod = 10**9 + 7
def cnt(n):
    if n < 0:
        return 1
    if 0 <= n < 3:
        return n + 1
    return n + (n-1)*(n-2)//2 + (n-2)*(n-3)*(n-4)//6 + 1

for i in range(h):
    for j in range(w):
        if j > 0:
            dp[i+1][j-1] += dp[i][j] * cnt(j-2) * cnt(w-2-j)
            dp[i+1][j-1] %= mod
        if j < w-1:
            dp[i+1][j+1] += dp[i][j] * cnt(j-1) * cnt(w-3-j)
            dp[i+1][j+1] %= mod
        dp[i+1][j] += dp[i][j] * cnt(j-1) * cnt(w-2-j)
        dp[i+1][j] %= mod
print(dp[h][k])


Measured memory_bytes: 3064
count, amount =  gets.strip.split.map(&:to_i)
a, b, c = -1, -1, -1

(0..count).each do |i|
  (0..count-i).each do |j|
    if i * 10000 + j * 5000 + (count - i - j) * 1000 == amount
      a, b, c = i, j, count - i -j
    end
  end
end

puts "#{a} #{b} #{c}"


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  if (s.size() >= 4) {
    if (s.substr(0, 4) == "YAKI") {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
import itertools

n, k = map(int, input().split())
xy = [tuple(map(int, input().split())) for i in range(n)]
ans = float("INF")
for a, b in itertools.combinations(xy, 2):
    for c, d in itertools.combinations(xy, 2):
        x1, x2 = a[0], b[0]
        y1, y2 = c[1], d[1]
        count = 0
        for x, y in xy:
            if min(x1, x2) <= x <= max(x1, x2) and min(y1, y2) <= y <= max(y1, y2):
                count += 1
        if count >= k:
            ans = min(ans, abs(x1 - x2) * abs(y1 - y2))
print(ans)

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    string s, t;
    cin >> s >> t;
    Int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s == u) {
        a--;
    }
    else {
        b--;
    }
    cout << a <<  " " << b << endl;
    return 0;
}


Measured memory_bytes: 256
// AOJ 0613 Treasures
// 2018.3.21 bal4u

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

#define INF 0x5555555555555555LL
long long seg[33554432]; int sz;

void segtree(int n)
{
	int k;
	k = 1; while (k < n) k <<= 1;
	sz = k;
	memset(seg, (int)INF, sizeof(seg));
}

// update kth value to v
void update(int k, long long v)
{
	int t;
	k += sz - 1;
	seg[k] = v;
	while (k > 0) {
		if (!(k & 1)) k--;
		t = k, k >>= 1;
		v = seg[t++]; if (v > seg[t]) v = seg[t];
		seg[k] = v;
	}
}

long long _query(int a, int b, int k, int l, int r)
{
	int m;
	long long lmin, rmin;
	if (r <= a || b <= l) return INF;
	if (a <= l && r <= b) return seg[k];
	k <<= 1, m = (l + r) >> 1;
	lmin = _query(a, b, ++k, l, m);
	rmin = _query(a, b, ++k, m, r);
	if (lmin > rmin) lmin = rmin;
	return lmin;
}

// get min in [a, b)
long long query(int a, int b)
{
	return _query(a, b, 0, 0, sz);
}


// セグメントツリー
#define MAX 14350000
typedef struct { long long x, y; } T;
T t[MAX], s[MAX]; int tsz, ssz;
T data[32]; int N;
long long D;

// バイナリサーチ
int bsch_lower(long long x)
{
	int m, l = 0, r = ssz;
	while (l < r) {
		m = (l + r) >> 1;
		if (s[m].x <= x) l = m + 1; else r = m;
	}
	return l-1;
}
int bsch_upper(long long x)
{
	int m, l = 0, r = ssz;
	while (l < r) {
		m = (l + r) >> 1;
		if (s[m].x < x) l = m + 1; else r = m;
	}
	return l;
}

int span(T *d, int n, T *s)
{
	int i, j, k, sz;
	long long x, y;

	if (n <= 0) return 0;
	x = s[0].x, y = s[0].y, sz = 0;
	d[0].x = d[0].y = 0; d[1].x = x, d[1].y = -y; d[2].x = -x, d[2].y = y;
	sz = k = 3;
	for (i = 1; i < n; i++) {
		x = s[i].x, y = s[i].y;
		for (j = 0; j < k; j++) {
			d[sz].x = d[j].x + x, d[sz++].y = d[j].y - y;
			d[sz].x = d[j].x - x, d[sz++].y = d[j].y + y;
		}
		k = sz;
	}
	return sz;
}

int cmp(const void *a, const void *b) {
	long long t = ((T *)a)->x - ((T *)b)->x;
	if (t < 0) return -1;
	if (t > 0) return 1;
	return 0;
}

int main()
{
	int i, k, l, r;
	long long ans, a;

	scanf("%d%lld", &N, &D);
	for (i = 0; i < N; i++) scanf("%lld%lld", &data[i].x, &data[i].y);
	k = N >> 1;
	tsz = span(t, k, data);
	qsort(t, tsz, sizeof(T), cmp);
	ssz = span(s, N-k, data + k);
	qsort(s, ssz, sizeof(T), cmp);
	s[ssz].x = INF;

	segtree(ssz);
	for (i = 0; i < ssz; i++) update(i, -s[i].y);

	ans = -INF;
	l = bsch_upper(-D - t[0].x); if (l < 0) l = 0;
	r = bsch_lower(D - t[0].x);

	for (i = 0; i < tsz; i++) {
		while (s[l].x > -D - t[i].x) l--;
		while (s[l].x < -D - t[i].x) l++;
		while (r >= l && s[r].x > D - t[i].x) r--;
		if (r < l) continue;
		a = -query(l, r + 1) + t[i].y;
		if (a > ans) ans = a;
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 712328
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.close();

        long min = (long)A * (N-1) + B;
        long max = (long)B * (N-1) + A;
        long ans = max - min + 1;

        System.out.println(Math.max(0, ans));

    }
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

int main() {
  int N; cin >> N;
  int P[N]; rep(i,N) { cin >> P[i]; P[i]--; }
  int pos[N]; rep(i,N) pos[(N-1)-P[i]] = i;
  multiset<int> gr;
  gr.insert(-1); gr.insert(-1);
  gr.insert(N); gr.insert(N);
  ll result = 0;
  rep(i,N) {
    auto r1 = gr.upper_bound(pos[i]);
    auto r2 = r1; r2++;
    auto l1 = r1; l1--;
    auto l2 = l1; l2--;
    ll tmp = (pos[i]-*l1)*(*r2-*r1) + (*r1-pos[i])*(*l1-*l2);
    result += tmp * (N-i);
    // cout << *l2 << " " << *l1 << " " << *r1 << " " << *r2 << endl;
    // cout << N-i << ":" << tmp << endl;
    gr.insert(pos[i]);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 5760
#include <cstring>
#include <iostream>
#include <cstdio>
#include <cmath>
const int INF=100005;
using namespace std;
int cnt[INF];
bool isprime(int n){
	if(n==1)return false;
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return true;
}
void solve(){
	for(int i=3;i<INF;i++){
		if(isprime(i)&&isprime((i+1)/2)){
			cnt[i]++;
		}
	}
	for(int i=1;i<INF;i++){
		cnt[i]+=cnt[i-1];
	}
} 
int main()
{
	int t;
	solve();
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		printf("%d\n",cnt[r]-cnt[l-1]);
	}
	return 0;
}

Measured memory_bytes: 1024
time=[]
for i in range(5):
  time.append(int(input()))

num=[]
min=10
  
for list in time:
  if list%10==0:
    num.append(list)
  else:
    num.append(list+(10-list%10))
    if min>list%10:
      min=list%10

print(sum(num)-(10-min))
  
  



Measured memory_bytes: 2940