akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll pref[100000];
int main()
{
   ll h,w,d;
   cin >> h >> w >> d;
   ll ara[h+10][w+10];
      map<ll,pair<ll,ll> > mp;
   for(ll i=1; i<=h; i++)
   {
       for(ll j=1; j<=w; j++)
       {
           cin >> ara[i][j] ;
           mp[ara[i][j]] = {i,j} ;
       }
   }


   for(ll i=d+1; i<=h*w; i++)
   {
     ll val = abs(mp[i].first-mp[i-d].first) ;
     ll val2 = abs(mp[i].second-mp[i-d].second) ;
     pref[i] = pref[i-d] + val+val2 ;
   }


   ll q;
   cin >> q;
   while(q--)
   {
       ll lf , rt ;
       cin >> lf >>  rt ;

       // cout << endl;
       cout << pref[rt] - pref[lf] << endl;

   }


}


Measured memory_bytes: 10640
n, m = map(int, input().split())
c = list(map(int, input().split()))

DP = [[100000 for _ in range(n+1)] for _ in range(m+1)]
DP[0][0] = 0

for i in range(m):
    for j in range(n+1):
        if(j >= c[i]):
            DP[i+1][j] = min(DP[i][j], DP[i+1][j-c[i]]+1)
        else:
            DP[i+1][j] = DP[i][j]

print(DP[m][n])


Measured memory_bytes: 43952
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int con = 0;
		for (int i = 1; i < N+1; i++) {

			if (i != sc.nextInt()) {
				con++;
			}
		}

		if (con == 2 || con==0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}

Measured memory_bytes: 35516
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    max_height = A[0]
    step_sum = 0
    for Ai in A:
        if Ai>=max_height:
            max_height = Ai
        else:
            step_sum = step_sum + (max_height - Ai)
    print(step_sum)
resolve()

Measured memory_bytes: 94116
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll x, k, d, x1, x2, n, ans = 1e16;
	cin >> x >> k >> d;
	x = abs(x);
	n = x / d;
	if(n >= k)
	{
		cout << x - d * k;
		return 0;
	}
	else
	{
		x1 = x - d * n;
		x2 = x1 - d;
		x2 = abs(x2);
		if(x1 <= x2)
		{
			if((k - n) % 2 == 0)
			{
				cout << x1;
				return 0;
			}
			else
			{
				ans = min(ans, min(x2, x1 + d));
			}
		}
		else
		{
			if((k - n - 1) % 2 == 0)
			{
				cout << x2;
				return 0;
			}
			else
			{
				ans = min(ans, min(x1, abs(x2 + d)));
			}
		}
		cout << ans;
	}
}

Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
  int n,sum,max,min,s;
  while(cin>>n){
    if(!n)break;
    min = 500;
    max = 0;
    for(;n>0;n--){
      sum = 0;
      for(int i=0;i<5;i++){
	cin>>s;
	sum+=s;
      }
      sum>max?max=sum:max;
      sum<min?min=sum:min;
    }
    cout<<max<<" "<<min<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.*;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List list = new List();
        
        int n = Integer.parseInt(br.readLine());
        
        String l;
        char query;
        int x, d;
        for (int i = 0; i < n; i++) {
            l = br.readLine();
            query = l.charAt(0);
            switch (query) {
                case '0':
                    x = Integer.parseInt(l.substring(2));
                    list.insert(x);
                    break;
                case '1':
                    d = Integer.parseInt(l.substring(2));
                    list.move(d);
                    break;
                case '2':
                    list.erase();
                    break;
            }
            //System.out.println("cursor: " + list.pointed.num);
            //list.printAll();
            //System.out.println("---");
        }
        list.printAll();
    }
}

class List {
    Node pointed;
    Node top, end;
    
    List() {
        top = new Node(Integer.MAX_VALUE, null, end);
        end = new Node(Integer.MAX_VALUE, top, null);
        pointed = end;
    }
    
