akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int t;
    cin >> t;
    rep(at, 0, t){
        int n, k;
        cin >> n >> k;
        vector<int> x(n), d(n);
        int sum = 0;
        rep(i, 0, n){
            cin >> x[i];
        }
        if(n <= k){
            cout << 0 << endl;
            continue;
        }
        rep(i, 1, n){
            d[i] = x[i] - x[i - 1];
            sum += d[i];
        }
        // cout << sum << endl;
        d[0] = 0;
        sort(all(d));
        reverse(all(d));
        rep(i, 0, k - 1){
            sum -= d[i];
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 2524
import sys
import bisect
input = sys.stdin.readline
 
def main():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    cnt=0
    while(cnt<m):
        a.sort()
        a[n-1]=a[n-1]//2
        cnt+=1
        if(cnt==m):
            break
        for i in range(n-1):
            if(a[n-1]<=a[n-i-2]):
                a[n-i-2]=a[n-i-2]//2
                cnt+=1
                if(cnt==m):
                    break
    print(sum(a))


main()

Measured memory_bytes: 14252
# -*- coding: utf-8 -*-

s = [input() for i in range(2)]

N = int(s[0])
S = str(s[1])
x = 0
y = [x]

for j in range(N):
    if  S[j] == "I":
        x = x + 1
        y.append(x)
    else:
        x = x - 1
        y.append(x)

print(max(y))


Measured memory_bytes: 3060
def main():
    s = input()
    n = len(s) - 1
    ans = 0

    for i in range(2**n):
        op = [""] * n
        for j in range(n):
            if (i>>j)&1:
                op[j] = "+"
        tmp = ""
        for a,b in zip(s,op + [""]):
            tmp += a + b
        ans += eval(tmp)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
n = int(input())
a = tuple(int(x) for x in input().split())

memo = tuple([None] * n for _ in range(n))
for i, aa in enumerate(a):
    memo[i][i] = aa

for l in range(n - 1, -1, -1):
    for r in range(l, n):
        if memo[l][r] is None:
            memo[l][r] = max(a[r] - memo[l][r - 1], a[l] - memo[l + 1][r])

print(memo[0][n - 1])


Measured memory_bytes: 164744
#include<stdio.h>

#define N 10000000

int main() {
  int A[101],B[101][101];
  int x,i,j,k,y,z;

  scanf("%d",&x);
  for(i = 1; i <= x; i++) {
    scanf("%d%d",&A[i - 1],&A[i]);
  }

  for(i = 1; i <= x; i++) {
    B[i][i] = 0;
  }

  for(y = 2; y <= x; y++) {
    for(i = 1; i <= x - y + 1; i++) {
      j = i + y - 1;
      B[i][j] = N;

      for(k = i; k < j; k++) {
	z = B[i][k] + B[k + 1][j] + A[i - 1] * A[k] * A[j];
	B[i][j] = (B[i][j] > z) ? z : B[i][j];
      }
    }
  }

  printf("%d\n",B[1][x]);

  return 0;
}
  



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

int gcd(int a, int b){
    if(a%b == 0) return b;
    else return gcd(b, a%b);
}

int main(){
    int k;
    int ans = 0;
    cin >> k;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            int gcdab = gcd(a,b);
            for(int c = 1; c <= k; c++){
                int tmp = gcd(c, gcdab);
                ans = ans + tmp;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

// {time, position, kind}
// kind == 1 if construction starts or -1 if construction ends;
vector<tuple<int, int, int>> events;

vector<int> ans;

int main(void) {
    int N, Q;
    cin >> N >> Q;

    for (int i = 0; i < N; i++) {
        int s, t, x;
        cin >> s >> t >> x;
        events.push_back(make_tuple(s - x, x, 1));
        events.push_back(make_tuple(t - x, x, -1));
    }
    sort(events.begin(), events.end());
    reverse(events.begin(), events.end());

    vector<int> people(Q);
    for (int i = 0; i < Q; i++) {
        int d;
        cin >> d;
        people[i] = d;
    }

    ans.resize(Q);

    multiset<int> constructions;
    for (int i = 0; i < Q; i++) {
        int d = people[i];

        while (events.size() > 0) {
            auto event = events.back();
            int time, pos, kind;
            tie(time, pos, kind) = event;
            if (time > d) {
                break;
            }

            if (kind == 1) {
                constructions.insert(pos);
            } else {
                auto it = constructions.find(pos);
                assert(it != constructions.end());
                constructions.erase(it);
            }

            events.pop_back();
        }

        if (constructions.size() > 0) {
            ans[i] = *(constructions.begin());
        } else {
            ans[i] = -1;
        }
    }

    for (int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 18824
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

calc x y
  | x > 0 && y > 0 && x' < y' = s
  | x > 0 && y > 0 && x' > y' = s + 2
  | x > 0 && y < 0 && x' < y' = s + 1
  | x > 0 && y < 0 && x' >= y' = s + 1
  | x < 0 && y > 0 && x' <= y' = s + 1
  | x < 0 && y > 0 && x' > y' = s + 1
  | x < 0 && y < 0 && x' < y' = s + 2
  | x < 0 && y < 0 && x' > y' = s
  | x == 0 && y > 0 = s
  | x == 0 && y < 0 = s + 1
  | x < 0 && y == 0 = s
  | x > 0 && y == 0 = s + 1
  where
    y' = abs y
    x' = abs x
    s = abs (y' - x')

main = do
  [x, y] <- getIntList
  print $ calc x y


Measured memory_bytes: 3804
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static int n;
    public static int[] a;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        for(int i=n-1;i>=0;i--){
            if(i==0) System.out.printf("%d",a[i]);
            else System.out.printf("%d ",a[i]);
        }
        System.out.printf("\n");
        return;
}
}


Measured memory_bytes: 26432
import random
import sys
import time
import copy

input = sys.stdin.readline

def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(d):
        s.append(list(map(int, input().split())))
    
    start_time = time.time()
    beamwidth = 10
    suff = 0
    # while True:
    #     elapsed_time = time.time() - start_time
    #     if elapsed_time >= 1.8:
    #         break
        
    # ここから
    topk = [{"last": [0 for _ in range(26)], "score": 0, "ans": []} for _ in range(beamwidth)]
    for i in range(d):
        # print(i)
        # print(*topk, sep='\n')
        # 各候補に対して top-k を生成
        nnnnn = []  # top-k * top-k 
        for bi in range(beamwidth):
            last = topk[bi]["last"]
            tmpsufss = []
            for con in range(26):
                tmpsufss.sort(key=lambda x: -x["score"])
                ttttt = topk[bi]["score"] + s[i][con]
                minus = 0
                for j in range(26):
                    if con == j:
                        continue
                    minus -= (i - last[j]) * c[j]
                ttttt += minus

                if len(tmpsufss) < beamwidth:
                    tmpsufss.append({
                        "last": copy.deepcopy(last),
                        "score": ttttt,
                        "ans": copy.deepcopy(topk[bi]["ans"])
                    })
                    tmpsufss[-1]["last"][con] = i
                    tmpsufss[-1]["ans"].append(con)
                else:
                    if tmpsufss[-1]["score"] < ttttt:
                        tmpsufss.pop()
                        tmpsufss.append({
                            "last": copy.deepcopy(last),
                            "score": ttttt,
                            "ans": copy.deepcopy(topk[bi]["ans"])
                        })
                        tmpsufss[-1]["last"][con] = i
                        tmpsufss[-1]["ans"].append(con)
            nnnnn.extend(tmpsufss)

        nnnnn.sort(key=lambda x: -x["score"])
        topk = nnnnn[:beamwidth]
        

    print(*[a + 1 for a in topk[0]["ans"]])

if __name__ == '__main__':
    main()


Measured memory_bytes: 171732
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb((a))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 1005;
using namespace std;
ll n,arr[N],memo[N];
ll solve(ll ind)
{
    if(ind == n-1)
        return 0;
    ll &ans = memo[ind];
    if(~ans)
        return ans;
    ans = 1e9;
    ans = min(ans,solve(ind+1)+abs(arr[ind]-arr[ind+1]));
    if(ind<n-2)
        ans = min(ans,solve(ind+2)+abs(arr[ind]-arr[ind+2]));
    return ans;
}
int main()
{
    abdelrahman001
    memset(memo,-1,sizeof memo);
    cin >> n;
    for(int i = 0;i<n;i++)
        cin >> arr[i];
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll pow(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}



int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){

 // }

   int a,b,c,k;
   cin >> a >> b>> c >> k;
   int sum = 0;
   sum += min(k,a);
   k = max(k-a,0ll);
 	// sum += min(k,b);
   k = max(k-b,0ll);
   sum -= min(k,c);
   k = max(k-c,0ll);
  	cout << sum << endl;

return 0;
	
	}




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

int main() {
    int A,B;
    int a,b;
    cin >> A >> B;
    if (A == 2) {
        a = 0;
    }
    else if (A == 4 || A == 6 || A == 9 || A == 11) {
        a = 1;
    }
    else {
        a = 2;
    }
    
    if (B == 2) {
        b = 0;
    }
    else if (B == 4 || B == 6 || B == 9 || B == 11) {
        b = 1;
    }
    else {
        b = 2;
    }

    if (a == b) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
int t;
ll n,a,b,c,d;
map <ll,ll> mp;
ll f(ll n)
{
    if(mp.count(n))
        return mp[n];
    ll res=n<1e18/d?n*d:(ll)1e18;
    ll l1=(n/2)*2;//向下取整
    ll r1=((n+1)/2)*2;//向上取整
    ll l2=(n/3)*3;
    ll r2=((n+2)/3)*3;
    ll l3=(n/5)*5;
    ll r3=((n+4)/5)*5;
    res=min(res,(n-l1)*d+f(l1/2)+a);
    res=min(res,(r1-n)*d+f(r1/2)+a);
    res=min(res,(n-l2)*d+f(l2/3)+b);
    res=min(res,(r2-n)*d+f(r2/3)+b);
    res=min(res,(n-l3)*d+f(l3/5)+c);
    res=min(res,(r3-n)*d+f(r3/5)+c);
    return mp[n]=res;
}
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n>>a>>b>>c>>d;
        mp.clear();
        mp[0]=0;
        mp[1]=d;
        cout<<f(n)<<endl;
    }

    return 0;
}


Measured memory_bytes: 4500
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;

    cout << c - min(a-b, c) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define BUFMAX 12

int main(){
    char buf[BUFMAX];
    int a,b,c;

    fgets(buf,BUFMAX,stdin);
    buf[BUFMAX-1] = '\0';
    sscanf(buf,"%d %d", &a, &b);
    c = (a + b) / 2;
    printf("%d\n",c);

    return 0;
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  string s; cin>>s;
  int n = s.size();
  int ans = 0;
  for (int i=1; i<n; i++) {
    if (s[i-1] != s[i]) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>  
 
using namespace std;  
   
char table[100][100];  
int w, h;  
const int dir[4][2] = {{ -1, 0 },  { 1, 0 },  { 0, -1 },  { 0, 1 }};  
   

void Dfs(int x, int y, char cur) {
  table[x][y] = 'X';
  for (int i = 0; i < 4; ++i) {
    int next_x = x + dir[i][0];
    int next_y = y + dir[i][1];
    if (next_x >= 0 && next_x < w
        && next_y >=0 && next_y < h
        && table[next_x][next_y] == cur) {
        Dfs(next_x, next_y, cur);
    }
  }
}

int main()  
{  
   
  while (cin >> h >> w, w > 0) {
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> table[j][i];
      }
    }
    int ret = 0;
    for (int i = 0; i < w; ++i) {
      for (int j = 0; j < h; ++j) {
        if (table[i][j] != 'X') {
          Dfs(i, j, table[i][j]);
          ++ret;
        }
      }
    }
    cout << ret << endl;
  }
  return 0;  
} 

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

int main(){
  int N,X,Y;
  cin >>N>>X>>Y;
  vector<int> ans(N,0);
    for(int i=1; i<N+1; i++){
      for(int j=1; j<N+1; j++){
        if(i<j){
        int k = min(abs(j-i),abs(X-i)+1+abs(j-Y));
        ans.at(k)++ ;
        }
      }
    }
  for(int k=1; k<N; k++){
    cout<<ans.at(k)<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

int main() {
	int a, b, c, t;

	std::cin >> t;
	a = t / 3600;
	b = t % 3600 / 60;
	c = t % 3600 % 60;
	std::cout << a << ":" << b << ":" << c << std::endl;
	
	return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	int n, cnt = 1, a = 0;
	cin >> n;
	vector<int> vec(n+2, 0);
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		vec[x] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		if (vec[i] < vec[i + 1])
			cnt++;
		else
		{
			a = max(a, cnt);
			cnt = 1;
		}

	}
	cout << n-a << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int n; cin >> n;
  int c[4] = {0};
  rep(i,n) {
    string s; cin  >> s;
    if (s == "AC") c[0]++;
    else if (s == "WA") c[1]++;
    else if (s == "TLE") c[2]++;
    else if (s == "RE") c[3]++;
  }

  cout << "AC x " << c[0] << endl;
  cout << "WA x " << c[1] << endl;
  cout << "TLE x " << c[2] << endl;
  cout << "RE x " << c[3] << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#define MAX 20
#define INF 1e9

using namespace std;

int H,W,sx,sy,ans;
int field[MAX][MAX];
const int dx[] = {0,0,-1,1};
const int dy[] = {-1,1,0,0};

bool cur(int &x,int &y,int dir,int &g){
  while(true){
    if(0 > x || x >= H || 0 > y || y >= W){
      return false;
    }
    if(field[x][y] == 1){
      field[x][y] = 0;
      x -= dx[dir];
      y -= dy[dir];
      return true;
    }
    if(field[x][y] == 3){
      g = 1;
      return true;
    }

    x += dx[dir];
    y += dy[dir];
  }
}

void solve(int x,int y,int cnt){
  if(field[x][y] == 3){
    ans = min(ans,cnt);
    return;
  }

  if(cnt == 11){
    return;
  }

  for(int i = 0 ; i < 4 ; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];

    if(0 > nx || nx >= H || 0 > ny || ny >= W || field[nx][ny] == 1){
      continue;
    }

    int xx = x, yy = y,g = -1;
    if(cur(xx,yy,i,g)){
      if(g == 1){
	ans = min(ans,cnt);
	return;
      }
      solve(xx,yy,cnt+1);
      xx += dx[i];
      yy += dy[i];
      field[xx][yy] = 1;
    }
  }
 
}

int main(){
  while(cin >> W >> H, W | H){
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cin >> field[i][j];
	
	if(field[i][j] == 2){
	  sx = i;
	  sy = j;
	  field[i][j] = 0;
	}

      }
    }

    ans = INF;
    solve(sx,sy,1);

    if(ans == INF){
      cout << -1 << endl;
    }else{
      cout << ans << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
n = int(input())
s = input()

m = [[0] * n for _ in range(n)]
lcs = 0

# i = 0
for j in range(1, n):
    if s[j] == s[0]:
        m[0][j] = 1
        lcs = 1

# dp
for i in range(1, n-1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            m[i][j] = min(m[i-1][j-1] + 1, j - i)
            lcs = max(m[i][j], lcs)
        else:
            m[i][j] = 0

print(lcs)


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

int main() {
  int n, k, i, ans = 1000000000;
  cin >> n >> k;
  vector<int> h(n);
  for (i = 0; i < n; ++i) {
    cin >> h[i];
  }
  sort(h.rbegin(), h.rend());
  for (i = 0; i + k - 1 < n; ++i) {
    ans = min(ans, h[i] - h[i + k - 1]);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n;
  cin >> n;
  int k[n];
  int minValue = INT_MAX;
  rep(i, n) {
    cin >> k[i];
    minValue = min(minValue, k[i]);
  }
  int dist[n];
  int total = 0;
  rep(i, n) {
    dist[i] = k[i] - minValue;
    total += dist[i];
  }
  int position = total / n;
  int cost1 = 0, cost2 = 0;
  rep(i, n) {
    cost1 += (position - dist[i]) * (position - dist[i]);
    cost2 += ((position + 1) - dist[i]) * ((position + 1) - dist[i]);
  }
  cout << min(cost1, cost2) << endl;
  return 0;
}

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

int main(void){
    int N;
    cin >> N;
    vector<int> v(N);
    for(auto& it : v) cin >> it;
    sort(v.begin(), v.end());
    cout << *(v.rbegin()) - *(v.begin()) << endl;
    return 0;
}

Measured memory_bytes: 256
k, x = map(int, input().split())

if x-k+1 < -1000000:
	ans = list(range(-1000000, x+k))
elif x+k-1 > 1000000:
  	ans = list(range(x-k+1, 1000001))
else:
  	ans = list(range(x-k+1, x+k))

print(*ans)

Measured memory_bytes: 3060
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		//int a = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		//string[] input = Console.ReadLine().Split(' ');
		//int b = int.Parse(input[0]);
		//int c = int.Parse(input[1]);
		// 文字列の入力
		//string s = Console.ReadLine();
		//出力
		//Console.WriteLine((a+b+c) + " " + s);
		
		int n = int.Parse(Console.ReadLine().Replace(" ", ""));
        int m = (int)Math.Sqrt((double)n) * (int)Math.Sqrt((double)n);
        if (n - m == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
	}
}

Measured memory_bytes: 11092
n = int(input())
x = [int(i) for i in input().split()]
mod = 1000000007

fact = [1]*(n+1)
for i in range(1,n+1):
    fact[i] = (fact[i-1]*i)%mod
inv = [1]*(n+1)
inv[n] = pow(fact[n],mod-2,mod)
for i in range(n-1,1,-1):
    inv[i] = (inv[i+1]*(i+1))%mod

l = 0
ans = 0
for i in range(n-2):
    l = (l+x[n-2-i]-x[i])%mod
    f = (fact[n-1]*fact[i]*inv[i+2])%mod
    ans = (ans+l*f)%mod
for i in range(n-1):
    l = (x[n-1]-x[n-2-i])%mod
    ans = (ans+((fact[n-1]*fact[i]%mod)*inv[i+1]%mod)*l%mod)%mod
print(ans)

Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

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

  int len = s.size();
  rep(i, len) if(s[i]=='7'){
    out("Yes");
    return 0;
  }
  out("No");
}


Measured memory_bytes: 3624
s = input()

ans = 0
a = 0
b = 0
for i in range(len(s)):
    if s[i] == 'A':
        if b > 0:
            a = 1
            b = 0
        elif b == 0:
            a += 1
            b = 0
    if s[i] == 'B':
        if a > 0 and b == 0:
            b += 1
        elif b > 0:
            a = 0
            b = 0
    if s[i] == 'C':
        if b > 0:
            ans += a
            b = 0
        elif b == 0:
            a = 0
            b = 0
print(ans)


Measured memory_bytes: 41312
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;


int main() {
	LL a,b,c;
	cin>>a>>b>>c;
	cout<<min(a+b, min(b+c, a+c))<<endl;
	return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,1000) {
    string t;
    int x = i;
    rep(j,3) {
      t += '0'+x%10;
      x /= 10;
    }
    int ti = 0;
    rep(j,n) {
      if (s[j] == t[ti]) {
        ti++;
        if (ti == 3) break;
      }
    }
    if (ti == 3) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3676
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)


def read_matrix(H, W)->np.ndarray:
    '''return np.ndarray shape=(H,W) matrix'''
    lines = []
    for _ in range(H):
        lines.append(read())
    lines = ' '.join(lines)  # byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import

N, K = ints()
A = read_matrix(N, N)


# from numba import njit


# @njit('i8[:,:](i8[:,:],i8[:,:])', cache=True)
def matmul_mod(X: np.ndarray, Y: np.ndarray)->np.ndarray:
    MOD = 10**9 + 7
    # return X @ Y
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    for i in range(X.shape[0]):  # Xの行
        for j in range(Y.shape[1]):  # Yの列
            tmp = (X[i, :] * Y[:, j]) % MOD
            ret[i, j] = tmp.sum() % MOD
    return ret


A_double = np.asanyarray(A, dtype=np.int64)
ans = np.eye(N, dtype=np.int64)
for j in range(int(K).bit_length()):
    if (K >> j) & 1:
        ans = matmul_mod(ans, A_double)
    A_double = matmul_mod(A_double, A_double)

print(ans.sum() % MOD)




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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int w, a, b, ans;
  cin >> w >> a >> b;

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

  if (a + w < b)
    ans = b - a - w;
  else
    ans = 0;
  cout << ans << endl;
  return 0;
}


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

int main() {
  long long N,K;
  cin >> N >> K;
  vector<long long> V(N,0);
  for (long long i = 0; i < N; i++) 
    cin >> V.at(i);
  
  vector<long long> W(110000,2000000000000);
  W.at(0) = 0;
  
  for (long long j = 0; j < N - 1; j++) {
    for (long long k = 1; k <= K; k++) {
      if (j + k < N)
        W.at(j + k) = min(W.at(j + k),W.at(j) + abs(V.at(j) - V.at(j + k)));
    }
  }
  
  cout << W.at(N - 1) << endl;
                              
}

Measured memory_bytes: 4768
package main

import "fmt"

func main() {
	var n int
	var ins []int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var in int
		fmt.Scan(&in)
		ins = append(ins, in)
	}

	var max = ins[0]
	sum := 0
	for i := 0; i < n; i++ {
		sum += ins[i]
		if max < ins[i] {
			max = ins[i]
		}
	}

	fmt.Println(sum - max/2)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int hoge(int x){
  int ans = 0;
  while(x){
    ans+=x%10;
    x/=10;
  }
  return ans;
}

signed main(){
  int n;
  string s, t;
  cin >> s >> t;
  sort(ALL(s));
  sort(ALL(t),greater<int>());
  if(s < t) cout <<"Yes\n";
  else cout <<"No\n";

  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

int num[]={59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1};
                                         //右辺の要素数が[]の中に自動で入る

int count(int a, int cnt){ // ここが動的計画法
  
    if(!a)return cnt; // !a は a == 0 ということ
    for(int i = 0;i < 12;i++)if(a >= num[i]){
        if(i == 11)return cnt + a;
        return min(count(a - num[i], cnt + 1),count(a - num[i + 1], cnt + 1));
                     // 1番大きな引き出し方と2番目を同時に試して少ない方が答え
    }
}

int main(){
    int a;
    cin >> a;
    cout << count(a, 0);
}

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

diff = [i < j for i, j in zip(A[0:], A[1:])]

buy = []
sell = []
is_increasing = False
for i, diff_i in enumerate(diff):
    if is_increasing is False and diff_i is True:
        buy.append(i)
    if is_increasing is True and diff_i is False:
        sell.append(i)
    is_increasing = diff_i
else:
    sell.append(N - 1)

money = 1000
stock = 0
for i in range(N):
    if i in buy:
        stock = money // A[i]
        money -= stock * A[i]
    elif i in sell:
        money += stock * A[i]
        stock = 0

print(money)


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dict = new Dictionary<string, Tuple<int, double>>();
            dict["0.25"] = new Tuple<int, double>(l[0], l[0]*4);
            dict["0.5"] = new Tuple<int, double>(l[1], l[1]*2);
            dict["1"] = new Tuple<int, double>(l[2], l[2]);
            dict["2"] = new Tuple<int, double>(l[3], l[3]*0.5);
            var n = double.Parse(Console.ReadLine());
            
            decimal total = 0;
            foreach (var d in dict.OrderBy(z => z.Value.Item2)) {
                var v = double.Parse(d.Key);
                total += (decimal)Math.Floor(n / v) * d.Value.Item1;
                if (n % v == 0) break;
                else n %= v;
            }
            
            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 13536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld dp[301][301][301];
ll n;
ld p[301];
ld solv(ll cnt1,ll cnt2,ll cnt3)
{
    if(dp[cnt1][cnt2][cnt3]>=-0.5)
        return dp[cnt1][cnt2][cnt3];
    ld ans=1;
    if(cnt1!=0)
        ans+=p[cnt1]*(solv(cnt1-1,cnt2,cnt3));
    if(cnt2!=0)
        ans+=p[cnt2]*(solv(cnt1+1,cnt2-1,cnt3));
    if(cnt3!=0)
        ans+=p[cnt3]*(solv(cnt1,cnt2+1,cnt3-1));
    ld s=p[cnt1+cnt2+cnt3];
    return dp[cnt1][cnt2][cnt3]=ans/s;

}
int main()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
        p[i]=(1.0*i)/((long double)n);
    ll cnt[4];
    cnt[0]=cnt[1]=cnt[2]=cnt[3]=0;
    for(int i=0;i<n;i++)
    {

        ll x;
        cin>>x;
        cnt[x]++;
    }
    for(ll i=0;i<=n;i++)
        for( ll j=0;j<=n;j++)
            for(ll k=0;k<=n;k++)
                dp[i][j][k]=-1;
    dp[0][0][0]=0;;
    cout<<setprecision(10)<<solv(cnt[1],cnt[2],cnt[3])<<endl;
    return 0;
}


Measured memory_bytes: 426368
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int arraySize = scanner.nextInt();
        int[] array = new int[arraySize];
        for (int i = 0; i < arraySize; ++i) {
            array[i] = scanner.nextInt();
        }

        if (arraySize < 3) {
            System.out.println("1");
            return;
        }

        int ans = 1;
        String state = (array[0] > array[1]) ? "decreasing" : (array[0] == array[1]) ? "equal" : "increasing";
        for (int i = 2; i < arraySize; ++i) {
            if (state.equals("restart")) {
                state = (array[i - 1] > array[i]) ? "decreasing" : (array[i - 1] == array[i]) ? "equal" : "increasing";
            } else if (array[i - 1] > array[i]) {
                state = (state.equals("increasing")) ? "restart" : "decreasing";
            } else if (array[i - 1] < array[i]) {
                state = (state.equals("decreasing")) ? "restart" : "increasing";
            }// else {
            //     state = "equal";
            // }

            ans += (state.equals("restart")) ? 1 : 0;
            // System.out.println("i = " + i + ", state = " + state + ", ans = " + ans);
        }

        System.out.println(ans);

    }
}

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

int main()
{
    int N;
    string S;
    cin >> N >> S;

    int ans = 0;
    for (int i=1; i<N; i++) {

        vector<bool> first(26, false);
        vector<bool> second(26, false);
        for (int j=0; j<i; j++) {
            first[S[j]-'a'] = true;
        }
        for (int j=i; j<N; j++) {
            second[S[j]-'a'] = true;
        }

        int count = 0;
        for (int j=0; j<26; j++) {
            if (first[j] && second[j]) {
                count++;
            }
        }

        ans = max(ans, count);

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
Q,H,S,D = [int(x) for x in input().split()]
N = int(input())

ans = 0
t = Q*4
if t>H*2:
    t = H*2
if t>S:
    t = S
if t*2>D:
    ans = (N//2)*D
    N = N%2
ans += t*N
    
print(ans)


Measured memory_bytes: 3316
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=1;i<=9;i++){
		if(n%i==0){
			if(n/i <= 9){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
    return 0;
}
//.........

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int N, M;
int P[101010], Y[101010];
string ids[101010];

string zero_padding(int n)
{
    int keta = 0;
    int nn = n;
    while (nn > 0)
    {
        nn /= 10;
        keta++;
    }
    string s = to_string(n);
    for (int i = 0; i < 6 - keta; i++)
    {
        s = '0' + s;
    }
    return s;
}

int main()
{
    cin >> N >> M;
    vector<vector<pair<int, int>>> PV(N + 1);
    repe(i, 1, M)
    {
        cin >> P[i] >> Y[i];
        PV[P[i]].push_back(make_pair(Y[i], i));
    }
    repe(i, 1, N)
    {
        sort(PV[i].begin(), PV[i].end());
        for (int j = 0; j < PV[i].size(); j++)
        {
            auto e = PV[i][j];
            string id = zero_padding(i) + zero_padding(j + 1);
            ids[e.second] = id;
        }
    }
    repe(i, 1, M)
    {
        cout << ids[i] << endl;
    }
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<char> P(N); for(auto& p : P) cin >> p;
  vector<char> Q(N); for(auto& q : Q) cin >> q;
  string Ps(P.begin(), P.end());
  string Qs(Q.begin(), Q.end());

#if 1
  vector<char> vc{};
  for (int i = 1; i <= N; ++i) {
    vc.push_back('0' + i);
  }

  int a{}, b{};
  int i = 1;
  do {
    string s(vc.begin(), vc.end());
    if (s == Ps) {
      a = i;
    }
    if (s == Qs) {
      b = i;
    }
    ++i;
  } while (std::next_permutation(vc.begin(), vc.end()));
  auto ans = std::abs(a - b);
#else
  std::deque<string> que{};
  que.push_back("");
  vector<string> res{};
  while (!que.empty()) {
    auto s = que.front();
    que.pop_front();
    if ((int)s.size() == N) {
      res.push_back(s);
      continue;
    }
    for (int i = 1; i <= N; ++i) {
      char c = '0' + i;
      if (s.find(c) == s.npos) {
        que.push_back(s + c);
      }
    }
  }
  boost::sort(res, std::less<string>());

  auto Pitr = boost::lower_bound(res, Ps);
  auto Qitr = boost::lower_bound(res, Qs);
  auto Pindex = std::distance(res.begin(), Pitr);
  auto Qindex = std::distance(res.begin(), Qitr);
  auto ans = std::abs(Pindex - Qindex);
#endif

  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  string s;
  cin >> s;
  
  if(s.at(2)==s.at(3) && s.at(4)==s.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }  
}  

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

ll n, m, c[100008], x, y;
string s;

struct union_find {//1-origin
	vector<int> rnk, par;
	union_find(int n) {
		rnk.resize(n);
		par.resize(n);
		for(int i = 0; i < n; i++){
			par[i] = i;
			rnk[i] = 0;
		}
	}
	
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rnk[x] < rnk[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rnk[x] == rnk[y])rnk[x]++;
		}
	}
	
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
};

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m;
	union_find uf(n);
	rep(i, 0, n){cin >> c[i];}
	rep(j, 0, m){
		cin >> x >> y;
		uf.unite(x, y);
	}
	
	set<ll> s;
	priority_queue<P> q;
	rep(i, 0, n){
		s.insert(uf.find(i));
		q.push(P(-c[i], uf.find(i)));
	}
	ll goal = s.size();
	ll task = 2*(goal-1);
	ll use[n];
	ll cnt = 0;
	memset(use, 0, sizeof(use));
	ll ans = 0;
	rep(i, 0, n){
		if(task == 0){break;}
		auto buf = q.top(); q.pop();
		ll cost = -buf.first;
		ll k = buf.second;
		if(use[k] == 0){
			use[k] = 1;
			ans += cost;
			task--;
		}
		else{
			cnt++;
			if(cnt <= goal-2){
				ans += cost;
				task--;
			}
		}
	}
	if(task > 0){
		print("Impossible")
	}
	else{
		print(ans)
	}
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	rep(i,N) cin >> S[i];
	sort(S.begin(),S.end());

	int count = 1;
	int count_max = 1;
	set<string> st;
	st.insert(S[0]);
	for (int i = 1; i < N; i++) {
		if (S[i] == S[i-1]) {
			count++;
		}
		else count = 1;

		if (count == count_max) {
			st.insert(S[i]);
		}
		if (count > count_max) {
			st.clear();
			st.insert(S[i]);
			count_max = count;
		}

	}

	for (string s : st) {
		cout << s << endl;
	}


	return 0;
}


Measured memory_bytes: 25104
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n,m,k;cin>>n>>m>>k;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            int sum=m*i+n*j-i*j*2;
            if(sum==k){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue<int, vector<int>, greater<int> > q;从小到大
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// vector<int>().swap(v);清空释放内存
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;
const db eps=1e-7;
const db pi=acos(-1);
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define rep(i,be,en) for (int i=be;i<=en;i++)
using namespace std;
const int N=1e5+7;

int T,n,m,fl=0;

vector<int> v[N];
int vis[N];

void dfs(int u,int fa){
    rep(i,0,v[u].size()-1){
        int son=v[u][i];
        if(son!=fa&&vis[son]==0){
            vis[son]=u;
            dfs(son,u);
        }
    }
}

void bfs(){
    queue<pair<int,int> > q;
    q.push({1,-1});
    while(!q.empty()){
        auto x=q.front();
        int u=x.first,fa=x.second;
        q.pop();
        rep(i,0,v[u].size()-1){
            int son=v[u][i];
            if(son!=fa&&vis[son]==0){
                vis[son]=u;
                q.push({son,u});
            }
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,m){
        int a,b;
        scanf("%d%d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    bfs();
    rep(i,2,n){
        if(vis[i]==0){
            fl=1;
            break;
        }
    }
    if(fl) puts("No");
    else{
        puts("Yes");
        rep(i,2,n){
            printf("%d\n",vis[i]);
        }
    }

}

Measured memory_bytes: 10212
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    string s, t, rot;
    cin >> s >> t;
    bool yn = false;
    REP(i, s.size()){
        rot = s.substr(i,s.size()-i) + s.substr(0,i);
        if (rot == t) yn = true;
    }
    if (yn) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    //cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC081D solver = new ABC081D();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC081D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int[] pos = new int[2];
            pos[0] = -in.nextInt();
            pos[1] = -in.nextInt();
            ArrayList<Integer> xList = new ArrayList<Integer>();
            ArrayList<Integer> yList = new ArrayList<Integer>();

            int count = 0;
            boolean turnX = true;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'F') count++;
                else if (turnX) {
                    xList.add(count);
                    count = 0;
                    turnX = false;
                } else {
                    yList.add(count);
                    count = 0;
                    turnX = true;
                }
            }
            if (turnX) {
                xList.add(count);
            } else {
                yList.add(count);
            }

            pos[0] += xList.get(0);
            xList.remove(0);
            Collections.sort(xList);
            Collections.sort(yList);

            for (int i = xList.size() - 1; i >= 0; i--) {
                int cn = xList.get(i);
                if (pos[0] < 0) pos[0] += cn;
                else pos[0] -= cn;
            }
            for (int i = yList.size() - 1; i >= 0; i--) {
                int cn = yList.get(i);
                if (pos[1] < 0) pos[1] += cn;
                else pos[1] -= cn;
            }

            String ans = (pos[0] == 0 && pos[1] == 0) ? "Yes" : "No";
            out.println(ans);
        }

    }
}



Measured memory_bytes: 24148
#include <iostream>

int main(){
	int k, s;

	std::cin >> k >> s;

	int n = 0;

	for(int x = 0; x <= k; ++x){
		for(int y = 0; y <= k; ++y){
			if(s - x - y <= k && s - x - y >= 0)++n;
		}
	}

	std::cout << n << std::endl;

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    dp()
}

fun dp() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val dp = Array(n) {3 * 10e5.toInt()}
    dp[0] = s.drop(1).filter { it == 'E' }.count()

    for (i in 1 until n) {
        if (s[i - 1] == 'E' && s[i] == 'E') {
            dp[i] = dp[i - 1] - 1
        } else if (s[i - 1] == 'W' && s[i] == 'W') {
            dp[i] = dp[i - 1] + 1
        } else {
            dp[i] = dp[i - 1]
        }
    }

    println(dp.min()!!)
}

Measured memory_bytes: 50516