akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int n,m;
int dame[200000];
int ans[200000];
signed main(){
  cin >> n >> m;
  REP(i,m){
    int k;
    cin >> k;
    dame[k] ++;
  }
  ans[0] = 1;
  if(dame[1]==0) ans[1] = 1;
  for(int i = 2;i<=n;i++){
    if(dame[i]==1) continue;
    ans[i] = ans[i-1] + ans[i-2];
    ans[i] %= MOD;
  }
  cout << ans[n]%MOD << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
  int N,i,j,A,B,tmp;
  A=0;
  B=0;
  int a[N];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<N-1;i++){
    for(j=i+1;j<N;j++){
      if(a[j]>a[i]){
        tmp = a[j];
        a[j]=a[i];
        a[i]=tmp;
      }
    }

  }

  for(i=0;i<N;i++){
    if(i%2==0){
      A+=a[i];
    }
    else{
  B+=a[i];
    }
  }
  printf("%d\n",A-B);
  return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;


ll gcd(ll a, ll b)
{
	if (a%b == 0) return(b);
	else return(gcd(b, a%b));
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}


ll f(ll x, ll C, ll D){

	ll cnt = x;
	cnt -= x/C + x/D - x/lcm(D, C);
	return cnt;
}

int main(void){

	ll A, B, C, D; cin >> A >> B >> C >> D;

	ll ans = (f(B, C, D) - f(A-1, C, D));
	cout << ans << endl;



	return 0;

}


Measured memory_bytes: 3608
N,W=map(int, input().split())
dp=[[0 for j in range(W+1)] for i in range(N+1)]
v=[0]*(N+1)
w=[0]*(N+1)
for i in range(1,N+1):
    v[i],w[i]=map(int,input().split())
for i in range(1,N+1):
    for j in range(1,W+1):
        if j < w[i]:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i])
print(dp[N][W])


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

using namespace std;

int main()
{
	string a,b,c;
	cin >> a >> b >> c;
	char now='a';
	int ac=0,bc=0,cc=0;
	while(true)
	{
		if(now=='a')
		{
			ac++;
			if(ac>a.size())
			{
				cout << "A" << endl;
				return 0;
			}
			now=a[ac-1];
		}
		else if(now=='b')
		{
			bc++;
			if(bc>b.size())
			{
				cout << "B" << endl;
				return 0;
			}
			now=b[bc-1];
		}
		else
		{
			cc++;
			if(cc>c.size())
			{
				cout << "C" << endl;
				return 0;
			}
			now=c[cc-1];
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

long long int power(long long int a, int n){
	if(n == 0){
		return 1;
	}
	else if(n % 2 == 0){
		return power(a * a, n / 2);
	}
	else{
		return a * power(a, n - 1);
	}
}

int main(){
	int N, A, i, j, xsub, k, l;
	scanf("%d%d", &N, &A);
	int x[2][N], xnum[2] = {0, 0}, xznum = 0;
	for(i = 0; i < N; i++){
		scanf("%d", &xsub);
		if(xsub == A){
			xznum++;
		}
		else if(xsub > A){
			x[0][xnum[0]] = xsub - A;
			xnum[0]++;
		}
		else{
			x[1][xnum[1]] = A - xsub;
			xnum[1]++;
		}
	}
	if(xnum[0] < xnum[1]){
		k = 0;
		l = 1;
	}
	else{
		k = 1;
		l = 0;
	}
	long long int way[N * 25], sum = 0;
	way[0] = power(2, xznum);
	for(i = 1; i < N * 25; i++){
		way[i] = 0;
	}
	for(i = 0; i < xnum[k]; i++){
		sum += x[k][i];
		for(j = sum; j >= x[k][i]; j--){
			way[j] += way[j - x[k][i]];
		}
	}
	for(i = 0; i < xnum[l]; i++){
		for(j = 0; j <= sum - x[l][i]; j++){
			way[j] += way[j + x[l][i]];
		}
	}
	printf("%lld\n", way[0] - 1);
	return 0;
}

Measured memory_bytes: 128
/*
 *  * main.cpp
 *   *
 *    */

#include <bits/stdc++.h>
using namespace std;


bool cmp(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}
int main() {

    int n, r;
    scanf("%d%d", &n, &r);
    if (n >= 10) printf("%d\n", r);
    else {
        printf("%d\n", r + 100 * (10 - n));
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] H = new int[N + 1];
            for (int i = 0; i < N; i++) {
                H[i] = in.nextInt();
            }
            H[N] = Integer.MAX_VALUE;
            int max = 0;
            int cur = 0;
            for (int i = 0; i < N; i++) {
                if (H[i] >= H[i + 1]) {
                    cur++;
                } else {
                    max = Math.max(max, cur);
                    cur = 0;
                }
            }
            out.println(max);
        }

    }
}



Measured memory_bytes: 52464
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
    char s[11];
}node;

