akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  ll x,k,d; cin>>x>>k>>d;
  ll ans=0;
  if(x>=0){
    ll s = x/d;
    if(s >= k){
      ans = x - k*d;
    }else{
      k -= s;
      if(k%2==0){
        ans = x - d*s;
    }else{
      x -= s*d;
      ans = min(abs(x-d),abs(x+d));
    }
    }
  }else{
    ll s = -x/d;
    if(s>=k){
      ans = x + k*d;
    }else{
      k -= s;
      if(k%2==0){
        ans = x + d*s;
      }else{
        x += s*d;
        ans = min(abs(x-d),abs(x+d));
      }
    }
  }
  cout<<abs(ans)<<endl;
  return 0;
}


Measured memory_bytes: 3508
#include<iostream>
#include<cmath>

using namespace std;

struct S{
	double min;
	int s, a, c;
};

int main(){

	int N, l[257],r[257],o[257],x[257];
	int s, a, c;
	double H;
	S ans;

	while (1){

		cin >> N;
		if (N == 0) break;

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

		for (s = 0; s <= 15; s++){
			for (a = 0; a <= 15; a++){
				for (c = 0; c <= 15; c++){
					r[0] = s;
					for (int i = 1; i <= N; i++){
						r[i] = (a*r[i - 1] + c) % 256;
					}
					for (int i = 1; i <= N; i++){
						o[i] = (l[i] + r[i]) % 256;
					}
					for (int i = 0; i < 256; i++) {
						x[i] = 0;
					}
					for (int i = 1; i <= N; i++){
						x[o[i]]++;
					}
					H = 0;
					for (int i = 0; i < 256; i++){
						if(x[i]!=0) H += ((double)x[i] / N)*log((double)x[i] / N);
					}
					H *= -1;
					if (s == 0 && a == 0 && c == 0 || ans.min>H+1e-9){
						ans.min = H;
						ans.s = s, ans.a = a, ans.c = c;
					}
				}
			}
		}
		cout << ans.s << " " << ans.a << " " << ans.c << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
def solve(k, a, b):
    for i in range(a, b + 1):
        if i % k == 0:
            return "OK"
    return "NG"


def main():
    k = int(input())
    a, b = map(int, input().split())
    res = solve(k, a, b)
    print(res)


def test():
    assert solve(7, 500, 600) == "OK"
    assert solve(4, 5, 7) == "NG"
    assert solve(1, 11, 11) == "OK"


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 9196
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	int x[5];
	int i;
	for (i = 0; i < 5; i++) {
		cin >> x[i];
	}
	
	for (i = 0; i < 5; i++) {
		if (x[i] == 0) {
			cout << i + 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cmath>
#include<cstdio>
#define PI 3.14159265358979
using namespace std;
struct P{
  double x,y;
};
int n;


int Plot(P p1,P p2,int counter){
  if(counter >= n)return 0; 
  double th = 60.0*(PI/180.0); // degree to rad
  P s,t,u;
  s.x = (2.0 * p1.x + 1.0 * p2.x)/3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y)/3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x)/3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y)/3.0;  
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y ) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y ) * cos(th) + s.y;  

  counter++;
 
  Plot(p1,s,counter);
  printf("%.8lf %.8lf\n",s.x,s.y);
  Plot(s,u,counter);
  printf("%.8lf %.8lf\n",u.x,u.y);
  Plot(u,t,counter);
  printf("%.8lf %.8lf\n",t.x,t.y);
  Plot(t,p2,counter);
   
}

int main(){
  const P first = {0.0,0.0},second = {100.0,0.0};

  cin >> n;  
  printf("%.8lf %.8lf\n",first.x,first.y);
  Plot(first,second,0);
  printf("%.8lf %.8lf\n",second.x,second.y);
 

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	cout << fixed << setprecision(8);
	int a, b, C; cin >> a >> b >> C;
	double rad = acos(-1)*C / 180,
		S = a*b*sin(rad) / 2,
		L = a + b + sqrt(a*a + b*b - 2 * a*b*cos(rad)),
		h = S * 2 / a;
	cout << S << endl;
	cout << L << endl;
	cout << h << endl;
		return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <iostream>

#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>


using namespace std;

int main( int argc , char ** argv ){
	
	int N = 0;
	cin >> N;

	vector<int> a;
	int buf = 0;
	for(int i =0 ; i < N ; i++){
		buf = 0;
		cin >> buf;
		a.push_back(buf);
	}
	

	int count = 0;
	for(int step = 0 ; step < N ; step++){

			if( step+1 == a[a[step]-1] ) count ++;	
	}

	cout << count/2 << endl;
}



Measured memory_bytes: 892
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

c=array(3)
3.times do|i|
    c[i]=get_i
end
flag=true
1.upto(100) do|a1|
    b=array(3)
    3.times do|i|
        b[i]=c[0][i]-a1
    end
    flag=true
    2.times do|i|
        unless c[i+1][0]-b[0]==c[i+1][1]-b[1] and c[i+1][1]-b[1]==c[i+1][2]-b[2]
            flag=false
            break
        end
    end
    if flag
        break
    end
end
puts yn_judge(flag)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51},b,c;
int main()
{
	cin>>n>>m;
	if(n==1 || m==1)
		cout<<1<<endl;
	else if(n%2==0 || m%2==0)
		cout<<n*m/2<<endl;
	else
		cout<<m*(n/2)+m/2+1<<endl;	
} 

