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

int main () 
{
    int a, b;
    string op;
    
    while (1)
    {
        cin >> a >> op >> b;
        
        if (op == "?")
        {
            break;
        }
        
        int ans;
        
        if (op == "+")
        {
            ans = a + b;
        }
        else if (op == "-")
        {
            ans = a - b;
        }
        else if (op == "*")
        {
            ans = a * b;
        }
        else if (op == "/")
        {
            ans = a / b;
        }
        
        std::cout << ans << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3136
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<int> A;
vector<int> L;
vector<int> R;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

// based on pdf
// https://img.atcoder.jp/abc125/editorial.pdf
int main(void) {
    int N;
    cin >> N;

    A.resize(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    L.resize(N + 1, 0);
    L[1] = A[1];
    for (int i = 2; i <= N; i++) {
        L[i] = gcd(max(L[i - 1], A[i]), min(L[i - 1], A[i]));
    }

    R.resize(N + 1, 0);
    R[1] = A[N];
    for (int i = 2; i <= N; i++) {
        R[i] = gcd(max(R[i - 1], A[N - i + 1]), min(R[i - 1], A[N - i + 1]));
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        chmax(ans, gcd(max(L[i - 1], R[N - i]), min(L[i - 1], R[N - i])));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a,b;
  cin >> a>>b;
 
  if (b<a) {
  cout << a-b << endl; 
  }
  
  else {
  cout << 0 << endl;
  }
  
}



Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

#define STEPS_BUF_LEN 128

int main(void) {
    char steps[STEPS_BUF_LEN];
    int len;
    bool is_easy_steps;

    fgets(steps, STEPS_BUF_LEN, stdin);
    len = strlen(steps);
    if (steps[len-1] == '\n') {
        steps[len-1] = '\0';
        len--;
    }

    is_easy_steps = true;
    for (int h = 0; h < len; h++) {
        char step = steps[h];
        int i = h+1;
        if (i % 2 == 0) {
            // L or U or D
            if (step != 'L' && step != 'U' && step != 'D') {
                is_easy_steps = false;
                break;
            }
        } else {
            // R or U or D
            if (step != 'R' && step != 'U' && step != 'D') {
                is_easy_steps = false;
                break;
            }
        }
    }

    if (is_easy_steps) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define pb              push_back
#define fastread()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
    fastread();
    ll n,h;
    cin>>n;
    ll ans = 0;
    for(int i=1; i<=n; i++){
        h = n/i;
        ans += i*(1+h)*h/2;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3656
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double W = sc.nextInt();
        double H = sc.nextInt();
        double x = sc.nextInt();
        double y = sc.nextInt();
        double S = W*H/2;
      
      if(W==x*2&&H==y*2){System.out.print(S+" "+1);}
      else{System.out.print(S+" "+0);}
 
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);  
	return s + n;  
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else 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;
}

//だから私は～
//#define int long long
// ===============================================================

/*signed*/int main() {
	ll a, b, t;
	cin >> a >> b >> t;
	ll x = t / a;
	cout << x * b << endl;
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <map>

using namespace std;



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

    int a,b;
    cin>>a>>b;

    if((a*b)%2==0){
        printf("Even");
    }else{
        printf("Odd");
    }

    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int n,ed,B,root,g[N],f[N],q[N],deg[N];
struct E{int v,nxt;}e[N<<1];
inline void adde(int x,int y){e[++ed].v=y;e[ed].nxt=g[x];g[x]=ed;}
int dfs(int x,int y){
	int i;f[x]=0;
	for(i=g[x];i;i=e[i].nxt)if(e[i].v!=y&&!dfs(e[i].v,x))return 0;
	int t=0;
	for(i=g[x];i;i=e[i].nxt)if(e[i].v!=y)q[++t]=f[e[i].v]+1;
	if(!t)return 1;
	if(~t&1)q[++t]=0;
	sort(q+1,q+1+t);
	if(q[t]>B)return 0;
	int l=1,r=t+1;
	for(;l<r;){
		int mid=(l+r)>>1;
		int l1=0,r1=t+1;
		for(i=1;i<=t/2;++i){
			if(++l1,l1==mid)++l1;
			if(--r1,r1==mid)--r1;
			if(q[l1]+q[r1]>B)break;
		}
		if(i<=t/2)l=mid+1;
		else r=mid;
	}
	if(l>t)return 0;
	return f[x]=q[l],1; 
}

int main(){
	//freopen("aa.in","r",stdin);
	int i,j;
	scanf("%d",&n);
	for(i=1;i<n;++i){
		int x,y;scanf("%d%d",&x,&y);
		adde(x,y);adde(y,x);
		++deg[x];++deg[y];
	}
	int tot=0;
	for(i=1;i<=n;++i){
		if(deg[i]&1)++tot;
		if(deg[i]==1)root=i;	
	}
	tot>>=1;
	int l=1,r=n;
	for(;l<r;){
		int mid=(l+r)>>1;B=mid;
		if(!dfs(root,root))l=mid+1;
		else r=mid;
	}
	printf("%d %d",tot,l);
	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
template<typename T>
int sz(const T &a){return (int)a.size();}
int good[101];
int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int a,b;
        cin>>a;
        while(a--){
            cin>>b;
            good[b]=true;
        }
    }
    int am=0;
    for(int i=1;i<=n;i++){
        if(!good[i])am++;
    }
    printf("%d\n",am);
    return 0;
}

Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        // TODO ??????????????????????????????????????¨?????¨????????????????????????

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        String strN = Integer.toString(n);

        if (n >= 3 && n <= 10000) {
            for(int i = 1; i <= n; i++){

                int x = 0;

//              i???3????????°?????´???
                if(i % 3 == 0){
                    System.out.print(" " + i);
//              i???3?????????????????´???
                }else if(i % 10 == 3){
                    System.out.print(" " + i);
                } else if (i / 1000 == 3) {
                    System.out.print(" " + i);
                } else if ((x = i % 1000) / 100 == 3) {
                    System.out.print(" " + i);
                } else if ((x = x % 100) / 10 == 3) {
                    System.out.print(" " + i);
                }
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 26872
#include <stdio.h>

int main(void)
{
	int n = 0;
	int m = 0;
	int sum = 0;

	scanf("%d %d", &m, &n);

	if ((2 <= m && m <= 100)
	 && (2 <= n && n <= 100)
	) {
		sum = (m - 1) * (n - 1);
	}

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

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

#define PI 3.141592653589793

int main(void)
{
	int a, b, c;
	double s, l, h;

	scanf("%d%d%d", &a, &b, &c);

	s = sin(c * PI / 180.0)*a*b / 2;
	l = a + b + sqrt(a*a + b*b - 2 * a*b * cos(c * PI / 180.0));
	h = s / a * 2;

	printf("%lf %lf %lf\n", s, l, h);

	return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
const int N = 10;

int h, w, k, ans;
char C[N][N];
bool choose_row[N];
bool choose_col[N];

void dfs(int row, int col) {
	if (row <= h) {
		choose_row[row] = true;
		dfs(row + 1, col);
		choose_row[row] = false;
		dfs(row + 1, col);
	} else if (col <= w) {
		choose_col[col] = true;
		dfs(row, col + 1);
		choose_col[col] = false;
		dfs(row, col + 1);
	} else {
		char MP[N][N] = {};
		for (int i = 1; i <= h; i++)
			for (int j = 1; j <= w; j++)
				MP[i][j] = C[i][j];
		for (int i = 1; i <= h; i++)
			if (choose_row[i])
				for (int j = 1; j <= w; j++)
					MP[i][j] = '.';
		for (int i = 1; i <= w; i++)
			if (choose_col[i])
				for (int j = 1; j <= h; j++)
					MP[j][i] = '.';
		int cnt = 0;
		for (int i = 1; i <= h; i++)
			for (int j = 1; j <= w; j++)
				if (MP[i][j] == '#')
					++cnt;
		if (cnt == k) ++ans;
	}
}

int main() {
	cin >> h >> w >> k;
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			cin >> C[i][j];
	dfs(1, 1);
	cout << ans << "\n";
}

Measured memory_bytes: 3632
num, weight = gets.split.map(&:to_i)
things = []
num.times { things << gets.split.map(&:to_i) }
w_range = (things.first.first..things.first.first + 3).to_a
things_1 = []
things_2 = []
things_3 = []
things_4 = []
things.each do |w, v|
  case w_range.find_index(w)
  when 0
    things_1 << v
  when 1
    things_2 << v
  when 2
    things_3 << v
  when 3
    things_4 << v
  end
end
things_1.sort! { |a, b| b <=> a }
things_2.sort! { |a, b| b <=> a }
things_3.sort! { |a, b| b <=> a }
things_4.sort! { |a, b| b <=> a }
cumulative_things_1 = [0]
cumulative_things_2 = [0]
cumulative_things_3 = [0]
cumulative_things_4 = [0]
things_1.each { |v| cumulative_things_1 << cumulative_things_1.last + v }
things_2.each { |v| cumulative_things_2 << cumulative_things_2.last + v }
things_3.each { |v| cumulative_things_3 << cumulative_things_3.last + v }
things_4.each { |v| cumulative_things_4 << cumulative_things_4.last + v }
ans = []
cumulative_things_1.each_with_index do |v1, i1|
  cumulative_things_2.each_with_index do |v2, i2|
    cumulative_things_3.each_with_index do |v3, i3|
      cumulative_things_4.each_with_index do |v4, i4|
        ans << v1 + v2 + v3 + v4 if i1 * w_range[0] + i2 * w_range[1] + i3 * w_range[2] + i4 * w_range[3] <= weight
      end
    end
  end
end
puts ans.max


Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> A(n), B(n);
    vector<vector<ll>> dp(n, vector<ll>(n+1, INF<ll>));
    for (int i = 0; i < n; ++i) {
        cin >> A[i] >> B[i];
        dp[i][i+1] = 0;
    }
    for (int len = 2; len <= n; ++len) {
        for (int i = 0, j = len; j <= n; ++i, ++j) {
            for (int k = 1; k < j; ++k) {
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]+A[i]*B[k-1]*A[k]*B[j-1]);
            }
        }
    }
    cout << dp[0][n] << "\n";
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
ll int N,y;
vector<double> v;
double sum;
double dp[3005][3005][3];
double fun(int i,int count,int x)
{
    if(i==N-1)
    {
        if(x==0)
        {
            if(count>=y)
            {
                dp[i][count][x]=(1-v[i]);    
            }
            else
            {
                dp[i][count][x]=0;
            }
        }
        else
        {
            if((count+1)>=y)
            {
                dp[i][count][x]=v[i];
            }
            else
            {
                dp[i][count][x]=0;
            }
        }
    }
    else
    {
        if(x==0)
        {
            if(dp[i+1][count][0]==-1)
            dp[i+1][count][0]=fun(i+1,count,0);
            if(dp[i+1][count][1]==-1)
            dp[i+1][count][1]=fun(i+1,count,1);
            dp[i][count][x]=((1-v[i])*dp[i+1][count][0]);
            dp[i][count][x]+=((1-v[i])*dp[i+1][count][1]);
        }
        else
        {
            if(dp[i+1][count+1][0]==-1)
            dp[i+1][count+1][0]=fun(i+1,count+1,0);
            if(dp[i+1][count+1][1]==-1)
            dp[i+1][count+1][1]=fun(i+1,count+1,1);
            dp[i][count][x]=((v[i])*dp[i+1][count+1][0]);
            dp[i][count][x]+=(v[i]*dp[i+1][count+1][1]);
        }
    }
    return dp[i][count][x];
}
int main()
{
    int i,j,p;
    double x;
    cin>>N;
    y=(N/2)+1;
    for(i=0;i<N;i++)
    {
        cin>>x;
        v.pb(x);
    }
    for(i=0;i<N;i++)
    {
        for(j=0;j<N+5;j++)
        {
            for(p=0;p<3;p++)
            dp[i][j][p]=-1;
        }
    }
    dp[0][0][0]=fun(0,0,0);
    dp[0][0][1]=fun(0,0,1);
    double sum=0.00000000;
    sum+=(dp[0][0][0]);
    sum+=dp[0][0][1];
    printf("%0.9lf\n",sum);
    return 0;
}


Measured memory_bytes: 211840
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
  string s;
  cin >> s;
  if((s.front() == s.back()) == (s.length()%2 == 0)) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}


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

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

  vector<vector<int>> alph(n, vector<int>(26, 0));

  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++) alph[i][s[j] - 'a']++;
  }

  string ans = "";

  for (int i = 0; i < 26; i++)
  {
    int max_num = alph[0][i];
    for (int j = 1; j < n; j++) max_num = min(max_num, alph[j][i]);
    for (int k = 0; k < max_num; k++) ans += i + 'a';
  }

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

Measured memory_bytes: 256
using System;

namespace AOJ.ITP
{
    public class SumOfNumbers
    {
        public static void Main()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "0") { break; }

                int answer = 0;
                for (int i = 0; i < input.Length; i++)
                {
                    answer += int.Parse(input.Substring(i, 1));
                }

                Console.WriteLine(answer);
            }
        }
    }
}

