akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;

typedef long long llint;

int main() {
    int a, b, c, x, y;

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

    // int a_half = min(a, c);
    // int b_half = min(b, c):

    // int ans = 0;
    // while(x != 0 && y != 0) {

    //     if (a < c && b < c) {
    //         ans = a * x + b * y;
    //     } if (a > c && b > c) {

    //         if 
    //     }

    // }
    llint min = -1;
    for (int i = 0; i <= x; i++) {
        int ab_num = (x - i) * 2;

        llint price;
        if (y > ab_num / 2) {
            price = i * a + ab_num * c + (y - ab_num / 2) * b;
        } else {
            price = i * a +  ab_num * c;
        }

        if (price < min || min == -1) {
            min = price;
        }
    }

    for (int i = 0; i <= y; i++) {
        int ab_num = (y - i) * 2;

        llint price;
        if (x > ab_num / 2) {
            price = i * b + ab_num * c + (x - ab_num / 2) * a;
        } else {
            price = i * b +  ab_num * c;
        }

        if (price < min || min == -1) {
            min = price;
        }
    }

    cout << min << endl;
}

Measured memory_bytes: 256
s=input()
x,y=map(int,input().split())
a=[0]*8000
b=[0]*8000
tmp=0
T=True
asize=0
bsize=0
for i in s:
    if i=="T":
        tmp=1-tmp
        T=True
    elif tmp==0:
        if T:
            asize+=1
            T=False
        a[asize-1]+=1
    else:
        if T:
            bsize+=1
            T=False
        b[bsize-1]+=1
c={0}
for i in range(asize):
    d=set()
    if i==0:
        if s[0]=="T":
            d.add(-a[i])
        d.add(a[i])
    else:
        for j in c:
            d.add(j+a[i])
            d.add(j-a[i])
    c=d
if not x in c:
    print("No")
    quit()
c={0}
for i in range(bsize):
    d=set()
    for j in c:
        d.add(j+b[i])
        d.add(j-b[i])
    c=d
if not y in c:
    print("No")
    quit()
print("Yes")


Measured memory_bytes: 49500
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
/*切り上げの計算！*/
int maxtime(int x) {
	return(x + 9) / 10 * 10;

}
int main() {
	long long int N, M;
	cin >> N >> M;
	pair<int, int> d;
	d.first = 0;
	d.second = 0;
	vector<pair<long int, long int>> S;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		pair<long int, long int> key;
		key.first = a;
		key.second = b;
		S.push_back(key);
	}
	sort(S.begin(), S.end());
	long long int sum = 0;
	for (int i = 0; i < N; i++) {
		if (M > S[i].second) {
			M = M - S[i].second;
			long long int k = S[i].first * S[i].second;
			sum = sum + k;
		}
		else {
			sum = sum + S[i].first * M;
			cout << sum;
			return 0;
		}
	}
}

Measured memory_bytes: 2420
h,w,k=map(int,input().split())
r,s,t,u=map(lambda x:int(x)-1,input().split())
b=[input()for _ in range(h)]
l=[[-1]*w for _ in range(h)]
l[r][s]=0
from collections import*
d=deque([(r,s)])
while d:
  x,y=d.popleft()
  if(x==t)&(y==u):exit(print(l[x][y]))
  for e,f in [[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      p,q=x+e*i,y+f*i
      if not(0<=p<h and 0<=q<w)or b[p][q]=="@":break
      if 0<=l[p][q]<=l[x][y]:break
      if l[p][q]==-1:d+=[(p,q)]
      l[p][q]=l[x][y]+1
print(-1)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

//// UnionFind
struct UnionFind{
	vector<int> v;
	UnionFind(int n) : v(n, -1) {}

	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
		return true;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};
int n;
vector<int> G[33];
int res[55];

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		rep(i,33)G[i].clear();
		rep(i,n){
			int f;
			cin>>f;
			rep(j,f){
				int d;
				cin>>d;
				d--;
				G[d].pb(i);
			}
		}
		rep(i,n)res[i]=INF;
		rep(i,n)rep(d,30){
			UnionFind uf(n);
			for(int dd=d;dd>=0;dd--){
				rep(j,G[dd].size())rep(k,j){
					if(uf.same(i,G[dd][j])||uf.same(i,G[dd][k]))uf.unite(G[dd][j],G[dd][k]);
				}
			}
			if(uf.size(i)==n){
				res[i]=d;
				//dbg(d);
				break;
			}
		}
		int ans=*min_element(res,res+n);
		if(ans==INF)cout<<"-1"<<endl;
		else cout<<ans+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 200005
typedef long long ll;
using namespace std;
int n;
ll a[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",a+i);	
		a[i]+=a[i-1];
	}
	ll ans=0x7fffffffffffffff;
	for(int i=1;i<n;++i)
		ans=min(abs(a[n]-a[i]*2),ans);
	printf("%lld",ans);
	return 0;
}

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

int main(){
	int N,M,C;
	cin >> N >> M >> C;
	int a[100][100];
	int sum=0;
	int rec=0;
	for(int i=0;i<N+1;i++){
		for(int j=0;j<M;j++){
			cin >> a[i][j];
		}
	}
	for(int i=1;i<N+1;i++){
		sum = 0;
		for(int j=0;j<M;j++){
			sum += a[i][j] * a[0][j];
		}
		if(sum+C>0){
			rec++;
		}
	}
	cout << rec;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <string.h>
using namespace std;
 
int main()
{
  /*処理系*/
  int A, B;
  int ans = -1;
  cin >> A >> B;
  for (float yen = 1.0; yen <= 1009.0; yen++)
  {
    if ((int)(yen * 0.08) == A)
      if ((int)(yen * 0.1) == B)
      {
        ans = yen;
        break;
      }
  }
  cout << ans;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
   N, K = map(int, input().split()) 
   NUM = [i for i in range(N+1)]
   LOWER = 0
   UPPER = 0
   CNT = 0
   for j in range(K):
       LOWER += NUM[j]
       UPPER += NUM[N-j]
   for i in range(N+1):
       if i + K >= N+1:
           CNT += 1
           break
       CNT += UPPER -LOWER + 1
       LOWER += NUM[K+i]
       UPPER += NUM[N-(K+i)]
   print(CNT%((10**9)+7))

if __name__ == '__main__':
    main()

Measured memory_bytes: 16964
#include<stdio.h>
//using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int i,a[500000],sum=0;
	int max,min;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(i==0) 
		{
			max=a[i];
			min=a[i];
			sum++;
		}
		else
		{
			if(max>=a[i]&&min>=a[i])
			{
				sum++;
				//printf("%d ",a[i]);
			}
			if(max<a[i]) max=a[i];
			if(min>a[i]) min=a[i];
		}
	}
	printf("%d\n",sum);
} 


Measured memory_bytes: 896
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		//キーボード入力メソッド
		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");
		}
	}

}



