akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
 
int main(){
	int i;
	int N,M;
	cin>>N>>M;

	if(N>=M){
		cout<<0<<endl;
	}
	else{
		int X[M],K=0,Kyori[M-1],ten;
		for(i=0;i<M;i++){
			cin>>X[i];
		}
		sort(X, X+M);// 配列
		for(i=0;i<M-1;i++){
			Kyori[i] = X[i+1] - X[i];
		}
		sort(Kyori, Kyori+M-1);
		ten = M-N;
		for(i=0;i<ten;i++){
			K +=Kyori[i];
		}
		cout<<K<<endl;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    std::vector<std::vector<int>> edg(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v; std::cin >> u >> v;
        u--; v--;
        edg[u].push_back(v);
        edg[v].push_back(u);
    }

    std::vector<int> dp(n + 4, 1e9 + 2), ans(n + 4);
    dp[0] = 0;
    auto func = [&](auto &self, int pos, int prev = -1) -> void {
        auto iter = std::lower_bound(dp.begin(), dp.end(), a[pos]);
        const int len = iter - dp.begin();
        const int prevv = dp[len];

        dp[len] = a[pos];
        ans[pos] = std::lower_bound(dp.begin(), dp.end(), 1e9 + 2) - dp.begin() - 1;

        for (int to : edg[pos]) {
            if (to == prev) continue;
            self(self, to, pos);
        }
        
        dp[len] = prevv;
    };
    func(func, 0);
    for (int i = 0; i < n; i++) std::cout << ans[i] << std::endl;
    return 0;
}


Measured memory_bytes: 30904
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int  long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 998244353
// order_of_key and *find_by_order
#define N 100001
int32_t main() {
	fast;
	int h, w, k;
	cin >> h >> w >> k;
	string s[h];
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	int cnt = 0;
	for (int i = 0; i < (1 << h); i++) {
		for (int j = 0; j < (1 << w); j++) {
			map<pair<int , int >, int  > m;
			int p = i;
			int c = 0;
			while (p) {
				if (p & 1) {
					for (int k = 0; k < w; k++) {
						m[ {c, k}] = 1;
					}
				}
				p /= 2;
				c++;
			}
			p = j;
			c = 0;
			while (p) {
				if (p & 1) {
					for (int k = 0; k < h; k++) {
						m[ {k, c}] = 1;
					}
				}
				p /= 2;
				c++;
			}
			int to = 0;
			for (int u = 0; u < h; u++) {
				for (int v = 0; v < w; v++) {
					if (m[ {u, v}] == 0 and s[u][v] == '#')
						to++;
				}
			}
			if (to == k)
				cnt++;
		}
	}
	cout << cnt;


}











Measured memory_bytes: 3664
#include <iostream>
#include <vector> 
#include <set>
using namespace std ;
#define endl "\n"
#define int long long int 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


int32_t main()
{
  IOS;

/*#ifndef ONLINE_JUDGE 
    freopen("input.txt","r",stdin) ;
    freopen("output.txt","w",stdout) ;
  #endif*/
  
  int n , x ;
  cin >> n >> x ;
  vector<int>l(n+1);
  vector<int>d(n+1);
  int answer = 1 ;
  for(int i = 0 ; i < n ; i++ ){
    cin >> l[i] ;
    d[i+1] = d[i] + l[i] ;
    if(d[i+1] <= x )answer++;
  }
  cout<<answer<<endl;
  return  0 ;
} 


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
const int maxn = 15;

int n, m, f[1<<maxn][maxn], cost[1<<maxn], dis[maxn][maxn];

int calc(int s,int t){return cost[s|t]-cost[s]-cost[t];}
void upd(int &a,int b){a = (a < b ? a : b);}
int main()
{
	scanf("%d%d",&n,&m);
	fo(i,1,m)
	{
		int x, y, z; scanf("%d%d%d",&x,&y,&z);
		-- x; -- y; dis[x][y] = dis[y][x] = z;
	}
	fo(i,0,(1<<n)-1)
		fo(j,0,n-1) if(i&(1<<j))
			fo(k,j+1,n-1) if((i&(1<<k))&&dis[j][k])
				cost[i] += dis[j][k];
	memset(f,0x3f,sizeof(f));
	f[1][0] = 0;
	fo(s,0,(1<<n)-1) fo(i,0,n-1) if(f[s][i]!=0x3f3f3f3f&&(s&(1<<i)))
	{
		fo(j,0,n-1) if((!(s&(1<<j)))&&dis[i][j])
			upd(f[s|(1<<j)][j], f[s][i] + calc(s-(1<<i),(1<<j)));
		int t = (1<<n)-1-s;
		for(int y = t; y >= 1; y = ((y-1)&t))
			upd(f[s|y][i], f[s][i] + calc(s-(1<<i),y));
	}
	printf("%d\n",f[(1<<n)-1][n-1]);
	return 0;
}


Measured memory_bytes: 2304
N = int(input())
N -= 1
S = str(input())
count = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
    for j in range(i,N+1):
        k = 2*j - i
        if k > N:
            pass
        elif S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
            pass
        else:
            count -= 1
print(count)

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

using namespace std;

bool is_ok(vector<vector<char>> &seq, int n, int m, int h, int d) {
  int cur = m - 1;
  for (int i = 0; i < d; ++i) {
    if ( (0 < cur) && (seq[i][cur-1] == '1') )
      --cur;
    else if ( (cur < n - 1) && seq[i][cur] == '1')
      ++cur;
  }
  return cur == (h - 1);
}

int main() {

  while (true) {
    int n, m, h, d;

    cin >> n >> m >> h >> d;

    if (cin.fail())
      break;

    vector<vector<char>> seq(d, vector<char>(n-1));

    for (int i = 0; i < d; ++i)
      for (int j = 0; j < n-1; ++j)
        cin >> seq[i][j];


    bool det1 = is_ok(seq, n, m, h, d);
    bool det2 = false;

    int i, j;
    for (i = 0; i < d && !det2; ++i) {
      for (j = 0; j < n-1 && !det2; ++j) {
        vector<vector<char>> seq2 = seq;
        if ( (j == 0 || seq2[i][j-1] == '0') && (j == n-2 || seq2[i][j+1] == '0') )
          seq2[i][j] = '1';
        if (is_ok(seq2, n, m, h, d))
          det2 = true;
      }
    }

    if (det1)
      cout << 0 << endl;
    else if (det2)
      cout << i << " " << j << endl;
    else
      cout << 1 << endl;
  }
}


Measured memory_bytes: 3080
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static final String SHARP = "#";
	private static final String DOT = ".";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] sH = new String[H];
		String[][] s = new String[H + 2][W + 2];

		for (int i = 0; i < H + 1; i++) {
			Arrays.fill(s[i], "C");
		}

		for (int i = 0; i < H; i++) {
			sH[i] = sc.next();
		}

		for (int i = 1; i < H + 1; i++) {
			for (int j = 1; j < W + 1; j++) {
				s[i][j] = sH[i - 1].split("")[j - 1];
			}
		}

		int count = 0;
		for (int i = 1; i < H + 1; i++) {
			for (int j = 1; j < W + 1; j++) {
				count = 0;
				if (SHARP.equals(s[i][j])) {
					System.out.print(SHARP);
				} else if (DOT.equals(s[i][j])) {
					if (SHARP.equals(s[i - 1][j - 1])) count++;
					if (SHARP.equals(s[i - 1][j])) count++;
					if (SHARP.equals(s[i - 1][j + 1])) count++;
					if (SHARP.equals(s[i][j - 1])) count++;
					if (SHARP.equals(s[i + 1][j - 1])) count++;
					if (SHARP.equals(s[i][j + 1])) count++;
					if (SHARP.equals(s[i + 1][j])) count++;
					if (SHARP.equals(s[i + 1][j + 1])) count++;
					System.out.print(count);
				}
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 37248
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main() {
    ll a,b,c;
    cin>> a>>b>>c;
    cout<<a+b+c-max({a,b,c})<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

struct Team {
    int id;
    i64 score;

    Team(int id=0, i64 score=0) : id(id), score(score) {}
    bool operator> (const Team &o) const {
        if (score == o.score) {
            return id < o.id;
        } else {
            return score > o.score;
        }
    }
    bool operator< (const Team &o) const {
        if (score == o.score) {
            return id > o.id;
        } else {
            return score < o.score;
        }
    }
};

template<class Monoid> struct SegTree { // {{{
    using Func = function<Monoid(Monoid, Monoid)>;
    const int sz;
    const Func fn;
    const Monoid unity;
    vector<Monoid> dat;

    SegTree(int n, const Monoid &u, Func f)
        : sz(1 << (__lg(n+5) + 1)), fn(f), unity(u), dat(sz*2, unity) {}

    void set(int k, const Monoid &v) { dat[k + sz] = v; }

    Monoid& operator[] (int k) { return dat[k + sz]; }

    void build() { for (int k = sz-1; k > 0; --k) dat[k] = fn(dat[2*k], dat[2*k+1]); }

    void update(int k, const Monoid &v) {
        dat[ k += sz ] = v;
        while(k >>= 1) dat[k] = fn(dat[2*k], dat[2*k+1]);
    }

    Monoid query(int a, int b) const {
        Monoid L = unity,  R = unity;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = fn(L, dat[a++]);
            if (b & 1) R = fn(dat[--b], R);
        }
        return fn(L, R);
    }
}; // }}}

int d[1000100];
int t[1000100];
i64 x[1000100];

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N, R, L;
    cin >> N >> R >> L;

    for (int i = 1; i <= R; ++i) {
        cin >> d[i] >> t[i] >> x[i];
    }

    SegTree<Team> seg(N, Team(0, -LINF), [](const Team &a, const Team &b) { return (a > b) ? a : b; });

    for (int i = 1; i <= N; ++i) {
        seg.update(i, Team(i, 0));
    }

    vector<i64> tsum(N+1, 0);

    for (int i = 1; i <= R; ++i) {
        const auto top = seg.query(1, N+1);
        tsum[top.id] += t[i] - t[i-1];

        const auto p = seg[d[i]];
        seg.update(d[i], Team(d[i], p.score + x[i]));
    }
    const auto top = seg.query(1, N+1);
    tsum[top.id] += L - t[R];

    int longest = *max_element(begin(tsum) + 1, end(tsum));

    for (int i = 1; i <= N; ++i) {
        if (tsum[i] == longest) {
            cout << i << endl;
            return 0;
        }
    }



    return 0;
}

// vim: set foldmethod=marker :



Measured memory_bytes: 17884
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int h[] = new int[n];
    for(int i = 0 ; i < n ; ++i){
      h[i] = sc.nextInt();
    }
    
    Arrays.sort(h);
    
    long ans = 0;
    
    for(int i = 0 ; i < n-k ; ++i){
      ans += h[i];
    }

    System.out.println(ans);
    
  }
}