Measured memory_bytes: 5644
#include <bits/stdc++.h>
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))
#define MEM(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int mod = 1e9 + 7;
int a[200200];
int main() {
    int n, x;
    scanf("%d", &n);
    int four = 0;
    int two = 0;
    int not_four = 0;
    for(int i = 0; i < n; ++ i) {
        scanf("%d", &x);
        if(x % 2 == 0 && x % 4 != 0) two++;
        else if(x % 4 == 0) four++;
        else not_four++;
    }
    if(two == 0) {
        if(four + 1 < not_four) puts("No");
        else puts("Yes");
    } else {
        if(four < not_four) puts("No");
        else puts("Yes");
    }
}


Measured memory_bytes: 256
r,g,b,n=gets.chomp.split(" ").map(&:to_i);
ans = 0
(n+1).times do |u|
  (n+1).times do |v|
      if (n - (r*u + g*v)) % b == 0 && n >= (r*u + g*v)
        ans = ans + 1
      end
  end
end
p ans

Measured memory_bytes: 1788
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N=0,K,cnt=0,s,d;
  cin >> N >> K;
  for(int a=1;a<=N;a++){
    if((a+1) % K == 0){
      d = (a+1)/K;
    }else
      d = (a+1)/K + 1;
    s = (N+a)/K;
    if(d > s || 2*a % K != 0)
      continue;
    cnt += (s-d+1)*(s-d+1);
  }
  cout << cnt << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

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

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

