akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <chrono>
#include <random>
#include <cstdio>
#define ll long long int
#define endl '\n'
#define pb push_back
#define mp make_pair
// #define mod 998244353
#define rep(i,n) for(ll i=0;i<n;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define pll pair<ll, ll>
#define pint pair<int, int>
#define S second
#define F first
#define all(c) (c).begin(),(c).end()
using namespace std;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
const int N=500001;
// vector<pair<ll, ll> > adj[N];
// bool vis[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
#define pi 3.14159265358979323846264338
using namespace std; 
ll max(ll a, ll b){ if(a>b)return a;return b;}
ll min(ll a, ll b){ if(a < b) return a;return b;}
ll inf = 100000000000000000;
vector <int> adj[N];


void solve() 
{
    ll a, b;
    cin>>a>>b;

    if(a > b) swap(a, b);

    if(a == b)
    {
        cout<<2*a - 2<<endl;
    }
    else if(a + 1 == b)
    {
        cout<<2*a - 2<<endl;
    }
    else
    {
        ll c =sqrt(a*b);
        if(c*c == a*b) c--;

        if(c*(c+1) >= a*b)
        {
            cout<<2*c - 2<<endl;
        }
        else
        {
            cout<<2*c - 1<<endl;
        }
    }

} 

int main()
{
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // cout<<'\n';
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

int main() {
  ios::sync_with_stdio(false);

  int N, M = 100001;
  cin >> N;

  vector<int> A(M);
  vector<int> B(M);
  for (int i = 0; i < N / 2; i++) {
    int a, b;
    cin >> a >> b;
    A.at(a)++, B.at(b)++;
  }

  int a, b, X = 0, Y = 0;
  for (int i = 0; i < M; i++) {
    if (A.at(i) > X) X = A.at(i), a = i;
    if (B.at(i) > Y) Y = B.at(i), b = i;
  }

  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());

  if (a == b) cout << min(N - A.at(0) - B.at(1), N - A.at(1) - B.at(0)) << endl;
  else cout << N - A.at(0) - B.at(0) << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String S=sc.next();
		int s=S.length();
		char[] a = S.toCharArray();
		
		if(s<=K) {
			System.out.print(S);
		}
		else {
			for(int i=0;i<K;i++) {
				System.out.print(a[i]);
			}
			System.out.print("...");
		}
		
		sc.close();
	}
}


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

long int *Marge(int N,long int*A){
	if (N==1){
		return A;
	}
	else{
		long int N1=N/2;
		long int N2=N-N1;
		int i;
		long int *A1=malloc(N1*sizeof(long int));
		long int *A2=malloc(N2*sizeof(long int));
		for (i=0;i<N1;i++){
			A1[i]=A[i];
		}
		for (i=N1;i<N;i++){
			A2[i-N1]=A[i];
		}
		long int *B1=Marge(N1,A1);
		long int *B2=Marge(N2,A2);
		long int *B=malloc(N*sizeof(long int));
		i=0;
		int j=0;
		int k=0;
		while(k<N){
			if(i==N1){
				for (k;k<N;k++){
					B[k]=B2[j];
					j++;
				}
				break;
			}
			else if (j==N2){
				for (k;k<N;k++){
					B[k]=B1[i];
					i++;
				}
				break;
			}
			else if (B1[i]>B2[j]){
				B[k]=B1[i];
				k++;
				i++;
			}
			else{
				B[k]=B2[j];
				k++;
				j++;
			}
		}
		return B;
	}
}

int main(){
	int N;
	scanf("%d",&N);
	int  i;
	long int *A=malloc(N*sizeof(long int));
	for (i=0;i<N;i++){
		scanf("%ld",&A[i]);
	}
	long int *B=Marge(N,A);
	i=0;
	int j=0;
	long int *L=malloc(2*sizeof(long int));
	while(i<N&&j<2){
		long int L1=B[i];
		if (B[i+1]==L1){
			L[j]=L1;
			j++;
			i+=2;
		}
		else{
			i++;
		}
	}
	long int ans=L[0]*L[1];
	printf("%ld\n",ans);
	return 0;
}

Measured memory_bytes: 31872
c=[]
for i in range(3):
  c.append(list(map(int,input().split())))
#print(c)

res=0
for i in range(2):
  if c[i][0]-c[i+1][0]==c[i][1]-c[i+1][1] and c[i][2]-c[i+1][2]==c[i][1]-c[i+1][1]:
    res+=1

for j in range(2):
  if c[0][j]-c[0][j+1]==c[1][j]-c[1][j+1] and c[2][j]-c[2][j+1]==c[1][j]-c[1][j+1]:
    res+=1
print("Yes" if res==4 else "No")

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

int main() {
	int N;
  	cin >> N;
	vector<int> A(N);
  	for(int i = 0; i < N; i++) cin >> A.at(i);
  
  	int ans = 0;
  	for(int i = 0; i < N-1; i++){
      if(A.at(i) == A.at(i+1)){
        ans++;
        i++;
      }
    }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  string S;
  cin >> S;
  if(S[0] == S[1] && S[0] == S[2]){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = Integer.parseInt(s.nextLine());
		boolean flag=true;
		int[] seq = new int[n];
		if(n<=100) {
		
		for(int i=0;i<n;i++) {
			seq[i]=s.nextInt();
			if(seq[i]>=0 && seq[i]<1000) {
				continue;
			}else {
				flag=false;
				break;
			}
		}
		}
		
		if(flag==true) {
			for(int j=n;j>0;j--) {
				if(j!=1) {
					System.out.print(seq[j-1]+" ");
				}else {
					System.out.println(seq[j-1]);
				}
			}
		}
		
	}

}

