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

typedef pair<double,double> PA;

int n,k;
vector<PA> p;
double memo[1510][1510];

double dp(int a,int b){
    
    if(b >= k) return 0;
    if(memo[a][b] != -1.0) return memo[a][b];
    
    double res,add;
    int i,num;
    res = 0;
    add = 0;
    num = a+1;
    for(i=a+1;i<p.size()&&p[i].first<p[a].second;i++){
        if(add < p[i].second-p[a].second){
            num = i;
            add = p[i].second-p[a].second;
        }
    }
    if(i != a+1) res = max(res,dp(num,b+1)+add);
    for(int j=i;j<p.size();j++){
        add = p[j].second-p[j].first;
        res = max(res,dp(j,b+1)+add);
    }
    
    return memo[a][b] = res;
}

int main()
{
    
    double x,y,r,as,at,ll,rr;
    vector<PA> vec;
    
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lf %lf %lf",&x,&y,&r);
        if(y+r < 0) continue;
        as = asin(r/sqrt(x*x+y*y));
        at = atan2(y,x);
        ll = at-as;
        rr = at+as;
        if(ll < -M_PI){
            ll += 2*M_PI;
            rr += 2*M_PI;
        }
        vec.push_back( PA(max(0.0,ll),min(M_PI,rr)) );
    }
    
    sort(vec.begin(),vec.end());
    
    double ma = 0.0;
    p.push_back(PA(0.0,0.0));
    for(int i=0;i<vec.size();i++){
        if(ma == M_PI) break;
        if(ma < vec[i].second){
            if(i < vec.size()-1 && vec[i].first == vec[i+1].first) continue;
            ma = vec[i].second;
            p.push_back(vec[i]);
        }
    }
    fill_n(*memo,1510*1510,-1.0);
    printf("%.13f\n",dp(0,0)/M_PI);
    
    return(0);
}


Measured memory_bytes: 21616
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;