struct E {
  int to;
  ll c;
};
std::vector<E> V[101010];
ll L[100010];

void DFS(int v, int pre, ll d) {
  L[v] = d;
  for (auto &e : V[v]) {
    if (pre == e.to)
      continue;
    DFS(e.to, v, d + e.c);
  }
}

void solve(long long N, vector<long long> a, vector<long long> b,
           vector<long long> c, long long Q, long long K, vector<long long> x,
           vector<long long> y) {
  fill(L, L + 100010, -1);
  N--;
  REP(i, N) {
    a[i]--;
    b[i]--;
    V[a[i]].push_back({(int)b[i], c[i]});
    V[b[i]].push_back({(int)a[i], c[i]});
  }
  K--;
  DFS(K, -1, 0);
  dump(L[K]);

  REP(i, Q) {
    x[i]--;
    y[i]--;
    ll ans = L[x[i]] + L[y[i]];
    cout << ans << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  long long Q;
  long long K;
  cin >> N;
  vector<long long> a((N - 1) - 1 + 1);
  vector<long long> c((N - 1) - 1 + 1);
  vector<long long> b((N - 1) - 1 + 1);
  for (int i = 0; i <= (N - 1) - 1; i++) {
    cin >> a[i];
    cin >> b[i];
    cin >> c[i];
  }
  cin >> Q;
  vector<long long> y(Q - 1 + 1);
  vector<long long> x(Q - 1 + 1);
  cin >> K;
  for (int i = 0; i <= Q - 1; i++) {
    cin >> x[i];
    cin >> y[i];
  }
  solve(N, a, b, c, Q, K, x, y);
  return 0;
}


Measured memory_bytes: 22144
#include<iostream>
using namespace std;
int main(){
int a[4],b[4],h,w,i,j;
while(cin>>a[0]){
h=w=0;
for(i=1;i<4;i++)cin>>a[i];
for(i=0;i<4;i++)cin>>b[i];
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(i==j&&a[i]==b[j])h++;
else if(a[i]==b[j])w++;
}
}
cout<<h<<" "<<w<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;
const long long P = 1000000007;

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int ans = min(a*n , b);
  cout << ans << endl;
  return 0;
}

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