int compare_ascending(const void* a, const void* b){
    int x = *(char*)a-*(char*)b;
    return x;
}

int compare_ascending2(const void* a, const void* b){
    int z = strcmp(((node*)a)->s ,  ((node*)b)->s);
    return z;
}

int main(){
    int n;
    scanf("%d", &n);
    long long int ans = 0;
    node a[n];
    for(int i=0; i<n; i++){
        char buf[11];
        scanf("%s", buf);
        qsort(buf, 10, sizeof(char), compare_ascending);
        strcpy(a[i].s, buf);
    }
    qsort(a, n, sizeof(node), compare_ascending2);
    int x = 1;
    for(int i=1; i<n; i++){
        if(strcmp(a[i-1].s, a[i].s) == 0){
            ans += x;
            x++;
        }else{
            x = 1;
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 2300
/* kadai3_4
   nabe9393 */
 
#include<stdio.h>
 
int main(void){
  int number, i, answer=0; //answerの値で判断。
  scanf("%d", &number ); //入力
  for(i=1; i < 10; i++){ //初期化　条件判定　更新
    if(number % i == 0 && number / i < 10){ //割り切れて尚且つ商が１０未満
      answer++; //answerに１を足す
    }
  }
  if(answer != 0){ //answerが０ではない時がYes
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
return 0;
} 

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

using namespace std;

int gcd(int a, int b){
    if(a%b == 0){
        return b;
    }else{
        return gcd(b, a%b);
    }
}

int main(int argc, char const *argv[])
{
    int k;
    cin >> k;
    int ans = 0;

    for(int a = 1; a < k+1; a++){
        for(int b = 1; b < k+1; b++){
            for(int c = 1; c < k+1; c++){
                ans += gcd(a, gcd(b, c));
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
program pie
  implicit none
  integer ::N,L,ful,kake,i,sa
  integer :: tabe

  read(*,*) N,L
  ful=L*N+N*(N-1)/2
  sa=N*1000
  do i=1,N
     kake=ful-L-(i-1)
     if(abs(kake-ful).lt.sa) then
        sa=abs(kake-ful)
        tabe=kake
     endif
  enddo
  write(*,'(i0)') tabe

end program pie

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] pri = new int[260000];
		for(int i=2;i<=250000;i++){
			pri[i] = i;
		}
		for(int i=2;i<=300000;i++){
			for(int j=i+i;j<=250000;j+=i){
					pri[j]=0;
			}
		}

		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int sum=0;
			int count=0;
			int i=0;
			while(count<n){
				if(pri[i]>0){
					sum += pri[i];
					count++;
				}
				i++;
			}
			System.out.println(sum);
		}
	}
	
}

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

int sum(int N) {
    return N * (N + 1) / 2;
}
int main() {
    int N, L;
    cin >> N >> L;

    if (L >= 0) cout << sum(L + N - 1) - sum(L) << endl;
    else if (L < 0 && L + N - 1 >= 0) cout << sum (L + N - 1) - sum(-L) << endl;
    else cout << sum(-(L + N - 1)) - sum(-L) << endl;
}

Measured memory_bytes: 256
#include        <map>
#include      <cmath>
#include      <queue>
#include     <string>
#include     <cstdio>
#include     <vector>
#include    <cstring>
#include   <iostream>
#include  <algorithm>
using namespace std;
#define ll long long
const ll inf = 0x3f3f3f3f;
const int maxn = 55;
const ll mod = 1e9+7;

double a[maxn];

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

    for(int i=1;i<n;i++){
        a[i] = (a[i]+a[i-1])/2;
    }
    printf("%.5f\n",a[n-1]);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a, b;
    int win;
    scanf("%d %d", &a, &b);
    win = a + b;
    if(a - b > win){
        win = a - b;
    }
    if(a * b > win){
        win = a * b;
    }
    printf("%d", win);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18;
const int N = (int)5e5 + 100;
const int MAXA = (int)3e6;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ifstream cin("input.txt");
    // ofstream cout("output.txt");
    string s;
    cin >> s;
    int n = s.size();
    int r = 0,p = 0;
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(r == p){
            if(s[i] == 'p')ans--;
            r++;
        }else{
            if(s[i] == 'g')
            ans++;

            p++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3764
S=input()
N=len(S)

check=True

for i in range( (N-1)//2 ):
    if S[i]!=S[N-1-i]:
        check=False

S_sub1 = S[0:(N-1)//2]
N1=len(S_sub1)
if N1%2==1:
    for i in range( (N1-1)//2 ):
        if S_sub1[i]!=S[N1-1-i]:
            check=False
else:
    for i in range( N1//2 ):
        if S_sub1[i]!=S[N1-1-i]:
            check=False

S_sub2 = S[ (N+3)//2-1:N]
N2=len(S_sub2)
if N2%2==1:
    for i in range( (N2-1)//2 ):
        if S_sub2[i]!=S[N2-1-i]:
            check=False
else:
    for i in range( N2//2 ):
        if S_sub2[i]!=S[N2-1-i]:
            check=False

if check:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int N,M;
P t[10000];
 
int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    for(int i=0;i<N;i++)cin>>t[i].second>>t[i].first;
    sort(t,t+N);
    reverse(t,t+N);
    int ans=0;
    for(int i=0;i<N;i++){
      int d=min(M,t[i].second);
      M-=d;
      ans+=t[i].first*(t[i].second-d);
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main()
{
  char _[100], s[100], __[100];
  cin >> _ >> s >> __;
  cout <<  "A" << s[0] << "C" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b,c;
  int count5=0,count7=0;
  cin>>a>>b>>c;
  if(a==5)  count5++;
  if(a==7)  count7++;
  if(b==5)  count5++;
  if(b==7)  count7++;
  if(c==5)  count5++;
  if(c==7)  count7++;
  if(count5==2&&count7==1){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
      int []po=new int[]{0,2,0,1,0,1,0,0,1,0,1,0};
        Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      int m=sc.nextInt();
      System.out.println((n+m<10)?n+m:"error");
    }
}


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

int A[210][210];

template <typename T>
void warshallFloyd(T& d){
    for (int i = 0; i < d[0].size(); i++) d[i][i] = 0;

    for (int k = 0; k < d[0].size(); k++){
		for (int i = 0; i < d[0].size(); i++){
	    	for (int j = 0; j < d[0].size(); j++){
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
	    	}
		}
    }
}

int main(){
	int H, W;
	cin >> H >> W;
	array<array<int, 10>, 10> c;
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			cin >> c[i][j];
		}
	}
	for (int  i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cin >> A[i][j];
		}
	}

	warshallFloyd(c);

	ll res = 0;
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			if (A[i][j] == -1) continue;

			res += c[A[i][j]][1];
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int t[100005];
int x[100005];
int y[100005];
int main()
{
    cin>>n;
    t[0]=0;
    x[0]=0;
    y[0]=0;
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    }
    int flag=0;
    for(int i=1;i<=n;i++){
        if(t[i]-t[i-1]<x[i]+y[i]-x[i-1]-y[i-1]||(t[i]-t[i-1]-x[i]-y[i]+x[i-1]+y[i-1])%2!=0){
            flag=1;
            break;
        }
    }
    if(flag==0){
        cout<<"Yes"<<endl;
        
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
//
// Created by 刘晴瑞 on 2020/8/29.
//

#include "cstdio"

int main(){
    int d,t,s;
    scanf("%d%d%d",&d,&t,&s);
    if (t * s >= d)
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;

using ll = long long;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

int main(){
  int N;
  string s[2];
  cin >> N >> s[0] >> s[1];

  ll ans = (s[0][0] == s[1][0] ? 3 : 6);
  for(int i = 1; i < s[0].size(); i++){
    if(s[0][i] == s[0][i - 1]) continue;
    if(s[0][i] == s[1][i]){
      if(s[0][i - 1] == s[1][i - 1]) ans = (ans * 2) % mod;
    }else{
      if(s[0][i - 1] == s[1][i - 1]) ans = (ans * 2) % mod;
      else ans = (ans * 3) % mod;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  double x[n];
  double money = 0.0;
  for(int i=0; i<n; i++){
    cin >> x[i];
    string u;
    cin >> u;
    if(u == "JPY") money += x[i];
    else money += x[i]*380000.0;
  }
  cout << money <<endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

int a[200100];

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    int k,n; cin>>k>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    int ans=min(a[n-1]-a[0],k-(a[1]-a[0]));

    for(int i=1;i<n;i++) {
        //start at house i
        if(i+1<n) ans=min(ans,k-abs(a[i+1]-a[i]));
        int temp2=k-abs(a[i]-a[i-1]);
        ans=min({ans,temp2});
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 1024
use proconio::input;

fn main() {
    input! {
        t: String,
    }
    let chars: Vec<_> = t.chars().collect();
    let mut questions = Vec::new();

    if chars.len() > 1 && chars.first().unwrap() == &'?' {
        match chars[1] {
            'P' => questions.push('D'),
            'D' | '?' => questions.push('P'),
            _ => unreachable!(),
        }
    } else if chars.len() == 1 && chars.first().unwrap() == &'?' {
        questions.push('D')
    }

    for window in chars.windows(3) {
        let (prev, now, next) = (window[0], window[1], window[2]);
        if now == '?' {
            match prev {
                'P' | '?' => questions.push('D'),
                'D' => match next {
                    'D' | '?' => questions.push('P'),
                    'P' => questions.push('D'),
                    _ => unreachable!(),
                },
                _ => unreachable!(),
            }
        }
    }

    if chars.last().unwrap() == &'?' {
        questions.push('D');
    }

    let mut result: Vec<_> = Vec::new();
    questions.reverse();
    for c in chars {
        match c {
            'P' => result.push('P'),
            'D' => result.push('D'),
            '?' => result.push(questions.pop().unwrap()),
            _ => unreachable!(),
        }
    }
    println!("{}", result.into_iter().collect::<String>());
}


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

int main() {

  int N;
  cin >> N;

  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}

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

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

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

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

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

/* library */

/* main */

signed main() {
    ll N;
    cin >> N;
    vector<pl> v;
    FOR(i, 0, N) {
        ll A, B;
        cin >> A >> B;
        v.push_back(make_pair(B, A));
    }
    ll t = 0;
    sort(ALL(v));
    FOR(i, 0, N) {
        ll A = v[i].second;
        ll B = v[i].first;
        t += A;
        if (B < t) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 6384
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;
#define N 12
int dx[]={1,0,0,-1};
int dy[]={0,-1,1,0};
char str[]="DLRU";
int num;
char ch[N*N];
int map[N][N];
int h,w;
bool dfs(int dep,int tx,int ty,int td){
    if (dep==num){
        return 1;
    }
    for (int i=0;i<4;i++){
        if (td+i==3) continue;
        for (int j=1;;j++){
            int nx=dx[i]*j+tx;
            int ny=dy[i]*j+ty;
            if (nx<0||ny<0||nx>h||ny>w) break;
            if (map[nx][ny]==1){
                map[nx][ny]=0;
                ch[dep]=str[i];
                if (dfs(dep+1,nx,ny,i)==1) return 1;
                map[nx][ny]=1;
                break;
            }
        }
    }
    return 0;
}
int main(){
    while (scanf("%d%d",&h,&w)==2){
        num=0;
        int sx,sy,sd;
        for (int i=0;i<h;i++){
            scanf("%s",ch);
            for (int j=0;j<w;j++){
                if (ch[j]=='o') {map[i][j]=1;num++;}
                else map[i][j]=0;
                if (ch[j]=='U') {sx=i,sy=j,sd=3;};
                if (ch[j]=='D') {sx=i,sy=j,sd=0;};
                if (ch[j]=='L') {sx=i,sy=j,sd=1;};
                if (ch[j]=='R') {sx=i,sy=j,sd=2;};
            }
        }
        //printf("%d\n",num);
        int flag=0;
        dfs(0,sx,sy,sd);
        for (int i=0;i<num;i++)
            printf("%c",ch[i]);
        printf("\n");
    }
    return 0;
}

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

int main(){
	int n,k;	cin>>n>>k;
	int ans=0;

	int x;
	for(int i=0;i<n;i++){
		cin>>x;
		ans+=min(x,k-x)*2;
	}

	cout<<ans<<endl;

	return 0;
}


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

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    set<pair<int, int>> hd;
    vector<ll> ans(10, 0);
    set<pair<int, int>> bl;
    for (int i = 0; i < n; i++)
    {
        int t1, t2;
        cin >> t1 >> t2;
        bl.insert(make_pair(t1 - 1, t2 - 1));
        for (int i = max(1, t1 - 2); i < min(h - 1, t1 + 1); i++)
        {
            for (int j = max(1, t2 - 2); j < min(w - 1, t2 + 1); j++)
                hd.insert(make_pair(i, j));
        }
    }
    ans[0] = 1ll * (h - 2) * (w - 2) - hd.size();
    for (auto x : hd)
    {
        int t = 0;
        for (int i = max(0, x.first - 1); i < min(h, x.first + 2); i++)
        {
            for (int j = max(0, x.second - 1); j < min(w, x.second + 2); j++)
            {
                if (bl.count(make_pair(i, j)))
                    t++;
            }
        }
        ans[t]++;
    }
    for (int i = 0; i < 10; i++)
        cout << ans[i] << endl;
}


Measured memory_bytes: 50444
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,m;
    cin >> n >> m;
    int Counter[m] = {};
    for(int i = 0; i < n; i++){
        int query;
        cin >> query;
        for(int j = 0; j < query; j++){
            int input;
            cin >> input;
            Counter[input-1] += 1;
        }
    }
    int count = 0;
    for(int i = 0; i < m; i++){
        if(Counter[i] == n){
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define NIL -1
#define M 10000
typedef struct{
  int l,r,p;
}Node;
Node Tree[M];
int n;
void Preorder(int u){
  if(u==NIL) return;
  printf(" %d",u);
  Preorder(Tree[u].l);
  Preorder(Tree[u].r);
}
void Inorder(int u){
  if(u==NIL)return;
  Inorder(Tree[u].l);
  printf(" %d",u);
  Inorder(Tree[u].r);
}
void Postorder(int u){
  if(u==NIL)return;
  Postorder(Tree[u].l);
  Postorder(Tree[u].r);
  printf(" %d",u);
}
int main(){
  int i,id,left,right,root;
  scanf("%d",&n);
  for(i=0;i<n;i++) Tree[i].p=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&left,&right);
    Tree[id].l=left;
    Tree[id].r=right;
    if(left!=NIL)Tree[left].p=id;
    if(right!=NIL)Tree[right].p=id;
  }
  for(i=0;i<n;i++)
    if(Tree[i].p==NIL) root=i;
  printf("Preorder\n");
  Preorder(root);
  printf("\n");
  printf("Inorder\n");
  Inorder(root);
  printf("\n");
  printf("Postorder\n");
  Postorder(root);
  printf("\n");
  return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,K; cin>>N>>K;
  int ans=0;
  rep(i,0,N){
    int X; cin>>X;
    if(K<=X) ans++;
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 1e5 + 1;

int n;
vi adj[N];
vpi e;
int col[N] = {}, parent[N];

void input()
{
	cin >> n;	
	FOR (i, 1, n - 1)
	{
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
		e.pb({x, y});
	}
}

void dfs (int cur = 1, int prev = 0)
{
    int clr = 0;
    parent[cur] = prev;
	for (int i: adj[cur])
		if (i != prev)
		{
		    clr++;
		    if (clr == col[cur]) clr++;
		    col[i] = clr;
			dfs(i, cur);
		}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	input();
    int mx = 0;
    FOR (i, 1, n) mx = max(mx, ll(adj[i].size()));
    cout << mx << endl;
    dfs();
    
    for (pi i: e)
    {
        if (parent[i.fi] == i.se) cout << col[i.fi] << endl;
        else cout << col[i.se] << endl;
    }
}

Measured memory_bytes: 9712
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int **A;
  int *b;
  int *c;
  int n, m, i, j;

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

  A = (int **)malloc(sizeof(int *) * n);
  for (i = 0; i < n; i++) {
    A[i] = (int *)malloc(sizeof(int) * m);
  }
  b = (int *)malloc(sizeof(int) * m);
  c = (int *)malloc(sizeof(int) * n);

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

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

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

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

  return 0;
}

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

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

	if(s[0] == s[1] && s[1] == s[2]){
    	cout << "No" << endl;
    } else {
    	cout << "Yes" << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n;
    ll sum = 0;
    cin >> n;
    vector<int>a,b(n-1);
    rep(i, n - 1)cin >> b[i];
    a.push_back(b[0]);
    rep(i, n - 2) {
        a.push_back(min(b[i], b[i + 1]));
    }
    a.push_back(b[n - 2]);
    for (auto s : a) {
        sum += s;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


void swap(int *nx, int *ny)
{
    int temp = *nx;
    *nx = *ny;
    *ny = temp;
}


void sort3(int *n1, int *n2, int *n3)
{
    if (*n1 > *n2) swap(n1, n2);
    if (*n2 > *n3) swap(n2, n3);
    if (*n1 > *n2) swap(n1, n2);
}

int main(void)
{
    int na, nb, nc;
    

    scanf("%d", &na);
    scanf("%d", &nb);
    scanf("%d", &nc);
    
    sort3(&na, &nb, &nc);
    

    printf("%d %d %d\n", na,nb,nc);

    
    return (0);
}


Measured memory_bytes: 2060
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int Q; cin >> Q;
	rep(i, 0, Q) {
		int a, b; cin >> a >> b;
		if (a > b)swap(a, b);
		int c = a*b;
		int d = sqrt(c);
		if (d*d == c)d--;
		if ((d + 1)*(d + 1) < c)d++;
		int ans = d*2;
		if (d*(d + 1) >= c)ans--;
		if (d >= b)ans--;
		if (d >= a)ans--;
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    int n;
    int c=0;
    cin>>n;
    int p[n];
    
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n-2;i++){
        if(p[i]<=p[i+1]&&p[i+1]<=p[i+2]||p[i]>=p[i+1]&&p[i+1]>=p[i+2])
            c++;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int gcd(int a,int b){
    if(a%b==0) return(b);
    else return(gcd(b,a%b)); 
}

int main(){
    ll k,ans=0;cin >> k;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                ll tem = gcd(i,j);
                ans += gcd(tem,l);
            }
        }
    }
    
    cout << ans << endl;
}

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


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

ll n;
cin>>n;

ll arr[n+1];
ll arr1[100001];
memset(arr1,0,sizeof(arr1));
ll sum1=0;
for(int i=0;i<n;i++){
    cin>>arr[i];
    sum1+=arr[i];
    arr1[arr[i]]++;
}
int q;
cin>>q;
ll sum=sum1;
while(q--){
    ll a,b;
    cin>>a>>b;

  if(arr1[a]!=0){
    sum=sum-(arr1[a]*a)+(arr1[a]*b);
    arr1[b]+=arr1[a];
    arr1[a]=0;
  }

  cout<<sum<<endl;
}

}



Measured memory_bytes: 5220
#-------------------------------------------------------------------------------
#関数定義
def f(a,d,T):
    try:
        return T[d+1:].index(a)+(d+1)
    except ValueError:
        return len(T)

def g(a,d,T):
    try:
        return (d-1)-T[d-1::-1].index(a)
    except ValueError:
        return 0
#-------------------------------------------------------------------------------
#インポート
from math import inf
from random import random,randint
import time
from copy import copy
#-------------------------------------------------------------------------------
#定数
TIME_LIMIT=1.83 #ループの時間制限
PROB=0.001 #突然変異の確率  
A=26 #アルファベットの数
START=time.time()
C_MIN,C_MAX=1,5
#-------------------------------------------------------------------------------
#読み込み部
D=int(input())

C=[0]+list(map(int,input().split())) #減る満足度のベース
S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))           
#-------------------------------------------------------------------------------
#貪欲部
L=[0]*(A+1)
T=[0]
for d in range(1,D+1):
    Y=-inf
    E=0
    for a in range(1,A+1):
        X=S[d][a]
        for s in range(1,A+1):
            if a!=s:
                X-=C[s]*(d-L[s])

        if X>Y:
            Y=X
            E=a
    L[E]=d
    T.append(E)
#-------------------------------------------------------------------------------
#調節部
while time.time()-START<=TIME_LIMIT:
    K=randint(C_MIN,C_MAX)
    e=randint(1,D)

    U=copy(T)
    X=0
    for d in range(e,min(e+K,D+1)):
        p=T[d]
        q=randint(1,A)
        Y=(d-g(p,d,T))*(f(p,d,T)-d)
        Z=(d-g(q,d,T))*(f(q,d,T)-d)
        X+=(S[d][q]-S[d][p])+Z*C[q]-Y*C[p]
        
    if X>0 or random()<PROB:
        T[d]=q
    else:
        T=copy(U)

for i in range(1,D+1):
    print(T[i])


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

#define ll long long
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define rfo(i,n,a) for(ll i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define N 3000001

int h[N];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll t,n,i,j,x;
    cin>>n;
    ll a[n],mx=0;
    fo(i,0,n){
    cin>>a[i];
    mx=max(mx,a[i]);
    }

    fo(j,0,n){
    ll x=a[j];
    for(i=1;x*i<=mx;i++){
            if(x*i>mx)
            break;
    h[x*i]++;
    }
    }
    ll ans=0;
    fo(i,0,n)
    if(h[a[i]]==1)
        ans++;
    cout<<ans<<endl;

}


Measured memory_bytes: 8996
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int X;
  cin >> X;
  
  int x = 0;
  int ans;
  for (ans = 1; x < X; ans++)
  {
    x += ans;
  }
  ans--;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = input()

rgb_cnt = Counter(S)
ans = rgb_cnt["R"] * rgb_cnt["G"] * rgb_cnt["B"] 

for i in range(1,N-1):
    max_dist = min(i,N-i-1)
    m = S[i]
    for d in range(1,max_dist+1): # 中心からの距離
        l = S[i-d]
        r = S[i+d]
        if (l!=m and r!=m and l!= r):
            ans -= 1
print(ans)




Measured memory_bytes: 9460
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 10;
int par[MAXN], nums[MAXN];
vector<int> idx[MAXN], val[MAXN];
int count(int i) {
    sort(idx[i].begin(), idx[i].end());
    sort(val[i].begin(), val[i].end());
    auto it1 = idx[i].begin();
    auto it2 = val[i].begin();
    int cnt = 0;
    while (it1 != idx[i].end() && it2 != val[i].end()) {
        if (*it1 == *it2) {
            cnt++;
            it1++;
            it2++;
        }
        else if (*it1 > *it2) it2++;
        else it1++;
    }
    return cnt;

}
int find(int i) {
    if (par[i] == i) return i;
    return par[i] = find(par[i]);
}
void add (int i,int j) {
    int a = find(i);
    int b = find(j);
    par[a] = b;
}
int main() {
//    freopen("test.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m, a, b;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> nums[i];
        par[i] = i;
    }
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        add(a, b);
    }
    for (int i = 1; i <= n; i++) {
        idx[find(i)].push_back(i);
        val[find(i)].push_back(nums[i]);
    }
    int tot = 0;
    for (int i = 1; i <= n; i++) {
        tot += count(i);
    }
    cout << tot << endl;



    return 0;
}

Measured memory_bytes: 12032
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
#define MAX 100100
//#define NIL -1

vector<int> parent(MAX);
vector<int> length(MAX);

void init(int n){
    for(int i=0; i<n; i++){
        parent[i]=i;
        length[i]=1;
    }
}

int find(int x){
    while(parent[x]!=x){
        x=parent[x];
    }
    return x;
}

bool same(int x, int y){
    return find(x)==find(y);
}

bool unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x==y){
        return false;
    }
    if(length[x]<length[y]){
        swap(x,y);
    }
    parent[y]=x;
    length[x]+=length[y];
    return true;
}

int main() {
    int n;
    int m;
    int k;
    cin >> n >> m >> k;
    vector<int> F(n,0);
    vector<int> B(n,0);
    init(n);

    for(int i=0; i<m; i++){
        int a;
        int b;
        cin >> a >> b;
        a--;
        b--;
        unite(a, b);
        F[a]++;
        F[b]++;
    }

    for(int i=0; i<k; i++){
        int c;
        int d;
        cin >> c >> d;
        c--;
        d--;
        if(same(c, d)){
            B[c]++;
            B[d]++;
        }
    }

    for(int i=0; i<n; i++){
        cout << length[find(i)] - F[i] - B[i] - 1 << " ";
    }
    cout << endl;

    return 0;
}

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

void solve() {
    ll n;
    cin >> n;
    vector<vector<ll> > v;
    for (int i = 0; i < n; i++) {
        ll x, y, z;
        cin >> x >> y >> z;
        vector<ll> curr = {x, y, z};
        v.push_back(curr);
    } 
    vector<vector<ll> > dp(n + 1, vector<ll>(3, 0));
    for (int i = 1; i <= n; i++) {
        dp[i][0] = v[i - 1][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = v[i - 1][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = v[i - 1][2] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define MOD 1000000007

using namespace std;

using ll = long long;

template <class T, T M>
class modulo {
public:
    T data;

    modulo(T data = 0) : data(data % M) {
    }

    modulo operator+(const modulo &x) const {
        return modulo(data + x.data);
    }

    modulo operator-(const modulo &x) const {
        return modulo(data + (M - x.data));
    }

    modulo operator*(const modulo &x) const {
        return modulo(data * x.data);
    }

    modulo operator/(const modulo &x) const {
        return modulo(data * x.inv().data);
    }

    modulo operator+=(const modulo &x) {
        return data = (data + x.data) % M;
    }

    modulo operator-=(const modulo &x) {
        return data = (data + (M - x.data)) % M;
    }

    modulo operator*=(const modulo &x) {
        return data = (data * x.data) % M;
    }

    modulo operator/=(const modulo &x) {
        return data = (data * x.inv().data) % M;
    }

    modulo inv() const {
        return _pow(M - 2);
    }

    template <class Integer>
    modulo operator^(Integer n) const {
        if (n >= 0) {
            return _pow(n);
        } else {
            return _pow(M - 1 - (-n) % (M - 1));
        }
    }

    friend std::ostream& operator<<(std::ostream &os, const modulo &x) {
        os << x.data;
        return os;
    }

private:
    template <class NonNegativeInteger>
    modulo _pow(NonNegativeInteger n) const {
        modulo result(1);
        modulo x(*this);
        while (n) {
            if (n & 1) {
                result *= x;
            }
            x *= x;
            n >>= 1;
        }
        return result;
    }
};

template <class T, T M>
struct combinatorics {

    using Mod = modulo<T, M>;

    T N;
    std::vector<Mod> factorial;
    std::vector<Mod> inv_factorial;

    combinatorics(T N) : N(N), factorial(N + 1), inv_factorial(N + 1) {
        factorial[0] = 1;
        for (T i = 1; i <= N; ++i) {
            factorial[i] = factorial[i - 1] * i;
        }
        inv_factorial[N] = factorial[N].inv();
        for (T i = N; i >= 1; --i) {
            inv_factorial[i - 1] = inv_factorial[i] * i;
        }
    }

    Mod P(T n, T k) {
        if (0 <= k && k <= n) {
            return factorial[n] * inv_factorial[k];
        } else {
            return 0;
        }
    }

    Mod C(T n, T k) {
        if (0 <= k && k <= n) {
            return factorial[n] * inv_factorial[k] * inv_factorial[n - k];
        } else {
            return 0;
        }
    }

    Mod H(T n, T k) {
        if (n == 0 && k == 0) {
            return 1;
        } else {
            return C(n + k - 1, k);
        }
    }
};

int main() {

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

    using Mod = modulo<ll, MOD>;

    int n, k;
    cin >> n >> k;
    k = min(k, n);

    combinatorics<ll, MOD> c(n);

    Mod result = 0;
    
    REP(i, k + 1) {
        result += c.C(n, i) * c.H(n - i, i);
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 6340
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
int b[222222];
int vis[6222];
int a[6666];
 
vector<ll> S;
 
void dfs(int u, ll s)
{
	if(vis[u]) return ;
	vis[u]=1;
	s+=b[u];
	S.pb(s);
	dfs(a[u],s);
}
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++) 
	{
		cin>>a[i]; a[i]--;
	}
	for(int i=0;i<n;i++) 
	{
		cin>>b[i]; 
	}
	ll ans = -ll(1e18);
	for(int i=0;i<n;i++)
	{
		memset(vis,0,sizeof(vis));
		dfs(i,0);
		if(S.back()>0&&k>=int(S.size()))
		{
			ll q = k/int(S.size());
			if(q>=1)
			{
				ll mx = -ll(1e18);
				if(q-1>0) mx=0;
				for(int i=0;i<int(S.size());i++)
				{
					mx=max(mx,S[i]);
				}
				ans=max(ans,(q-1)*S.back()+mx);
			}
			
			{
				int r = k%int(S.size());
				ll mx = 0;
				for(int i=0;i<r;i++)
				{
					mx=max(mx,S[i]);
				}
				ans=max(ans,mx+q*S.back());
			}
		}
		else
		{
			for(int j=1;j<=k;j++)
			{
				if(j-1<S.size()) ans=max(ans,S[j-1]);
				else break;
			}
		}
		S.clear();
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 3988
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        List<String> s = new ArrayList<>();
        boolean ok = true;
        for (int i = 0; i < n; i++) {
            String x = sc.next();
            if (s.contains(x)) {
                ok = false;
            }
            s.add(x);
        }
        if (!ok) {
            System.out.println("No");
            return;
        }
        for (int i = 0; i < n; i++) {

            int last = s.get(i).length() - 1;
            if (i == n - 1) {
                break;
            }
            if (s.get(i).charAt(last) != s.get(i + 1).charAt(0)) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

struct Restaurant {
    string name;
    int score;
    int id;
};

bool compare(const Restaurant& r1, const Restaurant& r2)
{
    if (r1.name == r2.name) {
        return r1.score > r2.score;
    } else {
        return r1.name < r2.name;
    }
}

int main()
{
    int n;
    cin >> n;

    vector<Restaurant> v(n);
    for (int i = 0; i < n; i++) {
        Restaurant r;
        cin >> r.name >> r.score;
        r.id = i + 1;
        v[i] = r;
    }
    sort(v.begin(), v.end(), compare);
    for (int i = 0; i < n; i++) {
        cout << v[i].id << endl;
    }
    return 0;
}

Measured memory_bytes: 256