akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {  
  int N;
  cin >> N;
  
  vector<int> num(N);
  int i;
  for (i = 0; i < N; i++){
    cin >> num.at(i);
  }
  
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  
  int score = 0;
  for (i = 0; i < N; i += 2){
    score += num.at(i);
    if (i + 1 < N){
      score -= num.at(i + 1);
    }
  }
  cout << score << endl;
}

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

typedef long long ll;

int main() {

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

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

    int k = 0;
    cin >> k;

    int i = 0;
    ll multi = 0;
    for(i = 0; i <= 1e6; i++) {
        multi = multi * 10 + 7;
        multi = multi % k;


        if(multi == 0) break;
    }

    if(i <= 1e6) cout << i + 1 << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int a[100005];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(a[n]!=2)
    {
        printf("-1\n");
        return 0;
    }
    ll MIN=2,MAX=3;
    for(int i=n-1;i>0;i--)
    {
        m=max(m,a[i]);
        if(MAX<a[i])
        {
            printf("-1\n");
            return 0;
        }
        else MAX=MAX/a[i]*a[i]+a[i]-1;
        if(MIN%a[i]==0) continue;
        if(MIN<a[i]) MIN=a[i];
        else MIN=(MIN/a[i]+1)*a[i];
        if(MIN>MAX)
        {
            printf("-1\n");
            return 0;
        }
    }
    printf("%lld %lld\n",MIN,MAX);
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[2100];
double dp[2100][2100];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		scanf("%s",str);
		for(int i=0;i<=b;i++)for(int j=0;j<a;j++)dp[i][j]=0;
		dp[0][0]=1;
		for(int i=0;i<b;i++){
			for(int j=0;j<a;j++){
				for(int k=1;k<=6;k++){
					dp[i+1][(j+k)%a]+=dp[i][j]/6;
				}
			}
		}
		double ret=0;
		for(int i=0;i<a;i++){
			double val=0;
			for(int j=0;j<a;j++){
				if(str[(i+j)%a]=='R')val+=dp[b][j];
			}
			ret=max(ret,val);
		}
		printf("%.12f\n",ret);
	}
}

Measured memory_bytes: 33904
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  else{
    if (N % 2 == 0) return Pow(A * A % nmax, N / 2) % nmax;
    else return A * Pow(A * A % nmax, N / 2) % nmax;
  }
}

ll nCr(ll N, ll R){
  ll ans = 1;
  for (ll i = 1; i <= R; i++){
    ans *= N + 1 - i; ans %= nmax;
    ans *= Pow(i, nmax - 2); ans %= nmax;
  }
  return ans;
}