Measured memory_bytes: 26152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int n;
    cin >> n;
    vi mx;
    int mnmx = 1e9 + 1;
    for (int i = 0; i < n; i++)
    {
        int a;
        scanf("%d", &a);

        bool flg = true;
        if (mnmx < a)
        {
            for (size_t j = 0; j < mx.size(); j++)
            {
                if (mx[j] < a)
                {
                    mx[j] = a;
                    flg = false;
                    break;
                }
            }
        }
        if (flg)
        {
            mx.push_back(a);
            mnmx = a;
        }
    }

    cout << mx.size() << endl;

    return 0;
}


Measured memory_bytes: 892
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	int n;
	cin >> n;
	if (n < 4)
	{
		cout << "No";
		return 0;
	}
	if (n == 5 || n == 6 || n == 9 || n == 10 || n == 13 || n == 17)
	{
		cout << "No";
		return 0;
	}
	cout << "Yes";
	system("pause");
}

Measured memory_bytes: 504
#include<stdio.h>
int main(){int n,i,j,c=1,a[100010];scanf("%d", &n);for(i=1;i<=n;i++)scanf("%d",&a[i]);for(j=a[1];j!=2;c++){i=a[j];a[j]=0;j=i;if(!i){printf("-1\n");return 0;}}printf("%d\n",c);return 0;}

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

struct Node{
	int id;
	int depth;
	int height;
	Node *parent;
	vector<Node*> childs;

    bool operator<( const Node& param ) const {
        return id < param.id;
    }
};
Node *nil;

list<int> ids;
map<int, list<int>> getChilds;

void conChilds(Node *node){
	for(int childId : getChilds[node->id]){
		if(childId != -1){
			Node *child = new Node();
			child->id = childId;
			child->depth = node->depth + 1;
			child->parent = node;
			(node->childs).push_back(child);
			conChilds(child);
		}else{
			(node->childs).push_back(nil);
		}
	}

	int maxHeight = -1;
	for(Node *child : node->childs){
		if(child != nil)
			maxHeight = max(maxHeight, child->height);
	}
	node->height = maxHeight+1;
}

list<int> preorderList;
void preorder(Node *node){
	auto childs = node->childs;
	int k = childs.size();
	preorderList.push_back(node->id);
	if(k > 0 && childs[0] != nil) preorder(childs[0]);
	if(k > 1 && childs[1] != nil) preorder(childs[1]);
}

list<int> inorderList;
void inorder(Node *node){
	auto childs = node->childs;
	int k = childs.size();
	if(k > 0 && childs[0] != nil) inorder(childs[0]);
	inorderList.push_back(node->id);
	if(k > 1 && childs[1] != nil) inorder(childs[1]);
}

list<int> postorderList;
void postorder(Node *node){
	auto childs = node->childs;
	int k = childs.size();
	if(k > 0 && childs[0] != nil) postorder(childs[0]);
	if(k > 1 && childs[1] != nil) postorder(childs[1]);
	postorderList.push_back(node->id);
}

int main(){
	int n, id, t, maxId = 25;
	cin >> n;

	r(i, n){
		cin >> id;
		ids.push_back(id);
		list<int> childs;
		maxId = max(maxId, id);

		cin >> t;
		childs.push_back(t);
		cin >> t;
		childs.push_back(t);

		getChilds[id] = childs;
	}

	//search root
	bool isRoot[maxId+1]{};
	for(int id : ids){
		isRoot[id] = true;
	}
	for(int id : ids){
		for(int childId : getChilds[id]){
			isRoot[childId] = false;
		}
	}
	int rootId = -1;
	r(i, maxId+1){
		if(isRoot[i]){
			rootId = i;
			break;
		}
	}
	if(rootId == -1)
		printf("root couldn't be found");

	Node *root = new Node();
	root->id = rootId;
	root->depth = 0;
	root->parent = nil;

	conChilds(root);

	preorder(root);
	inorder(root);
	postorder(root);

	printf("Preorder\n");
	for(int i : preorderList) printf(" %d", i);
	printf("\nInorder\n");
	for(int i : inorderList) printf(" %d", i);
	printf("\nPostorder\n");
	for(int i : postorderList) printf(" %d", i);
	printf("\n");

	return 0;
}



Measured memory_bytes: 3288
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

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

    int N;
    cin>>N;
    vector<int> a(N);
    for (int n = 0; n < N; n++) cin>>a[n];
    sort(begin(a), end(a), greater<int>());

    int alice = 0;
    int bob = 0;
    for (int n = 0; n < N; n++) {
        if (n % 2 == 0) alice += a[n];
        else bob += a[n];
    }
    cout<<alice - bob<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M; cin >> N >> M; 
vector<int> cnt(M, 0);
for (int i = 0; i < N; ++i) {
int K; cin >> K;
for (int j = 0; j < K; ++j) {
int A; cin >> A; 
--A;
 ++cnt[A]; 
}
}
int ans = 0; 
for (int i =0; i < M; ++i){
if (cnt[i]== N) {
 ++ans;
} 
}
 
cout << ans << endl; 
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,count=0,a;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
   {
     scanf("%d",&a);
      if(i%2&&a%2) count++;
   }
  printf("%d\n",count);
 return 0;
}

