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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,k,a[200010],val;
vector <LL> v,vv;
bool vis[200010];

int main()
{
	cin>>n>>k;
	k++;
	repn(i,n) cin>>a[i];
	v.pb(1);
	vis[1]=1;
	int pos=1;
	while(true)
	{
		pos=a[pos];
		if(vis[pos])
		{
			val=pos;
			break;
		}
		vis[pos]=true;
		v.pb(pos);
	}
	rep(i,v.size())
	{
		if(v[i]==val)
		{
			pos=i;
			for(int j=i;j<v.size();j++) vv.pb(v[j]);
			break;
		}
	}
	if(k-1<=pos) cout<<v[k-1]<<endl;
	else cout<<vv[((k-pos)%vv.size()-1+vv.size())%vv.size()]<<endl;
	return 0;
}

Measured memory_bytes: 9412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

ll a,b,c,k;

int main(){
    ll ans;
    cin>>a>>b>>c>>k;
    if(k<=a)ans=k;
    else if(k<=a+b)ans=a;
    else {
        ans=a-(k-(a+b));
    }

    cout<<ans;

    return 0;

}


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

int main()
{
    int H, N;
    cin >> H >> N;
    int sum = 0;
    int A;
    for(int i = 0; i < N; i++) {
        cin >> A;
        sum += A;
    }
    if(sum >= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf  114514
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int a,b;cin>>a>>b;
    int c=b-a;
    int sum=0;
    rep(i,0,c)sum+=i;
    cout<<sum-a<<endl;
    return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  vector<int> cnt(n,0);
  for(int i=0; i<n+m-1; ++i){
    int a, b;
    cin >> a >> b;
    --a; --b;
    v[a].push_back(b);
    ++cnt[b];
  }
  int root;
  for(int i=0; i<n; ++i) if(cnt[i] == 0) root = i;
  vector<int> ans(n,-2);
  ans[root] = -1;
  queue<int> que;
  que.push(root);
  while(!que.empty()){
    int x = que.front();
    que.pop();
    for(int a:v[x]){
      --cnt[a];
      if(cnt[a] == 0){
        ans[a] = x;
        que.push(a);
      }
    }
  }
  for(int i=0; i<n; ++i){
    printf("%d\n", ans[i]+1);
  }
}

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

using namespace std;

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i)
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i)

#define DEBUG(...) fprintf(stderr , __VA_ARGS__)

template<typename T>inline int chkmin(T &x , const T &y){ return x > y ? x = y , 1 : 0; }
template<typename T>inline int chkmax(T &x , const T &y){ return x < y ? x = y , 1 : 0; }

template<typename T>inline T read(T &f)
{
	f = 0 ; int x = 1 ; char c = getchar();
	while(!isdigit(c)) x = c == '-' ? -1 : 1 , c = getchar();
	while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
	return f *= x;
}

using int64 = long long;
using uint64 = unsigned long long;

const int N = 200000 + 5;

int n , f[N][2] ; char S[N];

int main()
{
	scanf("%s" , S + 1) , n = strlen(S + 1);
	f[1][0] = 1;
	if(S[2] == S[1])
	{
		f[2][1] = 1;
	}
	else
	{
		f[2][0] = 2 , f[2][1] = 1;
	}
	rep(i , 3 , n)
	{
		if(S[i] != S[i - 1])
		{
			chkmax(f[i][0] , f[i - 1][0] + 1);
			chkmax(f[i][0] , f[i - 1][1] + 1);
		}
		else
		{
			chkmax(f[i][0] , f[i - 1][1] + 1);
		}
		chkmax(f[i][1] , f[i - 2][0] + 1);
		if(S[i] != S[i - 3] && S[i - 1] != S[i - 2])
		{
			chkmax(f[i][1] , f[i - 2][1] + 1);
		}
	}
	cout << max(f[n][1] , f[n][0]) << endl;
	return 0;
}


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

int main(){
    int n;
    int k;
    int ans=0;
    cin >>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
        if(h[i]>=k) ans++;
    }
    cout << ans<<endl;
}

Measured memory_bytes: 640
def main():
    import sys
    a = input()
    ans =0
    for i in range(2**3):
        t = a[0]
        for j in range(3):
            if i & (1 <<j):
                t = t +'+'
            else:
                t = t +'-'
            t = t +a[j+1]
        ans =eval(t)
        if ans == 7:
            print(t+'=7')
            sys.exit()
if __name__ =='__main__':
    main()


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

