akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
const int maxn=3010;
const int maxm=(2e5)+10;
int n,h,w,x[maxn],y[maxn];
ll dp[maxn];
struct node { int x,y; } D[maxn];
ll iv[maxm],ivjc[maxm],jc[maxm];
bool cmp(node a,node b) {
	if (a.x==b.x) return a.y<b.y;
	return a.x<b.x;
}
ll C(int x,int y) {
	x+=y;
	return jc[x]*ivjc[y]%mod*ivjc[x-y]%mod;
}
void update(ll &x,ll y) {
	x+=y; if (x>=mod) x-=mod;
}
int main() {
	//freopen("1.txt","r",stdin);
	jc[0]=iv[0]=ivjc[0]=1;
	jc[1]=iv[1]=ivjc[1]=1;
	for (int i=2;i<maxm;i++) {
		jc[i]=jc[i-1]*i%mod;
		iv[i]=(mod-mod/i)*iv[mod%i]%mod;
		ivjc[i]=ivjc[i-1]*iv[i]%mod;
	}
	
	read(h); read(w); read(n);
	for (int i=1;i<=n;i++) read(x[i]),read(y[i]);
	n+=2; x[n-1]=1; y[n-1]=1;
	x[n]=h; y[n]=w;
	
	for (int i=1;i<=n;i++) D[i]=(node){x[i],y[i]};
	sort(D+1,D+n+1,cmp);
	for (int i=1;i<=n;i++) x[i]=D[i].x,y[i]=D[i].y;
	
	dp[1]=1;
	for (int i=1;i<=n;i++) {
		for (int j=1;j<i;j++)
			if (y[j]<=y[i])
				update(dp[i],mod-dp[j]*C(x[i]-x[j],y[i]-y[j])%mod);
	}
	printf("%lld\n",(mod-dp[n])%mod);
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int data[1000];

int main()
{
	int n;
	
	while(~scanf("%d",&n))
	{
		int i,j,sum=0,a;
		for(i=0;i<n;i++)
		{
			scanf("%d",&data[i]);
			if(data[i]%2==0)
			{
				sum++;
			}
		}
		
		a = pow(3,n)-pow(2,sum);
		
		printf("%d\n",a);
	}
	
	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]

    for i in range(1, d + 1):
        print(1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9420
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  int n, m;
  cin >> n >> m;
  int ans=1;
  if(n==1){
    cout << m << endl;
    return 0;
  }
  for(int i=2; i*i<=m; i++){
    if(!(m%i)){
      if(i<=m/n)
        ans = max(ans, i);
      if(m/i<=m/n)
        ans = max(ans, m/i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
int a[10],l[10],r[10],cnter=0,lt,rt;
char s[10];
int cal(long long x){
	printf("? %lld\n",x);
	fflush(stdout);
	scanf("%s",s);
	return s[0]=='Y' ? 1 : 0;
}
void solve(int op){
	int L=l[op],R=r[op];
	while(L<R){
		int mid=(L+R)>>1;
		if(cal(10ll*mid))R=mid;
		else L=mid+1; 
	}
	printf("! %d\n",L);
}
int main(){
	l[1]=1,r[1]=9;
	rep(i,2,9){
		l[i]=l[i-1]*10;
		r[i]=r[i-1]*10+9;
	}
	rep(i,1,9)a[i]=cal(l[i]) && cal(r[i]),cnter+=a[i];
	rep(i,1,9)if(a[i])rt=i;
	rep2(i,9,1)if(a[i])lt=i;
	
	if(!cnter){
		printf("! 1000000000\n");
		//fflush(stdout);
	}else if(cnter==9){
		int pan=cal(1000000000ll);
		if(pan)printf("! %d\n",l[1]);
		else solve(rt);
	}
	else if(a[9] && a[1]){
		solve(rt);
	}
	else if(!a[9]){
		solve(rt);
	}else if(!a[1]){
		solve(lt);
	}
}

Measured memory_bytes: 660
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int n;
string a, b;

int main(){
	cin >> n >> a >> b;
	ll ans = 1LL;
	int prev;
	int i;
	if (n == 1) {
		cout << "3" << endl;
		return 0;
	}
	if (a[0] != b[0]) {
		ans = ans * 6 % MOD;
		i = 2;
		prev = 2;
	}
	else {
		ans = ans * 3 % MOD;
		i = 1;
		prev = 1;
	}
	while(i<n){
		if (a[i] == b[i]) {//
			if (prev == 2) {
				i++;
			}
			else {
				ans = ans * 2 % MOD;
				i++;
			}
			prev = 1;//
		}
		else {
			if (prev == 2) {
				ans = ans * 3 % MOD;
				i += 2;
			}
			else {
				ans = ans * 2 % MOD;
				i += 2;
			}
			prev = 2;//
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	int N , x[101] , y[101] , h[101] , i;
	int  X , Y ;
	long long H ;
	int t ;
	scanf("%d",&N);
	for( i = 0 ; i < N  ; i++ ){
		scanf("%d%d%d",&x[i],&y[i],&h[i]);
	}
	if( N == 1 ){
		printf("%d %d %d\n",x[0],y[0],h[0]);
		return 0 ;
	}
	for( X = 0 ; X <= 100 ; X++ ){
		for( Y = 0 ; Y <= 100 ; Y++){
			for( i = 0 ; i < 100 ; i++ ){
				if( h[i] > 0 ) break ;
			}
			H = h[i] + abs(X-x[i]) + abs(Y-y[i]) ;
			if( H >= 1){
				for( i = 0 ; i < N ; i++  ){
					t = H - abs(X-x[i]) - abs(Y-y[i]) ;
					t = max(t,0);
					if( t != h[i] )break ;
				} 
				if( i == N ){
					printf("%d %d %lld\n",X,Y,H);
					return 0 ;
				}
			}

		}
	}

	return 0 ;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	if(n==m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[51];
int main(){
	int n,ans;
	cin>>n;
	for(int i=0;i<n;i++)
	    cin>>a[i];
	for(int i=0;i<n-1;i++)
		for(int j=i+1;j<n;j++)
		    ans+=a[i]*a[j];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
    int n,score;
    string s;
    vector<tuple<string, int, int>> r;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s >> score;
        r.push_back(make_tuple(s,100-score,i+1));
    }
    sort(r.begin(),r.end());
    for(int i=0;i<n;i++){
        cout << get<2>(r[i]) << endl;
    }
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		int min = Math.min(A, B);
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= min; i++) {
			if(A % i == 0 && B % i == 0) {
				list.add(i);
			}
		}
		Collections.sort(list, Collections.reverseOrder());
		System.out.println(list.get(K - 1));
	}
}

Measured memory_bytes: 23124
N,K = map(int,input().split())

cnt = 0
for i in range(K+1,N+1): # i:割る数
    cnt += (i-K)*(N//i)
    if K != 0:
        cnt += max(N%i-K+1,0)
    else:
        cnt += max(N%i-K,0)
    # print(cnt)
print(cnt)

Measured memory_bytes: 2940
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<deque>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
using namespace std;
long long d[100005];//d[i]的值为k到i的距离
typedef pair<int,int>P;
vector<P>vec[100005];
void dfs(int x,int y)
{
     int k=vec[x].size();
     for(int i=0;i<k;i++)
     {
          P s=vec[x][i];
          if(s.first!=y)
          {
               d[s.first]=d[x]+s.second;
               dfs(s.first,x);
          }
     }
}
int main()
{
     int n;
     scanf("%d",&n);
     for(int i=0;i<n-1;i++)
     {
          int a,b,c;
          scanf("%d%d%d",&a,&b,&c);
          vec[a].push_back(P(b,c));
          vec[b].push_back(P(a,c));
     }
     int m,k;
     scanf("%d%d",&m,&k);
     d[k]=0;
     dfs(k,k);
     for(int i=0;i<m;i++)
     {
          int a,b;
          scanf("%d%d",&a,&b);
          printf("%lld\n",d[a]+d[b]);
     }
     return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main(){
	while(true){
		int T, P, R;
		cin >> T >> P >> R;
		if(T == 0 && P == 0 && R == 0){ break; }
		vector<int> accepted(T), penalty(T);
		vector< vector<int> > wrong(T, vector<int>(P));
		while(R--){
			int tid, pid, time;
			string status;
			cin >> tid >> pid >> time >> status;
			--tid; --pid;
			if(status == "CORRECT"){
				++accepted[tid];
				penalty[tid] += time + wrong[tid][pid] * 1200;
			}else{
				++wrong[tid][pid];
			}
		}
		vector<pipii> v(T);
		for(int i = 0; i < T; ++i){
			v[i] = pipii(P - accepted[i], pii(penalty[i], i));
		}
		sort(v.begin(), v.end());
		for(int i = 0; i < T; ++i){
			cout << v[i].second.second + 1 << " ";
			cout << P - v[i].first << " ";
			cout << v[i].second.first << endl;
		}
	}
	return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n;
  cin >> n;
  double pos[n*2] = {};
  vector<int> index(n);
  for(int i=0;i<n;i++){
    cin >> pos[2*i] >> pos[2*i+1];
    index[i]=i;
  }
  int64_t count = 0;
  double dist = 0.0;
  do{
    for(int i=1;i<n;i++){
      dist += sqrt( 
        (pos[2*(index[i-1])]-pos[2*(index[i])])*(pos[2*(index[i-1])]-pos[2*(index[i])])
        +(pos[2*(index[i-1])+1]-pos[2*(index[i])+1])*(pos[2*(index[i-1])+1]-pos[2*(index[i])+1])
         );
    }
    count++;
  }while(next_permutation(index.begin(),index.end()));
         
  cout << fixed << setprecision(10) << dist/(double)count;    
  return 0;
}


Measured memory_bytes: 3756
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>

using namespace std;
int main(){
  int N,H;
  int a[111111];
  int b[111111];
  int i;
  cin >> N >> H;
  for(i=0;i<=N-1;i++)
    cin >> a[i] >> b[i];
  int max = 0;
  for(i=0;i<=N-1;i++)
    if(a[i]>max) max = a[i];
  sort(b,b+N,greater<>());
  int sum = 0;
  int k = 0;
  while(b[k]>max && H > 0){
    H -= b[k];
    k++;
  }
  
  if(H>=0)cout << k  + (H + max -1) / max;
  else cout << k  << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int h,r;
	scanf("%d %d",&h,&r);
	if(h+r>0){
		printf("1\n");
	}
	else	if(h+r<0){
		printf("-1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}


Measured memory_bytes: 2624
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
# define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
# define ft first
# define sec second

int main()
{
    string s;
    int r=0,w=0;
    int n;
    cin>>n;
    cin>>s;
    for( char c : s)
    {
        if(c=='R') r++;
        else w++;
    }
    //cout<<r;
    int rcnt=0;
    for(int i= 0 ;i < r ; i++ ) rcnt+=(s[i]=='R');
    cout<<r-rcnt;
}



Measured memory_bytes: 3420
# include <bits/stdc++.h>
using namespace std;
int main(){
	int h , w , a , b; 
	cin >> h >> w >> a >> b;
	string grid[h];
	for(int i = 0; i < h; i ++)for(int j = 0; j < w; j ++) grid[i] += "1";
	for(int i = 0; i < b; i ++)for(int j = 0; j < a; j ++) grid[i][j] = '0';
	for(int i = b; i < h; i ++)for(int j = a; j < w; j ++) grid[i][j] = '0';
	for(int i = 0; i < h; i ++)cout << grid[i] << '\n';
}

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

using namespace std;

long long n, ans;

main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        if (i % 3 == 0 || i % 5 == 0){
        } else {
            ans += i;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3624
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{

    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var NXT = Console.ReadLine().Split().Select(double.Parse).ToArray();
            var times = Math.Ceiling(NXT[0] / NXT[1]);
            Console.WriteLine(times * NXT[2]);
        }
    }
}

Measured memory_bytes: 28136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int n, m;

int main(){
  cin >> n >> m;
  bool flag = false;
  rep(i, n + 1){ //10000
    rep(j, n - i + 1){ //5000
      int x = i * 10000;
      int y = j * 5000;
      int z = (n - i - j) * 1000;
      if( x + y + z == m ){
        flag = true;
        cout << i << " " << j << " " << (n-i-j) << endl;
        break;
      }
    }
    if(flag) break;
  }
  if(!flag){
    cout << "-1 -1 -1" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int m = stdIn.nextInt();

        boolean[][] lampToSwitch = new boolean[m][n];
        for(int i=0; i<m; i++){
            int k = stdIn.nextInt();
            for(int j=0; j<k; j++){
                int s = stdIn.nextInt();
                lampToSwitch[i][s-1] = true;
            }
        }

        int[] surplus = new int[m];
        for(int i=0; i<m; i++){
            surplus[i] = stdIn.nextInt();
        }

        boolean[] bit = new boolean[n+1];
        int ans = 0;
        do{
            boolean clearFlag = true;
            for(int i=0; i<m; i++){
                int onSwitches = 0;
                for(int j=0; j<n; j++){
                    if(lampToSwitch[i][j]){
                        if(bit[j]){
                            onSwitches++;
                        }
                    }
                }
                if(onSwitches % 2 != surplus[i]){
                    clearFlag = false;
                    break;
                }
            }

            if(clearFlag){
                ans++;
            }

            changeBit(bit);
        }while(!finish(bit));

        System.out.println(ans);
    }

    static void changeBit(boolean[] bit){
        boolean carryBit = true;
        for(int i=0; i<bit.length; i++){
            if(carryBit){
                if(bit[i]){
                    bit[i] = false;
                }else{
                    bit[i] = true;
                    carryBit = false;
                }
            }
        }
    }

    static boolean finish(boolean[] bit){
        return bit[bit.length-1];
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;
int main()
{
       long n,k,x,y;
       while(cin>>n)
       {
           cout<<(n*(n+1))/2<<"\n";
       }
        return 0;

}




Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<cassert>
#include<sstream>
  
#define INF (1<<29)
#define MAX 1000001
  
using namespace std;
  
struct Edge {
  int to, cost;
  Edge(int to = INF, int cost = INF) : to(to), cost(cost) {}
};
  
typedef pair<int, int> Pii; // cost, pos
typedef vector<Edge> Edges;
  
Edges es[MAX];
  
Pii visit(int prev, int curr) {
   
  Pii r(0, curr);
   
  for(int i=0; i<es[curr].size(); i++) {
   const Edge& e = es[curr][i];
    
   if(e.to != prev) {
     Pii t = visit(curr, e.to); // 再帰的に辿る
     t.first += e.cost;
     if(r.first < t.first) r = t; // コストの比較
   }
  }
  return r;
}
  
int diameter() {
  Pii r = visit(-1, 1);
  Pii t = visit(-1, r.second);
  return t.first; // (r.second, t.second) is farthest pair らしい...
}
 
int n;
 
int main()
{
  int n;
  cin >> n;
   
  for(int i=0; i<n; i++) {
    int s, t, w;
     
    cin >> s >> t >> w;
    es[s].push_back( Edge(t, w) );
    es[t].push_back( Edge(s, w) );
  }
   
  cout << diameter() << endl;
   
  return 0;
}

Measured memory_bytes: 35564
#include<iostream>
using namespace std;
const int maxn=300000+1;
int a[maxn],b[maxn];
int main()
{
	int n;
	string s;
	cin>>n>>s;
	a[0]=0;
	for(int i=1;i<n;i++)
	{
		a[i]=a[i-1];
		if(s[i-1]=='E')	a[i]++;
	}
	int maxx=a[n-1];
	b[n-1]=0;
	for(int i=n-2;i>=0;i--)
	{
		b[i]=b[i+1];
		if(s[i+1]=='W')	b[i]++;
		maxx=max(maxx,b[i]+a[i]);
		//cout<<maxx<<endl;
	}
	cout<<n-maxx-1<<endl;
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,INF=1<<30;

struct tri{
    int a,b,c,d,e,f;
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;cin>>H>>W;
    
    vector<vector<char>> S(1200,vector<char>(1200,'.'));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>S[400+i][400+j];
        }
    }
    
    vector<vector<int>> A(1200,vector<int>(1200)),B(1200,vector<int>(1200));
    for(int i=1198;i>=0;i--){
        for(int j=1;j<1200;j++){
            if(S[i][j]=='#'){
                A[i][j]=A[i+1][j-1]+1;
            }else{
                A[i][j]=A[i+1][j-1];
            }
        }
        for(int j=1198;j>=0;j--){
            if(S[i][j]=='#'){
                B[i][j]=B[i+1][j+1]+1;
            }else{
                B[i][j]=B[i+1][j+1];
            }
        }
    }
    
    ll ans=0;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=1;i-k>=0&&j+k<W;k++){
                if(S[400+i][400+j]=='.'||S[400+i-k][400+j+k]=='.') continue;
                int a=i-k,b=j-k,c=i-2*k,d=j;
                ans+=A[400+c][400+d]-A[400+a+1][400+b-1];
                
                a=i+k;b=j+k;c=i;d=j+2*k;
                ans+=A[400+c][400+d]-A[400+a+1][400+b-1];
            }
            
            //cout<<i<<" "<<j<<" "<<ans<<endl;
        }
    }
    
    //cout<<ans<<endl;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=1;i-k>=0&&j-k>=0;k++){
                if(S[400+i][400+j]=='.'||S[400+i-k][400+j-k]=='.') continue;
                int a=i-k,b=j+k,c=i-2*k,d=j;
                ans+=B[400+c][400+d]-B[400+a+1][400+b+1];
                
                a=i+k;b=j-k;c=i;d=j-2*k;
                ans+=B[400+c][400+d]-B[400+a+1][400+b+1];
            }
            
            //cout<<i<<" "<<j<<" "<<ans<<endl;
        }
    }
    
    //cout<<ans<<endl;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=j+2;k<W;k+=2){
                if(S[400+i][400+j]=='.'||S[400+i][400+k]=='.') continue;
                if(S[400+i-(k-j)/2][400+(j+k)/2]=='#') ans--;
                if(S[400+i+(k-j)/2][400+(j+k)/2]=='#') ans--;
            }
        }
    }
    
    for(int j=0;j<W;j++){
        for(int i=0;i<H;i++){
            for(int k=i+2;k<H;k+=2){
                if(S[400+i][400+j]=='.'||S[400+k][400+j]=='.') continue;
                if(S[400+(i+k)/2][400+j-(k-i)/2]=='#') ans--;
                if(S[400+(i+k)/2][400+j+(k-i)/2]=='#') ans--;
            }
        }
    }
    
    cout<<ans<<endl;
}




Measured memory_bytes: 13184
H,W = map(int,input().split())


H_flag = [False]*H
W_flag = [False]*W


_map = []
for i in range(H):
    x = list(input())
    _map.append(x)
    for j in range(W):
        if x[j] == '#':
            H_flag[i] = True

for i in range(W):
    for j in range(H):
        if _map[j][i] == '#':
            W_flag[i]= True

for i in range(H):
    for j in range(W):
        if H_flag[i] and W_flag[j]:
            print(_map[i][j],end="")
    if H_flag[i] :
        print()

#print(H_flag)
#print(W_flag)



Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
int arr[N];
int ans;
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
	}
	for(int i = 1 ; i <= n ; ++i){
		if(arr[i] != i){
			continue;
		}
		int j = i;
		while(j < n && arr[j + 1] == j + 1){
			++j;
		}
		ans += (j - i + 2) >> 1;
		i = j;
	}
	printf("%d\n" , ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/
double dp[301][301][301];

double expected(ll x, ll y, ll z, ll n){
    ll o = n-x-y-z;
    if(dp[x][y][z]>=0) return dp[x][y][z];
    double res=n;
    if(x>0) res+= expected(x-1,y,z,n)*x;
    if(y>0) res+= expected(x+1,y-1,z,n)*y;
    if(z>0) res+= expected(x,y+1,z-1,n)*z;
    res /= (x+y+z);
    dp[x][y][z]=res;
    return res;
}

int main(){
    _cin;
    cout << setprecision(22);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;
    vll a(4);
    fo(i,n){
        cin >> x;
        a[x]++;
    }
    fo(i,301){
        fo(j,301){
            fo(k,301) dp[i][j][k]=-1;
        }
    }
    dp[0][0][0]=0;
    cout << expected(a[1],a[2],a[3],n);
    
    

}
 return 0;      
}

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


double s(double a, double b, double c){
    double S, z;
    z = (a+b+c)/2.0;
    S = z*(z-a)*(z-b)*(z-c);
    return sqrt(S);
}

int main(void){
    int n=0;
    double x[21], y[21], sum=0;
    double xx, yy, tt;
    for(int i=1; scanf("%lf,%lf",&x[i],&y[i])!=EOF; i++){
        n = i;
    }
    for(int i=2; i<=n; i++){
        xx = sqrt((x[i]-x[i-1])*(x[i]-x[i-1])+(y[i]-y[i-1])*(y[i]-y[i-1]));
        yy = sqrt(x[i]*x[i]+y[i]*y[i]);
        tt = sqrt(x[i-1]*x[i-1]+y[i-1]*y[i-1]);
        sum+=s(xx, yy, tt);
    }
    
        xx = sqrt((x[n]-x[1])*(x[n]-x[1])+(y[n]-y[1])*(y[n]-y[1]));
        yy = sqrt(x[n]*x[n]+y[n]*y[n]);
        tt = sqrt(x[1]*x[1]+y[1]*y[1]);
        sum+=s(xx, yy, tt);
    cout << fixed;
    cout << setprecision(7) << sum << endl;
    return 0;
}



Measured memory_bytes: 3300
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
long long n,m,a,b,ans,pos=-10;
long long br[100001]={};

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		if(br[a]==0){
			br[a]=b;
		}else{
			br[a]=min(b,br[a]);
		}
	}
	for(int i=1;i<=n;i++){
		if(br[i]!=0){
			if(i>=pos){
				ans++;
				pos=br[i];
			}else{
				pos=min(pos,br[i]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#include <math.h>
#include <stdlib.h>


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

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

const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    int amin = 200005;
    for(int i = 0; i < n; i++){
        if(a[i] < amin) amin = a[i];
    }
    if(amin != 1) {
        cout << -1 << endl;
        return 0;
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == ans+1) ans++;
    }
    cout << n - ans << endl;


    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

vector<ll> pfact(ll n) {
	vector<ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			while (n % i == 0) n /= i;
		}
	}
	if (n != 1) ret.push_back(n);
	return ret;
}

int main() {
	IOS();
	ll a, b;
	cin >> a >> b;
	ll g = gcd(a, b);
	dump(pfact(g).size() + 1);

	return 0;
}

Measured memory_bytes: 256
s = input()

end = len(s) - 1
half = int(len(s) / 2) - 1
flag = True
while end != 1:
    end -= 2
    half -= 1
    start = 0
    flag = True
    for i in range(half+1, end):
        if s[i] != s[start]:
            flag = False
            break
        start += 1
    if flag == True:
        print(end+1)
        exit()




Measured memory_bytes: 8984
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

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

const int N = 1e5 + 10;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	if (k == 1) return cout << 0, 0;
	cout << n - k;












	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {

    val (N, W) = readLine()!!.split(" ").map(String::toInt)
    val WV = Array(N) { readLine()!!.split(" ").map(String::toInt) }
    val w = WV.map { it[0] }
    val v = WV.map { it[1] }

    val dp = LongArray(W + 1)

    for (i in 0 until N) {
        for (j in W downTo w[i]) {
            dp[j] = Math.max(dp[j - w[i]] + v[i], dp[j])
        }
    }
//    dp.joinToString(",").let(::println)

    println(dp.last())
}


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

int main() {
  int h, w;
  while (cin >> h >> w, (h | w) != 0) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cout << "#";
      }
      cout << "\n";
    }
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 7+1e18
#define lld long double
#define eps 0.000001
#define endl '\n'
using namespace std ;