int main(){
    string S;
    cin >> S;
    int ans=0;
    REP(i,S.size()){
        if(S[i]=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans;
}

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

int main()
{
    int N, K, d, t;
    cin >> N >> K;
    vector<int> m (N, 0);
    for (int i = 0; i < K; i++)
    {
        cin >> d;
        while (d--)
        {
            cin >> t;
            m[t-1] = 1;
        }
    }

    int v = 0;
    for (int i = 0; i < N; i++)
    {
        if (m[i]==0) v++;
    }
    cout << v << endl;
}

Measured memory_bytes: 3600
//#include <cstdio>
//#include <algorithm>
//using namespace std;
//char s[500010];
//int n,ans,t[500010],pos[500010],tot;
//main()
//{
//	scanf("%d",&n);
//	scanf("%s",s+1);
//	int c1=0,c2=0,flag=0;
//	for (int i=1;i<=n;i++)
//	{
//		if (s[i]=='0')
//			flag=0;
//		if (s[i]=='1' && s[i+1]=='0' && s[i+2]=='1')
//		{
//			pos[++tot]=i;
//			i+=2;
//			if (flag)
//			{
//				t[tot-1]=1;
//			}
//			flag=1;
//		}
//	}
//	for (int i=1;i<=tot;i++)
//	{
//		int sum1=0,sum2=0;
//		for (int j=pos[i]-1;j>=1;j--)
//			if (s[j]=='0')
//				break;
//			else
//				sum1++;
//		if (!t[i])
//		{
//			for (int j=pos[i]+3;j<=n;j++)
//				if (s[j]=='0')
//					break;
//				else
//					sum2++;
//			ans+=max(sum1,sum2)+1;	
//			continue;
//		}
//		int now=i,mid=pos[i+1]-pos[i]-3,po=i;
//		while (t[now])
//		{
//			if (mid>pos[now+1]-pos[now]-3)
//			mid=pos[now+1]-pos[now]-3,po=now;
//			now++;
//		}
//		for (int j=pos[now]+3;j<=n;j++)
//			if (s[j]=='0')
//				break;
//			else
//				sum2++;
//		if (mid<=sum1 && mid<=sum2)
//		{
//			ans+=sum1+sum2;
//			for (int j=i;j<po;j++)
//				ans=ans+pos[j+1]-pos[j]-3+1;
//			ans++;
//			for (int j=po+1;j<now;j++)
//				ans=ans+pos[j+1]-pos[j]-3+1;
//			ans++;
//		}
//		else if (sum1<=mid && sum1<=sum2)
//		{
//			ans+=sum2;
//			for (int j=i;j<now;j++)
//				ans=ans+pos[j+1]-pos[j]-3+1;
//			ans++;
//		}
//		else if (sum2<=mid && sum2<=sum1)
//		{
//			ans+=sum1;
//			for (int j=i;j<now;j++)
//				ans=ans+pos[j+1]-pos[j]-3+1;
//			ans++;
//		}
//		i=now;
//	}
////	for (int i=1;i<=tot;i++)
////	if (t[i]==0)
////	{
////		int sum1=1,sum2=1;
////		for (int j=pos[i]+3;j<=n;j++)
////			if (s[j]=='0')
////			{
////				if (pos[i+1]==j-1)
////					t[i+1]=1;
////				break;
////			}
////			else
////				sum1++;
////		for (int j=pos[i]-1;j>=1;j--)
////			if (s[j]=='0')
////				break;
////			else
////				sum2++;
////		if (sum2>=sum1)
////			t[i+1]=0,s[pos[i]+2]='0',ans+=sum2;
////		else
////			ans+=sum1;
////	}
//	printf("%d\n",ans);
//}
#include <cstdio>
#include <algorithm>
using namespace std;
long long f[500010][3],ans;
int n;
char s[500010];
main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	if (n<3)
	{
		puts("0");
		return 0;
	}
	s[0]='0',s[n+1]='0',s[n+2]='0';
	int pre=0,now=1;
	while (now<=n+2)
	{
		while(s[now]!='0')
			now++;
		if(now==pre+1)
		{
			ans+=max(f[pre][0],max(f[pre][1],f[pre][2]));
			pre=now;
			now++;
			continue;
		}
		f[now][0]=max(f[pre][0],max(f[pre][1],f[pre][2]));
		if(s[now+1]=='1')
			if(now==pre+2)
				f[now][1]=f[pre][0]+now-pre-1;
			else
				f[now][1]=max(f[pre][1]+now-pre-2,f[pre][0]+now-pre-1);
		if(s[now-1]=='1')
		{
			int pos=now;
			while(pos+1<=n&&s[pos+1]=='1')
				pos++;
			if(now==pre+2)
				f[now][2]=f[pre][0]+pos-now;
			else
				f[now][2]=max(max(f[pre][0],f[pre][1]),f[pre][2]-1)+pos-now;
		}
		pre=now;
		now++;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 12416
PROGRAM piyo
      IMPLICIT NONE
      integer(16) :: n,k,i,buffer
      
      
      read*,n,k
      
      buffer = n
      i = 0
      do while(.true.)
        buffer = buffer / k
        i = i + 1
        
        if( buffer == 0 ) exit
      end do
      
      print*,i
      
      
      
      END PROGRAM

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  int n, k;
  cin>>n>>k;
  int ans = 0;
  rep(i, 0, n) {
    int a;
    cin>>a;
    int dist1 = abs(a - 0);
    int dist2 = abs(k - a);
    ans += 2*min(dist1, dist2);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int l,len,i,t,n,m;
string s;
char a[10001];
int main(){
   cin>>s;
   len=s.length();
   for(i=0;i<len;i++)
   {
   	if(s[i]=='0')a[t++]='0';
   	else if(s[i]=='1')a[t++]='1';
   	else {t--;if(t<0)t=0;}
   }
   if(t)for(i=0;i<t;i++)cout<<a[i];
   cout<<endl;
    return 0;
} 

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

int main() {
	int N;
	cin >> N;
	vector<int> P(N);
	for(auto &p : P) cin >> p;

	vector<int> num(N+2, 0);
	for(int i=N-1;i>=0;i--) {
		num[P[i]] = num[P[i]+1] + 1;
	}
	cout << N - *max_element(num.begin(), num.end()) << endl;
}

Measured memory_bytes: 1792
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntMap.Strict as IntMap
import Data.Monoid

discount :: Int -> IntMap.IntMap Int -> IntMap.IntMap Int
discount 0 p = p
discount m p = case IntMap.maxViewWithKey p of
                  Nothing -> p
                  Just ((k, l), p')
                    | m < l -> IntMap.insertWith (+) (k `quot` 2) m $ IntMap.insert k (l - m) p'
                    | otherwise -> discount (m - l) $ IntMap.insertWith (+) (k `quot` 2) l p'

main = do
  [n,m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  p <- IntMap.fromListWith (+) . map (\x -> (x,1)) . unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let result :: Int64
      result = getSum $ IntMap.foldMapWithKey (\k l -> Sum $! fromIntegral k * fromIntegral l) $ discount m p
  print result


Measured memory_bytes: 21500
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val m = sc.nextInt()
  val xy = (1..m).map { Pair(sc.nextInt(), sc.nextInt()) }

  val array = Array(n) { 1 }
  val reds = Array(n) { false }
  reds[0] = true

  for (xyi in xy) {
    val x = xyi.first - 1
    val y = xyi.second - 1

    if (array[x] == 0) {

    } else if (array[x] == 1) {
      array[x] = array[x] - 1
      array[y] = array[y] + 1
      if (reds[x]) {
        reds[y] = true
      }

      reds[x] = false
    } else {
      array[x] = array[x] - 1
      array[y] = array[y] + 1
      if (reds[x]) {
        reds[y] = true
      }
    }
  }

  // println(array.joinToString(" "))

  println(reds.filter { it }.size)

}


Measured memory_bytes: 66592
//code by lynmisakura
/****************************/
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<stdio.h>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;

const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;

#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
	
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
/***************************/

int main(void){
	int m,k;cin >> m >>k;
	if(k >= qp(2,m)){
		cout << -1 << endl;
		return 0;
	}
	if(m == 1){
		if(k == 0){
			cout << "0 0 1 1"<<endl; return 0;
		}else{
			cout << -1 << endl; return 0;
		}
	}
	
	rep(i,qp(2,m)){
		if(i == k)continue;
		else cout << i << " ";
	}
	cout << k << " ";
	rep(i,qp(2,m)){
		if(qp(2,m) - 1 - i == k)continue;
		else cout << qp(2,m) - 1 - i << " ";
	}
	cout << k << endl;
	
	return 0;
}


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

int fld[64][64] = {0};
int dx[] = {0,0,1,1,1,-1,-1,-1};
int dy[] = {1,-1,0,1,-1,0,1,-1};

void dfs(int y, int x)
{
	fld[y][x] = 0;
	for(int i=0; i<8; i++)
	{
		int ny = y+dy[i];
		int nx = x+dx[i];

		if(fld[ny][nx])
		{
			dfs(ny,nx);
		}
	}
}


int main()
{
	int w,h,c;
	while(cin >> w >> h, w||h)
	{
		memset(fld,0,sizeof(fld));

		for(int y=1; y<=h; y++)
		for(int x=1; x<=w; x++)
		{
			cin >> fld[y][x];
		}

		c=0;
		for(int y=1; y<=h; y++)
		for(int x=1; x<=w; x++)
		{
			if(fld[y][x])
			{
				c++;
				dfs(y,x);
			}
		}

		cout << c << endl;
	}
}

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

int main()
{
  int h, m, s, h3, m3, s3;
  while (1){
    cin >> h >> m >> s;
    if (h < 0){
      break;
    }
    m += 60 * h;
    s += 60 * m;
    s = 7200 - s;
    s3 = s * 3;
    m = s / 60;
    s %= 60;
    h = m / 60;
    m %= 60;
    m3 = s3 / 60;
    s3 %= 60;
    h3 = m3 / 60;
    m3 %= 60;
    printf("%02d:%02d:%02d\n%02d:%02d:%02d\n", h, m, s, h3, m3, s3);
  }

  return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

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

	int a,b,c,x,y;cin>>a>>b>>c>>x>>y;

	if(a+b > c*2){
		int mi = min(x,y);
		if(x==y)cout<< c*2*mi<<endl;

		x -=mi; y-=mi;
		if(x){
			if(a >= c*2){
				cout<<c*2*mi+c*2*x<<endl;
			}else {
				cout<<c*2*mi+a*x<<endl;
			}
		}
		if(y){
			if(b >= c*2){
				cout<<c*2*mi+c*2*y<<endl;
			}else {
				cout<<c*2*mi+b*y<<endl;
			}
		}


	}else {
		cout<<a*x+b*y<<endl;
	}
}




Measured memory_bytes: 256
fun c96(args: Array<String>) {
    val board = args.drop(1).map { it.toCharArray() }

    var ans = true
    board.forEachIndexed { y, chars ->
        chars.forEachIndexed { x, c ->
            if (board[y][x] == '#') {
                var alone = true
                (-1..1).forEach { dy ->
                    (-1..1).forEach { dx ->
                        val ny = y + dy
                        val nx = x + dx
                        if ((ny >= 0 && ny < board.size && nx >= 0 && nx < board.first().size)
                                && !(dy == 0 && dx == 0)
                                && (dy == 0 || dx == 0)
                                && board[ny][nx] == '#') {
                            alone = false
                        }
                    }
                }
                if (alone) {
                    ans = false
                }
            }
        }
    }

    println(if (ans) "Yes" else "No")
}


fun main(args: Array<String>) {
    c96(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

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

int main(){
  ll N;cin >> N;
  ll P;cin >> P;
  ll GU=0,KI=0;
  for(int i=0;i<N;i++){
    int A;cin >> A;
    if(A%2==0){
      GU ++;
    }else{
      KI ++;
    }
  }
  if(KI==1&&GU==0&&P==0){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  if(KI==0){
    if(P==1){
      cout << 0 << endl;
      return 0;
    }
    ans = 2;
  }
  for(int i=0;i<N-1;i++){
    ans = ans * 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <iostream>
using  namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e5+5;
const ll INF=0x3f3f3f3f;
ll min(ll x,ll y)
{
  if(x>=y) return  y;
  else return x;
}
int main()
{
    ll l,r,ans;
    cin>>l>>r;
    if(l/2019!=r/2019) ans=0;
    else
    {
         ans=INF;
        for(ll i=l; i<r; i++)
        {
            for(ll j=i+1; j<=r; j++)
            {
            ans=min(ans,(i*j)%2019);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {
    string S;
    cin >> S;

    bool flag = false;
    rep(i, S.size()) if (S[i] == '7')
        flag = true;
    
    flag ? cout << "Yes": cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3632
from sys import exit
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
s = {i for i in range(0, 102)}
np = s - set(map(int, input().split()))
t = len(np)
d = 100
ans = 0
for _ in range(t):
    i = np.pop()
    if d > abs(x - i):
        d = abs(x - i)
        ans = i
print(ans)


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

int main() {
  double ab,bb;
  int ai,bi,ans;
  cin >> ai >> bi;
  ab = ai;
  bb = bi;
  if (((ab+bb)/2)-((ai+bi)/2) == 0) {
    cout << (ai+bi)/2;
  } else {
    cout << (ai+bi+1)/2;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int n;
vector<int> nums;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < 2 * n; i++) {
		int temp; scanf("%d", &temp);
		nums.push_back(temp);
	}
	sort(nums.begin(), nums.end());
	int res = 0;
	for (int i = nums.size() - 1; i >= 1; i -= 2)res += min(nums[i], nums[i - 1]);
	cout << res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int Q = 301;

void solve() {
    int n,a; ll d;
    cin>>n>>d>>a;
    vector<pi> v(n);
    REP(i,0,n-1) {
        cin>>v[i].first>>v[i].second;
    }
    sort(all(v));
    vector<ll> bomb,strength;
    bomb.pb(INT_MIN);
    strength.pb(0);
    ll ans = 0;
    REP(l,0,n-1) {
        int L,R;
        L = lower_bound(all(bomb),v[l].first-d) - bomb.begin();
        R = upper_bound(all(bomb),v[l].first+d) - bomb.begin();
        if (L<R) {
            v[l].second -= a*(strength[R-1]-strength[L-1]);
        }
        if (v[l].second > 0) {
            ll temp = (v[l].second + a - 1)/a;
            bomb.pb(v[l].first + d);
            int N = bomb.size();
            strength.pb(temp);
            strength[N-1] += strength[N-2];
            ans += temp;
        }
    }
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 5220
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

ll a[MAXN];

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    	sum += a[i];
    }
    sort(a + 1, a + 1 + n);
    int ans = n;
    for (int i = n; i >= 1; i--) {
		if (sum * 2 < a[i + 1]) {
			ans -= i;
			break;
		}
		sum -= a[i];
    }
    cout << ans;
    return 0;
}

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

int main() {	

	int a, b; cin >> a >> b;
	a--;
	b--;
	int ans;
	if (b % a == 0) {
		ans = b / a;
	}
	else {
		ans = b / a + 1;
	}
		
	cout << ans << endl;
	return 0;
}

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


int main()
{
    int color[4] = {0};
    int n;
    char c;
    cin >> n;
    while (n--) {
        cin >> c;
        if (c == 'P') {
            color[0]++;
        } else if(c == 'W') {
            color[1]++;
        } else if(c == 'G') {
            color[2]++;
        } else if(c == 'Y') {
            color[3]++;
        }
    }
    int cnt = 0;
    for (int i = 0; i < 4; i++) {
        if (color[i] != 0) {
            cnt++;
        }
    }
    if (cnt == 3 && color[3] == 0) {
        cout << "Three" << endl;
    } else if(cnt == 4) {
        cout << "Four" << endl;
    }
    
    return 0;
}


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

#define DEBUG(x) cerr << #x << " = " << x << endl

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };

template<typename T>
struct Dice {
  T var[6]; int id[6];
  Dice() {
    id[0] = TOP, id[1] = FRONT, id[2] = LEFT;
    id[3] = RIGHT, id[4] = BACK, id[5] = BOTTOM;
  }
  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const { return var[id[f]]; }
  bool operator ==(const Dice<T>& a) const {
    const Dice<T>& b = *this;
    for(int i = 0; i < 6; i++) {
      if(a[i] != b[i]) return false;
    }
    return true;
  }
  // a -> b, b -> c, c -> d, d -> a
  void roll(FACE a, FACE b, FACE c, FACE d) {
    int value = id[d];
    id[d] = id[c], id[c] = id[b], id[b] = id[a], id[a] = value;
  }
  // FRONT???RIGHT????§??????????
  void roll_r() { roll(FRONT, RIGHT, BACK, LEFT); }
  // FRONT???TOP????§??????????
  void roll_u() { roll(FRONT, TOP, BACK, BOTTOM); }
  // TOP, RIGHT, BOTTOM, LEFT???????¨???????????§??????????
  void roll_c() { roll(TOP, RIGHT, BOTTOM, LEFT); }
  // roll_r??¨roll_u????????????????????????????????????roll_c???4?????????
  bool eq(const Dice& d) {
    for(int k = 0; k < 6; k++) {
      for(int i = 0; i < 4; i++) {
        if(*this == d) return true;
        roll_c();
      }
      if(k % 2 == 0) roll_r();
      else roll_u();
    }
  }
};

int main() {
  Dice<int> dice;
  cin >> dice[TOP];
  cin >> dice[FRONT];
  cin >> dice[RIGHT];
  cin >> dice[LEFT];
  cin >> dice[BACK];
  cin >> dice[BOTTOM];
  int N; cin >> N;
  for(int i = 0; i < N; ++i) {
    int top, front; cin >> top >> front;
    Dice<int> tmp = dice;
    for(int j = 0; j < 6; ++j) {
      for(int k = 0; k < 4; ++k) {
        // cerr << "tmp =";
        // cerr << " " << tmp[TOP];
        // cerr << " " << tmp[FRONT];
        // cerr << " " << tmp[RIGHT];
        // cerr << " " << tmp[LEFT];
        // cerr << " " << tmp[BACK];
        // cerr << " " << tmp[BOTTOM];
        // cerr << endl;
        if(tmp[TOP] == top && tmp[FRONT] == front) cout << tmp[RIGHT] << endl;
        tmp.roll_c();
      }
      if(j % 2 == 0) tmp.roll_r();
      else tmp.roll_u();
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>

using namespace std;
using ll = long long;

int main()
{
	double T, X;
	cin >> T >> X;
	double ans;
	ans = T / X;
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>

typedef long long ll;

std::map<ll, ll> PrimeFactorization(ll num){
  std::map<ll, ll> prime_factors;
  for(ll i = 2 ; i * i <= num ; ){
    if(num % i == 0){
      num /= i;
      prime_factors[i]++;
    }else{
      i++;
    }
  }
  if(num > 1){
      prime_factors[num]++;
  }
  return prime_factors;
}

int main(){
  ll N;
  std::cin >> N;
  std::map<ll, ll> prime_factors = PrimeFactorization(N);
  ll resa = 0;
  for(auto it = prime_factors.begin() ; it != prime_factors.end() ; it++){
    ll sum = 0;
    for(ll k = 1 ; k <= it -> second + 1; k++){
      sum += k;
      if(sum > it -> second){
	resa += k - 1;
	break;
      }else{
	continue;
      }// end of if
    }// end of k
  }// end of it
  std::cout << resa << std::endl;
  return 0;
}


Measured memory_bytes: 3344
#include <stdio.h>
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<complex>
#include<vector>

using namespace std;

int nx[]={0,1,0,-1};
int ny[]={0,1,0,-1};
//*****************************************
int X,Y;
int ans;

int main(void){

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

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





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <set>
using namespace std;
class sai
{
    public :
    int ue;
    int tem;
    int migi;
    int hidari;
    int oku;
    int sita;
    void roll(char c){
        int kari;
        if (c == 'S') {
        kari = ue;
        ue = oku;
        oku = sita;
        sita = tem;
        tem = kari;
    } else if (c == 'N') {
        kari = ue;
        ue = tem;
        tem = sita;
        sita = oku;
        oku = kari;
    } else if (c == 'E') {
        kari = ue;
        ue = hidari;
        hidari = sita;
        sita = migi;
        migi = kari;
    } else if (c == 'W') {
        kari = ue;
        ue = migi;
        migi = sita;
        sita = hidari;
        hidari = kari;
    }
  
    }
};
sai roll(sai b, char c) {
    if (c == 'S') {
        b = {b.oku,b.ue,b.migi,b.hidari,b.sita,b.tem};
    } else if (c == 'N') {
        b = {b.tem,b.sita,b.migi,b.hidari,b.ue,b.oku};
    } else if (c == 'E') {
        b = {b.hidari,b.tem,b.ue,b.sita,b.oku,b.migi};
    } else if (c == 'W') {
        b = {b.migi,b.tem,b.sita,b.ue,b.oku,b.hidari};
    }
    return b;
}
int migiha(sai b,int x, int y){
    int ans  = 999;
    string s = "EEEEWEEEEWEEEEWEEEEWEWEEEEWWEEEE";
    for(int i = 0; i < s.length(); i++){
        if(b.ue == x and b.tem == y){
            ans = b.migi;
            break;
        }
        b.roll(s[i]);
    }
    return ans;
}
int main(void){
    int a1,a2,a3,a4,a5,a6,n;
    int x ,y;
    int ans = 999;
    string s = "EEEENEEEENEEEENEEEENENEEENNEEEE";
    cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6 ;
    sai b = {a1,a2,a3,a4,a5,a6};
    cin >> n;
    for(int j = 0; j < n; j++){
        cin >> x >> y;
        for(int i = 0; i < s.length(); i++){
            if(b.ue == x and b.tem == y){
                ans = b.migi;
                break;
            }
            b.roll(s[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
using System;
class Program {
    static void Main (string[] args) {
        
        string[] astr = Console.ReadLine ().Split (' ');
        int a = int.Parse (astr[0]);
        int b = int.Parse (astr[1]);
        int c = int.Parse (astr[2]);

        int d = 0;
        int e = 0;
        int f = 0;

        int rtn = 9999999;
        int rtn1 = 0;
        int rtn2 = 0;
        
        //A + B  c
        d = a + b;
        e = c + b;
        f = c + a;

        int[] ar1 = new int[3]{d,e,f};

        for(int i= 0; i < 3;i++ ){
            if(rtn >= ar1[i]){
                rtn = ar1[i];
            } 
        }

        Console.WriteLine(rtn);
    }
}

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

int main(){
    int n,ans=0;
    cin >> n;
    int v[n], c[n];
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) cin >> c[i];

    for (int i = 0; i < n; i++){
        if(v[i] - c[i] > 0){
            ans += v[i] - c[i];
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char s[100000];

int main()
{
  int state;
  scanf("%s",s);
  int i,ans=0;

  if (s[0]=='B') {
    state=0;
  } else {
    state=1;
  }

  for (i=1;i<strlen(s);i++) {
    if (s[i]=='B' && state==1) {
      ans++;
      state=0;
    } else if (s[i]=='W' && state==0) {
      ans++;
      state=1;
    }
  }

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


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1<<30)-(1<<15))

int t[110],v[40010],limitv[40010];
double s;
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,40005)limitv[i]=INF;
	rep(i,0,n)scanf("%d",t+i);
	int tt=0;
	rep(i,0,n){
		int v;
		scanf("%d",&v);
		rep(j,0,2*t[i]+1)limitv[2*tt+j]=min(limitv[2*tt+j],2*v);
		tt+=t[i];
	}
	limitv[2*tt]=0;
	for(int i=2*tt;i>=0;i--)limitv[i]=min(limitv[i],limitv[i+1]+1);
	v[0]=0;
	rep(i,1,2*tt)v[i]=min(v[i-1]+1,limitv[i]);
	int s=0;
	rep(i,0,2*tt)s+=v[i]+v[i+1];
	printf("%f\n",s/8.0);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int W,a,b;
    cin >> W >> a >> b;
    if(b > a && b - a > W){
        cout << b - a - W;
    }
    else if(a > b && a - b > W){
        cout << a - b - W;
    }
    else{
        cout << 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000001;

using namespace std;



int main(void) {
	string s;
	int p;

	cin >> s;
	p = s.rfind("FESTIVAL");
	FOR(i, 0, p - 1) {
		cout << s[i];
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N):
  t = 0
  for j in range(i,N-1):
    if(t < CSF[j][1]):
      t = CSF[j][1]
    elif(t%CSF[j][2] == 0):
      pass
    else:
      t += CSF[j][2] - t%CSF[j][2]
    t += CSF[j][0]
  print(t)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>

typedef long long int lld;
typedef unsigned long long int ulld;
const int mod = 1000000007;

using namespace std;

int main (void) {
	ios::sync_with_stdio (false);
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int re = 0;
	if (k >= a) {
		re = a;
		k -= a;
	} else {
		re = k;
		k = 0;
	}

	if (k > 0) {
		k -= b;
	}
	if (k > 0) {
		re -= k;
	}

	cout << re << endl;
	return 0;
}

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

using namespace std; 

int main()
{
	double sum=0;
	int n;
	cin>>n;
	vector<double>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	sum = ((v[0]+v[1])/2);
	for(int i=2;i<n;i++)
	{
		sum=((sum+v[i])/2);
		
	}
	cout<<(sum)<<endl;
}




Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

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

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

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

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

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

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

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

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

fn main() {
    input!{
        N: usize,
        a: [usize; N],
    }
    let mut ans = 0;
    let mut k = 1;
    for i in 0..N {
        if a[i] != k {
            ans += 1;
        } else {
            k += 1;
        }
    }
    if ans > 0 && k < 2 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


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

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

Measured memory_bytes: 256
import sys
from itertools import count
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


MOVES = [
    ((1, 0), [(2,-1),(2,0),(2,1),(2,2),(1,1)]),
    ((-1, 0),[(-2,-1),(-2,0),(-2,1),(-2,-2),(-1,-1)]),
    ((0, 1), [(1,2),(0,2),(-1,2),(-2,2),(-1,1)]),
    ((0, -1), [(1,-2),(0,-2),(-1,-2),(2,-2),(1,-1)]),
    ]

CONVERTED_MOVES = None

def solve(dist, start, goal):
    q = [start]
    cnt = 0
    while q:
        nq = []
        while q:
            x = q.pop()
            if x == goal:
                return cnt
            if dist[x] < cnt:
                continue
            for d,l in CONVERTED_MOVES:
                nx = x+d
                if dist[nx] > cnt:
                    dist[nx] = cnt
                    q.append(nx)
                if dist[nx] < 0:
                    for t in l:
                        p = x+t
                        if dist[p] > cnt+1:
                            dist[p] = cnt+1
                            nq.append(p)
        q = nq
        cnt += 1

    return -1




if __name__ == '__main__':
    H,W = map(int,readline().split())
    start = tuple(map(lambda i:int(i)+1,readline().split()))
    goal = tuple(map(lambda i:int(i)+1,readline().split()))

    H += 4
    W += 4

    dist = [-1]*(W*H)

    start = start[0]*W+start[1]
    goal = goal[0]*W+goal[1]

    for t,s in zip(count(2*W,W),read().split()):
        for i,c in zip(count(t+2),s.decode()):
            if c == '.':
                dist[i] = 10**7

    convert = lambda x,y: x*W+y
    CONVERTED_MOVES = []
    for d,l in MOVES:
        d = convert(*d)
        l = [convert(*d) for d in l]
        CONVERTED_MOVES.append((d,l))

    print(solve(dist,start,goal))


Measured memory_bytes: 87804
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int end = sc.nextInt();
    int min = sc.nextInt();
    int max = sc.nextInt();
    sc.close();

    long sum = 0;

    for (int i = 1; i <= end; i++) {
      int x = getXxx(i);

      if (min <= x && x <= max) {
        sum += i;
      }
    }

    System.out.println(sum);
    
  }

  private static int getXxx(int num) {

    int result = 0;

    while(num > 0) {
      result += num % 10;
      num /= 10;
    }

    return result;

  }
}	

Measured memory_bytes: 21716
L=[111,222,333,444,555,666,777,888,999]
N=int(input())
M=[L[i]-N for i in range(len(L))]
O=[M[j] for j in range (len(M)) if M[j]>=0]
a=O[0]
num=M.index(a)
print(L[num])

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n, m; string s;
char maze[60][60];
int dis[60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
	cin >> s;
	bool flg0, flg1; ll res=0;
	flg0 = false; flg1 = false;
	if (s[0] == '0') {
		flg0 = true;
	}
	else if (s[0] == '1') {
		flg1 = true;
	}
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == '0'&&flg1) {
			flg0 = true; flg1 = false;
		}
		else if (s[i] == '1' && flg0) {
			flg1 = true; flg0 = false;
		}
		else if (s[i] == '0' && flg0) {
			flg0 = false; flg1 = true;
			s[i] = '1';
			res++;
		}
		else if (s[i] == '1' && flg1) {
			flg0 = true; flg1 = false;
			s[i] = '0';
			res++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 512
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};
#[fastout]
fn main() {
    input!(n: usize, q: usize, query: [(usize, usize); q]);

    let mut min_xv = vec![n - 2; n - 2];
    let mut min_yv = vec![n - 2; n - 2];
    let mut min_x = n - 2;
    let mut min_y = n - 2;
    let mut ans = (n - 2).pow(2);

    for que in query {
        let q1 = que.1 - 2;
        if que.0 == 1 {
            if min_x > q1 {
                for i in q1..min_x {
                    min_xv[i] = min_y;
                }
                min_x = q1;
            }
            ans -= min_xv[q1];
        } else {
            if min_y > q1 {
                for i in q1..min_y {
                    min_yv[i] = min_x;
                }
                min_y = q1;
            }
            ans -= min_yv[q1];
        }
    }

    println!("{}", ans);
}


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

int N, M, Q, X[510][510];

int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) { int l, r; cin >> l >> r; X[l][r]++; }
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++)  X[i][j] += X[i][j - 1];  }
	for (int i = 1; i <= Q; i++) {
		int p, q; cin >> p >> q;
		int sum = 0;
		for (int j = p; j <= q; j++) { sum += X[j][q] - X[j][p - 1]; }
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        Scanner cin = new Scanner();
        long N = cin.Long();
        long M = cin.Long();

        long ans = 0;
        if(M >= 2 * N&&N > 0)
        {
            ans += N;
            M -= 2 * N;
            ans += M / 4;
        }
        else if(M < 2 * N&&N > 0)
        {
            ans += M / 2;
        }
        else if(N == 0)
        {
            ans += M / 4;
        }
        Console.WriteLine(ans);    
        Console.ReadLine();
    }

}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define eps 10E-10
#define mod 998244353
#define pai acos(-1)
#define N 1000005

int ar[N],cnt[N];


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

    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>ar[i];
    sort(ar+1,ar+1+n);
    int ans=0;
    if(ar[1]==1){
      if(ar[1]==ar[2]) cout<<0<<endl;
      else cout<<1<<endl;
      return 0;
    }
    for(int i=1;i<=n; ){
      int x=ar[i],j=i,c=0;
      while(x==ar[j]) c++,j++;
      bool ok=1;
      if(cnt[ar[i]]==0){
         if(c==1) ans++;
         for(int k=2*ar[i];k<N;k+=ar[i]) cnt[k]++;
      }
      i=j;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8220
#include <stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i;
    char str1[30];
    scanf("%s",str1);
    int c=strlen(str1);
    sort(str1,str1+c);
    for(i=1;i<c;i++){
        if(str1[i]==str1[i-1]){
            printf("no");
            return 0;
        }
        else
            continue;
}

    printf("yes");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <math.h>
//#include <stack>
#include <algorithm>
#include <stdio.h>
//#include <cstdio>
using namespace std;
#define rep(i, b) for( int i = 0; i < b; i++ )
#define repi(i, a, b) for( int i = a; i < b; i++ )
typedef vector<int> vec;
#define eps 1e-10

struct C{
    double l, a, b;
};

int N, M;
double ans = 0;
vector<C> c;

/*
double dist( C c1, C c2 ){
    return pow(c1.l - c2.l, 2) + pow(c1.a - c2.a, 2) + pow(c1.b - c2.b, 2);
}*/

double dist( C c1, C c2 ){
    return (c1.l - c2.l)*(c1.l - c2.l) + (c1.a - c2.a)*(c1.a - c2.a) + (c1.b - c2.b)*(c1.b - c2.b);
}

void dfs( int d, vec v ){
    if( d == M ){
        double sum = 0;
        rep(i, v.size()) repi(j, i+1, v.size()){
            sum += dist(c[v[i]], c[v[j]]);
        }
        //cout << 'ans:' << ans << endl;
        ans = max( ans, sum );
    }else{
        repi(i, v[d-1]+1, N){
            v.push_back(i);
            dfs(d+1, v);
            v.pop_back();
        }
    }
}

int main(){
    cin >> N >> M;
    rep(i, N){
        C t;
        cin >> t.l >> t.a >> t.b;
        c.push_back(t);
    }
    vec v;

    rep(i, N){
        v.push_back(i);
        dfs(1, v);
        v.pop_back();
    }
    printf("%.20f\n", ans);
}

Measured memory_bytes: 1272
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] s = sc.next().split("");
		String[] v = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < 26; i++) {
			int tmp = 0;
			String[] u = s;
			loop: while (true) {
				boolean comp = true;
				for (int j = 0; j < u.length; j++)
					if (!u[j].equals(u[0])) {
						comp = false;
						break;
					}
				if (comp) {
					ans = Math.min(ans, tmp);
					break loop;
				}
				String[] w = new String[u.length - 1];
				for (int j = 0; j < w.length; j++) {
					if (u[j].equals(v[i]) || u[j + 1].equals(v[i]))
						w[j] = v[i];
					else
						w[j] = u[j];
				}
				u = w;
				tmp++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
#include<cstdio>
#define ll long long
int main() {
    ll s;
    int n,x,a,b;
    scanf("%d%d",&n,&x);
    s=a=0;
    while(n--) {
        scanf("%d",&b);
        a=a+b>x?a+b-x:0;
        s+=a;
        a=b-a;
    }
    printf("%lld\n",s);
    return 0;
}


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

int main(void) {
    string input;
    getline(cin, input);
    for(int r = 0; r < input.length(); r++) {
        if(isalpha(input[r]) && islower(input[r])) input[r] = toupper(input[r]);
    }
    cout << input << endl;
    return(0);
}

Measured memory_bytes: 1176
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		100										// 最大配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 配列数取得
	int liACnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liACnt);

	// 配列・和を取得
	int li1Array[D_ARRAY_MAX];
	int liSum = 0;
	for (i = 0; i < liACnt; i++) {
#ifdef D_TEST
		fscanf(szpFpT, "%d", &li1Array[i]);
#else
		fscanf(stdin, "%d", &li1Array[i]);
#endif
		liSum += li1Array[i];
	}
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif

	// 平均値取得
	int liAvg;
	if (liSum >= 0) {
		liAvg = (int)((double)liSum / (double)liACnt + 0.5);
	}
	else {
		liAvg = (int)((double)liSum / (double)liACnt - 0.5);
	}

	// コストの総和取得
	liSum = 0;
	for (i = 0; i < liACnt; i++) {
		liSum += (liAvg - li1Array[i]) * (liAvg - li1Array[i]);
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liSum);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 384