namespace ITP1_2_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



Measured memory_bytes: 17928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

bool cmp(char *s, int a, char *t, int b, int n){
	REP(i, n){
		if(*s != *t) return false;
		s += a;
		t += b;
	}
	return true;
}

char s[64][32];
ll a[64];
int m[64];
vector<pair<int, ll>> g[64*64];
void ad(int i, int p, int j, int q, ll c){
	DEBUG("(%d, %d) =[%lld]=> (%d, %d)\n", i, p, c, j, q);
	if(p<0) p += 64;
	if(q<0) q += 64;
	g[i*64+p].EB(j*64+q, c);
}

pque<pair<ll, int>> que;
bool u[64*64] = {};
void ini(int i, int p, int q){
	int r = p == 0 ? -q : p;
	DEBUG("Start from (%d, %d) (%d, %d): %lld\n", i, r, p, q, a[i]);
	if(r<0) r += 64;
	que.emplace(a[i], i*64+r);
}

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%s%lld", s[i], a+i);
	REP(i, n) m[i] = strlen(s[i]);
	REP(i, n){
		FOR(k, 1, m[i] + 1){
			REP(j, n){
				if(cmp(s[i]+k-1, -1, s[j], +1, min(k, m[j]))){
					DEBUG("  %d %d %d\n", i, k, j);
					if(k == m[j]) ad(i, k, 0, 0, a[j]);
					if(k < m[j]) ad(i, k, j, -(m[j]-k), a[j]);
					if(k > m[j]) ad(i, k, i, k-m[j], a[j]);
				}
				if(cmp(s[i]+m[i]-k, +1, s[j]+m[j]-1, -1, min(k, m[j]))){
					DEBUG("  %d -%d %d\n", i, k, j);
					if(k == m[j]) ad(i, -k, 0, 0, a[j]);
					if(k < m[j]) ad(i, -k, j, m[j] - k, a[j]);
					if(k > m[j]) ad(i, -k, i, -(k-m[j]), a[j]);
				}
			}
		}
		REP(k, m[i]){
			int t = min(k+1, m[i]-k);
			if(cmp(s[i]+k, -1, s[i]+k, +1, t)){
				int p = k - (t-1), q = k + (t-1);
				// DEBUG("  k = %d, p = %d, q = %d\n", k, p, q);
				ini(i, p, m[i]-q-1);
			}
		}
		FOR(k, -1, m[i]){
			int t = min(k+1, m[i]-k-1);
			DEBUG("    %d %d\n", k, t);
			if(cmp(s[i]+k, -1, s[i]+k+1, +1, t)){
				int p = k - (t-1), q = k+1 + (t-1);
				DEBUG("  k = %d %d, p = %d, q = %d\n", k, k+1, p, q);
				ini(i, p, m[i]-q-1);
			}
		}
	}
	while(que.size()){
		auto [c, i] = que.top(); que.pop();
		// DEBUG("(%d, %d): %lld\n", i/64, i%64, c);
		if(i%64 == 0){
			printf("%lld\n", c);
			return 0;
		}
		if(u[i]) continue;
		u[i] = true;
		for(auto [j, d] : g[i]) que.emplace(c+d, j);
	}
	printf("-1\n");
}




Measured memory_bytes: 3896
#include<stdio.h>

