akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s[] = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        sc.close();

        Map<String, Integer> hm = new HashMap<>();
        for (String string : s) {
            if (hm.containsKey(string)) {
                hm.put(string, hm.get(string) + 1);
            } else {
                hm.put(string, 1);
            }
        }
        int max = 0;
        for (Integer v : hm.values()) {
            if (max < v)
                max = v;
        }
        final int fmax = max;
        List<String> t = hm.entrySet().stream().filter(e -> e.getValue() == fmax).map(e -> e.getKey()).sorted()
                .collect(Collectors.toList());
        for (String w : t) {
            System.out.println(w);
        }
    }
}

Measured memory_bytes: 79504
#include <iostream>
#include <cstdio>

using namespace std;

int sosu_f[50001];

void era(void){
    sosu_f[0]=sosu_f[1]=1;
    for(int i=2;i<=50000;i++){
        if(!sosu_f[i]){
            for(int j=i+i;j<=50000;j+=i){
                sosu_f[j]=1;
            }
        }
    }
}

int main(void){
    int n;
    int count;
    
    era();
    
    while(cin>>n,n!=0){
        count=0;
        for(int i=0;i<=n/2;i++){
            if(!sosu_f[i]&&!sosu_f[n-i]){
                count++;
            }
        }
        cout<<count<<endl;
    }
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    int alice = 0, bob = 0;

    while (!v.empty()) {
        alice += v.back();
        v.pop_back();
        if (v.size() > 0) {
            bob += v.back();
            v.pop_back();
        }
    }
    cout << alice - bob;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e5;
ll N;
typedef pair<ll,ll> P;
P AB[MAX_N];
typedef vector<ll> per;
bool vst[MAX_N];
void dfs(ll v,const per &p){
	vst[v]=true;
	if(!vst[p[v]]){
		dfs(p[v],p);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N){
		cin>>AB[i].first;
	}
	REP(i,N){
		cin>>AB[i].second;
	}
	sort(AB,AB+N,[](P a,P b){
		return a.second<b.second;
	});
	per p(N);
	REP(i,N)p[i]=i;
	sort(p.begin(),p.end(),[](ll a,ll b){
		return AB[a].first<AB[b].first;
	});
	bool ans,f=false;
	REP(i,N){
		if(AB[p[i]].first>AB[i].second){
			f=true;
		}
	}
	if(f){
		ans=false;
	}else{
		ll cnt=0;
		REP(i,N){
			if(!vst[i]){
				dfs(i,p);
				cnt++;
			}
		}
		if(cnt>1){
			ans=true;
		}else{
			ans=false;
			REP(i,N-1){
				if(AB[i].second>=AB[p[i+1]].first){
					ans=true;
				}
			}
		}
	}
	cout<<(ans?"Yes":"No")<<endl;
}

Measured memory_bytes: 2688
N, M = map( int, input().split())
V = [ [] for _ in range(N)]
for _ in range(M):
    a, b = map( int, input().split())
    V[a-1].append(b-1)
    V[b-1].append(a-1)
for i in range(N):
    print( len(V[i]))

Measured memory_bytes: 3060
M=10**9+7
dp={"TTT"=>1}
gets.to_i.times do
  nex=Hash.new{|h,k|h[k]=0}
  dp.each do |k,v|
    "AGCT".chars.each do |c|
      s=k+c
      next if s.match(/AGC|GAC|ACG|A.GC|AG.C/)
      s=s[1..-1]
      nex[s]+=v
      nex[s]%=M
    end
  end
  dp=nex
end
p dp.values.inject(:+)%M

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
struct Unionfind {
  vector<int> d;
  Unionfind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main(){
  ll n,m;
  cin>>n>>m;
  vector<P> ab(m);
  for(int i=0;i<m;i++){
    ll a,b;
    cin>>a>>b;
    --a;
    --b;
    ab[i].first=a;
    ab[i].second=b;
  }
  ll add[m]={};
  Unionfind uf=Unionfind(n);
  for(int i=m-1;i>=0;i--){
    if(uf.same(ab[i].first,ab[i].second)){
      continue;
    }
    add[i]=ll(uf.size(ab[i].first))*ll(uf.size(ab[i].second));
    uf.unite(ab[i].first,ab[i].second);
  }
ll temp=0;
  for(int i=0;i<m;i++){
    temp+=add[i];
    cout<<temp<<endl;
  }
  return 0;
}


Measured memory_bytes: 5896
#include <iostream>

int main()
{
  int N;
  std::cin >> N;
  int p[N];
  for (int i = 0; i < N; i++) std::cin >> p[i];
  
  int  c = 0;
  for (int i = 0; i < N; i++){
    if (p[i] != i+1) c++;
  }
  
  if (c <= 2) {
    std::cout << "YES";
    return 0;
  }   
  std::cout << "NO";
  return 0;
}
  
  
  


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	int num[100];
	long long int dp[100][21] = {0};
	
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
		scanf("%d", num + i);
		
	dp[0][num[0]] = 1;
		
	for(int i = 1; i < n - 1; ++i) {
		for(int j = 0; j < 21; ++j) {
			
			if(j - num[i] > -1)
				dp[i][j] += dp[i - 1][j - num[i]];
			if(j + num[i] < 21)
				dp[i][j] += dp[i - 1][j + num[i]];
		}
	}
	
	printf("%lld\n", dp[n - 2][num[n - 1]]);
	
	return 0;
}

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

def main():
    s = input()

    for i in range(len(s)):
        if s[i] == 'A':
            start = i
            break
    for j in range(len(s)-1, -1, -1):
        if s[j] == 'Z':
            end = j
            break
    print(end - start + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3516
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
	    int b = sc.nextInt(); 
	    int c = sc.nextInt();
	    System.out.println(Math.min(b/a, c));
	}
}

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