Measured memory_bytes: 61096
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<int>num(N,0);
  
  for(int i=0;i<N;i++){
    cin >> num[i];
  }
  
  int mul_4 = 0;
  int mul_2 = 0;
  
  for(int i=0;i<N;i++){
    if(num[i] % 4 == 0)
      mul_4++;
    else if(num[i] % 2 == 0)
      mul_2++;
  }
  
  bool can = false;
  
  if(mul_4 >= N / 2)
    can = true;
  else if(mul_4 * 2 + mul_2 >= N)
    can = true;
  
  if(can)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,ii> iii;
typedef pair<int, iii> iiii;
typedef pair<double, ii> dii;
typedef long long ll;
typedef pair<ll, ii> lii;
const int INF = 1000000000;
const double EPS = 1e-9;
#define LSOne(S) (S & (-S))
int mods(int a, int b) { return (b + (a%b)) % b; }

const int MOD = 1e9 + 7;
int r, c;
ll dp[1005][1005];
char grid[1005][1005];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    cin >> r >> c;

    for (int i = 0; i < r; i++)
        for (int j = 0; j < c; j++)
            cin >> grid[i][j];

    dp[0][0] = 1;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            if (grid[i][j] == '.') {
                if (j+1 < c && grid[i][j+1] == '.') dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % MOD;
                if (i+1 < r && grid[i+1][j] == '.') dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;
            }
        }
    }

    cout << dp[r-1][c-1] << '\n';
     
    return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif    

    string a;
    cin>>a;
    int mx=0;
    for(int i=0;i<3;i++)
    {
        int cnt=0;
        while (i<3 && a[i]=='R')
        {
            i++;
            cnt++;
        }
        mx=max(mx,cnt);        
    }
    cout<<mx;

}


