akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>

const int MAX = 200010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long h, w, a, b;
int main()
{
	COMinit();
	std::cin >> h >> w >> a >> b;

	long long ans = 0;
	for (long long i = b + 1; i <= w; ++i) {
		long long mh = h - a;
		long long w1 = i - 1;
		long long h1 = mh - 1;
		long long route1 = COM(w1 + h1, w1);

		long long w2 = w - i;
		long long h2 = h - (mh + 1);
		long long route2 = COM(w2 + h2, w2);

		ans = (ans + route1 * route2) % MOD;
	}

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


Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
signed main(){
    int n,sum=0;
    cin>>n;
    int h[n+2]={};
    int cost[n+5]={};
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    cost[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        cost[i]=min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<cost[n-1]<<"\n";
    return(0);
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int l, r, lmax=0, rmin=n;

    for(int i = 0; i < m; i++){
        cin >> l >> r;
        if(lmax < l) lmax = l;
        if(rmin > r) rmin = r;
    }
    if(rmin - lmax + 1 < 0){
        cout << 0 << endl;
    }else{
        cout << rmin - lmax + 1 << endl;
    }
}

Measured memory_bytes: 256
object Main extends App {
  val xy = scala.io.StdIn.readLine()
  val xyArray = xy.split(" ").map(_.toInt).toVector
  val x = xyArray(0)
  val y = xyArray(1)
  var sum = 0
  if (x == 1) {
    sum += 300000
  } else  if (x == 2) {
    sum += 200000
  } else  if (x == 3) {
    sum += 100000
  }

  if (y == 1) {
    sum += 300000
  } else  if (y == 2) {
    sum += 200000
  } else  if (y == 3) {
    sum += 100000
  }

  if (x == 1 && y == 1) {
    sum += 400000
  }

  println(sum)
}

Measured memory_bytes: 25656
#include<stdio.h>
#include<string.h>

int num;
int Qdata;
int ans;
int k;
int i;
int j;
int data[2010] = {1};

int main(){
  scanf("%d",&num);

  for(i = 0;i < num;i++){
    scanf("%d",&ans);

    for(j = 2000;j >= 0;j--){
      if(j + ans < 2001 && data[j]){
        data[j + ans] = 1;
      }
    }
  }
    scanf("%d",&Qdata);

    for(i = 0;i < Qdata;i++){
      scanf("%d",&k);
      puts(data[k]?"yes":"no");
    }
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    rep(i, d){
        cin >> p[i] >> c[i];
    }

    int ans = INF;
    rep(kk, 1<<d){
        int sum = 0;
        int cnt = 0;
        set<int> s;
        rep(j, d){
            if(kk>>j & 1){
                sum += c[j];
                sum += 100 * (j+1) *p[j];
                cnt += p[j];
                s.insert(j);
            }
        }

        // printf("  %d %d\n",sum, cnt);
        // for (auto i : s)
        // {
        //     printf(     "%d \n",i);
        // }

        for (int i = d-1; i >=0 ; i--){
            if(g <= sum) break;
            if(s.find(i) == s.end()){
                int u = 100*(i+1);
                if(g-sum <= u * p[i]){
                    int num = (g-sum+u-1)/u;
                    cnt += num;
                    sum += num*u;
                    break;
                }else{
                    cnt += (p[i]-1);
                    sum += 100 *(i+1) * (p[i]-1);
                }
            }
        }
        // printf("%d %d\n",sum, cnt);
        if(g <= sum) chmin(ans, cnt);
    }


    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,x,ans=0;
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> x;
		ans+=min(x,k-x);
	}
	cout << ans*2 << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int H, W, N;
  cin >> H >> W >> N;
  vi a(N);
  int ans[H][W];
  REP(i, N) cin >> a.at(i);
  int now = 0;

  REP(i, H) {
    if (i % 2 == 0) {
      REP(j, W) {
        ans[i][j] = now + 1;
        a.at(now)--;
        if (a.at(now) == 0) now++;
      }
    } else {
      for (int j = W - 1; j >= 0; j--) {
        ans[i][j] = now + 1;
        a.at(now)--;
        if (a.at(now) == 0) now++;
      }
    }
  }

  REP(i, H) {
    REP(j, W) cout << ans[i][j] << " ";
    cout << "\n";
  }

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(n%i==0){
            if(n/i<=9){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

typedef long long LL;

LL N, X;

LL f(LL a, LL b) {
	return b ? a / b * b * 2 + f(b, a % b) : -a;
}

int main() {
	scanf("%lld%lld", &N, &X);
	printf("%lld\n", N + f(X, N - X));
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 2e5;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e16;
const int inf = 1e9;

vector <int> g[N];

long long dp[N][5];

void dfs (int v = 0, int p = -1) {
	dp[v][0] = dp[v][1] = 1;
	for (int to : g[v]) if (to != p) {
		dfs (to, v);
		dp[v][0] *= (dp[to][0] + dp[to][1]);
		dp[v][1] *= dp[to][0];
		dp[v][0] %= mod;
		dp[v][1] %= mod;
	}
}

int main () {
	boost;
	int n;
	cin >> n;
	for (int i = 1 ; i < n ; ++ i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		g[a].push_back (b);
		g[b].push_back (a);
	}
	dfs();
	cout << (dp[0][0] + dp[0][1]) % mod;
}

Measured memory_bytes: 19456
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define re(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second


ll binpow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return binpow(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,n,i,f=0,j,ans=0,k,x,r,l,t;
    cin >> n >> x >> t  ;
    l=n/x;
    if(n%x!=0) l++;
    cout << l*t << endl ;
    
    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
    ll a,b,k;
    cin >> a >> b >> k ;
    
    if(k<=a){
        cout << a-k << " " << b << endl;
    }
    else if(k<=a+b){
        cout << 0 << " " << b-k+a << endl;
    }
    else{
        cout << 0 << " " << 0 << endl;
    }

    
}

Measured memory_bytes: 256
/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Vikash Kumar @ Codechef/codeforces 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/   
#include<bits/stdc++.h>
 
#define ll                    long long int
#define ll_MAX                LLONG_MAX
#define ll_MIN                LLONG_MIN
#define pi                    3.14159265358979323846
#define count_1(n)            __builtin_popcountll(n)
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define mid(s,e)              (s+(e-s)/2)
const int MX=10010896;
const int lmt=3164;
const int N=10000001;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

const ll MXX=3005;
ll dp[MXX][MXX];

inline void solve(){
    /*_Start_*/
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
      cin>>a[i];
    for(ll l=n-1;l>=0;l--){
      for(ll r=l;r<n;r++){
        if(l==r)
          dp[l][r]=a[l];
        else
          dp[l][r]=max( a[l]-dp[l+1][r],a[r]-dp[l][r-1]  );
      }
    }
    cout<<dp[0][n-1]<<endl;
    /*_End_*/
   
}

int main()
{
	cout<<fixed<<setprecision(12);
	//freopen("input.txt", "r", stdin);
	fastio;ll  t=1,tc=1;
	//cin>>t;
	while(t--){solve();}return 0;
}

Measured memory_bytes: 70016
# -*- coding: utf-8 -*-
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

rem=k
nxt=1
visit=[]
visit_set=set([])
for i in range(k):
    visit.append(nxt)
    visit_set.add(nxt)
    nxt=a[nxt-1]
    # この判定をやめる
    if nxt in visit_set:
        break
    rem-=1

if rem==0:
    print(nxt)
else:
#    print('-'*60)
#    print('nxt=', nxt)
#    print('rem=', rem)
#    print('visit=', visit)
    
    loops=visit[visit.index(nxt):]
    print(loops[(rem-1)%len(loops)])    
    
#    print('-'*60)
#    print('loops=', loops)


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

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

    int ans = 0;
    for(int i=0; i<n; i++){
        long long int x, y;
        cin >> x >> y;
        if(x * x + y * y <= d * d) ans += 1;
    }

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

Measured memory_bytes: 3588
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import stdin
N = int(input())
A = [int(i) for i in input().split()]
A_i = sorted([a - (i + 1) for i, a in enumerate(A)])

if N % 2 != 0:
    idx_of_median = int(N // 2)  # 奇数時のインデックス [0, 1, 2, 3, 4] -> 5//2 = 2
    print(sum([abs(a - A_i[idx_of_median])for a in A_i]))
else:
    idx_of_median = int(N / 2) # 奇数時のインデックス [0, 1, 2, 3, 4, 5] -> 6/2 = 3 or 6/2 - 1 = 2
    print(sum([abs(a - A_i[idx_of_median]) for a in A_i]))


Measured memory_bytes: 27588
import java.util.Arrays;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();

        long[] arr = new long[(int) n];

        for (int i = 0; i < n; i++) {
            arr[i] = i+1;
        }

        for (int i=0; i<arr.length; i++)
        {

             if (arr[i]%5==0)
                arr[i] = 0;

            else if (arr[i]%3==0)
                arr[i] = 0;

        }

        long sum = Arrays.stream(arr).sum();

        System.out.println(sum);


    }
}

Measured memory_bytes: 40104
object Main extends App {
  
  val sc = new java.util.Scanner(System.in) 
  val n = sc.nextInt()
  val s = sc.next().toArray
  val ans =  s.scanLeft(0)((x, y) => if (y == 'I') x + 1 else x - 1).max
  println(ans)    
}

Measured memory_bytes: 55564
#include <stdio.h>

int main(){
    long long int A, B, K;

    scanf("%lld%lld%lld", &A, &B, &K);

    if(A >= K){
        printf("%lld %lld\n", A - K, B);
    }else{
        K -= A;

        if(B > K){
            printf("0 %lld\n", B - K);
        }else{
            printf("0 0\n");
        }
    }
}

Measured memory_bytes: 128
/**
 *    author: apurba_debnath
**/
#include <bits/stdc++.h>


#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;


using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a == c || a != b && a != c && b != c) cout << "No";
    else cout << "Yes";

    return 0;
}


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


int main()
{
	int n ;  cin >> n;
	int a[n+1],g = 0;
	int i = 1;
	while(i<=n)
	{
		cin >> a[i] ;
		i ++ ;
	}
	
	
	
	int dp[n+1] = {0};
	dp[1] = a[1];
	dp[2] = abs(a[2] - a[1]);
	dp[3] = min(abs(a[3] - a[2])+dp[2],abs(a[3]-a[1]));

	i = 4;
	while(i<=n )
	{
		dp[i] = min(abs(a[i] - a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
		i++;
	}
	cout<< dp[n];
}


Measured memory_bytes: 1024
n = int(input())
s = input()
r = 0
if n > 2:
    r = s.count('R') * s.count('G') * s.count('B')
    for i in range(n - 2):
        k = i + 2
        for j in range(i + 1, n - 1):
            k += 2 if j > i + 1 else 0
            if k >= n:
                break
            r -= 1 if s[i] != s[j] and s[i] != s[k] and s[j] != s[k] else 0
print(r)

Measured memory_bytes: 9204
import sys
input = sys.stdin.buffer.readline

def main():
    a,b,c,d = map(int,input().split())
    MOD = 10**9+7
    N = c+d+5
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1

    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(x,y):
        return (fac[x+y]*pow(fac[x],MOD-2,MOD)*pow(fac[y],MOD-2,MOD))%MOD

    print((comb(c+1,d+1)-comb(c+1,b)-comb(d+1,a)+comb(a,b))%MOD)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 82200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();
            if(max < p) {
                max = p;
            }
            ans += p;
        }
        ans = ans - max + max / 2;
        System.out.println(ans);
    }
}

Measured memory_bytes: 35628
#include<iostream>
using namespace std;
 
int judge(int a, int b, int x) {
	if ((x < a) || (a + b) < x)	return 0;
	else if (a <= x && x <= (a + b))	return 1;
 
}
 
int main() {
	int A, B, X;
	cin >> A >> B >> X;
 
	int ans = judge(A, B, X);
	if (ans == 0)	cout << "NO";
	else cout << "YES";
 
	return 0;
}

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

using namespace std;

typedef long long LL;

const int MAX_N = 1e5 + 10;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N, cnt[MAX_N] = {};
	LL ans = 0, A[MAX_N];
	vector<LL> vec;
	
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	
	sort(A, A + N);
	cnt[0] = 1;
	for (int i = 1; i < N; i++)
	{
		cnt[i] = A[i] == A[i - 1] ? cnt[i - 1] + 1 : 1;
		
		if (cnt[i] == 2) vec.emplace_back(A[i]);
		else if (cnt[i] == 4) ans = max(ans, A[i] * A[i]);
	}//for i
	
	for (int i = 0; i < (int)vec.size() - 1; i++)
		ans = max(ans, vec[i] * vec[i + 1]);
		
	cout << ans << '\n';
	
	return 0;
}//main

Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define of(i,a,b) for(register int (i)=(a);(i)>=(b);--(i))
#define rd read()
#define maxn 500001
#define ll long long
#define fre(a) freopen("a.in","r",stdin);freopen("a.out","w",stdout);
const int p=998244353;
int read() {int x=0,f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*f;}
void print(int x) { if(x<0){putchar('-');x=-x;}if(x>9)print(x/10);putchar(x%10+'0');}
int qp(int a, int  b) {int ans = 1;for(; b; b >>= 1, a *= a, a %= p) if(b & 1) ans *= a, ans %= p;return ans % p;}
int ans;
int main() {
    int n=rd,k=rd;
    fo(i,1,n)
    {
    	int m=rd;
    	ans+=2*min(m,k-m);
	}
	print(ans),puts(" ");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
  
  int s=sc.nextInt(), w=sc.nextInt();
  if(s<=w){
  System.out.println("unsafe");
    
  }else{
  System.out.println("safe");
  }
}
  
}

