akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        public static void Main()
        {
            string X = Console.ReadLine();
            int x = int.Parse(X);

            int ans = 0;

            ans += (x / 500) * 1000;
            ans += ((x % 500) / 5) * 5;

            Console.WriteLine(ans);
    
            

        }
    }
}

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

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int main()
{
  vector<int> a(101,0);
  int x, tmp = 0;
  while(~scanf("%d",&x)) a[x]++;
  vector<int> ans;
  FOR(i,1,100)
  {
    if(a[i] > a[tmp])
    {
      tmp = i;
      ans.clear();
      ans.push_back(tmp);
    }
    else if(a[i] == a[tmp])
      ans.push_back(i);
  }
  for(auto v : ans) printf("%d\n",v);
  return 0;
}

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

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

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

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

int n,q;

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

	cin>>n>>q;
	REP(i,q) {
		int v,w;cin>>v>>w;v--,w--;
		if(n==1) {
			cout<<v+1<<endl;
			continue;
		}
		while(v!=w) {
			if(v>w) v--,v/=n;
			else w--,w/=n;
		}
		cout<<v+1<<endl;
	}

	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
#include<queue>
#include<deque>
#define INF 0x3f3f3f3f
using namespace std;
char a[100][100],b[100][100];
int n,m;
int main(){
	while(cin>>n>>m){
	    for(int i=0;i<n;i++){
	        scanf("%s",a[i]);
	    }
	    for(int i=0;i<m;i++){
	        scanf("%s",b[i]);
	    }
	    int flag=1;
	    for(int i=0;i<n;i++){
	        for(int j=0;j<n;j++){
	            if(a[i][j]==b[0][0]){
	                flag=0;
	                for(int x=0;x<m;x++){
	                    for(int y=0;y<m;y++){
	                        if(a[i+x][j+y]!=b[x][y]){
	                            flag=1;
	                            break;
	                        }
	                    }
	                }
	            }
	            if(flag==0)
	            {
	                cout<<"Yes";
	                return 0;
	            }
	        }
	    }
	    cout<<"No";
	}
    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
 
#define MAX 100000
 
typedef struct {
  char name[10];
  int time;
} process;
 
void enqueue(process);
process dequeue(void);
 
int head = 0;
int tail = 0;
process Q[MAX];
 
int main(){
  int i, n, q, total=0;
  process p;
 
  scanf("%d%d", &n, &q);
 
  for(i=0; i<n; i++){
    scanf("%s%d", p.name, &p.time);
    enqueue(p);
  }
 
  while(1){
 
    if(head == tail){
      break;
    }
 
    if(Q[head].time > q){
      p = dequeue();
      p.time -= q;
      enqueue(p);
      total += q;
    }else{
      p = dequeue();
      printf("%s %d\n", p.name, p.time + total);
      total += p.time;
    }
  }    
 
  return 0;
  
}
 
void enqueue(process p){
  Q[tail] = p;
  if(tail+1 == MAX){
    tail = 0;
  }else{
  tail++;
  }
}
 
process dequeue(){
  process x;
 
  x = Q[head];
 
  if(head+1 == MAX){
    head = 0;
  }else{
    head++;
  }
  return x;
}

Measured memory_bytes: 2160
// AOJ 1034: Line Puzzle
// 2017.9.29 bal4u@uu

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

#define N 8
#define N2 66

typedef struct { signed char r, c, s, t; } T;
T start[N2]; int m;

signed char map[N][N]; int n, n2;
int mv[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};

int cmp(T *a, T *b)
{
	if (b->s - a->s) return b->s - a->s;
	if (b->r - a->r) return b->r - a->r;
	return a->c - b->c;
}

void print(signed char a[N][N])
{
	int r, c;

	for (r = 0; r < n; r++) {
		for (c = 0; c < n; c++) printf("%3d ", a[r][c]);
		printf("\n");
	}
	printf("\n");
}

int combi(signed char a[N][N], int m0, int n0)
{
	int i, j, f, r, c, s, t, r2, c2, ss, goal;
	signed char tmp[N][N], mk[N2][2];
	T q[N2]; int top;

	if (m0 >= m && n0 >= n2) return 1;
	q[0].r = start[m0].r, q[0].c = start[m0].c, q[0].s = 0, q[0].t = 0, top = 1;
	goal = start[m0].s;
	while (top > 0) {
		r = q[--top].r, c = q[top].c, s = q[top].s, t = q[top].t;
		mk[t][0] = r, mk[t][1] = c;
		for (i = 0; i < 4; i++) {
			r2 = r + mv[i][0], c2 = c + mv[i][1];
			if (r2 < 0 || r2 >= n || c2 < 0 || c2 >= n || a[r2][c2] <= 0) continue;
			for (f = j = 0; j <= t; j++) {
				if (mk[j][0] == r2 && mk[j][1] == c2) { f = 1; break; }
			}
			if (f) continue;
			ss = s + a[r2][c2];
			if (ss < goal) {
				q[top].r = r2, q[top].c = c2, q[top].s = ss, q[top++].t = t + 1;
			} else if (ss == goal) {
				memcpy(tmp, a, sizeof(tmp));
				for (j = 1; j <= t; j++) tmp[mk[j][0]][mk[j][1]] = 0;
				tmp[r2][c2] = 0;
//print(tmp);
				if (combi(tmp, m0+1, n0+t+2)) return 1;
			}
		}
	}
	return 0;
}

int main()
{
	int r, c, t, s;

	while (scanf("%d", &n) && n > 0) {
		n2 = n*n;
		for (s = m = 0, r = 0; r < n; r++) for (c = 0; c < n; c++) {
			scanf("%d", &t);
			if (t < 0) start[m].r = r, start[m].c = c, start[m++].s = -t;
			map[r][c] = t, s += t;
		}
		qsort(start, m, sizeof(T), cmp);
		puts(s == 0 && combi(map, 0, 0) ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int n; cin>>n;
    set<ll> hen;
    ll l1=0, l2=0;
    for(int i=0; i<n; i++){
        ll a; cin>>a;
        if(hen.find(a) != hen.end()){
            if(a>=l1){
                l2=l1;
                l1=a;
            }
            else if(a>=l2) l2=a;
            hen.erase(a);
        }
        else hen.insert(a);
    }
    cout << l1*l2 << endl;
}

Measured memory_bytes: 8248
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
s = 10000000000000
i = 1
while i*i <= N:
	if N % i == 0 and i+(N/i) < s:
		s = i+(N//i)
	i += 1
print(s-2)


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* main */

signed main(){
    string s,nox = "";
    cin >> s;
    FOR(i,0,s.size()){
        if(s[i] != 'x')nox += s[i];
    }
    FOR(i,0,nox.size()){
        if(nox[i] != nox[nox.size()-1-i]){
            cout << -1 << endl;
            return 0;
        }
    }
    ll counter[nox.size()+1] = {0};
    ll idx = 0;
    FOR(i,0,s.size()){
        if(s[i] != 'x')idx++;
        else counter[idx]++;
    }
    ll ans = 0;
    FOR(i,0,nox.size()+1){
        ans += abs(counter[i]-counter[nox.size()-i]);
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 1360
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   string s,t;
   cin>>s>>t;
   sort(s.begin(),s.end());
   sort(t.begin(),t.end(),greater<int>());

   s<t? cout<<"Yes":cout<<"No";

   


   
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

  int a[n][m];
  int b[m];
  int c[n];

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

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

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

  for(int i = 0; i < n; i++){
	for(int j = 0; j < m; j++){
	  c[i] += a[i][j] * b[j];
	}
  }

  for(int i = 0; i < n; i++){
	printf("%d\n", c[i]);
  }

  return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
const int maxn=(2e5)+10;
int n,a[maxn];
int ans,k;
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		int x; scanf("%d",&x);
		a[x]=i;
	}
	k=ans=1;
	for (int i=1;i<n;i++)
		if (a[i]<a[i+1]) {
			k++; ans=max(ans,k);
		}
		else k=1;
	printf("%d\n",n-ans);
	return 0;
}

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


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  int a[150];
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];

  }
  int c=0;
  for(int i=0;i<n;i++){
    if(4*m*a[i]>=sum){
        c++;
    }
  }
  if(c>=m){
    cout<<"Yes";
  }else{
    cout<<"No";
  }


  
}




Measured memory_bytes: 256
#include <stdio.h>

int x[55];
long long dp[55][2555];

int main(){
    int N, A;
    scanf("%d%d", &N, &A);
    dp[0][0] = 1;
    for(int i=0; i<N; i++){
        scanf("%d", &x[i]);
        for(int j=54; j>=1; j--){
            for(int k=2555; k>=x[i]; k--){
                dp[j][k] += dp[j-1][k-x[i]];
            }
        }
    }
    long long res=0;
    for(int i=1; i<=N; i++) res += dp[i][i*A];
    printf("%lld", res);
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);

void solve(long long A, long long B)
{
  rep(i, 10000)
  {
    double j = i;
    j *= 0.08;
    double k = i;
    k *= 0.10;
    if (A == (int)(j) && B == (int)(k))
    {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}

int main()
{
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


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

int main() {
    int K,A,B;
    cin >> K >> A >> B;
    if(B/K * K >= A) cout << "OK" << endl;
    else cout << "NG" << endl;

    return 0;
}

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

#define w cout
#define e '\n'
#define int long long
#define sz(x) (int)x.size()
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6;

void solve() {
	int n ; cin >> n;
	int x = (n / 500) * 1000;
	n = n - (n / 500)*500;
	w <<  x + (n / 5)*5 ;
	//~ w << ans;
}


signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	
	//~ cin >> t;
	while(t--) {
		solve();
	}
}


Measured memory_bytes: 256
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
int cnt[11][11];
void solve () {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		int x = i;
		int o;
		while (x != 0) {
			o = x % 10;
			x /= 10;
		}
		cnt[o][i % 10] ++;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i ++) {	
		int x = i;
		int o;
		while (x != 0) {
			o = x % 10;
			x /= 10;
		}
		ans += cnt[i % 10][o];
	}
	cout << ans;
}
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//  cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int h = scanner.nextInt();
        final int w = scanner.nextInt();
        final int k = scanner.nextInt();

        final int[][] table = new int[h][w];
        for (int i = 0; i < h; i++) {
            final char[] array = scanner.next().toCharArray();
            table[i][0] = array[0] - '0';
            for (int j = 1; j < array.length; j++) {
                table[i][j] = table[i][j - 1] + array[j] - '0';
            }
        }

        final boolean[] horizontals = new boolean[h];
        final int answer = recursive(0, horizontals, table, h, w, k);
        System.out.println(answer);
    }

    private static int recursive(final int index, final boolean[] horizontals, final int[][] table, final int h, final int w, final int k) {
        if (index == h) {
            if (!meetPreliminary(table, horizontals, k, h, w)) {
                return Integer.MAX_VALUE;
            }

            int vertical = 0;
            int count = 0;
            for (int j = 0; j < w; j++) {
                int sum = 0;
                for (int i = 0; i < h; i++) {
                    sum += table[i][j] - (vertical == 0 ? 0 : table[i][vertical - 1]);
                    if (sum > k) {
                        vertical = j;
                        count++;
                    }
                    if (horizontals[i]) {
                        sum = 0;
                    }
                }
            }

            for (final boolean horizontal : horizontals) {
                if (horizontal) {
                    count++;
                }
            }
            return count;
        }

        horizontals[index] = true;
        int tmp = recursive(index + 1, horizontals, table, h, w, k);

        horizontals[index] = false;
        return Math.min(tmp, recursive(index + 1, horizontals, table, h, w, k));
    }

    // 1列でKを超えないかどうか
    private static boolean meetPreliminary(final int[][] table, final boolean[] horizontals, final int k, final int h, final int w) {
        for (int j = 0; j < w; j++) {
            int sum = 0;
            for (int i = 0; i < h; i++) {
                sum += table[i][j] - (j == 0 ? 0 : table[i][j - 1]);
                if (sum > k) {
                    return false;
                }
                if (horizontals[i]) {
                    sum = 0;
                }
            }
        }
        return true;
    }
}


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