    void insert(int x) {
        Node new_node = new Node(x, pointed.left, pointed);
        pointed.left.right = new_node;
        pointed.left = new_node;
        pointed = new_node;
    }
    
    void move(int d) {
        if (d > 0) {
            while (d > 0) {
                pointed = pointed.right;
                d--;
            }
        } else {
            while (d < 0) {
                pointed = pointed.left;
                d++;
            }
        }
    }
    
    void erase() {
        pointed.left.right = pointed.right;
        pointed.right.left = pointed.left;
        pointed = pointed.right;
    }
    
    void printAll() {
        Node now = top.right;
        while (now.right != null) {
            System.out.println(now.num);
            now = now.right;
        }
    }
}

class Node {
    int num;
    Node left, right;
    
    Node(int n, Node l, Node r) {
        num = n;
        left = l;
        right = r;
    }
}
    


Measured memory_bytes: 90100
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
#include<atcoder/all>
 
using namespace std;
using namespace atcoder;
 
/* template */
 
using ll = long long;
 
void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
 
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;
}
 
template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=3.14159265358979323846;
 
 
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};
 
/* template */

ll op(ll a, ll b){
    return max(a,b);
}

ll e(){ return -1; }

ll target;

bool f(ll v){
    return v<target;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    segtree<ll, op, e> seg(n);
    rep(i,0,n){
        ll a; cin >> a;
        seg.set(i,a);
    }
    rep(_,0,q){
        int t; cin >> t;
        if(t==1){
            int x; ll v; cin >> x >> v; x--;
            seg.set(x,v);
        }
        else if(t==2){
            int l,r; cin >> l >> r; l--;
            cout << seg.prod(l,r) << endl;
        }
        else{
            int p; 
            cin >> p >> target; p--;
            cout << seg.max_right<f>(p)+1 << endl;
        }
    }
}

Measured memory_bytes: 9008
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

int main() {
  int n;
  while(cin >> n, n) {
    vector<P> p(n);
    REP(i, n) {
      double x, y;
      cin >> x >> y;
      p[i] = P(x,y);
    }
    P now(0,0);
    double ans = 0;
    REP(i,n) {
      int next = 0;
      for (int i=1; i<p.size(); ++i) {
        int c = ccw(now, p[i], p[next]);
        if (c == -1 || c == -2) {
          next = i;
        }
      }
      ans += abs(p[next]-now);
      now = p[next];
      p.erase(p.begin()+next);
    }
    printf("%.1f\n",ans);
  }
}

Measured memory_bytes: 0
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[input().split() for l in range(n)]
ans=0

for j in range(n):
    result=0
    for i in range(m):
        result+=int(a[j][i])*b[i]
    if result+c>0:
        ans+=1
print(ans)

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

int main(){

  int N,M;
  cin >> N >> M;
  long long x[N],y[N],z[N];
  long long sum[N];
  long long ans,num=0;
  rep(i,N) cin >> x[i] >> y[i] >> z[i];
  rep(i,N) sum[i] = x[i] + y[i] + z[i];
  sort(sum, sum+N, greater<long long>());
  rep(i,M) num+=sum[i];
  ans = num;
  num = 0;
  rep(i,N) sum[i] = x[i] + y[i] - z[i];
  sort(sum, sum+N, greater<long long>());
  rep(i,M) num+=sum[i];
  ans = max(ans,num);
  num = 0;
  rep(i,N) sum[i] = x[i] - y[i] + z[i];
  sort(sum, sum+N, greater<long long>());
  rep(i,M) num+=sum[i];
  ans = max(ans,num);
  num = 0;
  rep(i,N) sum[i] = -x[i] + y[i] + z[i];
  sort(sum, sum+N, greater<long long>());
  rep(i,M) num+=sum[i];
  ans = max(ans,num);
  num = 0;
  rep(i,N) sum[i] = x[i] - y[i] - z[i];
  sort(sum, sum+N, greater<long long>());
  rep(i,M) num+=sum[i];
  ans = max(ans,num);
  num = 0;
  rep(i,N) sum[i] = -x[i] + y[i] - z[i];
  sort(sum, sum+N, greater<long long>());
  rep(i,M) num+=sum[i];
  ans = max(ans,num);
  num = 0;
  rep(i,N) sum[i] = -x[i] - y[i] + z[i];
  sort(sum, sum+N, greater<long long>());
  rep(i,M) num+=sum[i];
  ans = max(ans,num);
  num = 0;
  rep(i,N) sum[i] = -x[i] - y[i] - z[i];
  sort(sum, sum+N, greater<long long>());
  rep(i,M) num+=sum[i];
  ans = max(ans,num);
  cout << ans << endl;
  return 0;
}


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();

      if ( a < b && b < c) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
      sc.close();
  }
}