Measured memory_bytes: 3624
while 1:
    n = int(input())
    if n == 0:break
    s = []
    for _ in range(n):s.append(tuple(map(int, input().split())))
    l = tuple(map(int, input().split()))
    e = []
    for i in range(n):
        if s[i][1] <= l[0] and s[i][2] <= l[1] and s[i][3] <= l[2] and s[i][1] * 4 + s[i][2] * 9 + s[i][3] * 4 <= l[3]:e.append(s[i][0])
    if e != []:
        for i in e:print(i)
    else:print("NA")


Measured memory_bytes: 5960
#include<stdio.h>
int main(void){
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0) break;
        if(x>y){
            printf("%d %d\n",y,x);
        }
        else {
            printf("%d %d\n",x,y);
        }
    }
}


Measured memory_bytes: 1984
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
int h,w;
char maze[50][50];
int d[50][50];
const int INF = 1e9;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int bfs(){
  queue<pair<int,int> > que;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      d[i][j]=INF;
    }
  }
  que.push(make_pair(0,0));
  d[0][0]=0;
  while(que.size()){
    pair<int,int> tmp = que.front();
    que.pop();
    if(tmp.first == h-1&&tmp.second == w-1) break;
    for(int i = 0; i < 4; i++){
      int nx = dx[i] + tmp.first;
      int ny = dy[i] + tmp.second;
      if(nx>=0&&nx<h&&ny>=0&&ny<w&&d[nx][ny]==INF&&maze[nx][ny]=='.'){
        que.push(make_pair(nx,ny));
        d[nx][ny] = d[tmp.first][tmp.second]+1;
      }
    }
  }
  return d[h-1][w-1];
}