int main()
{
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;
    int **array = new int*[n+1];
    for (int i=0; i<n+1; i++)
    {
      array[i] = new int[n+1];
    }

    for (int i=0; i<n+1; i++)
    {
      for (int j=0; j<n+1; j++)
      {
        array[i][j] = 0;
      }
    }

    for (int i=0; i<n; i++)
    {
      for (int j=0; j<n; j++)
      {
        cin >> array[i][j];
      }
    }

    for (int i=0; i<n; i++)
    {
      for (int j=0; j<n; j++)
      {
        array[n][j] += array[i][j];
        array[i][n] += array[i][j];
        array[n][n] += array[i][j];
      }
    }

    for (int i=0; i<=n; i++)
    {
      for (int j=0; j<=n; j++)
      {
        printf("%5d", array[i][j]);
      }
      cout << endl;
    }

    for (int i=0; i<n+1; i++)
    {
      delete[] array[i];
    }
    delete[] array;
  }
}

Measured memory_bytes: 1220
#include <stdio.h>
 
int main(void) {
 
  int i,j;
  int h[11];
 
  for(i=0;i< 10;i++)
    scanf("%d",&h[i]);
 
  for(i=0;i< 3;i++) {
    for(j=i+1;j< 10;j++)
      if(h[i]< h[j]) {
    h[10]=h[i];
    h[i]=h[j];
    h[j]=h[10];
      }
    printf("%d\n",h[i]);
  }
 
  return 0;
 
}

Measured memory_bytes: 0
main :: IO ()
main = interact $ unlines . map (convert . map read . words) . init . lines