Measured memory_bytes: 256
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# import numpy as np
def resolve():
    N = ir()
    # A = np.array(lr(), np.int32)
    A = lr()
    A = [[A[i], i] for i in range(N)]
    A.append([2*10**5+1, N+1])
    A = sorted(A, key=lambda x: x[0])
    c = []
    d = []
    e = []
    tmp = 1
    st = 0
    for i in range(N+1):
        if tmp == A[i][0]:
            st += 1
        else:
            if st > 1:
                c.append(tmp)
                d.append(st)
                e.append(st*(st-1)//2)
            else:
                c.append(tmp)
                d.append(st)
                e.append(0)
            tmp = A[i][0]
            st = 1
    ans = []
    tmp = 0
    # print(c, d, e)
    se = sum(e)
    for i in range(N):
        if A[i][0] > c[tmp]:
            tmp += 1
        num = d[tmp]
        plu = 0
        if num > 2:
            plu = (num-1)*(num-2)//2
        ans.append([se-e[tmp]+plu, A[i][1]])
    # print(ans)
    # print(iA)
    ans = sorted(ans, key=lambda x: x[1])
    for i in range(N):
        print(ans[i][0])

resolve()

Measured memory_bytes: 125488
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] result = new int[n];
		ArrayList<Edge>[] list = new ArrayList[n];
		for(int i = 0; i < n; i++){
		    list[i] = new ArrayList<Edge>();
		}
		for(int i = 0; i < n-1; i++){
		    int from = sc.nextInt()-1;
		    int to = sc.nextInt()-1;
		    list[from].add(new Edge(from, to, 0));
		    list[to].add(new Edge(to, from, 0));
		}
		int[] c = new int[n];
		for(int i = 0; i < q; i++){
		    int index = sc.nextInt()-1;
		    c[index] += sc.nextInt();
		}
		
		// 計算
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
		int[] visited = new int[n];
		pq.add(0);
		result[0] = c[0];
		visited[0] = 1;
		while(!pq.isEmpty()){
		    int from = pq.poll();
		    for(Edge e : list[from]){
		        int to = e.to;
		        if(visited[to] == 1) continue;
		        visited[to] = 1;
		        result[to] = result[from] + c[to];
		        pq.add(to);
		    }
		}
		
		// 出力
		for(int i = 0; i < n; i++){
		    System.out.print(result[i] + " ");
		}
		
	}
}

class Edge {
    int from;
    int to;
    int weight;
    
    Edge(int from, int to, int weight){
        this.from = from;
        this.to = to;
        this.weight = weight;
    }

    public String toString(){
        return "from:" + from + " to:" + to + " weight:" + weight;
    }   
}



Measured memory_bytes: 225260
n = int(input())
H = list(map(int, input().split()))
ans = 0
r = 0
for l in range(n):
    while r < n - 1 and H[r] >= H[r+1]:
        r += 1
    ans = max(ans, r - l)
    if r == l:
        r += 1
print(ans)

Measured memory_bytes: 14252
#include <stdio.h>
int main(){
	
	int r, c;
	
	scanf("%d", &r);
	scanf("%d", &c);
	
	int hyou[r+1][c+1];
	
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			scanf("%d", &hyou[i][j]);
		}
	}
	
	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			if( i == r || j == c)
				hyou[i][j] = 0;
		}
	}

	for(int i = 0; i < r; i++){
		int som = 0;
		for(int j = 0; j < c; j++)
			som += hyou[i][j];
		hyou[i][c] = som;
	}
	
	for(int i = 0; i < c; i++){
		int som = 0;
		for(int j = 0; j < r; j++)
			som += hyou[j][i];
		hyou[r][i] = som;
	}
	
	for(int i = 0; i < c; i++)
		hyou[r][c] += hyou[r][i];
	
	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			if( j == c )
				printf("%d", hyou[i][j]);
			else
				printf("%d ", hyou[i][j]);
		}
		printf("\n");
	}
  	return 0;
}