Measured memory_bytes: 26128
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
  int a, b, c, d, p;
  cin >> a >> b >> c >> d >> p;
  if(p-c > 0) b += d * (p - c);
  cout << min(a*p, b)<< endl;
  return 0;
}
  

Measured memory_bytes: 1164
n = int(input())
l = list(map(int, input().split()))
d = {}
for i in range(n):
  if 1<=l[i]<=399:
    a = 0
  elif 400<=l[i]<=799:
    a = 1
  elif 800<=l[i]<=1199:
    a = 2
  elif 1200<=l[i]<=1599:
    a = 3
  elif 1600<=l[i]<=1999:
    a = 4
  elif 2000<=l[i]<=2399:
    a = 5
  elif 2400<=l[i]<=2799:
    a = 6
  elif 2800<=l[i]<=3199:
    a = 7
  else:
    a = 8
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
if not(8 in d):
  print(len(d.keys()), len(d.keys()))
else:
  if len(d.keys()) == 1:
    print(len(d.keys()), len(d.keys())-1+d[8])
  else:
    print(len(d.keys())-1, len(d.keys())-1+d[8])
  

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;

int main(){
	int r,g,x;
    
    cin >> r >> g;
    
    x = g * 2 - r;
    
    cout << x;
    
	return 0;
}

Measured memory_bytes: 256
import java.util.*;


class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int d = stdIn.nextInt();
    int[][] x = new int[n][d];
    for(int i = 0;i<x.length;i++) {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    }
    int a = 0;
    int count = 0;
    for(int i = 0;i<x.length;i++) {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    }
    System.out.println(count);
  }
  public static boolean hantei(int a) {
    for(int i = 1;i<=(int)Math.sqrt(a);i++) {
      if(a==i*i) return true;
    }
    return false;
  }
  }

Measured memory_bytes: 21972
#include <iostream>
using namespace std;
int main()
{
	int x;
	cin >> x;
	int a = x / 3600;
	int b = (x - a * 3600) / 60;
	int c = x - a * 3600 - b*60;
	cout << a <<':'<< b << ':' << c << endl;
}



Measured memory_bytes: 3096
var H = 0;
var W = 0;

function main(input) {
  H = input.split("\n")[0].split(" ")[0];
  W = input.split("\n")[0].split(" ")[1];
  var matrix = init(
    input.split("\n").filter((line, i) => {
      return i !== 0;
    })
  );
  for (var i = 0; i < H; i++) {
    matrix = removeRow(matrix, i);
  }
  matrix = t(matrix);
  for (var j = 0; j < W; j++) {
    matrix = removeRow(matrix, j);
  }
  print(t(matrix));
}

function print(ary) {
  ary.forEach(row => {
    var noNeedPrint = row.reduce((acc, v) => acc && v === "n", true);
    if (!noNeedPrint) {
      console.log(row.filter(e => e !== "n").join(""));
    }
  });
}

function removeRow(ary, i) {
  var isWhiteRow = ary[i].reduce(
    (accum, v) => accum && (v === "." || v === "n"),
    true
  );
  if (!isWhiteRow) return ary;
  return ary.map((a, j) => {
    return a.map(b => {
      return j === i ? "n" : b;
    });
  });
}