int main(){
  cin>>h>>w;
  int cnt = 0; 
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin>>maze[i][j];
      if(maze[i][j]=='#') cnt++;
    }
  }
  int res = bfs();
  if(res==INF){
    cout<<-1<<endl;
  }
  else cout<<h*w-res-cnt-1<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var n = consoleReader.Int;
            var a = consoleReader.Split.Double;
            Array.Sort(a);
            var current = a[0];
            for (int i = 1; i < a.Length; i++)
            {
                current = (current + a[i]) / 2;
            }
            return current;
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader
    {
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = textReader.ReadLine().Split();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.textReader.ReadLine().Split(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

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

int main(){
    // int N; cin>>N;
    int N = 3;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A, A+N);
    
    int cost = 0;
    for(int i = 1; i < N; i++){
        cost += abs(A[i] - A[i-1]);
    }
    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int a[7]={0},x;
      for(;n--;)
	{
	  cin>>x;
	  x=x/10;
	  if(x>6)
	    x=6;
	  a[x]++;
	}
      for(int i=0;i<7;i++)
	cout<<a[i]<<endl;
    }

}

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

int main(){
	// sengen
	int n,m;
	// nyuryoku
	cin >> n >> m;
	int s[m],c[m];
	for(int i=0;i<m;i++){
		cin >> s[i] >> c[i];
	}
	// keisan
	int keta[n];
	int count = 0;
	int ans = -1;
	if(m==0 && n==1){
		ans = 0;
		goto END;
	}else if(m==0 && n==2){
		ans = 10;
		goto END;
	}else if(m == 0 && n == 3){
		ans = 100;
		goto END;
	}
	if(n == 1){
		for(int i=0;i<10;i++){
			for(int j=0;j<m;j++){
				if(i != c[j]){
					break;
				}
				if(j == m-1){
					ans = i;
					goto END;
				}
			}
		}
	}else{
		for(int i=10;i<1000;i++){
			count = 0;
            int kari = i;
			while(kari>0){
				keta[count] = kari%10;
				kari = kari/10;
				count++;
			}
			if(count  != n){
				continue;
			}
			reverse(keta,keta + n);
			for(int j=0;j<m;j++){
				if(keta[s[j]-1] != c[j]){
					break;
				}
				if(j == m-1){
					ans = i;
					goto END;
				}
			}
		}
	}
	// syutsuryoku
	END : cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pa pair<int,int>
#define pii pair<ll,ll>
#define st first
#define nd second
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
const int MAX=200005;
int tab[MAX];
int main()
{
  BOOST;
  ll ans=0;
  int n,k;
  cin>>n>>k;
  for (int i=1;i<=n;i++)
  {
    cin>>tab[i];
  }

  sort(tab+1,tab+n+1,greater<int>());
  for (int i=1;i<=min(n,k);i++)
  {
    tab[i]=0;
  }

  for (int i=1;i<=n;i++)
  {
    ans+=tab[i];
  }

  cout<<ans;
  return 0;
}


Measured memory_bytes: 1024
def comb(n, r, p):
    num, den = 1, 1
    r = min(r, n - r)
    for i in range(1, r + 1):
        num = num * (n - i + 1) % p
        den = den * i % p
    return num * pow(den, p - 2, p) % p


n, a, b = map(int, input().split())
MOD = 1_000_000_007
ans = pow(2, n, MOD)
ans %= MOD
ans -= comb(n, a, MOD)
ans %= MOD
ans -= comb(n, b, MOD)
ans %= MOD
ans -= 1
ans %= MOD
print(ans)


Measured memory_bytes: 9156
#include <iostream>
#include <iomanip>

using namespace std;

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

    for (int bit = 0; bit < 1<<(n-1); bit++){
        // cout << setfill('0') << bitset<3>(bit) << endl;
        int sum = s[0] - '0';
        /* +-を挿入した文字列tを作成する。*/
        for (int i = 1; i < n; i++){
            if (bit & (1 << (i-1))){
                sum += s[i] - '0';
            } else {
                sum -= s[i] - '0';
            }
        }
        if (sum == 7){
            string t;
            for (int i = 0; i < n-1; i++){
                t += s[i];
                if (bit & (1 << i)){
                    t += '+';
                } else {
                    t += '-';
                }
            }
            t += s[n-1];
            t += '=';
            t += to_string(sum);
            cout << t << endl;
            return 0;
        }
    }
}


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