Measured memory_bytes: 26144
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

	vector<int>vec(3);
	vec[0] = A + B;
	vec[1] = A - B;
	vec[2] = A * B;

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

	cout << vec[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S,T;
  cin >> S >> T;
  int ans=0;
  for (int i = 0; i < S.size();i++)
  {
    if(S.at(i)!=T.at(i)){
      ans++;
    }
  }
  
  cout << ans << endl;

}






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

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    bool ans=true;
    string S;
    cin >> S;
    rep(i,S.length()){
        if(i%2==0){
            if(S[i]=='L')ans=false;
        }
        if(i%2==1){
            if(S[i]=='R')ans=false;
        }
    }
    if(ans)cout << "Yes";
    else cout << "No";
    


}

/*



 */



Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in map(int, input().split())]

cnt = 0
for i in range(len(a)):
    if a[i] < 0:
       cnt += 1

b = []
for j in range(len(a)):
    b.append(abs(a[j]))

if cnt % 2 != 0:
        b.append(-2*min(b))

print(sum(b))

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

// input
int A, B, C;


void input() {
    cin >> A >> B >> C;
}


int main() {
    input();
    int ans;
    if (A == B) ans = C;
    else if (A == C) ans = B;
    else ans = A;
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

typedef unsigned long long ull;

ull pow2(ull m, ull n, const int c) {
  ull ans = 1;

  while (n > 1) {
    if (n & 1) ans = ans * m % c;
    n >>= 1;
    m = m * m % c;
  }

  return ans * m % c;
}

int main() {
  ull m, n; cin >> m >> n;

  cout << pow2(m, n, 1000000007) << endl;
}

Measured memory_bytes: 1152
def bfs(g, n):
	tovisit = []
	for i in range(0, n):
		tovisit.append(i)
	queue = []
	tovisit.remove(0)
	queue.append([0, tovisit])
	cnt = 0

	while queue != []:
		status = queue.pop(0)
		now = status[0]
		currenttovisit = status[1]
		if currenttovisit == []: cnt = cnt + 1
		else:
			for i in range(0, n):
				newtovisit = []
				for j in range(0, len(currenttovisit)):
					newtovisit.append(currenttovisit[j])
				if i in currenttovisit and graph[now][i]:
					newtovisit.remove(i)
					queue.append([i, newtovisit])
	return cnt

N, M = map(int, raw_input().split())
graph = []
for i in range(0, N):
	arrow = []
	for j in range(0, N):
		arrow.append(False)
	graph.append(arrow)

for i in range(0, M):
	a, b = map(int, raw_input().split())
	graph[a-1][b-1] = True
	graph[b-1][a-1] = True

print bfs(graph, N)

Measured memory_bytes: 3716
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
        }
        
        System.out.print(list.get(n-1));
        for(int i = n-2; i >= 0; i--) System.out.print(" " + list.get(i));
        System.out.println();
    }
}


Measured memory_bytes: 26104
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  int ball[3] = {1,0,0};
  string str;
  while(getline(cin,str)){
    swap(ball[str[0]-'A'],ball[str[2]-'A']);
  }
  rep(i,3)if(ball[i])cout<<(char)(i+'A')<<endl;
  return 0;
}

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

using namespace std;

const int P = 998244353;