Measured memory_bytes: 1728
#include <vector>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;
    vector<int> Xs, Ys, Zs;
    vector<int> As(N, 0);

    unordered_map<int, vector<int>> used_indices;

    int x, y, z;
    for (int i = 0; i < M; i++) {
        cin >> x >> y >> z;
        Xs.push_back(x - 1);
        Ys.push_back(y - 1);
        Zs.push_back(z);
        used_indices[x - 1].push_back(y - 1);
        used_indices[y - 1].push_back(x - 1);
    }
    unordered_set<int> indices_set;
    for (int i = 0; i < N; i++) {
        indices_set.insert(i);
    }
    queue<int> que_value;
    queue<int> que_index;
    int count = 0;
    int value, index;
    while (!indices_set.empty()) {
        if (que_value.size() == 0) {
            index = *indices_set.begin();
            value = 1;
            indices_set.erase(indices_set.begin());
            count += 1;
        } else {
            index = que_index.front();
            value = que_value.front();
            que_index.pop();
            que_value.pop();
            if (indices_set.find(index) == indices_set.end()) {
                continue;
            } else {
                indices_set.erase(indices_set.find(index));
            }
        }
        // cout << index << value << endl;
        // if (As[index] != 0) {
        //     continue;
        // }
        // As[index] = value;
        // equations in which X_index is used
        for (auto used_index: used_indices[index]) {
            if (Zs[used_index] % 2 == 0) {
                que_index.push(used_index);
                que_value.push(value);
            } else {
                que_index.push(used_index);
                // 1 -> 2, 2 -> 1
                que_value.push(3 - value);
            }
            
        }

    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 16008
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 3003
using namespace std;
const int Mod = 998244353;

int n, fac[N], inv[N], ifac[N];

void prework() {
    fac[0] = inv[1] = ifac[0] = 1;
    for (int i = 1; i <= n; ++i)
        fac[i] = 1ll * fac[i - 1] * i % Mod;
    for (int i = 2; i <= n; ++i)
        inv[i] = 1ll * inv[Mod % i] * (Mod - Mod / i) % Mod;
    for (int i = 1; i <= n; ++i)
        ifac[i] = 1ll * ifac[i - 1] * inv[i] % Mod;
}

inline int C(int x, int y) {
    return x < y ? 0 : 1ll * fac[x] * ifac[y] % Mod * ifac[x - y] % Mod;
}

int x, f[N][N << 1];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n >> x;
    prework();
    f[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < (n << 1); ++j)
            (f[i + 1][j + 1] += f[i][j]) %= Mod,
            (f[i + 1][j + 2] += f[i][j]) %= Mod;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int tmp = 0;
        for (int j = 0; j < x; ++j)
            (tmp += f[i][j]) %= Mod;
        for (int j = x + 1; j <= (i << 1); j += 2) {
            if (j < i) continue;
            int a = i - (j - (x - 1)), b = j - 2 * (j - (x - 1));
            if (2 * (x - 1) > j) (tmp += (a >= 0 && b >= 0 ? f[a][b] : 0)) %= Mod;
            else (tmp += ((j == (i << 1)) && (x & 1))) %= Mod;
        }
        (ans += 1ll * tmp * C(n, i) % Mod) %= Mod;
    }
    cout << ans + 1 << endl;
    return 0;
}


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

using namespace std;

const int DIM = 57;

double v[DIM];

main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> v[i];
	}
	
	sort(v + 1, v + 1 + n);
	
	for(int i = 2; i <= n; i++)
		v[i] = (v[i - 1] * 1.0 + v[i]) / 2;
	
	cout << fixed << setprecision(6) << v[n];
}

Measured memory_bytes: 256
def main():
    n, m, *ab, = map(int, open(0).read().split())
    p = [-1] * (n + 1)

    def find(x):
        while p[x] > 0:
            x = p[x]
        return x

    def union(i, j):
        pi, pj = find(i), find(j)
        if pi == pj:
            return
        if p[pi] < p[pj]:
            pi, pj = pj, pi
            i, j = j, i
        p[pi] += p[pj]
        p[pj] = pi
        reconnect(j, pi)

    def reconnect(i, j):
        while p[i] > 0:
            k = p[i]
            p[i] = j
            i = k

    for i, j in zip(ab[::2], ab[1::2]):
        union(i, j)

    print(-min(p))


if __name__ == '__main__':
    main()


Measured memory_bytes: 57144
#95d　高速化・整理
N,C = map(int, input().split())

#左右の折り返し毎に計算すると　2**(N-1) で地球爆発する。折り返しは無駄なので1回のみにする。
#すると、折り返し点N通り、時計回り・反時計回り2通り、計2Nの計算でOKとなる

#入力を読み込みつつ、時計回りの移動のカロリーを計算
xv_list = [(0,0)]
total_cal_list_cw = [0] #時計回りに進んだ時のカロリーリスト
max_total_cal_list_cw = [0] #時計回りに進んだ時、i以下最大のカロリーリスト
max_total_cal_cw = 0

for i in range(1,N+1): #10**5
    x,v = map(int, input().split())
    xv_list.append((x,v))
    total_cal_cw = total_cal_list_cw[i-1] + v - x + xv_list[i-1][0]
    total_cal_list_cw.append(total_cal_cw)
    
    if max_total_cal_cw < total_cal_cw:
        max_total_cal_cw = total_cal_cw
        
    max_total_cal_list_cw.append(max_total_cal_cw)

#半時計回り移動のカロリーを計算
rev_xv_list = [(0,0)] + [(C - xv[0],xv[1]) for xv in xv_list[:-(N+1):-1]] #xv_kistを逆順に読み込み、xは原点から反時計回り時の距離にする
total_cal_list_acw = [0] #反時計回り時のカロリーリスト。以下同様。
max_total_cal_list_acw = [0]
max_total_cal_acw = 0