int main() {
  int a, b, c;
  int count = 0;
  cin >> a >> b >> c;
  if (a == b) count++;
  if (b == c) count++;
  if (a == c) count++;
  if (count == 3) count--;
  cout << 3 - count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;


int main(){
	string s,t,u;
	cin>>s>>t>>u;
	int a=(int)s.length();
	int b=(int)t.length();
	int c=(int)u.length();
	queue<char> aq,bq,cq;
	rep(i,a)aq.push(s[i]);
	rep(i,b)bq.push(t[i]);
	rep(i,c)cq.push(u[i]);
	char flag='a';
	char win;
	while(true){
		if(flag=='a'){
			if(aq.empty()){
				win='A';
				break;
			}
			else{
				flag=aq.front();
				aq.pop();
			}
		}
		if(flag=='b'){
			if(bq.empty()){
				win='B';
				break;
			}
			else{
				flag=bq.front();
				bq.pop();
			}
		}
		if(flag=='c'){
			if(cq.empty()){
				win='C';
				break;
			}
			else{
				flag=cq.front();
				cq.pop();
			}
		}
	}
	cout<<win<<endl;
}

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/ 4
// Problem:ABC 089 _ d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

// D: 進む量
int H, W, D;
pair< int, int > dist[90909];
int memo[90909];

int solve(int x)
{
  if (memo[x] != 0) return memo[x];
  if (x < D) return 0;

  int tmp = abs(dist[x].first - dist[x - D].first) + abs(dist[x].second - dist[x - D].second);
  return memo[x] = solve(x - D) + tmp;
}

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

  memset(memo, 0, sizeof(memo));
  cin >> H >> W >> D;
  int t;
  REP(hi, H) {
    REP(wi, W) {
      cin >> t;
      dist[t - 1] = {wi, hi};
    }
  }

  int Q;
  cin >> Q;
  REP(qi, Q) {
    int l, r;
    ll ans;
    cin >> l >> r;
    ans = solve(r - 1) - solve(l - 1);
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

vector<int> prime_vector(int n) {
    vector<int> p;
    vector<char> q(n);
    int m = (int)sqrt(n - 1);

    for (int i = 2; i <= m; i++) {
        if (q[i] != 0) continue;
        for (int j = i * i; j < n; j += i) {
            q[j] = 1;
        }
    }
    for (int i = 2; i < n; i++) {
        if (q[i] == 0) p.push_back(i);
    }
    return p;
}

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

    auto v = prime_vector(100000);
    vector<int> a(100002);
    for (int i = 0; i < v.size(); i++) {
        a[v[i]] = 1;
    }
    for (int i = 100000; i >= 0; i--) {
        if (a[i] && !a[(i + 1) / 2]) a[i] = 0;
    }
    a[2] = 0;
    for (int i = 1; i <= 100000; i++) {
        a[i] += a[i - 1];
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        cout << a[r] - a[l - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, k = gi()
a = gi()
ans = 0
temp = 0
for j in range(k):
	ans += (a[j] * (a[j] + 1)) / (2 * a[j])
temp = ans
for j in range(k, n):
	temp -= (a[j - k] * (a[j - k] + 1)) / (2 * a[j - k])
	temp += (a[j] * (a[j] + 1)) / (2 * a[j])
	ans = max(ans, temp)
print(ans)

Measured memory_bytes: 24804
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <climits>
#include <algorithm>

using namespace std;

struct Tag {
    int x, y, level;
    Tag() {}
    Tag(int xx, int yy, int l) : x(xx), y(yy), level(l) {}
};

bool operator < (const Tag &t1, const Tag &t2) {
    return t1.level > t2.level;
}

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void check(vector<vector<int> > &room, vector<pair<int, int> > &v, int sx, int sy) {
    int W = room[0].size();
    int H = room.size();

    priority_queue<Tag> q;
    q.push(Tag(sx, sy, room[sy][sx]));
    room[sy][sx] = 0;
    int level = 0;
    int cnt = 0;

    while(!q.empty()) {
        int x = q.top().x;
        int y = q.top().y;
        int lv = q.top().level;
        q.pop();

        if(lv > level) {
            v.push_back(make_pair(level, cnt));
            level = lv;
        }
        ++cnt;

        for(int i = 0; i < 4; ++i) {
            int nx = x+dx[i];
            int ny = y+dy[i];
            if(nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
            if(room[ny][nx] == 0) continue;
            q.push(Tag(nx, ny, room[ny][nx]));
            room[ny][nx] = 0;
        }
    }
    v.push_back(make_pair(level, cnt));
}

int main() {
    while(true) {
        int R;
        cin >> R;
        if(!R) break;

        vector<pair<int, int> > v[2];
        for(int K = 0; K < 2; ++K) {
            int W, H, X, Y;
            cin >> W >> H >> X >> Y;
            vector<vector<int> > room(H, vector<int>(W));
            for(int i = 0; i < H; ++i) {
                for(int j = 0; j < W; ++j) {
                    cin >> room[i][j];
                }
            }
            check(room, v[K], X-1, Y-1);
        }

        int ans = INT_MAX;
        for(int i = 0; i < v[0].size(); ++i) {
            int l = v[0][i].first;
            int rem = R-v[0][i].second;
            //cout << l << ':' << rem << endl;
            if(rem <= 0) {
                ans = min(ans, l);
                break;
            }

            int left = 0, right = v[1].size();
            while(left < right) {
                int center = (left+right)/2;
                int cr = v[1][center].second;
                if(cr < rem) left = center+1;
                else right = center;
            }
            if(left >= v[1].size()) continue;
            ans = min(ans, l+v[1][left].first);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, d, x;
  cin >> n >> d >> x;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    for(int j = 1; j <= d; j += a){
      ans++;
    }
  }
  cout << ans + x << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String n = a+b;
    int k = Integer.parseInt(n);
    int kk = (int)(Math.sqrt(k));
    System.out.println(Math.pow(kk, 2) == k ? "Yes" : "No");
  }
}

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

#define mod 1000000007
#define modd 998244353
#define PI 3.1415926
#define ll long long
#define ld long double
#define pb push_back
#define popb pop_back
#define beg begin()
#define en end()
#define sz(v) (int)((v).size())
#define all(v) (v).begin(),(v).end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define endl "\n"
#define forn(i,a,n) for(int i=a;i<int(n);++i)
#define forb(i,a,n) for(int i=int(n)-1;i>=a;--i)
#define cout(ans) cout<< ans << "\n"
#define couts(ans) cout<< ans <<" "
#define coutss(a,b) cout<< a <<" "<< b << "\n"
#define coutsm(a,b,c) cout<< a <<" "<< b <<" "<< c << "\n"
#define maxx *max_element
#define minn *min_element


void speed()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
}

void solve()
{      
    int n;cin>>n;
    ld p[n];
    forn(i,0,n)
    {
        cin>>p[i];
    }
    ld dp[n+1][n+1];
    // memset(dp,0,sizeof(dp));
    forn(i,0,n+1)
    {
        forn(j,0,n+1)
        {
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    forn(i,1,n+1)
    {
        forn(j,0,i+1)
        {
            if(j)
                dp[i][j]=dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1];
            else
                dp[i][j]=dp[i-1][j]*(1-p[i-1]);
        }
    }
    ld ans=0;
    forn(i,1,n+1)
    {
        if(i>(n-i))
        {
            ans+=dp[n][i];
        }
    }
    cout<<fixed<<setprecision(9)<<ans<<endl;

}


int main()
{   
    speed();
    int tc=1;
    // cin>>tc;
    while(tc--)
    {
        solve();
    }
}

Measured memory_bytes: 144464
#include<iostream>
#include <cmath>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    int h,a;
    cin >> h >> a;
    
    int ret = ceil((double)(h) / a);
    
    // 出力
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    rep(i, N){
        cin>>A[i];
    }
    sort(ALL(A));
    vector<bool> OK(N, true);
    rep(i, N-1){
      	if(A[i]==A[i+1]){
          	OK[i]=false;
          	OK[i+1]=false;
        }
    }
    vector<bool> P(1000001, true);
    rep(i, N){
        if(P[A[i]]){
            for(ll j=0; A[i]*j<=1000000; j++){
                P[A[i]*j]=false;
            }
        }
        else{
            OK[i]=false;
        }
    }
    ll Ans=0;
    rep(i, N){
        if(OK[i])Ans++;
    }
    cout<<Ans<<endl;
}
     

Measured memory_bytes: 5068
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const int INF = 1<<30;

struct Edge {
    int to, cost;
    Edge(int to, int cost) : to(to), cost(cost) {}
};

struct S {
    int v, cost;
    S(int v=0, int cost=0) : v(v), cost(cost) {}
    bool operator<(const S& s) const {
        return cost > s.cost;
    }
};

int V, E;
vector< vector<Edge> > G;
int main() {
    cin >> V >> E;
    int r; cin >> r;
    G.clear(); G.resize(V);
    for (int i = 0; i < E; i++) {
        int s, t, d; cin >> s >> t >> d;
        G[s].push_back(Edge(t, d));
    }

    vector<int> D(V, INF);
    D[r] = 0;
    priority_queue<S> PQ;
    PQ.push(S(r, 0));
    while (!PQ.empty()) {
        S c = PQ.top(); PQ.pop();
        for (int i = 0; i < G[c.v].size(); i++) {
            Edge& e = G[c.v][i];
            int ncost = D[c.v] + e.cost;
            if (D[e.to] > ncost) {
                D[e.to] = ncost;
                PQ.push(S(e.to, ncost));
            }
        }
    }
    for (int i = 0; i < V; i++) {
        if (D[i] == INF) {
            cout << "INF" << endl;
        } else {
            cout << D[i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 11216
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<"debug... "<<n1<<"\n"
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> arr(n);
    rep (i,0,n)
    {
        cin>>arr[i];
    }
    ll ans=0,mn=1e10;
    rep (i,0,n)
    {
        mn=min(mn,arr[i]);
        if (mn==arr[i])
        {
            ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
set<char> se;
bool check(int x){
    bool res = true;
    string s = to_string(x);
    rep(i, 0, s.size()){
        if (se.find(s[i]) != se.end()) res = false;
    }
    return res;
}

int main(){
    int n, k, ans;
    char d;
    sc(n), sc(k);
    rep(i, 0, k) cin >> d, se.insert(d);
    rep(i, n, 10*n){
        ans = i;
        if (check(ans)) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n;
	scanf("%d",&n);
	int a[n];
	int i;
	int max = 0;
	int sum = 0;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(max < a[i])max = a[i];
		sum += a[i];
	}
	//全ての合計からmax*2を引いてそれが0以上ならok
	if( sum-max*2 >0){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
S = input()

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  i = S.find(p[0])
  if i >= 0:
    j = S[i + 1 :].find(p[1])
    if j >= 0:
      k = S[i + j + 2 :].find(p[2])
      if k >= 0:
        ans += 1
print(ans)

Measured memory_bytes: 38512
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[3];
		str[0] = sc.nextLine();
		str[1] = sc.nextLine();
		str[2] = sc.nextLine();
		boolean f = true;
		int i = 0;
		while(f) {
			if(str[i].substring(0,1).equals("a")){
				str[i] = str[i].substring(1,str[i].length());
				i = 0;
			}else if(str[i].substring(0,1).equals("b")){
				str[i] = str[i].substring(1,str[i].length());
				i = 1;
			}else if(str[i].substring(0,1).equals("c")){
				str[i] = str[i].substring(1,str[i].length());
				i = 2;
			}
			if(str[i].equals("")){
				if(i == 0) {
					System.out.println("A");
					return;
				}else if(i == 1) {
					System.out.println("B");
					return;
				}else if(i == 2) {
					System.out.println("C");
					return;
				}
			}
		}
	}
}

Measured memory_bytes: 21972
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,a[100111];
int main()
{
	get1(n);
	int win=0;
	for(int i=1;i<=n;i++)
	{
		get1(a[i]);
		win^=(a[i]-1)&1;
	}
	if(win)puts("First");
	else
	{
		int cur=win,last=win;
		while(true)
		{
			int odd=0;
			for(int i=1;i<=n;i++)
			{
				if(a[i]&1)
				{
					if(odd==0)odd=i;
					else
					{
						odd=0;
						break;
					}
				}
			}
			if(odd==0||a[odd]==1)break;
			a[odd]--;odd=0;
			for(int i=1;i<=n;i++)if(odd==0)odd=a[i];else odd=__gcd(odd,a[i]);
			for(int i=1;i<=n;i++)a[i]/=odd;
			odd=0;for(int i=1;i<=n;i++)odd^=(a[i]-1)&1;
			if(last^odd)break;
			last=odd;
			cur^=1;
		}
		puts(cur?"First":"Second");
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

// 素因数を数列で返す。N の数が大きくても大丈夫
// ソートされていないので注意すること
template <class T> map<T, long long> factring_sequence(T N) {
    map<T, long long> ans;
    long long i = 2;
    while (i * i <= N) {
        if (N % i == 0) {
            ans[i]++;
            N /= i;
        } else {
            i++;
        }
    }
    if (N != 1)
        ans[N]++;
    return ans;
};

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

    ll N, P;
    cin >> N >> P;

    auto fac = factring_sequence<ll>(P);
    ll ans   = 1;
    for (auto &&i : fac) {
        ll cnt = i.second / N;
        if (N <= i.second)
            REP(j, cnt) ans *= i.first;
    }

    print(ans);

    return 0;
}

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

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

	int n;
	int num;
	string kind;
	cin >> n;
	vector<int> card(52);
	for (int i = 0; i < n; i++){
		cin >> kind;
		cin >> num;
		switch (kind[0]){
		case 'H':
			num += 13;
			break;
		case 'C':
			num += 26;
			break;
		case 'D':
			num += 39;
			break;
		}
		card[num - 1] = 1;
	}
	for (int i = 0; i < 13; i++){
		if (card[i] == 0){
			cout << 'S' << ' ' << i + 1 << '\n';
		}
	}
	for (int i = 13; i < 26; i++){
		if (card[i] == 0){
			cout << 'H' << ' ' << i - 12 << '\n';
		}
	}
	for (int i = 26; i < 39; i++){
		if (card[i] == 0){
			cout << 'C' << ' ' << i - 25 << '\n';
		}
	}
	for (int i = 39; i < 52; i++){
		if (card[i] == 0){
			cout << 'D' << ' ' << i - 38 << '\n';
		}
	}

	return 0;
}


Measured memory_bytes: 3148
package main
import (
	"fmt"
)

func notExist(l []int, i int) bool{
  flag := true
  for _, v := range l {
    if v == i {
      flag = false
      return flag
    }
  }
  return flag
}

func loop (x, n int, l []int) int {
  ans := x
  for i:=0; i <= n; i++ {
    for j := -1; j != 3; j +=2{
      if notExist(l, x + i * j) {
        ans = x + i * j
        return ans
      }
    }
  }
  return ans
}

func main() {
  var x, n, a int
  fmt.Scan(&x)
  fmt.Scan(&n)
  l := make([]int, n)
  for i:=0; i < n; i++ {
    fmt.Scan(&a)
    l[i] = a
  }

  ans := loop(x, n, l)
  fmt.Printf("%d\n", ans) 
}

Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

struct edge {int to; double cost;};
typedef pair<double, int> P; // firstは最短距離, secondは頂点の番号

const double INF=LLONG_MAX/2;
const int MAX_V=1010;
int V,E;
vector<edge> G[MAX_V];
double d[MAX_V];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d+V, INF);
  d[s]=0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second; // 頂点の番号
    if (d[v] < p.first) continue;
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

double x[1010],y[1010],r[1010];

int main(){
  cin>>x[0]>>y[0]>>x[1]>>y[1];
  r[0]=r[1]=0;
  cin>>V;
  rep(i,V) cin>>x[i+2]>>y[i+2]>>r[i+2];
  V+=2;
  rep(i,V) for(int j=i+1;j<V;j++){
    double d=max(0.0,sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2))-(r[i]+r[j]));
    G[i].push_back({j,d});
    G[j].push_back({i,d});
  }
  dijkstra(0);
  cout<<setprecision(22);
  cout<<d[1]<<endl;
  return 0;
}


Measured memory_bytes: 22804
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000000
	maxBufSize     = 100000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}
func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {
	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

var dp [][]int

func initDP(n int) {
	dp = make([][]int, n+1)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, n+1)
		for j := 0; j < len(dp[0]); j++ {
			dp[i][j] = -1
		}
	}
}

func resolve() {
	ans := []int{}
	for true {
		n := nextInt(sc)
		if n == 0 {
			break
		}
		as := nextIntSlice(sc, n)
		initDP(n)
		_rec(as, n, 0, n)
		ans = append(ans, dp[0][n])
	}
	for _, v := range ans {
		fmt.Println(v)
	}
	return
}

func _rec(as []int, n, l, r int) int {
	if dp[l][r] > -1 {
		return dp[l][r]
	}
	if r-l == 1 { // prevent to hit daruma
		dp[l][r] = 0
		return dp[l][r]
	}
	if r-l == 2 {
		if abs(as[l]-as[r-1]) <= 1 {
			dp[l][r] = 2
		} else {
			dp[l][r] = 0
		}
		return dp[l][r]
	}
	if abs(as[l]-as[r-1]) <= 1 {
		v := _rec(as, n, l+1, r-1)
		// if we can remove internal blocks
		if (r - 1 - (l + 1)) == v {
			dp[l][r] = v + 2
			return dp[l][r]
		} else {
			dp[l][r] = v
		}
	}
	for i := l + 1; i < r; i++ {
		v := _rec(as, n, l, i) + _rec(as, n, i, r)
		if dp[l][r] < v {
			dp[l][r] = v
		}
	}
	return dp[l][r]
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}



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

int main(){
    int N;
    cin >> N;
    map<string, int> mp;
    while(N--){
        string s;
        cin >> s;
        mp[s]++;
    }
    for(string s : {"AC", "WA", "TLE", "RE"}) cout << s << " x " << mp[s] << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;

int main(){
    int k,n;
    cin >> k >>n;
    vector<int> home(n+1);
    for (int i=0;i<n;i++){
        cin >> home.at(i);
    }
    home.at(n)=k+home.at(0);
    int nax =-INF;
    for (int i=0;i<n;i++){
        nax = max(home.at(i+1)-home.at(i),nax);
    }
    cout << k-abs(nax) << endl;
    return 0;
}

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

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

  int x, n;
  cin >> x >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v.at(i);

  bool is_found = false;
  int cnt = 0;
  int ans;
  while (!is_found)
  {
    int a = x - cnt;
    int b = x + cnt;
    bool a_is_ok = true;
    bool b_is_ok = true;
    for (int i = 0; i < n; i++)
    {
      if (v.at(i) == a)
      {
        a_is_ok = false;
        break;
      }
    }
    if (a_is_ok)
    {
      ans = a;
      break;
    }
    
    for (int i = 0; i < n; i++)
    {
      if (v.at(i) == b)
      {
        b_is_ok = false;
        break;
      }
    }
    if (b_is_ok)
    {
      ans = b;
      break;
    }
    if (a_is_ok || b_is_ok)
    {
      is_found = true;
    }
    cnt++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656