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

namespace AtTest.Dwango5
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            string s = Read();
            int q = ReadInt();
            int[] ks = ReadInts();

            long[] mCnts = new long[n];
            long[] cCnts = new long[n];
            long[] mcCnts = new long[n];
            for (int i = 0; i < n; i++)
            {
                if (i > 0)
                {
                    mCnts[i] = mCnts[i - 1];
                    cCnts[i] = cCnts[i - 1];
                    mcCnts[i] = mcCnts[i - 1];
                }
                if (s[i] == 'M') mCnts[i]++;
                if (s[i] == 'C')
                {
                    cCnts[i]++;
                    mcCnts[i] += mCnts[i];
                }
            }

            for (int i = 0; i < q; i++)
            {
                long res = 0;
                for (int j = 0; j < n; j++)
                {
                    if (s[j] != 'D') continue;

                    int maxI = Math.Min(j + ks[i] - 1, n - 1);
                    res += mcCnts[maxI] - mcCnts[j]
                        - (cCnts[maxI] - cCnts[j]) * mCnts[j];
                }
                Console.WriteLine(res);
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 36352
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

// disjoin set
public class Main {
    static class UnionFind {

        private int parent[];
        private int rank[];

        public UnionFind(int Num_element) {
            parent = new int[Num_element];
            rank = new int[Num_element];
            for (int i = 0; i < Num_element; i++)
                parent[i] = i;
        }
        public void makeSet(int x) {
            parent[x] = x;
            rank[x] = 0;
        }

        public void union(int x, int y) {
            link(findSet(x), findSet(y));
        }

        public int findSet(int x) {
            if (parent[x] != x) {
                parent[x] = findSet(parent[x]);
            }
            return parent[x];
        }


        public void link(int x, int y) {
            if (rank[x] > rank[y]) {
                parent[y] = x;
            } else {
                parent[x] = y;
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }
        public void command(int com, int x, int y){
            if(com == 0){
               //unite
                union(x,y);
            }else{
                //same
                if( findSet(x) == findSet(y))
                    System.out.println("1");
                else
                    System.out.println("0");
            }
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Disjoin set element number
        int Num_element;

        //Query times
        int Num_query;


            Num_element = sc.nextInt();
            Num_query = sc.nextInt();
            UnionFind Disjoin_set = new UnionFind(Num_element);
            for (int i=0;i<Num_query;i++){
                // '0' denotes unite and '1' denotes same operation.
                int com = sc.nextInt();
                int x = sc.nextInt();
                int y = sc.nextInt();
                Disjoin_set.command(com,x,y);
            }

    }
}



Measured memory_bytes: 102500
import numpy as np
a,b,h,m=map(int,input().split())
s=abs(6*m-30*(h+m/60))
t=min(s,360-s)
t=np.deg2rad(t)
c=(a**2+b**2-2*a*b*np.cos(t))**(1/2)
print(c)

Measured memory_bytes: 27200
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <unordered_map>
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define ll long long
#define INF ((1<<30)-1)
#define NEG (-1)
#define MOD 1000000007
#define MAXN 100100
#define EPS 1e-9
#define INFLL 1e18
using namespace std;
FILE *in,*out;

int N,M,K;
pair<int,int> ar[200100];
int sum[510];
int res[510][510];

int read()
{
    int i,j,k;
    fscanf(in,"%d%d%d",&K,&N,&M);
    for(i=0;i<N;i++)
    {
        fscanf(in,"%d%d",&j,&k);
        ar[i].f = j;
        ar[i].s = k;
    }
    sort(ar,ar+N);
    for(i=N-1;i>=0;i--)
    {
        for(j=i;j>=0 && ar[j].f == ar[i].f; j--)
            sum[ar[j].s] ++;
        
        for(k=0;k<=K;k++)
            res[ar[i].f][k] = sum[k] + res[ar[i].f][k-1];
        // for(k=0;k<=K;k++)
        // {
        //     printf("%d(%d) ",sum[k],res[i][k]);
        // }
        // printf("\n");
        i = j+1;
    }
    for(i=K;i>=0;i--)
    {
        for(j=0;j<=K;j++)
        {
            res[i][j] = max(res[i][j],res[i+1][j]);
        }
    }
    // for(i=0;i<=K;i++)
    // {
    //     for(j=0;j<=K;j++)
    //     {
    //         printf("%d ",res[i][j]);
    //     }
    //     printf("\n");
    // }
    for(i=0;i<M;i++)
    {
        fscanf(in,"%d%d",&j,&k);
        printf("%d\n",res[j][k]);
    }
    
    return 0;
}

int main()
{
    // in = fopen("A.in","r");
    // out  = fopen("A.out","w");
    in = stdin;
    out = stdout;
    read();
    return 0;
}
//////////// Local Snippets
// forx
// fory
// vectorx
// pairx
// sizex

Measured memory_bytes: 3456
N = int(input())
S = input()

ture_count_list = []
for i in range(1, N):
    count_list = []
    left_S_list = []
    for s in S[0:i]:
        if s not in left_S_list:
            left_S_list.append(s)
        else:
            pass
    for m in left_S_list:
        if m in S[i:]:
            count_list.append(True)
        else:
            count_list.append(False)
        ture_count_list.append(count_list.count(True))


print(max(ture_count_list))


Measured memory_bytes: 3060
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef long long int ll ;
typedef unsigned long long int ull;
using namespace std;
int main(){
    
    ll n;
    cin>>n;
    ll ans=LLONG_MAX;
    int flag=0;
    for(int i=1;i<=9;i++){
        if(n%i==0){
            ll val= n/i;
            if(1<=val && val<=9){ flag=1; break; }
            
        }
    }
    if(flag) cout<<"Yes";
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
const int maxn = 200005;
int f[maxn], nxt[maxn][26], last[26], n;
char s[maxn];
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	rep (i, 0, 25) nxt[n][i] = last[i] = n + 1;
	per (i, n-1, 0) {
		last[s[i+1]-'a'] = i + 1;
		rep (j, 0, 25) nxt[i][j] = last[j];
	}
	memset(f, 0x3f, sizeof f); f[n+1] = 0;
	per (i, n, 0) rep (j, 0, 25)
		f[i] = min(f[i], f[nxt[i][j]] + 1);
	int cur = 0;
	while (cur <= n)
		rep (i, 0, 25) if (f[cur] == f[nxt[cur][i]] + 1) {
			putchar('a' + i); cur = nxt[cur][i]; break;
		}
	return 0;
}

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



int main() {
    int a, b;
    cin >> a >> b;
    
    int sum = 1, cnt = 0;
    while(sum < b) {
        sum += a-1;
        cnt++;
    }
    
    cout << cnt << endl;
    
    
    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a) 
int main(){
  int n;
  cin>>n;
  ll a[n],b[n],c[n];
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  rep(i,n)cin>>c[i];
  ll ans =0;
  sort(a,a+n);sort(c,c+n);
  rep(i,n){

      ans+=(lower_bound(a,a+n,b[i])-a)*(n-(upper_bound(c,c+n,b[i])-c));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define mod 998244353
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}

struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        return p1.first<p2.first;
    }
}; 


int main(){
	ll x;cin>>x;
	if(x>=400 &&x<=599){
		cout<<8<<endl;
	}
	if(x>=600 &&x<=799){
		cout<<7<<endl;
	}	
	if(x>=800 &&x<=999){
		cout<<6<<endl;
	}
	if(x>=1000 &&x<=1199){
		cout<<5<<endl;
	}
	if(x>=1200 &&x<=1399){
		cout<<4<<endl;
	}
	if(x>=1400 &&x<=1599){
		cout<<3<<endl;
	}
	if(x>=1600 &&x<=1799){
		cout<<2<<endl;
	}			
	if(x>=1800 && x<=1999){
		cout<<1<<endl;
	}		
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>

using namespace std;

int main()
{
  long long X;
  cin >> X;

  long long ans = 0;
  ans += (X / 500) * 1000;
  X -= (X / 500) * 500;
  ans += (X / 5)*5;

  cout << ans << endl;
}

Measured memory_bytes: 256
# C - Maximal Value
def main():
    n = int(input())
    b = list(map(int, input().split()))
    a = []

    for i in range(n):
        if i == 0:
            a.append(b[0])
        elif i == n - 1:
            a.append(b[-1])
        else:
            a.append(min(b[i-1], b[i]))

    print(sum(a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9144
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

main(){
	int n,k;
	cin>>n>>k;
	int a[k]={};
	rep(i,k)cin>>a[i];
	sort(a,a+k);rev(a,a+k);
	int t=0;
	for(int i=1;i<k;i++)t+=a[i];
	debug(a[0],t);
	dump(max(a[0]-t-1,0ll));
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct
{
    char name[16];
    int time;
} proc;

#define QUEUE_SIZE (200000)
proc queue[QUEUE_SIZE];
int front;
int rear;

void qpush(proc p)
{
    queue[rear] = p;
    rear = (rear + 1) % QUEUE_SIZE;
}

proc qfront(void)
{
    return (queue[front]);
}

void qpop(void)
{
    front = (front + 1) % QUEUE_SIZE;
}

int main(void)
{
    int n, q;
    proc tmp;
    int current;
    int i;

    scanf("%d %d", &n, &q);
    for (i = 0; i < n; i++){
        scanf("%s %d", tmp.name, &tmp.time);
        qpush(tmp);
    }

    current = 0;
    while (front != rear){
        tmp = qfront();
        qpop();

        if (tmp.time <= q){
            current += tmp.time;
            printf("%s %d\n", tmp.name, current);
        }
        else {
            current += q;
            tmp.time -= q;
            qpush(tmp);
        }
    }

    return 0;
}

Measured memory_bytes: 4296
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int fa=0,fb=0;
	cin>>s;
	for(int i=0;i<3;i++){
		if(s[i]=='A')fa=1;
		else if(s[i]=='B')fb=1;
	}
	if(fa&&fb)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

using namespace std;

vector <pair<int, int> > a[2];
char s[1000005];

bool cmp(pair<int, int> u, pair<int, int> v) {
	return u.second - u.first < v.second - v.first;
}

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		
		int cur = 0;
		int cost = 0;
		int l = strlen(s);
		
		for (int j = 0; j < l; j++) {
			if (s[j] == '(') cur++;
			else cur--;
			cost = max(cost, -cur);
		}
		
		if (cur >= 0) a[0].push_back(make_pair(cost, cur));
		else a[1].push_back(make_pair(cost, -cur));
	}
	
	sort(a[0].begin(), a[0].end());
	sort(a[1].begin(), a[1].end(), cmp);
	
	int now = 0;
	bool gg = 0;
	
	for (int i = 0; i < a[0].size(); i++) {
		if (now < a[0][i].first) gg = 1;
		now += a[0][i].second;
	}
	
	for (int i = 0; i < a[1].size(); i++) {
		if (now < a[1][i].first) gg = 1;
		now -= a[1][i].second;
	}
	
	if (gg || now != 0) printf("No\n");
	else printf("Yes\n");
}


Measured memory_bytes: 11196
while True:
    n = int(input())
    if n == 0: break
    xs = [(0, 0)]
    dic = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    maxX, minX, maxY, minY = 0, 0, 0, 0
    for i in range(n - 1):
        n, d = map(int, input().split())
        xs.append((xs[n][0] + dic[d][0], xs[n][1] + dic[d][1]))
        if xs[-1][0] > maxX: maxX = xs[-1][0]
        elif xs[-1][0] < minX: minX = xs[-1][0]
        if xs[-1][1] > maxY: maxY = xs[-1][1]
        elif xs[-1][1] < minY: minY = xs[-1][1]
    print(maxX - minX + 1, maxY - minY + 1)

Measured memory_bytes: 7608
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

@njit((i8, i8, i8, i8[:,:]), cache=True)
def solve(R,C,K,item):
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j][k] = np.maximum(new_dp[j][k],new_dp[j-1][k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i-1][j-1])
  ans = dp[-1].max()
  return ans

R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
  r,c,v = map(int, input().split())
  item[r-1,c-1] = v
print(solve(R,C,K,item))


Measured memory_bytes: 177012
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y ;
  int ans=0 ;
  cin >> x >> y ;
  for(int i=0 ; i<2 ; i++){
    if(x<y){
      ans= ans+y ;
      y-- ;
    }
    else{
      ans= ans+x ;
      x-- ;
    }
  }
  cout<< ans <<endl ;
}
      

Measured memory_bytes: 256
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
	int n  ;
	double d ;
	cin>>n>>d ;
	int cou = 0 ;
	rep(i , n){
		double x , y ;
		cin>>x>>y ;
		double dis = x*x + y*y ;
		if(sqrt(dis)<=d){
			cou++;
		}
	}
	cout<<cou;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3828
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    n = int(input().strip())
    parts("", 0, 0, n)


def parts(char, pos, used, n):
    if pos == n:
        print(char)
        return

    a_ord = ord("a")
    for u in range(used):
        parts(char + chr(a_ord + u), pos + 1, used, n)
    u = used + 1
    parts(char + chr(a_ord + u - 1), pos + 1, u, n)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4404
# input
n = int(input())
h = [int(i) for i in input().split()]

# main
h.reverse()
flag = True
for i in range(n-1):
  if h[i+1] == h[i]+1:
    h[i+1] -= 1
  if h[i+1] > h[i]+1:
    flag = False
    break

# output
if flag:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n, ans;
vector<pair<int, int> > red, blue;
bool checked_red[210];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        red.pb(mp(x, y));
    }
    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        blue.pb(mp(x, y));
    }
    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());
    rep(i, 0, n) {
        int min_itr = -1, min_dis = INF;
        rep(j, 0, n) {
            if (!checked_red[j] && red[j].first < blue[i].first && red[j].second < blue[i].second) {
                if (blue[i].second - red[j].second < min_dis) {
                  min_dis = blue[i].second - red[j].second;
                  min_itr = j;
                }
            }
        }
        if (min_itr != -1) {
            checked_red[min_itr] = true;
            ans++;
        } 
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
sw_list = []
for i in range(M):
    sw_list.append(list(map(int,input().split()))[1:])
zero_or_one = list(map(int,input().split()))

cnt = 0
for i in range(2**N):
    on_off = list(map(int,list(bin(i)[2:].zfill(N))))
    for j in range(M):
        on = 0
        for index in sw_list[j]:
            on += on_off[index-1]
        if on%2 != zero_or_one[j]:
            break
    else:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
class UnionFind:
    def __init__(self, N):
        # negative value: represents the root of a tree; its absolute value is the size of the tree
        # positive value: the parent's index
        self.vertices = [-1 for _ in range(N)]
        self.rank = [0] * N
        
    def find(self, v):
        if self.vertices[v] < 0: # v is a root
            return v
        else:
            # path compression: reconnect v to the root
            self.vertices[v] = self.find(self.vertices[v])
            return self.vertices[v]
        
    def union(self, u, v):
        s1 = self.find(u) # the root of the tree including vertex u
        s2 = self.find(v) # the root of the tree including vertex v
        
        if s1 == s2: # u and v is in the same tree
            return False
        
        if self.rank[s1] > self.rank[s2]: # the tree including u is taller
            self.vertices[s1] += self.vertices[s2] # update the size of the bigger tree
            self.vertices[s2] = s1
        else: # the tree including v is taller
            self.vertices[s2] += self.vertices[s1] # update the size of the bigger tree
            self.vertices[s1] = s2
            if self.rank[s1] == self.rank[s2]:
                self.rank[s2] += 1
        return True
        
    def is_connected(self, u, v):
        return self.find(u) == self.find(v)
    
    def size(self, v):
        return -self.vertices[self.find(v)]
        
    def is_connected(self, u, v):
        return self.find(u) == self.find(v)
    
    def size(self, v):
        return -self.vertices[self.find(v)]

class Kruskal:
    def __init__(self, N):
        self.N = N # #vertices
        self.E = []

    def add_edge(self, init, end, weight):
        self.E.append((weight, init, end))
        
    def min_spanning_tree(self):
        N, E = self.N, self.E
        weight = 0; edges = []
        n_edges = 0
        uf = UnionFind(N) # for judging connectivity
        E = sorted(E)
        for w, a, b in E:
            if uf.union(a, b):
                edges.append((a, b))
                n_edges += 1; weight += w
            if n_edges == N - 1: break
        return edges, weight

N, M = map(int, input().split())
kr = Kruskal(N)
for _ in range(M):
    a, b, c = map(int, input().split())
    kr.add_edge(a, b, c)
_, ans = kr.min_spanning_tree()
print(ans)


Measured memory_bytes: 24380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
  string s;
  cin >> s;
  string t = s;
  reverse(ALL(t));
  if(s == t) cout << "Yes" << endl;
  else cout << "No" << endl;
    return 0;
}


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