int n, m;
int visited[100001];
int parent[100001];
vector<int> adj[100001];

void bfs(int src)
{
    queue<int> q;
    q.push(src);
    visited[src] = true;

    while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        for (auto e : adj[cur])
        {
            if (!visited[e])
            {
                q.push(e);
                parent[e] = cur;
                visited[e] = true;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    bfs(1);
    for (int i = 2; i <= n; i++)
    {
        if (parent[i] == 0)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes" << '\n';
    for (int i = 2; i <= n; i++)
    {
        cout << parent[i] << '\n';
    }
}

Measured memory_bytes: 10996
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var hwn = Input.ar;
        var ct = new long[10];
        ct[0] = (long)(hwn[0] - 2) * (hwn[1] - 2);
        var dic = new Dictionary<int, Dictionary<int,int>>();
        for(var i = 0; i < hwn[2]; i++)
        {
            var ab= Input.ar;
            for(var j=0;j<3;j++)
                for(var k = 0; k < 3; k++)
                {
                    var h = ab[0]-1 - j;
                    var w = ab[1]-1 - k;
                    if (h < 0 || h >= hwn[0] - 2 || w < 0 || w >= hwn[1] - 2) continue;
                    if (!dic.ContainsKey(h))
                        dic[h] = new Dictionary<int, int>();
                    if (dic[h].ContainsKey(w))
                        dic[h][w]++;
                    else dic[h][w] = 1;
                    ct[dic[h][w] - 1]--;
                    ct[dic[h][w]]++;
                }
        }
        WriteLine(string.Join("\n", ct));
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


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

int main() {
  int x;
  cin >> x;
  int ans;
  if (x < 600) ans = 8;
  else if (x < 800) ans = 7;
  else if (x < 1000) ans = 6;
  else if (x < 1200) ans = 5;
  else if (x < 1400) ans = 4;
  else if (x < 1600) ans = 3;
  else if (x < 1800) ans = 2;
  else ans = 1;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 55;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif

  string s,t;
  cin>>s>>t;
  int n,m;
  cin>>n>>m;
  string tt;
  cin>>tt;
  if(tt==s)n--;
  else m--;
  cout<<n<<" "<<m<<endl;
  return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}

int main_C() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;  cin >> S;
    int L = S.size();

    string P[4] = { "dream", "dreamer", "erase", "eraser" };

    queue<int> que;
    que.push(0);
    bool ok = false;
    while(!que.empty()) {
        int i = que.front(); que.pop();
        
        if (i==L) {
            ok = true;
            break;
        }

        for(string ptn : P) {
            if (S.substr(i,ptn.size()) == ptn) {
                que.push(i + ptn.size());
            }
        }
    }

    string ans = ok ? "YES" : "NO";
    
    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
constexpr long INF = 1LL << 60;
constexpr int MOD = 1e9 + 7;


vector<vector<int>> G;
long cost[202020];

void dfs(int v, int pv) {

    for(int nv : G[v]) {
        if(nv==pv) continue;
        cost[nv] += cost[v];
        dfs(nv, v);
    }
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n, q, a, b, c, d; cin >> n >> q;
    G.resize(n);
    REP(i,n-1) {
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    REP(i,q) {
        cin >> c >> d;
        --c;
        cost[c] += d;
    }

    dfs(0, -1);

    REP(i,n) cout << cost[i] << '\n';
    return 0;
}


Measured memory_bytes: 24320
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

int main(void)
{
    int N;
    int p[10], q[10];
    int i, j;
    int a = 1, b = 1;

    cin >> N;

    vector<int> per(N, 0);

    rep(i, 0, N)
    {
        per[i] = i + 1;
    }

    rep(i, 0, N)
    {
        cin >> p[i];
    }

    do
    {
        rep(i, 0, N)
        {
            if (per[i] == p[i])
            {
                continue;
            }
            else
            {
                break;
            }
        }

        if (i == N)
        {
            break;
        }

        a++;

    } while (next_permutation(per.begin(), per.end()));

    rep(i, 0, N)
    {
        per[i] = i + 1;
    }

    rep(i, 0, N)
    {
        cin >> q[i];
    }

    do
    {
        rep(i, 0, N)
        {
            if (per[i] == q[i])
            {
                continue;
            }
            else
            {
                break;
            }
        }

        if (i == N)
        {
            break;
        }

        b++;

    } while (next_permutation(per.begin(), per.end()));

    cout << abs(a - b) << endl;
}

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[a[i]-1]==i+1) ans++;
  }
  cout<<ans/2<<endl;
}


Measured memory_bytes: 640
import java.util.*;
import java.util.Map;
import java.util.TreeMap;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        String S = sc.next();
        String T = sc.next();
        TreeMap<Character, Character> maps = new TreeMap<Character, Character>();
        TreeMap<Character, Character> mapt = new TreeMap<Character, Character>();
        
        for(int i=0; i<S.length(); i++){
            char s = S.charAt(i);
            char t = T.charAt(i);
            if(maps.containsKey(s)){
                if(maps.get(s)!=t){
                    System.out.println("No");
                    return;
                }
            }
            else if(mapt.containsKey(t)){
                if(mapt.get(t)!=s){
                    System.out.println("No");
                    return;
                }
            }
            else{
                maps.put(s, t);
                mapt.put(t, s);
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 26864
import sys
input = sys.stdin.readline

class Node:
    def __init__(self, val):
        self.val  = val
        self.prev = None
        self.next = None

class DoublyLinkedList:
    def __init__(self):
        self.sentinel = Node(None)
        self.sentinel.prev = self.sentinel
        self.sentinel.next = self.sentinel

    def insert(self, val):
        node = Node(val)
        node.prev = self.sentinel
        node.next = self.sentinel.next
        self.sentinel.next.prev = node
        self.sentinel.next = node

    def delete(self, val):
        self.delete_node(self.search(val))

    def deleteFirst(self):
        self.delete_node(self.sentinel.next)

    def deleteLast(self):
        self.delete_node(self.sentinel.prev)

    def search(self, val):
        cursor = self.sentinel.next
        while cursor != self.sentinel and cursor.val != val:
            cursor = cursor.next
        return cursor

    def delete_node(self, node):
        if node == self.sentinel:
            return
        node.prev.next = node.next
        node.next.prev = node.prev

n = int(input())
linked_list = DoublyLinkedList()
for index in range(n):
    command = input().rstrip()
    if command[0] == 'i':
        linked_list.insert(command[7:])
    elif command[6] == 'F':
        linked_list.deleteFirst()
    elif command[6] == 'L':
        linked_list.deleteLast()
    else:
        linked_list.delete(command[7:])

node = linked_list.sentinel.next
output = []
while node != linked_list.sentinel:
    output.append(node.val)
    node = node.next
print(" ".join(map(str, output)))


Measured memory_bytes: 227596
#!/usr/bin/env python3

n = int(input())
a = list(map(int,input().split()))

cnt = 0
a2 = []
for i in range(n):
    if a[i]<0:
        cnt += 1
        a2.append(a[i]*(-1))
    else:
        a2.append(a[i])

if cnt%2 == 0:
    print(sum(a2))
else:
    memo = 10**9
    for i in range(n):
        memo = min(abs(a[i]),memo)
    print(sum(a2)-2*memo)
        




Measured memory_bytes: 14332
N = int(input())
words = []

rule_length = True
rule_2time = True
rule_startEnd = True

for i in range(N):
    word = input()
    if 1 > len(word) or len(word) > 10:
         rule_length = False
    if word in words:
        rule_2time = False
    if i !=0 and words[-1][-1] != word[0]:
        rule_startEnd = False    
    words.append(word)

if rule_length and rule_2time and rule_startEnd:
    print('Yes')
else:
    print('No')    



Measured memory_bytes: 3060
import Control.Monad
import Control.Applicative
import Data.Char
import Data.List

solve :: String -> String
solve s =
    let chunk = group $ sort [toLower c | c<-s, isAlpha c] in
    let sets = [(c,length s) | s@(c:_)<-chunk] in
    unlines $ map (showchr sets) ['a'..'z']
    where
    showchr :: [(Char,Int)] -> Char -> String
    showchr sets c =
        let n = maybe 0 id (lookup c sets) :: Int in
        [c] ++ " : " ++ (show n)

main =
    putStr =<< solve <$> getContents

Measured memory_bytes: 3952
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h> 
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

double v[200020];

int main(){
  rep(i,200020)v[i]=longinf;
  int n;
  cin >> n;
  pair<double,pair<double,double>> p[n];
  double t=0;
  rep(i,n){
    double x;
    cin >> x;
    double s=t;
    double e=t+x;
    t+=x;
    p[i].second.first=s;
    p[i].second.second=e;
  }
  rep(i,n)cin >> p[i].first;
  rep(i,n){
    rep(j,2*t+1){
      if(p[i].second.first<=0.5*j && 0.5*j<=p[i].second.second){
        v[j]=min(v[j],p[i].first);
      }
    }
  }
  rep(i,n){
    rep(j,2*t+1){
      v[j]=min(v[j],p[i].first+min(abs(0.5*j-p[i].second.first),abs(0.5*j-p[i].second.second)));
    }
  }
  rep(j,2*t+1)v[j]=min(v[j],-0.5*j+t);
  rep(j,2*t+1)v[j]=min(v[j],0.5*(double)j);
  double ans=0.0;
  rep(i,2*t){
    ans+=(v[i]+v[i+1])/2.0;
  }
  cout << setprecision(12) << ans/2.0 << endl;
return 0;}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    int m,f,b;
    scanf("%d%d%d",&m,&f,&b);
    if(b<=m){
        printf("0\n");
    }
    else if(b>m+f){
        printf("NA\n");
    }
    else {
        printf("%d\n",b-m);
    }
    return 0;
}


Measured memory_bytes: 2112
def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.readline

    S = input().rstrip('\n')
    N = len(S)

    A = [ord(s)-97 for s in S]
    H = [0] * (N+1)
    h2i = {}
    for i in range(N):
        H[i+1] = H[i] ^ (1 << A[i])
        if H[i+1] in h2i:
            h2i[H[i+1]].append(i+1)
        else:
            h2i[H[i+1]] = [i+1]

    dp = [N+1] * (N+1)
    dp[0] = 0
    pow2 = [2**i for i in range(26)]
    for i in range(N):
        h = H[i]
        if h in h2i:
            ii_list = h2i[h]
            ii = bisect_left(ii_list, i+1)
            if ii < len(ii_list):
                ii = ii_list[ii]
                if i:
                    dp[ii] = min(dp[ii], dp[i])
                else:
                    dp[ii] = 1
        for j in pow2:
            new_h = h ^ j
            if new_h in h2i:
                ii_list = h2i[new_h]
                ii = bisect_left(ii_list, i+1)
                if ii < len(ii_list):
                    ii = ii_list[ii]
                    dp[ii] = min(dp[ii], dp[i] + 1)
    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 84220
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
using namespace std;
int f[105];
int main()
{
	ios::sync_with_stdio(false);
	int n,m,a,b,t,p=0;
	cin>>n>>m;
    a=-1;
	b=-1;
    for(int i=1;i<=m;i++)
    {
    	cin>>f[i];
        if(~f[i]&1)
		{
			continue;
		}
        else if(p==0)
		{
			a=i;
		}
		else if(p==1)
		{
			b=i;
		}
        else
		{
			cout<<"Impossible"<<endl;
			exit(0);
		}
		p++;
    }
    if(a==-1) a=1;
    if(b==-1) b=m;
    t=f[1];
    f[1]=f[a];
    f[a]=t;
    t=f[m];
    f[m]=f[b];
    f[b]=t;
    if(m==1)
	{
		if(f[1]==1)
		{
			cout<<1;
			cout<<endl;
			cout<<1;
			cout<<endl;
			cout<<1;
			cout<<endl;
			exit(0);
		}
	}
    for(register int i=1;i<=m;i++)
    {
    	cout<<f[i]<<' ';
	}
    if(m==1)
	{
		f[1]--;
		cout<<endl;
		cout<<2;
		cout<<endl;
		cout<<f[1];
		cout<<' ';
		cout<<1;
		cout<<endl;
		exit(0);
	}
	cout<<endl;
	if(f[m]>1)
	{
		cout<<m;
	}else{
		cout<<m-1;
	}
	cout<<endl;
	cout<<f[1]+1;
	cout<<' ';
    for(register int i=2;i<m;i++)
	{
		cout<<f[i]<<' ';
	}
    if(f[m]>1)
	{
		cout<<f[m]-1<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,n,a,count=0,counta=0;
  cin>>n;
  for(i=0;i<n;i++){
    count=0;
    cin>>a;
    for(j=2;j*j<=a;j++){
      if(a%j==0){
	    count++;
	    break;
      }
    }
    if(count==0&&a>1)counta++;
  }
  cout<<counta<<endl;
  return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x) & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

const LL mod = 1e9 + 7;

int n, m;

int f[N], c[N];

int Fin(int v) {

    if(f[v] == v) return v;

    return f[v] = Fin(f[v]);

}

void solve() {

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

    rep(i, 1, n) f[i] = i, c[i] = 0;

    rep(i, 1, m) {

        int u, v;

        scanf("%d %d", &u, &v);

        int fu = Fin(u);

        int fv = Fin(v);

        if(fu != fv) f[fu] = fv;

    }

    rep(i, 1, n) {

        c[Fin(i)]++;

    }

    int ans = 0;

    rep(i, 1, n) ans = max(ans, c[i]);

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

}


int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


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

int main() {
  long long N;
  cin>>N;
  long long A=N/3;
  long long B=N/5;
  long long C=N/15;
  cin>>A>>B>>C;
 
  long long  ans=(N*(N+1))/2-(3*A*(A+1))/2-(5*B*(B+1))/2+15*(C*(C+1))/2;
    cin>>ans;
  cout<<ans<<endl;
  
  
}


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

//関数
    
    
    
//main関数
int main() {
    
    
    
    //入力
    int N;
    cin>>N;
    vector<long> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    
    
    
    
    
    
    
    
    
    
    //計算
   /* vector<long> B();
    long sum=10e15;
    int ans=0;
    for(int i=0;i<N;i++){
        sum+=A.at(i);
        ans+=B.at(sum);
        B.at(sum)++;
    }*/
    vector<long> B(N+1);
    B.at(0)=0;
    for(int i=1;i<=N;i++){
        B.at(i)=B.at(i-1)+A.at(i-1);
    }
    
    /*for(int i=0;i<=N;i++){
        cout<<B.at(i)<<" ";
    }
    cout<<endl;*/
    
    sort(B.begin(),B.end());
    
   /* for(int i=0;i<=N;i++){
        cout<<B.at(i)<<" ";
    }
    cout<<endl;*/
    
    vector<long> C(N+2);
    long old=B.at(0);
    long count=1;
    for(int i=1;i<=N;i++){
        if(old==B.at(i)){
            count++;
        }else{
            C.at(count)++;
            old=B.at(i);
            count=1;
        }
    }
    C.at(count)++;
    
    /*for(int i=0;i<N;i++){
        cout <<C.at(i)<<" ";
    }
    cout<<endl;*/
    
    long ans=0;
    for(int i=0; i<N+2;i++){
        ans+=C.at(i)*i*(i-1)/2;
    }
    
    
    
    
    
    
    //出力
    cout <<ans<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    double mean = 0;
    vector<int> x(n);
    for(int i = 0; i < n; i++) {
        cin >> x[i];
        mean += x[i];
    }
    mean /= n;
    int m = (int)(mean + 0.5);
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ans += (x[i] - m) * (x[i] - m);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#if 1

#include <bits/stdc++.h>
using namespace std;
int d[100005];
int n,k;
int a[105];

int main()
{
    scanf("%d %d", &n, &k);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
    }
    d[0] = 0;
    for(int i = 1;i <= k;i++)
    {
        for(int j = 1;j <= n;j++)
        {
            if(i-a[j] >= 0&&d[i-a[j]] == 0)
            {
                d[i] = 1;
            }
        }
    }
    #if 0
    for(int i = 0;i <= k;i++)
    {
        printf("%d ",d[i]);
    }
    #endif
    if(d[k] == 1)
    {
        printf("First");
    }
    else
    {
        printf("Second");
    }
}

#endif // 1++


Measured memory_bytes: 640
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))

res = defaultdict(lambda: 0)
for i in range(N):
    res[A[i]] += 1
    
cnt = len(res) - K
if cnt <= 0:
    print(0)
else:
    res_2 = sorted(res.items(), key=lambda x:x[1])
    ans = 0
    for i in range(cnt):
        ans += res_2[i][1]
    print(ans)


Measured memory_bytes: 39320
n = int(input())

a = [i**5 for i in range(1000)]
for i in range(1000):
    for j in range(i+1, 1000):
        if a[j] - a[i] == n:
            print(j, i)
            exit()
        if a[j] + a[i] == n:
            print(j, -i)
            exit()



Measured memory_bytes: 9192
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    Int n;
    cin >> n;
    Int ans = 0;
    vector<Int> numcnt(100000 + 1, 0);
    for (Int i = 0; i < n; i++) {
        Int a;
        cin >> a;
        numcnt[a]++;

        ans += a;
    }

    Int q;
    cin >> q;
    for (Int i = 0; i < q; i++) {
        Int b, c;
        cin >> b >> c;

        ans += (c - b) * numcnt[b];

        numcnt[c] += numcnt[b];
        numcnt[b] = 0;

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4000
while True:
    n,m = map(int,input().split())
    if n==0: break
    dp = [list(map(int,input().split())) for _ in range(n)]
    dp.sort(key=lambda x:x[1],reverse=True)
    sm = 0
    for d,p in dp:
        d,m = [d-m, 0] if d>m else [0, m-d]
        if m==0: sm += d*p
    print(sm)

Measured memory_bytes: 9904
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    /////////////////////
    // Write code below /
    /////////////////////
    int numberOfP = 0, numberOfW = 0, numberOfG = 0, numberOfY = 0;
    
    int numberOfHinaarare;
    cin >> numberOfHinaarare;
    for (int indexOfHinaarare = 0; indexOfHinaarare < numberOfHinaarare; indexOfHinaarare++) {
        string colorOfHinaarare;
        cin >> colorOfHinaarare;
        if (colorOfHinaarare == "P") {
            numberOfP++;
        } else if (colorOfHinaarare == "W") {
            numberOfW++;
        } else if (colorOfHinaarare == "G") {
            numberOfG++;
        } else if (colorOfHinaarare == "Y") {
            numberOfY++;
        }
    }
    
    int colorCount = 0;
    if (numberOfP) {
        colorCount++;
    }
    if (numberOfW) {
        colorCount++;
    }
    if (numberOfG) {
        colorCount++;
    }
    if (numberOfY) {
        colorCount++;
    }
    
    if (colorCount == 4) {
        cout << "Four" << endl;
    } else if (colorCount == 3) {
        cout << "Three" << endl;
    } else {
        cout << "error" << endl;
    }
    
    return 0;
}


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

using namespace std;

string s;
int main() {
    
    cin>>s;
    if(s=="SAT") cout<<1;
    else if(s=="FRI") cout<<2;
     else if(s=="THU") cout<<3;
      else if(s=="WED") cout<<4;
      else if(s=="TUE") cout<<5;
      else if(s=="MON") cout<<6;
      else if(s=="SUN") cout<<7;
      
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int64_t i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int64_t i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int64_t i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int64_t n; cin >> n;

	int64_t aval[3]; cin >> aval[0] >> aval[1] >> aval[2];
	int64_t bval[3]; cin >> bval[0] >> bval[1] >> bval[2];

	int64_t cs[4] = { n, 0, 0, 0 };

	int64_t max_n = n;
	{
		// A -> B
		{
			int64_t imax = 0;
			if (bval[0] > aval[0]) imax = n / aval[0];
			FOR_LE(i, 0, imax) {
				int64_t r = n - i * aval[0];

				int64_t jmax = 0;
				if (bval[1] > aval[1]) jmax = r / aval[1];
				FOR_LE(j, 0, jmax) {
					int64_t k = 0;
					int64_t r2 = r - j * aval[1];
					if (bval[2] > aval[2]) {
						k = r2 / aval[2];
					}
					int64_t r3 = r2 - k * aval[2];

					max_n = max(max_n, r3 + i * bval[0] + j * bval[1] + k * bval[2]);
				}
			}
		}

		bool unchanged = n == max_n;

		n = max_n;
		// B -> A
		if (unchanged) {
			int64_t imax = 0;
			if (aval[0] > bval[0]) imax = n / bval[0];
			FOR_LE(i, 0, imax) {
				int64_t r = n - i * bval[0];

				int64_t jmax = 0;
				if (aval[1] > bval[1]) jmax = r / bval[1];
				FOR_LE(j, 0, jmax) {
					int64_t k = 0;
					int64_t r2 = r - j * bval[1];
					if (aval[2] > bval[2]) {
						k = r2 / bval[2];
					}
					int64_t r3 = r2 - k * bval[2];

					max_n = max(max_n, r3 + i * aval[0] + j * aval[1] + k * aval[2]);
				}
			}
		}
		else {
			int order[3] = { 0, 1, 2 };
			int c = 0;
			if (aval[0] > bval[0]) {
				order[c] = 0;
				c++;
			}
			if (aval[1] > bval[1]) {
				order[c] = 1;
				c++;
			}
			if (aval[2] > bval[2]) {
				order[c] = 2;
				c++;
			}

			if (c == 0) {
				// Do nothing
			}
			else if (c == 1) {
				int64_t num = max_n / bval[order[0]] * aval[order[0]];
				max_n = max_n % bval[order[0]] + num;
			}
			else {
				int64_t max_prev = max_n;

				int64_t d = bval[order[0]] * bval[order[1]];
				
				int64_t maxi = min(d / bval[order[0]], max_prev / bval[order[0]]);
				FOR_LE(i, 0, maxi) {
					int64_t o0c = i;
					int64_t r = max_prev - o0c * bval[order[0]];

					int64_t o1C = r / bval[order[1]];
					int64_t r2 = r - o1C * bval[order[1]];

					max_n = max(max_n, r2 + o0c * aval[order[0]] + o1C * aval[order[1]]);
				}

				int64_t mini = max(maxi, (max_prev - d) / bval[order[0]]);
				FOR_LE(i, mini, max_prev / bval[order[0]]) {
					int64_t o0c = i;
					int64_t r = max_prev - o0c * bval[order[0]];

					int64_t o1C = r / bval[order[1]];
					int64_t r2 = r - o1C * bval[order[1]];


					max_n = max(max_n, r2 + o0c * aval[order[0]] + o1C * aval[order[1]]);
				}
			}
		}
	}

	cout << max_n << endl;

	return 0;
}


Measured memory_bytes: 256
from itertools import combinations

n = int(input())
r = range(n)
a = [([], []) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].append(x - 1)

fail = lambda x: not all(x.isdisjoint(a[i][0]) and x.issuperset(a[i][1]) for i in x)

while all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int n,m,ans=0;
    cin>>n;
    vi dupli;
    map<int,bool>mp;
    rep(i,n){
        int x;
        cin>>x;
        if(mp[x]){
            dupli.pb(x);
        }
        mp[x]=true;
        m=max(m,x);
    }
    vector<bool> dp(m+1,true);
    for(auto x:dupli)dp[x]=false;
    for(auto x:mp){
        int z=x.first;
        if(dp[z])ans++;
        for(int i=z;i<=m;i+=z){
            dp[i]=false;
        }
    }
    cout<<ans<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 13024