Measured memory_bytes: 1072
n,m = map(int,input().split())

if (n == 1) and (m == 1):
  ans = 1
elif n == 1 and m != 1:
  ans = m-2
elif m == 1 and n != 1:
  ans = n-2
else:
  ans = (m-2)*(n-2)
  
print(ans)

Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    string s;cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

typedef long long ll;
const int MAX_N = int(1e5) + 5;
#define REP(i, n) for (int i = 0; i < n; i++)

ll n, k, a[MAX_N], b[MAX_N]{} ,c[MAX_N]{};

int main() {
    cin >> n >> k;
    REP(i,n){
        cin >> a[i];
        b[i+1] += b[i] + a[i];
        if(a[i]>0)c[i+1] += a[i];
        c[i+1] += c[i];
    }
    ll ans = 0;
    REP(i,n-k+1){
        ans = max(ans,c[i]+c[n]-c[i+k]+max(0LL,b[i+k]-b[i]));
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& vec){
    os << "[";
    for(const auto& v : vec){
        os << v << ",";
    }
    os << "]";
    return os;
}

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

int N,K;


int main(){
    cin >> N >> K;
    vector<int> D(K);
    rep(i,K) cin >> D[i];

    while(1){
        string s = to_string(N);
        bool f = true;
        for(int i=0;i<s.size();i++){
            for(int j=0;j<K;j++){
                if(s[i]-'0'==D[j]){
                    f=false;
                    break;
                }
            }
        }
        if(f){
            cout << N << endl;
            return 0;
        }
        N++;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            List<Integer> list = Arrays.stream(br.readLine().split(" "))
                    .map(Integer::parseInt)
                    .collect(Collectors.toList());

            int n = list.get(0);
            int x = list.get(1);

            if (n == 0 && x == 0) {
                break;
            }

            int count = 0;
            for (int i = 1; i <= n - 2; i++) {
                for (int j = i + 1; j <= n - 1; j++) {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) {
                            count++;
                        }
                    }
                }
            }

            System.out.println(count);
        }
    }
}

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

int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double theta = abs((h * 30 + m * 0.5) - m * 6);
    if(theta > 180) theta = 360 - theta;
    theta = theta / 180 * acos(-1);

    double ans = a * a + b * b - 2 * a * b * cos(theta);
    cout << fixed << setprecision(12) << sqrt(ans) << endl;
    return 0;
}

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