lli spf[100000+1];
lli const MAXN = 100001;
lli modex(lli x,lli y,lli p);
void getZarr(string str, lli Z[]);
void sieve();
vector<lli> getFactorization(lli x);
vector<lli> ans; 
vector<lli> printDivisors(lli n) 
{ 
    // Note that this loop runs till square root 
    for (lli i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            // If divisors are equal, print only one 
            if (n/i == i) 
               ans.pb(i); 
  
            else // Otherwise print both 
                {ans.pb(i); ans.pb(n/i);} 
        } 
    }
    return ans; 
}
int main()
{
   
    

    lli n,m;
    cin>>n>>m;
    
    vector<lli> v=printDivisors(m);

    lli o;
    sort(v.begin(),v.end());
    //loopl(i,0,v.size()) cout<<v[i]<<" ";
    //cout<<endl;
    loopl(i,0,v.size())
    {
        if(m/v[i] >=n) o=v[i];
        else break;
    }
    cout<<o<<endl;

    
}


void getZarr(string str, lli Z[]){
    Z[0]=0;
    lli n = str.length();
    lli L, R, k;
    L = R = 0;
    loopl(i,1,n){
        if (i > R){
            L = R = i;
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        } else {
            k = i-L;
            if (Z[k] < R-i+1)
                Z[i] = Z[k];
            else {
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}

lli modex(lli x,lli y,lli p) 
{ 
    lli res = 1; 
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
  
        y = y>>1;  
        x = (x*x) % p;   
    } 
    return res; 
}

void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
    spf[i] = i; 
  
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (int j=i*i; j<MAXN; j+=i) 
  
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
vector<lli> getFactorization(lli x) 
{ 
    vector<lli> ret; 
    while (x != 1) 
    { 
        ret.pb(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int d, n, s, t, sum;
int main(void){
    while(cin>>d>>n, d){
        sum=0;
        for(int i=0; i<n; i++){
            cin >> s >> t;
            sum += t-s;
        }
        if(sum<d) cout << d-sum << endl;
        else cout << "OK" << endl;
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[105][10];
signed main() {
    int H,W,K;
    cin >> H >> W >> K;
    dp[0][0] = 1;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            int X = 0,Y = 0,Z = 0;
            for(int k = 0; k < (1 << (W-1)); k++) {
                bool ok = false;
                for(int l = 0; l < W-1; l++) {
                    if(1 & (k >> l)) {
                        if(ok) {
                            goto END;
                        }
                        ok = true;
                    }
                    else {
                        ok = false;
                    }
                }
                if(j+1 != W && 1 & (k >> j)){
                    Y++;
                }
                else if(j-1 >= 0 &&(1 & (k >> (j-1)))) {
                    Z++;
                }
                else {
                    X++;
                }
            END:;
            }
            dp[i+1][j] += X*dp[i][j]%mod;
            dp[i+1][j] %= mod;
            if(j+1 != W) {
                dp[i+1][j+1] += Y*dp[i][j]%mod;
                dp[i+1][j+1] %= mod;
            }
            if(j-1 >= 0) {
                dp[i+1][j-1] += Z*dp[i][j]%mod;
                dp[i+1][j-1] %= mod;
            }
        }
    }
    cout << dp[H][K-1] << endl;
}


Measured memory_bytes: 3548
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let _n: usize = iterator.next().unwrap().parse().unwrap();
    let s: &str = iterator.next().unwrap();

    let mut head = String::new();

    let mut stack: Vec<char> = Vec::new();
    for c in s.chars() {
        if c == '(' {
            stack.push(c);
        } else {
            if let Some(_) = stack.pop() {
                // nothing
            } else {
                head.push('(');
            }
        }
    }

    let mut tail = String::new();
    for _ in 0..stack.len() {
        tail.push(')');
    }

    return format!("{}{}{}", head, s, tail);
}


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

int main() {
  int n, manzoku = 0;
  cin >> n;
  vector<int> meshi(n), base(n), additional(n-1);
  for (int i=0; i<n; i++) {
    cin >> meshi.at(i);
  }
  for (int i=0; i<n; i++) {
    cin >> base.at(i);
  }
  for (int i=0; i<n-1; i++) {
    cin >> additional.at(i);
  }
  for (int i=0; i<n-1; i++) {
    if (meshi.at(i+1) - meshi.at(i) == 1) {
      manzoku += additional.at(meshi.at(i) - 1);
    }
  }
  for (int i=0; i<n; i++) {
    manzoku += base.at(i);
  }
  cout << manzoku << endl;
}

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

int main(){
    int n, max, kosuu;
    kosuu = 0;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n;i++){
        vec.at(i) = 0;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> vec.at(i);
        max = *max_element(vec.begin(), vec.end());
        if(max == vec[i]){
            kosuu += 1;
        }
    }
    cout << kosuu;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main()
{
	double a[1001];
	int n;


	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);

	double ans = -999999999;

	for (int i = 1; i < n - 2; i++)
	{
		ans = max(ans, (a[n - 1] + a[n - 2]) / (a[i] - a[i - 1]));
	}
	ans = max(ans, (a[n - 1] + a[n - 4]) / (a[n - 2] - a[n - 3]));
	ans = max(ans, (a[n - 3] + a[n - 4]) / (a[n - 1] - a[n - 2]));

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

	return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    int cnt[10][10] = {0};
    for (int i = 1; i <= n; i++)
    {
        string s = to_string(i);
        int num1 = s.back() - '0';
        int num2 = s[0] - '0';
        cnt[num2][num1]++;
    }
    ll ans = 0;
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            ans += 1ll * cnt[i][j] * cnt[j][i];
            //DBG(ans);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int s[100001];
    int n,q,i,j,c=0,t;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>s[i];
    cin>>q;
    for(i=0;i<q;i++)
    {
        cin>>t;
        j = 0;
        s[n] = t;
        while(s[j]!=t)
            j++;
        if(j!=n)
            c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair

ll ds(string x){
    int res=0;
    for(int i=0 ; i<x.length() ; i++){
        res+=x[i]-'0';
    }
    return res;
}

int main(){
	fast;
	int test=1;
	//cin >> test;
	while(test--){
	    string n;
	    cin >> n;
	    int len=n.length();
	    cout << max(ds(n),n[0]-'1'+(len-1)*9);
	}
	return 0;
}

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

int main() {
    int n;
    ll m;
    cin >> n >> m;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];
    sort(A.begin(), A.end());
    vector<ll> B(n+1);
    B[0] = 0;
    rep(i, n) B[i+1] = A[i] + B[i];
    auto calc = [&](int x) {
      ll a = 0, b = 0;
      rep(i, n) {
        int c = lower_bound(A.begin(), A.end(), x-A[i]) - A.begin();
        a += n - c;
        b += B[n] - B[c];
        b += A[i] * ll(n-c);
      }
      return make_pair(a, b);
    };

    int l = 0, r = 200001;
    while (l+1 < r) {
      int c = (l+r)/2;
      auto p = calc(c);
      if (p.first > m) l = c;
      else {
        r = c;
      }
    }
    auto p = calc(l);
    ll ans = p.second;
    ans -= l*(p.first-m);
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=128;
const ll MAX_N=500010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,ans=0;
vl v,v1;
vp p[100010];
string s;
ll solve(void){
    if(v.back()>v1[0])return 0;
    return v1[0]-v.back()+1;
}
int main(){
    cin>>n>>m;
    rep(i,m){
     cin>>a>>b;
     v.push_back(a);
     v1.push_back(b);
    }
 
    sort(v.begin(),v.end());
    sort(v1.begin(),v1.end());
 
    cout<<solve()<<endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M, V, P; cin >> N >> M >> V >> P;
    ll A[N]; rep(i, N) cin >> A[i];
    sort(A, A+N);
    //採用される可能性のある問題には単調性がある
    ll ok = N, ng = -1;
    ll m = (ok+ng)/2;

    ll ruiseki[N+1] = {};
    rep(i, N) ruiseki[i+1] = ruiseki[i] + A[i];

    while(abs(ok-ng) > 1){
        //A[m]は採用される可能性があるか?
        //つまりA[m]+Mは,投票後に上からP番目以内となり得るか?
        //A[m+1]からA[N-P]以上となりたい
        if(A[m]+M < A[N-P]) ng = m;
        else{
            //A[0]からA[m], A[N-1]からA[N-P+1]までは足しちゃってよい
            ll rem = M*V - (m+1)*M - (P-1)*M;
            if(rem <= 0) ok = m;
            else{
                //rem個のものをA[m+1],...,A[N-P]に対して分ける
                ll sum = ruiseki[N-P+1] - ruiseki[m+1] + rem;
                ll boarder;
                if(sum % (N-P-m)) boarder = sum/(N-P-m) + 1;
                else boarder = sum/(N-P-m);
                if(A[m]+M < boarder) ng = m;
                else ok = m;
            }
        }
        m = (ok+ng)/2;
    }
    cout << N-ok << endl;
    return 0;
}

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

int main() {
    int h, w;

    std::cin >> h >> w;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::string s;

            std::cin >> s;

            if (s == "snuke") {
                std::cout << static_cast<char>('A' + j) << i + 1 << std::endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;<n;i++)
#define int64 long long 
using namespace std;

int main(){
  int N,ans;
  cin>>N;
  rep(i,6){
    ans+=N%10;
    N-=N%10;
    N/=10;
  }
  if(ans==1){
    cout<<10<<endl;
  }else{
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.append(X)
y.append(Y)

x.sort()
y.sort()
xmax = x[-1]
ymin = y[0]

if xmax<ymin:
    ans = "No War"
else: ans = "War"

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
struct edge {
    ll from;
    ll to;
    ll cost;
};
int main(void){
    ll n,m;
    ll d[1000];
    vector<edge> edges;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        struct edge add;
        cin>>add.from>>add.to>>add.cost;
        add.from--,add.to--;
        edges.push_back(add);
    }
    fill(d,d+n,-INF);
    d[0]=0;
    bool negative_cycle=false;
    for(int i=0;i<n-1;i++){
        for(auto e:edges){
            if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    ll a=d[n-1];
    for(int i=0;i<n-1;i++){
        for(auto e:edges){
            if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    if(a!=d[n-1]) cout<<"inf"<<endl;
    else cout<<d[n-1]<<endl;
}

Measured memory_bytes: 384
N = int(input())

A = (int(x) for x in input().split())

A = list(A)

step = 0

for i in range(N-1):
    if A[i] - A[i+1] >= 0:
        step += A[i] - A[i+1]
        A[i+1] += A[i] - A[i+1]



print(step)

Measured memory_bytes: 32152
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        if (int.Parse(s) % m1(s) == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }

    static int m1(string s)
    {
        var sum = 0;
        for (int i = 0; i < s.Length; i++)
        {
            sum += s[i] - '0';
        }
        return sum;
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
const ll mod = 998244353;

int t[200 * 1001 * 4];

int Max (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return t[v];
	int tm = (tl + tr) / 2;
	return max(Max (v*2, tl, tm, l, min(r,tm)),
		Max (v*2+1, tm+1, tr, max(l,tm+1), r));
}

void Update (int v, int tl, int tr, int pos, int new_val) {
	if (tl == tr)
		t[v] = new_val;
	else {
		int tm = (tl + tr) / 2;
		if (pos <= tm)
			Update (v*2, tl, tm, pos, new_val);
		else
			Update (v*2+1, tm+1, tr, pos, new_val);
		t[v] = max(t[v*2], t[v*2+1]);
	}
}

int main()
{
  int n;
  cin >> n;
  vector<pair<ll, ll>> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  vector<int> skip(n);
  for (int i = 0; i < n; ++i) {
    auto it = lower_bound(a.begin(), a.end(),
        make_pair<ll, ll>(a[i].first + a[i].second, -1));
    skip[i] = it - a.begin() - 1;
  }

  Update(1, 0, n, 2, 2);
  for (int i = n - 1; i >= 0; --i) {
    skip[i] = max(skip[i], Max(1, 0, n, i, skip[i]));
    Update(1, 0, n, i, skip[i]);
  }

  vector<ll> ans(n + 1);
  ans[n] = 1;
  for (int i = n - 1; i >= 0; --i) ans[i] = (ans[i + 1] + ans[skip[i] + 1]) % mod;
  cout << ans[0] << endl;
  return 0;
}


Measured memory_bytes: 7808
a, b, k = map(int, input().split())
ans = set([])
for i in range(0, k):
    if a + i > b or b - i < a:
        break
    ans.add(a + i)
    ans.add(b - i)
ans = list(ans)
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 3060