Measured memory_bytes: 35816
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	string s, ans;
	cin >> s;
	ans = s;
	ans[5] = ' ';
	ans[13] = ' ';
	cout << ans << endl;
	return 0;
}
//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int n, m, i, j;
  char a[110][110], c;
  cin >> n >> m;
  for(i = 0; i < n+2; i++)
    for(j = 0; j < m+2; j++)
      a[i][j] = '#';
  for(i = 1; i <= n; i++){
    for(j = 1; j <= m; j++){
      cin >> c;
      a[i][j] = c;
    }
  }
  
  for(i = 0; i < n+2; i++){
    for(j = 0; j < m+2; j++){
      cout << a[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;
use proconio::marker::{Bytes, Chars};

fn main() {
    input! {
        n: i64,
    }

    let mut sum = 0;
    for i in 1..=n {
        if i % 3 != 0 && i % 5 !=0 && i % 15 != 0{
            sum = sum + i
        }
    }
    
    println!("{}",sum)
    // let mut yes = false;
    // for s in  n {
    //     if s == '7' {
    //         yes = true;
    //     }
    // }
    // if yes {
    //     println!("Yes" )
    // }else{
    //     println!("No")
    // }


}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1));
    auto pr = dp;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
                pr[i][j] = 3;
            } else if (dp[i - 1][j] > dp[i][j - 1]) {
                dp[i][j] = dp[i - 1][j];
                pr[i][j] = 1;
            } else {
                dp[i][j] = dp[i][j - 1];
                pr[i][j] = 2;
            }
    string ans;
    for (int i = n, j = m; i && j; ) {
        int p = pr[i][j];
        if (p == 3)
            ans += s[i - 1];
        i -= p & 1;
        j -= p >> 1 & 1;
    }
    reverse(begin(ans), end(ans));
    cout << ans << endl;
}


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