int main(){
  ll N, A, B; cin >> N >> A >> B;

  ll ans = Pow(2, N) - 1;

  ans -= nCr(N, A); ans %= nmax;
  ans -= nCr(N, B); ans %= nmax;
  if (ans < 0) ans += nmax;
  ans %= nmax;
  cout << ans << endl;


  return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    int ans = pow(10, 9);
    for(int i=0; i<n-k+1;i++){
        int dif;
        dif = h.at(i+k-1) -h.at(i);
        ans = min(ans, dif);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define F(i, n) for (i = 0; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
int32_t main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s, t;
  int i;
  cin >> s >> t;
  t.erase(t.length() - 1);
  if (s.compare(t) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,c;
vector<int> vec[100001];
int l[100001];
vector<int> vi;

int main(void){
	scanf("%d%d%d",&n,&m,&c);
	for(int i=0;i<c;i++){
		scanf("%d",&l[i]);
	}
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		vec[a].push_back(b);
		//printf("%d %d\n",a,b);
	}
	for(int i=0;i<c;i++){
		sort(vec[i].begin(),vec[i].end());
		reverse(vec[i].begin(),vec[i].end());
		for(int j=0;j<min((int)vec[i].size(),l[i]);j++){
			vi.push_back(vec[i][j]);
		}
	}
	sort(vi.begin(),vi.end());
	reverse(vi.begin(),vi.end());
	int ans=0;
	for(int i=0;i<min(m,(int)vi.size());i++){
		ans+=vi[i];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 8024
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<long long int> A(6);
	for (int i = 0; i < 6; i++) {
		cin >> A[i];
	}
	long long int Min = A[1];
	int rec = 0;
	for (int i = 1; i < 6; i++) {
		if (Min >= A[i]) {
			Min = A[i];
			rec = i;
		}
	}
	if (A[0] % A[rec] != 0) {
		cout << (A[0] / A[rec]) + 5 << endl;
	}
	else {
		cout << (A[0] / A[rec]) + 4 << endl;
	}
	return 0;
}

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


def main():
    INF = 10**9
    N, M = map(int, input().split())
    h = []
    dp = [INF for i in range(1 << N)]

    for i in range(M):
        a, b = map(int, input().split())
        s = 0
        for c in map(int, input().split()):
            c -= 1
            s |= 1 << c
        h.append((a, s))

    dp[0] = 0

    for s in range(1 << N):
        for i in range(M):
            t = s | h[i][1]
            cost = dp[s] + h[i][0]
            dp[t] = min(dp[t], cost)

    print(dp[-1] if dp[-1] != INF else -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N] = {};
int d[N];

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while (!q.empty()) {
        u = q.front(); q.pop();
        for (int v = 0; v < n; v++) {
            if (M[u][v] == 0) continue;
            if (d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i+1 << ' ' << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}

int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);
}


Measured memory_bytes: 3116
#include "stdio.h"
#include "string.h"

char tablew[256];

int main()
{
	char* table = tablew + 128;
	while(1)
	{
		for(int i = -128; i < 128; i++)
		{
			table[i] = i;
		}
		int n;
		scanf("%d",&n);
		if(n == 0)
		{
			break;
		}
		for(int i = 0; i < n; i++)
		{
			char w1,w2;
			scanf(" %c %c",&w1,&w2);
			table[w1] = w2;
		}
		int m;
		scanf("%d",&m);
		for(int i = 0; i < m; i++)
		{
			char w1;
			scanf(" %c",&w1);
			printf("%c",table[w1]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1000
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<numeric>
#include<algorithm>
using namespace std;

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

	if (N == M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = [int(x) for x in input().split()]
if N == 1:
  print("Yes")
else:
  for i in reversed(range(1,N)):
    if H[i]-H[i-1] >= 0:
      continue
    else:
      if H[i-1] - H[i] <= 1:
        H[i-1] -= 1
      else:
        print("No")
        quit()

  if H[1]-H[0] >= 0:
    print("Yes")
  else:
    if H[0]-H[1] <= 1:
      print("Yes")
    else:
      print("No")

Measured memory_bytes: 14396
n = int(input())
As  = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
for a in As:
    d[a] += 1
S = sum(As)

q =int(input())
for _ in range(q):
    b,c = map(int, input().split())
    tmp = d[b]
    S -= b*tmp
    S += c*tmp
    d[b] = 0
    d[c] += tmp
    print(S)


Measured memory_bytes: 23832
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
//---------------------------
int N;
int A[200000],B[200000],b[200000];
int ans=0;

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>N;
  REP(i,N) cin>>A[i];
  REP(i,N) cin>>B[i];

  REP(k,29){
    ll T = 1<<k;
    REP(i,N) b[i]=B[i]%(2*T);
    sort(b, b+N);
    ll t_sum=0;

    REP(i,N){
      // a固定
      ll fix_a = A[i]%(2*T);
      int T01 = lower_bound(b,b+N,T-fix_a) - b;
      int T12 = lower_bound(b,b+N,2*T-fix_a) - b;
      int T23 = lower_bound(b,b+N,3*T-fix_a) - b;
      t_sum += (T12 - T01) + (N - T23);
    }
    if(t_sum%2 == 1) ans += T;
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 2560
N=int(input())
*A,=map(int,input().split())
s=[0,*A,0]
x=[abs(s[i]-s[i-1]) for i in range(1,len(s))]
S=sum(x)

for i in range(1,N+1):
    print(S-abs(s[i]-s[i-1])-abs(s[i+1]-s[i])+abs(s[i+1]-s[i-1]))

Measured memory_bytes: 20444
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <set>
#include <map>
#include <string>
#define SIZE 2005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int dp[SIZE][SIZE];

int main()
{
	int n,m,K;
	scanf("%d %d %d",&n,&m,&K);
	for(int i=1;i<K;i++)
	{
		dp[i][K-i]=1;
	}
	for(int L=2*K-1;L<=n+m;L+=K-1)
	{
		for(int i=0;i<=L;i++)
		{
			int s=i,t=L-i;
			if(s>=SIZE||t>=SIZE) continue;
			for(int j=0;j<K;j++)
			{
				if(s>=j&&t>=K-j-1)
				{
					dp[s][t]+=dp[s-j][t-(K-j-1)];
					if(dp[s][t]>=MOD) dp[s][t]-=MOD;
				}
			}
		}
	}
	int ret=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if((n-i)%(K-1)==0&&(m-j)%(K-1)==0)
			{
				ret+=dp[i][j];
				if(ret>=MOD) ret-=MOD;
			}
		}
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 15872
#include <iostream>
using namespace std;
 
int main() {
	int X,Y;
	cin>>X>>Y;
	if(Y%2==0){
		if(Y<2*X||Y>4*X){
			cout<<"No"<<endl;
		}
		else{
			cout<<"Yes"<<endl;
		}
	}else
		cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3632
import Control.Applicative
import Data.Maybe
import Data.List

data Dice = Dice {
    top :: Integer,
    right :: Integer,
    left :: Integer,
    front :: Integer,
    back :: Integer,
    bottom :: Integer
} deriving (Show)

data Direction = E | N | S | W deriving (Eq, Show, Read)
data Relative = RIGHT | LEFT deriving (Eq, Show, Read)

main = do 
    [t, f, r, l, bk, bt] <- toIntList <$> getLine
    getLine
    nss <- map toIntList . lines <$> getContents
    let dice = Dice { top=t, front=f, right=r, left=l, back=bk, bottom=bt }
    mapM_ (\[x,y] -> print . right $ ans dice x y) nss


toIntList :: String -> [Integer]
toIntList = map read . words


rotate :: Dice -> Direction -> Dice
rotate Dice {top=t, right=r, left=l, front=f, back=bk, bottom=bt} E =
    Dice{ right = t, top = l, left = bt, bottom = r, front = f, back = bk }

rotate Dice {top=t, right=r, left=l, front=f, back=bk, bottom=bt} W =
    Dice{ left = t, top = r, right = bt, bottom = l, front = f, back = bk }

rotate Dice {top=t, right=r, left=l, front=f, back=bk, bottom=bt} N =
    Dice{ back = t, top = f, front = bt, bottom = bk, right = r, left = l }

rotate Dice {top=t, right=r, left=l, front=f, back=bk, bottom=bt} S =
    Dice{ front = t, top = bk, back = bt, bottom = f, right = r, left = l }


roll :: Dice -> Relative -> Dice
roll Dice {top=t, right=r, left=l, front=f, back=bk, bottom=bt} RIGHT =
    Dice{ front = l, right = f, back = r, left = bk, top = t, bottom = bt }

roll Dice {top=t, right=r, left=l, front=f, back=bk, bottom=bt} LEFT =
    Dice{ front = r, left = f, back = l, right = bk, top = t, bottom = bt }


ans :: Dice -> Integer -> Integer -> Dice
ans d t f =
    let rolls = (scanl rotate d $ replicate 4 N) ++ (scanl roll d $ replicate 3 RIGHT)
        fd = fromJust $ find (\x -> front x == f) rolls in
        fromJust . find(\x -> top x == t) . scanl rotate fd $ replicate 4 E





Measured memory_bytes: 4108
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sam = a+b;
		
      	if(a%3==0 || b%3==0 || sam%3==0){
          System.out.print("Possible");
        }else{
          System.out.print("Impossible");
        }
      
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
#define ll long long
#define ull unsigned long long

char grid[1100][1100]{};
ll dp[1100][1100]{};

ll mod = 1000000007;
int main()
{

    ll H,W;
    cin>>H>>W;

    for(int i = 0 ; i<H ; i++)
    for(int j = 0 ; j<W ; j++)
    cin>>grid[i][j];



    dp[0][0] = 1;
    for(int i = 0 ; i<H ; i++)
    {
        for(int j = 0 ; j<W ; j++)
        {
            if(grid[i][j]=='#')continue;
            if(i-1>=0)dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
            if(j-1>=0)dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;

        }
    }


    cout<<(dp[H-1][W-1])%mod<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    vector<int> per;
    double div = 1;
    rep(i, N) {
        div *= i + 1;
        per.push_back(i);
    }
    double ans = 0;
    do {
        int p_x = 0;
        int p_y = 0;
        rep(i, N) {
            P p = items[per[i]];
            if (i != 0) {
                ans += pow(pow(abs(p_x - p.first), 2) + pow(abs(p_y - p.second), 2), 0.5);
            }
            p_x = p.first;
            p_y = p.second;
        }
    } while (next_permutation(per.begin(), per.end()));

    cout << ans / div << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
    int row, col;
    int sum[110] = {};
    int sheet[110][110];
    
    cin >> row >> col;
    
    int i, j;
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            cin >> sheet[i][j];
            cout << sheet[i][j] << " ";
            sheet[i][col] += sheet[i][j];
            sum[j] += sheet[i][j];
        }
        sum[col] += sheet[i][col];
        cout << sheet[i][col] << endl;
    }

    for(int i=0; i<col+1; i++){
        cout << sum[i];
        if(i == col) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
        return 0;
}



Measured memory_bytes: 3140
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] X = new int[5];

        for (int i = 0; i < 5; i++) {
            X[i] = sc.nextInt();
        }
        sc.close();

        for (int i = 0; i < 5; i++) {
            if (X[i] == 0) {
                System.out.println(i + 1);
            }
        }
        return;
    }
}


Measured memory_bytes: 35692
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& a){
	os<<'{';
	foreach(i,a) os<<(i!=begin(a)?" ":"")<<*i;
	return os<<'}';
}

set<int> calc(const set<int>& a,const set<int>& b,char op)
{
	set<int> res;
	for(int x:a) for(int y:b){
		if(op=='*') res.insert(x*y);
		if(op=='+') res.insert(x+y);
		if(op=='-') res.insert(x-y);
		if(op=='/' && y) res.insert(x/y);
	}
	return res;
}

set<int> expr(const string& s,int l,int r)
{
	vector<set<int>> vals;
	string ops;
	for(int i=l;i<r;i++){
		if(s[i]=='('){
			int cnt=0,j=i++;
			for(;j<r;j++){
				if(s[j]=='(') cnt++;
				if(s[j]==')') cnt--;
				if(cnt==0) break;
			}
			vals.push_back(expr(s,i,j));
			i=j;
		}
		else if(strchr("*+-/",s[i]))
			ops.push_back(s[i]);
		else{
			int x=0;
			for(;i<r && isdigit(s[i]);i++)
				x=x*10+s[i]-'0';
			vals.push_back(set<int>({x}));
			i--;
		}
	}
	int n=vals.size();
	vector<vector<set<int>>> dp(n,vector<set<int>>(n));
	rep(i,n) dp[i][i]=vals[i];
	per(i,n) repi(j,i+1,n) repi(k,i,j){
		set<int> t=calc(dp[i][k],dp[k+1][j],ops[k]);
		dp[i][j].insert(all(t));
	}
	return dp[0][n-1];
}

int main()
{
	for(string s;getline(cin,s),s!="#";)
		cout<<expr(s,0,s.size()).size()<<endl;
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define mod 1000000007
#define inf 9999999999999999ll
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
ll nCrModPFermat(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,y;
    cin>>x>>y;
    ll a=2*y-x;
    ll b=2*x-y;
    if(a>=0 && b>=0 && a%3==0 && b%3==0)
    {
    	a/=3;
    	b/=3;
    	cout<<nCrModPFermat(a+b,a,mod)<<endl;
    }
    else
    {
    	cout<<0<<endl;
    }
}


Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
#define pi 3.141592653589
using namespace std;
ll fact(ll n) {
	if (n == 0)return 1;
	return n * fact(n - 1) % 1000000007;
}
signed main() {
	ll n, m;
	cin >> n >> m;
	if (n == m)cout << fact(n) * fact(m) * 2 % 1000000007 << endl;
	else if (abs(n - m) == 1)cout << fact(n) * fact(m) % 1000000007 << endl;
	else cout << 0 << endl;
	getchar(); getchar(); return 0;
}


Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
int n,m;
int d[51];
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int t,tt;
		cin>>t>>tt;
		d[t]++;
		d[tt]++;
	}
	for(int i=1;i<=n;i++){
		cout<<d[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 100005
#define ll long long
int n;
ll a[maxn];
ll minn,maxx;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    minn=2,maxx=2;
    for(int i=n-1;i>=0;i--)
    {
        minn=((minn-1)/a[i]+1)*a[i];
        maxx=(maxx/a[i]+1)*a[i]-1;
    }
    if(minn>maxx)
        cout<<"-1"<<endl;
    else
        cout<<minn<<" "<<maxx<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,n,ans,d;
    cin>>n>>a>>b;
    c=n/(a+b);
    d=n%(a+b);
    if(d>a)d=a;
    ans=0;
    ans=c*a+d;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}

int a[2][20];
int dp[1 << 19][20];
const int INF = 1e9 + 7;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[0][i];
    for (int i = 0; i < n; i++) cin >> a[1][i];
    bool ok = true;
    for (int i = 0; i < n - 1; i++) ok &= (a[0][i] <= a[0][i + 1]);
    if (ok) {cout << 0 << '\n'; return 0;}
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 0; i < n; i++) dp[1 << i][i] = i;
    for (int mask = 1; mask < (1 << n); mask++) {
        for (int i = 0; i < n; i++) {
            if (!(mask & (1 << i))) continue;
            if (dp[mask][i] > INF) continue;
            int idx = __builtin_popcount(mask) - 1;
            int pre = a[(i ^ idx) & 1][i];
            for (int j = 0; j < n; j++) if (!(mask & (1 << j))) {
                int now = a[(j ^ (idx + 1)) & 1][j];
                if (now < pre) continue;
                int cost = j;
                for (int jj = 0; jj < j; jj++) if (mask & (1 << jj)) cost--;
                dp[mask | (1 << j)][j] = min(dp[mask | (1 << j)][j], dp[mask][i] + cost);
            }
        }
    }
    int ans = INF;
    for (int i = 0; i < n; i++) ans = min(ans, dp[(1 << n) - 1][i]);
    cout << ((ans < 1234567) ? ans : -1) << '\n';
    

    return 0;
}


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

int func(int a, int b){
    int res = 0;
    while(a > 0){
        a /= b;
        res++;
    }
    return res;
}

int main(){
    int N, K;
    cin >> N >> K;
    cout << func(N, K) << endl;
    return 0;
}

Measured memory_bytes: 3620
from operator import itemgetter
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=sorted(a,key=itemgetter(0))
buy=0
money=0
for j in range(n):
  if buy+b[j][1]<m:
    money+=b[j][0]*b[j][1]
    buy+=b[j][1]
  else:
    money+=(m-buy)*b[j][0]
    print(money)
    break
  

Measured memory_bytes: 29864
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
ll M = 1e9 + 7;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll s, w;
  cin >> s >> w;
  if (w >= s)
    cout << "unsafe";
  else
    cout << "safe";
}

Measured memory_bytes: 3556
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // 標準入力からデータを読み込む準備
        Scanner sc = new Scanner(System.in);
        int n, r, i, j;
        while ((n = sc.nextInt()) != 0 && (r = sc.nextInt()) != 0) {
            int data[] = new int[n];
            // 最初に一番下を1番として順にn番まで の札が積み上げられた山を仮定して，山を混ぜて切り終わったときから
            for (i = 0; i < n; i++) {
                data[i] = n - i;
            }
            for (i = 0; i < r; i++) {// r回値の確保
                int p = sc.nextInt();
                int c = sc.nextInt();
                // (３つに分割)配列ごと変数にしてる

                int subData[] = new int[n];
                for (j = 0; j < c; j++) {
                    subData[j] = data[p + j - 1];// 新しいのを定義しc個入れる
                }
                for (j = 0; j < p - 1; j++) {
                    subData[c + j] = data[j];// p-1まで入れる
                }
                for (j = 0; j < n + 1 - p - c; j++) {
                    subData[c + p - 1 + j] = data[c + p - 1 + j];
                }
                for (j = 0; j < n; j++) {// 代入
                    data[j] = subData[j];
                }
            }
            System.out.println(data[0]);

        }

    }
}



Measured memory_bytes: 37328
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>

int main()
{
	int a, b;
	a = 0, b = 0;

	scanf("%d %d", &a, &b);
	if (a >= -1000 && b <= 1000) {
		if (a > b) {
			printf("a > b\n");
		}
		else if (a == b) {
			printf("a == b\n");
		}
		else {
			printf("a < b\n");
		}
	}

	return 0;
}


Measured memory_bytes: 2024
#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>;

string s;

int main() {
  cin >> s;
  if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
    return 0;
  }
};

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

int mod = 1e9 + 7;

void add(int& a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}

// 桁DP
int dp[10007][110][2]; // dp[i][j][k]: i:桁 j:総和の余り k:K以下が確定しているか 0:no, 1:yes

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

    string K;
    int D;
    cin >> K;
    cin >> D;

    CLR(dp, 0);

    dp[0][0][0] = 1;
    REP(i, K.size()) {
        REP(j, D) {
            REP(k, 2) {
                int num = K[i] - '0';
                int t = k ? 9 : num;
                REP(d, t + 1) {
                    add(dp[i + 1][(j + d) % D][k || (d < num)], dp[i][j][k]);
                }
            }
        }
    }

    int ans = 0;
    REP(k, 2) add(ans, dp[K.size()][0][k]);
    cout << (ans - 1 + mod) % mod << endl;

    return 0;
}