function t(matrix) {
  var h = matrix.length;
  var w = matrix[0].length;

  var newMatrix = matrix[0].map(a => new Array(h));
  for (var i = 0; i < h; i++) {
    for (var j = 0; j < w; j++) {
      newMatrix[j][i] = matrix[i][j];
    }
  }
  return newMatrix;
}

function init(ary) {
  return ary
    .filter(a => {
      return a.split("").length > 0;
    })
    .map(a => {
      return a.split("");
    });
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	map<string,int> cnt;
	while(N--){
		string str; cin >> str;
		cnt[str]++;
	}
	cout << "AC x " << cnt["AC"] << '\n';
	cout << "WA x " << cnt["WA"] << '\n';
	cout << "TLE x " << cnt["TLE"] << '\n';
	cout << "RE x " << cnt["RE"] << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3636
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

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

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

int main() {
  ll N;
  cin >> N;
  ll k = 0;
  ll total = 0;
  for(ll i=0; ; i++) {
    if((total = (i * (i+1)) / 2) >= N) {
      k = i;
      break;
    }
  }
  REP(i,1,k+1) {
    if(i != total - N) {
      cout << i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<algorithm>
#define L long long
#include<string.h>
#include <math.h>
using namespace std;
int n;
long long area;
int a [60]={2,3,13,23,43,53,73,83,103,113,163,173,193,223,233,263,283,293,313,353,373,383,433,443,463,503,523,563,593,613,643,653,673,683,733,743,773,823,853,863,883,953,983,1013,1033,1063,1093,1103,1123,1153,1163,1193,1213,1223,1283,1303,1373};
int  main()
{
       scanf("%d",&n);

           for(int i=0;i<n-1;i++)
            cout<<a[i]<<' ';
           cout<<a[n-1]<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    int64 n;
    cin >> n;
    int64 rs = 1;
    vec64 ciur (n + 1000, 0);
    for (int64 i = 2; i <= n; i++){
        for (int64 j = i+i; j <=n; j+=i){
            ciur[j]++;
        }
    }
    // for (int i = 0; i <=n; i++){
    //     cts(i); ctn(ciur[i]);
    // }
    for (int i = 2; i <=n; i++){
        // ctn(rs);
        rs+=( (ciur[i] + 2) * i);
    }
    ctn(rs);
    return 0;
}


Measured memory_bytes: 81408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

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

    int n, l, t;
    cin >> n >> l >> t;
    vector<int> x(n), w(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> w[i];
    }

    int m[3] = { 0, t % l, l - t % l }, q = t / l, d = 0;
    for (int i = 0; i < n; i++) {
        x[i] += m[w[i]];
        d += w[i] == 1 ? q : -q - 1;
        if (x[i] >= l) x[i] -= l, d++;
    }
    d %= n;
    if (d < 0) d += n;
    sort(x.begin(), x.end());

    for (int i = 0; i < n; i++) {
        int i1 = i + d;
        if (i1 >= n) i1 -= n;
        cout << x[i1] << "\n";
    }

    return 0;
}

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



#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll   long long 
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
#define md          1000000007
#define fmd         998244353 
#define M           100011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}

class BIT{
public:
    int n;
    vector<int>B;
    BIT(int sz){
        n=sz;
        B=vector<int> (n+1);
    }
    void up(int x,int y){
        for(;x<=n;x+=x&-x)B[x]+=y;
    }
    int sum(int x){int s=0;
        for(;x>=1;x-=x&-x)s+=B[x];
        return s;
    }

};


int solve(){
    ll n,i,j,k,m,x,y,z;
    cin>>n>>m;
    vector<pair<int,int> > v[m+1];
    BIT b(m);
    vector<int> ans(m+10);

    for(i=1;i<=n;++i){
        int l,r;
        cin>>l>>r;
        v[r-l+1].pb({l,r});
        ans[1]++;
        ans[r-l+2]--;
    }

    for(i=1;i<=m;++i){
        for(j=i;j<=m;j+=i){
            int cnt=b.sum(j);
            // trace(i,j,cnt);
            if(cnt){
                ans[i]+=cnt;
                ans[i+1]-=cnt;
            }
        }
        if(!v[i].size())continue;
        for(auto x:v[i]){
            b.up(x.F,1);
            b.up(x.S+1,-1);
        }
    }
        for(i=1;i<=m;++i)ans[i]+=ans[i-1];
        for(i=1;i<=m;++i)cout<<ans[i]<<"\n";




    

    die();
}
 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif

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

    int t;
    t=1;;
    // prec();
    // cin>>t;
 
    while(t--){

        solve();
    }
 
 
 
 


#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

Measured memory_bytes: 8448
#!/usr/bin/env ruby
# require 'pry'

t = gets.chomp.split('')
t.push(nil).unshift(nil)
t.each.with_index do |ele, i|
  next if ele != '?'
  if t[i-1] == 'P'
    t[i] = 'D'
  elsif t[i+1] == 'D' || t[i+1] == '?'
    t[i] = 'P'
  else
    t[i] = 'D'
  end
end
puts t.join


Measured memory_bytes: 32332
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(b<c||d<a) printf("0\n");
    else if(a<=c&&b>=d) printf("%d\n",d-c);
    else if(c<=a&&d>=b) printf("%d\n",b-a);
    else printf("%d\n",min(b,d)-max(a,c));
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	// "reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func first_and_last(w int) string{
    _ret := make([]string, 0)
    for i:=0; i<w+2; i++{
        _ret = append(_ret, "#")
    }
    ret := strings.Join(_ret, "") + "\n"
    return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	h, w := nextInt(), nextInt()
	fmt.Fprint(out, first_and_last(w))
	for y:=0; y<h; y++{
		line := next()
		s := "#" + line + "#" + "\n"
		fmt.Fprint(out, s)
	}
	fmt.Fprint(out, first_and_last(w))
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<String, ArrayList<Integer>> map = new TreeMap<String, ArrayList<Integer>>();
		ArrayList<Integer> page ;

		while (sc.hasNext() ) {
			String key = sc.next();
			int pageIn = sc.nextInt();
			if ( !map.containsKey(key) ) {
				map.put(key, new ArrayList<Integer>() );
			}
			map.get(key).add(pageIn);
		}
		
		
		Iterator it = map.keySet().iterator();
		while (it.hasNext()) {
			String key = (String) it.next();
			ArrayList <Integer> list = map.get(key);
			Collections.sort(list);
			System.out.println(key);
			for(int i = 0; i < list.size(); i++){
				if(i == 0){
					System.out.print(list.get(i));
				}else{
					System.out.print(" " + list.get(i));
				}
			}
			System.out.println();
			
                 }
		
	}

}  

Measured memory_bytes: 26432
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

ll N;

void solve() {
    cin >> N;
    vll a(N);
    ll tmp=0, total=0, ans=10000000000;
    rep(i,N){
        cin >> a[i];
        total += a[i];
    }
    total -= tmp;
    rep(i,N-1){
        tmp += a[i];
        ans = min(ans, abs(tmp+tmp-total));
    }
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 4796
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
#define N 200005
int a[N],n;
bool chk(int mid)
{
	stack<pii> s; s.emplace(0,0);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>a[i-1]) continue;
		while(s.top().fir>a[i]) s.pop();
		int val=a[i];
		while(s.top().fir==val&&s.top().sec==mid-1)
		{
			s.pop();
			val--;
		}
		if(!val) return 0;
		if(s.top().fir==val)
		{
			auto [v,w]=s.top(); s.pop();
			s.emplace(v,w+1);
		}
		else s.emplace(val,1);
	}
	return 1;
}
signed main()
{
	cin>>n; for(int i=1;i<=n;i++) a[i]=read();
	bool ok=1; for(int i=1;i<=n;i++) ok&=(a[i]>a[i-1]);
	if(ok) {cout<<1<<endl; return 0;}
	int l=2,r=n,ans;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(chk(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 4404
def main():
    N = int(input())
    l = list(map(int, input().split()))
    l2 = []
    for i in range(len(l)):
        if l[i] % 2 == 0:
            l2.append(l[i])
    for i in range(len(l2)):
        if not l2[i] % 3 == 0 and not l2[i] % 5 == 0:
            print('DENIED')
            return
    print('APPROVED')

main()

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

typedef long long int int64;
static const int64 mod = 1000000007LL;
int64 qpow(int64 a,int b)
{
	int64 val = 1;
	for(int j = 0;j < b;++j) val = val * a % mod;
	return val;
}

int64 dp[25000][400];
int64 dp2[25000][400];
int n,k,m;
int a[25000];
int64 pre[400];
int vis[400],visn;
int64 inv[25000];
int main()
{
	scanf("%d%d%d",&n,&k,&m);
	if(k == 1) {
		printf("%d\n", n-m+1);
		return 0;
	}
	bool color = false;
	for(int i = 0;i < m;++i) {
		scanf("%d",&a[i]);
		--a[i];
		if(i >= k) {
			if(--vis[a[i-k]] == 0) --visn;
		}
		if(vis[a[i]]++ == 0) ++visn;
		if(visn == k) color = true;
	}
	if(color) {
		printf("%lld\n", qpow(k,n-m)*(n-m+1)%mod);
		return 0;
	}
	memset(vis,0,sizeof(vis));visn = 0;
	int la = 0,lb = 0;
	for(int i = 0;i < m;++i) {
		if(vis[a[i]]) break;
		++la;vis[a[i]] = true;
	}
	memset(vis,0,sizeof(vis));visn = 0;
	for(int i = m-1;i >= 0;--i) {
		if(vis[a[i]]) break;
		++lb;vis[a[i]] = true;
	}
	if(la == m) {
		dp[0][0] = k;if(la == 1) dp2[0][0] = k;
		for(int i = 1;i < n;++i) {
			pre[k-2] = dp[i-1][k-2];
			for(int j = k-3;j >= 0;--j) pre[j] = (pre[j+1] + dp[i-1][j]) % mod;
			for(int j = 0;j < k-1;++j) {
				dp[i][j] = ((j == 0 ? 0 : dp[i-1][j-1] * (k-j)) + pre[j]) % mod;
			}
			pre[k-2] = dp2[i-1][k-2];
			for(int j = k-3;j >= 0;--j) pre[j] = (pre[j+1] + dp2[i-1][j]) % mod;
			for(int j = 0;j < k-1;++j) {
				dp2[i][j] = ((j >= la-1 ? dp[i][j] : 0) + (j == 0 ? 0 : dp2[i-1][j-1] * (k-j)) + pre[j]) % mod;
			}
		}
		int64 ans = 0;
		for(int j = 0;j < k-1;++j) ans += dp2[n-1][j];
		ans %= mod;
		inv[1] = 1;
		for(int i = 2;i <= k;++i) {
			inv[i] = (mod-mod/i)*inv[mod%i]%mod;
			if(i>k-m) ans = ans * inv[i] % mod;
		}
		ans = (qpow(k,n-m)*(n-m+1)-ans)%mod;
		if(ans < 0) ans += mod;
		printf("%lld\n", ans);
	} else {
		dp[0][la-1] = 1;
		for(int i = 1;i < n;++i) {
			pre[k-2] = dp[i-1][k-2];
			for(int j = k-3;j >= 0;--j) pre[j] = (pre[j+1] + dp[i-1][j]) % mod;
			for(int j = 0;j < k-1;++j) {
				dp[i][j] = ((j == 0 ? 0 : dp[i-1][j-1] * (k-j)) + pre[j]) % mod;
			}
		}
		dp2[0][lb-1] = 1;
		for(int i = 1;i < n;++i) {
			pre[k-2] = dp2[i-1][k-2];
			for(int j = k-3;j >= 0;--j) pre[j] = (pre[j+1] + dp2[i-1][j]) % mod;
			for(int j = 0;j < k-1;++j) {
				dp2[i][j] = ((j == 0 ? 0 : dp2[i-1][j-1] * (k-j)) + pre[j]) % mod;
			}
		}
		int64 ans = 0;
		for(int i = 0;i <= n-m;++i) {
			int i2 = n-m-i;
			int64 val1 = 0, val2 = 0;
			for(int j = 0;j < k-1;++j) val1 += dp[i][j];
			val1 %= mod;
			for(int j = 0;j < k-1;++j) val2 += dp2[i2][j];
			val2 %= mod;
			ans += val1 * val2 % mod;
		}
		ans = (qpow(k,n-m)*(n-m+1)-ans)%mod;
		if(ans < 0) ans += mod;
		printf("%lld\n", ans % mod);
	}
}


Measured memory_bytes: 156544
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3624
n, d = gets.split.map(&:to_i)
x = []
n.times do |i|
  x[i] = gets.split.map(&:to_i)
end
result = 0
c = x.combination(2).to_a
c.each do |pair|
  sq = 0
  d.times do |i|
    sq += (pair[0][i] - pair[1][i]) ** 2
  end
  result += 1 if sq == (sq ** (1/2.0)).to_i ** 2
end
puts result


Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include<stdio.h>
int main(void)
{
    int n = 0, a = 0, b;
    int d[200000];
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {n=(n<<1)+(n<<3)+c-'0'; c=getchar_unlocked();}
    int* e = d + n;
    do
    {
        d[n] = 0;
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {d[n]=(d[n]<<1)+(d[n]<<3)+c-'0'; c=getchar_unlocked();}
        a ^= d[n];
    } while(--n);
    while(d != e)
    {
        printf("%d ", a ^ *e);
        --e;
    }
    return 0;
}


Measured memory_bytes: 3272
C = [list(map(int, input().split())) for _ in range(3)]
a = [0] * 3
b = [0] * 3
for i in range(101):
    a[0] = i
    flg = True
    for j in range(3):
        b[j] = C[0][j] - i
        if b[j] < 0:
            flg = False
            break
    if flg:
        for j in range(1, 3):
            a[j] = C[j][0] - b[0]
            if a[j] < 0:
                flg = False
                break
    if flg:
        for j in range(3):
            for k in range(3):
                if C[j][k] != a[j] + b[k]:
                    flg = False
                    break
        if flg:
            print('Yes')
            quit()
print('No')

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#ifdef _MSC_VER
int getchar_unlocked() { return getchar(); }
#endif
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
#define qp(f) [](auto i){return f;}
using LL=long long;
using VI=vector<int>;
using VL=vector<LL>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;
const int inf = (int)1e9;
const LL MOD = 1000000007;
const double pi = acos(-1.0);
const string Snum = "0123456789";
const int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
template<class T>T Sort(T& a) { sort(a.begin(), a.end()); return a; }
template<class T>T ReSort(T& a) { sort(a.rbegin(), a.rend()); return a; }
template<class T>T Reverse(T& a) { reverse(a.begin(), a.end()); return a; }
template<class T>void Unique(T& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template<class T>auto Max(T a) { return *max_element(a.begin(), a.end()); }
template<class T>auto Min(T a) { return *min_element(a.begin(), a.end()); }
template<class T, class U>int Count(T a, U c) { return count(a.begin(), a.end(), c); }
template<class T, class U>U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); }
template<class T>T Age(T a, T b) { return (a + b - 1) / b; }
template<class T>T gcd(T n, T m) { return m == 0 ? n : gcd(m, n % m); }
template<class T>T lcm(T n, T m) { return n / gcd(n, m) * m; }

int solve(VI& a, int p, int r) {
	int x = a[r], i = p - 1;
	FOR(j, p, r) {
		if (a[j] <= x) {
			i++;
			swap(a[i], a[j]);
		}
	}
	swap(a[i + 1], a[r]);
	return i + 1;
}

int main() {
	int n; scanf("%d", &n);
	VI a(n); rep(i, n)scanf("%d", &a[i]);

	int pos = solve(a, 0, n - 1);
	rep(i, n) {
		if (i == pos)printf("[%d]", a[i]);
		else printf("%d", a[i]);
		printf(i == n - 1 ? "\n" : " ");
	}
}


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

using namespace std;



int main(){

    int n, k;
    scanf("%d%d", &n, &k);
    int num = 0;
    for(int i=1; i<=n; i++){
        int x;
        scanf("%d", &x);
        num += x >= k;
    }
    printf("%d\n", num);
}

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

int main() {
    string S;
    long long K;
    cin >> S >> K;

    int i = 0;
    while (S[i] == '1') i++;

    if (i < K) cout << S[i] << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int M, D;
  cin>>M>>D;
  int ans = 0;
  for(int i=1;i<=M;++i) {
    for(int j=22;j<=D;++j) {
      if(j%10<2) continue;
      if((j/10)*(j%10)==i) ans++;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3488
#include<iostream>

using namespace std;

static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;


int n, M[MAX][MAX];;

int prim() {
  int u, minv;
  int d[MAX], p[MAX], color [MAX];

  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while (1) {
    minv = INFTY;
    u = -1;
    for (int i = 0; i < n; i++) {
      if (minv > d[i] && color[i] != BLACK) {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1) {
      break;
    }
    color[u] = BLACK;
    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && M[u][v] != INFTY) {
        if (d[v] > M[u][v]) {
          d[v] = M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] != -1) {
      sum += M[i][p[i]];
    }
  }

  return sum;
}

int main() {
  cin >> n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int e; cin >> e;
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

  cout << prim() << endl;

  return 0;
}


Measured memory_bytes: 3092
N,Q =map(int,input().split())
S = input()

t = [0]
for i in range(N):
    t.append(t[-1]+1 if S[i:i+2] == "AC" else t[-1])
for i in range(Q):
    l,r = map(int,input().split())
    print(t[r-1]-t[l-1])

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> point;

point anchor;
constexpr int MX_N=101;
int N;
point vertices[MX_N];
int perm[MX_N];
double out[MX_N];

double dist(const point& a, const point& b){
    return abs(a-b);
}

double cross(const point& a, const point& b){
    return real(a)*imag(b) - imag(a)*real(b);
}

bool angleCmp(const point& a, const point& b){
    point relA = a-anchor;
    point relB = b-anchor;
    if(cross(relA,relB)==0.0)
        return dist(a,anchor) < dist(b,anchor);
    return arg(relA) < arg(relB);
}

bool ccw(const point& a,const point& b, const point& c){
    if(a==b || b==c || a==c)
        return false;
    point u = b-c;
    point v = b-a;
    double cr = cross(u,v);
    return cr > 0;
}

int main(){
    scanf("%d",&N);
    double x,y;
    for(int i = 0; i < N; i++){
        scanf("%lf %lf",&x,&y);
        vertices[i]=point(x,y);
        perm[i]=i;
    }
    sort(perm,perm+N,
            [](int a, int b){
                const point &pa = vertices[a];
                const point &pb = vertices[b];
                if(real(pa)!=real(pb))
                    return real(pa) < real(pb);
                return imag(pa) < imag(pb);
            });
    vector<int> L;
    vector<int> U;
    for(int i = 0; i < N;){
        int t = L.size();
        if(t >= 2 && !ccw(vertices[L[t-2]],vertices[L[t-1]],vertices[perm[i]]))
            L.pop_back();
        else
            L.push_back(perm[i++]);
    }
    for(int i = N-1; i >=0;){
        int t = U.size();
        if(t >= 2 && !ccw(vertices[U[t-2]],vertices[U[t-1]],vertices[perm[i]]))
            U.pop_back();
        else
            U.push_back(perm[i--]);
    }
    vector<int> hull;
    for(int i = 0; i < L.size()-1; ++i)
        hull.push_back(L[i]);
    for(int i = 0; i < U.size()-1; ++i)
        hull.push_back(U[i]);
    int h = hull.size();
    if(h == 2){
        out[hull[0]] = out[hull[1]] = 0.5;
    } else {
        for(int i = 0;i < h; ++i){
            point a = vertices[hull[(h+(i-1))%h]];
            point b = vertices[hull[i]];
            point c = vertices[hull[(i+1)%h]];
            point ab = (b-a)*point(0,1);
            point cb = (b-c)*point(0,-1);
            double ang = abs(arg(ab)-arg(cb))/(2*M_PI);
            out[hull[i]] = min(1-ang,ang);
        }
    }
    for(int i = 0; i < N; ++i){
        printf("%.16lf\n",out[i]);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  double t,a;
  cin>>n>>t>>a;
  double h,tem,min,ans;
  for(int i=1;i<=n;i++){
    cin>>h;
    if(i==1){
      min=abs(a-(t-h*0.006));
      ans=1;
    }else{
      tem=abs(a-(t-h*0.006));
      if(tem<min){
        min=tem;
        ans=i;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, b, c;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    int ans = 0;
    int count=1;
    for (int i = 0; i < n; i++)
    {
        if(count!=a[i]){
            ans++;
        }
        else{
            count++;
        }
    }
    if(ans==n){
        return cout<<-1<<"\n",0;
    }
    cout << ans << "\n";
}



Measured memory_bytes: 1400
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			double y=in.nextInt();
			double max=-1;
			int ans=-1;
			for(int i=0;i<n;i++)
			{
				int  b=in.nextInt();
				double r=in.nextInt();
				double t=in.nextInt();
				double tmp=0;
				if(t==1)
					tmp=1+y*(r/100);
				else if(t==2)
					tmp=Math.pow(1+(r/100), y);
				if(max<tmp)
				{
					max=tmp;
					ans=b;
				}	
			}
			System.out.println(ans);
		}
	}

}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int digit=n%10;
    if(digit==3)
        cout<<"bon";
    else if((digit==0)||(digit==1)||(digit==6)||(digit==8))
        cout<<"pon";
    else
        cout<<"hon";
    return 0;
}

Measured memory_bytes: 3616
size =  int(input().strip())
nums  = list(map(int, input().strip().split(' ')))
sortedNums = sorted(nums)
x1 = sortedNums[int(size/2-1)]
x2 = sortedNums[int(size/2)]
for i in nums:
    if(x1 == x2):
        print(x1)
    elif (i>=x2):
        print(x1)
    else:
        print(x2)


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	ll n,k;
	 cin>>n>>k;

	 vector<ll>vect(n);

	 f(i,0,n)
	 	cin>>vect[i];
	 sort(vect.begin(),vect.end());

	 ll ans=0;

	 for(int i=0;i<k;i++)
	 	ans+=vect[i];
	 cout<<ans<<"\n";

	
	return 0;
}

Measured memory_bytes: 3660
#include<cstdio>
#include<iostream>
using namespace std;
bool ok=1;
int a[4],b[4],c[4][4];
int main(){
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			cin>>c[i][j];
	for(a[1]=0;a[1]<=100&&ok;a[1]++)
		for(a[2]=0;a[2]<=100&&ok;a[2]++)
			for(a[3]=0;a[3]<=100&&ok;a[3]++){
				b[1]=c[1][1]-a[1];
				b[2]=c[1][2]-a[1];
				b[3]=c[1][3]-a[1];
				bool flag=1;
				for(int i=1;i<=3&&flag;i++)
					for(int j=1;j<=3&&flag;j++)
						if(c[i][j]!=a[i]+b[j])flag=0;
				if(flag)ok=0;
			}
	puts(ok?"No":"Yes");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	string str;
	cin >> str;
	if(str=="SUN")	cout << "7" << endl;
	else if(str=="SAT")	cout << "1" << endl;
	else if(str=="FRI")	cout << "2" << endl;
	else if(str=="THU")	cout << "3" << endl;
	else if(str=="WED")	cout << "4" << endl;
	else if(str=="TUE")	cout << "5" << endl;
	else	cout << "6" << endl;
	return 0;
}

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

long N;
vector<long> button;

int main(){
    scanf("%ld", &N);
    long b;
    for(long i=0; i<N; i++){
        scanf("%ld", &b);
        button.push_back(b-1);
    }
    long cnt = 0;
    long next = 0;
    long i;
    for(i=0; i<N; i++){
        cnt++;
        next = button[next];
        if(next==1)break;
    }
    if(i==N)printf("%d\n", -1);
    else printf("%ld\n", cnt);
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <stdlib.h>
 
typedef struct node{
  int p;
  int right;
  int left;
}Node;
 
Node *node,tmp;
 
int main(){
   
  int n,i,j,l,c,k,id,tmpP,depth,r;
   
  //in
  scanf("%d",&n);
   
  node = malloc(sizeof(Node)*n);
 
  //initialize
  for(i=0;i<n;i++){
    node[i].p = -1;
    node[i].right = -1;
    node[i].left = -1;
  }
   
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
     
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0) node[id].left = c;
      else node[r].right = c;
      node[c].p = id;
      r=c;
    }
  }
   
  //depthSearch & typeJudge
  for(i=0;i<n;i++){
    depth = 0;
    tmpP = node[i].p;
     
    while(tmpP != -1){
      tmpP = node[tmpP].p;
      depth++;
    }
     
    if(node[i].p == -1){
      printf("node %d: parent = %d, depth = %d, root, [",
       i,node[i].p,depth);
    }
    else if(node[i].left == -1) printf("node %d: parent = %d, depth = %d, leaf, [",
       i,node[i].p,depth);
    else printf("node %d: parent = %d, depth = %d, internal node, [",
       i,node[i].p,depth);
     
    tmpP = node[i].left;
    if(tmpP != -1) printf("%d",tmpP);
     
    while(tmpP != -1){
      tmpP = node[tmpP].right;
      if(tmpP != -1) printf(", %d",tmpP);
    }
    printf("]\n");
  }
 
  return 0;
}

Measured memory_bytes: 1784
X,K,D=map(int,input().split())
X=abs(X)


if K*D<=X:
    print(X-K*D)
else:
    x=X//D
    key=x%2
    if x==0:
        if K%2==0:
            print(X)
        else:
            print(abs(X-D))
    else:
        y=X-D*x
        if K%2==key:
            print(y)
        else:
            print(abs(y-D))

Measured memory_bytes: 9220
#include<stdio.h>
#include<string.h>
char comm[100][2000],temp;
int main()
{
int q,i,j,jin,jen,start,p=0,v,w;
char str[1005];
scanf("%s",str);
scanf("%d",&q);
getchar();
for(i=0;i<q;i++)
{
p=0;
scanf("%[^\n]s",comm[i]);
getchar();
if(comm[i][2]=='i')
{
jin=0;
jen=0;
for(v=6;comm[i][v]!=' ';v++)
{
jin=(comm[i][v]-'0')+jin*10;
}
for(v=v+1;comm[i][v]!='\0';v++)
{
jen=(comm[i][v]-'0')+jen*10;
}
for(j=jin;j<=jen;j++)
{
printf("%c",str[j]);
}
printf("\n");
}
else if(comm[i][2]=='v')
{
jin=0;
jen=0;
for(v=8;comm[i][v]!=' ';v++)
{
jin=(comm[i][v]-'0')+jin*10;
}
for(v=v+1;comm[i][v]!='\0';v++)
{
jen=(comm[i][v]-'0')+jen*10;
}
for(j=jin;j<=(jin+jen)/2;j++)
{
temp=str[j];
str[j]=str[jen-p];
str[jen-p]=temp;
p++;
}
}
else
{
jin=0;
jen=0;
for(v=8;comm[i][v]!=' ';v++)
{
jin=(comm[i][v]-'0')+jin*10;
}
for(v=v+1;comm[i][v]!=' ';v++)
{
jen=(comm[i][v]-'0')+jen*10;
}
start=v+1;
for(j=jin;j<=jen;j++)
{
str[j]=comm[i][start];
start++;
}
}
}
return 0;
}


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

using namespace std;

int n,m,f[3001][3001]; string s,t,st;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    getline(cin,s);
    getline(cin,t);
    n=s.length();
    m=t.length();
    for (int i = 0; i <= n; i ++)
    {
        f[i][0]=0;
    }
    for (int i = 0; i <= m; i++)
    {
        f[0][i]=0;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if(s[i-1]==t[j-1])
            {
                f[i][j]=f[i-1][j-1]+1;
            }
            else
            {
                f[i][j]=max(f[i-1][j],f[i][j-1]);
            }
        }
    }
    st="";int i=n,j=m;
    while (i!=0 && j!=0)
    {
        if(s[i-1]==t[j-1])
        {
            st=s[i-1]+st;
            i--;j--;
        }
        else
        {
            if(f[i-1][j]==f[i][j])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    cout << st;
    return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s, p;
    cin >> s >> p;

    s += s;
    s.erase(s.size() - 1, 1);

    string::size_type pos = s.find(p);
    if (pos != string::npos) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1e5 + 5;
ll pref[MAX];
int arr[MAX];
int n, k;

ll range_sum(int left, int right) {
    if(left > right) {
        return 0LL;
    }
    return pref[right] - pref[left - 1];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    int first_positive = -1;
    int f = 1;
    int new_n = n;
    for(int j = 1; j <= n; j++) {
        int now;
        cin >> now;
        if(now == 0) {
            k--;
            new_n--;
            continue;
        }
        arr[f] = now;
        if(first_positive == -1 && arr[f] > 0) {
            first_positive = f;
        }
        pref[f] = pref[f - 1] + arr[f];
        f++;
    }
    if(k == 0) {
        cout << 0 << '\n';
        return 0;
    }
    n = new_n;
    ll ans = (ll) 1e18;
    if(first_positive == -1) {
        ans = abs(arr[n - k + 1]);
    }
    else if(arr[1] > 0) {
        ans = arr[k];
    }
    else {
        fori(i, first_positive, n + 1) {
            if(i < k) {
                continue;
            }
            int pos = i - first_positive + 1;
            int need = k - pos;
            ans = min<ll>(ans, 2 * arr[i] + abs(arr[first_positive - 1 - need + 1]));
        }
        ford(i, first_positive - 1, 1) {
            if(n - i + 1 < k) {
                continue;
            }
            int pos = first_positive - 1 - i + 1;
            int need = k - pos;
            ans = min<ll>(ans, 2 * abs(arr[i]) + arr[first_positive + need - 1]);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1408