constexpr int MAX_N = 1e2;
constexpr int MAX_W = 1e5;

long dp[MAX_N+1][MAX_W+1];
int w[MAX_N], v[MAX_N];

int main() {
  int N, W;
  cin >> N >> W;
  for (int i{}; i < N; ++i) {
    cin >> w[i] >> v[i];
  }

  for (int i{}; i < N; ++i) {
    for (int j{}; j <= W; ++j) {
      if (j >= w[i]) {
        dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
      } else {
        dp[i+1][j] = dp[i][j];
      }
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n ; cin>> n;
    int start ; cin>> start ;
    vector<int> arr(n);
    for(int&p:arr) cin >> p;
    int ans = 0 ;
    for(int i = 0 ; i < n ; i++)
    {
        int first = abs(0-arr[i]) , second = abs(start - arr[i]);
        int mini = min (first , second);
        ans += (mini)*2;
    }
    cout << ans ;
    return 0 ;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define MAX 10000

struct Node{
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;
    if(y == NIL){
        root = z;
    }else{
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL) return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,x;
    string com;
    
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }else if(com == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }

    return 0;
}




Measured memory_bytes: 26604
#include<bits/stdc++.h>
using namespace std;
using Long = long long;
template<typename W>
struct Edge { 
    int to,rev;
    W cap;
    Edge(int to, int rev, W cap) : to(to), rev(rev), cap(cap) {}
};

template<typename W>
using Graph = vector<vector<Edge<W>>>;

template<typename W>
struct NetWork {
    Graph<W> G;
    NetWork(int V) : G(V) { }
    void add_edge(int from, int to, W cap) {
        G[from].emplace_back(to, (int)G[to].size(), cap);
        G[to].emplace_back(from, (int)G[from].size()-1, 0);
    }
};

template<typename W>
void bfs(int s, Graph<W> &g, vector<int> &level) {
    fill(level.begin(),level.end(), -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()) {
        int v=que.front();que.pop();
        for(auto &e : g[v]) {
            if( e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

template<typename W>
W dfs(int v,int t,W f, Graph<W> &g, vector<int> &iter, vector<int> &level) {
    if(v==t) return f;
    for(int &i = iter[v] ; i < g[v].size();i++ ) {
        Edge<W> &e = g[v][i];
        if( e.cap > 0 && level[v]<level[e.to] ) {
            int d = dfs(e.to, t , min(f , e.cap), g, iter, level);
            if( d > 0 ) {
                e.cap-=d;
                g[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// Dinic法
template<typename W>
W max_flow(NetWork<W> &network, int s, int t) {
    W flow = 0;
    Graph<W> &g = network.G;
    // level[i] : 頂点sから頂点iまでの最短距離
    vector<int> level(network.G.size(), -1);
    vector<int> iter(network.G.size(), 0);
    
    for( ; ; ) {
        bfs(s, g, level);
        // フローを流せるエッジが存在しない.
        if( level[t] < 0 ) return flow;
        fill(iter.begin(),iter.end(),0);
        int f;
        while( (f=dfs(s , t, numeric_limits<W>::max(), g, iter, level)) > 0){
            flow += f;
        }
    }
    return flow;
}

int main() {
    int V, E;
    cin >> V >> E;
    NetWork<int> network(V);
    for (int i = 0;i < E; i++) {
        int u,v,c;
        cin >> u >> v >> c;
        network.add_edge(u, v, c);
    }
    cout << max_flow(network, 0, V-1) << endl;
}


Measured memory_bytes: 3128
n = int(input())
a = list(map(int,input().split()))
for i in range(1,n // 2 + 1):
    an = a[n //2 - i]
    if (sum(a[n // 2 - i::n // 2 + 1 - i]) - an) % 2 == an:
        a[n // 2 - i] = 0
    else:
        a[n // 2 - i] = 1
b = []
cnt = 0
for i in range(len(a)):
    if a[i] == 1:
        b.append(str(i + 1))
        cnt += 1
if cnt != 0:
    print(cnt)
    print(' '.join(b))
else:
    print(0)

Measured memory_bytes: 16180
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S[i];
  }
  int a=0;
  for(int i=0;i<N;i++){
    if(S[i] == "Y"){
      a++;
    }
  }
  string ans;
  if(a>=1){
    ans="Four";
  }
  else{
    ans="Three";
  }
  cout << ans << endl;
}

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

typedef long long ll;
using namespace std;

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define _repi(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++)
#define REP(...) _overload(__VA_ARGS__, _repi, _rep,)(__VA_ARGS__)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	ll n;	cin >> n;
	ll x[n], y[n];
	REP(i, n){
		cin >> x[i] >> y[i];
	}
	int route[] = {0, 1, 2, 3, 4, 5, 6, 7};
	double ave = 0;
	ll cnt = 0;

	do{
		REP(i, n-1){
			ave += sqrt(pow(x[route[i]]-x[route[i+1]], 2) + pow(y[route[i]]-y[route[i+1]], 2));
		}
		cnt++;
	}while( next_permutation(route, route+n) );

	printf("%.10lf", ave / cnt);

	return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<vc> vcc;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}

int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
{
    ll i, j, n, m;
    cin >> n;
    vi a(n);
    ll sum = 0;
    fo(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    ll avg = 0;
    ll avg1 = 0;
    ll avg2 = 0;
    avg = sum / n;
    avg1 = avg + 1;
    avg2 = avg - 1;

    ll ans = 0, ans1 = 0, ans2 = 0;
    fo(i, n)
    {
        ll dif = a[i] - avg;
        ll dif1 = a[i] - avg1;
        ll dif2 = a[i] - avg2;
        ans += dif * dif;
        ans1 += dif1 * dif1;
        ans2 += dif2 * dif2;
    }
    cout << min({ans, ans1, ans2}) << endl;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m)
{
    int i, u, v;
    while (m--)
    {
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (v == par)
            continue;
        dfs(v, u);
    }
}


Measured memory_bytes: 10592
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;
typedef long long ll;
const int MODULO = 1000000007;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define SZ(c) ((int)(c).size())

int n,m;
bool use[100][100];
char s[100][101];
int dx[] =  {0,0,1,-1};
int dy[] =  {1,-1,0,0};

void dfs(int x,int y){
	use[y][x] = true;
	FOR(i,4){
		int nx = x + dx[i],ny = y + dy[i];
		if(0 <= nx && nx < m && 0 <= ny && ny < n && (!use[ny][nx]) && s[y][x] == s[ny][nx]){
			dfs(nx,ny);
		}
	}
}

int main(){
	while(cin>>n>>m,(n||m)){
		FOR(i,n) cin>>s[i];
		memset(use,0,sizeof(use));
		int ans = 0;
		FOR(i,n)FOR(j,m){
			if(!use[i][j]){
				ans++;
				dfs(j,i);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

int n, ans = 1, say[26];
char ch;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf(" %c",&ch);
		say[ch - 'a']++;
	}
	for(int i = 0; i < 26; i++)
		ans = 1ll*ans*(say[i] + 1)%mod;
	printf("%lld\n", (1ll*ans + mod - 1ll)%mod );
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int x1,x2,y1,y2,z1,z2,w1,w2,x,y,z,w;
    int i,n;

    while(scanf("%d",&n),n){
        for(i=0;i<n;i++){
            scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&z1,&w1,&x2,&y2,&z2,&w2);
            x=x1*x2-y1*y2-z1*z2-w1*w2;
            y=x1*y2+x2*y1+z1*w2-z2*w1;
            z=x1*z2+x2*z1+w1*y2-w2*y1;
            w=x1*w2+x2*w1+y1*z2-y2*z1;
            printf("%d %d %d %d\n",x,y,z,w);
        }   
    }   
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}

int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string N;
	//ll ans = 10000000000000000000ll;
	cin >> N;
	string abc = "ABC";
	string ans = abc + N;
	
	ll sum = 0;
	

	



cout << ans << endl;
	
	
	return 0;

	


}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using ll = long long;
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a <=8 && b <= 8) {
		cout << "Yay!";
	}
	else {
		cout << ":(";
	}
}







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


int main(void) {
  int a;
  cin >> a;

  cout << (a + (a * a) + (a * a * a)) << endl;
  
  return 0;
}

Measured memory_bytes: 3628
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #ifdef ONLINE_JUDGE
        #pragma GCC target ("avx512f")
    #else
        #pragma GCC target ("avx")
    #endif
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

string s;
deque<char> dc;
bool revflag = false;
int q,t,f;
char c;

signed main(){
    cin >> s;
    for(auto cs: s) dc.pb(cs);
    cin >> q;
    REP(i,q){
        cin >> t;
        if (t == 1){
            revflag ^= 1;
        } else {
            cin >> f >> c;
            if ((f == 1) ^ revflag){
                dc.push_front(c);
            } else {
                dc.push_back(c);
            }
        }
    }
    if (revflag){
        for(auto it = dc.rbegin(); it != dc.rend(); it++)
            cout << *it;
    } else {
        for(auto it = dc.begin(); it != dc.end(); it++)
            cout << *it;
    }
    cout << endl;
}

Measured memory_bytes: 896
k,a,b=map(int,input().split())
bis=1

if(k<=a-1):
    print(k+1)
elif(b<a+2):
    print(k+1)
else:
    bis+=a-1

    rest=k-(a-1)
#    print(bis,rest)

    exc=rest//2

    bis=(exc*b - (exc-1)*a)

    if(rest%2==1):
        bis+=1

    print(bis)




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


struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};



int main(){
    ll n, m;
    cin >> n >> m;
    vector<int> A(m), B(m);
    for(int i=0; i<m; i++){
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }

    vector<ll> ans;
    UnionFind uf(n);
    ll res = n * (n-1) / 2;

    for(int i=0; i<m; i++){
        ans.push_back(res);
        int x = A[m-i-1];
        int y = B[m-i-1];
        if(uf.issame(x, y)) continue;

        ll sx = uf.size(x), sy = uf.size(y);
        res -= (sx * sy);
        uf.merge(x, y);
    }
    reverse(ans.begin(), ans.end());
    for(int i=0; i<ans.size(); i++) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
    int g[]={114514,0,2,0,1,0,1,0,0,1,0,1,0};
    int a,b;
    cin>>a>>b;
    if(g[a]==g[b])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

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

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


#line 2 "tmp.cpp"

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

  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  } else {
    cout << "Yes" << endl;
  }

  vi ans(2 * n - 1, 0), used(2 * n);
  used[0] = true;
  ans[n - 1] = x;
  used[x] = true;
  ans[n - 2] = 1;
  used[1] = true;
  ans[n] = 2 * n - 1;
  used[2 * n - 1] = true;
  if (n > 2) {
    REP(i, 2 * n - 1) {
      if (used[i])
        continue;
      if (i < x)
        ans[n + 1] = i;
      else
        ans[n - 3] = i;
      used[i] = true;
      break;
    }

    int idx = 0;
    REP(i, 2 * n - 1) {
      if (used[i])
        continue;
      while (ans[idx] != 0)
        idx++;
      ans[idx] = i;
    }
  }

  REP(i, 2 * n - 1) { cout << ans[i] << endl; }
  return 0;
}


Measured memory_bytes: 3072
ps = []
l = 0.25
for p in map(int,input().split()):
  ps.append([p/l, l, p])
  l *= 2
ps.sort()

n = int(input())
ans = 0
for unitp, l, p in ps:
  num = int(n//l)
  ans += num*p
  n -= int(num*l)
  
print(ans)


Measured memory_bytes: 38384
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        d: usize, g: usize,
        mut pc: [(usize, usize); d]
    }
    pc.insert(0, (0, 0));

    let mut dp = vec![vec![0; 1001]; d+1];
    for i in 1..=d {
        let (p, c) = pc[i];
        for j in 0..=(i-1)*100 {
            for k in 0..=p {
                dp[i][j+k] = max(dp[i][j+k], dp[i-1][j] + k*i*100);
                if k == p {
                    dp[i][j+k] = max(dp[i][j+k], dp[i-1][j] + k*i*100 + c);
                }
            }
        }
    }
    let ans = dp[d].iter().find_position(|v| **v >= g).unwrap().0;
    println!("{}", ans);
}


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

typedef long long ll;

const int INF = 1e9;
const ll LINF = 1e18;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<int>> dp(n + 10, vector<int>(n + 10, 0));
    int ans = 0;
    for(int i = n - 1; i >= 1; i--){//右
        for(int j = i - 1; j >= 0; j--){//左
            dp[j][i] = (s[i] == s[j] ? min(i - j, dp[j + 1][i + 1] + 1) : 0);
            ans = max(ans, dp[j][i]);
        }
    }
    cout << ans << endl;
    cin >> n;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    set<int> s;
    for(int i=0; i<n; i++){
        cin>>v[i];
        s.insert(v[i]);
    }
    bool flag=true;
    int sz = s.size();
    if(sz == n){
        cout<<"YES\n";
    }
    else{
        cout<<"NO\n";
    }
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,R,ans;
struct node { int x,y; } d[maxn];
bool cmp(node a,node b) {
	if (a.y!=b.y) return a.y<b.y;
	return a.x<b.x;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); int x,y;
	for (int i=1;i<=n;i++) {
		read(x); read(y);
		d[i]=(node){x-y,x+y};
	}
	sort(d+1,d+n+1,cmp);
	for (int i=1;i<=n;i++) {
		if (!ans||R<=d[i].x) ans++,R=d[i].y;
	}
	printf("%d\n",ans);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    auto b = a;
    sort(b.rbegin(), b.rend());
    int mx = b[0];
    int secmx = b[1];
    for (int i = 0; i < n; i++)
    {
        if (mx == a[i])
        {
            cout << secmx << endl;
        }
        else
        {
            cout << mx << endl;
        }
    }
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	int n, k;

	std::cin >> n >> k;

	std::map<int, int> m;

	for (size_t i = 0; i < n; i++)
	{
		int a; 

		std::cin >> a;
		m[a]++;
	}

	std::vector<int> v;

	for (auto it = m.begin(); it != m.end(); it++)
	{
		v.push_back(it->second);
	}

	std::sort(v.begin(), v.end());

	int ans = 0, i = 0;

	while (v.size() - i > k) {
		ans += v[i];
		i++;
	}

	std::cout << ans << std::endl;

	return 0;

}


Measured memory_bytes: 10748
#include <stdio.h>

int main(void)
{
	size_t i=0,j=0;
	size_t h=0;
	int tmp=0;
	char height[50];
	int mt_height[10] = {0};
	int num=0;

	while(i < 10){
		fgets(height,sizeof(height),stdin);
		sscanf(height,"%d",&mt_height[i]);
		if(mt_height[i] >= 0 && mt_height[i] <= 10000)
			i++;
	}
	
	h = 1;
	for(i = h; i < 10; i++){
		tmp = mt_height[i];
		for(j = i; j >= h && mt_height[j-h] < tmp; j -= h){
			mt_height[j] = mt_height[j-h];
		}
		mt_height[j] = tmp;
	}
	for(i = 0; i < 3; i++){
		printf("%d\n",mt_height[i]);
	}

	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REP(j,n) for(int j = 0; j < n; j++)

using namespace std;
typedef pair<int, int> P;
struct team {
    string name;
    int win;
    int lose;
    int number;
    team(string n, int numb) {
        name = n;
        win = 0;
        lose = 0;
        number = numb;
    }
    bool operator<( const team& right ) const {
        if(win > right.win) return 0;
        if(win < right.win) return 1;
        if(lose < right.lose) return 0;
        if(lose > right.lose) return 1;
        if(number < right.number) return 0;
        if(number > right.number) return 1;
        return 0;
    }
};
int main() {
    while(1) {
        int n;
        cin >> n;
        if(n == 0) break;
        vector<team> list;
        REP(i,n) {
            string name;
            cin >> name;
            team ck = team(name,i);
            REP(j,n-1) {
                int tmp;
                cin >> tmp;
                
                if(tmp == 0) {
                    ck.win++;
                }
                else if(tmp == 1) {
                    ck.lose++;
                }
            }
            list.push_back(ck);
        }
        sort(list.begin(),list.end());
        
        REP(i,n) {
            team ck = list.back();
            list.pop_back();
            cout << ck.name << endl;
        }
        
        
        
        
        
    }
}

Measured memory_bytes: 1208
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  int ans = 0;
  for(int i=K;i<N;++i) {
    if(A[i]>A[i-K]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}



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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


int main() {
	

	map<ll,ll> m;

	int n;
	cin >> n;

	VLL v(n);
	REP(i, n)cin >> v[i];

	VLL a(n,0);
	a[0] = v[0];
	m[a[0]]++;
	m[0]++;
	ll ans = 0;
	if (a[0] == 0)ans++;
	FOR(i, 1, n) {
		a[i] = a[i - 1] + v[i];
		ans += m[a[i]];
		m[a[i]]++;
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 15872
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
typedef pair<int, int> P;

const int MAX_N = 500, MAX_M = 2e5, MAX_Q = 1e5, ST_SIZE = (1 << 19) - 1;
int n, m, q;

P p[MAX_M];
int ans[MAX_N][MAX_N];

void count() {
    for (int i = n - 1; i >= 0; i--) {
        pair<int, int>* b = lower_bound(p, p + m, P(i, 0));
        pair<int, int>* e = upper_bound(p, p + m, P(i, n - 1));
        ans[i][i] = upper_bound(b, e, P(i, i)) - b;
        for (int j = i + 1; j < n; j++) {
            ans[i][j] = ans[i + 1][j] + upper_bound(b, e, P(i, j)) - b;
        }
    }
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        p[i] = P(a - 1, b - 1);
    }
    
    sort(p, p + m);
    count();
    
    for (int i = 0; i < q; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        printf("%d\n", ans[a - 1][b - 1]);
    }

    return 0;
}


Measured memory_bytes: 3456