long long power(long long x, long long t) {
	long long ret = 1;
	for(; t; t >>= 1, x = x * x % P) {
		if(t & 1) {
			ret = ret * x % P;
		}
	}
	return ret;
}

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

	int n;
	cin >> n;

	int m = 1000001;

	vector<int> mu(m);
	vector<bool> mark(m);
	vector<int> p;
	mu[1] = 1;
	for(int i = 2; i < m; ++i) {
		if(!mark[i]) {
			p.emplace_back(i);
			mu[i] = -1;
		}
		for(int j = 0; j < p.size() && i * p[j] < m; ++j) {
			mark[i * p[j]] = true;
			if(i % p[j] == 0) {
				mu[i * p[j]] = 0;
				break;
			}
			mu[i * p[j]] = -mu[i];
		}
	}

	vector<int> cnt(m);
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		cnt[a[i]] += 1;
	}

	vector<int> s(m);
	for(int i = 1; i < m; ++i) {
		int pre = 0;
		for(int j = i; j < m; j += i) {
			s[i] = (s[i] + 1LL * pre * cnt[j] % P * j % P) % P;
			s[i] = (s[i] + 1LL * cnt[j] * (cnt[j] - 1) / 2 % P * j % P * j % P) % P;
			pre = (pre + 1LL * cnt[j] * j % P) % P;
		}
	}

	int ans = 0;

	for(int d = 1; d < m; ++d) {
		int inv = power(d, P - 2);
		for(int i = 1; d * i < m; ++i) {
			ans = (ans + 1LL * mu[i] * s[d * i] % P * inv % P + P) % P;	
		}
	}

	cout << ans << '\n';

	return 0;
}


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

#define MOD 1000000007
#define SIZE_1 2000005
#define SIZE_2 1000000
#define INT_BITS 32
typedef long long int ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;


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

    int a, b, c;
    cin >> a >> b >> c;

    cout << c << " " << a << " " << b;

    return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

N = int(input())
ans = 0
for i in range(1,N+1,2):
    if len(make_divisors(i)) == 8:
        ans += 1
print(ans)


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeMaximum(Node x){

  while(x->right!=NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeSuccessor(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right==NIL)
    y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL) x=y->left;
  else x=y->right;

  if(x!=NIL) x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;

  if(y!=z) z->key=y->key;
  free(y);
}

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

  z = 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;
    }
  }


}

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


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

 
  return 0;
}



Measured memory_bytes: 25200
#include<bits/stdc++.h>
using namespace std;
#define int long
signed main(){
  int n;
  string s;
  cin>>n>>s;
  vector<vector<int>> ind(10);
  for(int i=0;i<n;++i)ind[s[i]-'0'].push_back(i);
  int res=n*(n-1)*(n-2)/6;
  for(int i=0;i<1000;++i){
    int a=i/100,b=i/10%10,c=i%10;
    int pat=0;
    vector<int> p(ind[a].size(),0),q(ind[b].size(),0);
    if(min({ind[a].size(),ind[b].size(),ind[c].size()})==0)continue;
    if(*(ind[a].begin())>=*(ind[b].end()-1)||*(ind[b].begin())>=*(ind[c].end()-1))continue;
    for(int j=0;j<ind[b].size();++j){
      q[j] = ind[c].end() - upper_bound(ind[c].begin(),ind[c].end(),ind[b][j]);
    }
    for(int j=0;j<ind[a].size();++j){
      auto itr = upper_bound(ind[b].begin(),ind[b].end(),ind[a][j]);
      if(itr==ind[b].end())p[j]=-1;
      else {
        p[j] = ind[b].end() - itr;
      }
    }
    for(int j=ind[b].size()-1;j>0;--j)q[j-1]+=q[j];
    for(int j=0;j<ind[a].size();++j){
      if(p[j]>0)p[j] = q[ind[b].size()-p[j]];
      else p[j]=-1;
    }
    for(int j=0;j<ind[a].size();++j){
      pat += (p[j]>0?p[j]:0);
    }
    if(pat>1)res-=pat-1;
  }
  cout<<res;
}

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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';


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