convert :: [Int] -> String
convert [h,w] = unlines $ [lid] ++ replicate (h-2) mid ++ [lid]
    where lid = replicate w '#'
          mid = "#" ++ replicate (w-2) '.' ++ "#"


Measured memory_bytes: 4520
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    var cnt = 0
    for (i in 0 until h) {
        cnt += readLine()!!.count { it == '#' }
    }
    if (cnt==h+w-1) println("Possible")
    else println("Impossible")
}

Measured memory_bytes: 37816
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,N,S;
vi a,b;

vi ff(int x){
	vi c(n);
	int I=0;
	for(int i=0;i<n-1;i++) if(a[i+1]-a[i]>x){
		while(I<=i) c[I++]=i;
	}
	while(I<n) c[I++]=n-1;
	return c;
}

vi f(){
	vi dp(S);
	vvi c(N);
	dp[0]--;
	for(int i=0;i<N;i++) c[i]=ff(b[i+1]);
	for(int i=0;i<S;i++) for(int j=0;j<N;j++) if(i&1<<j){
		int I=dp[i-(1<<j)];
		dp[i]=max(dp[i],(I<n-1?c[j][I+1]:n-1));
	}
	reverse(a.begin(),a.end());
	for(int i=0;i<n;i++) a[i]*=-1;
	return dp;
}

int main(){
	cin>>n>>m;
	a=vi(n);
	for(auto &i:a) cin>>i;
	while(m){
		b.push_back(m);
		m/=2;
	}
	b.push_back(0);
	N=(int)b.size()-1;
	S=1<<N;
	vi L=f(),R=f(),c=ff(b[0]),d(n+1);
	for(int i=0;i<S;i++){
		int l=L[i],r=n-R[S-i-1]-1;
		if(r<=l+1) d[0]++;
		else if(c[l+1]+1>=r){
			d[l+1]++;
			d[r]--;
		}
	}
	for(int i=1;i<=n;i++) d[i]+=d[i-1];	
	for(int i=0;i<n;i++) cout<<(d[i]?"Possible":"Impossible")<<endl;
}

Measured memory_bytes: 17120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
     ll n,cnt=0;
     cin>>n;

       char s[n];
       for(ll i=0;i<n;i++)
        cin>>s[i];
          for(int i=0;i<n;i++){
             if(s[i]!=s[i+1])cnt++;}
              cout<<cnt<<endl;


return 0;}



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

int main(){
    int x ,y;
    cin >> x >>y ;
    string ans ;
    if(x == y) ans = "==" ;
    else if(x > y) ans = '>';
    else if(x < y) ans = '<' ;

    cout << "a "<<ans<<" b"<<  endl ;
    return 0 ;
}