Measured memory_bytes: 17536
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
  long long x = 1;
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n;
  std::cin>>n;

  std::map<std::string,ll> cnt;

  rep(i,0,n){
    std::string s;
    std::cin>>s;
    cnt[s]++;
  }

  ll max=0;
  for(auto e:cnt){
    chmax(max,e.second);
  }

  std::vector<std::string> ans;

  for(auto e:cnt){
    if(e.second==max)ans.push_back(e.first);
  }

  std::sort(all(ans));

  for(auto e:ans)std::cout<<e<<"\n";

  return 0;
}


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

bool ok[8][8];
int main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, m) {
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		ok[a][b] = ok[b][a] = true;
	}
	vector<int>v(n); iota(v.begin(), v.end(), 0);
	int cnt = 0;
	do {
		if (*v.begin())break;
		bool flag = true;
		rep(i, n - 1) {
			if (!ok[v[i]][v[i + 1]])flag = false;
		}
		if (flag)cnt++;
	} while (next_permutation(v.begin(), v.end()));
	printf("%d\n", cnt);
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
//const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};

mint exclude(ll n, ll a) {
    mint bunbo = 1;
    for (int i = 1; i <= a; i++) {
        bunbo *= i;
    }
    mint bunshi = 1;
    for (int i = 1; i <= a; i++) {
        bunshi *= (n - a + i);
    }

    return bunshi / bunbo;

}