ll t,i,x,j,y,z,k=0,n;

cin>>n;
  
if(n&1)	return cout<<0,0;
n=n/2;
j=0;
i=5;

while(n/i>0){
	j+=n/i;
	i*=5;
}

  
ce(j)
}
/*

124999999999999995
1 2 3 4 5 6 7 8
1 3 5 7 9
2 4 6 8 10 12 14 16 18 20 ... 100 

1 2 3 4 5 6 7 8 9 10 ...... 50


*/


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] aArray=new int[n];
        for(int i=0;i<n;i++){
            aArray[i]=scanner.nextInt();
        }
        int q=scanner.nextInt();
        int[] qArray=new int[q];
        for(int i=0;i<q;i++){
            qArray[i]=scanner.nextInt();
        }
        boolean[] booleans=new boolean[2000*20];
        int[] result=new int[(int)Math.pow(2,n)];
        for(int i=0;i<n;i++){
            for(int j=0;j<result.length;j++){
                int r=(int)Math.pow(2,n-i-1);
                if(j/r%2==0){
                    result[j]+=aArray[i];
                }
            }
        }
        Arrays.stream(result).forEach((i)->{
            booleans[i]=true;
        });
        for(int i=0;i<qArray.length;i++){
            if(booleans[qArray[i]]){
                System.out.println("yes");
            }else{
                System.out.println("no");
            }
        }



    }

}