void solve(){
    
    string n; cin >> n;
    int rem = 0;
    for(char c : n){
        rem = (rem * 10) + (c - '0');
        rem %= 9;
    }
    cout << (rem ? "No" : "Yes") << '\n';
    
}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false); cin.tie(0);

    int t = 1;
    // cin >> t;


    for(int i = 1; i <= t; i++){
        // cout << "Case #" << i << ": ";

        solve();

    }
    return 0;
}

Measured memory_bytes: 3780
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------


int dp[510][510];//とおった記録
char c[510][510];//めいろ本体
ll h,w;
queue<int> qx;
queue<int> qy;

int in(ll x,ll y){
    if(x<0 || y<0 || w<=x || h<=y){
        return 0;
    }
    return 1;
}

ll DFS(ll sx,ll sy){
    ll nx,ny,x,y;

    REP(i,w)REP(j,h)dp[i][j]=-1;

    qx.push(sx);
    qy.push(sy);

    dp[sx][sy]=0;

    for(;;){
        if(qx.empty()){return 0;}

        x=qx.front();
        y=qy.front();
        qx.pop();
        qy.pop();

        REP(i,4){
            nx=x+dx[i];
            ny=y+dy[i];
            if(in(nx,ny) && dp[nx][ny]==-1){

                //if障害物ですすめない
                if(c[nx][ny]=='#')continue;

                dp[nx][ny]=dp[x][y]+1;
                qx.push(nx);
                qy.push(ny);
            }
        }

    }
    return 0;
}