for i in range(1,N+1): #10**5
    x,v = rev_xv_list[i][0],rev_xv_list[i][1]
    total_cal_acw = total_cal_list_acw[i-1] + v - x + rev_xv_list[i-1][0]
    total_cal_list_acw.append(total_cal_acw)
    
    if max_total_cal_acw < total_cal_acw:
        max_total_cal_acw = total_cal_acw
    
    max_total_cal_list_acw.append(max_total_cal_acw)    

    
#準備ができたので、最大に摂取できるカロリーを求める。
ans = 0

for i in range(1,N+1): #10**5
    #a.先に時計回りをする場合
    #折り返さない場合
    if ans < total_cal_list_cw[i]:
        ans = total_cal_list_cw[i]
    #折り返す場合
    total_cal = total_cal_list_cw[i] - xv_list[i][0] #原点まで戻る
    if total_cal > 0:
        total_cal += max_total_cal_list_acw[N-i]
        if ans < total_cal:
            ans = total_cal
    
    #b.先に反時計回りをする場合
    #折り返さない場合
    if ans < total_cal_list_acw[i]:
        ans = total_cal_list_acw[i]
    #折り返す場合
    total_cal = total_cal_list_acw[i] - rev_xv_list[i][0] #原点まで戻る
    if total_cal > 0:
        total_cal += max_total_cal_list_cw[N-i]
        if ans < total_cal:
            ans = total_cal
        
print(ans)

Measured memory_bytes: 39132
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define mp make_pair
#define REP(i,a,b) for(ll i=a;i<b;i++)
typedef long long ll;
using namespace std;

void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}


int main(){

FAST();
 int n; cin>>n;
  if(n>=30)
    cout<<"Yes";
  else
    cout<<"No";


return 0;
}

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

int main(){

  int N ; 
  cin >> N ; 
  vector<int> L(N) ; 
  int cnt = 0 ; 
  
  for(int i = 0 ; i < N ; i++){
    cin >> L.at(i) ; 
  }
  
  sort(L.begin() , L.end()) ; 
  reverse(L.begin() , L.end()) ; 
  
  for(int i = 0 ; i < N-2 ; i ++){
    for(int j = i+1 ; j < N-1 ; j++){
      for(int k = j+1 ; k < N ; k++){

    	if(L.at(i) < (L.at(j) + L.at(k)) && L.at(j) != L.at(k) && L.at(i) != L.at(k) && L.at(i) != L.at(j) ){
       // cout << i << " " << j << " " << k << endl ;          
          cnt++ ; 
        }
      }
    }
  }
  
           cout << cnt << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;
    int answer=1;
    REP(i,n){
        if(answer < k){
            answer*=2;
        }else answer+=k;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n,k;
    cin >> n >> k;
    long a[n];
    for(int i=0;i<n;i++)cin >> a[i];

    long ans = 1L<<50;
    
    for(long bit=0;bit<(1<<n);bit++){
        int colors = 0;
        long maxx = a[0]-1;
        long cost = 0;
        
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                colors++;
                cost += max(0L,maxx + 1 - a[i]);
                maxx = max(maxx+1, a[i]);
            }
            maxx = max(maxx,a[i]);
        }

        if(colors >= k){
            ans = min(ans,cost);
        }
    }
    cout << ans << endl;
    
}

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

using namespace std;