int main() {

    ll n, a, b;
    cin >> n >> a >> b;

    mint all = mint(2).pow(n) - 1;

    mint ae = exclude(n, a);
    mint be = exclude(n, b);

    mint ans = all - ae - be;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
using namespace std;


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


int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n){
    cin >> d[i];
  }

  sort(d.begin(), d.end());
  
  int ans = 0;

  for(int i = d[n / 2 - 1]; i < d[n / 2]; ++i){
    ans++;
  }
  cout << ans << endl;

}


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

  string s=a+b>=c? "Yes":"No";
  Console.Write($"{s}");
 }
}

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

main(){
  ll n,w;
  cin>>n>>w;
  vector<ll> weight(n),value(n);
  for(ll i=0;i<n;++i)cin>>weight[i]>>value[i];

  vector<vector<ll> > dp(200,vector<ll>(200000));
  for(ll i=0;i<n;++i){
    for(ll j=0;j<=w;++j){
      if(j-weight[i]>=0)
        dp[i+1][j]=max(dp[i][j],dp[i][j-weight[i]]+value[i]);
      if(i>0)dp[i][j]=max(dp[i][j],dp[i-1][j]);
      if(j>0)dp[i][j]=max(dp[i][j],dp[i][j-1]);
    }
  }

  cout<<dp[n][w]<<endl;
}

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