int main(){

    cin>>h>>w;
    ll wall=0;
    REP(j,h)REP(i,w){
        cin>>c[i][j];
        if(c[i][j]=='#')wall++;
    }

    


    DFS(0,0);//(x,y)から探索

    if(dp[w-1][h-1]==-1){
        cout<<-1<<endl;
    }else{
        cout<<w*h-dp[w-1][h-1]-1-wall<<endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(void)
{
	int n;
	scanf("%d",&n);
	int cnt = 0;
	for(int i=1; i<=n; ++i)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(a == b) ++cnt;
		else cnt = 0;
		
		if(cnt >= 3) return printf("Yes"), 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 1736
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String S = in.readLine();
		if (S.equals("ABC")) {
			System.out.println("ARC");
		} else {
			System.out.println("ABC");
		}
	}

	void calc() {
	}

	void showResult() {
	}

}


Measured memory_bytes: 32376
a,b = input().split()
a = int(a)
b = int(b)
xy = [map(int, input().split()) for _ in range(a)]
x, y = [list(i) for i in zip(*xy)]

ans = 0

for i in range(a):
    if (x[i]**2 + y[i]**2)**0.5 <= b:
        ans +=1
    else:
        continue
print(ans)

Measured memory_bytes: 116728
[N,K] = list(map(int,input().split()))
x = list(map(int,input().split()))

#連続する蝋燭を全探索
l=0
r=K-1

ans=2*(10**9)+1
for i in range(N-K+1):
    # print('x[l], x[r]:', x[l], x[r])
    ans = min(ans, min(abs(x[l]), abs(x[r])) + x[r]-x[l])
    l+=1
    r+=1

print(ans)


Measured memory_bytes: 84576
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli inf = 1e16;

bool dfs(int n, vector<vector<pair<int, lli> > > &adj, vector<bool> &used, vector<lli> &pos){
	used[n] = true;
	for(int i=0; i<(int)adj[n].size(); i++){
		int npos = adj[n][i].first;
		lli d = adj[n][i].second;
		if(used[npos]){
			if(pos[npos] != pos[n]+d) return false;
		}else{
			pos[npos] = pos[n]+d;
			bool ret = dfs(npos, adj, used, pos);
			if(!ret) return false;
		}
	}
	return true;
}

int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<pair<int, lli> > > adj(n);
	for(int i=0; i<m; i++){
		lli l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		adj[l].push_back(make_pair(r, d));
		adj[r].push_back(make_pair(l, -d));
	}
	
	vector<bool> used(n, false);
	vector<lli> pos(n, 0);
	bool success = true;
	for(int i=0; i<n; i++){
		if(used[i]) continue;
		bool ret = dfs(i, adj, used, pos);
		if(!ret){
			success = false;
			break;
		}
	}
	if(success){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 18304
#include<algorithm>
#include<iostream>

const int INF = 1 << 29;

typedef std::pair<int, int> P;

int n;

int main()
{
	while( std::cin >> n, n )
	{
		int d[10][10], v = 0;

		for( int i = 0; i != 10; ++i )
			for( int j = 0; j != 10; ++j )
				d[i][j] = i == j ? 0 : INF;

		for( int i = 0; i != n; ++i )
		{
			int a, b, c;
			std::cin >> a >> b >> c;
			d[a][b] = d[b][a] = c;
			v = std::max( v, std::max( a, b ) );
		}

		for( int k = 0; k <= v; ++k )
			for( int i = 0; i <= v; ++i )
				for( int j = 0; j <= v; ++j )
					d[i][j] = std::min( d[i][j], d[i][k] + d[k][j] );
	
		P ans( INF, INF );
		for( int i = 0; i <= v; ++i )
		{
			P sum( 0, i );
			for( int j = 0; j <= v; ++j )
				sum.first += d[i][j];

			ans = std::min( ans, sum );
		}

		std::cout << ans.second << ' ' << ans.first << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int D;
cin>>D;
string ans="Christmas";
rep(i,25-D)ans+=" Eve";
cout<<ans<<endl;
//system("pause");
return 0;
}

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

int main(){
  int i,x;
  i = 1;
  while(1) {
    cin >> x;
    if (x == 0){
      break;
    }
    cout << "Case" << " " << i << ":" << " " << x << endl;
    i = i + 1;
  }
  return 0;
  }


Measured memory_bytes: 3012
# 初期入力
import sys
input = sys.stdin.readline
a =[]
for i in range(5):
    x = int(input())
    a.append(x)
k = int(input())

#ソートして最大と最小を比較
if a[-1] -a[0] >k:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> v[100005];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    priority_queue<int> pq;
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        for (int x : v[i]) pq.push(x);
        if (pq.empty()) continue;
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    ll N,M;
    ll waru = 1000000007;
    cin >> N >> M;
    vector<ll> a(M);
    if(M != 0)
    {
        rep(i,M) cin >> a[i];
    }
    vector<ll> DP;
    DP.push_back(1);
    ll M_count = 0;
    for(ll i = 1; i < N+1; i++)
    {
        if(M != 0)
        {
            if(a[M_count] == i)
            {
                DP.push_back(0);
                if(M_count + 1 != M) M_count++;
            }
            else
            {
                if(DP.size() > 1)DP.push_back((DP[DP.size()-1]+DP[DP.size()-2])%waru);
                else DP.push_back(DP[0]);
            }
        }
        else
        {
            if(DP.size() > 1)DP.push_back((DP[DP.size()-1]+DP[DP.size()-2])%waru);
            else DP.push_back(DP[0]);
        }
    }
    //rep(i,DP.size())cout << DP[i] << endl;
    if(DP[DP.size()-1] != 0) cout << DP[DP.size()-1] << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
using namespace std;
const int N=2e5+5;
int inf=0x3f3f3f3f;
typedef pair<int,int> pa;

double PI=3.141592654;

int main()
{
    double r;
     cin>>r;
     cout<<2*r*PI;
   return 0;
}


Measured memory_bytes: 3192
N = int(input())
array = list(map(int, input().split()))
sameNum = [0]*(N)
sum = 0
# kを削除していないlistでの組み合わせを調べる
for i in range(N):
    sameNum[array[i]-1] += 1
for i in range(N):
    sum += sameNum[i]*(sameNum[i]-1)//2

for k in range(1, N+1):
    sumT = sum
    print(sumT - sameNum[array[k-1]-1] + 1)

Measured memory_bytes: 81612
s=input()
k=int(input())

l=[]
st=set()
n=len(s)
for i in range(1,min(n,5)+1):
    for j in range(n+1-i):
        tmp=s[j:j+i]
        if tmp not in st:
            l.append(tmp)
            st.add(tmp)
l.sort()
print(l[k-1])

Measured memory_bytes: 4592
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n; cin >> n;
	vector<int> vs(n);
	for(auto &x:vs) cin >> x;
	sort(all(vs));
	int s1 = n, s2 = 0;
	int ans = 0;
	int i=0;
	for(int k=0; i<n and k<100010; ++k){
		if(s1==s2) ++ans;
		while(i<n and vs[i]<=k)
			s1--, s2++, ++i;
	}
	if(s1==s2) ++ans;
	cout << ans << endl;
}


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

int main(){

	double students[1001] = {0};
	double n, sum, ave, DeviationSum, StandardDeviation;

	cin >> n;
	while( n > 0 ){
		/* 要素の代入と合計値:sumと平均値:aveと偏差の和:deviationSumを宣言 */
		sum = ave = DeviationSum = 0;
		for(int i = 1; i <= n; i++){
		cin >> students[i];
		sum += students[i];
		}
		ave = sum / n;

		/* 偏差(deviation)の計算 */
		for(int i = 1; i <= n; i++){
			DeviationSum += pow(students[i]-ave,2);
		}

		/* 標準偏差(standard deviation)の計算 */
		StandardDeviation = sqrt(DeviationSum/n);

		printf("%.8f\n", StandardDeviation);
		cin >> n;
	}

	return 0;
}

/******************************************************************/
//注意点↓↓↓↓

//文章では、平均はmで宣言している
//プログラム上では、ave に変更している。

//用語の説明↓↓↓↓

//偏差(deviation)とは、個々の数値と平均値との差のことです。
//個々のデータが平均値から偏っている程度を表しています。
//偏差 = si - ave 
// siは個々の数値
// aveは平均値


//ここも重要点↓↓↓↓

//分散(dispersion)：偏差の二乗平均
//標準偏差(StandardDeviation)：正の偏差の二乗平均の平方根

/******************************************************************/


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

int main() {
  int N;
  long long X;
  cin >> N >> X;
  long long res = 1;
  long long S = 0;
  for (int i = 0; i < N; ++i) {
    long long v;
    cin >> v;
    S += v;
    if (S <= X) ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>

#define n(a,b) number[zyun[a][b]]
#define e(a) enzansi[enzan[a]]

int calc(int,int,int);

int main(void) {
	int zyun[24][4]={
		{0,1,2,3},
		{0,1,3,2},
		{0,2,1,3},
		{0,2,3,1},
		{0,3,1,2},
		{0,3,2,1},
		{1,0,2,3},
		{1,0,3,2},
		{1,2,0,3},
		{1,2,3,0},
		{1,3,0,2},
		{1,3,2,0},
		{2,0,1,3},
		{2,0,3,1},
		{2,1,0,3},
		{2,1,3,0},
		{2,3,0,1},
		{2,3,1,0},
		{3,0,1,2},
		{3,0,2,1},
		{3,1,0,2},
		{3,1,2,0},
		{3,2,0,1},
		{3,2,1,0}
	};
	char enzansi[3][2]={"+","-","*"};
	int number[4];
	int order,enzan[3];
	while(1) {
		scanf("%d %d %d %d",&number[0],&number[1],&number[2],&number[3]);
		if(number[0]==0 && number[1]==0 && number[2]==0 && number[3]==0)break;
		for(order=0;order<24;order++) {
			for(enzan[0]=0;enzan[0]<3;enzan[0]++) {
				for(enzan[1]=0;enzan[1]<3;enzan[1]++) {
					for(enzan[2]=0;enzan[2]<3;enzan[2]++) {
						if(calc(
							calc(
								calc(n(order,0),n(order,1),enzan[0])
								,n(order,2),enzan[1])
							,n(order,3),enzan[2])==10) {
							printf("(((%d %s %d) %s %d) %s %d)\n",
								n(order,0),e(0),n(order,1),
								e(1),n(order,2),e(2),n(order,3));
							goto out;
						}
						if(calc(
							calc(n(order,0),n(order,1),enzan[0]),
							calc(n(order,2),n(order,3),enzan[1]),
							enzan[2])==10) {
							printf("((%d %s %d) %s (%d %s %d))\n",
								n(order,0),e(0),n(order,1),
								e(2),n(order,2),e(1),n(order,3));
							goto out;
						}
						if(calc(
							calc(n(order,0),
								calc(n(order,1),n(order,2),enzan[0]),
								enzan[1]),
							n(order,3),enzan[2])==10) {
							printf("((%d %s (%d %s %d)) %s %d)\n",
								n(order,0),e(1),n(order,1),e(0),
								n(order,2),e(2),n(order,3));
							goto out;
						}
						if(calc(
							n(order,0),
							calc(
								calc(n(order,1),n(order,2),enzan[0]),
								n(order,3),enzan[1]),
							enzan[2])==10) {
							printf("(%d %s ((%d %s %d) %s %d))\n",
								n(order,0),e(2),n(order,1),e(0),
								n(order,2),e(1),n(order,3));
							goto out;
						}
						if(calc(
							n(order,0),
							calc(
								n(order,1),
								calc(n(order,2),n(order,3),enzan[0]),
								enzan[1]),
							enzan[2])==10) {
							printf("(%d %s (%d %s (%d %s %d)))\n",
								n(order,0),e(2),n(order,1),e(1),
								n(order,2),e(0),n(order,3));
							goto out;
						}	
					}
				}
			}
		}
		printf("0\n");
		out:;
	}
}

int calc(int a,int b,int enzansi) {
	switch(enzansi) {
		case 0:return a+b;break;
		case 1:return a-b;break;
		case 2:return a*b;break;
		default:
			return 0x7fffffff;
			break;
	}
	return 0x7fffffff;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long LL;

char a[105], b[105];

int main() {
	int flag = 0, l, ll, cnt = 0;
	scanf("%s %s", a, b);
	l = strlen(a); ll = strlen(b);
	sort(a, a + l);
	sort(b, b + ll);
	for(int i = 0; i < l; i++) {
		for(int j = 0; j < ll; j++) {
			if(a[i] == b[j]) cnt++;
			if(a[i] < b[j]) {
				flag = 1;
				break;
			}
		}
	}
	if(l < ll && cnt == l * ll) cout << "Yes" << endl;
	else if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
//=========================
//  author:hliwen
//  date:2020.1.19
//=========================
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define DEBUG puts("ok")
#define tie0 cin.tie(0),cout.tie(0)
#define fastio ios::sync_with_stdio(false)
#define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout)
using namespace std;
typedef long long ll;

template <typename T> inline void read(T &x) {
	T f = 1; x = 0; char c;
    for (c = getchar(); !isdigit(c); c = getchar()) if (c == '-') f = -1;
    for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x *= f;
}

int main() {
	int n, m;
	read(n), read(m);
	if (m < n) puts("No");
	else puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if(a+b<=a+c&&a+b<=c+b){
		printf("%d\n",a+b);
	}
	else if(a+c<=a+b&&a+c<=b+c){
		printf("%d\n",a+c);
	}
	else if(b+c<=a+b&&b+c<=a+c){
		printf("%d\n",b+c);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
ll n,m,k;
string s;
int main(){
    cin >> n >> m;
    ll res = 0;
    if(n == 1 && m == 1) res += 400000;
    res += max(300000-(n-1)*100000,0);
    res += max(300000-(m-1)*100000,0);
    cout << res << ednl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#define null NULL
#define maxn 4000
using namespace std;
struct pNode
{
    int xl,xr,y,type;
};
pNode g[maxn];
int dx[maxn],compress[maxn];

struct Node
{
    int dl,dr,cnt;
    long long s;
    Node *pl,*pr;
};
int n;

void build(Node *&p,int l,int r)
{
    p=(Node *)malloc(sizeof(Node));
    p->dl=l,p->dr=r,p->s=0,p->cnt=0;
    p->pl=null,p->pr=null;
    int mid=(l+r)/2;
    if(r>l)
    {
        build(p->pl,l,mid);
        build(p->pr,mid+1,r);
    }
}

void preorder(Node *p)
{
    if(p!=null)
    {
        printf("%d %d %d %lld\n",p->dl,p->dr,p->cnt,p->s);
        preorder(p->pl);
        preorder(p->pr);
    }
}

void modify(Node *&p)
{
    if(p->cnt>0)
        p->s = compress[p->dr+1]-compress[p->dl];
    else
        p->s=p->pl->s+p->pr->s;
}
void update(Node *&p,int l,int r,int type)
{
    if(p->dl==l &&p->dr==r)
    {
        if(type==0)
        {
            p->cnt += 1;
            p->s = compress[p->dr+1]-compress[p->dl];
        }else
        {
            p->cnt -= 1;
            if(p->cnt==0)
            {
                if(p->dl==p->dr)
                    p->s=0;
                else
                    p->s=p->pl->s+p->pr->s;
            }
        }
        return ;
    }
    int mid=(p->dl+p->dr)/2;
    if(r<=mid)
        update(p->pl,l,r,type);
    else if(l>mid)
        update(p->pr,l,r,type);
    else
        update(p->pl,l,mid,type),update(p->pr,mid+1,r,type);
    if(p->cnt>0)
        p->s = compress[p->dr+1]-compress[p->dl];
    else
        p->s=p->pl->s+p->pr->s;
}

bool cmpy(pNode a,pNode b)
{
    return a.y<b.y;
}
int main()
{
    int i,j,t,x1,y1,x2,y2;
    Node *tree=null;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        dx[2*i]=x1,dx[2*i+1]=x2;///x轴离散化
        g[2*i].xl=x1,g[2*i].xr=x2,g[2*i].y=y1,g[2*i].type=0;///表示矩形的下边线
        g[2*i+1].xl=x1,g[2*i+1].xr=x2,g[2*i+1].y=y2,g[2*i+1].type=1;///表示矩形的上边线
    }
    sort(dx,dx+2*n);
    t=dx[0],i=0,j=0;
    while(i<2*n)
    {
        compress[j++]=t;
        while(dx[i]==t) i++;
        t=dx[i];
    }
    ///compress数组一共num个数字，下标为0~num-1
    int num=j;

    sort(g,g+2*n,cmpy);
    build(tree,0,num-2);
    //preorder(tree);
    long long ans=0;
    for(i=0;i<2*n;i++)
    {
        int xl=lower_bound(compress,compress+num,g[i].xl)-compress;
        int xr=lower_bound(compress,compress+num,g[i].xr)-compress;
        if(i>0)
            ans += (g[i].y-g[i-1].y)*tree->s;
        update(tree,xl,xr-1,g[i].type);
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

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

    int a, b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 3600
INF = 10**9 + 7


def main():
    N, W = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(N)]

    dp = [[INF]*(10**5 + 1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(10**5 + 1):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if 0 <= j - A[i][1]:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j - A[i][1]] + A[i][0])
    ans = 0
    for j in range(10**5+1)[::-1]:
        if dp[N][j] <= W:
            ans = j
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 152796
#include <bits/stdc++.h>
using namespace std;
 
typedef pair <int, int> ii;
 
const int Maxn = 52;
 
int n;
int X[Maxn], Y[Maxn];
map <ii, int> M;
 
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d %d", &X[i], &Y[i]);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            int dx = X[i] - X[j], dy = Y[i] - Y[j];
            if (dx || dy) M[ii(dx, dy)]++;
        }
    int mx = 0;
    for (map <ii, int>::iterator it = M.begin(); it != M.end(); it++)
        mx = max(mx, it->second);
    printf("%d\n", n - mx);
    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/perl

use strict;
use warnings;

my ($n, $k);
{
    my $in = <STDIN>;
    ($n, $k) = split(" ", $in);
}
my $ans = 0;
while ($n > 0)
{
    $n = int($n / $k);
    $ans++;
}

print "$ans\n";

Measured memory_bytes: 640
n=int(input())
T,A=map(int,input().split())
for i in range(n-1):
    t,a=map(int,input().split())
    num1=-1*(T//-t)
    num2=-1*(A//-a)
    T=t*max(num1,num2)
    A=a*max(num1,num2)
print(T+A)


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100005;
const int mod=1e9+7;
int n,ans;
char s[maxn];
int sum[maxn],dp[maxn],nxt[maxn][3];

int main(){
	s[0]='$';scanf("%s",s+1);n=strlen(s)-1;
	REP(i,n)sum[i]=sum[i-1]+(s[i]-'a'+1);
	rep(j,3){
		nxt[n+1][j]=n+1;
		for(int i=n;i>=1;i--){
			nxt[i][j]=nxt[i+1][j];
			if(sum[i]%3==j)nxt[i][j]=i;
		}
	}
	dp[0]=1;
	int cur=1;
	REP(i,n){
		dp[i]+=dp[i-1];
		if(dp[i]>=mod)dp[i]-=mod;
		int c=(sum[i-1]+(s[i]=='a'?2:1))%3;
		cur=max(cur,i+1);
		while(cur<=n&&s[cur-1]!=s[cur])cur++;
		if(i==1&&cur==n+1){
			puts("1");
			return 0;
		}
		int j=nxt[cur][c];
		if(j<=n){
			dp[j]+=dp[i-1];
			if(dp[j]>=mod)dp[j]-=mod;
		}
	}
	REP(i,n)if((sum[n]-sum[i])%3==0){
		ans+=dp[i];
		if(ans>=mod)ans-=mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
using System; class Program { static void Main(string[] args) { int a, b, d, r; double f; string[] num = Console.ReadLine().Split(' '); a = int.Parse(num[0]); b = int.Parse(num[1]); d = a / b; r = a % b; f = (double)a / b; Console.Write(d + " " + r + " "); Console.WriteLine("{0:0.000000}", f); } } 


Measured memory_bytes: 9288