int main(){
    int a, b, sum;
    int i;

    while(scanf("%d %d", &a, &b) != EOF){
        sum = a + b;
        for(i = 1; sum >= 10; i++){
            sum /= 10;
        }
        printf("%d\n", i);
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int main(){
  long long int n, m;
  cin >> n >> m;
  vector<int> d(n, 0);
  vector<vector<int>> E(n);
  for(int i=0;i<m;i++){
    int a, b;
    cin >> a >> b;
    a--;b--;
    E[a].emplace_back(b);
    E[b].emplace_back(a);
  }
  vector<bool> visited(n, false);
  function<void(int)> dfs = [&](int cur){
    visited[cur] = true;
    for(auto&& to:E[cur]){
       if (!visited[to]){
         d[to] = d[cur] + 1;
         dfs(to);
       }
    }
  };
  dfs(0);
  bool is_digraph = true;
  for(int i=0;i<n;i++){
    for(auto&& t:E[i]){
      if(!((d[i]^d[t])&1)){
        is_digraph = false; 
      }
    }
  }
  // cerr << is_digraph << endl;
  // for(auto&& r:d)cerr << r << " ";
  // cerr << endl;
  if(is_digraph){
    long long int even = 0;
    for(auto&& r:d)even += (r % 2 == 0);
    cout << even * (n - even) - m << endl;
  }else{
    cout << n * (n - 1) / 2 - m << endl; 
  }
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, M;
  map <int, int> D;
  cin >> N;
  for (int i = 0; i < N; i++){
    int d;
    cin >> d;
    D[d]++;
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    int t;
    cin >> t;
    if (D[t]) --D[t];
    else {
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long[] names = new long[5];
		for (int i = 0; i < n; i++) {
			int index = nameIndex(sc.next());
			if (index != -1)
				names[index]++;
		}

		long count = 0;
		for (int i = 0; i < names.length; i++) {
			for (int j = i + 1; j < names.length; j++) {
				for (int k = j + 1; k < names.length; k++) {
					count += names[i] * names[j] * names[k];
				}
			}
		}
		System.out.println(count);
	}

	static int nameIndex(String str) {
		switch (str.charAt(0)) {
		case 'M':
			return 0;
		case 'A':
			return 1;
		case 'R':
			return 2;
		case 'C':
			return 3;
		case 'H':
			return 4;
		default:
			return -1;
		}
	}
}

Measured memory_bytes: 48680
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
signed main(){
  int n;
  while(cin>>n,n){
    int x[n],y[n];
    for(int i=0;i<n;i++) cin>>x[i]>>y[i];
    set<P> s;
    for(int i=0;i<n;i++) s.insert(P(x[i],y[i]));
    int ans=0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	int dx=x[i]-x[j],dy=y[i]-y[j];
	int kx=dy,ky=-dx;
	if(s.count(P(x[i]+kx,y[i]+ky))&&
	   s.count(P(x[j]+kx,y[j]+ky))){
	  ans=max(ans,dx*dx+dy*dy);
	}
	kx=-dy,ky=dx;
	if(s.count(P(x[i]+kx,y[i]+ky))&&
	   s.count(P(x[j]+kx,y[j]+ky))){
	  ans=max(ans,dx*dx+dy*dy);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, mi = inf, cnt = 0,sum=0;
	cin >> n;
	rep(i, n) {
		int a;
		cin >> a;
		mi = min(mi, abs(a));
		if (a < 0) {
			cnt++;
		}
		sum += abs(a);
	}
	if (cnt % 2 == 0) {
		cout << sum << endl;
	}
	else {
		cout << sum - mi*2 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Competitive
{
    internal class LCS
    {
        public string A;
        public string B;
        public int NA;
        public int NB;

        public LCS(string A, string B)
        {
            this.A = A;
            this.B = B;
            NA = A.Length;
            NB = B.Length;
        }

        public int Solve()
        {
            int[,] dp = new int[NA + 1, NB + 1];

            for (int a = 0; a <= NA; a++)
            for (int b = 0; b <= NB; b++)
            {
                if (a == 0 || b == 0) dp[a, b] = 0;
                else
                {
                    char ca = A[a - 1];
                    char cb = B[b - 1];
                    if (ca == cb)
                    {
                        dp[a, b] = dp[a - 1, b - 1] + 1;
                    }
                    else
                    {
                        dp[a, b] = Math.Max(dp[a, b - 1], dp[a - 1, b]);
                    }
                }
            }

            return dp[NA, NB];
        }
    }

    internal class Solution
    {
        public int N;
        public string[] As;
        public string[] Bs;

        public void Run()
        {
            N = Input.ReadInt();
            As = new string[N];
            Bs = new string[N];
            for (int i = 0; i < N; i++)
            {
                As[i] = Console.ReadLine();
                Bs[i] = Console.ReadLine();
            }

            for (int i = 0; i < N; i++)
            {
                var runner = new LCS(As[i], Bs[i]);
                Console.WriteLine(runner.Solve());
            }
        }

    }

    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}


Measured memory_bytes: 13128
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

const int Maxn=1e5;

int N;
vector<int> G[Maxn+5];
void addedge(int u,int v) {
	G[u].push_back(v);
	G[v].push_back(u);
}

int DFS(int u,int fa) {
	int p=0;
	for(int i=0;i<(int)G[u].size();i++) {
		int v=G[u][i];
		if(v==fa)continue;
		p+=DFS(v,u);
	}
	if(p>=2)return p;
	else return p^1;
}

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d",&N);
	for(int i=1;i<N;i++) {
		int u,v;
		scanf("%d %d",&u,&v);
		addedge(u,v);
	}
	puts(DFS(1,-1)==0?"Second":"First");
	return 0;
}

Measured memory_bytes: 5760
n=int(input())

ll=[]
rr=[]

for _ in range(n):
    a,b=map(int,input().split())
    ll.append(a)
    rr.append(b)

ll.sort()
rr.sort()

if n%2==0:
    print((rr[n//2-1]+rr[n//2])-(ll[n//2]+ll[n//2-1])+1)
else:
    print(rr[n//2]-ll[n//2]+1)




Measured memory_bytes: 99040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(int &a,int b){
	a = min(a,b);
}
void chmax(ll &a,ll b){
	a = max(a,b);
}

// bool s(pair<int,int> a, pair<int,int> b){
// 	double k1 = a.first/a.second;
// 	double k2 = b.first/b.second;
// 	return k1 > k2;
// }

// int ret = INT_MAX;

// void go(int h,vector<pair<int , int>>& a,int sum){
// 	if(h <=0){
// 		self_min(ret,sum);
// 		return;
// 	}else{
// 		rep(i,a.size()){
// 			if(h>0){
// 				go(h-a[i].first,a,sum+ a[i].second);
// 			}
// 		}
// 	}
// }

const int INF = 1001001001;

int main(){
	int h,n; cin>> h >> n;
	vector<int> dp(h+1,INF);
	dp[0] = 0;

	rep(i,n){
		int a,b;
		cin >> a >> b;
		rep(j,h){
			int jh = min(j+a,h);
			dp[jh] = min(dp[jh], dp[j] + b);
		}
	}

	cout << dp[h] << endl;

	return 0;
}

Measured memory_bytes: 256
S = input()
n = len(S)
A = [S[0]]
B = [S[0:2]]
i = 0
j = 0
while i< n-1:
  if A[j] != S[i+1]:
    A.append(S[i+1])
    i += 1
    j+=1
  else:
    A.append(S[i+1:i+3])
    i += 2
    j += 1
i = 1
j = 0
while i< n-1:
  if B[j] != S[i+1]:
    B.append(S[i+1])
    i += 1
    j+=1
  else:
    B.append(S[i+1:i+3])
    i += 2
    j += 1
if A[-1] ==A[-2]:
  del A[-1]
if B[-1] == B[-2]:
  del B[-1]

print(max(len(A), len(B)))

Measured memory_bytes: 12828
let N = Int(readLine()!)!
var ans = 0
var aCount = 0
var bCount = 0
var abCount = 0
for _ in 0..<N {
  var str = readLine()!.characters.map{String($0)}
  var len = str.count
  let hasA = str[len-1] == "A"
  let hasB = str[0] == "B"
  if hasA && hasB {
    abCount += 1
  } else {
    if hasA {
      aCount += 1
    }
    if hasB {
      bCount += 1
    }
  }
  for i in 1..<len {
    if str[i-1] == "A" && str[i] == "B" {
      ans += 1
    }
  }
}
if abCount == 0 || aCount + bCount > 0 {
  ans += min(aCount, bCount) + abCount
} else {
  ans += abCount - 1
}
print(ans)

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

int main() {
  int n,k,x;
  cin >> n >> k;
  int sum=0;
  for(int i=0;i<n;i++){
    cin >> x;
    if(x<=k-x){
      sum += 2*x;
    }
    else{
      sum += 2*(k-x);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string S;

void solve() {
	cin >> S;
	N = sz(S);

	int s = 0;
	int res = 0;
	rep(i, 0, N) {
		if(S[i] == 'T') {
			if(s) s--;
			else res++;
		}
		else s++;
	}
	cout << res + s << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}




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


int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> g[3];
  for(int i=0;i<n;++i){
    for(int j=0;j<3;++j){
      ll x;
      cin >> x;
      g[j].push_back(x);
    }
  }

  ll cal=0;
  for(int bit=0;bit<(1<<3);++bit){
    vector<ll> kouho;
    for(int i=0;i<n;++i){
      ll tmp=0;
      for(int j=0;j<3;++j){
        if(bit &(1<<j)) tmp+=g[j][i];
        else tmp-=g[j][i];
      }
      kouho.push_back(tmp);
    }
    sort(kouho.rbegin(),kouho.rend());
    ll res=0;
    for(int i=0;i<m;++i){
      res+=kouho[i];
    }
    cal=max(cal,res);
  }

  cout << cal << endl;
  return 0;

}


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

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans =0;
    for(int r=0; r<=(N/R); r++){
        for(int g=0; g<=((N-r*R)/G); g++){
            int count = r*R + g*G;
            if((N-count)%B != 0){continue;}
            int b = (N-count)/B;
            if( b >= 0){
                ans += 1;
            }
        }
    }

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

Measured memory_bytes: 3632
from collections import deque

h, w = map(int, input().split())
INF = 10000000000
b = 0
maze = [[] for _ in range(h)]
for i in range(h):
  l = list(input())
  b += l.count("#")
  maze[i] = l

dist = [[INF for _ in range(w)] for _ in range(h)]
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

q = deque()
q.append((0,0))
dist[0][0] = 0

while q:
  x, y = q.popleft()
  if (x == w-1) and (y == h-1): break
  for i in range(len(dx)):
    nx = x + dx[i]
    ny = y + dy[i]
    if (nx >= 0) and (nx < w) and (ny >= 0) and (ny < h) and (maze[ny][nx] != "#") and (dist[ny][nx] == INF):
      q.append((nx, ny))
      dist[ny][nx] = dist[y][x] + 1
      
if dist[h-1][w-1] == INF:
  print(-1)
else:
  print((h*w) - (dist[h-1][w-1]+1) - b)

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;


/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};

const int N = 100100;
VI avail[N];

int main(void){
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  VI man(m, -1);
  REP(i, 0, n) {
    int ki;
    cin >> ki;
    REP(j, 0, ki) {
      int l;
      cin >> l;
      l--;
      avail[i].push_back(l);
      if (man[l] == -1) {
	man[l] = i;
      } else {
	uf.unite(man[l], i);
      }
    }
  }
  VI root(n, 0);
  int numroot = 0;
  REP(i, 0, n) {
    int r = uf.root(i);
    if (root[r] == 0) {
      numroot++;
      root[r] = 1;
    }
  }
  cout << (numroot >= 2 ? "NO" : "YES") << endl;
}


Measured memory_bytes: 7296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		string abcd = Console.ReadLine();
		var nums = new int[4];
		for(int i = 0; i < abcd.Length; i++)
			nums[i] = (int)(abcd[i]-'0');
		
		var n = abcd.Length - 1;
		
		for(int bit = 0; bit < (1 << n);  bit++)
		{
			long wa = nums[0];
			StringBuilder sb = new StringBuilder();;
			sb.Append(nums[0]);
			for(int i = 0; i < n; i++)
			{
				if(((bit>>i)&1)==0)
				{
					wa += nums[i+1];
					sb.Append('+');
				}
				else
				{
					wa -= nums[i+1];
					sb.Append('-');
				}
				sb.Append(nums[i+1]);
				
			}
			if(wa == 7)
			{
				sb.Append("=7");
				Console.WriteLine(sb);
				return;
			}
		}

	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

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;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vl v(n),ans1,ans2;
	rep(i,n)cin>>v[i];
	ll mx=0,mit=0;
	rep(i,n){
		if(chmax(mx,abs(v[i])))mit=i;
	}
	rep(i,n){
		if(i==mit)continue;
		ans1.push_back(mit);
		ans2.push_back(i);
	}
	if(v[mit]>0){
		rep(i,n-1){
			ans1.push_back(i);
			ans2.push_back(i+1);
		}
	}
	else{
		rrep(i,n-1){
			ans2.push_back(i);
			ans1.push_back(i+1);
		}
	}
	cout<<ans1.size()<<endl;
	rep(i,ans1.size()){
		cout<<ans1[i]+1<<" "<<ans2[i]+1<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lo;
lo arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
    lo q;
    cin >> q;
    cout << arr[q-1];    
}


//g++ code.cpp -o code.exe
// code.exe

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve(void)
{
  string str;cin>>str;
  int N = str.size();
  int ANS = N*(N-1)/2;
  map<char,int> mp;
  for (int i = 0; i < N; i++)
  {
    mp[str[i]]++; 
  }
  for (auto &&i : mp)
  {
    ANS -= i.second *(i.second-1)/2;
  }
  

  cout<<ANS +1<<endl;
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 720
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stack>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<cstring>
#include<sstream>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<time.h>
typedef long long ll;
using namespace std;


int main() {
	//freopen("run.in", "r", stdin);
	//freopen("run.out", "w", stdout);

	int n, q;
	cin >> n;
	int a[10050], b[505];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> b[i];
	}
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < n; j++) {
			if (b[i] == a[j]) {
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    vector<ll> Sa(n + 1), Sb(m + 1);
    Sa[0] = 0, Sb[0] = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        Sa[i + 1] = Sa[i] + a[i];
    }
    for(int i = 0; i < m; ++i){
        cin >> b[i];
        Sb[i + 1] = Sb[i] + b[i];
    }
    int ans = 0;
    for(int i = 0; i <= n; ++i){
        int p = upper_bound(Sb.begin(), Sb.end(), k - Sa[i]) - Sb.begin();
        if(p == 0)  continue;
        chmax(ans, i + p - 1);
        // cerr << k - Sa[i] << ' ';
        cerr << p << endl;
    }
    // for(int i = 0; i <= m; ++i){
    //     cerr << Sb[i] << ' ';
    // }
    // cerr << endl;
    cout << ans << endl;
}

Measured memory_bytes: 9536
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
 
diff = [V[i] - C[i] for i in range(N)]
diff.sort(reverse=True)
 
i, ans = 0,0
for d in diff:
    if d <= 0:
        break
    ans += d
print(ans)

Measured memory_bytes: 61968
#include <stdio.h>

int main(void) {
	int a[3], K;
	int b = 0;
	scanf("%d%d%d%d", &a[0], &a[1], &a[2], &K);

	for (int j = 0; j < 2; j++) {

	for (int i = 0; i < 2; i++) {
		if (a[i] < a[i + 1]) {
			b = a[i];
			a[i] = a[i + 1];
			a[i + 1] = b;
		}
	}



}

	for (int i = 1; i <= K; i++) {
		a[0] = a[0] * 2;
	}

	
 printf("%d", a[0] + a[1] + a[2]);


	return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}
int ara[100010];
int main()
{
    IOS;
    int n;cin>>n;
    ll sum=0;
    priority_queue<int,vector<int>,greater<int> >q;
    for(int i=0;i<n;i++)
    {
        int a;cin>>a;
        if(q.empty())
        {
            sum+=a;
            q.push(a);
        }
        else
        {
            int top=q.top();
            if(sum+a<sum-2*top-a)
            {
                sum=sum-2*top-a;
                q.pop();
                q.push(-a);
                q.push(-top);
            }
            else
            {
                sum+=a;
                q.push(a);
            }
        }
//        cout<<i<<" "<<i<<"  "<<sum<<endl;
    }
    cout<<sum<<endl;
}








Measured memory_bytes: 892
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main() {
	string s,t,m;
	cin >> s;
	int len = s.length();
	for (int i = 0;i < len;i++) t += s[len - i - 1];
	if (s == t) {
		for (int i = (len + 3) / 2-1;i < len;i++) m += s[i];
		t.clear();
		for (int i = 0;i < m.size();i++) t += m[m.size() - 1 - i];
		if (t == m) {
			m.clear();
			for (int i = 0;i <(len - 1) / 2;i++) m += s[i];
			t.clear();
			for (int i = 0;i < m.size();i++) t += m[m.size() - i - 1];
			if (t == m) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void swap(char * a,char * b){
 char *tmp;
 * tmp= *a;
  *a=*b;
  *b=*tmp;
}

int main(){
  string S;
  cin >>S;
  int p=0;
  vector <int>data;
  char l='L';
  char r='R';
  for (int i=0;i<S.size();i++){
   // if ()
  if (S.at(i)==r){
  p++;  
    if (i==S.size()-1){
      data.push_back(p);
    }
  }
 else if (S.at(i)==l){
  data.push_back(p);
    p=1;
    swap(r,l);
    if (i==S.size()-1){
      data.push_back(p);
    }
 }
  }
  int j=0;
  vector <int>data2;
  for (int c:data){
  j+=c;
    data2.push_back(j);
   }
 //  for (int i:data2){
// cout <<i<<" ";
  //}
vector <int>data1(S.size());
 
 // cout);
 // for (int i=0;i<S.size();i++){
//  cout <<data1.at(i)<<" ";
//  }
  for (int i=0;2*i+1<data.size();i++){
  if (data.at(2*i)%2==data.at(2*i+1)%2){
  data1.at(data2.at(2*i)-1)= (data.at(2*i)+data.at(2*i+1))/2;
  data1.at(data2.at(2*i))= (data.at(2*i)+data.at(2*i+1))/2;
  }
  if (data.at(2*i)%2==0&&data.at(2*i+1)%2==1){
   data1.at(data2.at(2*i)-1)= (data.at(2*i)+data.at(2*i+1))/2;
   data1.at(data2.at(2*i))= (data.at(2*i)+data.at(2*i+1))/2+1;
 }
   if (data.at(2*i)%2==1&&data.at(2*i+1)%2==0){
   data1.at(data2.at(2*i)-1)= (data.at(2*i)+data.at(2*i+1))/2+1;
   data1.at(data2.at(2*i))= (data.at(2*i)+data.at(2*i+1))/2;
 }
  }
  for (int i=0;i<S.size();i++){
 cout <<data1.at(i)<<" ";
 }
}

  

Measured memory_bytes: 1976
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

int mxN = 50000000;
vector<int> cnt(mxN + 1);

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<pair<int, int>> b(m);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        b[i] = make_pair(y, x);
    }
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    int j = 0;
    for (auto p : b) {
        int x = p.second, y = p.first;
        while (j < n && x--) {
            if (a[j] < y) a[j] = y;
            j++;
        }
    }
    long long sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    cout << sum;

    return 0;
}

Measured memory_bytes: 199672
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI as(n);
  FOR(a,as) {
    cin >> a;
  }
  int maxabs = -1;
  int argmax = -1;
  REP(i,0,n) {
    if(abs(as[i]) > maxabs) {
      maxabs = abs(as[i]);
      argmax = i;
    }
  }
  cout << n * 2 - 2 << endl;
  REP(i,0,n) {
    if(i != argmax) {
      cout << argmax + 1 << " " << i + 1 << endl;
    }
  }
  if(as[argmax] >= 0) {
    REP(i,1,n) {
      cout << i << " " << i + 1 << endl;
    }
  } else {
    for(int i=n; i>1; i--) {
      cout << i << " " << i - 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// cout << fixed << setprecision(10);
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
int dist[303][303],dist2[303][303];
void init(){
    for (int i = 0; i <= 300; i++){
        for (int j = 0; j <= 300; j++){
            dist[i][j] = MM;
            dist2[i][j] = MM;
        }
    }
}

void floyd(){
    for (int i = 0; i <= 300; i++){
        for (int j = 0; j <= 300; j++){
            for (int k = 0; k <= 300; k++){
                if (dist[i][j] == MM || dist[j][k] == MM) continue;
                dist[i][k] = min(dist[i][k], dist[i][j] + dist[j][k]);
            }
        }
    }
}
void floyd2(){
    for (int i = 0; i <= 300; i++){
        for (int j = 0; j <= 300; j++){
            for (int k = 0; k <= 300; k++){
                if (dist2[i][j] == MM || dist2[j][k] == MM) continue;
                dist2[i][k] = min(dist2[i][k], dist2[i][j] + dist[j][k]);
            }
        }
    }
}

int main(){
    int N; cin >> N;
    long long a;
    vector<long long> v;
    for (int i = 0; i < N; i++){
        cin >> a;
        a -= i+1;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    long long tmp;
    if (N % 2 == 1){
        tmp = v[N/2];
    } else {
        tmp = (v[N/2]+v[N/2-1])/2;
    }
    long long ans = 0;
    for (int i = 0; i < N; i++){
        ans += abs(v[i]-tmp);
    }
    cout << ans << endl;
} 

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		long x = scan.nextLong();
		long[]a = new long[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextLong();
		}
		scan.close();
		Arrays.sort(a);
		long sum = 0;
		if(a[0] > x) {
			System.out.println(0);
			System.exit(0);
		}
		for(int i = 0; i < N; i++) {
			sum += a[i];
			if(sum > x) {
				System.out.println(i);
				System.exit(0);
			}
		}
		if(sum == x) {
			System.out.println(N);
		}else {
			System.out.println(N - 1);
		}

	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;
long double ans[100001];
int main() {
	IOS;
	ll n,k;
	cin>>n>>k;
	ll arr[n+1];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	
	for(ll i=1;i<=k;i++){
		for(ll j=0;j<n;j++){
			if(arr[j]==i)
			{
				ans[i]=1;
				break;
			}
			else if(arr[j]<i){
				if(ans[i-arr[j]]==0){
					ans[i]=1;
					break;
				}
			}
		}
	}
	if(ans[k]==1)
	cout<<"First";
	else
	cout<<"Second";
	
	
	
}


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

int main() {
    int64_t K;
    string S, S_sht;
    cin >> K >> S;
    if (S.size() <= K) {
        cout << S << endl;
    } else {
        for(int64_t i = 0; i < K; i++) {
            S_sht += S[i];
        }
        cout << S_sht << "..." << endl;
    }
    return 0;
}

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

using namespace std;

int N, res;
vector < int > a(100005), ff(100005);

int main() {
    cin >> N;
    
    for (int i = 1; i <= N; ++i) {
        cin >> a[i];
        ++ff[a[i]];
    }
    
    for (int i = 0; i <= 100000; ++i) {
        res = max(res, ff[i] + ff[i + 1] + ff[i + 2]);
    }
    cout << res << '\n';
    
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

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

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF= 1e20;

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();

int main() {
	string s;
	cin >> s;
	SORT(s);
	if (s=="abc")coutY();
	else coutN();
	return 0;
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}

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

using namespace std;

typedef long long int ll;

ll a[2001][2001];
bool vis[2001];

void DFS(vector<ll> adj[] , ll vertex , ll s , ll dis)
{
    vis[s] = 1;
    a[vertex][s] = min(dis,a[vertex][s]);
    for(int i=0 ; i<adj[s].size();  i++)
    {
        if(!vis[adj[s][i]])
        {
            DFS(adj,vertex,adj[s][i],dis+1);
        }
    }
}

void BFS(vector<ll> adj[] , ll vertex , ll s , ll dis)
{
    queue<ll> Q;
    Q.push(s);
    a[vertex][s] = dis;

    while(!Q.empty())
    {
        ll u = Q.front();
        Q.pop();

        vis[u]=1;
        for(int i=0 ; i<adj[u].size() ; i++)
        {
            if(!vis[adj[u][i]])
            {
                Q.push(adj[u][i]);
                a[vertex][adj[u][i]] = min(1 + a[vertex][u],a[vertex][adj[u][i]]);
                //cout << u << " " << adj[u][i] << " " << a[vertex][u] << " " << a[vertex][adj[u][i]] << endl;
            }
            else
                a[vertex][adj[u][i]] = min(1 + a[vertex][u],a[vertex][adj[u][i]]);

        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,x,y;
    cin >> n >> x >> y;

    vector<ll> adj[n+1];
    for(int i=2; i<=n ; i++)
    {
        adj[i].push_back(i-1);
        adj[i-1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);

    for(int i=1 ;i<=n ;i++)
    {
        for(int j=1 ; j<=n ; j++)
        {
          a[i][j] = 10000;
        }
    }

    BFS(adj,3,3,0);
    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=n ;j++)
            vis[j]=0;

        BFS(adj,i,i,0);
    }



    map<pair<ll,ll>,bool> mp;
    ll ans[n]={0};
    for(int i=1 ;i<=n ;i++)
    {
        for(int j=1 ; j<=n ; j++)
        {
           if(a[i][j]!=0 && mp.find({i,j})==mp.end())
           {
              // cout << i << " " << j << " " << a[i][j]<<endl;
               mp[{i,j}]=1;
               mp[{j,i}]=1;
               ans[a[i][j]]++;
           }
        }
    }
    for(int i=1 ; i<n ; i++)
        cout << ans[i] << "\n";

    return 0;
}


Measured memory_bytes: 281600
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

vector< vector<int> > board;
vector<int> p, sw;
	int n, m, k;
	int ans=0;

void sol(int n){

	int cal, flag=0;

	if(n==0){
		for(int i=0;i<m;i++){
			cal=0;
			for(int j=0;j<board[i].size();j++){
				if(sw[board[i][j]]==1) cal++;
			}
			if(cal%2!=p[i]){
				flag=1;
				break;
			}
		}

		if(flag==0) ans++;
		//ans++;
		return;
	}

	for(int i=0;i<2;i++){
		sw[n]=i;
		sol(n-1);
	}
}

int main(){


	cin>> n >> m;
	sw.resize(n+1);
	p.resize(m);

	board.resize(m);
	for(int i=0;i<m;i++){
		cin>> k;
		board[i].resize(k);
		for(int j=0;j<k;j++){
			cin>> board[i][j];
		}
	}

	for(int i=0;i<m;i++) cin>> p[i];

	sol(n);			

	cout<< ans << endl;


}

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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	string s;
	cin >> s;
	int acnt = 0,bcnt = 0;
	for(int i = 0;i < 3;i++){
		if(s[i] == 'A'){
			acnt++;
		}else{
			bcnt++;
		}
	}
	if(acnt == 0 || bcnt == 0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 3636