#define ld long double
#define ll long long
#define ull unsigned long long

#define f first
#define s second

#define endl '\n'
#define pii pair <ll, ll>

#define ios ios_base::sync_with_stdio(0), cin.tie()
#define pb push_back
#define mp make_pair

#define pi 3.14159265358979323846264
#define y1 abacaba

using namespace std;

const int MXN = 1e5 + 30;
const int MAXN = 1e3 + 2;
const ll INF = 1e9 + 7;
const ll BINF = 1e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-15;   
const ll dx[] = {0, 0, 1, -1};      
const ll dy[] = {1, -1, 0, 0};
           
int n;
int a[MXN];
int b[MXN];
int c[MXN];

ll ans;
int cnt[MXN]; 
ll res;

int main(){
    //freopen("input.txt", "r", stdin); 
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i]; 
    } 
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> c[i];
    }
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    sort(c + 1, c + n + 1);
    int j = 1;
    for(int i = 1; i <= n; i++){
        while(a[j] < b[i] && j <= n){
            j ++;
        }
        cnt[i] = j - 1;
    } 
    j = 1; 
    for(int i = 1; i <= n; i++){
        while(b[j] < c[i] && j <= n){
            ans += cnt[j]; 
            j++;
        }
        res += ans;
    }
    cout << res;
    return 0;
}

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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