int main()
{
  int l, r, d, count = 0;
  cin>>l>>r>>d;
  for(int i = l; i <= r; i++)
  {
    if(i%d == 0)
    {
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 3568
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
cnt=0
for i in range(n):
    a = list(map(int,input().split()))
    tmp = c
    for j,k in zip(a,b):
        tmp += j * k
    if tmp > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N;
  string s;
  cin >> N >> s;
  i64 ans = 1e18;
  i64 w = 0;
  i64 e = count(all(s), 'E');
  for(i64 i = 0;i < N;i++) {
    if(s[i] == 'E') e--;
    ans = std::min(ans, w + e);
    if(s[i] == 'W') w++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 900
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        private static long mod = 1000000007;

        static void Main(string[] args)
        {
            var r = ReadSplit();
            var a = r[0].Decimal();
            var v = r[1].Decimal();
            var r2 = ReadSplit();
            var b = r2[0].Decimal();
            var w = r2[1].Decimal();
            var t = Read().Decimal();
            if (w >= v)
            {
                WriteRead("NO");
                return;
            }
            var m = v - w;
            var k = Math.Abs(b - a);
            var ps = k / m;
            if (t >= ps)
            {
                WriteRead("YES");
                return;
            }
            WriteRead("NO");
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 17872
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	string S; cin >> S;
	for (int i = 0; i < S.size(); i++) cout << "x";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2e5+1e2;
int n,Ans;
int a[maxn],b[maxn];

inline void file() {
	freopen("AGC024B.in","r",stdin);
	freopen("AGC024B.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	For (i,1,n) a[i]=read();
	For (i,1,n) b[a[i]]=b[a[i]-1]+1;
	For (i,1,n) chkmax(Ans,b[i]);
	printf("%d\n",n-Ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
double eps=1e-8;
ll mod=1e9+7;
ll inf=1e9;
priority_queue<P,vector<P>,greater<P> > pq;

int main(){
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  for(ll b=k+1;b<=n;b++){
    ans+=n/b*(b-k);
    ans+=max(0LL,n%b-k+(k==0?0:1));
  }
  
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> abc(n, vector<int>(3, 0));
    rep(i, n) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

    vector<vector<int>> dp(n + 1, vector<int>(3, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 2; j++) {
            for (int k = 0; k <= 2; k++) {
                if (j != k) dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abc[i][j]);
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}

Measured memory_bytes: 11136
def solve(m, f, r):
    if (m == -1 or f == -1) or m + f < 30:
        return "F"
    for a, b in ((80, "A"), (65, "B"), (50, "C")):
        if m + f >= a:
            return b
    if r >= 50:
        return "C"
    return "D"
while True:
    m, f, r = map(int, input().split())
    if m == f == r == -1:
        break
    print(solve(m, f, r))


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

using namespace std;
typedef complex<double> P;

P read()
{
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    return P(x2-x1,y2-y1);
}

int judge(P s1,P s2)
{
    P tmp=s1*conj(s2);
    if(tmp.real()==0)
    {
        return 1;
    }else if(tmp.imag()==0)
    {
        return 2;
    }else
    {
        return 0;
    }
}

int main()
{
    int q;
    cin>>q;

    while(q--)
    {
        P s1=read(),s2=read();
        cout<<judge(s1,s2)<<endl;
    }

    return 0;
}



Measured memory_bytes: 3224
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

ans = [Q for _ in range(N)]

for i in range(Q):
    p = A[i]
    ans[p-1] -= 1

for i in range(N):
    if ans[i] < K:
        print('Yes')
    else:
        print('No')

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

int GetRandom(int min,int max){
	return min + (int)(rand()*(max-min+1.0)/(1.0+RAND_MAX));
}

int main(){
    // 入力
    int D;
    cin >> D;   // D = 365
    ll c[26];
    for(int i=0;i<26;i++)
        cin >> c[i];
    ll s[D][26];
    for(int i=0;i<D;i++)
        for(int j=0;j<26;j++)
            cin >> s[i][j];
    // 初期解t[D]
    int t[D];
    /*
    for(int i=0;i<D;i++)
        cin >> t[i];
    */
    for(int i=0;i<D;i++){
        t[i] = GetRandom(1,26);   // 1<=, <=26
    }
    // クエリ
    int M;
    // cin >> M;
    M = 100000;
    int d[M], q[M];
    /*
    for(int i=0;i<M;i++)
        cin >> d[i] >> q[i];
    */
    for(int i=0;i<M;i++){
        d[i] = GetRandom(1,D);   // 1<=, <=26 
        q[i] = GetRandom(1,26);   // 1<=, <=26 
    }

    // 処理部
    ll v_best = 0;
    for(int query=0;query<M;query++){
        int last[26] = {}, q_;
        // コンテスト種別の変更
        q_ = t[d[query]-1];
        t[d[query]-1] = q[query];
        // D日分
        ll v = 0;
        for(int i=1;i<=D;i++){
            // 満足度の増加分
            v += s[i-1][t[i-1]-1];
            last[t[i-1]-1] = i;
            // 満足度の低下分（コンテスト26種分）
            for(int j=0;j<26;j++)
                v -= c[j]*(i - last[j]);
        }
        // cout << v << endl;
        if(v < v_best){
            t[d[query]-1] = q_;
        }
    }

    // 答え出力
    for(int i=0;i<D;i++)
        cout << t[i] << endl;

}

Measured memory_bytes: 4496
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
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 mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

//istream& operator>>(istream& is, const mint& a){return is >> a.x;}
//ostream& operator<<(ostream& os, const mint& a){return os << a.x;}

// 2^n
mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

// nCa
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n);
	mint ans = 0, sum = 0;
	rep(i,n){
		cin >> a[i];
		ans += sum * a[i];
		sum += a[i];
	}
	cout << ans.x << endl;
	return 0;
}


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

int main(){
    int a1, a2, a3;
    char c1, c2;
    cin >> a1 >> c1 >> a2 >> c2 >> a3;   
    
    if(a2 <= 4){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }

}

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

int main(){
    int64_t mod = 1000000007 ;
    int n,k ;
    cin >> n >> k ;
    int s = 0 ;
    int l = 0 ;
    int i ;
    for ( i = 0; i < k-1; i++)
    {
        s += i ;
        l += n-i ;
        if (l > mod)
        {
            l %= mod ;
        }
        if (s > mod)
        {
            s %= mod ;
        }
        
    }
    int64_t ans = 0 ;
    while (i < n+1)
    {
        s += i ;
        l += n-i ;
        if (l > mod)
        {
            l %= mod ;
        }
        if (s > mod)
        {
            s %= mod ;
        }
        int64_t temp = l - s + 1 ;
        if (temp < 0)
        {
            temp += mod ;
        }
        ans += temp ;
        if (ans >= mod)
        {
           ans %= mod ;
        }
        i++ ;
    }
    cout << ans << endl ;
}

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

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//




int main()
{
	IOS
	int H,W,h,w;
	cin >> H >> W >> h >> w;
	cout << H * W - h*W - w * H + h * w;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 8

int Location[N][N];
int row[N];
int col[N];
int attackR[2*N-1];
int attackL[2*N-1];

void init(){
  int i,j;
  for(i=0;i<N;i++)row[i]=col[i]==-1;
  for(i=0;i<2*N-1;i++) attackR[i]=attackL[i]=-1;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      Location[N][N]=-1;
    }
  }
}

void printLocation(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(Location[i][j]==1&&row[i]!=j)return;
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }

}
void putQueen(int i){
  int j;
  if(i==N){
    printLocation();
    return ;
  }
  for(j=0;j<N;j++) {
    if(col[j]==1||attackL[j+i]==1||attackR[i-j+N-1]==1)continue;
    row[i]=j;
    col[j]=attackL[j+i]=attackR[i-j+N-1]=1;
    putQueen(i+1);
    col[j]=attackL[j+i]=attackR[i-j+N-1]=-1;
  }
}
int main(){
  int n;
  int r,c,i;
  init();
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    Location[r][c]=1;
  }
  putQueen(0);
  return 0;
}

Measured memory_bytes: 572
/* ITP1_5_A 

*/
#include <stdio.h>
int main(void)
{
	int vertical, horizonal, work;
	
	fscanf(stdin, "%d %d", &vertical, &horizonal);
	while (vertical && horizonal) {
		while (vertical--) {
			work = horizonal;
			while (work--) fputc('#', stdout);
			fputc('\n', stdout);
		}
		fputc('\n', stdout);
	fscanf(stdin, "%d %d", &vertical, &horizonal);
	}
	
	return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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 main() {
    ll X, Y; cin >> X >> Y;

    ll ans = 0;
    while(X <= Y) {
        X *= 2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    string s;
	cin>>s;
	if(s=="SUN")cout<<7<<endl;
	else if(s=="MON")cout<<6<<endl;
	else if(s=="TUE")cout<<5<<endl;
	else if(s=="WED")cout<<4<<endl;
	else if(s=="THU")cout<<3<<endl;
	else if(s=="FRI")cout<<2<<endl;
	else cout<<1<<endl;
}

Measured memory_bytes: 256
A = []
for i in range(5):
    A.append(int(input()))

#minA = 124
minIdx = 0
minV = 9


for i in range(5):
    temp = A[i] % 10
    if 0 < temp and temp < minV:
        minIdx = i
        minV = temp

ans = 0

for i in range(5):
    if i == minIdx:
        ans += A[i]
    else:
        if A[i] % 10 == 0:
            ans += A[i]
        else:
            ans += A[i] + 10 - (A[i] % 10)

print(ans)


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

int K;
int dfs(int,int,string);

int main(){
    cin>>K;
    int k=1;//何番目
    int n=1;//桁数
    while(k<=K){
        k=dfs(k,n,"");//桁数ごとに探索
        n++;
    }
    return 0;
}

int dfs(int k,int n,string s){//k:何番目か　n:何桁か
    if((int)s.size()==n){//n桁の時の探索
        if(k==K){//番号が一致で出力
            cout<<s<<endl;
        }
        k++;//次へ
        return k;//n桁の探索終わり
    }
    if((int)s.size()==0){//なんもない
        for(int i=1;i<10;i++){
            string ns=s;
            ns.push_back((char)(i+'0'));//一桁の数を追加
            k=dfs(k,n,ns);
        }
    }else{//なにかある
        for(int i=0;i<10;i++){
            if(abs((int)(s.back()-'0')-i)<=1){//lunlun数の条件を満たすとき(iが)
                string ns=s;
                ns.push_back((char)(i+'0'));//iを追加
                k=dfs(k,n,ns);//深くまで探索していく
            }
        }
    }
    return k;
}

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

int main() {
  int N, M, S;
  cin >> N >> M;
  S=0;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
    S=S+A[i];
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  if (4*M*A[M-1]>=S) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
 
int main(){
    double n, t, a; cin >> n >> t >> a;
    vector<double> h(n);
    rep(i, n){cin >> h[i];}
    double temp = 100000;
    int place = 0;
    rep(i, n){
        double diff = abs(a - (t - h[i] * 0.006));
        if (diff < temp){
            temp = diff;
            place = i+1;
        }
    }
    cout << place << endl;
}

Measured memory_bytes: 3816
n = int(input())
a = list(map(int,input().split()))

if n % 2 == 0:
    for i in reversed(range(n)):
        if i % 2 == 1:
            print(a[i], end=" ")
    for i in range(n):
        if i % 2 == 0:
            print(a[i], end=" ")
else:
    for i in reversed(range(n)):
        if i % 2 == 0:
            print(a[i], end=" ")
    for i in range(n):
        if i % 2 == 1:
            print(a[i], end=" ")

Measured memory_bytes: 26180
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa, bb;
	cin >> aa >> bb;
	if(aa < 10 && bb < 10)
	{
		cout << (aa * bb) << endl;
	}
	else
	{
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    char a,b;
    cin>>a>>b;
    
    if(a=='H' && b=='H') cout<<'H'<<endl;
    else if(a=='H' && b=='D') cout<<'D'<<endl;
    else if(a=='D' && b=='H') cout<<'D'<<endl;
    else cout<<'H'<<endl;
    
    return 0;
}

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

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

    vector<int> a(A);
    for(int i = 0; i < A; ++i) cin >> a[i];

    vector<int> b(B);
    for(int i = 0; i < B; ++i) cin >> b[i];

    vector<int> x(M), y(M), c(M);
    for(int i = 0; i < M; ++i) cin >> x[i] >> y[i] >> c[i];

    int a_min = *min_element(begin(a), end(a));
    int b_min = *min_element(begin(b), end(b));
 
    int ans = a_min+b_min;
    for(int i = 0; i < M; ++i){
        ans = min(ans, a[x[i]-1]+b[y[i]-1]-c[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 2176
class SegTree:
    X_unit = 0
    X_f = max

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)
lim = 4*10**5
n,k = map(int,input().split())
seg = SegTree(lim)
# a = [0]*n
# seg.build(a)
for i in range(n):
    a = int(input())
    seg.set_val(a,seg.fold(max(0,a-k),min(lim,a+k+1)) + 1)

print(seg.fold(0,lim))

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


int main(){
  int n;
  cin >>n;
  vector<string> st(n);
  rep(i,n)cin>>st.at(i);
  map<string,int> mp;
  int checker = 0;
  rep(i,n){
    if(mp.count(st.at(i))){
      mp[st.at(i)]+=1;
    }
    else{
      mp[st.at(i)] = 0;
    }

    checker = max(checker,mp.at(st.at(i)));
  }

  for(auto p:mp){
    if(p.second == checker){
      cout<<p.first<<endl;
    }
  }
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long

class UnionFind {
  public:
  vector<int> par, rank, size;
  UnionFind(int N): par(N), rank(N, 0), size(N, 1) {
    rep(i, 0, N) par[i] = i;
  }
  void addNode(int x) {
    par[x] = x;
    rank[x] = 0;
    size[x] = 1;
  }
  int root(int x) {
    if (par[x] != x) {
      par[x] = root(par[x]);
    }
    return par[x];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      par[x] = y;
      size[y] += size[x];
    } else {
      par[y] = x;
      size[x] += size[y];
      if (rank[x] == rank[y]) {
        rank[x] += 1;
      }
    }
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  int com, x, y;
  UnionFind uf(n);
  rep(i, 0, q) {
    cin >> com >> x >> y;
    if (com) {
      if (uf.same(x, y)) {
        cout << 1 << endl;
      } else cout << 0 << endl;
    } else {
      uf.unite(x, y);
    }
  }
};



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

int main(){
  long long int W,H,x,y;
  cin >> W >> H >> x >> y;


  double ans1 = (double)(W*H)/2.0;
  int ans2 = 0;
  if(W%2==0 && H%2 == 0){
    if(W/2==x&&H/2 ==y){
      ans2 =1 ;
    }
  }


  cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
	int a, b, c;

	cin >> a;

	b = a / 10;
	c = a % 10;

	if (b == 9 || c == 9) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
while(true){
int a,b;
cin >> a >> b;
if(a==0&&b==0)return 0;
int x[4],y[4];
for(int i=0;i<4;i++){
x[i]=a%10;
a/=10;
y[i]=b%10;
b/=10;
}

int hit=0,blow=0;
for(int i=0;i<4;i++)if(x[i]==y[i])hit++;

for(int i=0;i<4;i++){
for(int j=0;j<4;j++)if(x[i]==y[j])blow++;
}
blow-=hit;

printf("%d %d\n",hit,blow);
}
}

Measured memory_bytes: 1144
function gcd(a,b){
  if(b==0){return a;}
  return gcd(b,a%b);
}

function main(input){
  const lines = input.split('\n');
  const N = parseInt(lines[0]);
  const As = lines[1].split(' ').map(x => parseInt(x));

  var result = As[0];
  for(var i=1;i<N;i++){
    result = gcd(result, As[i])
  }
  console.log(result);
}

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

Measured memory_bytes: 21324
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll k,n;
  cin >> k >> n;
  vector<ll> a(n+1);
  rep(i,n) cin >> a[i];
  a[n]=a[0]+k;
  ll ans=0;
  rep(i,n) {
    //cout << a[i+1]-a[i] << endl;
    chmax(ans,a[i+1]-a[i]);
  }
  cout << k-ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int64_t m2,m1;
  m2 = 2LL;
  m1 = 1LL;
  
  for (int i=0;i<N-1;i++){
    m2 += m1;
    swap(m1,m2);
  }
  
  cout << m1 << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000000
using Graph=vector<vector<int>>;

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N,1);
  for(int i=0;i<K;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int a;
      cin>>a;
      a--;
      A.at(a)=0;
    }
  }

  int ans=0;
  for(int i=0;i<N;i++){
    ans+=A.at(i);
  }
  cout<<ans<<endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:
ll x[100010];
ll d[100010];
ll nd[100010];
int a[100010];

int b[64][100010];
int idx[100010];

int main(void){
	ll n;
	cin >> n;
	rep(i,n) cin >> x[i];
	
	ll m,k;
	cin >> m >> k;
	rep(i,m) cin >> a[i],a[i]--;

	rep(i,n-1) b[0][i]=i;
	rep(i,m) swap(b[0][a[i]-1],b[0][a[i]]);

	rep(j,63) rep(i,n-1) b[j+1][i]=b[j][b[j][i]];

	rep(i,n-1) idx[i]=i;

	rrep(j,63){
		if((k&(1LL<<j))==0) continue;
		rep(i,n-1) idx[i]=b[j][idx[i]];
	}

	
	/*
	cout << endl;
	rep(i,n-1) cout << idx[i] << endl;
	cout << endl;
	*/

	rep(i,n-1) d[i]=x[i+1]-x[i];
	rep(i,n-1) nd[i]=d[idx[i]];

	ll cur=x[0];
	rep(i,n) cout << cur << endl,cur+=nd[i];
	return 0;
}

Measured memory_bytes: 29440
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,sum,f,h,fi,t,fiv;
cin>>x;
f = x/500;
x = x%500;

fiv = x /5;
x = x%5;
sum = f*1000+fiv*5;
cout<<sum<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		long n = sc.nextLong(); //人数
		long min = Long.MAX_VALUE / 10;
		for(int i = 0; i < 5; i++) {
			long time = sc.nextLong();
			if (min > time)
				min = time;
		}
		long plus = n / min;
		if (n % min > 0) plus++;
		long ans = plus  + 4;
		out.println(ans);
		
		out.close();
	}
	  private static long gcd(long m, long n) {
		    if(m < n) return gcd(n, m);
		    if(n == 0) return m;
		    return gcd(n, m % n);
		}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N; cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    sort(ALL(L));
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            for (int k = j+1; k < N; k++) {
                if (L[i] == L[j] || L[i] == L[k] || L[j] == L[k]) continue;
                if (L[i] + L[j] > L[k]) ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#define INF 1e6
using namespace std;
typedef long long ll;
vector<int> G[100001];
int n,m,s,t;
int dist_s[100001];
int dist_l[100001];
int main(void){
	scanf("%d %d %d %d",&n,&m,&s,&t);
	s--;
	t--;
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	fill(dist_s,dist_s+n,INF);
	queue<int> que;
	que.push(s);
	dist_s[s]=0;
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			int nec=G[v][i];
			if(dist_s[nec]==INF){
				dist_s[nec]=dist_s[v]+1;
				que.push(nec);
			}
		}
	}
	fill(dist_l,dist_l+n,INF);
	que.push(t);
	dist_l[t]=0;
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			int nec=G[v][i];
			if(dist_l[nec]==INF){
				dist_l[nec]=dist_l[v]+1;
				que.push(nec);
			}
		}
	}
	int mincost=dist_s[t];
	ll cnt=0;
	sort(dist_s,dist_s+n);
	sort(dist_l,dist_l+n);
	for(int i=0;i<n;i++){
		int midl=lower_bound(dist_l,dist_l+n,mincost-dist_s[i]-2)-dist_l;
		int midr=upper_bound(dist_l,dist_l+n,mincost-dist_s[i]-2)-dist_l;
		if(midl<n && midl>=0 && dist_s[i]+dist_l[midl]+2==mincost){
			cnt+=(ll)(midr-midl);
		}
	}
	printf("%lld\n",cnt);
	return 0;
}

Measured memory_bytes: 8216
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void solve()
{
	int n;
	cin >> n;
	vi a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int res = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			if (a[i] == a[j])
			{
				continue;
			}
			int sum = a[i] + a[j];
			int dif = a[i] - a[j];
			for (int k = j + 1; k < n; ++k)
			{
				if (a[i] == a[k] || a[j] == a[k]) {
					continue;
				}
				if (sum > a[k] && dif+ a[k] > 0
				        && a[k] > dif) {
					res++;
				}
			}
		}
	}
	cout<<res<<endl;

}
int main()
{
	std::ios::sync_with_stdio(false);
		solve();

	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include<string>
#define rep(i,a,b) for(long long int i=(a);i<(b);i++)
#define se(a) a.begin(),a.end()
#define ll long long int
#define mll map<ll,ll>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e16
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	rep(i,0,n)
	cin>>a[i];
	ll dp[n][n];
	rep(i,0,n)
	dp[i][i]=0;
	ll b[n+1];b[0]=0;
	rep(i,0,n)
	b[i+1]=b[i]+a[i];
	for(int gap=2;gap<=n;gap++)
	for(int i=0;i<n-gap+1;i++)
	{
		int j=i+gap-1;
		dp[i][j]=inf;
		for(int k=i;k<j;k++)
		dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+b[j+1]-b[i]);
	}
	cout<<dp[0][n-1]<<endl;
//	rep(i,0,n)
//	{
//		rep(j,0,n)
//		cout<<dp[i][j]<<" ";
//		cout<<endl;
//	}
}

Measured memory_bytes: 1536
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main(void){
    ll n;
    ll m;
    ll sum=0;
    vector<ll> a;
    cin >> n;
    cin >>m;
    REP(i,m){
        ll tmp;
        cin >>tmp;
        sum += tmp;
    }

    if(sum > n){
        cout << "-1" << endl;
    }else{
        cout << n-sum << endl;
    }

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int ans = 0;
    int A[N+1]; rep(i, N) cin >> A[i+1];
    for(int i = 1; i <= N; i++){
        if(i < A[i] && A[A[i]] == i) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<vector<int>>c(3,vector<int>(3));
  for(int i=0;i<3;i++){
  for(int j=0;j<3;j++)
    cin>>c.at(i).at(j);
  
  }set<int>s1;
  for(int i=0;i<3;i++){
  s1.insert(c.at(i).at(0)-c.at(i).at(1));
  }set<int>s2;
  for(int i=0;i<3;i++){
  s2.insert(c.at(i).at(1)-c.at(i).at(2));
  }if(s1.size()==1 && s2.size()==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
   
  
  return 0;
}

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

using namespace std;

#define N 1000010

int a[N] = {0};
int seen[N] = {0};

int main() {
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        int v;
        scanf("%d", &v);
        a[v]++;
    }
    int step = 0;
    for(int i=1000000; i >= 1; i--) {
    	bool printed = false;
        if(a[i]) {
            for(int j=(i << 1); j <= 1000000; j += i) {
                a[j] = 0;
            }
            if(a[i] > 1) {
            	a[i] = 0;
            }
        }
    }
    int cnt = 0;
    for(int i=1; i<=1000000; i++) {
        if(a[i]) {
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 7692
// ABC_155_C
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define forn(i, n) for(int i = 0; i < (int)n; ++i)

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

	map<string, int> mp;
	forn(i, n) {
		string tmp;
		cin >> tmp;
		++mp[tmp];
	}

	int max = 0;
	for(auto item : mp) {
		int tmp = item.second;
		if(max < tmp) max = tmp;
	}

	for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
		if(itr->second >= max) cout << itr->first << "\n";
	}

	return 0;
}

Measured memory_bytes: 19236
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define Mod 1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
ll ckck(ll N)
{
    ll lo=1,hi=1e10;
    ll  mid,ind;
    ll cnt;
    while(lo<=hi)
    {
        mid=lo+(hi-lo)/2;
        cnt=mid*(mid+1);
        cnt/=2;
        cnt-=1;
        if(N>cnt)
        {
            ind=mid;
            lo=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return ind;
}

int main()
{
   int A,B;
   cin>>A>>B;
   if(B>=A)
    cout<<"unsafe";
   else
    cout<<"safe";

}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
int p[300000], n, m;
pair<int, int>x[300000];
int main() {
	cin >> n >> m; for (int i = 1; i <= n; i++) { p[i] = i; }
	for (int i = 0; i < m; i++) { int r; cin >> r; p[r] = -i; }
	for (int i = 1; i <= n; i++) { x[i] = make_pair(p[i], i); }
	sort(x + 1, x + n + 1);
	for (int i = 1; i <= n; i++) { cout << x[i].second << endl; }
	return 0;
}

Measured memory_bytes: 6204
package main

import (
  "fmt"
)

func main() {
  var n int
  fmt.Scanf("%d", &n)
  mod := 1000000000 + 7
  ans := 1
  for i := 1; i <= n; i++ {
    ans = (ans * i) % mod
  }
  fmt.Println(ans)
}

Measured memory_bytes: 1832
#A 歳の高橋君が観覧車に乗ろうとしています。この観覧車は、13 歳以上が乗るには B 円 (B は偶数) かかりますが、
#6 歳以上 12 歳以下の人はその半額で乗ることができ、 さらに 5 歳以下の人は無料で乗ることができます。
#高橋君が観覧車に乗るには何円かかるかを求めてください。

A, B = map(int, input().split())
if A <= 5:
    print(0)
elif 6 <= A <= 12:
    print(B//2)
else:
    print(B)



Measured memory_bytes: 38256
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm> 
#include <cstring>
#include <cmath>
#include <map>
#include<queue>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	string s;
	cin>>s;
	int n=s.size();
	int j=n;
	for(j;;j--)
	{
		if(s[j]=='T')
		break;
	}
	int k=0;
	for(k;;k++)
	{
		if(s[k]=='S')
		break;
	 } 
	int tnum=0;
	int snum=0;
	for(int i=k;i<=j;i++)
	{
		
		if(s[i]=='S') 
		{
			snum++;
		}
		if(s[i]=='T') 
		{
			if(snum!=0)
			{
				snum--;
			}
			else
			{
				tnum++;
			}
			
		}
	}
	cout<<k+(n-j)+snum+tnum-1;
	return 0;
}

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

int n, k;

int main(){
    string s;
    cin >> n >> k;
    cin >> s;
    k--;
    if(s[k] == 'A') s[k] = 'a';
    else if(s[k] == 'B') s[k] = 'b';
    else s[k] = 'c';

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256