Measured memory_bytes: 36920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[102],b[102];
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	ll ans=0;
	for(int i=1;i<n;i++){
		a[i]=a[i]+a[i-1];
	}
	for(int i=0;i<n;i++){
		ll sum=a[i];
		for(int j=i;j<n;j++){
			sum+=b[j];
		}
		ans=max(ans,sum);
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

int main() {
    uint32_t N, C0(0), C1(0),C2(0),C3(0);
    cin >> N;
    map<string, uint32_t>S;

    for (uint32_t i = 0; i < N; ++i)
    {
        string Si;
        cin >> Si;
        S[Si]++;
    }

    cout << "AC x "  << S["AC"] <<endl;
    cout << "WA x "  << S["WA"] << endl;
    cout << "TLE x " << S["TLE"] << endl;
    cout << "RE x "  << S["RE"] << endl;


	return 0;
}



Measured memory_bytes: 3196
// ABC047 B - すぬけ君の塗り絵 2 イージー
#include <stdio.h>

int main(void)
{
    int W, H, N;

    scanf("%d %d %d", &W, &H, &N);

    int S[N][3];
    int i = 0;
    for (i = 0; i < N; i++) {
        scanf("%d %d %d", &S[i][0], &S[i][1], &S[i][2]);
    }

    int xStart = 0, xEnd = W, yStart = 0, yEnd = H;
    for (i = 0; i < N; i++) {
        switch (S[i][2]) {
        case 1:
            if (xStart < S[i][0]) {
                xStart = S[i][0];
            }
            break;
        case 2:
            if (xEnd > S[i][0]) {
                xEnd = S[i][0];
            }
            break;
        case 3:
            if (yStart < S[i][1]) {
                yStart = S[i][1];
            }
            break;
        case 4:
            if (yEnd > S[i][1]) {
                yEnd = S[i][1];
            }
            break;
        default:
            break;
        }
    }
    
    int result = (xEnd - xStart) * (yEnd - yStart);
    if (xEnd <= xStart || yEnd <= yStart) {
        result = 0;
    }

    printf("%d\n", result);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1000000007;

int main() {
    string S;
    cin >> S;
    for(int i=0;i<S.size();i++){
        if(S[i] == '?') S[i] = 'D';
    }
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 3752
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD1 1000000007

int main() {
  int r,g,b;
  cin >> r >> g >> b;
  if((10*g + b) % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;

}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

int main()
{ 
    std::string s;
    std::cin >> s;
    int count = 0;
    for(int i = 0; i < s.length() / 2;i++){
      int j = s.length() - 1 - i;
      if(s[i] != s[j]) count++;
    }
    std::cout << count << std::endl;
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'



ll gcd(ll a, ll b) {
  if (b > a) {
    swap(a, b);
  }
  ll r = a%b;
  while (r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}


int main() {
  ll a, b;
  cin >> a >> b;

  vl kou;
  for (ll i = 1; i*i <= a; i++) {
    if (a % i == 0) {
      ll x = i, y = a / i;
      if (b % x == 0) {
        kou.push_back(x);
      }
      if (b % y == 0) {
        kou.push_back(y);
      }
    }
  }

  sort(all(kou));
  UNIQUE(kou);
  vl ans;
  rep (i, kou.size()) {
    ll x = kou[i];
    bool flag = true;
    for (int j = 0; j < ans.size(); j++) {
      if (gcd(x, ans[j]) > 1) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans.push_back(x);
    }
  }
  
  cout << ans.size() << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int a,b,c,x,y;

  cin >> a >> b >> c >> x >> y;

  vec d(3);
  d[0] = a * x + b * y;
  d[1] = 2 * max(x,y) * c;
  d[2] = 2 * min(x,y) * c + ((x > y ? x : y) - min(x,y)) * (x > y ? a : b);

  cout << *min_element(d.begin(), d.end()) << endl;

  return 0;
}


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

typedef int64_t ll;
using namespace std;

int main() {
    // freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    vector<string> w(n);
    for (auto &i: w)
        cin >> i;

    string ans  = "Yes";
    for (int i=1; i<n; i++) {
        for (int j=0; j<n; j++) {
            if (i != j && w[i] == w[j]) {
                ans = "No";
                break;
            }
        }

        if (w[i-1][w[i-1].size()-1] != w[i][0]) {
            ans = "No";
            break;
        }
    }

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

Measured memory_bytes: 3580
#include <iostream>
#define MAX_N 10
#define MAX_D 10
using namespace std;
int n, d, x[MAX_N][MAX_D];

void solve()
{
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int norm = 0;
            for (int k = 0; k < d; k++)
            {
                int diff = abs(x[i][k] - x[j][k]);
                norm += diff * diff;
            }
            for (int k = 0; k <= norm; k++)
            {
                if (k * k == norm)
                {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
}

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

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> x[i][j];
        }
    }

    solve();
}


Measured memory_bytes: 256
// 2020-07-26 23:46:17
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

struct L {
  ll s, t, u;
  L(ll s_, ll t_, ll u_) : s(s_), t(t_), u(u_) {}
};

void answer() {
  int n, m;
  cin >> n >> m;
  vector<L> lx, ly;
  map<ll, int> mx, my;
  mx[0] = 0;
  my[0] = 0;
  rep(i, n) {
    int s, t, u;
    cin >> s >> t >> u;
    lx.emplace_back(L(s, t, u));
    mx[s] = 0;
    mx[t] = 0;
    my[u] = 0;
  }
  rep(i, m) {
    int s, t, u;
    cin >> u >> s >> t;
    ly.emplace_back(L(s, t, u));
    my[s] = 0;
    my[t] = 0;
    mx[u] = 0;
  }
  vector<ll> xs, ys;
  for(auto& p : mx) {
    p.second = xs.size();
    xs.emplace_back(p.first);
  }
  for(auto& p : my) {
    p.second = ys.size();
    ys.emplace_back(p.first);
  }
  vector<vector<int> > G(xs.size() * 2, vector<int>(ys.size() * 2, 0));
  for(const auto& l : lx) {
    int yi = my[l.u] * 2;
    REPC(xi, mx[l.s] * 2, mx[l.t] * 2) {
      G[xi][yi] = -1;
    }
  }
  for(const auto& l : ly) {
    int xi = mx[l.u] * 2;
    REPC(yi, my[l.s] * 2, my[l.t] * 2) {
      G[xi][yi] = -1;
    }
  }
  queue<P> que;
  {
    int s = mx[0] * 2 + 1;
    int t = my[0] * 2 + 1;
    que.emplace(P(s, t));
  }
  int xr = xs.size() * 2, yr = ys.size() * 2;
  {
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};
    while(!que.empty()) {
      int x, y;
      tie(x, y) = que.front(); que.pop();
      if(x == 0 || x == xr-1 || y == 0 || y == yr-1) {
        cout << "INF" << '\n';
        return;
      }
      if(G[x][y] == 1) continue;
      G[x][y] = 1;
      rep(di, 4) {
        int nx = x + dx[di], ny = y + dy[di];
        if(0 <= nx && nx < xr && 0 <= ny && ny < yr && G[nx][ny] == 0) {
          que.emplace(P(nx, ny));
        }
      }
    }
  }
  ll ans = 0;
  rep(x, xr-1) rep(y, yr-1) {
    if(G[x][y] == 1 && x % 2 && y % 2) {
      ans += (xs[(x+1)/2] - xs[x/2]) * (ys[(y+1)/2] - ys[y/2]);
    }
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 144724
#include <iostream>
#include <vector>

using namespace std;

const int Max = 1000000;
bool P[Max];

void eratos(){
	for( int i = 0;i < Max;i++ ) P[i] = true;
	P[0] = P[1] = false;
	for( int i = 2;i * i < Max;i++ ) if( P[i] ) for( int j = 2;i * j < Max;j++ ) P[i * j] = false;
}
int main(int argc, char const* argv[])
{
	eratos();
	vector<int> data;

	for( int i = 0;i < Max;i++ ) if( P[i] ) data.push_back( i );

	int n;

	while( cin >> n && n != 0 ){
		unsigned int j = 0;
		for( int i = 0;i < n;i++ ) j += data[i];
		cout << j << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
class Unionfind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)
        
    def find(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if(x == y):
            return
        
        if(self.parents[x] > self.parents[y]):
            x, y = y, x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}:{}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = Unionfind(N)

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a, b)

ans = [uf.size(i) for i in range(N)]
print(max(ans))

Measured memory_bytes: 22508
n, k =map(int,input().split())
A = [0]*(n+1)
t = 0
for _ in range(k) :
  d = int(input())
  a = list(map(int,input().split()))
  set(a)
  while t < d :
    A[a[t]] += 1
    t += 1
  t = 0
    
print(A.count(0) - 1)

Measured memory_bytes: 9216
#include<cstdio>
#include<algorithm>
using namespace std;
long long S[201000];
int n;
int Go(int b, int e) {
	int bb = b, ee = e, mid, r = b;
	while (bb <= ee) {
		mid = (bb + ee) >> 1;
		if ((S[mid] - S[b]) * 2 <= S[e] - S[b]) {
			r = mid;
			bb = mid + 1;
		}
		else ee = mid - 1;
	}
	return r;
}
long long w[4], res = 1e18;
void Calc(int p1, int p2, int p3) {
	w[0] = S[p1];
	w[1] = S[p2] - S[p1];
	w[2] = S[p3] - S[p2];
	w[3] = S[n] - S[p3];
	sort(w, w + 4);
	res = min(res, w[3] - w[0]);
}
int main() {
	int i, a;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &a);
		S[i] = S[i - 1] + a;
	}
	for (i = 1; i < n; i++) {
		int p1 = Go(0, i);
		int p2 = Go(i, n);
		Calc(p1, i, p2);
		Calc(p1, i, p2 + 1);
		Calc(p1 + 1, i, p2);
		Calc(p1 + 1, i, p2 + 1);
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 1792
N = int(input())
a = [int(x) for x in input().split()]
nums = {}
ans = 0
for i in a:
    if(i in nums):
        nums[i] += 1
    else:
        nums[i] = 1
for x in nums:
    if(x > nums[x]):
        ans += nums[x]
    elif(x == nums[x]):
        pass
    else:
        ans += nums[x]-x
print(ans)


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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int k; string s;
	cin >> k >> s;
	string also = k < s.size() ? "..." : "";
	s.resize(k, ' ');
	cout << s << also << ende;
  return 0;
}


Measured memory_bytes: 3656
#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 vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

const ll MOD = 1e9 + 7;

ll mul(ll a, ll b)
{
    return (a * b) % MOD;
}

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

    //freopen("input.txt", "r", stdin);
    
    int n, k;
    cin >> n >> k;

    vector<ll> v(n);
    vector<ll> pos, neg;

    for(auto &z : v)
    {
        cin >> z;

        if(z > 0)
            pos.pb(z);
        else if(z < 0)
            neg.pb(0-z), z = llabs(z);
    }

    if(sz(pos) + sz(neg)/2*2 >= k && (k % 2 == 0 || sz(pos) > 0))
    {
        ll ans = 1;
        sort(rall(pos));
        sort(rall(neg));
        if(k % 2 && !pos.empty())
            ans = mul(ans, pos[0]);

        vector<ll> temp;

        for(int i = k%2; i + 1 < sz(pos); i += 2)
            temp.pb((pos[i]*pos[i+1]));
        for(int i = 0; i + 1 < sz(neg); i += 2)
            temp.pb((neg[i]*neg[i+1]));
        sort(rall(temp));

        /*
        for(auto z : temp)
            cout << z << " ";
        cout << endl;
        */

        for(int i = 0; i < k/2; ++i)
            ans = mul(ans, temp[i]%MOD);
        cout << ans;
    }
    else
    {
        ll ans = 1;
        sort(all(v));

        for(int i = 0; i < k; ++i)
            ans = mul(ans, v[i]);
        ans = (MOD - ans) % MOD;
        cout << ans;
    }
}


Measured memory_bytes: 8200
A,B,N=map(int, input().split())

ans = 0
if N < B:
  ans = int(A*N/B)-A*int(N/B)
elif N == B:
  ans = int(A*(N-1)/B)-A*int((N-1)/B)
else:
  ans = int(A*(B-1)/B)-A*int((B-1)/B)
print(ans)
  

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1 << 17;
LL n, k, s;
LL a[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	const int M = 1000 * 1000 * 1000;
	cin >> n >> k >> s;
	
	FOR(i, 0, k) a[i] = s;
	FOR(i, k, n)
	{
		if (s == M) a[i] = 1;
		else a[i] = M;
	}
	
	FOR(i, 0, n) cout << a[i] << ' ';
	cout << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,m;
    cin >> n >> m;
    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		
		int k = stdIn.nextInt();
		
		String dec = Integer.toString(n,k);
		
		System.out.println(dec.length());
	}

}


Measured memory_bytes: 23764
#include <stdio.h>
#include <string.h>
#include "math.h"


int main(int argc, char *argv[]){

  int i, j;
  long long int n;
  long long int m;
  long long int x;

  scanf("%lld", &n);

  m = (int)sqrt(n) + 1;

  for(i=m; i>=1; i--){
    if(n % i == 0){
      x = i + (n / i) - 2;
      i = 0;
    }
  }
  printf("%lld\n", x);

  return 0;
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int z = 0;
	int a, b;
	cin >> a >> b;
	cout << max(z, a - b * 2) << endl;

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<string> s(n);
	ll ans = 0;
	ll a, b, ab;
	a = b = ab = 0;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		if (s[i].size() >= 2) {
			for (int j = 0; j < s[i].size() - 1; j++) {
				if (s[i].substr(j, 2) == "AB") ans++;
			}
		}
		if (s[i][s[i].size() - 1] == 'A' && s[i][0] == 'B') ab++;
		if (s[i][s[i].size() - 1] == 'A') a++;
		if (s[i][0] == 'B') b++;
	}
	if (ab == a && ab == b) {
		ans += max(min(ab - 1, n - 1), 0ll);
	} else {
		ans += max(min(min(a, b), n - 1), 0ll);
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 768