const LL mod = 1000000007;

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

    char pre = S[0];
    int ans = 0;
    REP(i, S.size()) {
        if (pre != S[i]) ans++;
        pre = S[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int l,r,d;
  cin>>l>>r>>d;


  int ans=0;
  for(int i=l;i<=r;i++){
    if(i%d==0) ans++;
  }
  

  cout << ans << endl;

}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main(){
    int n, h, w;
    cin >> n >> h >> w;
    int res=0;
    for(int i=0; i<n; ++i){
        int a, b;
        cin >> a >> b;
        if(a>=h && b>=w)
            ++res;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
package main
import (
    "bufio"
    "fmt"
    "math"
    "os"
    "strings"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
    if sc.Scan() {
        ret, _ := strconv.Atoi(sc.Text())
        return ret
    }
    return 0
}

func readLine() string {
    var ret string
    if sc.Scan() {
        ret = sc.Text()
    }
    return ret
}

func main(){
    s := readLine()
    params := strings.Split(s, " ")
    n, _ := strconv.Atoi(params[0])
    l, _ := strconv.Atoi(params[1])
    
    nSum := (l - 1) * n + n * (n + 1) / 2
    minAbsFlavor := int(math.Abs(float64(l)))
    for i := 1; i <= n; i++ {
        if flavor := l + i - 1; int(math.Abs(float64(flavor))) < int(math.Abs(float64(minAbsFlavor))) {
            minAbsFlavor = flavor
        }
    }
    result := nSum - minAbsFlavor
    fmt.Println(result)
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pii Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define int ll
signed main(void) {
	vector<int> a(4);

	cin >> a[0] >> a[1] >> a[2] >> a[3];

	sort(ALL(a));

	if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
		cout << "YES" << endl;
	else
	{
		cout << "NO" << endl;
	}



	return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count_combination = 0

for a_i in range(a + 1):
    for b_i in range(b + 1):
        for c_i in range(c + 1):
            sum_coins = 500 * a_i + 100 * b_i + 50 * c_i
            if sum_coins == x:
                count_combination += 1
            elif sum_coins > x:
                break
print(count_combination)


Measured memory_bytes: 3060
def run():
    n = int(input())
    li = [int(x) for x in input().split()]
    assert(len(li) == n)

    q = int(input())
    for _ in range(q):
        com, b, e = [int(x) for x in input().split()]
        if com == 0:
            print(min(li[b:e]))
        elif com == 1:
            print(max(li[b:e]))
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



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

int main() {
  long long A, B, K;
  cin >> A >> B >> K;
  if(K <= A) {
    cout << A - K << " " << B << endl;
  }
  else if(A < K && K <= A + B) {
    cout << 0 << " " << B - (K - A) << endl;
  }
  else if(A + B < K) {
    cout << 0 << " " << 0 << endl;
  }
}

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

using ll = long long;
const ll mod = 998244353;


ll dp[3030][3030][3];
int a[3030];
int main(){
    int n, k;
    cin >> n >> k;
    for(int i=0;i<n;i++)cin >> a[i];
    dp[0][0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=k;j++){ //和为0到k 
            (dp[i+1][j][0] += dp[i][j][0]) %= mod;
            (dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
            (dp[i+1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) %= mod;
            if(j + a[i] <= k){
                (dp[i+1][j+a[i]][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
                (dp[i+1][j+a[i]][2] += dp[i][j][0] + dp[i][j][1]) %= mod;
            }
        }
    }
    cout << dp[n][k][2] << endl;
}


Measured memory_bytes: 215296
def nCr(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

x,y = map(int,input().split())

if max(x,y) > 2 *min(x,y):
    print(0)
elif (x+y) % 3 == 0:
    k = (x+y)//3
    n = (2*x-y)//3
    print(nCr(k,n))
else:
    print(0)



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() { 
    int n;
    cin >> n;
    int a[110000];
    rep(i, n) {
        int A;
        cin >> A;
        A--;
        a[i] = A;
    }
    int count = 1;
    int j = 0;
    rep(i, 110000) {
        if(a[j] == 1) {
            cout << count << endl;
            return 0;
        }
        j = a[j];
        count++;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 4024
#include <iostream>
#include <fstream>
#include <vector>

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

typedef long long ll;

int main()
{

    int n, k;
    cin >> n;
    cin >> k;
    vector<int> h(n);

    int ans = 0;
    REP(i, n)
    {
        cin >> h[i];
        if (h[i] >= k)
            ans++;
    }
    cout << ans << endl;
    //printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 640
H, W = map(int, input().split())
grid = [input() for i in range(H)]
tate = [[-1]*W for i in range(H)]
yoko = [[-1]*W for i in range(H)]

def calc(x,y):
    if grid[y][x] == '#':
        return
    if tate[y][x] == -1:
        count = 1
        up = y
        down = y
        while True:
            if up == 0 or grid[up-1][x] == '#':
                break
            else:
                up -= 1
                count += 1
        while True:
            if down == H-1 or grid[down+1][x] == '#':
                break
            else:
                down += 1
                count += 1
        for i in range(up, down+1):
            tate[i][x] = count
    if yoko[y][x] == -1:
        count = 1
        left = x
        right = x
        while True:
            if left == 0 or grid[y][left-1] == '#':
                break
            else:
                left -= 1
                count += 1
        while True:
            if right == W-1 or grid[y][right+1] == '#':
                break
            else:
                right += 1
                count += 1
        for i in range(left, right+1):
            yoko[y][i] = count
    return

for x in range(W):
    for y in range(H):
        calc(x, y)

ans = 0
for x in range(W):
    for y in range(H):
       ans = max(ans, tate[y][x]+yoko[y][x]-1)
print(ans)
    

Measured memory_bytes: 123096