namespace ABC138C
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<double> v = Console.ReadLine().Split(' ').Select(e => double.Parse(e)).OrderBy(e=>e).ToList();
            while (v.Count>1)
            {
                v[0] = (v[0] + v[1]) / 2;
                v.RemoveAt(1);
            }
            Console.WriteLine((double)v[0]);
        }
    }
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    string s(4, ' ');
    rep(i, 4) {
        int x; cin >> x;
        s[i] = '0' + x;
    }
    sort(all(s));
    cout << (s == "1479" ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    int N;
    cin >> N;
    string A,B,C;
    cin >>A>>B>>C;
    int ans = 0;
    rep(i,N){
        if(A[i] == B[i]){
            if(A[i] == C[i]) continue;
            else ans++;
        }else if(A[i] == C[i]){
            ans++;
        }else if(B[i] == C[i]){
            ans++;
        }else{
            ans += 2;
        }
    }
    
    cout << ans << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

ansL = 0
ansR = float('inf')
for _ in range(M):
  l, r = map(int, input().split())
  ansL = ansL if ansL > l else l
  ansR = ansR if ansR < r else r

print(max(0, ansR - ansL + 1))

Measured memory_bytes: 3060
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim();
  var expressions = inputs.split('\n');
 
  for (var i = 0; i < expressions.length; i++) {
    if (expressions[i] === '0 ? 0') {
      break;
    }
    var expression = expressions[i].split(' ');
    var left = parseFloat(expression[0]);
    var right = parseFloat(expression[2]);
    var op = expression[1];
 
    if (op === '+') {
      console.log(left + right);
    } else if (op === '-') {
      console.log(left - right);
    } else if (op === '*') {
      console.log(left * right);
    } else if (op === '/') {
      console.log(Math.floor(left / right));
    }
  }
 
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15824
N = int(input())
L = [input() for i in range(N)]

dp = [1 for i in range(N)]

last = {}

for i in range(N) :
    if i == 0 :
        last[L[i]] = i
    else :
        if L[i] not in last :
            dp[i] = dp[i-1]
        elif L[i] == L[i-1] :
            dp[i] = dp[i-1]
        else :
            j = last[L[i]]
            dp[i] = dp[i-1] + dp[j]
        
        last[L[i]] = i

ans = dp[N-1]
ans %= 10**9+7
print(ans)

Measured memory_bytes: 761528
#include<bits/stdc++.h>
    using namespace std;
    #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < int , int >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 100005
    #define inf 9999999999



     int main()
     {
         ll t;
         t=1;
         while(t--){


        ll n,k;
         cin>>n>>k;
         ll a[n];
         ll ans[n];
         ll l=9999999;
         memset(ans,l,sizeof(ans));
         ans[0]=0;
         forl(i,0,n,n)cin>>a[i];
           // cout<<ans[1];
         forl(i,0,n,n)
         {
                forl(j,1,n,k+1)
                {
                if(j<=n-1)
             ans[i+j]=min(ans[i+j],(ans[i]+abs(a[i]-a[i+j])));
                }
            // ans[i+2]=min(ans[i+2],(ans[i]+abs(a[i]-a[i+2])));
             //cout<<ans[i+1]<< " "<<ans[i+2]<<endl;
         }
         cout<<ans[n-1]<<endl;
      }

}



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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int INF = 1e6;
#define MAX_V 210

struct edge {
	int to, cap, rev;
	edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {};
};

vector<edge> G[MAX_V];
int level[MAX_V]; 
int iter[MAX_V]; 

void add_edge(int from, int to, int cap)
{
	G[from].push_back(edge(to, cap, (int)G[to].size()));
	G[to].push_back(edge(from, 0, (int)G[from].size() - 1));
}

void bfs(int s)
{
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);

	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (edge &e : G[v]) {
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v, int t, int f)
{
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t)
{
	int flow = 0;
	while (true) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
}

int H, W;
string s[110];

int main() {
	cin >> H >> W;
	int st = H + W, gl = st + 1;
	rep(i, H) {
		cin >> s[i];
		rep(j, W) {
			if (s[i][j] == 'S') {
				add_edge(st, i, INF);
				add_edge(st, j + H, INF);
			} else if (s[i][j] == 'T') {
				add_edge(i, gl, INF);
				add_edge(j + H, gl, INF);				
			} else if (s[i][j] == 'o') {
				add_edge(i, j + H, 1);
				add_edge(j + H, i, 1);
			}
		}
	}
	int flow = max_flow(st, gl);
	if (flow < INF) {
		cout << flow << endl;
	} else {
		puts("-1");
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 200005;

int n, a[MAXN];
bool b[MAXN];

inline bool Chk(int x)
{
	for (int i = 1; i < n << 1; i ++)
		b[i] = a[i] >= x;
	if (b[n] == b[n - 1] || b[n] == b[n + 1])
		return b[n];
	int l = n, r = n;
	while (l > 1 && (b[l] ^ b[l - 1]))
		l --;
	while (r <= n - 1 << 1 && (b[r] ^ b[r + 1]))
		r ++;
	if (l + r >= n << 1)
		return b[l];
	return b[r];
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i < n << 1; i ++)
		a[i] = Read();
	int l = 1, r = (n << 1) - 1, ret = 0;
	while (l <= r)
	{
		int mid = l + r >> 1;
		if (Chk(mid))
			ret = mid, l = mid + 1;
		else
			r = mid - 1;
	}
	return printf("%d\n", ret), 0;
}


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

using namespace std;

#define STR(var) #var

// 曜日
enum Day {
    SUN,MON,TUE,WED,THU,FRI,SAT
};

int main(void) {
    string str;
    cin >> str;
    int daynum;
    if (equal(str.begin(), str.end(), STR(SUN))) daynum = SUN;
    if (equal(str.begin(), str.end(), STR(MON))) daynum = MON;
    if (equal(str.begin(), str.end(), STR(TUE))) daynum = TUE;
    if (equal(str.begin(), str.end(), STR(WED))) daynum = WED;
    if (equal(str.begin(), str.end(), STR(THU))) daynum = THU;
    if (equal(str.begin(), str.end(), STR(FRI))) daynum = FRI;
    if (equal(str.begin(), str.end(), STR(SAT))) daynum = SAT;

    cout << 7 - daynum << endl;
    return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    cin >> s;

    int n = s.size();
    ll ans = 0, up = 0, down = 0;
    int state = 0;
    REP(i, n){
        if(state == 0){
            if(s[i] == '<'){
                up++;
            }else{
                down++;
                state = 1;
            }
        }else{
            if(s[i] == '<'){
                ll a = max(up, down), b = min(up, down);
                ans += a*(a+1)/2 + b*(b-1)/2;
                up = 1;
                down = 0;
                state = 0;
            }else{
                down++;
            }
        }
    }

    ll a = max(up, down), b = min(up, down);
    ans += a*(a+1)/2 + b*(b-1)/2;

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


Measured memory_bytes: 900
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n; cin>>n;
	int b; cin>>b;
	char c; cin>>c;
	int d; cin>>d;
	int q=b*100+d;
	n*=q;
	cout<<n/100;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007

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

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

  int ans = 0;
  if (k <= a) {
    cout << k << endl;
    return 0;
  }
  else {
    k -= a;
    if (k <= b) {
      cout << a << endl;
      return 0;
    }
    else {
      k -= b;
      cout << a - k << endl;
      return 0;
    }
  }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll a, b;
    cin >> a >> b;

    if(a*b%2 == 0){
        cout << "Even" << endl;
    }
    else{
        cout << "Odd" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,ll> P;

ll d[32][32];
ll now[510][510];
ll r[3]={0,1,2};

ll cost[5][35];

int main(){
    ll n,C;
    cin>>n>>C;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            cin>>d[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int a;
            cin>>a;
            a--;
            now[i][j]=a;
        }
    }
    ll ans = (ll)INF;
    for(ll r=0;r<3;r++){
        for(ll c=0;c<C;c++){
            ll tmp=0;
            for(ll x=0;x<n;x++){
                for(ll y=0;y<n;y++){
                    if((x+y)%3==r){
                        tmp+=d[now[x][y]][c];
                    }
                }
            }
            cost[r][c]=tmp;
        }
    }
    for(ll i=0;i<C;i++){
        for(ll j=0;j<C;j++){
            for(ll k=0;k<C;k++){
                if(i==j)continue;
                if(j==k)continue;
                if(k==i)continue;
                ll tmp = cost[0][i]+cost[1][j]+cost[2][k];
                //cout<<i<<" "<<j<<" "<<k<<" "<<tmp<<endl;
                ans = min(ans,tmp);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll a[55];
    cin >> N;
    rep(i,0,N) cin >> a[i];
    ll min_val = INF, min_pos = -1, max_val = -INF, max_pos = -1;
    rep(i,0,N){
        if(a[i] < min_val){
            min_val = a[i];
            min_pos = i;
        }
        if(a[i] > max_val){
            max_val = a[i];
            max_pos = i;
        }
    }
    vector<lpair> lp;
    if(abs(max_val) > abs(min_val)){
        rep(i,0,N){
            lp.push_back(make_pair(max_pos+1, i+1));
        }
        rep(i,0,N-1){
            lp.push_back(make_pair(i+1, i+2));
        }
    }else{
        rep(i,0,N){
            lp.push_back(make_pair(min_pos+1, i+1));
        }
        rrep(i,N-1,1){
            lp.push_back(make_pair(i+1, i));
        }
    }
    // vector<lpair> lp;
    // if(abs(max_val) > abs(min_val)){
    //     ll v = abs(max_val);
    //     rep(i,1,N){
    //         while(a[i-1] > a[i]){
    //             a[i] += v;
    //             lp.push_back(make_pair(max_pos+1, i+1));
    //         }
    //     }
    // }else{
    //     ll v = min_val;
    //     rrep(i,N-2,0){
    //         while(a[i] > a[i+1]){
    //             a[i] += v;
    //             lp.push_back(make_pair(min_pos+1, i+1));

    //         }     
    //     }
    // }
    print(lp.size());
    rep(i,0,lp.size()){
        cout << lp[i].first << " " << lp[i].second << endl;
    }
}


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

int main() 
{
    string S;
    cin >> S;
    
    map<char, int> mp;
    for (int i = 0; i < S.size(); i++) {
        mp[S[i]]++;
    }
    
    for (auto x : mp) {
        if (x.second >= 2){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1e9+7;
using namespace std;

int main(){
    int n, ans; cin >> n;
    if(n <= 104) ans = 0;
    else if(n <= 134) ans = 1;
    else if(n <= 164) ans = 2;
    else if(n <= 188) ans = 3;
    else if(n <= 194) ans = 4;
    else ans = 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const int N = (int)1e5 + 5;
const int A = 60;

ll n, a[N], cnt[A], basis[A];

void init() {
  cin >> n;
  for(int i = 0 ; i < n ; ++i) {
    cin >> a[i];
    for(int j = 0 ; j < A ; ++j) if((1LL << j) & a[i]) cnt[j]++;
  }
}
void solve() {
  ll ans = 0;
  for(int j = 0 ; j < A ; ++j) if(cnt[j] % 2) {
    for(int i = 0 ; i < n ; ++i) if((1LL << j) & a[i]) a[i] ^= (1LL << j);
    ans += (1LL << j);
  }

  for(int i = 0 ; i < n ; ++i) {
    for(int j = A - 1 ; j >= 0 ; --j) {
      if(a[i] & (1LL << j)) {
        if(!basis[j]) {
          basis[j] = a[i];
          break;
        }
        a[i] ^= basis[j];
      }
    }
  }

  ll ans2 = 0;
  for(int j = A - 1 ; j >= 0 ; --j) {
    if(!basis[j] || (ans2 & (1LL << j))) continue;
    ans2 ^= basis[j];
  }

  cout << ans + ans2 * 2 << '\n';
}

int main() {
  init();
  solve();
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ {
  public class AOJ {
    public static void Main(string[] args) {
      var n = Console.ReadLine().Split(' ').ToList().Select(int.Parse).ToArray();
      Console.WriteLine(n[0] < n[1] ? (n[1] < n[2] ? "Yes" : "No") : "No");
    }
  }
}

Measured memory_bytes: 9324
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    ll res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            auto it = lower_bound(a.begin(), a.end(), a[i] + a[j]);
            it--;
            res += ((int)(it - a.begin())) - j;
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int n, x;
    cin >> n >> x;

    n = 2 * n - 1;

    if (x == 1 || x == n)
    {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    vector<int> ans(n);
    vector<bool> used(n + 1);

    if (n == 3)
    {
        ans[0] = 1, ans[1] = 2, ans[2] = 3;
    }
    else
    {
        if (x == 2)
        {
            ans[n / 2 - 2] = 4;
            ans[n / 2 - 1] = 1;
            ans[n / 2] = x;
            ans[n / 2 + 1] = 3;
        }
        else
        {
            ans[n / 2 - 2] = x - 2;
            ans[n / 2 - 1] = x + 1;
            ans[n / 2] = x;
            ans[n / 2 + 1] = x - 1;
        }

        for (int i = -2; i <= +1; ++i)
            used[ans[n / 2 + i]] = true;

        for (int i = 0, j = 1; i < n; ++i)
        {
            if (ans[i])
                continue;

            while (used[j])
                ++j;

            ans[i] = j++;
        }
    }

    for (auto y : ans)
        cout << y << endl;

    return 0;
}

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

const int MOD = 998244353;
const int MAXN = 100005;

int N, Di, C[MAXN];
int main(){
	scanf("%d", &N);
	
	bool ok = true;
	for(int i = 0; i < N; i++){
		scanf("%d", &Di);
		
		if(i == 0){
			if(Di != 0){
				ok = false;
				break;
			}
		}else{
			if(Di == 0){
				ok = false;
				break;
			}
		}
	
		C[Di]++;
	}
	
	if(!ok){
		printf("0\n");
		return 0;
	}
	
	long long res = 1;
	for(int i = 1; i <= N - 1; i++)
	for(int j = 0; j < C[i]; j++)
		res = res * C[i - 1] % MOD;
	
	printf("%lld\n", res);
	
	return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		wv.append((w,v))
		
	DP = [[1000000000000000000000000 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][v] = w
			DP[i][0] = 0
			continue
		
		for j in range(100001):
			DP[i][j] = min(DP[i][j], DP[i-1][j])
			if j+v < 100001:
				DP[i][j+v] = min(DP[i][j+v], DP[i-1][j] + w)
				
	ans = -1
	for i, val in enumerate(DP[N-1]):
		if val <= W:
			#print("{} {}".format(val, i))
			if ans == -1 or ans < i:
				ans = i
		
	print(ans)
	#print(DP[N-1][0])
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 171912
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n,k; cin >>n>>k;
  double ans=0;
  rep(i,n){
    double key=0;
    ll j=i+1;
    while(j<k){
      j*=2;
      key++;
    }
    ans+=(double)((double)1/n)*pow(0.5,key);
  }
  cout <<fixed<<setprecision(12)<<ans<<endl;
}
      

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007
#define INF 1001001001

int n, m, x, c[15], a[15][15], ans = INF;
main(){
    scanf("%d%d%d", &n, &m, &x);
    for(int i=0; i<n; i++){
        scanf("%d", &c[i]);
        for(int j=0; j<m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(int i=0; i < (1<<n); i++){
        int cost = 0, b[15] = {};
        bool flag = true;
        for(int j=0; j<n; j++){
            if((i>>j) & 1){
                cost += c[j];
                for(int k=0; k<m; k++){
                    b[k] += a[j][k];
                }
            }
        }
        for(int j=0; j<m; j++){
            if(b[j] < x){
                flag = false;
                break;
            }
        }
        if(flag)ans = min(ans, cost);
    }
    if(ans == INF){
        puts("-1");
        return 0;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF=1001001001;
using ll=long long;
 
int main() {
  long double a,b,c;
  cin>>a>>b>>c;
  if(4*a*b<(c-a-b)*(c-a-b)&&c-a-b>0){
  cout<<"Yes"<<endl;
  }else{
  cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))

count = 1 # 最初の数は入れる

flag = L[0]

for i in range(1,N):
    if L[i] <= flag:
        count += 1
        flag = L[i]
        if flag == 1:
            break
    

print(count)

Measured memory_bytes: 24744
#include <stdio.h>

int main (void)
{
	int w, i, n, m;
	scanf("%d", &w);
	
	int lot[w];
	for(i=0; i<w; i++)
	{
		lot[i]=i+1;
	}
	scanf("%d", &n);
	int lot_n[2];
	
	for(i=0; i<n; i++)
	{
		scanf("%d,%d", &lot_n[0], &lot_n[1]);
		m=lot[lot_n[0]-1];
		lot[lot_n[0]-1]=lot[lot_n[1]-1];
		lot[lot_n[1]-1]=m;
	}
	
	for(i=0; i<w; i++)
	{
		printf("%d\n", lot[i]);
	}
	return 0;
}

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

int main() {
    int k;
    string s;
    cin >> k;
    cin >> s;
    if (s.length() > k) {
        s.erase(s.begin() + k, s.end());
        s += "...";
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>

using namespace std;

struct point{
  int x, y;
};

struct button{
  point l,r;
  string name;
};

struct page{
  string name;
  vector<button>btn;   
}; 

int m,now;
vector<page> a;
page nowpage;
string buf[10001];

void func(void){
  for(int i=0;i<a.size();i++){
    if(buf[now]==a[i].name){
      nowpage=a[i];
      return ;
    }
  }
}

void click(int c,int d){
  
  for(int i=0;i<nowpage.btn.size();i++){
    if(nowpage.btn[i].l.x <=c && c<=nowpage.btn[i].r.x &&
       nowpage.btn[i].l.y <=d && d<=nowpage.btn[i].r.y ){
      fill(buf+now+1,buf+10001,"");
      buf[++now]=nowpage.btn[i].name;
      return ;
    }
  }
}


int main(void){
  int n;
  int w,h,b;
  page in;
  button tmp;

  while(cin >> n,n){
  
    a.clear();
    fill(buf,buf+10001,"");

    cin >> w >> h;
    
    for(int i=0;i<n;i++){
      in.btn.clear();
      cin >> in.name >> b;    
      if(i==0)buf[0]=in.name;

      for(int j=0;j<b;j++){
	cin >> tmp.l.x >> tmp.l.y >> tmp.r.x >> tmp.r.y >> tmp.name;
	in.btn.push_back(tmp);
      }
      a.push_back(in);
    }

    now=0;

    cin >> m;

    while(m--){
      string s;
      cin >> s;

      func();

      if(s=="click"){
	int c,d;
	cin >> c >> d;
	click(c,d);
      }
      else if(s=="back" && now>0)now--;
      else if(s=="forward" && buf[now+1]!="")now++;
      else if(s=="show")cout << buf[now] << endl;

    }
  }

  return 0;
}

Measured memory_bytes: 992
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  long long int a, b, c, x, y;
  long long int sum = 0;
  cin >> a >> b >> c >> x >> y;
  if (x > y) {
    if (a*x + b*y > 2*c*y + a*(x-y)) sum = 2*c*y + a*(x-y);
    else sum = a*x + b*y;
    if (2*c*x < sum) sum = 2*c*x;
  }
  else {
    if (a*x + b*y > 2*c*x + b*(y-x)) sum = 2*c*x + b*(y-x);
    else sum = a*x + b*y;
    if (2*c*y < sum) sum = 2*c*y;
  }
  cout << sum  << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int a, b;
    cin >> a >> b;
    if (6 <= a && a <= 12)
        b /= 2;
    if (a < 6)
        b = 0;
    cout << b << endl;
}

Measured memory_bytes: 256
import {stdin} from 'process';
let input = "";
stdin.on('data', x => {input += x});
stdin.on('end', () => {
    let lines = input.split('\n');
    let [n, m] = lines[0].split(' ')
        .map(x=>parseInt(x.trim()));
    if (m === 0) {
        console.log(0);
        return;
    }
    let signs = [
        [ 1, 1, 1],
        [ 1, 1,-1],
        [ 1,-1, 1],
        [ 1,-1,-1],
        [-1, 1, 1],
        [-1, 1,-1],
        [-1,-1,-1],
    ]
    let points = [];
    for (let _ of signs) { points.push(new Array<number>()); }
    for (let i = 0; i < n; i++) {
        let [x, y, z] = lines[i+1].split(' ')
            .map(x=>parseInt(x.trim()));
        signs.forEach(([a,b,c], i) => {
            points[i].push(x*a + y*b + z*c);
        });
    }
    let pointMax = points.map(x => {
        x.sort((x, y) => y - x);
        return x.slice(0, m).reduce((x, y) => x + y);
    });
    pointMax.sort((x, y) => y - x);
    console.log(pointMax[0]);
});

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

using namespace std;

#define int long long
#define fr(i, n) for(int i=0;i<n;i++)
#define frr(i, n) for(int i=n;i>=0;i--)
#define fra(i, a, n) for(int i=a;i<n;i++)
#define frra(i, a, n) for(int i=a;i>=n;i--)
#define f(i, a) for(auto &i:a)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef set<int> si;
typedef unordered_map<int, int> uii;
typedef unordered_set<int> usi;

const int mod = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int inf = LONG_LONG_MAX;
const double eps = 1e-9;
const double pi = 3.14159265358979323;

int power(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1)res = (res * x) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return res;
}

void solve() {
    //CODE BEGIN
    int n;
    cin >> n;
    vvi a(3, vi(n));
    vvi dp(3, vi(n + 1));
    for (int i = 0; i < n; ++i) {
        cin >> a[0][i] >> a[1][i] >> a[2][i];
    }
    for (int j = 1; j <= n; ++j) {
        for (int i = 0; i < 3; ++i) {
            for (int k = 0; k < 3; ++k) {
                if (i != k) {
                    dp[i][j] = max(dp[k][j - 1] + a[i][j - 1], dp[i][j]);
                }
            }
        }
    }
    cout << max(max(dp[0][n], dp[1][n]), dp[2][n]) << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int test = 1;
//    cin >> test;
    for (int i = 0; i < test; ++i) {
//        cout << "Case #" << i + 1 << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 5752
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b,c,d;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
    for(int i=0;i<=n-1;i++)
        if((b-a)>=(i*c-(n-i-1)*d)&&(b-a)<=(i*d-(n-i-1)*c))
		{
            printf("YES\n");
            return 0;
        }
    printf("NO\n");
    return 0;    
}

Measured memory_bytes: 256
import math
while True:
    x,y,s=map(int, input().split())
    c=0
    if x==0 and y==0 and s==0:
        break
    else:
        for a in range(1,s):
            for b in range (1,s-a+1):
                if math.floor(a*(100+x)/100)+math.floor(b*(100+x)/100)==s:
                    if math.floor(a*(100+y)/100)+math.floor(b*(100+y)/100)>c:
                        c=math.floor(a*(100+y)/100)+math.floor(b*(100+y)/100)
        print(c)


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

int main(){
    string n; cin >> n;
    int ans=0;
    int a=0;
    for (int i=0;i<n.size();i++){
        a=(int)(n[i]-'0');
        ans+=a;
    }
    if (ans%9==0){
        cout << "Yes" << "\n";
    }
    else {
        cout << "No" << "\n";
    }
}



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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, s;
  cin >> s >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    s -= x;
  }
  if (s <= -1) {
    s = -1;
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 3660
#include <iostream>
using namespace std;
int main(void){
  int n,a[100]={0};
  cin >> n;
  for(int i = 0; i < n; i++){
      cin >> a[i];
  }
  for(int i = n-1; i >= 0; i--){
  cout<<a[i];
  if(i>0){
    cout<<" ";
  }
 }
  cout<<endl;
}


Measured memory_bytes: 3108