int dfs(map<int, vector<int>> &adList, int node, vector<pair<int, int>> &dp)
{
    // cout << node << " " << adList[node].size() << endl;
    if (dp[node].first)
    {
        return dp[node].second;
    }
    if (adList[node].size() == 0)
    {
        return 0;
    }

    int maxL = INT_MIN;
    for (int i = 0; i < adList[node].size(); i++)
    {
        int length = 1 + dfs(adList, adList[node][i], dp);
        // cout << node << " " << adList[node][i] << " " << length << endl;
        maxL = max(maxL, length);
    }

    dp[node] = make_pair(true, maxL);
    return maxL;
}

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

    int n, m;
    cin >> n >> m;

    vector<int> x(m);
    vector<int> y(m);

    map<int, vector<int>> adList;
    vector<pair<int, int>> dp(n + 1);

    for (int i = 0; i < m; i++)
    {
        cin >> x[i] >> y[i];
        adList[x[i]].push_back(y[i]);
    }

    if (n == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    if (m == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    int result = INT_MIN;
    for (int i = 1; i <= n; i++)
    {
        if (!dp[i].first)
        {
            result = max(result, dfs(adList, i, dp));
        }
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 17536
import java.util.*;
        public class Main {
         
        	public static void main(String[] args) {
        		// TODO 自動生成されたメソッド・スタブ
        		Scanner sc = new Scanner(System.in);
              	int a = sc.nextInt();
              int sum = 0;
              	for(int i = 1; i <= a; i++) {
                  sum += i;
                }
              System.out.println(sum);
            }
        }

Measured memory_bytes: 20692
import java.util.Scanner;

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

		while (true) {
			String s = sc.next();
			if (s.equals("0")) {
				break;
			}
			a = new int[3][3];
			for (int i = 0; i < 3; i++) {
				a[0][i] = s.charAt(i);
			}
			for (int i = 1; i < 3; i++) {
				s = sc.next();
				for (int j = 0; j < 3; j++) {
					a[i][j] = s.charAt(j);
				}
			}
			if (
					(a[0][0] == 'b' && a[0][1] == 'b' && a[0][2] == 'b') ||
					(a[1][0] == 'b' && a[1][1] == 'b' && a[1][2] == 'b') ||
					(a[2][0] == 'b' && a[2][1] == 'b' && a[2][2] == 'b') ||
					(a[0][0] == 'b' && a[1][0] == 'b' && a[2][0] == 'b') ||
					(a[0][1] == 'b' && a[1][1] == 'b' && a[2][1] == 'b') ||
					(a[0][2] == 'b' && a[1][2] == 'b' && a[2][2] == 'b') ||
					(a[0][0] == 'b' && a[1][1] == 'b' && a[2][2] == 'b') ||
					(a[0][2] == 'b' && a[1][1] == 'b' && a[2][0] == 'b')) {
				System.out.println("b");
			} else if (
					(a[0][0] == 'w' && a[0][1] == 'w' && a[0][2] == 'w') ||
					(a[1][0] == 'w' && a[1][1] == 'w' && a[1][2] == 'w') ||
					(a[2][0] == 'w' && a[2][1] == 'w' && a[2][2] == 'w') ||
					(a[0][0] == 'w' && a[1][0] == 'w' && a[2][0] == 'w') ||
					(a[0][1] == 'w' && a[1][1] == 'w' && a[2][1] == 'w') ||
					(a[0][2] == 'w' && a[1][2] == 'w' && a[2][2] == 'w') ||
					(a[0][0] == 'w' && a[1][1] == 'w' && a[2][2] == 'w') ||
					(a[0][2] == 'w' && a[1][1] == 'w' && a[2][0] == 'w')) {
				System.out.println("w");
			} else {
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 12000
"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
# flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)
 
def iin(): return int(input())
 
 
def lin(): return list(map(int, input().split()))
 
 
# range = xrange
# input = raw_input
 
def main():
    T = 1
    while T:
        T-=1
        n, m = lin()
        a = lin()
        sm = sum(a)
        ch = 0
        lst = sm/(4*m)
        for i in a:
            if i>=lst:
                ch+=1
        print('Yes' if ch>=m else 'No')

 
 
 
 
 
main()
 
# threading.Thread(target=main).start()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

int main() {
	// 오늘 할 것!  종만북 보기! 
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	ll Min = 9999999999;
	ll Max = 0;
	rep(i, n) {
		ll x; cin >> x;
		Min = min(Min, x);
		Max = max(Max, x);
	}
	cout << Max - Min << '\n';


}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int temp = 0;

    temp = a;
    a = b;
    b = temp;

    temp = a;
    a = c;
    c = temp;

    System.out.println(a+" "+b+" "+c);
  }
}

Measured memory_bytes: 21460
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B;
	cin>>A>>B;
	int ans=0;
	if (A<=5){
	}else if (A>=6 &&A<=12){
		ans+=B/2;
	}else{
		ans+=B;
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef pair<lint, lint> P;
vector<lint> dist;
const lint INF = 1e18;
struct  edge{lint to, cost;};
vector<edge> G[100010];

void dij(lint start){
  priority_queue<P, vector<P>, greater<P> > que;
  for(lint i = 0; i < dist.size(); i++) dist[i] = INF;
  dist[start] = 0;
  que.push(P(0, start));
  
  while(!que.empty()){
    P p = que.top(); que.pop();
    lint next = p.second;
    if(dist[next] < p.first) continue;
    for(lint i = 0; i < G[next].size(); i++){
      edge e = G[next][i];
      if(dist[next] + e.cost < dist[e.to]){
        dist[e.to] = dist[next] + e.cost;
        que.push(P(dist[e.to], e.to));
      }
    }
  }
}

signed main(){
  lint N; cin >> N;
  for(lint i = 0; i < N - 1; i++){
    lint a, b, c; cin >> a >> b >> c;
    edge e = {b - 1, c}, e1 = {a - 1, c};
    G[a - 1].push_back(e); G[b - 1].push_back(e1); 
  }
  dist.resize(N);
  lint Q, K; cin >> Q >> K;
  dij(K - 1);
  for(lint i = 0; i < Q; i++){
    lint x, y; cin >> x >> y;
    lint ans = dist[x - 1] + dist[y - 1];
    cout << ans << endl;
  }
}
  

Measured memory_bytes: 11120
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <math.h>

using namespace std;

#define NUM 1300000

int main(){
	int* table = new int[NUM];
	int limit;

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;
	table[1] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	table[1] = 1;
	table[2] = 0;

	int pre_index = 2,gap;

    for(int i = 3; i <= 1299709; i++){
		if(table[i] == 1){
			table[i] = 0;
			gap = i - pre_index;
			for(int k = i-1; k >= pre_index+1;k--){
				table[k] = gap;
			}
			pre_index = i;
		}
	}

	int n;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		printf("%d\n",table[n]);
	}
	return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>x(m);
    for(int i=0;i<m;i++){
        cin>>x[i];
    }
    if(n>=m){
        cout<<0<<endl;
    }else{
        int min=*min_element(x.begin(),x.end());
        int max=*max_element(x.begin(),x.end());
        sort(x.begin(),x.end());
        vector <int>span;
        for(int i=0;i<m-1;i++){
            span.push_back(x[i+1]-x[i]);
        }
        sort(span.begin(),span.end());
        reverse(span.begin(),span.end());
        int total=0;
        for(int i=0;i<n-1;i++){
            total+=span[i];
        }
        cout<<max-min-total<<endl;
    }
    
    



}

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

int main()
{

        int K, N;
        cin >> K >> N;
        int A[N];
        for (int i = 0; i < N; ++i) {
                cin >> A[i];
        }
        int len[N];
        for (int i = 0; i < N; ++i) {
                if (i == 0) continue;
                len[i] = A[i] - A[i-1];
                if (i == N-1) {
                        len[0] = K - A[i] + A[0];
                }
        }
        int maxv = -1;
        long long ans = 0;
        for (int i = 0; i < N; ++i) {
                ans += len[i];
                if (maxv < len[i]) maxv = len[i];
        }
        cout << ans - maxv << endl;







}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define llMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n, m;
map<int, int> mp;

int main(){
  cin >> n >> m;
  vector<int> a(m);
  vector<ll> dp(n+1);
  for(int i = 0; i < m; i++)cin >> a[i];
  sort(all(a));
  reverse(all(a));
  string res = "";
  mp[1] = 2; mp[2] = 5; mp[3] = 5;
  mp[4] = 4; mp[5] = 5; mp[6] = 6;
  mp[7] = 3; mp[8] = 7; mp[9] = 6;//動的計画法部分
  dp[0] = 0;
  // cout << INT32_MIN << endl;
  for(int i = 1; i < n+1; i++){
    ll ans  = INT32_MIN;
    for(int j = 0; j < m; j++){
      ll index = i - mp[a[j]];
      if(index >= 0){
        ll tmp = dp[index]+1;
        // cout << i <<" "<<mp[a[j]] << " " <<a[j] << endl;
        ans = max(tmp, ans);
      } 
    }
    dp[i] = ans;
    // cout << i << " " << dp[i] << endl;
  }
  int i = n;//マッチの数
  while(i > 0){
    for(int j = 0; j < m; j++){
      int index = i - mp[a[j]];
      if(index < 0 )continue;
      if(dp[index] == (dp[i]-1)){
        // cout << index << endl;
        res += a[j]+'0';
        i -= mp[a[j]];
        // cout <<i<<" " <<res << endl;
        break;
      }
    }
  }
  // cout << dp[n] << endl;
  cout << res << endl;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[][] table = new int[n][] ;
   
            //証言の表の作成
            for(int i = 0; i < n; i++)
            {
                int a = int.Parse(Console.ReadLine());
                table[i] = new int[a];
                for(int j = 0; j < a; j++)
                {
                    string[] str = Console.ReadLine().Split(' ');
                    int x = int.Parse(str[0]);
                    int y = int.Parse(str[1]);
                    if (y == 1) {table[i][j] = x;}
                    else { table[i][j] = -x; }
                }
            }



            double max = 0;

            //以下各パターンにおいて矛盾がないか調べる
            for(int i = 1; i < (Math.Pow(2,n)); i++)
            {
                double[] X = new double[n];
                int p = i;
                for(int q = n-1; q >= 0; q--)
                {
                    if (p >= (int)(Math.Pow(2, q)))
                    {
                        X[q] = 1;
                        p -= (int)(Math.Pow(2, q));
                    }
                    else {
                        X[q] = 0;
                    }
                }



                for (int xi = 0; xi < n; xi++)
                {
                    if (X[xi] != 0)
                    {
                        for (int yi = 0; yi < table[xi].Length; yi++)
                        {
                            if (((table[xi][yi]>0 ^ X[Math.Abs(table[xi][yi])-1] ==0))==false)
                            {
                                goto badend;
                            }
                        }
                    }
                }
                    if(X.Sum()>max)
                    {
                        max = X.Sum();
                    }
            badend:;

            }

            Console.WriteLine(max);

            //ここまで
        }
    }
}


Measured memory_bytes: 17488
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100100;
int i,j,k,n,l,t,ff,ch,st;
int x[N],w[N];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
int main() {
	R(n);R(l);R(t);
	st=0;
	for (i=0;i<n;i++) {
		R(x[i]);R(w[i]);
		if (w[i]==1) st=(st+t/l)%n;
		else st=(st+n-t/l)%n;
		int tt=t%l;
		if (w[i]==1) {
			x[i]+=tt;
			if (x[i]>=l) x[i]-=l,st=(st+1)%n;
		}
		else {
			x[i]-=tt;
			if (x[i]<0) x[i]+=l,st=(st+n-1)%n;
		}
	}
	sort(x,x+n);
	for (i=st;i<st+n;i++) printf("%d\n",x[i%n]);
}

Measured memory_bytes: 1920
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    long double a;
    long double b;
    cin >> a >> b;
    ll ans = a*b;
    cout << ans << endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
int main(){
	char s[200];
	cin>>s;
	for(int i=0; i<strlen(s); i++){
		for(int j=i+1; j<strlen(s); j++){
			if(s[i]=='C'&&s[j]=='F'){
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
//cool
#include <iostream>
#include <fstream>
#include <set>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for(int i=a; i<b; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define clean(a, b) memset(a, b, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pb push_back

ll n, a[30], ans;
bool ch[30];

ll main(){
	IOS;
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i];
	for (int i=1; i<n-1; i++){
		if (a[i] > min(a[i-1] , a[i+1]) && a[i]< max(a[i-1] , a[i+1])){
			ans++;
		}
	}
	cout << ans;
}
		
		


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long

signed main(){
	int K, A, B;
	scanf("%lld%lld%lld", &K, &A, &B);
	if(A >= K){
		printf("1\n");
	}
	else if(A <= B){
		printf("-1\n");
	}
	else{
		printf("%lld\n", 2 * (((K - A) + (A - B) - 1) / (A - B)) + 1);
	}
	return 0;
}

Measured memory_bytes: 128
program main
  implicit none
  integer :: n, i, j, k, a(3, 3), b(10)
  logical :: chosen(3, 3), bingo
  do i = 1, 3
    read (*, *) a(:, i)
  end do
  read (*, *) n
  do k = 1, n
    read (*, *) b(k)
  end do

  chosen(:, :) = .false.
  do k = 1, n
    do i = 1, 3
      do j = 1, 3
        if (a(j, i) == b(k)) chosen(j, i) = .true.
      end do
    end do
  end do

  bingo = .false.
  do i = 1, 3
    bingo = bingo .or. (chosen(1, i) .and. chosen(2, i) .and. chosen(3, i))
    bingo = bingo .or. (chosen(i, 1) .and. chosen(i, 2) .and. chosen(i, 3))
  end do
  bingo = bingo .or. (chosen(1, 1) .and. chosen(2, 2) .and. chosen(3, 3))
  bingo = bingo .or. (chosen(3, 1) .and. chosen(2, 2) .and. chosen(1, 3))
  if (bingo) then
    write (*, "(a)") "Yes"
  else
    write (*, "(a)") "No"
  end if
end program main


Measured memory_bytes: 256
//complete Binary tree


#include<stdio.h>
#define N NULL
#define MAX 250

int main()
{
  int i,n,arr[MAX];


  //input data
  scanf("%d",&n);
  for(i = 1; i< n+1; i++)
    {
      scanf("%d",&arr[i]);
    }

  //output data
  for(i = 1; i < n+1; i++)
    {
      printf("node %d: ",i);

      printf("key = %d, ",arr[i]);

      if(i != 1)
	{
	  printf("parent key = %d, ",arr[i/2]);
	}
      if(2*i <= n)
	{
	  printf("left key = %d, ",arr[2*i]);
	}
      if(2*i+1 <= n)
	{
	  printf("right key = %d, ",arr[2*i+1]);
	}
      printf("\n");
    }


  return 0;
}




Measured memory_bytes: 2040
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int b[n];
    for(int i = 0;i < n;i++)scanf("%d",&b[i]);
    int prs[n];
    for(int i = 0;i < n;i++)prs[i] = 0;
    int cop[n];
    int bdresflag=0;
    for(int st = 0;st < n;st++){
        int conpflag=0;

        for(int copind = 0;copind < n;copind++)cop[copind] = b[copind];

        for(int prscnt = 0;prscnt < n;prscnt++){
            int ablflag=0;
            for(int chind = n-prscnt-1;chind >= 0;chind--)if(cop[chind]==chind+1){
                ablflag=1;
                prs[prscnt]=chind+1;
                for(int copind = chind+1;copind < n-prscnt;copind++)cop[copind-1]=cop[copind];
                if(prscnt==n-1)conpflag=1;
                break;
            }
            if(!ablflag)break;
        }
        if(conpflag)break;
        if(!conpflag && st==n-1)bdresflag=1;
    }
    if(bdresflag){
        puts("-1");
        return 0;
    }
    for(int i = n-1;i>=0;i--)printf("%d\n",prs[i]);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner (System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		if ((r<=x && x<= w-r) && (r<=y && y<= h-r) ) System.out.println("Yes");
		else System.out.println("No");
	}
}


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

int main() {
  char s[100001], t[100001];
  scanf("%s %s", s, t);
  int ls = strlen(s), lt = strlen(t), substr[ls+1][26]; long ans = 0;
  for (int i=0; i<26; i++) substr[ls][i] = -1;
  for (int i=ls-1; i>=0; i--) {
    for (int j=0; j<26; j++) substr[i][j] = substr[i+1][j];
    substr[i][s[i]-'a'] = i;
  }
  int idx = 0;
  for (int i=0; i<lt; i++) {
    int numt = t[i]-'a';
    if (substr[0][numt] == -1) {
      printf("-1\n");
      return 0;
    }
    if (substr[idx][numt] == -1) {
      ans += ls-idx;
      idx = 0;
    }
    ans += substr[idx][numt]+1 - idx;
    idx = substr[idx][numt]+1;
  }
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 10496
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	int N, K; cin >> N >> K;
	int x[101];
	int sum = 0;
	rep(i, 1, N + 1) {
		cin >> x[i];
		sum += (K - x[i] > x[i]) ? 2 * x[i] : 2 * (K - x[i]);
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)

const ll N = 123456;
const ll mod = 1e9 + 7;
const ld eps = 1e-5;

int a[123][123];
int dp[23][(1 << 22)];

int n;
ll lim = (1 << 22) - 1;
ll solve(ll i , ll mask) {
    if(i == n) return mask == lim;
    if(dp[i][mask] != -1) return dp[i][mask];

    ll c = 0;

    rep(j , 0 , n - 1) {

        if(a[i][j] != 0 && (mask & (1 << j)) == 0) {
            c += solve(i + 1 , mask | (1 << j));
            c %= mod;
        }
    }

    dp[i][mask] = c;

    return c;

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

    cout << fixed;

    cin >> n;

    rep(i , 0 , n - 1) {
        rep(j , 0 , n - 1) {
            cin >> a[i][j];
        }
    }

    lim = (1 << n) - 1;
    rep(i , 0 , 22) {
        rep(j , 0 , lim) {
            dp[i][j] = -1;
        }
    }
    cout << solve(0 , 0) << endl;

    return 0;
}


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

int main() {
  int64_t N,K,Z=0;
  cin>>N>>K;
  if(K%2==0){
    int64_t A=(N+K/2)/K;
    Z+=A*A*A;
  }
  int64_t A=N/K;
  Z+=A*A*A;
  cout<<Z<<endl;
  
}

Measured memory_bytes: 256
n = int(input())
nList = list(map(int,input().split()))

cDic = {}
for i in nList:
  if not(i in cDic):
    cDic[i] = 1
  else:
    cDic[i] += 1

count = 0
for i,j in cDic.items():
  if i <= j:
    count += j-i
  else:
    count += j

print(count)
  

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

int main ()

{
    int N;

    int i,x,a=0,b=0,c=0;
    scanf("%d",&N);
    int ara[N];

    for(i=0;i<N;i++) scanf("%d",&ara[i]);

    for(i=0;i<N;i++){

        if(ara[i]%4==0) a++;
        if(ara[i]%4==1||ara[i]%4==3) b++;
        if(ara[i]%4==2) c++;
    }
    if(c==0&&a>=b-1) {
            printf("Yes");
            return 0;}
    else if(c>0&&a>=b){
        printf("Yes");
        return 0;
    }
    else {
        printf("No");
        return 0;
    }

}


Measured memory_bytes: 640
MyString=Union{String,SubString{String},Char}
MyStringArray=Union{Array{String,1},Array{SubString{String},1},Array{Char,1}}
parseInt(x::MyString) = parse(Int, x)
parseInt(x::Real) = trunc(Int, x)
parseBigInt(x::MyString) = parse(BigInt, x)
parseBigInt(x::Real) = trunc(BigInt, x)
parseFloat(x::MyString) = parse(Float64, x)
parseFloat(x::Real) = trunc(Float64, x)
parseBigFloat(x::MyString) = parse(BigFloat, x)
parseBigFloat(x::Real) = trunc(BigFloat, x)
parseMap(x::MyStringArray) = map(parseInt, x)
parseMapBig(x::MyStringArray) = map(parseBigInt, x)

function main()
    n=parseInt(readline())
    println(sum([i for i in 1:n]))
end
main()

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i < N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  cout << A.back() - A.front();
  return 0;
}

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

int main() {
	int a,b; cin >> a >> b;
	int ans = 0;
	rep(i,2) {
		ans+=max(a,b);
		if(max(a,b)==a) a--;
		else b--;
	}
	cout << ans << endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 5005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL cycle(int st);

int N, K;
LL p[SIZE];
LL c[SIZE];

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

    cin >> N >> K;

    for(int i = 1; i <= N; ++i) {
        cin >> p[i];
    }
    for(int i = 1; i <= N; ++i) {
        cin >> c[i];
    }

    LL res = LMIN;
    for(int i = 1; i <= N; ++i) {
        res = max(res, cycle(i));
    }
    cout << res << endl;
    return 0;
}

LL cycle(int st) {
    int k = K;
    LL res = 0;
    int tmp = st;
    LL mx = LMIN;
    int cy = 0;
    do {
        tmp = p[tmp];
        res += c[tmp];
        mx = max(mx, res);
        --k;
        ++cy;
    } while(tmp != st && k > 0);

    if(k == 0) {
        return mx;
    }

    if(res > 0) {
        LL tres = res;
        res = res * (K / cy);
        k = K % cy;
        LL t = 0;
        mx = 0;
        tmp = st;
        while(k > 0) {
            k--;
            tmp = p[tmp];
            t += c[tmp];
            mx = max(mx, t);
        }

        t = res - tres;
        tmp = st;
        mx = res + mx;
        do {
            tmp = p[tmp];
            t += c[tmp];
            mx = max(t, mx);
        } while(tmp != st);

        return mx;
    }

    return mx;
}


Measured memory_bytes: 3688
// God be praised
#include <bits/stdc++.h>
using namespace std;

bool test () {
	string s, t;
	cin >> s >> t;

	int n = s.length();

	for (int i = n-1; i >= 0; i--) {
		bool ok = true;
		for (int cnt = 0; cnt < n; cnt++) {
			if (t[cnt] != s[(i+cnt)%n]) {
				ok = false;
				break;
			}
		}
		if (ok) return true;
	}

	return false;
}

int main () {
	if (test()) puts("Yes");
	else puts("No");

	return 0;
}

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

int main(){
    int n;
    int x;
    int t;
    int nOt;
    cin >> n >> x >> t;
    if(n%x == 0){
        nOt = n/x;
        cout << nOt*t << endl;
    }
    else{
        nOt = n/x+1;
        cout << nOt*t << endl;
    }
}

Measured memory_bytes: 3560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
const int N = 100010;

char s[10];
int rec[N];
int main()
{

	int i, j, k, n;
	scanf("%d", &n);
	int lb = 0, rb = n;
	printf("%d\n", 0), fflush(stdout);
	scanf("%s", s); if(s[0] == 'V')return 0;
	if(s[0] == 'F')rec[0] = rec[n] = 1;
	while(lb <= rb){
		int md = lb + rb + 1 >> 1;
		printf("%d\n", md), fflush(stdout);
		scanf("%s", s); if(s[0] == 'V')return 0;
		if(s[0] == 'F')rec[md] = 1;
		if(rec[md] == rec[lb]){
			if(md - lb & 1)
				rb = md - 1;
			else
				lb = md;
		}else{
			if(md - lb & 1)
				lb = md;
			else
				rb = md - 1;
		}
	}

	return 0;
}


Measured memory_bytes: 852
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main(){
    int n,m,c;
    cin>>n>>m>>c;
    int b[m];
    rep(i,m) cin>>b[i];
    int a[n][m];
    rep(i,n) rep(j,m) cin>>a[i][j];

    int count=0;

    rep(i,n){
        int Sum=0;
        rep(j,m){
            Sum+=b[j]*a[i][j];
        }
        if(Sum+c>0) count++;
    }

    cout<<count<<endl;
}

Measured memory_bytes: 3576