Measured memory_bytes: 3208
(let* ((dmax (read))
       (c (make-array '(27)))
       (s (make-array (list (1+ dmax) 27)))
       (score 0)
       (last (make-array '(27) :initial-element 0)))
  ; read
  (loop :for i :from 1 :to 26
        :do (setf (aref c i) (read)))
  (loop :for d :from 1 :to dmax
        :do (loop :for i :from 1 :to 26
                  :do (setf (aref s d i) (read))))
  ;;
  (loop :for d :from 1 :to dmax
        :do (let ((x (read)))
              (setf (aref last x) d)
              (incf score (aref s d x))
              (decf score (loop :for i :from 1 :to 26
                                :sum (* (aref c i) (- d (aref last i)))))
                (format t "~A~%" score))))


Measured memory_bytes: 29904
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N;
    cin >> N;
    string S;
    cin >> S;
 
    lint max_right_skewness = 0;
    lint right_skewness = 0;
    for (const auto c : S) {
        right_skewness += (c == ')' ? 1 : -1);
        max_right_skewness = max(max_right_skewness, right_skewness);
    }
    lint max_left_skewness = 0;
    lint left_skewness = 0;
    for (int i = N - 1; i >= 0; i--) {
        char c = S.at(i);
        left_skewness += (c == '(' ? 1 : -1);
        max_left_skewness = max(max_left_skewness, left_skewness);
    }
    string res = "";
    range(i, 0, max_right_skewness) res.push_back('(');
    for (const auto c : S) res.push_back(c);
    range(i, 0, max_left_skewness) res.push_back(')');
    cout << res << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long m,n,g,cnt = 1;
long long gcd(long long m,long long n) {
	if (m % n == 0)
		return n;
	else
		return gcd(n,m % n);
}
int main() {
	cin >> m >> n;
	g = gcd(m,n);
	for(long long i = 2; i <= sqrt(g); i++) {
		if (g % i == 0) {
			cnt++;
			while(g % i == 0)
				g = g / i;
		}
	}
	if (g > 1)
		cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
while(true){
   var n=arr.shift();
   if(n==0)break;
   if(n==1){
      continue;
   }
   var ary=[];
   for(var i=0;i<n;i++)ary[i]=false;
   for(var i=1;i<n;i++){
      ary[i*i%n]=true;
   }
   var m=[];
   ary.forEach(function(v,i){
      if(v)m.push(i);
   });
   var ans=[];
   var len=(n-1)/2 ;
   for(var i=0;i<=len;i++)ans[i]=0;
   for(var i=0;i<m.length;i++){
      for(var j=i+1;j<m.length;j++){
         var x=m[i]-m[j];
         if(x<0)x+=n;
         if(len<x)x=n-x;
         ans[x]+=2;
      }
   }
   ans.shift();
   ans.forEach(function(v){
      console.log(v);
   });
}

Measured memory_bytes: 21068
import java.util.*;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int K = sc.nextInt();

		if (K <= (N + 1) / 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}

}


Measured memory_bytes: 23892
//Solution By SlavicG
#include <bits/stdc++.h>
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	int n, k;
	cin >> n >> k;
	int a[n];
	int dp[n];
	forn(i,n)cin >> a[i];
	forn(i,n)dp[i] = INT_MAX;
	dp[0] = 0;
	for(int i = 0;i<n;i++)
	{
		for(int j = 1 ; j <= k;j++)
		{
			if(i + j < n)dp[i+j] = min(dp[i + j], dp[i] + abs(a[i + j] - a[i]));
		}
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 4388
N = int(input())
# 0地点を加える
A = [0] + list(map(int, input().split())) + [0]

total = 0
for i in range(N+1):
  total += abs(A[i]-A[i+1])

# a地点を抜くと(a-1->a)-(a->a+1)が消え、(a-1->a+1)を通る
for i in range(1, N+1):
  aa = abs(A[i-1]-A[i])
  ab = abs(A[i]-A[i+1])
  c =  abs(A[i-1]-A[i+1])
  print(total + c - (aa+ab))
  

Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n),b(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  for(Int i=0;i<n;i++) cin>>b[i];
  Int res=0;
  for(Int i=0;i<n;i++){
    if(b[i]<=a[i]) res+=a[i]-b[i];
    else res-=(b[i]-a[i])/2;
  }
  cout<<(res>0?"No":"Yes")<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }
    REP(i,k,n){
        if(a[i]>a[i-k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 4832
'''
Created on 2020/09/19

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  cnt=0
  ans=False
  for i in range(N):
    d,e=map(int,pin().split())
    if d==e:
      cnt+=1
      if cnt==3:
        ans=True
        cnt=0
    else:
      cnt=0
  if ans:
    print("Yes")
  else:
    print("No")
  return 
main()

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

template<typename T> class WeightedUnionFind{
    protected:
        vector<int> par;
        vector<int> rnk;
        vector<T> diff_weight;
    public:
        WeightedUnionFind(int n, T u);
        int root(int x);
        void unite(int x, int y, T w);
        bool same(int x, int y);
        T weight(int x);
        T diff(int x, int y);
};

template<typename T> WeightedUnionFind<T>::WeightedUnionFind(int n, T u){
    par = vector<int>(n);
    rnk = vector<int>(n);
    diff_weight = vector<T>(n);
    for (int i = 0; i < n; i++){
        par[i] = i; rnk[i] = 0; diff_weight[i] = u;
    }
}

template<typename T> int WeightedUnionFind<T>::root(int x){
    if (par[x] == x) return x;
    int r = root(par[x]);
    diff_weight[x] += diff_weight[par[x]];
    return par[x] = r;
}

template<typename T> void WeightedUnionFind<T>::unite(int x, int y, T w){
    w += weight(x); w -= weight(y);
    x = root(x); y = root(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]){
        par[x] = y;
        diff_weight[x] = -w;
    }else{
        par[y] = x;
        diff_weight[y] = w;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

template<typename T> bool WeightedUnionFind<T>::same(int x, int y){
    return root(x) == root(y);
}

template<typename T> T WeightedUnionFind<T>::weight(int x){
    root(x);
    return diff_weight[x];
}

template<typename T> T WeightedUnionFind<T>::diff(int x, int y){
    return weight(y) - weight(x);
}


int main(){
    int n, m;
    cin >> n >> m;
    WeightedUnionFind<ll> wuf(n, 0LL);
    for (int i = 0; i < m; i++){
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        if (wuf.same(l, r)){
            if (wuf.diff(l, r) != d){
                cout << "No" << endl;
                return 0;
            }
        }else{
            wuf.unite(l, r, d);
        }
    }

    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scn = new Scanner(System.in);
        long N = scn.nextLong();
        long A = scn.nextLong();
        long B = scn.nextLong();
        
        if(A!=0){
            long tmp = (N/(A+B))*A;
            tmp += N%(A+B)<=A ? N%(A+B) : A;
            System.out.println(tmp);
        }
        else System.out.println(0);
    }
}


Measured memory_bytes: 35496
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i] -= (i + 1);
    }
    sort(ALL(a));
    int l = (n + 1) / 2, r = l - 1;
    ll ans;
    ll totl = 0, totr = 0;
    rep(i, n) {
        totl += abs(a[i] - a[l]);
        totr += abs(a[i] - a[r]);
    }
    ans = min(totl, totr);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3996
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100+10;
int n,a[N];
bool cmp(int x,int y){
return x>y;
}
int main() {
    while(~scanf("%d",&n)){
        int sum=0;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        for(int i=0;i<n;i+=2){
            sum+=(a[i]-a[i+1]);

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


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

string s;
vector<vector<int>> dp(3000,vector<int> (3000,-1));
string s1,s2;
int len1,len2;
int a[3000]={0};
int lcs(int l1,int l2)
{
    if(l1==-1||l2==-1)
        return 0;
    if(dp[l1][l2]==-1)
    {
        if(s1[l1]==s2[l2])
        {
            //<<l1<<endl;
            //v.insert(l1);
            dp[l1][l2]=1+lcs(l1-1,l2-1);
        }
        else {
            dp[l1][l2]=max(lcs(l1-1,l2),lcs(l1,l2-1));
        }
    }
    return dp[l1][l2];
}

int main()
{
    int flag=0;
    cin>>s1>>s2;
    len1=s1.length();
    len2=s2.length();
    int ans=lcs(len1-1,len2-1);
    /*f(i,len1)
    {
        f(j,len2)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    int i=len1-1;
    int j=len2-1;
    while(i>=0)
    {
        while(j>=0)
        {
            if(dp[i][j]<=0)
            {
                flag=1;
                break;
            }
            if(i!=0&&j!=0)
            {
                if(dp[i][j]!=dp[i-1][j-1])
                {
                    if(dp[i][j]==dp[i-1][j]||dp[i][j]==dp[i][j-1])
                    {
                        if(dp[i][j]==dp[i-1][j])
                            i=i-1;
                        else
                            j=j-1;
                    }
                    else
                    {
                        s+=s1[i];
                        i--;
                        j--;
                    }
                }
                else
                {
                    i--;
                    j--;
                }
            }
            else if(i==0)
            {
                s+=s1[0];
                flag=1;
                break;
            }
            else if(j==0)
            {
                s+=s2[0];
                flag=1;
                break;
            }
        }
        if(flag==1)
            break;
    }
    reverse(s.begin(),s.end());
    cout<<s;

    //for(auto i: v)
      //  cout<<s1[i];
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    while(1) {
        ll n, m;
        cin >> n >> m;
        if(!n) break;
        vector<ll> ma(m);
        REP(i, n) {
            ll d, v;
            cin >> d >> v;
            chmax(ma[d-1], v);
        }

        ll ret = 0;
        REP(i, m) ret += ma[i];
        cout << ret << endl;
    }

    return 0;
}



Measured memory_bytes: 3216
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int x,y;
char fie[100][100]={};
char visited[100][100]={};
int c;


void dfs(int sx,int sy){
    if(sx<0 || sy<0 || sx>=x || sy>=y)return;
    if(visited[sy][sx])return;
    if(fie[sy][sx]!='.' && fie[sy][sx]!='@')return;
    c++;
    visited[sy][sx]=true;
    
    int d[5]={-1,0,1,0,-1};
    rep(i,4){
        dfs(sx+d[i],sy+d[i+1]);
    }
}

int main(){
    
    
    while(cin>>x>>y){
        c=0;
        rep(i,100)
        rep(j,100)
        visited[i][j]=false;
        
        int sx=-1,sy=-1;
        if(x==0 && y==0)break;
        
        rep(i,y){
            rep(j,x){
                cin>>fie[i][j];
                if(fie[i][j]=='@'){
                    sx=j,sy=i;
                }
            }
        }
        dfs(sx,sy);
        cout<<c<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=2e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
typedef unsigned long long uint64;
typedef unsigned int uint32;
namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
	{
		return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
	}
 
    template<typename T>inline T read()
	{
		T x=0;static char ch;T f=1;
		for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
		for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
		return x*f;
		
	}
}
using namespace  IO;
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
}
#define pb push_back
int n;
vector<int>E[N];
void input()
{
	int x,y;
	n=read<int>();
	For(i,2,n)
	{
		x=read<int>(),y=read<int>();
		E[x].pb(y),E[y].pb(x);
	}
}
const int mo=924844033;
int sz[N];
void add(int &x,int y){x+=y;x-=(x>=mo?mo:0);}
int g[1<<20],f[1<<20];
void dfs(int u,int pre)
{
	sz[u]=1;
	g[n]++;
	for(int v:E[u])if(v^pre)
	{
		dfs(v,u),sz[u]+=sz[v];
		add(g[sz[v]],mo-1);
	}
	//add(g[sz[u]],mo-1);
	if(pre)add(g[n-sz[u]],mo-1);
}
ll power(ll x,int y)
{
	ll res=1;
	for(;y;x=x*x%mo,y>>=1)if(y&1)res=res*x%mo;
	return res;
}
int rev[1<<20];
void NTT(int *p,int len,int type)
{
	For(i,0,len-1)if(i<rev[i])swap(p[i],p[rev[i]]);
	int tim,wn,X;
	for(int i=2;i<=len;i<<=1)
	{
		tim=i>>1;
		wn=power(5,(mo-1)/i);
		if(type==-1)wn=power(wn,mo-2);
		for(int j=0;j<len;j+=i)
		{
			X=1;
			for(int k=0;k<tim;k++,X=1ll*X*wn%mo)
			{
				int u=p[j+k],v=1ll*p[j+k+tim]*X%mo;
				p[j+k]=(u+v)%mo;
				p[j+k+tim]=(u-v+mo)%mo;
			}
		}
	}
	if(type==-1)
	{
		int inv=power(len,mo-2);
		For(i,0,len-1)p[i]=1ll*p[i]*inv%mo;
	}
}
int mc[N],inv[N];
int ans[N];
int C(int x,int y){return 1ll*mc[x]*inv[y]%mo*inv[x-y]%mo;}
void work()
{
	dfs(1,0);
	//For(i,0,n)cout<<g[i]<<endl;
	mc[0]=inv[0]=1;
	For(i,1,n)mc[i]=1ll*mc[i-1]*i%mo;
	inv[n]=power(mc[n],mo-2);
	Fordown(i,n-1,1)inv[i]=1ll*inv[i+1]*(i+1)%mo;
	For(i,0,n)g[i]=1ll*g[i]*mc[i]%mo;
	For(i,0,n)f[i]=inv[n-i];
	int len=1,cnt=0;
	for(;len<=n*2;len<<=1)cnt++;
	For(i,0,len)rev[i]=(rev[i>>1]>>1)|(i&1)<<(cnt-1);
	NTT(g,len,1),NTT(f,len,1);
	For(i,0,len)g[i]=1ll*g[i]*f[i]%mo;
	NTT(g,len,-1);
	//For(i,1,n)cout<<g[i+n]<<endl;
	For(i,1,n)ans[i]=1ll*g[n+i]*inv[i]%mo;
	For(i,1,n)write(ans[i],'\n');
}
int main()
{
	//file();
	input();
	work();
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 1e+9 + 7;

template <typename T=long long>
T pow_mod(T n, T p, T m)
{
    if(p == 0) return 1;
    if(p%2 == 1) return pow_mod<T>(n, p-1, m) * n % m;
    else{
        T tmp = pow_mod<T>(n, p/2, m) % m;
        return tmp * tmp % m;
    }
}

// nCk を O(n) で求めるクラス
template <typename T>
class Combination 
{
    private:
        int _mod;
        std::vector<T> factorial, factorial_inv;

    public:
        Combination(int n, int mod): _mod(mod), factorial(n+1, 1), factorial_inv(n+1)
        {
            for(int i = 1; i <= n; ++i) factorial[i] = (i*factorial[i-1]) % _mod;
            factorial_inv[n] = pow_mod<T>(factorial[n], _mod-2, _mod);  // 逆元を取る操作は重いので一回のみ行う
            for(int i = n; i >= 1; --i) factorial_inv[i-1] = (i*factorial_inv[i]) % _mod;
        } 

        T operator()(int n, int k)
        {
            if(n < 0 or k > n) return 0;
            return factorial[n] * factorial_inv[k] %_mod * factorial_inv[n-k] %_mod;
        }
};

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

    Combination<long long> comb(N, MOD);

    long long ans = 0;
    FOR(i, 1, N){  // 0 が i 個あるとき
        ans += comb(N, i) * (pow_mod<long long>(9, N-i, MOD)-pow_mod<long long>(8, N-i, MOD)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 18752