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

int main() {
  int K;
  cin >> K;
  string S;
  cin >> S;
  if(S.size() <= K) {
    cout << S << endl;
  }
  else {
    for(int i = 0; i < K; i++) {
      cout << S.at(i);
      if(i == K-1) {
        cout << "..." << endl;
      }
    }
  }
}


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

int N;
#define MAXN 100000
int A[MAXN], B[MAXN], C[MAXN];
long long n[MAXN], s[MAXN + 1];

int main() {
  scanf("%d", &N);
  for(int i = 0; i < N; ++i) scanf("%d", &A[i]);
  for(int i = 0; i < N; ++i) scanf("%d", &B[i]);
  for(int i = 0; i < N; ++i) scanf("%d", &C[i]);
  sort(A, A + N); sort(B, B + N); sort(C, C + N);
  for(int i = 0; i < N; ++i) {
    n[i] = lower_bound(A, A + N, B[i]) - A;
    s[i + 1] = s[i] + n[i];
  }
  long long res = 0;
  for(int i = 0; i < N; ++i) {
    res += s[lower_bound(B, B + N, C[i]) - B];
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 2944
using System;
using System.Collections.Generic;

namespace AtCoder2020Ned
{
    class Program
    {
        static void Main(string[] args)
        {
            var numberOfPicked = int.Parse(Console.ReadLine());
            var priseList = new Dictionary<string, object>();

            for (int i = 0; i < numberOfPicked; i++)
            {
                var priseName = Console.ReadLine();

                if (!priseList.ContainsKey(priseName))
                {
                    
                    priseList.Add(priseName, null);
                }
            }

            Console.WriteLine(priseList.Count);
        }
    }
}


Measured memory_bytes: 49760
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

int main(){
  ll x, ans = 0, check = 100;
  cin >> x;
  while(check<x){
    check += check*0.01;
    ans++;
  }

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


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <map>
 
using namespace std;

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

    int N;
    int countR = 0;
    int countB = 0;

    cin >> N;

    for(int i = 0; i < N; i++)
    {
        char s;
        cin >> s;
        if(s == 'R')
        {
            countR++;
        } else {
            countB++;
        }
    }

    if(countR > countB)
    {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

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

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

struct Node *root,*NIL;

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

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

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

struct Node * find(struct Node *x,int k){
  while(x!=NIL && k!=x->key){
    if(k<x->key) x=x->left;
    else x=x->right;
  }
  return x;
}

void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  struct Node *fi;
  char str[20];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(str[0]=='f'){
      scanf("%d",&x);
      fi=find(root,x);
      if(fi==NIL) printf("no\n");
      else printf("yes\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19360
n = int(input())
L = list(map(int, input().split()))
cnt = 0
for i in range(n):
    a = L[i]
    for j in range(i + 1, n):
        b = L[j]
        if a == b:
            continue
        for k in range(j + 1, n):
            c = L[k]
            if a == b or b == c or c == a:
                continue
            if a + b > c and b + c > a and c + a > b:
                cnt += 1
                # print(i, j, k)
print(cnt)


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

int main(){
    int N, W; cin>>N>>W;
    int value[N],weight[N];
    for(int i=0;i<N;i++) cin>>value[i]>>weight[i];

    int dp[110][10010];
    for(int i=0;i<W;i++) dp[0][i] = 0;

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

    cout<<dp[N][W]<<endl;

    return 0;
}


Measured memory_bytes: 7076
#include <stdio.h>

int main(void)
{
	int x[3];
	int i, j, n;
	
	scanf("%d", &n);
	
	for (j = 0; j < n; j++){
		for (i = 0; i < 3; i++){
			scanf("%d", &x[i]);
		}
		if ((x[1] < x[0]) && (x[0] > x[2])){
			if ((x[1] * x[1] + x[2] * x[2]) == (x[0] * x[0])){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		
		else if ((x[0] < x[1]) && (x[1] > x[2])){
			if ((x[0] * x[0]) + (x[2] * x[2]) == (x[1] * x[1])){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		else {
			if ((x[0] * x[0]) + (x[1] * x[1]) == (x[2] * x[2])){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
	}
	
	return (0);
}

Measured memory_bytes: 1804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,a[N],s[N][2],ans=N;
char S[N];
signed main()
{
	n=read();
	scanf("%s",S+1);
	for (int i=1;i<=n;i++) if (S[i]=='#') a[i]=1;else a[i]=0;
	for (int i=1;i<=n;i++)
	{
		s[i][0]=s[i-1][0],s[i][1]=s[i-1][1];
		if (a[i]==1) s[i][1]++;else s[i][0]++;
	}
	for (int i=0;i<=n;i++) ans=min(ans,s[i][1]+s[n][0]-s[i][0]);
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}

Measured memory_bytes: 2816
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'


const int MXN = 110000;
int x, sieve[MXN];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

	cin >> x;
	FOR(i, 2, MXN){
		if (sieve[i]) continue;
		else{
			for(int j = 2*i; j< MXN; j+=i){
				sieve[j] = 1;
			}
		}
	}
	FOR(i, x, MXN){
		if (!sieve[i]){
			cout << i << newl;
			break;
		}
	}


















	return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

namespace arc093_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            x[0]--; x[1]--;
            Console.WriteLine(100 + " " + 100);
            int count = 0;
            for (int i = 0; 50 <= x[0]; i++)
            {
                for (int j = 0; j < 100; j++) Console.Write('#');
                Console.WriteLine(); count++;
                for (int j = 0; j < 100; j++) Console.Write(j % 2 == 0 ? '.' : '#');
                Console.WriteLine(); count++;
                x[0] -= 50;
            }
            for (int j = 0; j < 100; j++) Console.Write('#');
            Console.WriteLine(); count++;
            for (int j = 0; j < 50; j++)
            {
                if (j < x[0]) Console.Write(".#");
                else Console.Write("##");
            }
            Console.WriteLine(); count++;
            for (int j = 0; j < 100; j++) Console.Write('#');
            Console.WriteLine(); count++;

            for (int i = 0; 50 <= x[1]; i++)
            {
                for (int j = 0; j < 100; j++) Console.Write('.');
                Console.WriteLine(); count++;
                for (int j = 0; j < 100; j++) Console.Write(j % 2 == 0 ? '.' : '#');
                Console.WriteLine(); count++;
                x[1] -= 50;
            }
            for (int j = 0; j < 100; j++) Console.Write('.');
            Console.WriteLine(); count++;
            for (int j = 0; j < 50; j++)
            {
                if (j < x[1]) Console.Write("#.");
                else Console.Write("..");
            }
            Console.WriteLine(); count++;
            for (; count < 100; count++)
            {
                for (int j = 0; j < 100; j++) Console.Write('.');
                Console.WriteLine();
            }
        }
    }
}

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


void solve(long long D, long long G, std::vector<long long> p, std::vector<long long> c){
    int ans = 1e9;

    // bit全探索
    for (int i=0; i<(1<<D); i++) {
        int solve = 0, score = 0;
        int partial = -1;
        // それぞれのbitをチェックする
        for (int j=0; j<D; j++) {
            if (i & (1<<j)) {
                solve += p[j];
                score += 100 * (j + 1) * p[j] + c[j];
            } else {
                partial = j;
            }
        }

        long long less = G - score;
        if (less > 0) {
            int part_score = 100 * (partial + 1);
            if (less > part_score * p[partial]) continue;
            solve += min(p[partial], (less + (part_score-1)) / part_score);
        }
        ans = min(ans, solve);
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long D;
    scanf("%lld",&D);
    long long G;
    scanf("%lld",&G);
    std::vector<long long> p(D);
    std::vector<long long> c(D);
    for(int i = 0 ; i < D ; i++){
        scanf("%lld",&p[i]);
        scanf("%lld",&c[i]);
    }
    solve(D, G, std::move(p), std::move(c));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector<vector<int>> a(3,vector<int>(3));
	map<int,pair<int,int>> m;
	
	for(int i=0;i<3;i++)for(int j=0;j<3;j++){
		cin>>a[i][j];
	
	}
	int n;
	cin>>n;
	vector<int> b(n);
	vector<vector<int>> bingo(3,vector<int>(3));
	for(int loop=0;loop<n;loop++){
		cin>>b[loop];
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(b[loop]==a[i][j]){
					bingo[i][j]=1;
				}
			}
		}
	}
	int found=0;
	for(int i=0;i<3;i++){
		int c=1;
		for(int j=0;j<3;j++)c&=bingo[i][j];
		if(c){
			found=1;
			break;
		}
		c=1;
		for(int j=0;j<3;j++){
			c&=bingo[j][i];
		}
		if(c){
			found=1;
			break;
		}
		c=1;
	}
	int c=1;
	for(int i=0;i<3;i++)c&=bingo[i][i];
	if(c)found=1;
	c=1;
	for(int i=0;i<3;i++)c&=bingo[i][2-i];
	if(c)found=1;
	if(found){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>


using namespace std;


static const int MAX = 100000;

vector< pair<int, int> > graph[MAX];


vector<int> bfs(int start)
{
    vector<int> d(MAX, 0);
    vector<bool> discovered(MAX, false);
    queue<int> visiting;


    visiting.push(start);
    discovered[start] = true;

    while (!visiting.empty()) {
        int now = visiting.front();
        visiting.pop();

        for (auto it = graph[now].begin(); it != graph[now].end(); ++it) {
            if (!discovered[(*it).first]) {
                discovered[(*it).first] = true;
                visiting.push((*it).first);
                d[(*it).first] = d[now] + (*it).second;
            }
        }
    }

    return d;
}


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

    for (int i = 0; i < n - 1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        graph[s].push_back(make_pair(t, w));
        graph[t].push_back(make_pair(s, w));
    }

    vector<int> d = bfs(0);
    int x = distance(d.begin(), max_element(d.begin(), d.end()));

    d = bfs(x);
    int diameter = *max_element(d.begin(), d.end());
    cout << diameter << endl;

    return 0;
}



Measured memory_bytes: 10160
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@jit
def main(n, d, x, a):
  ans = n + x
  for i in a:
    ans += (d-1)//i
  return ans

n,d,x,*a = map(int, read().split())
print(main(n,d,x,a))

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);
  bool b = false;
  for(int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  for(int i = 0; i < M; i++) {
    cin >> y.at(i);
  }  
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  for(int i = X+1; i < Y; i++) {
    if(i > x.at(N-1) && i <= y.at(0)) {
      b = true;
      break;
    }
  }
  if(b == true) {
    cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    ll K , N;
    cin >> K >> N;
    vector<ll> vec(N);
    for (ll i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    ll min=1000000;
    for (ll i = 0; i < N; i++){
        ll d;
        if(i==N-1){
            d=vec.at(N-1)-vec.at(0);
        }
        else d=K-(vec.at(i+1)-vec.at(i));
        if(d<min){
            min=d;
        }
        
        
    }

    cout << min <<endl;
    
}

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

char s [5];

int main (){
scanf ("%s",&s);
	if ( s[0] == s[1] && s[1]== s[2] ) 
      puts ("Yes");
	else if ( s[1]== s[2] && s[2]== s[3] ) 
      puts ("Yes");
	else 
      puts ("No");
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int num;
	double w, h;

	while(scanf("%d, %lf, %lf", &num, &w, &h)!=EOF)  {
		if(w/(h*h)>=25)
			cout << num << endl;
	}

	return 0;

}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int A, B;
    cin>>A>>B;

    cout<<max(0, A - 2 * B)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
        public static void main(String[] args){
                Scanner scanner=new Scanner(System.in);
                int n=scanner.nextInt();
                int k=scanner.nextInt();
                int[] l=new int[n];
                for(int i=0;i<n;i++){
                        l[i]=scanner.nextInt();
                }
                int tmp=0;
                for(int i=1;i<n;i++){
                        for(int j=i;j>0;j--){
                                if(l[j-1]<l[j]){
                                        tmp=l[j-1];                                        l[j-1]=l[j];
                                        l[j]=tmp;
                                }else{
                                        break;
                                }
                        }
                }

                int sum=0;
                for(int i=0;i<k;i++){
                        sum+=l[i];
                }
                System.out.println(sum);
        }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int N = 220000;
int num, n, x, y, a, b, c;
ll p[N], q[N], r[N], s[N], ans; 
int main(){
	scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	for (int i=1; i<=a; i++) scanf("%lld", &p[i]);
	for (int i=1; i<=b; i++) scanf("%lld", &q[i]);
	for (int i=1; i<=c; i++) scanf("%lld", &r[i]);
	sort(p+1, p+a+1, greater<int>());
	sort(q+1, q+b+1, greater<int>());
	sort(r+1, r+c+1, greater<int>());
	for (int i=1; i<=x; i++){
		s[++num] = p[i];
		ans += p[i]; 
	}
	for (int i=1; i<=y; i++){
		s[++num] = q[i];
		ans += q[i];
	}
	sort(s+1, s+num+1);
	for (int i=1; i<=min(c, x+y); i++){
		if (r[i] < s[i]) break;
		else ans = ans - s[i] + r[i];
	}
	printf("%lld", ans);
	return 0;
} 

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

int main() {
  int N;
  cin >> N;
  
  int d;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> d;
    vec.at(i) = d;
  }

  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  int ans = 1;
  for(int i = 1; i < N; i++){    
    if(vec.at(i-1) > vec.at(i)){
      ans++;    
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
def get_ln_int_inputs():
    return list(map(int, input().split()))


def main():
    input()
    rates = get_ln_int_inputs()

    colors = [0] * 8
    free_colors = 0
    for rate in rates:
        if rate >= 3200:
            free_colors += 1
        else:
            colors[rate // 400] = 1
    fixed_colors = sum(colors)

    print(str(max(fixed_colors, 1)) + " " + str(max(fixed_colors + free_colors, 1)))


main()

Measured memory_bytes: 3060
import bisect

n,q = list(map(int, input().split()))

list_xst = []
for _ in range(n):
    s,t,x = list(map(int, input().split()))
    list_xst.append([x, s-x, t-x])

list_xst.sort(key=lambda l:l[0])

list_d = [int(input()) for _ in range(q)]

retn = [-1] * q
jmp = [-1] * q

for x,s,t in list_xst:
    i = bisect.bisect_left(list_d, s)
    tt = bisect.bisect_left(list_d, t)
    while i < tt:
        if (jmp[i] != -1):
            i = jmp[i]
        else:
            retn[i] = x
            jmp[i] = tt
            i += 1

print(*retn, sep="\n")

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


void MakePost(vector<int> &post, vector<int> pre, vector<int> in, int start, int end, int* posi)
{
    int mid;
    int root;

    if (start < end) {
        root = pre[*posi];
        mid = distance(in.begin(), find(in.begin(), in.end(), root));
        ++(*posi);
        MakePost(post, pre, in, start, mid, posi);
        MakePost(post, pre, in, mid+1, end, posi);
        post.push_back(root);
    }

    return;
}

int main(void)
{
    int i;
    int key;
    int num;
    int posi = 0;
    vector<int> inorder;
    vector<int> preorder;
    vector<int> postorder;

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%d", &key);
        preorder.push_back(key);
    }
    for (i = 0; i < num; i++) {
        scanf("%d", &key);
        inorder.push_back(key);
    }

    MakePost(postorder, preorder, inorder, 0, preorder.size(), &posi);
    printf("%d", postorder[0]);
    for (i = 1; i < num; i++) {
        printf(" %d", postorder[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 yy
#define y1 Yy
#define yn YY
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

int n;
long long a[100005],b[100005],res;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lld %lld",a+i,b+i);
    for(int i=n-1;i>=0;i--){
        long long curr=a[i]+res;
        if(curr%b[i]!=0)curr+=b[i]-curr%b[i];
        res=curr-a[i];
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 1920
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if len(set(s)) == 1:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

    if s[0] == s[-1] and b[0] % 2 and b[-1] % 2:
        ans += k-1
    
    print(ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


Measured memory_bytes: 9836
#include <algorithm>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> x(N), y(N);
  vector<ll> xarray, yarray;
  for (ll i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    xarray.push_back(x[i]);
    yarray.push_back(y[i]);
  }
  sort(xarray.begin(), xarray.end());
  sort(yarray.begin(), yarray.end());

  ll ans = (xarray[N - 1] - xarray[0]) * (yarray[N - 1] - yarray[0]);

  for (ll xi = 0; xi < N; xi++) {
    for (ll xj = xi + 1; xj < N; xj++) {
      for (ll yi = 0; yi < N; yi++) {
        for (ll yj = yi + 1; yj < N; yj++) {
          ll lx = xarray[xi], rx = xarray[xj];
          ll ly = yarray[yi], ry = yarray[yj];

          ll count = 0;
          for (ll i = 0; i < N; i++) {
            if (lx <= x[i] && x[i] <= rx && ly <= y[i] && y[i] <= ry) {
              count++;
            }
          }
          if (count >= K)
            ans = min(ans, abs(rx - lx) * abs(ry - ly));
        }
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	lli sum=0;
	map<lli,lli> cnt;
	cnt[0]++;

	REP(i,0,n){
		lli a;
		cin>>a;
		sum+=a;
		cnt[sum]++;
	}

	lli ans=0;
	for(auto e:cnt){
		if(DEBUG)cout<<"f="<<e.first<<" s="<<e.second<<endl;
		ans += (e.second)*(e.second-1)/2;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    string c;
    cin >> c;
    cout << (c=="a"||c=="i"||c=="u"||c=="e"||c=="o"?"vowel":"consonant") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int N, K;
    cin >> N >> K;
    if ((N + 1) / 2 >= K) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll fact[200001],inv[200001],ct2[200001];

    ll power(ll a, ll b)    //a is base, b is exponent
    {
        if(b==0)
            return 1;
        if(b==1)
            return a;
        if(b%2 == 1)
            return (power(a,b-1)*a)%mod;
        ll q = power(a,b/2);
        return (q*q)%mod;
    }

    void init()
    {
        fact[0]=inv[0]=1;
        for(int i=1;i<=200000;++i)
        {
            fact[i]=(fact[i-1]*i)%mod;
            inv[i]=power(fact[i],mod-2);
        }
    }

    ll ncr(int n,int r)
    {
        if(n<r)
            return 0;
        return ((fact[n]*inv[n-r])%mod*inv[r])%mod;
    }

    ll sum(ll x)
    {
        ll ans=x*(x+1)/2;
        return ans%mod;
    }


    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        init();
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,m,k,i,j,ct,sum2=0,ans=0,z,ans2=0;
            cin>>n>>m>>k;
            if(n>m)
                swap(n,m);
            sum2=0;
            for(i=1;i<=m;++i)
            {
                sum2=(sum2+sum(m-i)+sum(i-1))%mod;
            }
            sum2=(sum2*power(2,mod-2))%mod;
            for(i=1;i<=n;++i)
            {
                j=i;
                ans=(ans+((m*m)%mod*(j-i))%mod+sum2)%mod;
                for(j=i+1;j<=n;++j)
                {
                    ans=(ans+((m*m)%mod*(j-i))%mod+2*sum2)%mod;
                }
                //cout<<i<<" "<<ans<<endl;
            }
            ans=(ans*ncr(n*m-2,k-2))%mod;
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3456
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
b = [0] * (max_a + 1)
a.sort()

for i in a:
    b[i] += 1
    if b[i] == 1:
        for j in range(2*i, max_a + 1, i):
            b[j] += 2
print(b.count(1))


Measured memory_bytes: 32236
a, b, k = map(int, input().split())


if(a>=k):
    a -= k
elif(a>k and k <= a+b):
        sa = abs(a-k)
        a = 0
        b -= sa
else:
    sa = abs(a-k)
    a = 0
    b -= sa
    if b < 0:
        b = 0
print(a, b)


Measured memory_bytes: 3060
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	ll ans=inf;
	for(ll i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			ans=min(ans,abs(i-1)+abs(n/i-1));
		}
	}	
	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a,b,k,N;
	int arr[105];
	cin>>a>>N;
	for(int i=0;i<N;i++){
		cin>>k;
		arr[k]=1;
	}
	b=0;
	while(a-b>=0||a+b<=105){
		if(arr[a-b]!=1){
			cout<<a-b;
			break;
		}
		else if(arr[a+b]!=1){
			cout<<a+b;
			break;
		}
		b+=1;
	}
	

}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++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(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N, K;
    cin >> N >> K;
    vector<int > p(N);
    REP(i, N) cin >> p[i];
    sort(ALL(p));
    int ans = 0;
    REP(i, K) ans += p[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
// x x x x x x
int main() {
    int n;
    cin >> n;
    vector<int> x(n+1), y(n+1);
    for(int i = 1; i <= n; ++i) {
        cin >> x[i];
    }
    y = x;
    sort(all(x));
    int left = x[n/2];
    int right = x[n/2+1];
    for(int i = 1; i <= n; ++i) {
        if(y[i] < right) cout << right << endl;
        else cout << left << endl;
    }
    return 0;
}

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


int main(){
	int H,W;
	int i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(W==0){break;}
		for(i=0;i<W;i++){printf("#");}
		printf("\n");
		for(i=0;i<H-2;i++){
			printf("#");
			for(j=0;j<W-2;j++){printf(".");}
			printf("#\n");
		}
		for(i=0;i<W;i++){printf("#");}
		printf("\n\n");
	}
	return 0;
}

Measured memory_bytes: 588
import java.util.*;

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

  static void solve(Scanner sc) {
    int n = sc.nextInt();
    int[] S = new int[n + 1];// 番兵分の要素を追加で
    for (int i = 0; i < n; i++) {
      S[i] = sc.nextInt();
    }

    int q = sc.nextInt();
    int sum = 0;
    for (int i = 0; i < q; i++) {
      if(linearSearch(S, n, sc.nextInt())) sum++;
    }

    System.out.println(sum);
  }

  static boolean linearSearch(int[] arr, int target, int key) {
    // 「番兵にたどり着くまで」と考えて、while だけでループと比較を表現できる
    int i = 0;
    arr[target] = key;
    while (arr[i] != key) i++;
    return i != target;
	}
}



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

using namespace std;

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

int main() {
    int n;
    cin >> n;
    vector<int> b(n-1);
    rep(i, n-1) cin >> b[i];
    int left = b[0], right = b[0];
    ll ans = 0;
    rep(i, n-1){
        right = b[i];
        left = min(b[i], left);
        ans += left;
        left = right;
    }
    cout << ans + left << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  long x,y,z,s[8][1000],sum,ans=0;
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%ld %ld %ld",&x,&y,&z);
    s[0][i]=x+y+z;
    s[1][i]=x+y-z;
    s[2][i]=x-y+z;
    s[3][i]=x-y-z;
    s[4][i]=-1*x+y+z;
    s[5][i]=-1*x+y-z;
    s[6][i]=-1*x-y+z;
    s[7][i]=-1*x-y-z;
  }
  for(int i=0;i<8;i++)
    sort(s[i],s[i]+n);
  for(int i=0;i<8;i++){
    sum=0;
    for(int j=n-1;j>=n-m;j--)
      sum+=s[i][j];
    ans=max(ans,sum);
  }
  printf("%ld\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,b,s,i,ans=0;

	scanf("%d %d",&a,&b);

	if(b>=100){
		s=a*1000+b;
	}else if(b>=10){
		s=a*100+b;
	}else{
		s=a*10+b;
	}

	for(i=1;i*i<=s;i++){
		if(i*i==s){
			ans=1;
			break;
		}
	}

	if(ans==1){
		printf("Yes");
	}else{
		printf("No");
	}

	return 0;

}

Measured memory_bytes: 128
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,x,ze=0,fi=0;
  cin>>n>>m>>x;
  int a;
  rep(i,m){
    cin>>a;
    if(a<x){
      ze++;
    }
    else{
      fi++;
    }
  }
  cout<<(fi<ze ? fi : ze)<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
 int x,y;
  int res;
  scanf("%d%d",&x,&y);
  int sum=0;
  
  for(int i=1;i<999;i++){
    sum+=i;
    if(sum-x==sum-y+1+i){
      
     res=sum-x; 
    }
  }
	printf("%d\n",res);






return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 			1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl 			'\n'
#define inf 			1e18
#define fi 				first
#define se 				second

int XX[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int YY[8]={+1, 0, -1, +1, -1, +1, 0, -1};
int dx[4]={-1,1,0,0};
int dy[4]={0,0,1,-1};


signed main() {

	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	int x,k,d;
	cin>>x>>k>>d;

	x=abs(x);

	int straight = min(k,x/d);

	k-=straight;
	x-=straight*d;

	if(k%2==0){
		cout<<x<<endl;
	}else{
		cout<<d-x<<endl;
	}


	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int a,b;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>a>>b;
    
    cout<<max(a+b,max(a-b,a*b))<<"\n";
    
    
    return 0;
}


Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;

ll GCD(ll a,ll b){

    if(a>b){

        return GCD(b,a);

    }

    else{

    ll r=b%a;

    while(r!=0){

        b=a;

        a=r;

        r=b%a;

    }

    return a;

    }

}

int main(){
    
    ll N,A[100010];
    cin>>N;
    rep(i,0,N)cin>>A[i];
    
    ll gcd=GCD(A[0],A[1]);
    rep(i,2,N){
        gcd=GCD(gcd,A[i]);
    }
    cout<<gcd<<endl;
}






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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,i,j;
	string s;
	cin>>n>>s;
	int lastR = -1;
	for(i=0;i<n;i++){
		if(s[i] == 'R'){lastR = i;}
	}
	if(lastR == -1 || lastR == 0){printf("0\n"); return 0;}
	int minim = 0;
	for(i=lastR;i>=0;i--){
		if(s[i] == 'W'){minim++;}
	}

	stack<int> qr, qw;
	for(i=0;i<n;i++){
		if(s[i] == 'R'){
			// printf("r push %d\n",i);
			qr.push(i);
		}
	}

	for(i=n-1;i>=0;i--){
		if(s[i] == 'W'){
			// printf("w push %d\n",i);
			qw.push(i);
		}
	}

	int cnt = 0;
	if(qw.size() == 0){printf("0\n"); return 0;}
	while(qr.size() > 0 && qw.size() > 0) {

		int frontR = qr.top(); qr.pop();
		int frontW = qw.top(); qw.pop();
		if(frontR > frontW){
			cnt++;
			//swap position
			swap(s[frontW], s[frontR]);
			// cout<<s<<endl;
			// qr.push(frontW);
			// qw.push(frontR);
			// printf("push %d %d\n",frontW, frontR);
		}else{
			break;
		}
	}

	printf("%d\n",min(minim, cnt));
	return 0;
};

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

int main(){
  int n, d;
  cin >> n >> d;
  
  vector<vector<int>> coord(n, vector<int>(d));
  
  for (int i = 0; i < n; i++){
    for (int j = 0; j < d; j++) {
      cin >> coord.at(i).at(j);
    }
  }
  
  int count = 0;
  
  for (int i = 0; i < n-1; i++) {
    for (int j = i + 1; j < n; j++) {
      int diff2 = 0;
      for (int k = 0; k < d; k++) {
        diff2 += (coord.at(i).at(k) - coord.at(j).at(k)) * (coord.at(i).at(k) - coord.at(j).at(k));
      }
      for (int l = 1; l < sqrt(diff2) + 0.5; l++) {
        if (diff2 == l * l) {
          count++;
        }
      }
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) x[i] = sc.nextInt();
        long[][][] dp = new long[n + 1][n + 1][50 * n + 1];
        dp[0][0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= i; j++) {
                for (int k = 0; k <= 50 * i; k++) {
                    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                    dp[i + 1][j][k] += dp[i][j][k];
                }
            }
        }
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += dp[n][i][a * i];
        }
        System.out.println(ans);
    }
}

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

int N, K;
ll a[100010];
ll b[100010], c[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < N; i++) {
    if (i == 0) b[i] = a[i];
    else b[i] = b[i - 1] + a[i];
  }
  for (int i = 0; i < N; i++) {
    if (i == 0) c[i] = a[i] > 0 ? a[i] : 0;
    else c[i] = c[i - 1] + (a[i] > 0 ? a[i] : 0);
  }
  ll ans = 0;
  for (int i = 0; i + K - 1 < N; i++) {
    ll sum = 0;
    if (i != 0) sum += c[i - 1];
    ll tmp = b[i + K - 1] - (i != 0 ? b[i - 1] : 0);
    sum += c[N - 1] - c[i + K - 1];
    ans = max(ans, max(sum, sum + tmp));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    ll int n,W;
    cin>>n>>W;
    vector<ll int> wt(n),v(n),dp(W+1,0);
    for(int i=0;i<n;i++)
        cin>>wt[i]>>v[i];
    for(int i=0;i<n;i++)
    {
        for(int j=W-wt[i];j>=0;j--)
            dp[j+wt[i]]=max(dp[j+wt[i]],dp[j]+v[i]);
    }
    cout<<dp[W];
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}



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


int main(){

    int N, A[200000];
    cin >> N;
    for( int i = 0; i < N; i++ ) cin >> A[i];


    for( int i = 0; i < N; i++ ) A[i] -= i+1;

    sort( A, A+N );
    
    long sum = 0;
    int b = A[N/2];
    for( int i = 0; i < N; i++ ) sum += abs( A[i] - b );
    
    cout << sum << endl;

    return 0;

}

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



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

int main() {
    long long n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    long long ans = 4;
    ans += ceil((double)n / min({a, b, c, d, e}));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int a[100005];
int n, m, sum;
void solve(int n, int m, int sum) {
  if (m == 0) {
    int all;
    if (sum == 1e9) {
      all = sum / n - 1;

    } else {
      all = sum + 1;
    }
    for (int i = 0; i < n; ++i) {
      a[i] = all;
    }
  } else {
    if (sum - n + m > 0) {
      for (int i = 0; i < n - m; ++i) {
        a[i] = 1;
      }
      a[n - m] = sum - n + m;
      for (int i = n - m + 1; i < n; ++i) {
        a[i] = sum;
      }
    } else {
      if (sum > 1) {
        solve(m + 1, m, sum);
        for (int i = m + 1; i < n; ++i) {
          a[i] = sum + 1;
        }
      } else {
        for (int i = 0; i < m; ++i) {
          a[i] = 1;
        }
        for (int i = m; i < n; ++i) {
          a[i] = 2;
        }
      }
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &sum);
  solve(n, m, sum);
  printf("%d", a[0]);
  for (int i = 1; i < n; ++i) {
    printf(" %d", a[i]);
  }
  printf("\n");
  return 0;
}


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

using namespace std;
using ll = long long;

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

bool isPalindrome(string s) {
  int n = s.size();
  bool res = true;
  rep(i, n) {
    if (s[i] != s[n - i - 1]) res = false;
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();

  bool ans = isPalindrome(s.substr(0, n / 2)) &&
             isPalindrome(s.substr(n / 2 + 1, n / 2)) && isPalindrome(s);
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
inf = 10**10
n,m,l = map(int,input().split())

def warshall_floyd(d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
    return d

G = [[inf] * n for _ in range(n)] #重み付きグラフ
for i in range(n):
    G[i][i] = 0
for _ in range(m):
    a,b,c = map(int,input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c

G = warshall_floyd(G)
P = [[0] * n for _ in range(n)]

for i in range(n):
    for j in range(n):
        if i == j:
            P[i][j] = 0
        elif G[i][j] <= l:
            P[i][j] = 1
        else:
            P[i][j] = inf

p = warshall_floyd(P)
q = int(input())

for _ in range(q):
    s,t = map(int,input().split())
    ans = p[s-1][t-1]-1
    print(ans if ans <= 10**9 else -1)

Measured memory_bytes: 59352
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int L;
    cin >> L;
    double ans = 0;

    repd(i, 1, L) {
        repd(j, 1, L - i) {
            chmax(ans, (double)i * (double)j * (double)(L - i - j));
        }
    }

    double s = (double)L / 3.0;
    ans = s * s * s;

    printf("%.7lf", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,t,A[100001];
int pre;
int solve(){
  int mx=A[n-1],mxs=0;
  for(int i=n-2;i>=0;i--){
    mxs=max(mxs,mx-A[i]);
    mx=max(mx,A[i]);
  }
  if(pre>mxs)return 0;
  if(mxs==0)return 0;
  pre=mxs;

  
  int num=A[n-1];
  vector<int>pos,minus;
  pos.push_back(n-1);
  for(int i=n-2;i>=0;i--){
    if(num-A[i]==mxs){
      for(int j=0;j<(int)pos.size();j++)minus.push_back(pos[j]);
      pos.clear();
    }
    if(num==A[i]) pos.push_back(A[i]);
    else if(num<A[i])pos.clear(),pos.push_back(i),num=A[i];
  }
  for(int i=0;i<minus.size();i++) A[minus[i]]--;
  return minus.size();
}

int main(){
   cin>>n>>t;
  for(int i=0;i<n;i++) cin>>A[i];
  int res=0,ans=0;
  while((res=solve()))ans+=res;
  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<string>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	string s = "CODEFESTIVAL2016";
	string S;
	cin >> S;
	ll cnt = 0;
	for (ll i = 0; i < s.size(); i++) {
		if (s[i] != S[i])
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256